C+ C NAME: C Time2Split C PURPOSE: C Convert string time arrays to integer C CATEGORY: C gen/for/lib C CALLING SEQUENCE: subroutine Time2Split(ctemplate_,ct,t) C INPUTS: C ctemplate character*(*) character template describing C time format C ct character*(*) string time C OUTPUTS C t(2) integer # 2-element standard time C INCLUDE: include 'fortime.h' C CALLS: C Time2YMD, Time2HMS, Time2Add, Time2Month, Time2YDoy 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 are extracted from ct and are C interpreted as follows to construct the time: 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 NOV-2004, Paul Hick (UCSD/CASS; pphick@ucsd.edu) C Bug fix. units_in_second needed to be divided by another 60. C- character ctemplate_*(*) character ct*(*) integer t(2) character cSay*10 /'Time2Split'/ integer yr integer mon integer day(2) integer doy(2) integer hms(4) integer tt (2) character cfmt*6 character ctemplate*80 integer Time2Month call Time2Template(ctemplate_,ctemplate) ip_yr4 = index(ctemplate, 'YEAR') if (ip_yr4 .eq. 0) ip_yr4 = index(ctemplate, 'YYYY') ip_yr2 = 0 if (ip_yr4 .eq. 0) ip_yr2 = index(ctemplate, 'YY') ip_doy = index(ctemplate, 'DOY' ) ip_cmon = index(ctemplate, 'MON' ) ip_imon = index(ctemplate, 'MN') ip_day = index(ctemplate, 'DD' ) ip_hh = index(ctemplate, 'hh' ) ip_mm = index(ctemplate, 'mm' ) ip_ss = index(ctemplate, 'ss' ) ip_fff = index(ctemplate, 'f' ) ! part of second (don't use mss here) if (ip_fff .ne. 0) then ip_ggg = ip_fff nl = len(ctemplate) do while (ip_ggg .lt. nl .and. ctemplate(ip_ggg+1:ip_ggg+1) .eq. 'f' ) ip_ggg = ip_ggg+1 end do nl = ip_ggg-ip_fff+1 write (cfmt,'(A2,I1,A1,I1,A1)') '(I',nl,'.',nl,')' end if if (ip_yr2 .ne. 0) then read (ct(ip_yr4:ip_yr4+3),'(I4.4)',iostat=iostat) yr if (iostat .ne. 0) call Say(cSay,'F',ctemplate,ct(:itrim(ctemplate))) if (yr .le. 50) then yr = yr+2000 else yr = yr+1900 end if else if (ip_yr4 .ne. 0) then read (ct(ip_yr4:ip_yr4+3),'(I4.4)',iostat=iostat) yr if (iostat .ne. 0) call Say(cSay,'F',ctemplate,ct(:itrim(ctemplate))) else yr = 0 end if t(1) = 0 t(2) = 0 if (ip_doy .ne. 0) then read (ct(ip_doy:ip_doy+2),'(I3.3)',iostat=iostat) doy(1) if (iostat .ne. 0) call Say(cSay,'F',ctemplate,ct(:itrim(ctemplate))) doy(2) = 0 call Time2YDoy(1,t,yr,doy) else if (ip_day .ne. 0) then if (ip_cmon .ne. 0) then mon = Time2Month(ct(ip_cmon:ip_cmon+2)) else if (ip_imon .ne. 0) then read (ct(ip_imon:ip_imon+1),'(I2.2)',iostat=iostat) mon if (iostat .ne. 0) call Say(cSay,'F',ctemplate,ct(:itrim(ctemplate))) else mon = 1 end if read (ct(ip_day:ip_day+1),'(I2.2)',iostat=iostat) day(1) if (iostat .ne. 0) call Say(cSay,'F',ctemplate,ct(:itrim(ctemplate))) day(2) = 0 call Time2YMD(1,t,yr,mon,day) else t(1) = 0 end if if (ip_hh .ne. 0) then read (ct(ip_hh:ip_hh+1),'(I2.2)',iostat=iostat) hms(1) if (iostat .ne. 0) call Say(cSay,'F',ctemplate,ct(:itrim(ctemplate))) else hms(1) = 0 end if if (ip_mm .ne. 0) then read (ct(ip_mm:ip_mm+1),'(I2.2)',iostat=iostat) hms(2) if (iostat .ne. 0) call Say(cSay,'F',ctemplate,ct(:itrim(ctemplate))) else hms(2) = 0 end if if (ip_ss .ne. 0) then read (ct(ip_ss:ip_ss+1),'(I2.2)',iostat=iostat) hms(3) if (iostat .ne. 0) call Say(cSay,'F',ctemplate,ct(:itrim(ctemplate))) else hms(3) = 0 end if if (ip_fff .ne. 0) then read (ct(ip_fff:ip_ggg),cfmt,iostat=iostat) hms(4) if (iostat .ne. 0) call Say(cSay,'F',ctemplate,ct(:itrim(ctemplate))) hms(4) = hms(4)*(TIME__ORIGIN(3)/TIME__SECONDS_IN_DAY) nl = 10**(ip_ggg-ip_fff+1) if (hms(4)/nl*nl .eq. hms(4)) then hms(4) = hms(4)/nl else hms(4) = nint(float(hms(4))/nl) end if else hms(4) = 0 end if call Time2HMS(1,tt,hms) call Time2Add(t,tt,t) return end