1 subroutine geth_idts (ndate, odate, idts)
4 !***********************************************************************
6 ! purpose - from 2 input mdates ('YYYY-MM-DD HH:MM:SS'), compute
7 ! the time difference in seconds.
9 ! on entry - ndate - the new hdate.
10 ! odate - the old hdate.
12 ! on exit - idts - the change in time in seconds.
14 !***********************************************************************
16 character*(*) ndate, odate
23 ! yrnew - indicates the year associated with "ndate"
24 ! yrold - indicates the year associated with "odate"
25 ! monew - indicates the month associated with "ndate"
26 ! moold - indicates the month associated with "odate"
27 ! dynew - indicates the day associated with "ndate"
28 ! dyold - indicates the day associated with "odate"
29 ! hrnew - indicates the hour associated with "ndate"
30 ! hrold - indicates the hour associated with "odate"
31 ! minew - indicates the minute associated with "ndate"
32 ! miold - indicates the minute associated with "odate"
33 ! scnew - indicates the second associated with "ndate"
34 ! scold - indicates the second associated with "odate"
36 ! mday - a list assigning the number of days in each month
37 ! newhrs - the number of hours between "ndate" and 1901
39 ! oldhrs - the number of hours between "odate" and 1901
42 integer yrnew, monew, dynew, hrnew, minew, scnew
43 integer yrold, moold, dyold, hrold, miold, scold
44 integer mday(12), i, newdys, olddys
49 integer, external :: nfeb
51 !************************* Subroutine Begin **************************
53 if (odate.gt.ndate) then
63 ! Assign the number of days in a months
80 ! Break down old hdate into parts
87 read(odate(1:4), '(I4)', err=101) yrold
88 read(odate(6:7), '(I2)', err=101) moold
89 read(odate(9:10), '(I2)', err=101) dyold
91 read(odate(12:13),'(I2)', err=101) hrold
93 read(odate(15:16),'(I2)', err=101) miold
95 read(odate(18:19),'(I2)', err=101) scold
101 ! Break down new hdate into parts
108 read(ndate(1:4), '(I4)', err=102) yrnew
109 read(ndate(6:7), '(I2)', err=102) monew
110 read(ndate(9:10), '(I2)', err=102) dynew
112 read(ndate(12:13),'(I2)', err=102) hrnew
114 read(ndate(15:16),'(I2)', err=102) minew
116 read(ndate(18:19),'(I2)', err=102) scnew
122 ! Check that the dates make sense.
127 ! Check that the month of NDATE makes sense.
129 if ((monew.gt.12).or.(monew.lt.1)) then
130 print*, 'GETH_IDTS: Month of NDATE = ', monew
134 ! Check that the month of ODATE makes sense.
136 if ((moold.gt.12).or.(moold.lt.1)) then
137 print*, 'GETH_IDTS: Month of ODATE = ', moold
141 ! Check that the day of NDATE makes sense.
144 ! ...... For all months but February
145 if ((dynew.gt.mday(monew)).or.(dynew.lt.1)) then
146 print*, 'GETH_IDTS: Day of NDATE = ', dynew
149 elseif (monew.eq.2) then
150 ! ...... For February
151 if ((dynew .gt. nfeb(yrnew)).or.(dynew.lt.1)) then
152 print*, 'GETH_IDTS: Day of NDATE = ', dynew
157 ! Check that the day of ODATE makes sense.
160 ! ...... For all months but February
161 if ((dyold.gt.mday(moold)).or.(dyold.lt.1)) then
162 print*, 'GETH_IDTS: Day of ODATE = ', dyold
165 elseif (moold.eq.2) then
166 ! ....... For February
167 if ((dyold .gt. nfeb(yrold)).or.(dyold .lt. 1)) then
168 print*, 'GETH_IDTS: Day of ODATE = ', dyold
173 ! Check that the hour of NDATE makes sense.
175 if ((hrnew.gt.23).or.(hrnew.lt.0)) then
176 print*, 'GETH_IDTS: Hour of NDATE = ', hrnew
180 ! Check that the hour of ODATE makes sense.
182 if ((hrold.gt.23).or.(hrold.lt.0)) then
183 print*, 'GETH_IDTS: Hour of ODATE = ', hrold
187 ! Check that the minute of NDATE makes sense.
189 if ((minew.gt.59).or.(minew.lt.0)) then
190 print*, 'GETH_IDTS: Minute of NDATE = ', minew
194 ! Check that the minute of ODATE makes sense.
196 if ((miold.gt.59).or.(miold.lt.0)) then
197 print*, 'GETH_IDTS: Minute of ODATE = ', miold
201 ! Check that the second of NDATE makes sense.
203 if ((scnew.gt.59).or.(scnew.lt.0)) then
204 print*, 'GETH_IDTS: SECOND of NDATE = ', scnew
208 ! Check that the second of ODATE makes sense.
210 if ((scold.gt.59).or.(scold.lt.0)) then
211 print*, 'GETH_IDTS: Second of ODATE = ', scold
215 if (.not. npass) then
216 print*, 'Screwy NDATE: ', ndate(1:nlen)
220 if (.not. opass) then
221 print*, 'Screwy ODATE: ', odate(1:olen)
225 ! Date Checks are completed. Continue.
229 ! Compute number of days from 1 January ODATE, 00:00:00 until ndate
230 ! Compute number of hours from 1 January ODATE, 00:00:00 until ndate
231 ! Compute number of minutes from 1 January ODATE, 00:00:00 until ndate
235 do i = yrold, yrnew - 1
236 newdys = newdys + (365 + (nfeb(i)-28))
239 if (monew .gt. 1) then
240 mday(2) = nfeb(yrnew)
242 newdys = newdys + mday(i)
247 newdys = newdys + dynew-1
249 ! Compute number of hours from 1 January ODATE, 00:00:00 until odate
250 ! Compute number of minutes from 1 January ODATE, 00:00:00 until odate
255 if (moold .gt. 1) then
256 mday(2) = nfeb(yrold)
258 olddys = olddys + mday(i)
263 olddys = olddys + dyold-1
265 ! Determine the time difference in seconds
267 idts = (newdys - olddys) * 86400
268 idts = idts + (hrnew - hrold) * 3600
269 idts = idts + (minew - miold) * 60
270 idts = idts + (scnew - scold)
272 if (isign .eq. -1) then
281 101 write(6,*) 'Error reading odate. odate = ',odate
282 write(6,*) 'Most likely an error in namelist.wps'
284 102 write(6,*) 'Error reading ndate. ndate = ',ndate
285 write(6,*) 'Most likely an error in namelist.wps'
288 !************************** Subroutine End ***************************
291 integer function nfeb(year)
293 ! Compute the number of days in February for the given year.
296 integer, intent(in) :: year ! Four-digit year
298 #ifdef NO_LEAP_CALENDAR
299 nfeb = 28 ! February always has 28 days for No Leap Calendar ...
301 nfeb = 28 ! By default, February has 28 days ...
302 if (mod(year,4).eq.0) then
303 nfeb = 29 ! But every four years, it has 29 days ...
304 if (mod(year,100).eq.0) then
305 nfeb = 28 ! Except every 100 years, when it has 28 days ...
306 if (mod(year,400).eq.0) then
307 nfeb = 29 ! Except every 400 years, when it has 29 days ...
308 if (mod(year,3600).eq.0) then
309 nfeb = 28 ! Except every 3600 years, when it has 28 days.