C$Procedure ET2ISO_M ( Convert ET to ISO format time strings ) SUBROUTINE ET2ISO_M ( ET, FORMAT, PREC, TSTRNG ) C$ Abstract C C This routine converts an ephemeris time (barycentric C dynamical time---TDB) to a UTC time string in the format C adopted by the International Standards Organization (ISO). C C$ Required_Reading C C TIME C C$ Keywords C C TIME C C$ Declarations DOUBLE PRECISION ET CHARACTER*(1) FORMAT INTEGER PREC CHARACTER*(*) TSTRNG C$ Brief_I/O C C VARIABLE I/O DESCRIPTION C -------- --- -------------------------------------------------- C ET I Input epoch, ephemeris seconds past J2000 (TDB). C FORMAT I Format of output epoch. C PREC I Digits of precision in fractional seconds. C TSTRNG O Output time string, UTC. C C$ Detailed_Input C C ET is the input epoch, ephemeris seconds C past J2000 (TDB). C C FORMAT is the format of the output time string. It may be C any of the following: C C 'C' yyyy-mm-ddThh:mm:ss[.ss...s] C 'D' yyyy-dddThh:mm:ss[.ss...s] C C PREC is the number of digits of precision to which C fractional seconds (for Calendar and Day-of-Year C formats) are to be computed. If PREC is zero, no C decimal point is appended to the output string. C PREC may not be less than zero. C C$ Detailed_Output C C TSTRNG is the output time string equivalent to the input C epoch, in the specified format, as shown below. C C 'C' '1986-04-12T16:31:09.814' C 'D' '1986-102T16:31:12.814' C C If an error occurs, TSTRNG is not changed. C C$ Parameters C C None. C C$ Exceptions C C 1) If the format for the output string is not recognized, the C error SPICE(INVALIDTIMEFORMAT) is signalled. TSTRNG is C not changed. C C 2) If the value of PREC is less than zero, the error C SPICE(NEGATIVEPREC) will be signalled. TSTRNG is C not changed. C C 3) If the output overflows the bounds of TSTRNG, the error C SPICE(OUTSTRINGTOOSHORT) will be signalled. TSTRNG will C be returned unchanged from its input value. C C$ Files C C None. C C$ Particulars C C The value of Delta ET corresponding to the input epoch is C determined, and subtracted from the input epoch to give UTC C seconds past J2000. The result is then converted to the C specified format. C C$ Examples C C Let the value of ET be -527644192.5403653 ephemeris seconds C past J2000. Assuming that the nominal values in the kernel pool C have not been altered, the following calls C C CALL ET2ISO_M ( ET, 'C', 0, TSTRNG ) C CALL ET2ISO_M ( ET, 'C', 3, TSTRNG ) C CALL ET2ISO_M ( ET, 'D', 5, TSTRNG ) C C produce the following output strings C C '1983-04-13T12:09:14' C '1983-04-13T12:09:14.274' C '1983-103T12:09:14.27400' C C respectively. C C$ Restrictions C C The conversion between ET and UTC depends on the values in the C kernel pool. The kernel pool should be loaded prior to calling C this subroutine. 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.1.0, 18-JUN-1999 (WLT) C C Fixed CHKIN/CHKOUT calls. C C- SPICELIB Version 1.0.0, 6-APR-1992 (WLT) C C-& C$ Index_Entries C C C Transform ephemeris time TDB to an ISO time string C C-& C C Local Parameters C INTEGER NMNTHS PARAMETER ( NMNTHS = 12 ) C C SPICELIB functions C INTEGER ISRCHC INTEGER RTRIM LOGICAL FAILED LOGICAL RETURN C C Local Variables C CHARACTER*(1) FMT CHARACTER*(3) MONTH CHARACTER*(80) UTC CHARACTER*(80) MYSTR CHARACTER*(3) MONTHS ( NMNTHS ) SAVE MONTHS CHARACTER*(2) IMONTH ( NMNTHS ) SAVE IMONTH INTEGER L INTEGER M 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' / IF ( RETURN() ) THEN RETURN ELSE CALL CHKIN ( 'ET2ISO_M' ) END IF C C First determine which format we need for calling ET2UTC. C CALL UCASE ( FORMAT, FMT ) IF ( ( FMT .NE. 'C' ) . .AND. ( FMT .NE. 'D' ) ) THEN CALL SETMSG ( 'The format requested for ISO format is ' // . 'not on the list of known formats. The ' // . 'acceptable formats are: C and D. The format '// . 'requested was #.' ) CALL ERRCH ( '#', FORMAT ) CALL SIGERR ( 'SPICE(INVALIDTIMEFORMAT)' ) CALL CHKOUT ( 'ET2ISO_M' ) RETURN END IF C C Make sure the number of digits of precision requested is at C least zero. C IF ( PREC .LT. 0 ) THEN CALL SETMSG ( 'The value of PREC, the number of digits used '// . 'to report fractional seconds, must be ' // . 'non-negative. The value input was #.' ) CALL ERRINT ( '#', PREC ) CALL SIGERR ( 'SPICE(NEGATIVEPREC)' ) CALL CHKOUT ( 'ET2ISO_M' ) RETURN END IF C C Let ET2UTC do all the real work... C CALL ET2UTC ( ET, FMT, PREC, UTC ) IF ( FAILED() ) THEN CALL CHKOUT ( 'ET2ISO_M' ) RETURN END IF C C We extract what we need from the UTC output. Note: we are going C to make EXPLICIT use of our knowledge of the formats of the C various UTC output strings. They are: C C 1 2 C 123456789012345678901234 C | | | C 'C' '1986 APR 12 16:31:09.814' C yyyy mmm dd hh:mm:ss.sss C C 'D' '1986-102 // 16:31:12.814' C yyyy-ddd // hh:mm:ss.sss C C IF ( FMT .EQ. 'D' ) THEN C C Just patch things together C MYSTR = UTC(1:8) // 'T' // UTC(13:) ELSE IF ( FMT .EQ. 'C' ) THEN C C Look up the number of the month. C MONTH = UTC (6:8) M = ISRCHC ( MONTH, NMNTHS, MONTHS ) MYSTR = UTC(1:4) // . '-' // . IMONTH(M) // . '-' // . UTC(10:11) // . 'T' // . UTC(13:) END IF C C Now we just make sure everything will fit into the supplied C output string. C L = RTRIM ( MYSTR ) IF ( L .GT. LEN(TSTRNG) ) THEN CALL SETMSG ( 'The supplied output argument did not have ' // . 'sufficient length to hold the requested ' // . 'output time string. The supplied output ' // . 'string had length #, the length required was '// . '#. The string that could not be returned ' // . 'was ''#''. ' ) CALL ERRINT ( '#', LEN(TSTRNG) ) CALL ERRINT ( '#', L ) CALL ERRCH ( '#', MYSTR(1:L) ) CALL SIGERR ( 'SPICE(OUTSTRINGTOOSHORT)' ) CALL CHKOUT ( 'ET2ISO_M' ) RETURN END IF C C If we survived the exception handling, make the last assignment C and checkout. C TSTRNG = MYSTR CALL CHKOUT ( 'ET2ISO_M' ) RETURN END