1 subroutine geth_newdate (ndate, odate, idts)
4 !**********************************************************************
6 ! purpose - from old date ('YYYY-MM-DD*HH:MM:SS') and time in
7 ! seconds, compute the new date.
9 ! on entry - odate - the old hdate.
10 ! idts - the change in time in seconds.
12 ! on exit - ndate - the new hdate.
13 ! idts - the change in time in seconds.
15 !**********************************************************************
18 character*(*) ndate, odate
24 ! yrold - indicates the year associated with "odate"
25 ! moold - indicates the month associated with "odate"
26 ! dyold - indicates the day associated with "odate"
27 ! hrold - indicates the hour associated with "odate"
28 ! miold - indicates the minute associated with "odate"
29 ! scold - indicates the second associated with "odate"
31 ! yrnew - indicates the year associated with "ndate"
32 ! monew - indicates the month associated with "ndate"
33 ! dynew - indicates the day associated with "ndate"
34 ! hrnew - indicates the hour associated with "ndate"
35 ! minew - indicates the minute associated with "ndate"
36 ! scnew - indicates the second associated with "ndate"
38 ! mday - a list assigning the number of days in each month
40 ! dth - the number of hours represented by "idts"
42 ! nday - the integer number of days represented by "idts"
43 ! nhour - the integer number of hours in "idts" after taking out
45 ! nmin - the integer number of minutes in "idts" after taking out
46 ! all the whole days and whole hours.
47 ! nsec - the integer number of minutes in "idts" after taking out
48 ! all the whole days, whole hours, and whole minutes.
51 integer yrnew, monew, dynew, hrnew, minew, scnew
52 integer yrold, moold, dyold, hrold, miold, scold
53 integer mday(12), nday, nhour, nmin, nsec, i
56 logical noLeapCalendar
59 !************************* Subroutine Begin *************************
62 ! Determine whether the routine should use a no-leap year calendar
64 noLeapCalendar = .false.
66 #ifdef NO_LEAP_CALENDAR
67 noLeapCalendar = .true.
72 ! Assign the number of days in a months
89 ! Break down old hdate into parts
96 read(odate(1:4), '(I4)') yrold
97 read(odate(6:7), '(I2)') moold
98 read(odate(9:10), '(I2)') dyold
100 read(odate(12:13),'(I2)') hrold
102 read(odate(15:16),'(I2)') miold
104 read(odate(18:19),'(I2)') scold
109 ! Set the number of days in February for that year.
112 if (.not. noLeapCalendar) then
113 if (mod(yrold,4).eq.0) then
115 if (mod(yrold,100).eq.0) then
117 if (mod(yrold,400).eq.0) then
124 ! Check that ODATE makes sense.
128 ! Check that the month of ODATE makes sense.
130 if ((moold.gt.12).or.(moold.lt.1)) then
131 print*, 'GETH_NEWDATE: Month of ODATE = ', moold
135 ! Check that the day of ODATE makes sense.
137 if ((dyold.gt.mday(moold)).or.(dyold.lt.1)) then
140 ! Send a custom message if any leap-day files if it is a No-Leap Calendar
142 if (noLeapCalendar .and. (moold .eq. 2) .and. (dyold .eq. 29)) then
143 print*,'GET_NEWDATE: Using a no-Leap Calendar, but data for 2/29 was found.'
145 print*, 'GET_NEWDATE: Day of ODATE = ', dyold
151 ! Check that the hour of ODATE makes sense.
153 if ((hrold.gt.23).or.(hrold.lt.0)) then
154 print*, 'GET_NEWDATE: Hour of ODATE = ', hrold
158 ! Check that the minute of ODATE makes sense.
160 if ((miold.gt.59).or.(miold.lt.0)) then
161 print*, 'GET_NEWDATE: Minute of ODATE = ', miold
165 ! Check that the second of ODATE makes sense.
167 if ((scold.gt.59).or.(scold.lt.0)) then
168 print*, 'GET_NEWDATE: Second of ODATE = ', scold
173 print*, 'Crazy ODATE: ', odate(1:olen), olen
178 ! Date Checks are completed. Continue.
182 ! Compute the number of days, hours, minutes, and seconds in idts
184 nday = idts/86400 ! Integer number of days in delta-time
185 nhour = mod(idts,86400)/3600
186 nmin = mod(idts,3600)/60
190 if (scnew .ge. 60) then
195 if (minew .ge. 60) then
199 hrnew = hrold + nhour
200 if (hrnew .ge. 24) then
210 if (dynew.gt.mday(monew)) then
211 dynew = dynew - mday(monew)
213 if (monew .gt. 12) then
218 if (.not. noLeapCalendar) then
219 if (mod(yrnew,4).eq.0) then
221 if (mod(yrnew,100).eq.0) then
223 if (mod(yrnew,400).eq.0) then
235 ! Now construct the new mdate
240 write(ndate,19) yrnew, monew, dynew, hrnew, minew, scnew
241 19 format(I4,'-',I2.2,'-',I2.2,'_',I2.2,':',I2.2,':',I2.2)
243 else if (nlen.eq.16) then
244 write(ndate,16) yrnew, monew, dynew, hrnew, minew
245 16 format(I4,'-',I2.2,'-',I2.2,'_',I2.2,':',I2.2)
247 else if (nlen.eq.13) then
248 write(ndate,13) yrnew, monew, dynew, hrnew
249 13 format(I4,'-',I2.2,'-',I2.2,'_',I2.2)
251 else if (nlen.eq.10) then
252 write(ndate,10) yrnew, monew, dynew
253 10 format(I4,'-',I2.2,'-',I2.2)
257 !************************** Subroutine End **************************