;------------------------------------------------------- ;Title: acse_readkongs.pro ;Purpose: Program to read support data for Kongsberg ; ;Input: sarg: date/time string, YYYYMMDDHH ; earg: data/time string, YYYYMMDDHH ;Output: time: radar time axis, decimal hours ; pitch: pitch of the radar antenna (deg) ; roll: roll of the radar antenna (deg) ; vel: vertical velocity of the radar antenna (m/s????) ; ;Keywords: directory: directory containing the data ; default is current working directory ; factor: factor by which to reduce data frequency ; jtime: time in decimal year day ;Author: Matthew Shupe ;Date: 7/7/2014 ;------------------------------------------------------- pro acse_readkongs,sarg,earg,time,pitch,roll,vel,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_readkongs: 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 Kongsberg files ;------------------------------------ time=dblarr(numa*24L*60*60*11.)*0-999. pitch=fltarr(numa*24L*60*60*11.)*0-999. roll=fltarr(numa*24L*60*60*11.)*0-999. vel=fltarr(numa*24L*60*60*11.)*0-999. velcomp=fltarr(numa*24L*60*60*11.)*0-999. jnk=' ' st1=strarr(6) st3=strarr(3) ind=0L for d=0,numa-1 do begin farg=darg[d]+'*Kongsberg*' 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 st1=strsplit(jnk,' ',/extract) st3=strsplit(st1[1],':',/extract) time[ind]=double(st3[0])+double(st3[1])/60.+double(st3[2])/3600.+d*24.0 pitch[ind]=st1[2]*180./!pi ;in deg roll[ind]=st1[3]*180./!pi ;in deg vel[ind]=st1[4] ;in m/s velcomp[ind]=st1[5] ;in m/s 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] vel=vel[0:ind-1] velcomp=velcomp[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] vel=vel[wh] velcomp=velcomp[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] vel=vel[wh] velcomp=velcomp[wh] time=time[wh] endif endif else begin time=findgen(1440)/1440*24. pitch=time*0-999. roll=pitch vel=pitch velcomp=pitch endelse ;compute julian time jtime=floor(sjd)+time/24.0 if keyword_set(directory) then cd,orig_dir end ;prog