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');
network_mode = fread(fid,1,'uchar');
firmware_version = fread(fid,1,'uchar');
unused_char3 = fread(fid,1,'uchar');
fpga_version=fread(fid,1,'uchar');
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');   
first_sample_acq_time = fread(fid,1,'uint64');   
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'));
acq_sequence_frame_index = 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');
unused_4 = fread(fid,1,'uchar');
unused_5 = fread(fid,1,'uchar');
num_of_data_bytes_per_headers = fread(fid,1,'uint32');

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_unused = 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_unused = 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')');          
 
% additional new parameters
AD_send_available_RX_buffers = fread(fid,1,'uint32');
AD_save_available_512_pages = fread(fid,1,'uint32');
byte_num_of_RX_buffers_dma_INTR_level = fread(fid,1,'uint16');
SD_folder_name_index = fread(fid,1,'uint16');
SD_file_saved_sectors = fread(fid,1,'uint32');
SD_file_sector_size = fread(fid,1,'uint32');
system_time = char(fread(fid,12,'uchar')');    % check
system_time = system_time*1;
FG_compensation_DA_X = fread(fid,1,'uint16');
FG_compensation_DA_Y = fread(fid,1,'uint16');
FG_compensation_DA_Z = fread(fid,1,'uint16');
FG_accelerometer_AD_X = fread(fid,1,'uint16');
FG_accelerometer_AD_Y = fread(fid,1,'uint16');
FG_accelerometer_AD_Z = fread(fid,1,'uint16');
FG_pressure_AD = fread(fid,1,'uint16');
FG_sampling_frequency = fread(fid,1,'uint16');
FG_AD_X = fread(fid,1,'uint32');
FG_AD_Y = fread(fid,1,'uint32');
FG_AD_Z = fread(fid,1,'uint32');
FG_SD_AD_data_sector_size_per_header = fread(fid,1,'uint16');
unused_6 = fread(fid,1,'uint16');



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 ,...
'network_mode', network_mode ,...
'firmware_version', firmware_version ,...
'unused_char3', unused_char3 ,...
'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_time', first_sample_acq_time ,...
'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 ,...
'acq_sequence_frame_index', acq_sequence_frame_index ,...
'sensor_orientation',{sensor_orientation},...
'sensor_distance',{sensor_distance},...
'sensor_ID',{sensor_ID},...
'unuse_4', unused_4 ,...
'unused_5', unused_5 ,...
'num_of_data_bytes_per_headers', num_of_data_bytes_per_headers ,...
'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_unused', SD_file_sector_size_unused ,...
'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_unused', SD_file_saved_sectors_unused ,...
'SD_percent_freeSpace', SD_percent_freeSpace ,...
'SD_freeSpace', SD_freeSpace ,...
'igain_tab', igain_tab ,...
'user_comments', user_comments ,...
'AD_send_available_RX_buffers', AD_send_available_RX_buffers ,...
'AD_save_available_512_pages', AD_save_available_512_pages ,...
'byte_num_of_RX_buffers_dma_INTR_level', byte_num_of_RX_buffers_dma_INTR_level ,...
'SD_folder_name_index', SD_folder_name_index ,...
'SD_file_saved_sectors', SD_file_saved_sectors ,...
'SD_file_sector_size', SD_file_sector_size ,...
'system_time', system_time ,... 
'FG_compensation_DA_X', FG_compensation_DA_X ,...
'FG_compensation_DA_Y', FG_compensation_DA_Y ,...
'FG_compensation_DA_Z', FG_compensation_DA_Z ,...
'FG_accelerometer_AD_X', FG_accelerometer_AD_X ,...
'FG_accelerometer_AD_Y', FG_accelerometer_AD_Y ,...
'FG_accelerometer_AD_Z', FG_accelerometer_AD_Z ,...
'FG_pressure_AD', FG_pressure_AD ,...
'FG_sampling_frequency', FG_sampling_frequency ,...
'FG_AD_X', FG_AD_X ,...
'FG_AD_Y', FG_AD_Y ,...
'FG_AD_Z', FG_AD_Z ,...
'FG_SD_AD_data_sector_size_per_header', FG_SD_AD_data_sector_size_per_header ,...
'unused_6', unused_6 );
          
