C$Procedure ISO2ET_M ( Convert ISO time strings to ET ) SUBROUTINE ISO2ET_M ( TSTRNG, ET ) C$ Abstract C C This routine converts date-time strings represented in C the format adopted by the International Standards Organization C (ISO) to equivalent epochs represented as ephemeris seconds past C J2000 Barycentric Dynamical Time (TDB). C C$ Required_Reading C C Time C C$ Keywords C C TIME C C$ Declarations CHARACTER*(*) TSTRNG DOUBLE PRECISION ET C$ Brief_I/O C C Variable I/O Description C -------- --- -------------------------------------------------- C TSTRNG I String representing a calendar or julian date epoch C ET O Ephemeris time (TDB) corresponding to TSTRNG C C$ Detailed_Input C C TSTRNG is an input time string, containing a time string C in ISO format. This routine is not sensitive to C the case of the characters that make up TSTRNG. C Thus 1992-192t12:29:28 and 1992-192T12:29:28 C are equivalent. C C The ISO standard time formats are: C C Year Month Day yyyy-mm-ddThh:mm:ss[.sss...] C yyyy-mm-dd C C Day of Year yyyy-dddThh:mm:ss[.sss...] C yyyy-ddd C C The letters y,m,d,h,m,s can stand for any digit. C All digits are required in these formats. Moreover C the year portion of these strings must be between C 1000 and 2999 inclusive. C C The length of TSTRNG should not exceed 80 characters. C C We point out that the format yyyy-ddd may be C interpreted very differently by routine UTC2ET. C 1992-003 is interpreted by UTC2ET as March 1, 1992 C whereas it is interpret as January 3, 1992 by ISO2ET. C C User's should be aware of these differences in C interpretation and exercise adequate care in their C programs to avoid this possible confusion. C C$ Detailed_Output C C ET is the equivalent of TSTRNG, expressed in ephemeris C seconds past J2000 (TDB). If an error occurs, or if C the input string is ambiguous, ET is not changed. C C$ Parameters C C None. C C$ Exceptions C C 1) If the string is interpreted as an ISO format string and C the year portion is not within the range [1000, 2999] the C error SPICE(YEAROUTOFBOUNDS) is signalled. ET is not changed. C C 2) If the string does not clearly match the ISO format C the error SPICE(NOTISOFORMAT) is signalled. ET is not changed. C C 2) Other parse errors are diagnosed by routines in the call C tree of ISO2ET_M. C C 3) If a leapseconds kernel has not been load into the kernel C pool, the error will be diagnosed by a routine in the C call tree of this routine. C C$ Files C C None. C C$ Particulars C C The input string is first converted to UTC seconds past J2000, C and the appropriate number of leap seconds are added to give C ephemeris seconds past J2000. C C$ Examples C C To convert the time string 1992-04-03T14:12:28 to the C corresponding ephemeris time, execute the following instructions: C C TSTRNG = '1992-04-03T14:12:28' C C CALL ISO2ET_M ( TSTRNG, ET ) C C$ Restrictions C C The conversion between ET and UTC depends on the values in the C input kernel pool. The kernel pool should be loaded prior to C calling this routine. See the required reading TIME for more C information. C C$ Literature_References C C Jesperson and Fitz-Randolph, From Sundials to Atomic Clocks, C Dover Publications, New York, 1977. C C Software Interface Specification: SFOC-2-SYS-Any-TimeForms C prepared by D. Wagner, Revision Date: Feb 6, 1990. C Document Identifier SFOC0038-01-09-03 (NAIF Document 268.00) C C$ Author_and_Institution C C W.L. Taber (JPL) C C$ Version C C- SPICELIB Version 1.0.0, 3-APR-1992 (WLT) C C-& C$ Index_Entries C C C Transform ISO time strings to ephemeris time TDB C Transform a time string to ephemeris time TDB C C-& C C SPICELIB functions C INTEGER BSRCHC INTEGER RTRIM LOGICAL RETURN C C Local Parameters C INTEGER NMNTHS PARAMETER ( NMNTHS = 12 ) C C In-line functions. C LOGICAL DIGIT LOGICAL COLON LOGICAL HYPHEN LOGICAL T C C Local Variables C CHARACTER*(128) ASCII CHARACTER*(128) MYSTR CHARACTER*(3) MONTHS ( 0 : NMNTHS ) SAVE MONTHS CHARACTER*(2) IMONTH ( NMNTHS ) SAVE IMONTH INTEGER I INTEGER L INTEGER M LOGICAL CHANGE C C Initial Values C DATA MONTHS / '???', 'JAN', 'FEB', 'MAR', . 'APR', 'MAY', 'JUN', . 'JUL', 'AUG', 'SEP', . 'OCT', 'NOV', 'DEC' / DATA IMONTH / '01', '02', '03', . '04', '05', '06', . '07', '08', '09', . '10', '11', '12' / C C In-line Function Definitions C DIGIT(I) = ICHAR(ASCII(I:I)) .GE. ICHAR('0') . .AND. ICHAR(ASCII(I:I)) .LE. ICHAR('9') HYPHEN(I) = ASCII(I:I) .EQ. '-' COLON(I) = ASCII(I:I) .EQ. ':' T(I) = ASCII(I:I) .EQ. 'T' .OR. ASCII(I:I) .EQ. 't' C C Standard SPICELIB exception handling C IF ( RETURN() ) THEN RETURN ELSE CALL CHKIN ( 'ISO2ET_M' ) END IF C C Left justify the input time string, and determine the location of C it's last non-blank character. Finally make some local copies. C CALL LJUST ( TSTRNG, ASCII ) L = RTRIM ( ASCII ) MYSTR = ASCII CHANGE = .FALSE. C C Next check for one of the ISO allowed formats. C IF ( L .EQ. 8 ) THEN C C The possible format is: yyyy-ddd. If we get a C match construct the corresponding SPICE day of C year format using JAN (e.g. 1991-JAN-261). C IF ( DIGIT (1) . .AND. DIGIT (2) . .AND. DIGIT (3) . .AND. DIGIT (4) . .AND. HYPHEN (5) . .AND. DIGIT (6) . .AND. DIGIT (7) . .AND. DIGIT (8) ) THEN MYSTR = ASCII(1:5) // 'JAN' // ASCII(5:) CHANGE = .TRUE. END IF ELSE IF ( L .EQ. 10 ) THEN C C The possible format is: yyyy-mm-dd. If we get a match C construct the corresponding SPICE yyyy-mm-dd format. C IF ( DIGIT (1) . .AND. DIGIT (2) . .AND. DIGIT (3) . .AND. DIGIT (4) . .AND. HYPHEN (5) . .AND. DIGIT (6) . .AND. DIGIT (7) . .AND. HYPHEN (8) . .AND. DIGIT (9) . .AND. DIGIT (10) ) THEN M = BSRCHC ( ASCII(6:7), NMNTHS, IMONTH ) MYSTR = ASCII(1:5) // MONTHS(M) // ASCII(8:) CHANGE = .TRUE. END IF ELSE IF ( L .GE. 17 ) THEN C C There are two possible formats yyyy-dddThh:mm:ss.ssssss C yyyy-mm-ddThh:mm:ss.ssssss C As above, if we get a match up to the first character following C a 'T', convert this to a standard SPICE time string. C IF ( DIGIT (1) .AND. DIGIT (2) . .AND. DIGIT (3) .AND. DIGIT (4) . .AND. HYPHEN (5) . .AND. DIGIT (6) .AND. DIGIT (7) .AND. DIGIT (8) . .AND. T (9) . .AND. DIGIT (10) .AND. DIGIT (11) . .AND. COLON (12) . .AND. DIGIT (13) .AND. DIGIT (14) . .AND. COLON (15) . .AND. DIGIT (16) .AND. DIGIT (17) ) THEN MYSTR = ASCII(1:5) // . 'JAN' // . ASCII(5:8) // . ' ' // . ASCII(10:) CHANGE = .TRUE. ELSE IF ( DIGIT (1) .AND. DIGIT (2) . .AND. DIGIT (3) .AND. DIGIT (4) . .AND. HYPHEN (5) . .AND. DIGIT (6) .AND. DIGIT (7) . .AND. HYPHEN (8) . .AND. DIGIT (9) .AND. DIGIT (10) . .AND. T (11) . .AND. DIGIT (12) .AND. DIGIT (13) . .AND. COLON (14) . .AND. DIGIT (15) .AND. DIGIT (16) . .AND. COLON (17) . .AND. DIGIT (18) .AND. DIGIT (19) ) THEN M = BSRCHC ( ASCII(6:7), NMNTHS, IMONTH ) MYSTR = ASCII(1:5) // . MONTHS(M) // . ASCII(8:10) // . ' ' // . ASCII(12:) CHANGE = .TRUE. END IF END IF C C If we didn't make some change to the input string, it's NOT C an ISO format string. Say so in an error message and return. C IF ( .NOT. CHANGE ) THEN CALL SETMSG ( 'The input string does not match the format ' // . 'expected of ISO time strings. The acceptable '// . 'formats are: yyyy-ddd, yyyy-mm-dd, ' // . 'yyyy-dddThh:mm:ss[.ss...], and ' // . 'yyyy-mm-ddThh:mm:ss[.ss...]. The input ' // . 'string was #. ' ) CALL ERRCH ( '#', MYSTR(1:L) ) CALL SIGERR ( 'SPICE(NOTISOFORMAT)' ) CALL CHKOUT ( 'ISO2ET_M' ) RETURN END IF C C Check for a year out of the range from 1000 to 2999 C IF ( CHANGE . .AND. ( LLT ( ASCII(1:4), '1000' ) . .OR. LGT ( ASCII(1:4), '2999' ) ) ) THEN CALL SETMSG ( 'Years outside the range from 1000 ' // . 'to 2999 are not supported in SPICE-ISO ' // . 'format. You''ve ' // . 'supplied a time string of the form ' // . '# ... ' ) CALL ERRCH ( '#', ASCII(1:7) ) CALL SIGERR ( 'SPICE(YEAROUTOFBOUNDS)' ) CALL CHKOUT ( 'ISO2ET_M' ) RETURN END IF C C That's it. C CALL UTC2ET ( MYSTR, ET ) CALL CHKOUT ( 'ISO2ET_M' ) RETURN END