PageRenderTime 90ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 0ms

/wrfv2_fire/external/esmf_time_f90/ESMF_Time.F90

http://github.com/jbeezley/wrf-fire
FORTRAN Modern | 1188 lines | 392 code | 108 blank | 688 comment | 3 complexity | ccb5ba98eca18b3f08a89b9194fc6d19 MD5 | raw file
Possible License(s): AGPL-1.0
  1. !
  2. ! Earth System Modeling Framework
  3. ! Copyright 2002-2003, University Corporation for Atmospheric Research,
  4. ! Massachusetts Institute of Technology, Geophysical Fluid Dynamics
  5. ! Laboratory, University of Michigan, National Centers for Environmental
  6. ! Prediction, Los Alamos National Laboratory, Argonne National Laboratory,
  7. ! NASA Goddard Space Flight Center.
  8. ! Licensed under the University of Illinois-NCSA license.
  9. !
  10. !==============================================================================
  11. !
  12. ! ESMF Time Module
  13. module ESMF_TimeMod
  14. !
  15. !==============================================================================
  16. !
  17. ! This file contains the Time class definition and all Time class methods.
  18. !
  19. !------------------------------------------------------------------------------
  20. ! INCLUDES
  21. #include <ESMF_TimeMgr.inc>
  22. !==============================================================================
  23. !BOPI
  24. ! !MODULE: ESMF_TimeMod
  25. !
  26. ! !DESCRIPTION:
  27. ! Part of Time Manager F90 API wrapper of C++ implemenation
  28. !
  29. ! Defines F90 wrapper entry points for corresponding
  30. ! C++ class {\tt ESMC\_Time} implementation
  31. !
  32. ! See {\tt ../include/ESMC\_Time.h} for complete description
  33. !
  34. !------------------------------------------------------------------------------
  35. ! !USES:
  36. ! inherit from ESMF base class
  37. use ESMF_BaseMod
  38. ! inherit from base time class
  39. use ESMF_BaseTimeMod
  40. ! associated derived types
  41. use ESMF_TimeIntervalMod
  42. use ESMF_CalendarMod
  43. use ESMF_Stubs
  44. implicit none
  45. !
  46. !------------------------------------------------------------------------------
  47. ! !PRIVATE TYPES:
  48. private
  49. !------------------------------------------------------------------------------
  50. ! ! ESMF_Time
  51. !
  52. ! ! F90 class type to match C++ Time class in size only;
  53. ! ! all dereferencing within class is performed by C++ implementation
  54. type ESMF_Time
  55. type(ESMF_BaseTime) :: basetime ! inherit base class
  56. ! time instant is expressed as year + basetime
  57. integer :: YR
  58. type(ESMF_Calendar), pointer :: calendar ! associated calendar
  59. end type
  60. !------------------------------------------------------------------------------
  61. ! !PUBLIC TYPES:
  62. public ESMF_Time
  63. !------------------------------------------------------------------------------
  64. !
  65. ! !PUBLIC MEMBER FUNCTIONS:
  66. public ESMF_TimeGet
  67. public ESMF_TimeSet
  68. ! Required inherited and overridden ESMF_Base class methods
  69. public ESMF_TimeCopy
  70. ! !PRIVATE MEMBER FUNCTIONS:
  71. private ESMF_TimeGetDayOfYear
  72. private ESMF_TimeGetDayOfYearInteger
  73. ! Inherited and overloaded from ESMF_BaseTime
  74. ! NOTE: ESMF_TimeInc, ESMF_TimeDec, ESMF_TimeDiff, ESMF_TimeEQ,
  75. ! ESMF_TimeNE, ESMF_TimeLT, ESMF_TimeGT, ESMF_TimeLE, and
  76. ! ESMF_TimeGE are PUBLIC only to work around bugs in the
  77. ! PGI 5.1-x compilers. They should all be PRIVATE.
  78. public operator(+)
  79. public ESMF_TimeInc
  80. public operator(-)
  81. public ESMF_TimeDec
  82. public ESMF_TimeDec2
  83. public ESMF_TimeDiff
  84. public operator(.EQ.)
  85. public ESMF_TimeEQ
  86. public operator(.NE.)
  87. public ESMF_TimeNE
  88. public operator(.LT.)
  89. public ESMF_TimeLT
  90. public operator(.GT.)
  91. public ESMF_TimeGT
  92. public operator(.LE.)
  93. public ESMF_TimeLE
  94. public operator(.GE.)
  95. public ESMF_TimeGE
  96. !EOPI
  97. !==============================================================================
  98. !
  99. ! INTERFACE BLOCKS
  100. !
  101. !==============================================================================
  102. !BOP
  103. ! !INTERFACE:
  104. interface ESMF_TimeGetDayOfYear
  105. ! !PRIVATE MEMBER FUNCTIONS:
  106. module procedure ESMF_TimeGetDayOfYearInteger
  107. ! !DESCRIPTION:
  108. ! This interface overloads the {\tt ESMF\_GetDayOfYear} method
  109. ! for the {\tt ESMF\_Time} class
  110. !
  111. !EOP
  112. end interface
  113. !
  114. !------------------------------------------------------------------------------
  115. !BOP
  116. ! !INTERFACE:
  117. interface operator(+)
  118. ! !PRIVATE MEMBER FUNCTIONS:
  119. module procedure ESMF_TimeInc, ESMF_TimeInc2
  120. ! !DESCRIPTION:
  121. ! This interface overloads the + operator for the {\tt ESMF\_Time} class
  122. !
  123. !EOP
  124. end interface
  125. !
  126. !------------------------------------------------------------------------------
  127. !BOP
  128. ! !INTERFACE:
  129. interface assignment (=)
  130. ! !PRIVATE MEMBER FUNCTIONS:
  131. module procedure ESMF_TimeCopy
  132. ! !DESCRIPTION:
  133. ! This interface overloads the = operator for the {\tt ESMF\_Time} class
  134. !
  135. !EOP
  136. end interface
  137. !
  138. !------------------------------------------------------------------------------
  139. !BOP
  140. ! !INTERFACE:
  141. interface operator(-)
  142. ! !PRIVATE MEMBER FUNCTIONS:
  143. module procedure ESMF_TimeDec, ESMF_TimeDec2
  144. ! !DESCRIPTION:
  145. ! This interface overloads the - operator for the {\tt ESMF\_Time} class
  146. !
  147. !EOP
  148. end interface
  149. !
  150. !------------------------------------------------------------------------------
  151. !BOP
  152. ! !INTERFACE:
  153. interface operator(-)
  154. ! !PRIVATE MEMBER FUNCTIONS:
  155. module procedure ESMF_TimeDiff
  156. ! !DESCRIPTION:
  157. ! This interface overloads the - operator for the {\tt ESMF\_Time} class
  158. !
  159. !EOP
  160. end interface
  161. !
  162. !------------------------------------------------------------------------------
  163. !BOP
  164. ! !INTERFACE:
  165. interface operator(.EQ.)
  166. ! !PRIVATE MEMBER FUNCTIONS:
  167. module procedure ESMF_TimeEQ
  168. ! !DESCRIPTION:
  169. ! This interface overloads the .EQ. operator for the {\tt ESMF\_Time} class
  170. !
  171. !EOP
  172. end interface
  173. !
  174. !------------------------------------------------------------------------------
  175. !BOP
  176. ! !INTERFACE:
  177. interface operator(.NE.)
  178. ! !PRIVATE MEMBER FUNCTIONS:
  179. module procedure ESMF_TimeNE
  180. ! !DESCRIPTION:
  181. ! This interface overloads the .NE. operator for the {\tt ESMF\_Time} class
  182. !
  183. !EOP
  184. end interface
  185. !
  186. !------------------------------------------------------------------------------
  187. !BOP
  188. ! !INTERFACE:
  189. interface operator(.LT.)
  190. ! !PRIVATE MEMBER FUNCTIONS:
  191. module procedure ESMF_TimeLT
  192. ! !DESCRIPTION:
  193. ! This interface overloads the .LT. operator for the {\tt ESMF\_Time} class
  194. !
  195. !EOP
  196. end interface
  197. !
  198. !------------------------------------------------------------------------------
  199. !BOP
  200. ! !INTERFACE:
  201. interface operator(.GT.)
  202. ! !PRIVATE MEMBER FUNCTIONS:
  203. module procedure ESMF_TimeGT
  204. ! !DESCRIPTION:
  205. ! This interface overloads the .GT. operator for the {\tt ESMF\_Time} class
  206. !
  207. !EOP
  208. end interface
  209. !
  210. !------------------------------------------------------------------------------
  211. !BOP
  212. ! !INTERFACE:
  213. interface operator(.LE.)
  214. ! !PRIVATE MEMBER FUNCTIONS:
  215. module procedure ESMF_TimeLE
  216. ! !DESCRIPTION:
  217. ! This interface overloads the .LE. operator for the {\tt ESMF\_Time} class
  218. !
  219. !EOP
  220. end interface
  221. !
  222. !------------------------------------------------------------------------------
  223. !BOP
  224. ! !INTERFACE:
  225. interface operator(.GE.)
  226. ! !PRIVATE MEMBER FUNCTIONS:
  227. module procedure ESMF_TimeGE
  228. ! !DESCRIPTION:
  229. ! This interface overloads the .GE. operator for the {\tt ESMF\_Time} class
  230. !
  231. !EOP
  232. end interface
  233. !
  234. !------------------------------------------------------------------------------
  235. !==============================================================================
  236. contains
  237. !==============================================================================
  238. !
  239. ! Generic Get/Set routines which use F90 optional arguments
  240. !
  241. !------------------------------------------------------------------------------
  242. !BOP
  243. ! !IROUTINE: ESMF_TimeGet - Get value in user-specified units
  244. ! !INTERFACE:
  245. subroutine ESMF_TimeGet(time, YY, YRl, MM, DD, D, Dl, H, M, S, Sl, MS, &
  246. US, NS, d_, h_, m_, s_, ms_, us_, ns_, Sn, Sd, &
  247. dayOfYear, dayOfYear_r8, dayOfYear_intvl, &
  248. timeString, rc)
  249. ! !ARGUMENTS:
  250. type(ESMF_Time), intent(in) :: time
  251. integer, intent(out), optional :: YY
  252. integer(ESMF_KIND_I8), intent(out), optional :: YRl
  253. integer, intent(out), optional :: MM
  254. integer, intent(out), optional :: DD
  255. integer, intent(out), optional :: D
  256. integer(ESMF_KIND_I8), intent(out), optional :: Dl
  257. integer, intent(out), optional :: H
  258. integer, intent(out), optional :: M
  259. integer, intent(out), optional :: S
  260. integer(ESMF_KIND_I8), intent(out), optional :: Sl
  261. integer, intent(out), optional :: MS
  262. integer, intent(out), optional :: US
  263. integer, intent(out), optional :: NS
  264. double precision, intent(out), optional :: d_
  265. double precision, intent(out), optional :: h_
  266. double precision, intent(out), optional :: m_
  267. double precision, intent(out), optional :: s_
  268. double precision, intent(out), optional :: ms_
  269. double precision, intent(out), optional :: us_
  270. double precision, intent(out), optional :: ns_
  271. integer, intent(out), optional :: Sn
  272. integer, intent(out), optional :: Sd
  273. integer, intent(out), optional :: dayOfYear
  274. ! dayOfYear_r8 = 1.0 at 0Z on 1 January, 1.5 at 12Z on
  275. ! 1 January, etc.
  276. real(ESMF_KIND_R8), intent(out), optional :: dayOfYear_r8
  277. character (len=*), intent(out), optional :: timeString
  278. type(ESMF_TimeInterval), intent(out), optional :: dayOfYear_intvl
  279. integer, intent(out), optional :: rc
  280. type(ESMF_TimeInterval) :: day_step
  281. integer :: ierr
  282. ! !DESCRIPTION:
  283. ! Get the value of the {\tt ESMF\_Time} in units specified by the user
  284. ! via F90 optional arguments.
  285. !
  286. ! Time manager represents and manipulates time internally with integers
  287. ! to maintain precision. Hence, user-specified floating point values are
  288. ! converted internally from integers.
  289. !
  290. ! See {\tt ../include/ESMC\_BaseTime.h and ../include/ESMC\_Time.h} for
  291. ! complete description.
  292. !
  293. ! The arguments are:
  294. ! \begin{description}
  295. ! \item[time]
  296. ! The object instance to query
  297. ! \item[{[YY]}]
  298. ! Integer year CCYR (>= 32-bit)
  299. ! \item[{[YRl]}]
  300. ! Integer year CCYR (large, >= 64-bit)
  301. ! \item[{[MM]}]
  302. ! Integer month 1-12
  303. ! \item[{[DD]}]
  304. ! Integer day of the month 1-31
  305. ! \item[{[D]}]
  306. ! Integer Julian days (>= 32-bit)
  307. ! \item[{[Dl]}]
  308. ! Integer Julian days (large, >= 64-bit)
  309. ! \item[{[H]}]
  310. ! Integer hours
  311. ! \item[{[M]}]
  312. ! Integer minutes
  313. ! \item[{[S]}]
  314. ! Integer seconds (>= 32-bit)
  315. ! \item[{[Sl]}]
  316. ! Integer seconds (large, >= 64-bit)
  317. ! \item[{[MS]}]
  318. ! Integer milliseconds
  319. ! \item[{[US]}]
  320. ! Integer microseconds
  321. ! \item[{[NS]}]
  322. ! Integer nanoseconds
  323. ! \item[{[d\_]}]
  324. ! Double precision days
  325. ! \item[{[h\_]}]
  326. ! Double precision hours
  327. ! \item[{[m\_]}]
  328. ! Double precision minutes
  329. ! \item[{[s\_]}]
  330. ! Double precision seconds
  331. ! \item[{[ms\_]}]
  332. ! Double precision milliseconds
  333. ! \item[{[us\_]}]
  334. ! Double precision microseconds
  335. ! \item[{[ns\_]}]
  336. ! Double precision nanoseconds
  337. ! \item[{[Sn]}]
  338. ! Integer fractional seconds - numerator
  339. ! \item[{[Sd]}]
  340. ! Integer fractional seconds - denominator
  341. ! \item[{[rc]}]
  342. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  343. ! \end{description}
  344. !
  345. ! !REQUIREMENTS:
  346. ! TMG2.1, TMG2.5.1, TMG2.5.6
  347. !EOP
  348. TYPE(ESMF_Time) :: begofyear
  349. INTEGER :: year, month, dayofmonth, hour, minute, second
  350. REAL(ESMF_KIND_R8) :: rsec
  351. ierr = ESMF_SUCCESS
  352. IF ( PRESENT( YY ) ) THEN
  353. YY = time%YR
  354. ENDIF
  355. IF ( PRESENT( MM ) ) THEN
  356. CALL timegetmonth( time, MM )
  357. ENDIF
  358. IF ( PRESENT( DD ) ) THEN
  359. CALL timegetdayofmonth( time, DD )
  360. ENDIF
  361. !
  362. !$$$ Push HMS down into ESMF_BaseTime from EVERYWHERE
  363. !$$$ and THEN add ESMF scaling behavior when other args are present...
  364. IF ( PRESENT( H ) ) THEN
  365. H = mod( time%basetime%S, SECONDS_PER_DAY ) / SECONDS_PER_HOUR
  366. ENDIF
  367. IF ( PRESENT( M ) ) THEN
  368. M = mod( time%basetime%S, SECONDS_PER_HOUR) / SECONDS_PER_MINUTE
  369. ENDIF
  370. IF ( PRESENT( S ) ) THEN
  371. S = mod( time%basetime%S, SECONDS_PER_MINUTE )
  372. ENDIF
  373. ! TBH: HACK to allow DD and S to behave as in ESMF 2.1.0+ when
  374. ! TBH: both are present and H and M are not.
  375. IF ( PRESENT( S ) .AND. PRESENT( DD ) ) THEN
  376. IF ( ( .NOT. PRESENT( H ) ) .AND. ( .NOT. PRESENT( M ) ) ) THEN
  377. S = mod( time%basetime%S, SECONDS_PER_DAY )
  378. ENDIF
  379. ENDIF
  380. IF ( PRESENT( MS ) ) THEN
  381. IF ( time%basetime%Sd /= 0 ) THEN
  382. MS = NINT( ( time%basetime%Sn*1.0D0 / time%basetime%Sd*1.0D0 ) * 1000.0D0 )
  383. ELSE
  384. MS = 0
  385. ENDIF
  386. ENDIF
  387. IF ( PRESENT( Sd ) .AND. PRESENT( Sn ) ) THEN
  388. Sd = time%basetime%Sd
  389. Sn = time%basetime%Sn
  390. ENDIF
  391. IF ( PRESENT( dayOfYear ) ) THEN
  392. CALL ESMF_TimeGetDayOfYear( time, dayOfYear, rc=ierr )
  393. ENDIF
  394. IF ( PRESENT( dayOfYear_r8 ) ) THEN
  395. ! 64-bit IEEE 754 has 52-bit mantisssa -- only need 25 bits to hold
  396. ! number of seconds in a year...
  397. rsec = REAL( time%basetime%S, ESMF_KIND_R8 )
  398. IF ( time%basetime%Sd /= 0 ) THEN
  399. rsec = rsec + ( REAL( time%basetime%Sn, ESMF_KIND_R8 ) / &
  400. REAL( time%basetime%Sd, ESMF_KIND_R8 ) )
  401. ENDIF
  402. dayOfYear_r8 = rsec / REAL( SECONDS_PER_DAY, ESMF_KIND_R8 )
  403. ! start at 1
  404. dayOfYear_r8 = dayOfYear_r8 + 1.0_ESMF_KIND_R8
  405. ENDIF
  406. IF ( PRESENT( timeString ) ) THEN
  407. ! This duplication for YMD is an optimization that avoids calling
  408. ! timegetmonth() and timegetdayofmonth() when it is not needed.
  409. year = time%YR
  410. CALL timegetmonth( time, month )
  411. CALL timegetdayofmonth( time, dayofmonth )
  412. !$$$ push HMS down into ESMF_BaseTime
  413. hour = mod( time%basetime%S, SECONDS_PER_DAY ) / SECONDS_PER_HOUR
  414. minute = mod( time%basetime%S, SECONDS_PER_HOUR) / SECONDS_PER_MINUTE
  415. second = mod( time%basetime%S, SECONDS_PER_MINUTE )
  416. CALL ESMFold_TimeGetString( year, month, dayofmonth, &
  417. hour, minute, second, timeString )
  418. ENDIF
  419. IF ( PRESENT( dayOfYear_intvl ) ) THEN
  420. year = time%YR
  421. CALL ESMF_TimeSet( begofyear, yy=year, mm=1, dd=1, s=0, &
  422. calendar=time%calendar, rc=ierr )
  423. IF ( ierr == ESMF_FAILURE)THEN
  424. rc = ierr
  425. RETURN
  426. END IF
  427. CALL ESMF_TimeIntervalSet( day_step, d=1, s=0, rc=ierr )
  428. dayOfYear_intvl = time - begofyear + day_step
  429. ENDIF
  430. IF ( PRESENT( rc ) ) THEN
  431. rc = ierr
  432. ENDIF
  433. end subroutine ESMF_TimeGet
  434. !------------------------------------------------------------------------------
  435. !BOP
  436. ! !IROUTINE: ESMF_TimeSet - Initialize via user-specified unit set
  437. ! !INTERFACE:
  438. subroutine ESMF_TimeSet(time, YY, YRl, MM, DD, D, Dl, H, M, S, Sl, &
  439. MS, US, NS, d_, h_, m_, s_, ms_, us_, ns_, &
  440. Sn, Sd, calendar, rc)
  441. ! !ARGUMENTS:
  442. type(ESMF_Time), intent(inout) :: time
  443. integer, intent(in), optional :: YY
  444. integer(ESMF_KIND_I8), intent(in), optional :: YRl
  445. integer, intent(in), optional :: MM
  446. integer, intent(in), optional :: DD
  447. integer, intent(in), optional :: D
  448. integer(ESMF_KIND_I8), intent(in), optional :: Dl
  449. integer, intent(in), optional :: H
  450. integer, intent(in), optional :: M
  451. integer, intent(in), optional :: S
  452. integer(ESMF_KIND_I8), intent(in), optional :: Sl
  453. integer, intent(in), optional :: MS
  454. integer, intent(in), optional :: US
  455. integer, intent(in), optional :: NS
  456. double precision, intent(in), optional :: d_
  457. double precision, intent(in), optional :: h_
  458. double precision, intent(in), optional :: m_
  459. double precision, intent(in), optional :: s_
  460. double precision, intent(in), optional :: ms_
  461. double precision, intent(in), optional :: us_
  462. double precision, intent(in), optional :: ns_
  463. integer, intent(in), optional :: Sn
  464. integer, intent(in), optional :: Sd
  465. type(ESMF_Calendar), intent(in), target, optional :: calendar
  466. integer, intent(out), optional :: rc
  467. ! locals
  468. INTEGER :: ierr
  469. ! !DESCRIPTION:
  470. ! Initializes a {\tt ESMF\_Time} with a set of user-specified units
  471. ! via F90 optional arguments.
  472. !
  473. ! Time manager represents and manipulates time internally with integers
  474. ! to maintain precision. Hence, user-specified floating point values are
  475. ! converted internally to integers.
  476. !
  477. ! See {\tt ../include/ESMC\_BaseTime.h and ../include/ESMC\_Time.h} for
  478. ! complete description.
  479. !
  480. ! The arguments are:
  481. ! \begin{description}
  482. ! \item[time]
  483. ! The object instance to initialize
  484. ! \item[{[YY]}]
  485. ! Integer year CCYR (>= 32-bit)
  486. ! \item[{[YRl]}]
  487. ! Integer year CCYR (large, >= 64-bit)
  488. ! \item[{[MM]}]
  489. ! Integer month 1-12
  490. ! \item[{[DD]}]
  491. ! Integer day of the month 1-31
  492. ! \item[{[D]}]
  493. ! Integer Julian days (>= 32-bit)
  494. ! \item[{[Dl]}]
  495. ! Integer Julian days (large, >= 64-bit)
  496. ! \item[{[H]}]
  497. ! Integer hours
  498. ! \item[{[M]}]
  499. ! Integer minutes
  500. ! \item[{[S]}]
  501. ! Integer seconds (>= 32-bit)
  502. ! \item[{[Sl]}]
  503. ! Integer seconds (large, >= 64-bit)
  504. ! \item[{[MS]}]
  505. ! Integer milliseconds
  506. ! \item[{[US]}]
  507. ! Integer microseconds
  508. ! \item[{[NS]}]
  509. ! Integer nanoseconds
  510. ! \item[{[d\_]}]
  511. ! Double precision days
  512. ! \item[{[h\_]}]
  513. ! Double precision hours
  514. ! \item[{[m\_]}]
  515. ! Double precision minutes
  516. ! \item[{[s\_]}]
  517. ! Double precision seconds
  518. ! \item[{[ms\_]}]
  519. ! Double precision milliseconds
  520. ! \item[{[us\_]}]
  521. ! Double precision microseconds
  522. ! \item[{[ns\_]}]
  523. ! Double precision nanoseconds
  524. ! \item[{[Sn]}]
  525. ! Integer fractional seconds - numerator
  526. ! \item[{[Sd]}]
  527. ! Integer fractional seconds - denominator
  528. ! \item[{[cal]}]
  529. ! Associated {\tt Calendar}
  530. ! \item[{[tz]}]
  531. ! Associated timezone (hours offset from GMT, e.g. EST = -5)
  532. ! \item[{[rc]}]
  533. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  534. ! \end{description}
  535. !
  536. ! !REQUIREMENTS:
  537. ! TMGn.n.n
  538. !EOP
  539. ! PRINT *,'DEBUG: BEGIN ESMF_TimeSet()'
  540. !$$$ push this down into ESMF_BaseTime constructor
  541. time%basetime%S = 0
  542. time%basetime%Sn = 0
  543. time%basetime%Sd = 0
  544. IF ( PRESENT( rc ) ) rc = ESMF_FAILURE
  545. time%YR = 0
  546. IF ( PRESENT( YY ) ) THEN
  547. ! PRINT *,'DEBUG: ESMF_TimeSet(): YY = ',YY
  548. time%YR = YY
  549. ENDIF
  550. IF ( PRESENT( MM ) ) THEN
  551. ! PRINT *,'DEBUG: ESMF_TimeSet(): MM = ',MM
  552. CALL timeaddmonths( time, MM, ierr )
  553. IF ( ierr == ESMF_FAILURE ) THEN
  554. IF ( PRESENT( rc ) ) THEN
  555. rc = ESMF_FAILURE
  556. RETURN
  557. ENDIF
  558. ENDIF
  559. ! PRINT *,'DEBUG: ESMF_TimeSet(): back from timeaddmonths'
  560. ENDIF
  561. IF ( PRESENT( DD ) ) THEN
  562. !$$$ no check for DD in range of days of month MM yet
  563. !$$$ Must separate D and DD for correct interface!
  564. ! PRINT *,'DEBUG: ESMF_TimeSet(): DD = ',DD
  565. time%basetime%S = time%basetime%S + &
  566. ( SECONDS_PER_DAY * INT( (DD-1), ESMF_KIND_I8 ) )
  567. ENDIF
  568. !$$$ push H,M,S,Sn,Sd,MS down into ESMF_BaseTime constructor
  569. IF ( PRESENT( H ) ) THEN
  570. ! PRINT *,'DEBUG: ESMF_TimeSet(): H = ',H
  571. time%basetime%S = time%basetime%S + &
  572. ( SECONDS_PER_HOUR * INT( H, ESMF_KIND_I8 ) )
  573. ENDIF
  574. IF ( PRESENT( M ) ) THEN
  575. ! PRINT *,'DEBUG: ESMF_TimeSet(): M = ',M
  576. time%basetime%S = time%basetime%S + &
  577. ( SECONDS_PER_MINUTE * INT( M, ESMF_KIND_I8 ) )
  578. ENDIF
  579. IF ( PRESENT( S ) ) THEN
  580. ! PRINT *,'DEBUG: ESMF_TimeSet(): S = ',S
  581. time%basetime%S = time%basetime%S + &
  582. INT( S, ESMF_KIND_I8 )
  583. ENDIF
  584. IF ( PRESENT( Sn ) .AND. ( .NOT. PRESENT( Sd ) ) ) THEN
  585. CALL wrf_error_fatal( &
  586. "ESMF_TimeSet: Must specify Sd if Sn is specified")
  587. ENDIF
  588. IF ( PRESENT( Sd ) .AND. PRESENT( MS ) ) THEN
  589. CALL wrf_error_fatal( &
  590. "ESMF_TimeSet: Must not specify both Sd and MS")
  591. ENDIF
  592. time%basetime%Sn = 0
  593. time%basetime%Sd = 0
  594. IF ( PRESENT( MS ) ) THEN
  595. ! PRINT *,'DEBUG: ESMF_TimeSet(): MS = ',MS
  596. time%basetime%Sn = MS
  597. time%basetime%Sd = 1000_ESMF_KIND_I8
  598. ELSE IF ( PRESENT( Sd ) ) THEN
  599. ! PRINT *,'DEBUG: ESMF_TimeSet(): Sd = ',Sd
  600. time%basetime%Sd = Sd
  601. IF ( PRESENT( Sn ) ) THEN
  602. ! PRINT *,'DEBUG: ESMF_TimeSet(): Sn = ',Sn
  603. time%basetime%Sn = Sn
  604. ENDIF
  605. ENDIF
  606. IF ( PRESENT(calendar) )THEN
  607. ! PRINT *,'DEBUG: ESMF_TimeSet(): using passed-in calendar'
  608. ! Note that the ugly hack of wrapping the call to ESMF_CalendarInitialized()
  609. ! inside this #ifdef is due to lack of support for compile-time initialization
  610. ! of components of Fortran derived types. Some older compilers like PGI 5.1-x
  611. ! do not support this F95 feature. In this case we only lose a safety check.
  612. #ifndef NO_DT_COMPONENT_INIT
  613. IF ( .not. ESMF_CalendarInitialized( calendar ) )THEN
  614. call wrf_error_fatal( "Error:: ESMF_CalendarCreate not "// &
  615. "called on input Calendar")
  616. END IF
  617. #endif
  618. time%Calendar => calendar
  619. ELSE
  620. ! PRINT *,'DEBUG: ESMF_TimeSet(): using default calendar'
  621. IF ( .not. ESMF_IsInitialized() )THEN
  622. call wrf_error_fatal( "Error:: ESMF_Initialize not called")
  623. END IF
  624. time%Calendar => defaultCal
  625. END IF
  626. ! PRINT *,'DEBUG: ESMF_TimeSet(): calling normalize_time()'
  627. !$$$DEBUG
  628. !IF ( time%basetime%Sd > 0 ) THEN
  629. ! PRINT *,'DEBUG ESMF_TimeSet() before normalize: S,Sn,Sd = ', &
  630. ! time%basetime%S, time%basetime%Sn, time%basetime%Sd
  631. !ENDIF
  632. !$$$END DEBUG
  633. CALL normalize_time( time )
  634. !$$$DEBUG
  635. !IF ( time%basetime%Sd > 0 ) THEN
  636. ! PRINT *,'DEBUG ESMF_TimeSet() after normalize: S,Sn,Sd = ', &
  637. ! time%basetime%S, time%basetime%Sn, time%basetime%Sd
  638. !ENDIF
  639. !$$$END DEBUG
  640. ! PRINT *,'DEBUG: ESMF_TimeSet(): back from normalize_time()'
  641. IF ( PRESENT( rc ) ) THEN
  642. rc = ESMF_SUCCESS
  643. ENDIF
  644. end subroutine ESMF_TimeSet
  645. !------------------------------------------------------------------------------
  646. !BOP
  647. ! !IROUTINE: ESMFold_TimeGetString - Get time instant value in string format
  648. ! !INTERFACE:
  649. subroutine ESMFold_TimeGetString( year, month, dayofmonth, &
  650. hour, minute, second, TimeString )
  651. ! !ARGUMENTS:
  652. integer, intent(in) :: year
  653. integer, intent(in) :: month
  654. integer, intent(in) :: dayofmonth
  655. integer, intent(in) :: hour
  656. integer, intent(in) :: minute
  657. integer, intent(in) :: second
  658. character*(*), intent(out) :: TimeString
  659. ! !DESCRIPTION:
  660. ! Convert {\tt ESMF\_Time}'s value into ISO 8601 format YYYY-MM-DDThh:mm:ss
  661. !
  662. ! The arguments are:
  663. ! \begin{description}
  664. ! \item[time]
  665. ! The object instance to convert
  666. ! \item[TimeString]
  667. ! The string to return
  668. ! \item[{[rc]}]
  669. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  670. ! \end{description}
  671. !
  672. ! !REQUIREMENTS:
  673. ! TMG2.4.7
  674. !EOP
  675. !PRINT *,'DEBUG: ESMF_TimePrint(): YR,S,Sn,Sd = ',time%YR,time%basetime%S,time%basetime%Sn,time%basetime%Sd
  676. !PRINT *,'DEBUG: ESMF_TimePrint(): year = ',year
  677. !PRINT *,'DEBUG: ESMF_TimePrint(): month, dayofmonth = ',month,dayofmonth
  678. !PRINT *,'DEBUG: ESMF_TimePrint(): hour = ',hour
  679. !PRINT *,'DEBUG: ESMF_TimePrint(): minute = ',minute
  680. !PRINT *,'DEBUG: ESMF_TimePrint(): second = ',second
  681. !$$$here... add negative sign for YR<0
  682. !$$$here... add Sn, Sd ??
  683. #ifdef PLANET
  684. write(TimeString,FMT="(I4.4,'-',I5.5,'_',I2.2,':',I2.2,':',I2.2)") &
  685. year,dayofmonth,hour,minute,second
  686. #else
  687. write(TimeString,FMT="(I4.4,'-',I2.2,'-',I2.2,'_',I2.2,':',I2.2,':',I2.2)") &
  688. year,month,dayofmonth,hour,minute,second
  689. #endif
  690. end subroutine ESMFold_TimeGetString
  691. !------------------------------------------------------------------------------
  692. !BOP
  693. ! !IROUTINE: ESMF_TimeGetDayOfYearInteger - Get time instant's day of the year as an integer value
  694. !
  695. ! !INTERFACE:
  696. subroutine ESMF_TimeGetDayOfYearInteger(time, DayOfYear, rc)
  697. !
  698. ! !ARGUMENTS:
  699. type(ESMF_Time), intent(in) :: time
  700. integer, intent(out) :: DayOfYear
  701. integer, intent(out), optional :: rc
  702. !
  703. ! !DESCRIPTION:
  704. ! Get the day of the year the given {\tt ESMF\_Time} instant falls on
  705. ! (1-365). Returned as an integer value
  706. !
  707. ! The arguments are:
  708. ! \begin{description}
  709. ! \item[time]
  710. ! The object instance to query
  711. ! \item[DayOfYear]
  712. ! The {\tt ESMF\_Time} instant's day of the year (1-365)
  713. ! \item[{[rc]}]
  714. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  715. ! \end{description}
  716. !
  717. ! !REQUIREMENTS:
  718. !EOP
  719. ! requires that time be normalized
  720. !$$$ bug when Sn>0? test
  721. !$$$ add tests
  722. DayOfYear = ( time%basetime%S / SECONDS_PER_DAY ) + 1
  723. IF ( PRESENT( rc ) ) rc = ESMF_SUCCESS
  724. end subroutine ESMF_TimeGetDayOfYearInteger
  725. !------------------------------------------------------------------------------
  726. !BOP
  727. ! !IROUTINE: ESMF_TimeInc - Increment time instant with a time interval
  728. !
  729. ! !INTERFACE:
  730. function ESMF_TimeInc(time, timeinterval)
  731. !
  732. ! !RETURN VALUE:
  733. type(ESMF_Time) :: ESMF_TimeInc
  734. !
  735. ! !ARGUMENTS:
  736. type(ESMF_Time), intent(in) :: time
  737. type(ESMF_TimeInterval), intent(in) :: timeinterval
  738. ! !LOCAL:
  739. integer :: rc
  740. !
  741. ! !DESCRIPTION:
  742. ! Increment {\tt ESMF\_Time} instant with a {\tt ESMF\_TimeInterval},
  743. ! return resulting {\tt ESMF\_Time} instant
  744. !
  745. ! Maps overloaded (+) operator interface function to
  746. ! {\tt ESMF\_BaseTime} base class
  747. !
  748. ! The arguments are:
  749. ! \begin{description}
  750. ! \item[time]
  751. ! The given {\tt ESMF\_Time} to increment
  752. ! \item[timeinterval]
  753. ! The {\tt ESMF\_TimeInterval} to add to the given {\tt ESMF\_Time}
  754. ! \end{description}
  755. !
  756. ! !REQUIREMENTS:
  757. ! TMG1.5.4, TMG2.4.4, TMG2.4.5, TMG2.4.6, TMG5.1, TMG5.2, TMG7.2
  758. !EOP
  759. ! copy ESMF_Time specific properties (e.g. calendar, timezone)
  760. ESMF_TimeInc = time
  761. ! call ESMC_BaseTime base class function
  762. call c_ESMC_BaseTimeSum(time, timeinterval, ESMF_TimeInc)
  763. end function ESMF_TimeInc
  764. !
  765. ! this is added for certain compilers that don't deal with commutativity
  766. !
  767. function ESMF_TimeInc2(timeinterval, time)
  768. type(ESMF_Time) :: ESMF_TimeInc2
  769. type(ESMF_Time), intent(in) :: time
  770. type(ESMF_TimeInterval), intent(in) :: timeinterval
  771. ESMF_TimeInc2 = ESMF_TimeInc( time, timeinterval )
  772. end function ESMF_TimeInc2
  773. !
  774. !------------------------------------------------------------------------------
  775. !BOP
  776. ! !IROUTINE: ESMF_TimeDec - Decrement time instant with a time interval
  777. !
  778. ! !INTERFACE:
  779. function ESMF_TimeDec(time, timeinterval)
  780. !
  781. ! !RETURN VALUE:
  782. type(ESMF_Time) :: ESMF_TimeDec
  783. !
  784. ! !ARGUMENTS:
  785. type(ESMF_Time), intent(in) :: time
  786. type(ESMF_TimeInterval), intent(in) :: timeinterval
  787. ! !LOCAL:
  788. integer :: rc
  789. !
  790. ! !DESCRIPTION:
  791. ! Decrement {\tt ESMF\_Time} instant with a {\tt ESMF\_TimeInterval},
  792. ! return resulting {\tt ESMF\_Time} instant
  793. !
  794. ! Maps overloaded (-) operator interface function to
  795. ! {\tt ESMF\_BaseTime} base class
  796. !
  797. ! The arguments are:
  798. ! \begin{description}
  799. ! \item[time]
  800. ! The given {\tt ESMF\_Time} to decrement
  801. ! \item[timeinterval]
  802. ! The {\tt ESMF\_TimeInterval} to subtract from the given
  803. ! {\tt ESMF\_Time}
  804. ! \end{description}
  805. !
  806. ! !REQUIREMENTS:
  807. ! TMG1.5.4, TMG2.4.4, TMG2.4.5, TMG2.4.6, TMG5.1, TMG5.2, TMG7.2
  808. !EOP
  809. ! copy ESMF_Time specific properties (e.g. calendar, timezone)
  810. ESMF_TimeDec = time
  811. ! call ESMC_BaseTime base class function
  812. call c_ESMC_BaseTimeDec(time, timeinterval, ESMF_TimeDec)
  813. end function ESMF_TimeDec
  814. !
  815. ! this is added for certain compilers that don't deal with commutativity
  816. !
  817. function ESMF_TimeDec2(timeinterval, time)
  818. type(ESMF_Time) :: ESMF_TimeDec2
  819. type(ESMF_Time), intent(in) :: time
  820. type(ESMF_TimeInterval), intent(in) :: timeinterval
  821. ESMF_TimeDec2 = ESMF_TimeDec( time, timeinterval )
  822. end function ESMF_TimeDec2
  823. !
  824. !------------------------------------------------------------------------------
  825. !BOP
  826. ! !IROUTINE: ESMF_TimeDiff - Return the difference between two time instants
  827. !
  828. ! !INTERFACE:
  829. function ESMF_TimeDiff(time1, time2)
  830. !
  831. ! !RETURN VALUE:
  832. type(ESMF_TimeInterval) :: ESMF_TimeDiff
  833. !
  834. ! !ARGUMENTS:
  835. type(ESMF_Time), intent(in) :: time1
  836. type(ESMF_Time), intent(in) :: time2
  837. ! !LOCAL:
  838. integer :: rc
  839. ! !DESCRIPTION:
  840. ! Return the {\tt ESMF\_TimeInterval} difference between two
  841. ! {\tt ESMF\_Time} instants
  842. !
  843. ! Maps overloaded (-) operator interface function to
  844. ! {\tt ESMF\_BaseTime} base class
  845. !
  846. ! The arguments are:
  847. ! \begin{description}
  848. ! \item[time1]
  849. ! The first {\tt ESMF\_Time} instant
  850. ! \item[time2]
  851. ! The second {\tt ESMF\_Time} instant
  852. ! \end{description}
  853. !
  854. ! !REQUIREMENTS:
  855. ! TMG1.5.4, TMG2.4.4, TMG2.4.5, TMG2.4.6, TMG5.1, TMG5.2, TMG7.2
  856. !EOP
  857. ! call ESMC_BaseTime base class function
  858. CALL ESMF_TimeIntervalSet( ESMF_TimeDiff, rc=rc )
  859. call c_ESMC_BaseTimeDiff(time1, time2, ESMF_TimeDiff)
  860. end function ESMF_TimeDiff
  861. !------------------------------------------------------------------------------
  862. !BOP
  863. ! !IROUTINE: ESMF_TimeEQ - Compare two times for equality
  864. !
  865. ! !INTERFACE:
  866. function ESMF_TimeEQ(time1, time2)
  867. !
  868. ! !RETURN VALUE:
  869. logical :: ESMF_TimeEQ
  870. !
  871. ! !ARGUMENTS:
  872. type(ESMF_Time), intent(in) :: time1
  873. type(ESMF_Time), intent(in) :: time2
  874. !
  875. ! !DESCRIPTION:
  876. ! Return true if both given {\tt ESMF\_Time} instants are equal, false
  877. ! otherwise. Maps overloaded (==) operator interface function to
  878. ! {\tt ESMF\_BaseTime} base class.
  879. !
  880. ! The arguments are:
  881. ! \begin{description}
  882. ! \item[time1]
  883. ! First time instant to compare
  884. ! \item[time2]
  885. ! Second time instant to compare
  886. ! \end{description}
  887. !
  888. ! !REQUIREMENTS:
  889. ! TMG1.5.3, TMG2.4.3, TMG7.2
  890. !EOP
  891. ! invoke C to C++ entry point for ESMF_BaseTime base class function
  892. call c_ESMC_BaseTimeEQ(time1, time2, ESMF_TimeEQ)
  893. end function ESMF_TimeEQ
  894. !------------------------------------------------------------------------------
  895. !BOP
  896. ! !IROUTINE: ESMF_TimeNE - Compare two times for non-equality
  897. !
  898. ! !INTERFACE:
  899. function ESMF_TimeNE(time1, time2)
  900. !
  901. ! !RETURN VALUE:
  902. logical :: ESMF_TimeNE
  903. !
  904. ! !ARGUMENTS:
  905. type(ESMF_Time), intent(in) :: time1
  906. type(ESMF_Time), intent(in) :: time2
  907. ! !DESCRIPTION:
  908. ! Return true if both given {\tt ESMF\_Time} instants are not equal, false
  909. ! otherwise. Maps overloaded (/=) operator interface function to
  910. ! {\tt ESMF\_BaseTime} base class.
  911. !
  912. ! The arguments are:
  913. ! \begin{description}
  914. ! \item[time1]
  915. ! First time instant to compare
  916. ! \item[time2]
  917. ! Second time instant to compare
  918. ! \end{description}
  919. !
  920. ! !REQUIREMENTS:
  921. ! TMG1.5.3, TMG2.4.3, TMG7.2
  922. !EOP
  923. ! call ESMC_BaseTime base class function
  924. call c_ESMC_BaseTimeNE(time1, time2, ESMF_TimeNE)
  925. end function ESMF_TimeNE
  926. !------------------------------------------------------------------------------
  927. !BOP
  928. ! !IROUTINE: ESMF_TimeLT - Time instant 1 less than time instant 2 ?
  929. !
  930. ! !INTERFACE:
  931. function ESMF_TimeLT(time1, time2)
  932. !
  933. ! !RETURN VALUE:
  934. logical :: ESMF_TimeLT
  935. !
  936. ! !ARGUMENTS:
  937. type(ESMF_Time), intent(in) :: time1
  938. type(ESMF_Time), intent(in) :: time2
  939. !
  940. ! !DESCRIPTION:
  941. ! Return true if first {\tt ESMF\_Time} instant is less than second
  942. ! {\tt ESMF\_Time} instant, false otherwise. Maps overloaded (<)
  943. ! operator interface function to {\tt ESMF\_BaseTime} base class.
  944. !
  945. ! The arguments are:
  946. ! \begin{description}
  947. ! \item[time1]
  948. ! First time instant to compare
  949. ! \item[time2]
  950. ! Second time instant to compare
  951. ! \end{description}
  952. !
  953. ! !REQUIREMENTS:
  954. ! TMG1.5.3, TMG2.4.3, TMG7.2
  955. !EOP
  956. ! call ESMC_BaseTime base class function
  957. call c_ESMC_BaseTimeLT(time1, time2, ESMF_TimeLT)
  958. end function ESMF_TimeLT
  959. !------------------------------------------------------------------------------
  960. !BOP
  961. ! !IROUTINE: ESMF_TimeGT - Time instant 1 greater than time instant 2 ?
  962. !
  963. ! !INTERFACE:
  964. function ESMF_TimeGT(time1, time2)
  965. !
  966. ! !RETURN VALUE:
  967. logical :: ESMF_TimeGT
  968. !
  969. ! !ARGUMENTS:
  970. type(ESMF_Time), intent(in) :: time1
  971. type(ESMF_Time), intent(in) :: time2
  972. !
  973. ! !DESCRIPTION:
  974. ! Return true if first {\tt ESMF\_Time} instant is greater than second
  975. ! {\tt ESMF\_Time} instant, false otherwise. Maps overloaded (>) operator
  976. ! interface function to {\tt ESMF\_BaseTime} base class.
  977. !
  978. ! The arguments are:
  979. ! \begin{description}
  980. ! \item[time1]
  981. ! First time instant to compare
  982. ! \item[time2]
  983. ! Second time instant to compare
  984. ! \end{description}
  985. !
  986. ! !REQUIREMENTS:
  987. ! TMG1.5.3, TMG2.4.3, TMG7.2
  988. !EOP
  989. ! call ESMC_BaseTime base class function
  990. call c_ESMC_BaseTimeGT(time1, time2, ESMF_TimeGT)
  991. end function ESMF_TimeGT
  992. !------------------------------------------------------------------------------
  993. !BOP
  994. ! !IROUTINE: ESMF_TimeLE - Time instant 1 less than or equal to time instant 2 ?
  995. !
  996. ! !INTERFACE:
  997. function ESMF_TimeLE(time1, time2)
  998. !
  999. ! !RETURN VALUE:
  1000. logical :: ESMF_TimeLE
  1001. !
  1002. ! !ARGUMENTS:
  1003. type(ESMF_Time), intent(in) :: time1
  1004. type(ESMF_Time), intent(in) :: time2
  1005. !
  1006. ! !DESCRIPTION:
  1007. ! Return true if first {\tt ESMF\_Time} instant is less than or equal to
  1008. ! second {\tt ESMF\_Time} instant, false otherwise. Maps overloaded (<=)
  1009. ! operator interface function to {\tt ESMF\_BaseTime} base class.
  1010. !
  1011. ! The arguments are:
  1012. ! \begin{description}
  1013. ! \item[time1]
  1014. ! First time instant to compare
  1015. ! \item[time2]
  1016. ! Second time instant to compare
  1017. ! \end{description}
  1018. !
  1019. ! !REQUIREMENTS:
  1020. ! TMG1.5.3, TMG2.4.3, TMG7.2
  1021. !EOP
  1022. ! call ESMC_BaseTime base class function
  1023. call c_ESMC_BaseTimeLE(time1, time2, ESMF_TimeLE)
  1024. end function ESMF_TimeLE
  1025. !------------------------------------------------------------------------------
  1026. !BOP
  1027. ! !IROUTINE: ESMF_TimeGE - Time instant 1 greater than or equal to time instant 2 ?
  1028. !
  1029. ! !INTERFACE:
  1030. function ESMF_TimeGE(time1, time2)
  1031. !
  1032. ! !RETURN VALUE:
  1033. logical :: ESMF_TimeGE
  1034. !
  1035. ! !ARGUMENTS:
  1036. type(ESMF_Time), intent(in) :: time1
  1037. type(ESMF_Time), intent(in) :: time2
  1038. !
  1039. ! !DESCRIPTION:
  1040. ! Return true if first {\tt ESMF\_Time} instant is greater than or equal to
  1041. ! second {\tt ESMF\_Time} instant, false otherwise. Maps overloaded (>=)
  1042. ! operator interface function to {\tt ESMF\_BaseTime} base class.
  1043. !
  1044. ! The arguments are:
  1045. ! \begin{description}
  1046. ! \item[time1]
  1047. ! First time instant to compare
  1048. ! \item[time2]
  1049. ! Second time instant to compare
  1050. ! \end{description}
  1051. !
  1052. ! !REQUIREMENTS:
  1053. ! TMG1.5.3, TMG2.4.3, TMG7.2
  1054. !EOP
  1055. ! call ESMC_BaseTime base class function
  1056. call c_ESMC_BaseTimeGE(time1, time2, ESMF_TimeGE)
  1057. end function ESMF_TimeGE
  1058. !------------------------------------------------------------------------------
  1059. !BOP
  1060. ! !IROUTINE: ESMF_TimeCopy - Copy a time-instance
  1061. ! !INTERFACE:
  1062. subroutine ESMF_TimeCopy(timeout, timein)
  1063. ! !ARGUMENTS:
  1064. type(ESMF_Time), intent(out) :: timeout
  1065. type(ESMF_Time), intent(in) :: timein
  1066. ! !DESCRIPTION:
  1067. ! Copy a time-instance to a new instance.
  1068. !
  1069. ! \item[{[rc]}]
  1070. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  1071. ! \end{description}
  1072. !
  1073. ! !REQUIREMENTS:
  1074. ! TMGn.n.n
  1075. !EOP
  1076. timeout%basetime = timein%basetime
  1077. timeout%YR = timein%YR
  1078. timeout%Calendar => timein%Calendar
  1079. end subroutine ESMF_TimeCopy
  1080. end module ESMF_TimeMod