PageRenderTime 41ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/WPS/ungrib/src/geth_newdate.F

http://github.com/jbeezley/wrf-fire
FORTRAN Legacy | 233 lines | 130 code | 33 blank | 70 comment | 27 complexity | aac3633ede113f30116d746081c79059 MD5 | raw file
Possible License(s): AGPL-1.0
  1. subroutine geth_newdate (ndate, odate, idts)
  2. implicit none
  3. !**********************************************************************
  4. !
  5. ! purpose - from old date ('YYYY-MM-DD*HH:MM:SS') and time in
  6. ! seconds, compute the new date.
  7. !
  8. ! on entry - odate - the old hdate.
  9. ! idts - the change in time in seconds.
  10. !
  11. ! on exit - ndate - the new hdate.
  12. ! idts - the change in time in seconds.
  13. !
  14. !**********************************************************************
  15. integer idts
  16. character*(*) ndate, odate
  17. integer nlen, olen
  18. !
  19. ! Local Variables
  20. !
  21. ! yrold - indicates the year associated with "odate"
  22. ! moold - indicates the month associated with "odate"
  23. ! dyold - indicates the day associated with "odate"
  24. ! hrold - indicates the hour associated with "odate"
  25. ! miold - indicates the minute associated with "odate"
  26. ! scold - indicates the second associated with "odate"
  27. !
  28. ! yrnew - indicates the year associated with "ndate"
  29. ! monew - indicates the month associated with "ndate"
  30. ! dynew - indicates the day associated with "ndate"
  31. ! hrnew - indicates the hour associated with "ndate"
  32. ! minew - indicates the minute associated with "ndate"
  33. ! scnew - indicates the second associated with "ndate"
  34. !
  35. ! mday - a list assigning the number of days in each month
  36. ! dth - the number of hours represented by "idts"
  37. ! i - loop counter
  38. ! nday - the integer number of days represented by "idts"
  39. ! nhour - the integer number of hours in "idts" after taking out
  40. ! all the whole days
  41. ! nmin - the integer number of minutes in "idts" after taking out
  42. ! all the whole days and whole hours.
  43. ! nsec - the integer number of minutes in "idts" after taking out
  44. ! all the whole days, whole hours, and whole minutes.
  45. !
  46. integer yrnew, monew, dynew, hrnew, minew, scnew
  47. integer yrold, moold, dyold, hrold, miold, scold
  48. integer mday(12), nday, nhour, nmin, nsec, i
  49. real dth
  50. logical opass
  51. !************************* Subroutine Begin *************************
  52. !
  53. ! Assign the number of days in a months
  54. !
  55. mday( 1) = 31
  56. mday( 2) = 28
  57. mday( 3) = 31
  58. mday( 4) = 30
  59. mday( 5) = 31
  60. mday( 6) = 30
  61. mday( 7) = 31
  62. mday( 8) = 31
  63. mday( 9) = 30
  64. mday(10) = 31
  65. mday(11) = 30
  66. mday(12) = 31
  67. !
  68. ! Break down old hdate into parts
  69. !
  70. hrold = 0
  71. miold = 0
  72. scold = 0
  73. olen = len(odate)
  74. read(odate(1:4), '(I4)') yrold
  75. read(odate(6:7), '(I2)') moold
  76. read(odate(9:10), '(I2)') dyold
  77. if (olen.ge.13) then
  78. read(odate(12:13),'(I2)') hrold
  79. if (olen.ge.16) then
  80. read(odate(15:16),'(I2)') miold
  81. if (olen.ge.19) then
  82. read(odate(18:19),'(I2)') scold
  83. endif
  84. endif
  85. endif
  86. !
  87. ! Set the number of days in February for that year.
  88. !
  89. mday(2) = 28
  90. if (mod(yrold,4).eq.0) then
  91. mday(2) = 29
  92. if (mod(yrold,100).eq.0) then
  93. mday(2) = 28
  94. if (mod(yrold,400).eq.0) then
  95. mday(2) = 29
  96. endif
  97. endif
  98. endif
  99. !
  100. ! Check that ODATE makes sense.
  101. !
  102. opass = .TRUE.
  103. ! Check that the month of ODATE makes sense.
  104. if ((moold.gt.12).or.(moold.lt.1)) then
  105. print*, 'GETH_NEWDATE: Month of ODATE = ', moold
  106. opass = .FALSE.
  107. endif
  108. ! Check that the day of ODATE makes sense.
  109. if ((dyold.gt.mday(moold)).or.(dyold.lt.1)) then
  110. print*, 'GET_NEWDATE: Day of ODATE = ', dyold
  111. opass = .FALSE.
  112. endif
  113. ! Check that the hour of ODATE makes sense.
  114. if ((hrold.gt.23).or.(hrold.lt.0)) then
  115. print*, 'GET_NEWDATE: Hour of ODATE = ', hrold
  116. opass = .FALSE.
  117. endif
  118. ! Check that the minute of ODATE makes sense.
  119. if ((miold.gt.59).or.(miold.lt.0)) then
  120. print*, 'GET_NEWDATE: Minute of ODATE = ', miold
  121. opass = .FALSE.
  122. endif
  123. ! Check that the second of ODATE makes sense.
  124. if ((scold.gt.59).or.(scold.lt.0)) then
  125. print*, 'GET_NEWDATE: Second of ODATE = ', scold
  126. opass = .FALSE.
  127. endif
  128. if (.not.opass) then
  129. print*, 'Crazy ODATE: ', odate(1:olen), olen
  130. STOP 'Error_odate'
  131. ! stop
  132. endif
  133. !
  134. ! Date Checks are completed. Continue.
  135. !
  136. !
  137. ! Compute the number of days, hours, minutes, and seconds in idts
  138. !
  139. nday = idts/86400 ! Integer number of days in delta-time
  140. nhour = mod(idts,86400)/3600
  141. nmin = mod(idts,3600)/60
  142. nsec = mod(idts,60)
  143. scnew = scold + nsec
  144. if (scnew .ge. 60) then
  145. scnew = scnew - 60
  146. nmin = nmin + 1
  147. end if
  148. minew = miold + nmin
  149. if (minew .ge. 60) then
  150. minew = minew - 60
  151. nhour = nhour + 1
  152. end if
  153. hrnew = hrold + nhour
  154. if (hrnew .ge. 24) then
  155. hrnew = hrnew - 24
  156. nday = nday + 1
  157. end if
  158. dynew = dyold
  159. monew = moold
  160. yrnew = yrold
  161. do i = 1, nday
  162. dynew = dynew + 1
  163. if (dynew.gt.mday(monew)) then
  164. dynew = dynew - mday(monew)
  165. monew = monew + 1
  166. if (monew .gt. 12) then
  167. monew = 1
  168. yrnew = yrnew + 1
  169. mday(2) = 28
  170. if (mod(yrnew,4).eq.0) then
  171. mday(2) = 29
  172. if (mod(yrnew,100).eq.0) then
  173. mday(2) = 28
  174. if (mod(yrnew,400).eq.0) then
  175. mday(2) = 29
  176. endif
  177. endif
  178. endif
  179. end if
  180. endif
  181. enddo
  182. !
  183. ! Now construct the new mdate
  184. !
  185. nlen = len(ndate)
  186. if (nlen.ge.19) then
  187. write(ndate,19) yrnew, monew, dynew, hrnew, minew, scnew
  188. 19 format(I4,'-',I2.2,'-',I2.2,'_',I2.2,':',I2.2,':',I2.2)
  189. else if (nlen.eq.16) then
  190. write(ndate,16) yrnew, monew, dynew, hrnew, minew
  191. 16 format(I4,'-',I2.2,'-',I2.2,'_',I2.2,':',I2.2)
  192. else if (nlen.eq.13) then
  193. write(ndate,13) yrnew, monew, dynew, hrnew
  194. 13 format(I4,'-',I2.2,'-',I2.2,'_',I2.2)
  195. else if (nlen.eq.10) then
  196. write(ndate,10) yrnew, monew, dynew
  197. 10 format(I4,'-',I2.2,'-',I2.2)
  198. endif
  199. !************************** Subroutine End **************************
  200. end