pro findtime,time,lun,rec_len,num_recs,rec ;=================================================================== ; ; By S Mayor in June 1995 ; Uses binary search algorithm from Press et al to ; locate reduced DIAL record given user-supplied time-string ; ; INPUT: ; time...... user-supplied string containing time (hh:mm or hh:mm:ss) ; lun....... logical unit number ; rec_len... record length ; num_recs.. number of records in the file ; ; OUTPUT: ; rec....... record number of dt ; ; INTERNAL: ; dt........ date/time structure to search for ; xsec ..... seconds to search for (corresponding to dt) ; ; Finds the closest record number to a time (dt) ; First, convert dt to number of seconds past a ; certain time/date ; ; Convert user-supplied time into PV-WAVE dt-structure ; then convert the dt-structure into number of seconds ; past certain time/date ; ; Get the month, day and year from the first record in the file record = assoc(lun,fltarr(rec_len)) z=record(0) first_header = z(0:29) byteswap = 0b if (first_header(11) lt 1) then byteswap = 1b if (byteswap) then byteorder,first_header,/Lswap yy=first_header(13) mm=first_header(11) dd=first_header(12) ; get the hour, minute and second from the user supplied time hh=strmid(time,0,2) mn=strmid(time,3,2) if (strlen(time) gt 5) then begin ss=strmid(time,6,2) endif else begin ss=0. endelse ;print,'findtime = ',yy,mm,dd,' ',hh,':',mn,':',ss dt = var_to_dt(yy,mm,dd,hh,mn,ss) xsec=dt_to_sec(dt) jl=0L ju=num_recs-1L entry: if (ju-jl gt 1) then begin jm = (ju + jl)/2 z=record(jm) if (byteswap) then byteorder,z,/Lswap yy=z(13) mm=z(11) dd=z(12) hh=z(0) mn=z(1) ss=z(2) dt = var_to_dt(yy,mm,dd,hh,mn,ss) sec=dt_to_sec(dt) if (sec lt xsec) then begin jl = jm endif else begin ju = jm endelse goto,entry endif rec=jm return end