;+ ; NAME: ; TimeUnit ; PURPOSE: ; Provides information about time units used in time structures ; CATEGORY: ; Tell time ; CALLING SEQUENCE: FUNCTION TimeUnit, tunit, $ nextup = nextup , $ mmsec = mmsec , $ all = all , $ years = years , $ yrs = yrs , $ days = days , $ hours = hours , $ hrs = hrs , $ minutes = minutes , $ seconds = seconds , $ mseconds= mseconds ; T = TimeUnit( [/all,/years,/days,/hours,/minutes,/seconds,/mseconds]) ; T = TimeUnit(/NextUp,[/all,/years,/days,/hours,/minutes,/seconds,/mseconds]) ; T = TimeUnit(/msec ,[/all,/years,/days,/hours,/minutes,/seconds,/mseconds]) ; INPUTS: ; tunit scalar; type: integer ; if tunit exist the corresponding name for the unit of time ; is returned (tag name of time structure, i.e. Y,M,D,H,M,S,MS) ; OPTIONAL INPUT PARAMETERS: ; /years,/days,/hours,/minutes,/seconds,/mseconds ; sets time unit for which information is needed (set only one at a time) ; /all returns information for all time units ; If /all is not set and no time unit keyword is set, then /day is assumed ; ; /nextup return the number of units in the next larger time unit ; e.g. if /hours is set the value is 24 (24 hours in a day) ; /mmsec returns number of mseconds (smallest time unit) in time unit ; e.g. if /hours is set the value is 60*60*100=3600000 ; ; If neither /nextup nor /mmsec is set the position of the time unit tag in the ; structure is returned. ; OUTPUTS: ; T scalar, if one of the time unit keywords is set. ; array[7] if /all is set ; The array is a long integer array if tag numbers are returned; ; or double precision if /nextup or /mmsec are used ; INCLUDE: @compile_opt.pro ; On error, return to caller ; CALLS: ; InitVar, IsType ; PROCEDURE: ; MODIFICATION HISTORY: ; SEP-1998, Paul Hick (UCSD/CASS) ; OCT-1998, Paul Hick (UCSD/CASS; pphick@ucsd.edu) ; Added tunit argument ;- IF IsType(yrs, /defined) THEN years = yrs IF IsType(hrs, /defined) THEN hours = hrs InitVar, all , /key InitVar, mmsec , /key InitVar, nextup , /key T = ['Y','D','H','M','S','MS'] IF IsType(tunit, /defined) THEN RETURN, T[tunit] unit = [keyword_set(years ) , $ keyword_set(days ) , $ keyword_set(hours ) , $ keyword_set(minutes ) , $ keyword_set(seconds ) , $ keyword_set(mseconds) ] CASE total(unit) OF 0: unit = 1 ; Default time unit is days 1: unit = (where(unit EQ 1))[0] ELSE: message, 'Set only one of the keywords Years,Days,Hours,Minutes,Seconds,mSeconds' ENDCASE Next = [0.0d0,365.25d0,24.0d0,60.0d0,60.0d0,1000.0d0] MS = 1+0*Next FOR I=n_elements(MS)-2,0,-1 DO $ FOR J=n_elements(MS)-1,I+1,-1 DO MS[I] = MS[I]*Next[J] ; # mseconds in unit T = [where(T EQ 'Y'),where(T EQ 'D'),where(T EQ 'H'),where(T EQ 'M'),where(T EQ 'S'),where(T EQ 'MS')] Next = Next[T] ; Sort units according to positions in structure MS = MS [T] unit = T[unit] CASE 1 OF nextup: begin CASE all OF 0: RETURN, Next[unit] ; # units in next larger time unit 1: RETURN, Next ENDCASE END mmsec: BEGIN CASE all OF 0: RETURN, MS[unit] ; # units in next larger time unit 1: RETURN, MS ENDCASE END ELSE: BEGIN CASE all OF 0: RETURN, unit ; Tag # for time unit 1: RETURN, T ; Tag # for year,day,hour, ... ENDCASE END ENDCASE END