function Header = rdKMShd(fid)

packet_starting_flag = char(fread(fid,4,'uchar')');
packet_length = fread(fid,1,'uint16');
host_WI_network_address = fread(fid,1,'uint16');
KMS820_SN = char(fread(fid,16,'uchar')');
KMS820_network_address = fread(fid,1,'uint16');
KMS820_network_address_mask = fread(fid,1,'uint16');
send_packet_ID = fread(fid,1,'uint32');
send_header_packet_ID = fread(fid,1,'uint32');
save_packet_ID = fread(fid,1,'uint32');
firmware_version = fread(fid,1,'uint16');
fpga_version=fread(fid,1,'uint16');
GPS_pos_info = char(fread(fid,32,'uchar')');          
GPS_time_info = char(fread(fid,24,'uchar')');            
GPS_syn_clk = char(fread(fid,8,'uchar')');            
sampling_frequency = fread(fid,1,'uint32');          
first_sample_acq_time1 = fread(fid,1,'uint32');          
first_sample_acq_time2 = fread(fid,1,'uint32');   
sampling_time_read_frame_interval = fread(fid,1,'uint16');
AD_main_temperature  = fread(fid,1,'uint16');
AD_SYS_I = fread(fid,1,'uint16');
AD_N11V  = fread(fid,1,'uint16');
AD_P11V  = fread(fid,1,'uint16');
AD_SYS_V = fread(fid,1,'uint16');
sensor_SN = cell(6,1);
for k = 1:6
    sensor_SN{k}  = char(fread(fid,16,'uchar')');
end
sensor_component = cell(6,1);
for k = 1:6
    sensor_component{k}  = char(fread(fid,1,'uchar'));
end
wireless_signal_strength = char(fread(fid,1,'uchar'));
unused_2 = fread(fid,1,'uchar');
sensor_orientation = cell(6,1);
for k = 1:6
    sensor_orientation{k}  = fread(fid,1,'uint16');
end
sensor_distance = cell(6,1);
for k = 1:6
    sensor_distance{k}  = fread(fid,1,'uint16');
end          
sensor_ID = cell(6,1);
for k = 1:6
    sensor_ID{k}  =fread(fid,1,'uchar');
end          
num_of_AD_page_send_queque_trigger_level = fread(fid,1,'uchar');         
num_of_AD_page_save_queque_trigger_level = fread(fid,1,'uchar');          
AD_send_available_RX_buffers =  fread(fid,1,'uint16');
AD_save_available_512_pages = fread(fid,1,'uint16');

status = char(fread(fid,8,'uchar')');
status = status*1;  
ch_setting = char(fread(fid,8,'uchar')');
ch_setting = ch_setting*1;
AD_ctrl_word = char(fread(fid,4,'uchar')');
AD_ctrl_word = AD_ctrl_word*1;
chActive = zeros(6,1);
temp = AD_ctrl_word(4);
for k = 1:6
    chActive(k) = mod(temp,2);
    temp = floor(temp/2);
end
    
DA_offset_value = fread(fid,6,'uint16');
DA_CAL_value = fread(fid,1,'uint16');
DA_SENSOR_value = fread(fid,1,'uint16');
SD_file_name = char(fread(fid,64,'uchar')');
SD_file_sector_size = fread(fid,1,'uint16');
SD_AD_data_sector_size_per_header = fread(fid,1,'uint16');
SD_file_limit_num = fread(fid,1,'uint32');
SD_file_index = fread(fid,1,'uint32');
SD_file_saved_sectors = fread(fid,1,'uint16');
SD_percent_freeSpace = fread(fid,1,'uint16');
SD_freeSpace =  fread(fid,1,'uint32');         
igain_tab = reshape(fread(fid,72,'uint16'),[4,3,6]);          
user_comments = char(fread(fid,128,'uchar')');          
 
Header = struct('packet_starting_flag',packet_starting_flag,...
'packet_length', packet_length ,...
'host_WI_network_address', host_WI_network_address ,...
'KMS820_SN', KMS820_SN ,...
'KMS820_network_address', KMS820_network_address ,...
'KMS820_network_address_mask', KMS820_network_address_mask ,...
'send_packet_ID', send_packet_ID ,...
'send_header_packet_ID', send_header_packet_ID ,...
'save_packet_ID', save_packet_ID ,...
'firmware_version', firmware_version ,...
'fpga_version', fpga_version,...
'GPS_pos_info', GPS_pos_info ,...
'GPS_time_info', GPS_time_info ,...
'GPS_syn_clk', GPS_syn_clk ,...
'sampling_frequency', sampling_frequency ,...
'first_sample_acq_time1', first_sample_acq_time1 ,...
'first_sample_acq_time2', first_sample_acq_time2 ,...
'sampling_time_read_frame_interval', sampling_time_read_frame_interval ,...
'AD_main_temperature', AD_main_temperature  ,...
'AD_SYS_I', AD_SYS_I ,...
'AD_N11V', AD_N11V  ,...
'AD_P11V', AD_P11V  ,...
'AD_SYS_V', AD_SYS_V ,...
'sensor_SN', {sensor_SN },...
'sensor_component',{sensor_component},...
'wireless_signal_strength', wireless_signal_strength ,...
'unused_2', unused_2 ,...
'sensor_orientation',{sensor_orientation},...
'sensor_distance',{sensor_distance},...
'sensor_ID',{sensor_ID},...
'num_of_AD_page_send_queque_trigger_level', num_of_AD_page_send_queque_trigger_level ,...
'num_of_AD_page_save_queque_trigger_level', num_of_AD_page_save_queque_trigger_level ,...
'AD_send_available_RX_buffers', AD_send_available_RX_buffers ,...
'AD_save_available_512_pages', AD_save_available_512_pages ,...
'status', status ,...
'ch_setting', ch_setting ,...
'AD_ctrl_word', AD_ctrl_word ,...
'chActive',chActive,...
'DA_offset_value', DA_offset_value ,...
'DA_CAL_value', DA_CAL_value ,...
'DA_SENSOR_value', DA_SENSOR_value ,...
'SD_file_name', SD_file_name ,...
'SD_file_sector_size', SD_file_sector_size ,...
'SD_AD_data_sector_size_per_header', SD_AD_data_sector_size_per_header ,...
'SD_file_limit_num', SD_file_limit_num ,...
'SD_file_index', SD_file_index ,...
'SD_file_saved_sectors', SD_file_saved_sectors ,...
'SD_percent_freeSpace', SD_percent_freeSpace ,...
'SD_freeSpace', SD_freeSpace ,...
'igain_tab', igain_tab ,...
'user_comments', user_comments );
          
