function mav_idpu_apid_packet_read,fp,time=time,unit=unit,verbose=verbose
fst = fstat(fp)
swrd = 0u
readu,fp,swrd
byteorder,swrd, /swap_if_little_endian
cntr = 0u
len = 0u
valid = 0
ccsds = uintarr(3)
buffer = 0u
tstr = 'Bad Sync'
if swrd eq '0830'x then begin
readu,fp,cntr,len
byteorder,cntr,len, /swap_if_little_endian
buffer = uintarr((len+1)/2 -3)
readu,fp,ccsds,buffer
byteorder,ccsds,buffer, /swap_if_little_endian
time = ccsds[0] * 2ul^16 +ccsds[1] + ccsds[2]/2d^16 + 978307200
valid = 1
tstr = time_string(time,prec=3)
dprint,unit=unit,verbose=verbose, dlevel=2,tstr,swrd,cntr,len,buffer, format='(" ",a-24," | ",3(" ",Z04),360Z5)'
endif else begin
buffer=0
dprint,unit=unit,verbose=verbose, dlevel=0,tstr,swrd, format='(" ",a-24," | ",Z6)'
endelse
pkt = {ccsds:ccsds,ctype:'c3'x, time:time, sync: swrd, cntr:cntr, length:len, buffer:buffer ,valid:valid}
return,pkt
end
pro mav_sep_dap_idpu_apid_30_load,realtime=realtime
if n_elements(realtime) ne 1 then realtime=0
if keyword_set(realtime) then pathnames = 'localhost'
if not keyword_set(realtime) then begin
source = mav_file_source()
pathnames = 0
append_array,pathnames, 'maven/sep/prelaunch_tests/EM1/20110411_154637_sep_EMIT/ipudpsci.dat
append_array,pathnames, 'maven/sep/prelaunch_tests/EM1/20110411_160348_SEP_EMIT/ipudpsci.dat'
append_array,pathnames, 'maven/sep/prelaunch_tests/EM1/20110411_161754_sep_EMIT_HP/ipudpsci.dat'
pathnames = 0
append_array,pathnames, 'maven/sep/prelaunch_tests/EM1/20110411_154637_sep_EMIT/rawtcp_buf.dat'
pathnames = 0
append_array,pathnames, 'maven/sep/testdir/20110816_184549_emit/decMISGFile.dat'
files = file_retrieve(pathnames,_extra= source)
endif else begin
dir = ''
files = file_search( dir+'APID30_*.dat' )
files = files[n_elements(files)-1]
endelse
dir = file_dirname(files[0])
printdat,dir
file_open,'w','e:/temp/ipudpsci_out.txt',unit=u
c0=0
c1=0
c2=0
c3=0
time=0d
for fn = 0,n_elements(files)-1 do begin
file = files[fn]
dprint,dlevel=1,'FILE: ',file
dprint,unit=u,dlevel=2,'File: ',file
fi= file_info(file)
if fi.exists then file_open,'r',file,unit=fp else continue
brk = 0
while not eof(fp) and not brk do begin
pkt = mav_idpu_apid_packet_read(fp,time=time,unit=u)
if keyword_set(pkt) eq 0 then break
tstr = ''
dprint,dlevel=1,dwait=5,'Collecting Data ',time_string(pkt.time),break_requested=brk
if keyword_set(brk) then stop
case pkt.ctype of
0 : begin
c = c0++
tstr = '0 SYNC ERR '+time_string(systime(1),tformat='hh:mm:ss.fff')
end
'C1'x: begin
c= c1++
status = mav_misg_status_decom(pkt)
mav_gse_structure_append ,status_ptrs, status
time = status.time
tstr = time_string(status.time,prec=3)
end
'C2'x: begin
c = c2++
end
'C3'x: begin
c = c3++
dl = 3
msg = mav_inst_message(pkt,/allow_pad)
if (msg.valid eq 0) then tstr='Invalid Message' else tstr = ''
if keyword_set(tstr) then dl =1
id0 = 0
id0 = msg.id and '111011'b
case id0 of
'08'x: dprint,unit=u,dlevel=1,msg.length,'Event'
'09'x: dprint,unit=u,dlevel=1,msg.length,'Unused'
'18'x: begin
mav_misg_message_proc,msg,science_ptrs,defsize=256
end
'19'x: begin
sephkp = mav_sep_hkp_decom(msg,last=sephkp)
mav_gse_structure_append ,sephkp_ptrs, sephkp
end
'1a'x: begin
mav_misg_message_proc,msg,noise_ptrs,defsize=60
end
'1b'x: dprint,unit=u,dlevel=1,msg.length,'MemDump'
else:
endcase
end
endcase
endwhile
free_lun,fp
endfor
if 1 then begin
if keyword_set(noise_ptrs) then begin
noisename = 'MAVEN_SEP_NOISE'
mav_misg_message_proc,0, noise_ptrs ,tname = noisename
get_data,noisename,ptr=ptr
*ptr.y = *ptr.y - shift( *ptr.y, [1,0] )
dt = shift(*ptr.x,-1) - shift( *ptr.x, 1)
w = where( abs(dt) gt 2.5)
(*ptr.y)[w,*] = 0
*ptr.v += 0.5
mav_misg_message_proc,0,science_ptrs ,tname = 'MAVEN_SEP_SCIENCE'
endif
endif
mav_gse_structure_append ,status_ptrs, tname='STATUS'
mav_gse_structure_append ,sephkp_ptrs, tname='SEPHKP'
if keyword_set(u) then free_lun,u
if keyword_set(realtime) then tlimit,systime(1)+ [-500,0]
end
mav_sep_dap_idpu_apid_30_load,realtime=realtime
end