;+ ; PROCEDURE ; thm_load_pkt ; ; CALLING SEQUENCE ; thm_load_pkt, apid=apid, $ ; pfile=pfile, pick_pkt_file=pick_pkt_file, $ ; pkt_struct=pkt_struct, pkt_data=pkt_data, $ ; tplot_store=tplot_store, calibrate=calibrate, $ ; frac=frac, hdr_only=hdr_only ; ; KEYWORDS ; ; HISTORY ; V. 1.0, John Bonnell, UCBSSL, March-April, 2005. ; -- initial version. ; V. 1.1, John Bonnell, UCBSSL, 19 May 2005. ; -- added 440, 44D, and 44E stub clauses to decom switch. ; -- changed default YSTYLE to 16 on all TPLOT variables. ; -- changed default YTICKFORMAT to Z6.6 on pkt_num TPLOT variable. ; -- made time tag of all 'delta' parameters (dpkt_num, dsubsec), ; the time tag of the leading sample, ; rather than the trailing sample or the average of the two time tags. ; ;- pro thm_load_pkt, apid=apid, $ pfile=pfile, pick_pkt_file=pick_pkt_file, $ pkt_struct=pkt_struct, pkt_data=pkt_data, $ tplot_store=tplot_store, calibrate=calibrate, $ frac=frac, hdr_only=hdr_only, def_pkt_dir=def_pkt_dir, $ daytime=daytime phdr_size = 6 ; primary header size, bytes. pkt_info = { $ apid_404:{ $ expected_apid:'404'X, apid_name:'SOH_404', $ pkt_size:128, hdr_size:16, phdr_size:phdr_size, $ pickfile_filter:'*_404.pkt', pickfile_default:'*_404.pkt' }, $ apid_406:{ $ expected_apid:'406'X, apid_name:'SOH_406', $ pkt_size:128, hdr_size:16, phdr_size:phdr_size, $ pickfile_filter:'*_406.pkt', pickfile_default:'*_406.pkt' }, $ apid_440:{ $ expected_apid:'440'X, apid_name:'FB_SS', $ pkt_size:3600, hdr_size:16, phdr_size:phdr_size, $ fb_source:[ 'V1', 'V2', 'V3', 'V4', 'V5', 'V6', $ 'E12DC', 'E34DC', 'E56DC', $ 'SCM1', 'SCM2', 'SCM3', $ 'E12AC', 'E34AC', 'E56AC' ], $ pickfile_filter:'*_440.pkt', pickfile_default:'*_440.pkt' }, $ apid_441:{ $ n_chan:6, $ chan_labels:[ 'VA1_FS', 'VA2_FS', 'VA3_FS', 'VA4_FS', 'VA5_FS', 'VA6_FS'], $ expected_apid:'441'X, apid_name:'VA_FS', $ pkt_size:3088, hdr_size:16, phdr_size:phdr_size, $ pickfile_filter:'*_441.pkt', pickfile_default:'' }, $ apid_442:{ $ n_chan: 6, $ chan_labels:[ 'VB1_FS', 'VB2_FS', 'VB3_FS', 'VB4_FS', 'VB5_FS', 'VB6_FS'], $ expected_apid:'442'X, apid_name:'VB_FS', $ pkt_size:3088, hdr_size:16, phdr_size:phdr_size, $ pickfile_filter:'*_442.pkt', pickfile_default:'' }, $ apid_443:{ $ n_chan: 6, $ chan_labels:[ 'EDC12_FS', 'EDC34_FS', 'EDC56_FS', 'EAC12_FS', 'EAC34_FS', 'EAC56_FS'], $ expected_apid:'443'X, apid_name:'E_FS', $ pkt_size:3088, hdr_size:16, phdr_size:phdr_size, $ pickfile_filter:'*_443.pkt', pickfile_default:'' }, $ apid_444:{ $ n_chan: 3, $ chan_labels:[ 'SCMZ_FS', 'SCMY_FS', 'SCMX_FS'], $ expected_apid:'444'X, apid_name:'SCM_FS', $ pkt_size:3088, hdr_size:16, phdr_size:phdr_size, $ pickfile_filter:'*_444.pkt', pickfile_default:'' }, $ apid_445:{ $ n_chan: 6, $ chan_labels:[ 'VA1_PB', 'VA2_PB', 'VA3_PB', 'VA4_PB', 'VA5_PB', 'VA6_PB'], $ expected_apid:'445'X, apid_name:'VA_PB', $ pkt_size:3088, hdr_size:16, phdr_size:phdr_size, $ pickfile_filter:'*_445.pkt', pickfile_default:'' }, $ apid_446:{ $ n_chan: 6, $ chan_labels:[ 'VB1_PB', 'VB2_PB', 'VB3_PB', 'VB4_PB', 'VB5_PB', 'VB6_PB'], $ expected_apid:'446'X, apid_name:'VB_PB', $ pkt_size:3088, hdr_size:16, phdr_size:phdr_size, $ pickfile_filter:'*_446.pkt', pickfile_default:'' }, $ apid_447:{ $ n_chan: 6, $ chan_labels:[ 'EDC12_PB', 'EDC34_PB', 'EDC56_PB', 'EAC12_PB', 'EAC34_PB', 'EAC56_PB'], $ expected_apid:'447'X, apid_name:'E_PB', $ pkt_size:3088, hdr_size:16, phdr_size:phdr_size, $ pickfile_filter:'*_447.pkt', pickfile_default:'' }, $ apid_448:{ $ n_chan: 3, $ chan_labels:[ 'SCMZ_PB', 'SCMY_PB', 'SCMX_PB'], $ expected_apid:'448'X, apid_name:'SCM_PB', $ pkt_size:3088, hdr_size:16, phdr_size:phdr_size, $ pickfile_filter:'*_448.pkt', pickfile_default:'' }, $ apid_449:{ $ n_chan: 6, $ chan_labels:[ 'VA1_WB', 'VA2_WB', 'VA3_WB', 'VA4_WB', 'VA5_WB', 'VA6_WB'], $ expected_apid:'449'X, apid_name:'VA_WB', $ pkt_size:3088, hdr_size:16, phdr_size:phdr_size, $ pickfile_filter:'*_449.pkt', pickfile_default:'' }, $ apid_44A:{ $ n_chan: 6, $ chan_labels:[ 'VB1_WB', 'VB2_WB', 'VB3_WB', 'VB4_WB', 'VB5_WB', 'VB6_WB'], $ expected_apid:'44A'X, apid_name:'VB_WB', $ pkt_size:3088, hdr_size:16, phdr_size:phdr_size, $ pickfile_filter:'*_44a.pkt', pickfile_default:'' }, $ apid_44B:{ $ n_chan: 8, $ chan_labels:[ 'EDC12_WB', 'EDC34_WB', 'EDC56_WB', 'EAC12_WB', 'EAC34_WB', 'EAC56_WB', 'EPERP_WB', 'EPARA_WB'], $ expected_apid:'44B'X, apid_name:'E_WB', $ pkt_size:3088, hdr_size:16, phdr_size:phdr_size, $ pickfile_filter:'*_44b.pkt', pickfile_default:'' }, $ apid_44C:{ $ n_chan: 8, $ chan_labels:[ 'SCMX_WB', 'SCMY_WB', 'SCMZ_WB', 'undef1_SCM_WB', 'undef2_SCM_WB', 'undef3_SCM_WB', 'SCMPERP_WB', 'SCMPARA_WB'], $ expected_apid:'44C'X, apid_name:'SCM_WB', $ pkt_size:3088, hdr_size:16, phdr_size:phdr_size, $ pickfile_filter:'*_44c.pkt', pickfile_default:'' }, $ apid_44D:{ $ expected_apid:'44D'X, apid_name:'FFT_PB', $ pkt_size:2064, hdr_size:16, phdr_size:phdr_size, $ fft_source:[ 'V1', 'V2', 'V3', 'V4', 'V5', 'V6', $ 'E12DC', 'E34DC', 'E56DC', $ 'SCM1', 'SCM2', 'SCM3', $ 'E12AC', 'E34AC', 'E56AC', $ 'undef15', $ 'EXB', 'EDOTB', 'SCMXB', 'SCMDOTB', $ 'undef20', 'undef21', 'undef22', 'undef23', 'undef24', 'undef25', 'undef26', $ 'undef27', 'undef28', 'undef29', 'undef30', 'undef31' ], $ pickfile_filter:'*_44d.pkt', pickfile_default:'*_44d.pkt' }, $ apid_44E:{ $ expected_apid:'44E'X, apid_name:'FFT_WB', $ pkt_size:2064, hdr_size:16, phdr_size:phdr_size, $ fft_source:[ 'V1', 'V2', 'V3', 'V4', 'V5', 'V6', $ 'E12DC', 'E34DC', 'E56DC', $ 'SCM1', 'SCM2', 'SCM3', $ 'E12AC', 'E34AC', 'E56AC', $ 'undef15', $ 'EXB', 'EDOTB', 'SCMXB', 'SCMDOTB', $ 'undef20', 'undef21', 'undef22', 'undef23', 'undef24', 'undef25', 'undef26', $ 'undef27', 'undef28', 'undef29', 'undef30', 'undef31' ], $ pickfile_filter:'*_44e.pkt', pickfile_default:'*_44e.pkt' }, $ apid_460:{ $ n_chan: 3, $ chan_labels:[ 'FGMX_TML_NS', 'FGMY_TML_NS', 'FGMZ_TML_NS'], $ expected_apid:'460'X, apid_name:'FGM_TML', $ pkt_size:3088, hdr_size:16, phdr_size:phdr_size, $ pickfile_filter:'*_460.pkt', pickfile_default:'*_460.pkt' }, $ apid_461:{ $ n_chan: 3, $ chan_labels:[ 'FGMX_TMH_NS', 'FGMY_TMH_NS', 'FGMZ_TMH_NS'], $ expected_apid:'461'X, apid_name:'FGM_TMH', $ pkt_size:3088, hdr_size:16, phdr_size:phdr_size, $ pickfile_filter:'*_461.pkt', pickfile_default:'*_461.pkt' } } ;stop pkt_info_tags = strupcase( tag_names( pkt_info)) idx = where( pkt_info_tags eq strupcase( apid), icnt) if icnt eq 1 then begin pinfo = pkt_info.(idx[0L]) endif else begin message, /info, string( apid, format='(A,X,"is not a valid APID identifier.")') stop return endelse verbose = 0b no_pctr = 1b uc_apid = strupcase( apid) if keyword_set( verbose) then $ message, /info, string( uc_apid, format='("selected APID:",X,A,".")') ;message, /info, string( pfile, format='("pfile:",X,A,".")') if keyword_set( pick_pkt_file) then begin pfile = dialog_pickfile( filter=pinfo.pickfile_filter, file=def_pkt_dir+pinfo.pickfile_filter) endif else begin if not keyword_set( pfile) then begin pfile = pinfo.pickfile_default endif endelse if pfile eq '' then begin message, /info, 'No PKT file selected; exiting.' return endif if keyword_set( verbose) then $ message, /info, string( pfile, format='("pfile:",X,A)') if keyword_set( hdr_only) then begin read_pkt_file_hdr_only, $ pick_pkt_file=pick_pkt_file, pfile=pfile, pkt_info=pinfo, $ verbose=verbose endif else begin if uc_apid eq 'APID_404' then begin read_pkt_file_404, $ pfile=pfile, pkt_info=pinfo, $ pkt_struct=pkt_struct, pkt_data=pkt_data, $ verbose=verbose, no_pctr=no_pctr ;,daytime=daytime endif else if uc_apid eq 'APID_406' then begin read_pkt_file_406, $ pfile=pfile, pkt_info=pinfo, $ pkt_struct=pkt_struct, pkt_data=pkt_data, $ verbose=verbose, no_pctr=no_pctr ;,daytime=daytime endif else if uc_apid eq 'APID_460' or uc_apid eq 'APID_461' then begin read_pkt_file_fgm, $ pfile=pfile, pkt_info=pinfo, $ pkt_struct=pkt_struct, pkt_data=pkt_data, ttt=ttt, $ verbose=verbose, no_pctr=no_pctr, frac=frac endif else if uc_apid eq 'APID_440' then begin read_pkt_file_440, $ pfile=pfile, pkt_info=pinfo, $ pkt_struct=pkt_struct, pkt_data=pkt_data, ttt=ttt, $ verbose=verbose, no_pctr=no_pctr endif else if uc_apid eq 'APID_44B' then begin read_pkt_file_44b, $ pfile=pfile, pkt_info=pinfo, $ pkt_struct=pkt_struct, pkt_data=pkt_data, ttt=ttt, $ verbose=verbose, no_pctr=no_pctr, frac=frac endif else if uc_apid eq 'APID_44C' then begin read_pkt_file_44c, $ pfile=pfile, pkt_info=pinfo, $ pkt_struct=pkt_struct, pkt_data=pkt_data, ttt=ttt, $ verbose=verbose, no_pctr=no_pctr, frac=frac endif else if uc_apid eq 'APID_44D' or uc_apid eq 'APID_44E' then begin read_pkt_file_fft, $ pfile=pfile, pkt_info=pinfo, $ pkt_struct=pkt_struct, pkt_data=pkt_data, ttt=ttt, $ verbose=verbose, no_pctr=no_pctr, frac=frac endif else begin read_pkt_file, $ pfile=pfile, pkt_info=pinfo, $ pkt_struct=pkt_struct, pkt_data=pkt_data, ttt=ttt, $ verbose=verbose, no_pctr=no_pctr, frac=frac endelse endelse if keyword_set( tplot_store) then begin if uc_apid eq 'APID_404' or uc_apid eq 'APID_406' then begin pkt_data_tags = strupcase( tag_names( pkt_data)) nitems = n_elements( pkt_data_tags) for i=0L,nitems-1L do begin item_name = string( pinfo.apid_name, strupcase(pkt_data_tags[ i]), $ format='(A,"_",A)') if strmatch( item_name, '*IMON*') or strmatch( item_name, '*IVMON*') or $ strmatch( item_name, '*IGND*') or strmatch( item_name, '*IFGE*') or $ strmatch( item_name, '*IPCB*') or strmatch( item_name, '*IDCB*') or $ strmatch( item_name, '*IEFI_USHER*') or strmatch( item_name, '*IEFI_GUARD*') or $ strmatch( item_name, '*IEFI_BRAID') or $ strmatch( item_name, '*IBEB_TEMP') or strmatch( item_name, '*ISPB_TEMP') or strmatch( item_name, '*IAXB_TEMP') then begin ; message, /info, 'IMON or IVMON conversion. byte_to_signed_int.' dd = byte_to_signed_int( pkt_data.(i)) endif else if strmatch( item_name, '*IEFI_IBIAS*') then begin dd = fix( pkt_data.(i)) endif else begin ; message, /info, 'no conversion.' dd = pkt_data.(i) endelse item_dim = size( dd, /n_dimensions) item_size = size( dd, /dimensions) ; message, /info, string( item_dim, format='("item_dim:", I2.2)') case item_dim of 1: begin ; message, /info, 'switch case 1.' store_data, item_name, $ data={ x:pkt_struct.t_hdr, y:float( reform( dd))}, $ lim={ ytitle:item_name, ystyle:2} end 2: begin ; message, /info, 'switch case 2.' mm = item_size( 0) nn = item_size( 1) line_indices = indgen( nn) if strmatch( item_name, '*MEMDUMP') then begin store_data, item_name, $ data={x:pkt_struct.t_hdr,y:float( dd),v:findgen(16)},$ lim={ ytitle:item_name, ystyle:2},dlim={spec:1,no_inter:1} endif else begin store_data, item_name, $ data={ x:pkt_struct.t_hdr, y:float( dd)}, $ lim={ ytitle:item_name, ystyle:2, $ labflag:1, labels:string( line_indices + 1), colors:( line_indices mod 6 + 1) } endelse end endcase endfor endif else if uc_apid eq 'APID_440' then begin units = 'ADC units' pkt_data_tags = strupcase( tag_names( pkt_data)) nitems = n_elements( pkt_data_tags) for i=0L,nitems-1L do begin item_name = string( pinfo.apid_name, strupcase(pkt_data_tags[ i]), $ format='(A,"_",A)') ytitle= string( item_name, units, format='(A,"!C!C[",A,"]")') dd = pkt_data.(i) item_dim = size( dd, /n_dimensions) item_size = size( dd, /dimensions) line_indices = indgen( item_size( 1)) store_data, item_name, $ data={ x:ttt, y:float( dd)}, $ lim={ ytitle:ytitle, labflag:1, labels:string( line_indices + 1), colors:( line_indices mod 6 + 1)} endfor nfbsrc = n_elements( pinfo.fb_source) item_name = string( pinfo.apid_name, 'FBSEL1', format='(A,"_",A)') store_data, item_name, $ data={ x:pkt_struct.t_hdr, y:float( pkt_struct.fbsel1)}, $ lim={ ytitle:item_name, yrange:[ 0., float( nfbsrc-1L)], ystyle:2, psym:4} item_name = string( pinfo.apid_name, 'FBSEL2', format='(A,"_",A)') store_data, item_name, $ data={ x:pkt_struct.t_hdr, y:float( pkt_struct.fbsel2)}, $ lim={ ytitle:item_name, yrange:[ 0., float( nfbsrc-1L)], ystyle:2, psym:4} endif else if uc_apid eq 'APID_44D' or uc_apid eq 'APID_44E' then begin units = 'ADC units' pkt_data_tags = strupcase( tag_names( pkt_data)) nitems = n_elements( pkt_data_tags) for i=0L,nitems-1L do begin item_name = string( pinfo.apid_name, strupcase(pkt_data_tags[ i]), $ format='(A,"_",A)') ytitle= string( item_name, units, format='(A,"!C!C[",A,"]")') dd = pkt_data.(i) ;item_dim = size( dd, /n_dimensions) ;item_size = size( dd, /dimensions) ;line_indices = indgen( item_size( 1)) store_data, item_name, $ data={ x:ttt, y:float( dd), v:findgen(64)}, $ lim={ ytitle:ytitle, spec:1, $ x_no_interp:1, $ yrange:[ 0., 63.], ystyle:1, y_no_interp:1, $ zrange:[ 0., 255.], zlog:0 } endfor nfftsrc = n_elements( pinfo.fft_source) item_name = string( pinfo.apid_name, 'FFTSEL1', format='(A,"_",A)') store_data, item_name, $ data={ x:pkt_struct.t_hdr, y:float( pkt_struct.fftsel1)}, $ lim={ ytitle:item_name, yrange:[ 0., float( nfftsrc-1L)], ystyle:2, psym:4} item_name = string( pinfo.apid_name, 'FFTSEL2', format='(A,"_",A)') store_data, item_name, $ data={ x:pkt_struct.t_hdr, y:float( pkt_struct.fftsel1)}, $ lim={ ytitle:item_name, yrange:[ 0., float( nfftsrc-1L)], ystyle:2, psym:4} item_name = string( pinfo.apid_name, 'FFTSEL3', format='(A,"_",A)') store_data, item_name, $ data={ x:pkt_struct.t_hdr, y:float( pkt_struct.fftsel1)}, $ lim={ ytitle:item_name, yrange:[ 0., float( nfftsrc-1L)], ystyle:2, psym:4} item_name = string( pinfo.apid_name, 'FFTSEL4', format='(A,"_",A)') store_data, item_name, $ data={ x:pkt_struct.t_hdr, y:float( pkt_struct.fftsel1)}, $ lim={ ytitle:item_name, yrange:[ 0., float( nfftsrc-1L)], ystyle:2, psym:4} item_name = string( pinfo.apid_name, 'BINS_PER_SPEC', format='(A,"_",A)') store_data, item_name, $ data={ x:pkt_struct.t_hdr, y:float( pkt_struct.bins_per_spec)}, $ lim={ ytitle:item_name, yrange:[ 0., 64.], ystyle:2, psym:4} item_name = string( pinfo.apid_name, 'SAMP_RATE', format='(A,"_",A)') store_data, item_name, $ data={ x:pkt_struct.t_hdr, y:float( pkt_struct.samp_rate)}, $ lim={ ytitle:item_name, yrange:[ 1./16., 8.], ystyle:2, ylog:1, psym:4} item_name = string( pinfo.apid_name, 'DER_E_OFF_SEL', format='(A,"_",A)') store_data, item_name, $ data={ x:pkt_struct.t_hdr, y:float( pkt_struct.der_e_off_sel)}, $ lim={ ytitle:item_name, yrange:[ 0., 1.0], ystyle:2, psym:4} item_name = string( pinfo.apid_name, 'DER_E_ACDC_SEL', format='(A,"_",A)') store_data, item_name, $ data={ x:pkt_struct.t_hdr, y:float( pkt_struct.der_e_acdc_sel)}, $ lim={ ytitle:item_name, yrange:[ 0., 1.0], ystyle:2, psym:4} endif else begin ; 441 through 44C, 460 through 461. units = 'ADC units' for i=0L,pinfo.n_chan-1L do begin cl = pinfo.chan_labels[ i] store_data, cl, $ data={ x:ttt, y:float( reform( pkt_data[ i, *]))}, $ lim={ ytitle:string( cl, units, format='(A,"!C!C[",A,"]")'), $ ystyle:16 } endfor dtt = ttt[ 1:*] - ttt[ 0:*] store_data, string( strupcase( apid), 'samp_dt', format='(A,"-",A)'), $ data={ x:ttt[ 0L:n_elements( dtt)-1L], y:dtt}, $ lim={ ytitle:string( strupcase( apid), 'samp_dt', format='(A,"!C!C[",A,"]")'), $ psym:-4, ystyle:16 } endelse store_data, string( strupcase( apid), 'file_pkt_idx', format='(A,"-",A)'), $ data={ x:pkt_struct.t_hdr, y:dindgen( n_elements( pkt_struct.t_hdr))}, $ lim={ ytitle:string( strupcase( apid), 'file_pkt_idx', format='(A,"!C!C[",A,"]")'), $ psym:-4, ystyle:16, ytickformat:'(I6.6)' } store_data, string( strupcase( apid), 'pkt_num', format='(A,"-",A)'), $ data={ x:pkt_struct.t_hdr, y:pkt_struct.pkt_num}, $ lim={ ytitle:string( strupcase( apid), 'pkt_num', format='(A,"!C!C[",A,"]")'), $ psym:-4, ystyle:16, ytickformat:'(Z6.6)' } pn = pkt_struct.pkt_num npn = n_elements( pn) dpn = float(pn[ 1:*]) - float(pn[ 0:*]) store_data, string( strupcase( apid), 'dpkt_num', format='(A,"-",A)'), $ data={ x:pkt_struct.t_hdr[0:npn-1L], y:dpn}, $ lim={ ytitle:string( strupcase( apid), 'dpkt_num', format='(A,"!C!C[",A,"]")'), $ psym:4, ystyle:16 } store_data, string( strupcase( apid), 'subsec', format='(A,"-",A)'), $ data={ x:pkt_struct.t_hdr, y:pkt_struct.subsec}, $ lim={ ytitle:string( strupcase( apid), 'subsec', format='(A,"!C!C[",A,"]")'), $ psym:-4, ystyle:16 } ss = long( pkt_struct.subsec) dss = ss[ 1:*] - ss[ 0:*] t_hdr = pkt_struct.t_hdr store_data, string( strupcase( apid), 'dsubsec', format='(A,"-",A)'), $ data={ x:t_hdr[ 0L:n_elements( dss)-1L], y:dss}, $ lim={ ytitle:string( strupcase( apid), 'dsubsec', format='(A,"!C!C[",A,"]")'), $ psym:-4, ystyle:16 } endif return end