function thm_unpack_hed, data_type, dh
uint_256 = uint( 256)
long_256 = long( 256)
apid = reform( uint( ( 32b*dh[ *, 0]/32b))*uint_256 + uint( dh[ *, 1]))
apid_ctr = reform( uint( ( 4b*dh[ *, 2]/2b))*uint_256 + uint( dh[ *, 3]))
app_data_field_len = reform( uint( dh[ *, 4])*uint_256 + uint( dh[ *, 5]))
clock_bytes = reform( dh[ *, 6:9])
subsec_bytes = reform( dh[ *, 10:11])
clock = reform( long( dh[ *, 9]) $
+ long_256*( long( dh[ *, 8]) $
+ long_256*( long( dh[ *, 7]) $
+ long_256*( long( dh[ *, 6])))))
subsec = reform( long( dh[ *, 11]) $
+ long_256*( long( dh[ *, 10])))
switch strlowcase( data_type) of
'fit': begin
compression = reform( dh[ *, 12]/128b)
efi_config = reform( dh[ *, 12] and 127b)
fgm_config = reform( dh[ *, 13] and 127b)
fgm_range_x = reform( dh[ *, 14]/16b)
fgm_range_y = reform( dh[ *, 14] and 15b)
fgm_range_z = reform( dh[ *, 15]/16b)
fgm_rate = reform( dh[ *, 15] and 7b)
fgm_rate = 2.^(2+fgm_rate)
hed_data = { data_type:data_type, $
apid:apid, apid_ctr:apid_ctr, app_data_field_len:app_data_field_len, $
clock_bytes:clock_bytes, subsec_bytes:subsec_bytes, $
clock:clock, subsec:subsec, $
compression:compression, $
efi_config:efi_config, fgm_config:fgm_config, $
fgm_range_x:fgm_range_x, fgm_range_y:fgm_range_y, fgm_range_z:fgm_range_z, $
fgm_rate:fgm_rate }
break
end
'fbk': begin
compression = reform( dh[ *, 12]/128b)
config = reform( dh[ *, 12] and 127b)
spare_config = reform( dh[ *, 13])
speed = reform( (dh[ *, 14]/16b) and 7b)
speed = 2.^( float(speed)-4.)
fb1_sel = reform( dh[ *, 15]/16b)
fb2_sel = reform( dh[ *, 15] and 15b)
fb_sel_str = [ 'V1', 'V2', 'V3', 'V4', 'V5', 'V6', $
'E12DC', 'E34DC', 'E56DC', $
'SCM1', 'SCM2', 'SCM3', $
'E12AC', 'E34AC', 'E56AC', $
'UNDEF' ]
fb1_sel_str = fb_sel_str[ fb1_sel]
fb2_sel_str = fb_sel_str[ fb2_sel]
hed_data = { data_type:data_type, $
apid:apid, apid_ctr:apid_ctr, app_data_field_len:app_data_field_len, $
clock_bytes:clock_bytes, subsec_bytes:subsec_bytes, $
clock:clock, subsec:subsec, $
compression:compression, $
speed:speed, $
fb1_sel:fb1_sel, fb1_sel_str:fb1_sel_str, $
fb2_sel:fb2_sel, fb2_sel_str:fb2_sel_str }
break
end
'vaf':
'vbf':
'eff':
'vap':
'vbp':
'efp':
'vaw':
'vbw': begin
compression = reform( dh[ *, 12]/128b)
config = reform( dh[ *, 12] and 127b)
spare_config = reform( dh[ *, 13])
speed = reform( dh[ *, 14]/16b)
speed = 2.^( float(speed) + 1.)
chan_sel = reform( dh[ *, 15] and 63b)
hed_data = { data_type:data_type, $
apid:apid, apid_ctr:apid_ctr, app_data_field_len:app_data_field_len, $
clock_bytes:clock_bytes, subsec_bytes:subsec_bytes, $
clock:clock, subsec:subsec, $
compression:compression, $
speed:speed, $
chan_sel:chan_sel }
break
end
'scf':
'scp': begin
compression = reform( dh[ *, 12]/128b)
config = reform( dh[ *, 12] and 127b)
spare_config = reform( dh[ *, 13])
speed = reform( dh[ *, 14]/16b)
speed = 2.^( float(speed) + 1.)
chan_sel = reform( dh[ *, 15] and 7b)
hed_data = { data_type:data_type, $
apid:apid, apid_ctr:apid_ctr, app_data_field_len:app_data_field_len, $
clock_bytes:clock_bytes, subsec_bytes:subsec_bytes, $
clock:clock, subsec:subsec, $
compression:compression, $
speed:speed, $
chan_sel:chan_sel }
break
end
'efw':
'scw': begin
compression = reform( dh[ *, 12]/128b)
config = reform( dh[ *, 12] and 127b)
spare_config = reform( dh[ *, 13])
speed = reform(dh[ *, 14]/16b)
speed = 2.^( float(speed) + 1.)
chan_sel = reform( dh[ *, 15])
hed_data = { data_type:data_type, $
apid:apid, apid_ctr:apid_ctr, app_data_field_len:app_data_field_len, $
clock_bytes:clock_bytes, subsec_bytes:subsec_bytes, $
clock:clock, subsec:subsec, $
compression:compression, $
speed:speed, $
chan_sel:chan_sel }
break
end
'ffp':
'ffw': begin
compression = reform( dh[ *, 12]/128b)
speed = reform( (dh[ *, 14]/16b) and 7b)
speed = 2.^( float(speed)-4.)
nbins = reform( (dh[ *, 14]/4b) and 3b)
nbins = 16.*2.^( float(nbins))
if (strlowcase( data_type) eq 'ffw') then begin
ff1_sel = reform( dh[ *, 13] and 31b)
ff2_sel = reform( dh[ *, 13]/32b + (dh[ *, 12] and 3b)*8b)
ff3_sel = reform( dh[ *, 15] and 31b)
ff4_sel = reform( dh[ *, 15]/32b + (dh[ *, 14] and 3b)*8b)
endif else if (strlowcase( data_type) eq 'ffp') then begin
ff1_sel = reform( dh[ *, 15] and 31b)
ff2_sel = reform( dh[ *, 15]/32b + (dh[ *, 14] and 3b)*8b)
ff3_sel = reform( dh[ *, 13] and 31b)
ff4_sel = reform( dh[ *, 13]/32b + (dh[ *, 12] and 3b)*8b)
endif else begin
endelse
ff_sel_str = [ 'V1', 'V2', 'V3', 'V4', 'V5', 'V6', $
'E12DC', 'E34DC', 'E56DC', $
'SCM1', 'SCM2', 'SCM3', $
'E12AC', 'E34AC', 'E56AC', $
'UNDEF', $
'EXB', 'EDOTB', 'SCMXB', 'SCMDOTB', $
'UNDEF', 'UNDEF', 'UNDEF', 'UNDEF', 'UNDEF', 'UNDEF', $
'UNDEF', 'UNDEF', 'UNDEF', 'UNDEF', 'UNDEF', 'UNDEF' ]
ff1_sel_str = ff_sel_str[ ff1_sel]
ff2_sel_str = ff_sel_str[ ff2_sel]
ff3_sel_str = ff_sel_str[ ff3_sel]
ff4_sel_str = ff_sel_str[ ff4_sel]
hed_data = { data_type:data_type, $
apid:apid, apid_ctr:apid_ctr, app_data_field_len:app_data_field_len, $
clock_bytes:clock_bytes, subsec_bytes:subsec_bytes, $
clock:clock, subsec:subsec, $
compression:compression, $
speed:speed, $
ff1_sel:ff1_sel, ff1_sel_str:ff1_sel_str, $
ff2_sel:ff2_sel, ff2_sel_str:ff2_sel_str, $
ff3_sel:ff3_sel, ff3_sel_str:ff3_sel_str, $
ff4_sel:ff4_sel, ff4_sel_str:ff4_sel_str }
break
end
'fgl':
'fgh': begin
compression = reform( dh[ *, 12]/128b)
fgm_config = reform( dh[ *, 12] and 127b)
fgm_msg = reform( dh[ *, 13])
fgm_range_x = reform( dh[ *, 14]/16b)
fgm_range_y = reform( dh[ *, 14] and 15b)
fgm_range_z = reform( dh[ *, 15]/16b)
fgm_rate = reform( dh[ *, 15] and 7b)
if strlowcase( data_type) eq 'fgh' then $
fgm_rate = bytarr( n_elements( fgm_rate)) + 5b
fgm_rate = 2.^(2+fgm_rate)
hed_data = { data_type:data_type, $
apid:apid, apid_ctr:apid_ctr, app_data_field_len:app_data_field_len, $
clock_bytes:clock_bytes, subsec_bytes:subsec_bytes, $
clock:clock, subsec:subsec, $
compression:compression, $
fgm_config:fgm_config, fgm_msg:fgm_msg, $
fgm_range_x:fgm_range_x, fgm_range_y:fgm_range_y, fgm_range_z:fgm_range_z, $
fgm_rate:fgm_rate }
break
end
else: begin
hed_data = 0
end
endswitch
return, hed_data
end