C+ C NAME: C Time2Str C PURPOSE: C Convert integer time arrays to string YYYY/MM/DD hh:mm:ss.mss C CATEGORY: C gen/for/lib C CALLING SEQUENCE: integer function Time2Str(ctemplate,t,ct) C INPUTS: C ctemplate character*(*) time format string C t (2) integer time C OUTPUTS C Time2Str integer length of ctemplate C ct character*(*) time string (with effective length C of Time2Str C INCLUDE: include 'fortime.h' C CALLS: C Time2YDoy, Time2YMD, Time2HMS, Time2JD, Time2DOW, Time2MonthStr C itrim, d2c C PROCEDURE: C The template can contain any combination of the following strings C 'YEAR', 'YYYY', 'YY', 'DOY','MON','MN','DD','hh','mm','ss' C The corresponding substrings in ct are filled as follows: C 'YEAR','YYYY' year C 'YY' 2-digit year (<= 50: 1900 is added) C (> 50: 2000 is added) C 'DOY' day of year C 'MON' month as 3-char string C 'MN' month as two-digit number C 'DD' day of month C 'hh','mm','ss' hours, minutes and seconds of day C 'f','ff','fff', etc. fraction of second C MODIFICATION HISTORY: C OCT-2003, Paul Hick (UCSD/CASS) C JUL-2004, Paul Hick (UCSD/CASS; pphick@ucsd.edu) C Replaced all write statements by calls to d2c to avoid I/O C recursion in g77. C- character ctemplate*(*) integer t(2) character ct*(*) integer yr integer mon integer day(2) integer doy(2) integer hms(4) character Time2DOW*3 character Time2MonthStr*3 integer units_in_second double precision day8 character d2c call Time2YMD (0,t,yr,mon,day) call Time2YDoy(0,t,yr,doy) ! day(2) = doy(2) call Time2HMS (0,doy,hms) ! NOT t(1,i) instead of doy !!!! call Time2Template(ctemplate,ct) i = index(ct, 'YEAR') if (i .eq. 0) i = index(ct, 'YYYY') !if (i .ne. 0) write (ct(i:i+3),'(I4.4)') yr if (i .ne. 0) ct(i:i+3) = d2c(yr,3)//d2c(yr,2)//d2c(yr,1)//d2c(yr,0) i = index(ct, 'YY') if (i .ne. 0) then !if (yr .ge. 2000) write (ct(i:i+1),'(I2.2)') yr-2000 if (yr .ge. 2000) ct(i:i+1) = d2c(yr-2000,1)//d2c(yr-2000,0) !if (yr .lt. 2000) write (ct(i:i+1),'(I2.2)') yr-1900 if (yr .lt. 2000) ct(i:i+1) = d2c(yr-1900,1)//d2c(yr-1900,0) end if i = index(ct, 'DOY') !if (i .ne. 0) write (ct(i:i+2),'(I3.3)') doy(1) if (i .ne. 0) ct(i:i+2) = d2c(doy(1),2)//d2c(doy(1),1)//d2c(doy(1),0) i = index(ct, 'MON') if (i .ne. 0) ct(i:i+2) = Time2MonthStr(mon) i = index(ct, 'MN' ) !if (i .ne. 0) write (ct(i:i+1),'(I2.2)') mon if (i .ne. 0) ct(i:i+1)= d2c(mon,1)//d2c(mon,0) i = index(ct, 'DD' ) !if (i .ne. 0) write (ct(i:i+1),'(I2.2)') day(1) if (i .ne. 0) ct(i:i+1) = d2c(day(1),1)//d2c(day(1),0) i = index(ct, 'DOW') if (i .ne. 0) ct(i:i+2) = Time2DOW(t) i = index(ct, 'hh' ) !if (i .ne. 0) write (ct(i:i+1),'(I2.2)') hms(1) if (i .ne. 0) ct(i:i+1) = d2c(hms(1),1)//d2c(hms(1),0) i = index(ct, 'mm' ) !if (i .ne. 0) write (ct(i:i+1),'(I2.2)') hms(2) if (i .ne. 0) ct(i:i+1) = d2c(hms(2),1)//d2c(hms(2),0) i = index(ct, 'ss' ) !if (i .ne. 0) write (ct(i:i+1),'(I2.2)') hms(3) if (i .ne. 0) ct(i:i+1) = d2c(hms(3),1)//d2c(hms(3),0) i = index(ct, 'f') if (i .ne. 0) then j = i nl = len(ct) do while (j .lt. nl .and. ct(j+1:j+1) .eq. 'f' ) j = j+1 end do nl = j-i+1 if (TIME__ORIGIN(3) .le. TIME__SECONDS_IN_DAY) then nl = 0 else units_in_second = TIME__ORIGIN(3)/TIME__SECONDS_IN_DAY hms(4) = hms(4)*10**(j-i+1) nl = hms(4)/units_in_second if (nl*units_in_second .ne. hms(4)) nl = nint(float(hms(4))/units_in_second) end if do k=i,j ct(k:k) = d2c(nl,j-k) end do end if ! Note that jd only has two chars in the template while we are writing ! 7 chars, so we do this last after making sure to make room first. i = index(ct, 'IJD') if (i .ne. 0) then ct(i+7:) = ct(i+3:) call Time2JD(0,t,day) !write (ct(i:i+6),'(I7)') day(1) j = day(1) ct(i:i+6) = d2c(j,6)//d2c(j,5)//d2c(j,4)//d2c(j,3)//d2c(j,2)//d2c(j,1)//d2c(j,0) end if i = index(ct, 'RJD') if (i .ne. 0) then ct(i+12:) = ct(i+3:) call Time2JD(0,t,day) !write (ct(i:i+6),'(I7)') day(1) j = day(1) day(1) = 0 call Time2Day8(0,day,day8) !ct(i+7:i+7) = '.' !write (ct(i+8:i+11),'(I4.4)') nint(10000*day8) k = nint(10000*day8) ct(i:i+11) = d2c(j,6)//d2c(j,5)//d2c(j,4)//d2c(j,3)//d2c(j,2)//d2c(j,1)//d2c(j,0)// & '.'//d2c(k,3)//d2c(k,2)//d2c(k,1)//d2c(k,0) end if i = index(ct, 'JEPOCH') if (i .ne. 0) then ct(i+9:) = ct(i+6:) call Time2JEpoch(0,t,day8) !write (ct(i:i+8),'(F9.4)') day8 j = day8 k = nint(10000*(day8-j)) ct(i:i+8) = d2c(j,3)//d2c(j,2)//d2c(j,1)//d2c(j,0)// & '.'//d2c(k,3)//d2c(k,2)//d2c(k,1)//d2c(k,0) end if Time2Str = itrim(ct) return end