;+ ; Project : SOHO - CDS ; ; Name : ANYTIM2TAI() ; ; Purpose : Converts any standard CDS time format to TAI. ; ; Explanation : Tests the type of input and tries to use the appropriate ; conversion routine to create the date/time in CDS TAI ; time format. ; ; Use : IDL> tai = anytim2tai(any_format) ; ; Inputs : any_format - date/time in any of the acceptable CDS ; time formats -- for acceptable formats see file ; aaareadme.txt. ; ; Opt. Inputs : None ; ; Outputs : Function returns CDS TAI double precision time value. ; ; Opt. Outputs: None ; ; Keywords : ERRMSG = If defined and passed, then any error messages ; will be returned to the user in this parameter ; rather than being printed to the screen. If no ; errors are encountered, then a null string is ; returned. In order to use this feature, the ; string ERRMSG must be defined first, e.g., ; ; ERRMSG = '' ; TAI = ANYTIM2TAI ( DT, ERRMSG=ERRMSG, ...) ; IF ERRMSG NE '' THEN ... ; ; Calls : DATATYPE, INT2UTC, STR2UTC ; ; Common : None ; ; Restrictions: None ; ; Side effects: None ; ; Category : Util, time ; ; Prev. Hist. : Based on ANYTIM2UTC by C. D. Pike. ; ; Written : William Thompson, GSFC, 20 May 1996 ; ; Modified : Version 1, William Thompson, GSFC, 20 May 1996 ; Version 2, 05-Oct-1999, William Thompson, GSFC ; Add support for Yohkoh 7-element external time. ; Version 3, 31-Jul-2001, William Thompson, GSFC ; Changed MESSAGE to MESSAGE, /CONTINUE ; Version 4, 16-Feb-2004, CDP. Added /quiet keyword because it was ; already required in the code. ; Version 5, 08-Sep-2004, William Thompson, GSFC ; Added keyword NOCORRECT ; ; Version : Version 4, 16-Feb-2004 ;- function anytim2tai, dt, errmsg=errmsg, nocorrect=nocorrect, quiet=quiet ; ; set default return value ; tai = 0.0D0 on_error, 2 ; Return to the caller of this procedure if error occurs. message='' ; Error message returned via ERRMSG if error is encountered. ; ; see if any parameters were passed ; if n_params() eq 0 then begin message = 'Syntax: TAI = ANYTIM2TAI(DATE-TIME)' goto, handle_error endif ; ; determine type of input ; type = datatype(dt,1) ; ; see if the input is an array ; np = n_elements(dt) if np gt 1 then tai = replicate(tai, np) ; ; act accordingly ; case type of 'Double': tai = dt else: begin message='' tai = utc2tai(dt,nocorrect=nocorrect,errmsg=message) ; ; If UTC2TAI returned an error message, then maybe the result is in ; seven-element Yohkoh external format, with the elements ; ; [HOUR, MINUTE, SECOND, MILLISECOND, DAY, MONTH, YEAR] ; sz = size(dt) if (message ne '') and (sz(0) gt 0) and (sz(1) eq 7) then begin if not keyword_set(quiet) then message, /info, $ 'Assuming Yohkoh 7-element external time' utc = {cds_ext_time, $ year: 0, $ month: 0, $ day: 0, $ hour: 0, $ minute: 0, $ second: 0, $ millisecond: 0} n_dates = n_elements(dt) / 7 if sz(0) gt 1 then begin utc = replicate(utc, n_dates) utc = reform(utc,sz(2:sz(0)),/overwrite) endif temp = reform(dt,7,n_dates) year = reform(temp(6,*)) w = where(year lt 50, count) if count gt 0 then year(w) = year(w) + 2000 w = where(year lt 100, count) if count gt 0 then year(w) = year(w) + 1900 utc(*).year = year utc(*).month = reform(temp(5,*)) utc(*).day = reform(temp(4,*)) utc(*).hour = reform(temp(0,*)) utc(*).minute = reform(temp(1,*)) utc(*).second = reform(temp(2,*)) utc(*).millisecond = reform(temp(3,*)) message = '' tai = utc2tai(utc,errmsg=message) endif end endcase if message eq '' then goto, finish ; ; Error handling point. ; handle_error: if n_elements(errmsg) eq 0 then message, message, /continue errmsg = message ; finish: return, tai end