FUNCTION TimeRound, dT, Unit ;+ ; NAME: ; TimeRound ; PURPOSE: ; Find rounded values bracketing the specified time range ; CATEGORY: ; Tell time ; CALLING SEQUENCE: ; R = TimeRound(dT,Unit) ; INPUTS: ; dT array; type: integer or float ; times (in unit of 'Unit') ; Unit array; type: integer ; determines the time units of dT ; (set by TimeUnit) ; OUTPUTS: ; R array[2]; type: float ; two times bracketing dT (in units of 'Unit') ; INCLUDE: @compile_opt.pro ; On error, return to caller ; PROCEDURE: ; Tricky and imperfect ; MODIFICATION HISTORY: ; ???-????, Paul Hick (pphick@ucsd.edu) ;- ; Conversion factor from time units to seconds A = ([365.25d0*86400d0,86400d0,3600d0,60d0,1d0,0.001d0])[Unit] ; Allowed rounded intervals in seconds D = [.001,.01,.1,1,2,5,10,30,60*[1,2,5,10,30],3600d0*[1,5,12],86400d0*[1,2,5]] D = D/A ; Allowed rounded intervals in time units A = max(dT)-min(dT) ; Real interval width A = where(D LT A/20.) ; Find rounded intervals less than (1/20) of real interval ; If there is none, take smallest rounded interval D = D[ (A[0] NE -1)*A[n_elements(A)-1] ] ; .. else take the largest of them RETURN, [floor(min(dT)/D),ceil(max(dT)/D)]*D END