;+ ; Project : HESSI ; ; Name : NEAR_TIME ; ; Purpose : Find index of time array nearest input time ; ; Category : time, utility ; ; Syntax : IDL> chk=near_time(times,itime) ; ; Inputs : TIMES = time array to search ; ITIME = time value to search on ; ; Outputs : INDEX = index of nearest time element ; ; History : Written, 1-Dec-2003, Zarro (L-3Com/GSFC) ; ; Contact : dzarro@solar.stanford.edu ;- function near_time,times,itime index=-1 if (not exist(times)) or (not exist(itime)) then return,index ;-- convert to double if string or structure format err='' dtime=itime if is_string(itime) or is_struct(itime) then begin dtime=anytim2tai(itime,err=err) if is_string(err) then begin message,err,/cont return,index endif endif if is_string(times[0]) or is_struct(times[0]) then begin diff=min(abs(anytim2tai(times,err=err)-dtime),index) if is_string(err) then begin message,err,/cont return,index endif endif else diff=min(abs(times-itime),index) return,index end