;------------------------------------------------------- ;Title: acse_readcross.pro ;Purpose: Program to read WBAND crossbow ; ;Input: sarg: date/time string, YYYYMMDDHH ; earg: data/time string, YYYYMMDDHH ;Output: time: radar time axis, decimal hours ; pitch: pitch of the ship (deg) ; roll: roll of the ship (deg) ; zacc: vertical acceleration of the ship (m/s2) ;Keywords: directory: directory containing the data ; default is current working directory ; factor: factor by which to decrease data frequency ; jtime: Time in decimal year day ;Author: Matthew Shupe ;Date: 7/7/2014 ;------------------------------------------------------- pro acse_readcross,sarg,earg,time,pitch,roll,zacc,directory=directory,factor=factor,jtime=jtime if keyword_set(directory) then cd,directory,current=orig_dir base_date=julday(1,1,1970,0,0,0) base=jul_to_dt(base_date) !dt_base=base ;---------------------------------- ;Determine a list of files to read ;---------------------------------- sjd=julday(strmid(sarg,4,2),strmid(sarg,6,2),strmid(sarg,0,4))-julday(1,1,strmid(sarg,0,4))+1 if strmid(sarg,6,2) ne strmid(earg,6,2) then begin ejd=julday(strmid(earg,4,2),strmid(earg,6,2),strmid(earg,0,4))-julday(1,1,strmid(earg,0,4))+1 if ejd lt sjd then begin print,'acse_readcross: cannot go across a new year.' stop endif numa=ejd-sjd+1 darg=strarr(numa) for i=0,numa-1 do begin darg[i]=strmid(sarg,0,4)+strtrim(sjd+i,2) endfor endif else begin darg=strmid(sarg,0,4)+strtrim(sjd,2) numa=n_elements(darg) endelse ;------------------------------------ ;Read in the daily Crossbow files ;------------------------------------ time=dblarr(numa*24L*60*60*21.)*0-999. pitch=fltarr(numa*24L*60*60*21.)*0-999. roll=fltarr(numa*24L*60*60*21.)*0-999. zacc=fltarr(numa*24L*60*60*21.)*0-999. jnk=' ' st2=strarr(9) st3=strarr(3) ind=0L for d=0,numa-1 do begin farg=darg[d]+'*Crossbow*' file=findfile(farg,count=numf) file=file[sort(long(strmid(file,0,11)))] for f=0,numf-1 do begin print,"Reading ",file[f] openr,lun,/get_lun,file[f] for i=0,3 do readf,lun,jnk while not eof(lun) do begin readf,lun,jnk st2=strsplit(jnk,' ',/extract) st3=strsplit(st2[1],':',/extract) time[ind]=double(st3[0])+double(st3[1])/60.+double(st3[2])/3600.+d*24.0 pitch[ind]=st2[3]*180./(2^15.) ;converts to deg roll[ind]=st2[2]*180./(2^15.) ;converts to deg zacc[ind]=st2[8]*(2.0*1.5)/(2^15.) ;converts m/s2 ;****note: if the angular rates are added their convertion factor is 150./(2^15.)..... i.e., 150 not 180. ind=ind+1 endwhile free_lun,lun endfor endfor if ind gt 0 then begin time=time[0:ind-1] pitch=pitch[0:ind-1] roll=roll[0:ind-1] zacc=zacc[0:ind-1] ;Trim data to the hour range requested shr=fix(strmid(sarg,8,2)) ehr=fix(strmid(earg,8,2)) wh=where(time ge shr and time le ehr+24.0*(numa-1),nm) if nm gt 0 then begin time=time[wh] pitch=pitch[wh] roll=roll[wh] zacc=zacc[wh] endif ;Cut down the data rate by a specified factor ;---------------------------------------------- if keyword_set(factor) then begin numt=n_elements(time) wh=lindgen(numt/factor)*factor pitch=pitch[wh] roll=roll[wh] zacc=zacc[wh] time=time[wh] endif endif else begin time=findgen(1440)/1440*24. pitch=time*0-999. roll=pitch zacc=pitch endelse ;compute julian time jtime=floor(sjd)+time/24.0 if keyword_set(directory) then cd,orig_dir end ;prog