PageRenderTime 55ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/wrfv2_fire/external/esmf_time_f90/ESMF_Clock.F90

http://github.com/jbeezley/wrf-fire
FORTRAN Modern | 1350 lines | 465 code | 156 blank | 729 comment | 2 complexity | 264a48feda1c560c9eaee3588258429e 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 Clock Module
  13. module ESMF_ClockMod
  14. !
  15. !==============================================================================
  16. !
  17. ! This file contains the Clock class definition and all Clock class methods.
  18. !
  19. !------------------------------------------------------------------------------
  20. ! INCLUDES
  21. #include <ESMF_TimeMgr.inc>
  22. !==============================================================================
  23. !BOPI
  24. ! !MODULE: ESMF_ClockMod
  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\_Clock.h} for complete description
  33. !
  34. !------------------------------------------------------------------------------
  35. ! !USES:
  36. ! inherit from ESMF base class
  37. use ESMF_BaseMod
  38. ! associated derived types
  39. use ESMF_TimeIntervalMod ! , only : ESMF_TimeInterval, &
  40. ! ESMF_TimeIntervalIsPositive
  41. use ESMF_TimeMod ! , only : ESMF_Time
  42. use ESMF_AlarmMod, only : ESMF_Alarm
  43. implicit none
  44. !
  45. !------------------------------------------------------------------------------
  46. ! !PRIVATE TYPES:
  47. private
  48. !------------------------------------------------------------------------------
  49. ! ! ESMF_Clock
  50. !
  51. ! ! F90 class type to match C++ Clock class in size only;
  52. ! ! all dereferencing within class is performed by C++ implementation
  53. ! internals for ESMF_Clock
  54. type ESMF_ClockInt
  55. type(ESMF_TimeInterval) :: TimeStep
  56. type(ESMF_Time) :: StartTime
  57. type(ESMF_Time) :: StopTime
  58. type(ESMF_Time) :: RefTime
  59. type(ESMF_Time) :: CurrTime
  60. type(ESMF_Time) :: PrevTime
  61. integer(ESMF_KIND_I8) :: AdvanceCount
  62. integer :: ClockMutex
  63. integer :: NumAlarms
  64. ! Note: to mimic ESMF 2.1.0+, AlarmList is maintained
  65. ! within ESMF_Clock even though copies of each alarm are
  66. ! returned from ESMF_AlarmCreate() at the same time they
  67. ! are copied into the AlarmList! This duplication is not
  68. ! as hideous as it might be because the ESMF_Alarm type
  69. ! has data members that are all POINTERs (thus the horrible
  70. ! shallow-copy-masquerading-as-reference-copy hack works).
  71. type(ESMF_Alarm), pointer, dimension(:) :: AlarmList
  72. end type
  73. ! Actual public type: this bit allows easy mimic of "deep" ESMF_ClockCreate
  74. ! in ESMF 2.1.0+
  75. ! NOTE: DO NOT ADD NON-POINTER STATE TO THIS DATA TYPE. It emulates ESMF
  76. ! shallow-copy-masquerading-as-reference-copy.
  77. type ESMF_Clock
  78. type(ESMF_ClockInt), pointer :: clockint
  79. end type
  80. !------------------------------------------------------------------------------
  81. ! !PUBLIC TYPES:
  82. public ESMF_Clock
  83. public ESMF_ClockInt ! needed on AIX but not PGI
  84. !------------------------------------------------------------------------------
  85. !
  86. ! !PUBLIC MEMBER FUNCTIONS:
  87. public ESMF_ClockCreate
  88. public ESMF_ClockDestroy
  89. public ESMF_ClockSet
  90. ! public ESMF_ClockSetOLD
  91. public ESMF_ClockGet
  92. ! public ESMF_ClockGetAdvanceCount
  93. ! public ESMF_ClockGetTimeStep
  94. ! public ESMF_ClockSetTimeStep
  95. ! public ESMF_ClockGetCurrTime
  96. ! public ESMF_ClockSetCurrTime
  97. ! public ESMF_ClockGetStartTime
  98. ! public ESMF_ClockGetStopTime
  99. ! public ESMF_ClockGetRefTime
  100. ! public ESMF_ClockGetPrevTime
  101. ! public ESMF_ClockGetCurrSimTime
  102. ! public ESMF_ClockGetPrevSimTime
  103. ! This must be public for ESMF_AlarmClockMod...
  104. public ESMF_ClockAddAlarm
  105. public ESMF_ClockGetAlarmList
  106. ! public ESMF_ClockGetNumAlarms
  107. ! public ESMF_ClockSyncToWallClock
  108. public ESMF_ClockAdvance
  109. public ESMF_ClockIsStopTime
  110. public ESMF_ClockStopTimeDisable
  111. ! Required inherited and overridden ESMF_Base class methods
  112. ! public ESMF_ClockRead
  113. ! public ESMF_ClockWrite
  114. public ESMF_ClockValidate
  115. public ESMF_ClockPrint
  116. !EOPI
  117. !==============================================================================
  118. contains
  119. !==============================================================================
  120. !
  121. ! This section includes the Set methods.
  122. !
  123. !------------------------------------------------------------------------------
  124. !BOP
  125. ! !IROUTINE: ESMF_ClockSetOLD - Initialize a clockint
  126. ! !INTERFACE:
  127. subroutine ESMF_ClockSetOLD(clockint, TimeStep, StartTime, &
  128. StopTime, RefTime, rc)
  129. ! !ARGUMENTS:
  130. type(ESMF_ClockInt), intent(out) :: clockint
  131. type(ESMF_TimeInterval), intent(in), optional :: TimeStep
  132. type(ESMF_Time), intent(in) :: StartTime
  133. type(ESMF_Time), intent(in) :: StopTime
  134. type(ESMF_Time), intent(in), optional :: RefTime
  135. integer, intent(out), optional :: rc
  136. ! Local
  137. integer i
  138. ! !DESCRIPTION:
  139. ! Initialize an {\tt ESMF\_Clock}
  140. !
  141. ! The arguments are:
  142. ! \begin{description}
  143. ! \item[clockint]
  144. ! The object instance to initialize
  145. ! \item[{[TimeStep]}]
  146. ! The {\tt ESMF\_Clock}'s time step interval
  147. ! \item[StartTime]
  148. ! The {\tt ESMF\_Clock}'s starting time
  149. ! \item[StopTime]
  150. ! The {\tt ESMF\_Clock}'s stopping time
  151. ! \item[{[RefTime]}]
  152. ! The {\tt ESMF\_Clock}'s reference time
  153. ! \item[{[rc]}]
  154. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  155. ! \end{description}
  156. !
  157. ! !REQUIREMENTS:
  158. ! TMG3.1, TMG3.4.4
  159. !EOP
  160. IF ( PRESENT(TimeStep) ) clockint%TimeStep = TimeStep
  161. IF ( PRESENT(RefTime) )THEN
  162. clockint%RefTime = RefTime
  163. ELSE
  164. clockint%RefTime = StartTime
  165. END IF
  166. clockint%CurrTime = StartTime
  167. clockint%StartTime = StartTime
  168. clockint%StopTime = StopTime
  169. clockint%NumAlarms = 0
  170. clockint%AdvanceCount = 0
  171. ALLOCATE(clockint%AlarmList(MAX_ALARMS))
  172. ! TBH: This incredible hack can be removed once ESMF_*Validate()
  173. ! TBH: can tell if a deep ESMF_* was created or not.
  174. DO i = 1, MAX_ALARMS
  175. NULLIFY( clockint%AlarmList( i )%alarmint )
  176. ENDDO
  177. IF ( PRESENT( rc ) ) rc = ESMF_SUCCESS
  178. end subroutine ESMF_ClockSetOLD
  179. ! !IROUTINE: ESMF_ClockSet - Set clock properties -- for compatibility with ESMF 2.0.1
  180. ! !INTERFACE:
  181. subroutine ESMF_ClockSet(clock, TimeStep, StartTime, StopTime, &
  182. RefTime, CurrTime, rc)
  183. ! !ARGUMENTS:
  184. type(ESMF_Clock), intent(inout) :: clock
  185. type(ESMF_TimeInterval), intent(in), optional :: TimeStep
  186. type(ESMF_Time), intent(in), optional :: StartTime
  187. type(ESMF_Time), intent(in), optional :: StopTime
  188. type(ESMF_Time), intent(in), optional :: RefTime
  189. type(ESMF_Time), intent(in), optional :: CurrTime
  190. integer, intent(out), optional :: rc
  191. ! Local
  192. integer ierr
  193. ! !DESCRIPTION:
  194. ! Initialize an {\tt ESMF\_Clock}
  195. !
  196. ! The arguments are:
  197. ! \begin{description}
  198. ! \item[clock]
  199. ! The object instance to initialize
  200. ! \item[{[TimeStep]}]
  201. ! The {\tt ESMF\_Clock}'s time step interval
  202. ! \item[StartTime]
  203. ! The {\tt ESMF\_Clock}'s starting time
  204. ! \item[StopTime]
  205. ! The {\tt ESMF\_Clock}'s stopping time
  206. ! \item[{[RefTime]}]
  207. ! The {\tt ESMF\_Clock}'s reference time
  208. ! \item[{[rc]}]
  209. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  210. ! \end{description}
  211. !
  212. ! !REQUIREMENTS:
  213. ! TMG3.1, TMG3.4.4
  214. !EOP
  215. ierr = ESMF_SUCCESS
  216. IF ( PRESENT(TimeStep) ) THEN
  217. CALL ESMF_ClockSetTimeStep ( clock, TimeStep, rc=ierr )
  218. ENDIF
  219. IF ( PRESENT(RefTime) ) clock%clockint%RefTime = RefTime
  220. IF ( PRESENT(StartTime) ) clock%clockint%StartTime = StartTime
  221. IF ( PRESENT(StopTime) ) clock%clockint%StopTime = StopTime
  222. IF ( PRESENT(CurrTime) ) THEN
  223. CALL ESMF_ClockSetCurrTime(clock, CurrTime, rc=ierr)
  224. ENDIF
  225. IF ( PRESENT(rc) ) rc = ierr
  226. end subroutine ESMF_ClockSet
  227. ! Create ESMF_Clock using ESMF 2.1.0+ semantics
  228. FUNCTION ESMF_ClockCreate( name, TimeStep, StartTime, StopTime, &
  229. RefTime, rc )
  230. ! return value
  231. type(ESMF_Clock) :: ESMF_ClockCreate
  232. ! !ARGUMENTS:
  233. character (len=*), intent(in), optional :: name
  234. type(ESMF_TimeInterval), intent(in), optional :: TimeStep
  235. type(ESMF_Time), intent(in) :: StartTime
  236. type(ESMF_Time), intent(in) :: StopTime
  237. type(ESMF_Time), intent(in), optional :: RefTime
  238. integer, intent(out), optional :: rc
  239. ! locals
  240. type(ESMF_Clock) :: clocktmp
  241. ! TBH: ignore allocate errors, for now
  242. ALLOCATE( clocktmp%clockint )
  243. CALL ESMF_ClockSetOLD( clocktmp%clockint, &
  244. TimeStep= TimeStep, &
  245. StartTime=StartTime, &
  246. StopTime= StopTime, &
  247. RefTime=RefTime, rc=rc )
  248. ESMF_ClockCreate = clocktmp
  249. END FUNCTION ESMF_ClockCreate
  250. ! Deallocate memory for ESMF_Clock
  251. SUBROUTINE ESMF_ClockDestroy( clock, rc )
  252. TYPE(ESMF_Clock), INTENT(INOUT) :: clock
  253. INTEGER, INTENT( OUT), OPTIONAL :: rc
  254. ! TBH: ignore deallocate errors, for now
  255. DEALLOCATE( clock%clockint%AlarmList )
  256. DEALLOCATE( clock%clockint )
  257. IF ( PRESENT( rc ) ) rc = ESMF_SUCCESS
  258. END SUBROUTINE ESMF_ClockDestroy
  259. !------------------------------------------------------------------------------
  260. !BOP
  261. ! !IROUTINE: ESMF_ClockGet - Get clock properties -- for compatibility with ESMF 2.0.1
  262. ! !INTERFACE:
  263. subroutine ESMF_ClockGet(clock, StartTime, CurrTime, &
  264. AdvanceCount, StopTime, TimeStep, &
  265. PrevTime, RefTime, &
  266. rc)
  267. ! !ARGUMENTS:
  268. type(ESMF_Clock), intent(in) :: clock
  269. type(ESMF_Time), intent(out), optional :: StartTime
  270. type(ESMF_Time), intent(out), optional :: CurrTime
  271. type(ESMF_Time), intent(out), optional :: StopTime
  272. type(ESMF_Time), intent(out), optional :: PrevTime
  273. type(ESMF_Time), intent(out), optional :: RefTime
  274. integer(ESMF_KIND_I8), intent(out), optional :: AdvanceCount
  275. type(ESMF_TimeInterval), intent(out), optional :: TimeStep
  276. integer, intent(out), optional :: rc
  277. integer :: ierr
  278. ! !DESCRIPTION:
  279. ! Returns the number of times the {\tt ESMF\_Clock} has been advanced
  280. ! (time stepped)
  281. !
  282. ! The arguments are:
  283. ! \begin{description}
  284. ! \item[clock]
  285. ! The object instance to get the advance count from
  286. ! \item[StartTime]
  287. ! The start time
  288. ! \item[CurrTime]
  289. ! The current time
  290. ! \item[AdvanceCount]
  291. ! The number of times the {\tt ESMF\_Clock} has been advanced
  292. ! \item[StopTime]
  293. ! The {\tt ESMF\_Clock}'s stopping time
  294. ! \item[{[TimeStep]}]
  295. ! The {\tt ESMF\_Clock}'s time step interval
  296. ! \item[{[PrevTime]}]
  297. ! The {\tt ESMF\_Clock}'s previous current time
  298. ! \item[{[PrevTime]}]
  299. ! The {\tt ESMF\_Clock}'s reference time
  300. ! \item[{[rc]}]
  301. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  302. ! \end{description}
  303. ! !REQUIREMENTS:
  304. ! TMG3.5.1
  305. !EOP
  306. ierr = ESMF_SUCCESS
  307. IF ( PRESENT (StartTime) ) THEN
  308. CALL ESMF_ClockGetStartTime( clock, StartTime=StartTime, rc=ierr )
  309. ENDIF
  310. IF ( PRESENT (CurrTime) ) THEN
  311. CALL ESMF_ClockGetCurrTime( clock , CurrTime, ierr )
  312. ENDIF
  313. IF ( PRESENT (StopTime) ) THEN
  314. CALL ESMF_ClockGetStopTime( clock , StopTime, ierr )
  315. ENDIF
  316. IF ( PRESENT (AdvanceCount) ) THEN
  317. CALL ESMF_ClockGetAdvanceCount(clock, AdvanceCount, ierr)
  318. ENDIF
  319. IF ( PRESENT (TimeStep) ) THEN
  320. CALL ESMF_ClockGetTimeStep(clock, TimeStep, ierr)
  321. ENDIF
  322. IF ( PRESENT (PrevTime) ) THEN
  323. CALL ESMF_ClockGetPrevTime(clock, PrevTime, ierr)
  324. ENDIF
  325. IF ( PRESENT (RefTime) ) THEN
  326. CALL ESMF_ClockGetRefTime(clock, RefTime, ierr)
  327. ENDIF
  328. IF ( PRESENT (rc) ) THEN
  329. rc = ierr
  330. ENDIF
  331. end subroutine ESMF_ClockGet
  332. ! !IROUTINE: ESMF_ClockGetAdvanceCount - Get the clock's advance count
  333. ! !INTERFACE:
  334. subroutine ESMF_ClockGetAdvanceCount(clock, AdvanceCount, rc)
  335. ! !ARGUMENTS:
  336. type(ESMF_Clock), intent(in) :: clock
  337. integer(ESMF_KIND_I8), intent(out) :: AdvanceCount
  338. integer, intent(out), optional :: rc
  339. ! !DESCRIPTION:
  340. ! Returns the number of times the {\tt ESMF\_Clock} has been advanced
  341. ! (time stepped)
  342. !
  343. ! The arguments are:
  344. ! \begin{description}
  345. ! \item[clock]
  346. ! The object instance to get the advance count from
  347. ! \item[AdvanceCount]
  348. ! The number of times the {\tt ESMF\_Clock} has been advanced
  349. ! \item[{[rc]}]
  350. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  351. ! \end{description}
  352. ! !REQUIREMENTS:
  353. ! TMG3.5.1
  354. !EOP
  355. AdvanceCount = clock%clockint%AdvanceCount
  356. IF ( PRESENT(rc) ) rc = ESMF_SUCCESS
  357. end subroutine ESMF_ClockGetAdvanceCount
  358. !------------------------------------------------------------------------------
  359. !BOP
  360. ! !IROUTINE: ESMF_ClockGetTimeStep - Get a clock's timestep interval
  361. ! !INTERFACE:
  362. subroutine ESMF_ClockGetTimeStep(clock, TimeStep, rc)
  363. ! !ARGUMENTS:
  364. type(ESMF_Clock), intent(in) :: clock
  365. type(ESMF_TimeInterval), intent(out) :: TimeStep
  366. integer, intent(out), optional :: rc
  367. ! !DESCRIPTION:
  368. ! Get an {\tt ESMF\_Clock}'s timestep interval
  369. !
  370. ! The arguments are:
  371. ! \begin{description}
  372. ! \item[clock]
  373. ! The object instance to get the time step from
  374. ! \item[TimeStep]
  375. ! The time step
  376. ! \item[{[rc]}]
  377. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  378. ! \end{description}
  379. !
  380. ! !REQUIREMENTS:
  381. ! TMG3.5.2
  382. !EOP
  383. TimeStep = clock%clockint%TimeStep
  384. IF ( PRESENT(rc) ) rc = ESMF_SUCCESS
  385. end subroutine ESMF_ClockGetTimeStep
  386. !------------------------------------------------------------------------------
  387. !BOP
  388. ! !IROUTINE: ESMF_ClockSetTimeStep - Set a clock's timestep interval
  389. ! !INTERFACE:
  390. subroutine ESMF_ClockSetTimeStep(clock, TimeStep, rc)
  391. ! !ARGUMENTS:
  392. type(ESMF_Clock), intent(inout) :: clock ! really INTENT(OUT)
  393. type(ESMF_TimeInterval), intent(in) :: TimeStep
  394. integer, intent(out), optional :: rc
  395. ! !DESCRIPTION:
  396. ! Set an {\tt ESMF\_Clock}'s timestep interval
  397. !
  398. ! The arguments are:
  399. ! \begin{description}
  400. ! \item[clock]
  401. ! The object instance to set the time step
  402. ! \item[TimeStep]
  403. ! The time step
  404. ! \item[{[rc]}]
  405. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  406. ! \end{description}
  407. !
  408. ! !REQUIREMENTS:
  409. ! TMG3.4.2
  410. !EOP
  411. clock%clockint%TimeStep = TimeStep
  412. IF ( PRESENT(rc) ) rc = ESMF_SUCCESS
  413. end subroutine ESMF_ClockSetTimeStep
  414. !------------------------------------------------------------------------------
  415. !BOP
  416. ! !IROUTINE: ESMF_ClockGetCurrTime - Get a clock's current time
  417. ! !INTERFACE:
  418. subroutine ESMF_ClockGetCurrTime(clock, CurrTime, rc)
  419. ! !ARGUMENTS:
  420. type(ESMF_Clock), intent(in) :: clock
  421. type(ESMF_Time), intent(out) :: CurrTime
  422. integer, intent(out), optional :: rc
  423. ! !DESCRIPTION:
  424. ! Get an {\tt ESMF\_Clock}'s current time
  425. !
  426. ! The arguments are:
  427. ! \begin{description}
  428. ! \item[clock]
  429. ! The object instance to get the current time from
  430. ! \item[CurrTime]
  431. ! The current time
  432. ! \item[{[rc]}]
  433. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  434. ! \end{description}
  435. !
  436. ! !REQUIREMENTS:
  437. ! TMG3.5.4
  438. !EOP
  439. CurrTime = clock%clockint%CurrTime
  440. IF ( PRESENT(rc) ) rc = ESMF_SUCCESS
  441. end subroutine ESMF_ClockGetCurrTime
  442. !------------------------------------------------------------------------------
  443. !BOP
  444. ! !IROUTINE: ESMF_ClockSetCurrTime - Set a clock's current time
  445. ! !INTERFACE:
  446. subroutine ESMF_ClockSetCurrTime(clock, CurrTime, rc)
  447. ! !ARGUMENTS:
  448. type(ESMF_Clock), intent(inout) :: clock ! really INTENT(OUT)
  449. type(ESMF_Time), intent(in) :: CurrTime
  450. integer, intent(out), optional :: rc
  451. ! !DESCRIPTION:
  452. ! Set an {\tt ESMF\_Clock}'s current time
  453. !
  454. ! The arguments are:
  455. ! \begin{description}
  456. ! \item[clock]
  457. ! The object instance to set the current time from
  458. ! \item[CurrTime]
  459. ! The current time
  460. ! \item[{[rc]}]
  461. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  462. ! \end{description}
  463. !
  464. ! !REQUIREMENTS:
  465. ! TMG3.4.3
  466. !EOP
  467. clock%clockint%CurrTime = CurrTime
  468. IF ( PRESENT(rc) ) rc = ESMF_SUCCESS
  469. end subroutine ESMF_ClockSetCurrTime
  470. !------------------------------------------------------------------------------
  471. !BOP
  472. ! !IROUTINE: ESMF_ClockGetStartTime - Get a clock's start time
  473. ! !INTERFACE:
  474. subroutine ESMF_ClockGetStartTime(clock, StartTime, rc)
  475. ! !ARGUMENTS:
  476. type(ESMF_Clock), intent(in) :: clock
  477. type(ESMF_Time), intent(out) :: StartTime
  478. integer, intent(out), optional :: rc
  479. ! !DESCRIPTION:
  480. ! Get an {\tt ESMF\_Clock}'s start time
  481. !
  482. ! The arguments are:
  483. ! \begin{description}
  484. ! \item[clock]
  485. ! The object instance to get the start time from
  486. ! \item[StartTime]
  487. ! The start time
  488. ! \item[{[rc]}]
  489. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  490. ! \end{description}
  491. !
  492. ! !REQUIREMENTS:
  493. ! TMG3.5.3
  494. !EOP
  495. StartTime = clock%clockint%StartTime
  496. IF ( PRESENT(rc) ) rc = ESMF_SUCCESS
  497. end subroutine ESMF_ClockGetStartTime
  498. !------------------------------------------------------------------------------
  499. !BOP
  500. ! !IROUTINE: ESMF_ClockGetStopTime - Get a clock's stop time
  501. ! !INTERFACE:
  502. subroutine ESMF_ClockGetStopTime(clock, StopTime, rc)
  503. ! !ARGUMENTS:
  504. type(ESMF_Clock), intent(in) :: clock
  505. type(ESMF_Time), intent(out) :: StopTime
  506. integer, intent(out), optional :: rc
  507. ! !DESCRIPTION:
  508. ! Get an {\tt ESMF\_Clock}'s stop time
  509. !
  510. ! The arguments are:
  511. ! \begin{description}
  512. ! \item[clock]
  513. ! The object instance to get the stop time from
  514. ! \item[StopTime]
  515. ! The stop time
  516. ! \item[{[rc]}]
  517. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  518. ! \end{description}
  519. !
  520. ! !REQUIREMENTS:
  521. ! TMG3.5.3
  522. !EOP
  523. StopTime = clock%clockint%StopTime
  524. IF ( PRESENT(rc) ) rc = ESMF_SUCCESS
  525. end subroutine ESMF_ClockGetStopTime
  526. !------------------------------------------------------------------------------
  527. !BOP
  528. ! !IROUTINE: ESMF_ClockGetRefTime - Get a clock's reference time
  529. ! !INTERFACE:
  530. subroutine ESMF_ClockGetRefTime(clock, RefTime, rc)
  531. ! !ARGUMENTS:
  532. type(ESMF_Clock), intent(in) :: clock
  533. type(ESMF_Time), intent(out) :: RefTime
  534. integer, intent(out), optional :: rc
  535. ! !DESCRIPTION:
  536. ! Get an {\tt ESMF\_Clock}'s reference time
  537. !
  538. ! The arguments are:
  539. ! \begin{description}
  540. ! \item[clock]
  541. ! The object instance to get the reference time from
  542. ! \item[RefTime]
  543. ! The reference time
  544. ! \item[{[rc]}]
  545. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  546. ! \end{description}
  547. !
  548. ! !REQUIREMENTS:
  549. ! TMG3.5.3
  550. !EOP
  551. refTime = clock%clockint%RefTime
  552. IF ( PRESENT(rc) ) rc = ESMF_SUCCESS
  553. end subroutine ESMF_ClockGetRefTime
  554. !------------------------------------------------------------------------------
  555. !BOP
  556. ! !IROUTINE: ESMF_ClockGetPrevTime - Get a clock's previous current time
  557. ! !INTERFACE:
  558. subroutine ESMF_ClockGetPrevTime(clock, PrevTime, rc)
  559. ! !ARGUMENTS:
  560. type(ESMF_Clock), intent(in) :: clock
  561. type(ESMF_Time), intent(out) :: PrevTime
  562. integer, intent(out), optional :: rc
  563. ! !DESCRIPTION:
  564. ! Get an {\tt ESMF\_Clock}'s previous current time
  565. !
  566. ! The arguments are:
  567. ! \begin{description}
  568. ! \item[clock]
  569. ! The object instance to get the previous current time from
  570. ! \item[PrevTime]
  571. ! The previous current time
  572. ! \item[{[rc]}]
  573. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  574. ! \end{description}
  575. !
  576. ! !REQUIREMENTS:
  577. ! TMG3.5.4
  578. !EOP
  579. ! hack for bug in PGI 5.1-x
  580. ! prevTime = Clock%clockint%CurrTime - Clock%clockint%TimeStep
  581. prevTime = ESMF_TimeDec( Clock%clockint%CurrTime, &
  582. Clock%clockint%TimeStep )
  583. IF ( PRESENT(rc) ) rc = ESMF_SUCCESS
  584. end subroutine ESMF_ClockGetPrevTime
  585. !------------------------------------------------------------------------------
  586. !BOP
  587. ! !IROUTINE: ESMF_ClockGetCurrSimTime - Get a clock's current simulation time
  588. ! !INTERFACE:
  589. subroutine ESMF_ClockGetCurrSimTime(clock, CurrSimTime, rc)
  590. ! !ARGUMENTS:
  591. type(ESMF_Clock), intent(in) :: clock
  592. type(ESMF_TimeInterval), intent(out) :: CurrSimTime
  593. integer, intent(out), optional :: rc
  594. ! !DESCRIPTION:
  595. ! Get an {\tt ESMF\_Clock}'s current simulation time
  596. !
  597. ! The arguments are:
  598. ! \begin{description}
  599. ! \item[clock]
  600. ! The object instance to get the current simulation time from
  601. ! \item[CurrSimTime]
  602. ! The current simulation time
  603. ! \item[{[rc]}]
  604. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  605. ! \end{description}
  606. !
  607. ! !REQUIREMENTS:
  608. ! TMG3.5.5
  609. !EOP
  610. CALL wrf_error_fatal( 'ESMF_ClockGetCurrSimTime not supported' )
  611. end subroutine ESMF_ClockGetCurrSimTime
  612. !------------------------------------------------------------------------------
  613. !BOP
  614. ! !IROUTINE: ESMF_ClockGetPrevSimTime - Get a clock's previous simulation time
  615. ! !INTERFACE:
  616. subroutine ESMF_ClockGetPrevSimTime(clock, PrevSimTime, rc)
  617. ! !ARGUMENTS:
  618. type(ESMF_Clock), intent(in) :: clock
  619. type(ESMF_TimeInterval), intent(out) :: PrevSimTime
  620. integer, intent(out), optional :: rc
  621. ! !DESCRIPTION:
  622. ! Get an {\tt ESMF\_Clock}'s previous simulation time
  623. !
  624. ! The arguments are:
  625. ! \begin{description}
  626. ! \item[clock]
  627. ! The object instance to get the previous simulation time from
  628. ! \item[PrevSimTime]
  629. ! The previous simulation time
  630. ! \item[{[rc]}]
  631. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  632. ! \end{description}
  633. !
  634. ! !REQUIREMENTS:
  635. ! TMG3.5.5
  636. !EOP
  637. CALL wrf_error_fatal( 'ESMF_ClockGetPrevSimTime not supported' )
  638. end subroutine ESMF_ClockGetPrevSimTime
  639. !------------------------------------------------------------------------------
  640. !BOP
  641. ! !IROUTINE: ESMF_ClockAddAlarm - Add an alarm to a clock's alarm list
  642. ! !INTERFACE:
  643. subroutine ESMF_ClockAddAlarm(clock, Alarm, rc)
  644. ! !ARGUMENTS:
  645. type(ESMF_Clock), intent(inout) :: clock
  646. type(ESMF_Alarm), intent(inout) :: Alarm
  647. integer, intent(out), optional :: rc
  648. ! !DESCRIPTION:
  649. ! Add an {\tt ESMF\_Alarm} to an {\tt ESMF\_Clock}'s {\tt ESMF\_Alarm} list
  650. !
  651. ! The arguments are:
  652. ! \begin{description}
  653. ! \item[clock]
  654. ! The object instance to add an {\tt ESMF\_Alarm} to
  655. ! \item[Alarm]
  656. ! The {\tt ESMF\_Alarm} to add to the {\tt ESMF\_Clock}'s
  657. ! {\tt ESMF\_Alarm} list
  658. ! \item[{[rc]}]
  659. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  660. ! \end{description}
  661. !
  662. ! !REQUIREMENTS:
  663. ! TMG4.1, TMG4.2
  664. !EOP
  665. IF ( PRESENT( rc ) ) rc = ESMF_SUCCESS
  666. clock%clockint%NumAlarms = clock%clockint%NumAlarms + 1
  667. IF ( clock%clockint%NumAlarms > SIZE (clock%clockint%AlarmList) ) THEN
  668. CALL wrf_error_fatal ( 'ESMF_ClockAddAlarm: too many alarms' )
  669. ELSE IF ( .NOT. ASSOCIATED( Alarm%alarmint ) ) THEN
  670. CALL wrf_error_fatal ( &
  671. 'ESMF_ClockAddAlarm: alarm not created' )
  672. ELSE
  673. IF ( Alarm%alarmint%RingTimeSet ) THEN
  674. Alarm%alarmint%PrevRingTime = Alarm%alarmint%RingTime
  675. ELSE
  676. !TBH: This has the nasty side-effect of forcing us to explicitly turn on
  677. !TBH: alarms that are created with RingInterval only, if we want them to start
  678. !TBH: ringing right away. And this is done (see
  679. !TBH: COMPUTE_VORTEX_CENTER_ALARM). Straighten this out...
  680. Alarm%alarmint%PrevRingTime = clock%clockint%CurrTime
  681. ENDIF
  682. Alarm%alarmint%Ringing = .FALSE.
  683. ! finally, load the alarm into the list
  684. ! write(0,*)'ESMF_ClockAddAlarm ',clock%clockint%NumAlarms
  685. clock%clockint%AlarmList(clock%clockint%NumAlarms) = Alarm
  686. ENDIF
  687. end subroutine ESMF_ClockAddAlarm
  688. !------------------------------------------------------------------------------
  689. !BOP
  690. ! !IROUTINE: ESMF_ClockGetAlarmList - Get a clock's alarm list
  691. ! !INTERFACE:
  692. subroutine ESMF_ClockGetAlarmList(clock, AlarmList, rc)
  693. ! !ARGUMENTS:
  694. type(ESMF_Clock), intent(in) :: clock
  695. type(ESMF_Alarm), pointer :: AlarmList(:)
  696. integer, intent(out), optional :: rc
  697. ! !DESCRIPTION:
  698. ! Get an {\tt ESMF\_Clock}'s {\tt ESMF\_Alarm} list
  699. !
  700. ! The arguments are:
  701. ! \begin{description}
  702. ! \item[clock]
  703. ! The object instance to get the {\tt ESMF\_Alarm} list from
  704. ! \item[AlarmList]
  705. ! The {\tt ESMF\_Clock}'s {\tt ESMF\_Alarm} list
  706. ! \item[{[rc]}]
  707. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  708. ! \end{description}
  709. !
  710. ! !REQUIREMENTS:
  711. ! TMG4.3
  712. !EOP
  713. AlarmList => clock%clockint%AlarmList
  714. IF ( PRESENT(rc) ) rc = ESMF_SUCCESS
  715. end subroutine ESMF_ClockGetAlarmList
  716. !------------------------------------------------------------------------------
  717. !BOP
  718. ! !IROUTINE: ESMF_ClockGetNumAlarms - Get the number of alarms in a clock's alarm list
  719. ! !INTERFACE:
  720. subroutine ESMF_ClockGetNumAlarms(clock, NumAlarms, rc)
  721. ! !ARGUMENTS:
  722. type(ESMF_Clock), intent(in) :: clock
  723. integer, intent(out) :: NumAlarms
  724. integer, intent(out), optional :: rc
  725. ! !DESCRIPTION:
  726. ! Get the number of {\tt ESMF\_Alarm}s in an {\tt ESMF\_Clock}'s
  727. ! {\tt ESMF\_Alarm} list
  728. !
  729. ! The arguments are:
  730. ! \begin{description}
  731. ! \item[clock]
  732. ! The object instance to get the number of {\tt ESMF\_Alarm}s from
  733. ! \item[NumAlarms]
  734. ! The number of {\tt ESMF\_Alarm}s in the {\tt ESMF\_Clock}'s
  735. ! {\tt ESMF\_Alarm} list
  736. ! \item[{[rc]}]
  737. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  738. ! \end{description}
  739. !
  740. ! !REQUIREMENTS:
  741. ! TMG4.3
  742. !EOP
  743. NumAlarms = clock%clockint%NumAlarms
  744. IF ( PRESENT(rc) ) rc = ESMF_SUCCESS
  745. end subroutine ESMF_ClockGetNumAlarms
  746. !------------------------------------------------------------------------------
  747. !BOP
  748. ! !IROUTINE: ESMF_ClockSyncToWallClock - Set clock's current time to wall clock time
  749. ! !INTERFACE:
  750. subroutine ESMF_ClockSyncToWallClock(clock, rc)
  751. ! !ARGUMENTS:
  752. type(ESMF_Clock), intent(inout) :: clock
  753. integer, intent(out), optional :: rc
  754. ! !DESCRIPTION:
  755. ! Set an {\tt ESMF\_Clock}'s current time to wall clock time
  756. !
  757. ! The arguments are:
  758. ! \begin{description}
  759. ! \item[clock]
  760. ! The object instance to synchronize to wall clock time
  761. ! \item[{[rc]}]
  762. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  763. ! \end{description}
  764. !
  765. ! !REQUIREMENTS:
  766. ! TMG3.4.5
  767. !EOP
  768. CALL wrf_error_fatal( 'ESMF_ClockSyncToWallClock not supported' )
  769. end subroutine ESMF_ClockSyncToWallClock
  770. !------------------------------------------------------------------------------
  771. !BOP
  772. ! !IROUTINE: ESMF_ClockAdvance - Advance a clock's current time by one time step
  773. ! !INTERFACE:
  774. subroutine ESMF_ClockAdvance(clock, RingingAlarmList, &
  775. NumRingingAlarms, rc)
  776. use esmf_timemod
  777. ! !ARGUMENTS:
  778. type(ESMF_Clock), intent(inout) :: clock
  779. type(ESMF_Alarm), dimension(MAX_ALARMS), intent(out), optional :: &
  780. RingingAlarmList
  781. integer, intent(out), optional :: NumRingingAlarms
  782. integer, intent(out), optional :: rc
  783. ! Local
  784. logical pred1, pred2, pred3
  785. integer i, n
  786. type(ESMF_Alarm) :: alarm
  787. logical :: positive_timestep
  788. !
  789. ! !DESCRIPTION:
  790. ! Advance an {\tt ESMF\_Clock}'s current time by one time step
  791. !
  792. ! The arguments are:
  793. ! \begin{description}
  794. ! \item[clock]
  795. ! The object instance to advance
  796. ! \item[{[RingingAlarmList]}]
  797. ! Return a list of any ringing alarms after the time step
  798. ! \item[{[NumRingingAlarms]}]
  799. ! The number of ringing alarms returned
  800. ! \item[{[rc]}]
  801. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  802. ! \end{description}
  803. !
  804. ! !REQUIREMENTS:
  805. ! TMG3.4.1
  806. !EOP
  807. ! hack for bug in PGI 5.1-x
  808. ! clock%clockint%CurrTime = clock%clockint%CurrTime + &
  809. ! clock%clockint%TimeStep
  810. clock%clockint%CurrTime = ESMF_TimeInc( clock%clockint%CurrTime, &
  811. clock%clockint%TimeStep )
  812. positive_timestep = ESMF_TimeIntervalIsPositive( clock%clockint%TimeStep )
  813. IF ( Present(NumRingingAlarms) ) NumRingingAlarms = 0
  814. clock%clockint%AdvanceCount = clock%clockint%AdvanceCount + 1
  815. DO i = 1, MAX_ALARMS
  816. alarm = clock%clockint%AlarmList(i)
  817. ! TBH: This is really dangerous. We need to be able to NULLIFY
  818. ! TBH: alarmint at compile-time (F95 synax) to make this safe.
  819. !$$$TBH: see if F95 compile-time pointer-nullification is supported by all
  820. !$$$TBH: compilers we support
  821. IF ( ASSOCIATED( alarm%alarmint ) ) THEN
  822. IF ( alarm%alarmint%Enabled ) THEN
  823. IF ( alarm%alarmint%RingIntervalSet ) THEN
  824. pred1 = .FALSE. ; pred2 = .FALSE. ; pred3 = .FALSE.
  825. ! alarm cannot ring if clock has passed the alarms stop time
  826. IF ( alarm%alarmint%StopTimeSet ) THEN
  827. IF ( positive_timestep ) THEN
  828. ! hack for bug in PGI 5.1-x
  829. ! PRED1 = clock%clockint%CurrTime > alarm%alarmint%StopTime
  830. PRED1 = ESMF_TimeGT( clock%clockint%CurrTime, &
  831. alarm%alarmint%StopTime )
  832. ELSE
  833. ! in this case time step is negative and stop time is
  834. ! less than start time
  835. ! PRED1 = clock%clockint%CurrTime < alarm%alarmint%StopTime
  836. PRED1 = ESMF_TimeLT( clock%clockint%CurrTime, &
  837. alarm%alarmint%StopTime )
  838. ENDIF
  839. ENDIF
  840. ! one-shot alarm: check for ring time
  841. ! TBH: Need to remove duplicated code. Need to enforce only one of
  842. ! TBH: alarm%alarmint%RingTimeSet or alarm%alarmint%RingIntervalSet ever
  843. ! TBH: being .TRUE. and simplify the logic. Also, the simpler
  844. ! TBH: implementation in the duplicated code below should be sufficient.
  845. IF ( alarm%alarmint%RingTimeSet ) THEN
  846. IF ( positive_timestep ) THEN
  847. ! hack for bug in PGI 5.1-x
  848. ! PRED2 = ( alarm%alarmint%RingTime <= clock%clockint%CurrTime &
  849. ! .AND. clock%clockint%CurrTime < alarm%alarmint%RingTime + &
  850. ! clock%clockint%TimeStep )
  851. PRED2 = ( ESMF_TimeLE( alarm%alarmint%RingTime, &
  852. clock%clockint%CurrTime ) &
  853. .AND. ESMF_TimeLT( clock%clockint%CurrTime, &
  854. ESMF_TimeInc( alarm%alarmint%RingTime, &
  855. clock%clockint%TimeStep ) ) )
  856. ELSE
  857. ! in this case time step is negative and stop time is
  858. ! less than start time
  859. ! hack for bug in PGI 5.1-x
  860. ! PRED2 = ( alarm%alarmint%RingTime >= clock%clockint%CurrTime &
  861. ! .AND. clock%clockint%CurrTime > alarm%alarmint%RingTime + &
  862. ! clock%clockint%TimeStep )
  863. PRED2 = ( ESMF_TimeGE( alarm%alarmint%RingTime, &
  864. clock%clockint%CurrTime ) &
  865. .AND. ESMF_TimeGT( clock%clockint%CurrTime, &
  866. ESMF_TimeInc( alarm%alarmint%RingTime, &
  867. clock%clockint%TimeStep ) ) )
  868. ENDIF
  869. ENDIF
  870. ! repeating alarm: check for ring interval
  871. IF ( alarm%alarmint%RingIntervalSet ) THEN
  872. IF ( positive_timestep ) THEN
  873. ! hack for bug in PGI 5.1-x
  874. ! PRED3 = ( alarm%alarmint%PrevRingTime + alarm%alarmint%RingInterval <= &
  875. ! clock%clockint%CurrTime )
  876. PRED3 = ( ESMF_TimeLE( ESMF_TimeInc( &
  877. alarm%alarmint%PrevRingTime, &
  878. alarm%alarmint%RingInterval ), &
  879. clock%clockint%CurrTime ) )
  880. ELSE
  881. ! in this case time step is negative and stop time is
  882. ! less than start time
  883. ! ring interval must always be positive
  884. ! hack for bug in PGI 5.1-x
  885. ! PRED3 = ( alarm%alarmint%PrevRingTime - alarm%alarmint%RingInterval >= &
  886. ! clock%clockint%CurrTime )
  887. PRED3 = ( ESMF_TimeGE( ESMF_TimeDec( &
  888. alarm%alarmint%PrevRingTime, &
  889. alarm%alarmint%RingInterval ), &
  890. clock%clockint%CurrTime ) )
  891. ENDIF
  892. ENDIF
  893. IF ( (.NOT. pred1) .AND. pred2 ) THEN
  894. alarm%alarmint%Ringing = .TRUE.
  895. alarm%alarmint%PrevRingTime = clock%clockint%CurrTime
  896. alarm%alarmint%RingTimeSet = .FALSE. !it is a one time alarm, it rang, now let it resort to interval
  897. IF ( PRESENT( RingingAlarmList ) .AND. &
  898. PRESENT ( NumRingingAlarms ) ) THEN
  899. NumRingingAlarms = NumRingingAlarms + 1
  900. RingingAlarmList( NumRingingAlarms ) = alarm
  901. ENDIF
  902. ELSE IF ( (.NOT. pred1) .AND. pred3 ) THEN
  903. alarm%alarmint%Ringing = .TRUE.
  904. IF ( positive_timestep ) THEN
  905. ! hack for bug in PGI 5.1-x
  906. ! IF ( PRED3) alarm%alarmint%PrevRingTime = alarm%alarmint%PrevRingTime + &
  907. ! alarm%alarmint%RingInterval
  908. IF ( PRED3 ) &
  909. alarm%alarmint%PrevRingTime = &
  910. ESMF_TimeInc( alarm%alarmint%PrevRingTime, &
  911. alarm%alarmint%RingInterval )
  912. ELSE
  913. ! in this case time step is negative and stop time is
  914. ! less than start time
  915. ! ring interval must always be positive
  916. ! hack for bug in PGI 5.1-x
  917. ! IF ( PRED3) alarm%alarmint%PrevRingTime = alarm%alarmint%PrevRingTime - &
  918. ! alarm%alarmint%RingInterval
  919. IF ( PRED3 ) &
  920. alarm%alarmint%PrevRingTime = &
  921. ESMF_TimeDec( alarm%alarmint%PrevRingTime, &
  922. alarm%alarmint%RingInterval )
  923. ENDIF
  924. IF ( PRESENT( RingingAlarmList ) .AND. &
  925. PRESENT ( NumRingingAlarms ) ) THEN
  926. NumRingingAlarms = NumRingingAlarms + 1
  927. RingingAlarmList( NumRingingAlarms ) = alarm
  928. ENDIF
  929. ENDIF
  930. ELSE IF ( alarm%alarmint%RingTimeSet ) THEN
  931. ! TBH: Need to remove duplicated code. Need to enforce only one of
  932. ! TBH: alarm%alarmint%RingTimeSet or alarm%alarmint%RingIntervalSet ever
  933. ! TBH: being .TRUE. and simplify the logic. Also, the simpler
  934. ! TBH: implementation in here should be sufficient.
  935. IF ( positive_timestep ) THEN
  936. ! hack for bug in PGI 5.1-x
  937. ! IF ( alarm%alarmint%RingTime <= clock%clockint%CurrTime ) THEN
  938. IF ( ESMF_TimeLE( alarm%alarmint%RingTime, &
  939. clock%clockint%CurrTime ) ) THEN
  940. alarm%alarmint%RingTimeSet = .FALSE. !it is a one time alarm, it rang, now let it resort to interval
  941. alarm%alarmint%Ringing = .TRUE.
  942. alarm%alarmint%PrevRingTime = clock%clockint%CurrTime
  943. IF ( PRESENT( RingingAlarmList ) .AND. &
  944. PRESENT ( NumRingingAlarms ) ) THEN
  945. NumRingingAlarms = NumRingingAlarms + 1
  946. RingingAlarmList( NumRingingAlarms ) = alarm
  947. ENDIF
  948. ENDIF
  949. ELSE
  950. ! in this case time step is negative and stop time is
  951. ! less than start time
  952. ! hack for bug in PGI 5.1-x
  953. ! IF ( alarm%alarmint%RingTime >= clock%clockint%CurrTime ) THEN
  954. IF ( ESMF_TimeGE( alarm%alarmint%RingTime, &
  955. clock%clockint%CurrTime ) ) THEN
  956. alarm%alarmint%RingTimeSet = .FALSE. !it is a one time alarm, it rang, now let it resort to interval
  957. alarm%alarmint%Ringing = .TRUE.
  958. alarm%alarmint%PrevRingTime = clock%clockint%CurrTime
  959. IF ( PRESENT( RingingAlarmList ) .AND. &
  960. PRESENT ( NumRingingAlarms ) ) THEN
  961. NumRingingAlarms = NumRingingAlarms + 1
  962. RingingAlarmList( NumRingingAlarms ) = alarm
  963. ENDIF
  964. ENDIF
  965. ENDIF
  966. ENDIF
  967. IF ( alarm%alarmint%StopTimeSet ) THEN
  968. ! TBH: what is this for???
  969. ENDIF
  970. ENDIF
  971. ENDIF
  972. clock%clockint%AlarmList(i) = alarm
  973. ENDDO
  974. IF ( PRESENT( rc ) ) rc = ESMF_SUCCESS
  975. end subroutine ESMF_ClockAdvance
  976. !------------------------------------------------------------------------------
  977. !BOP
  978. ! !IROUTINE: ESMF_ClockStopTimeDisable - NOOP for compatibility with ESMF 2.1.0+
  979. ! !INTERFACE:
  980. subroutine ESMF_ClockStopTimeDisable(clock, rc)
  981. !
  982. ! !ARGUMENTS:
  983. type(ESMF_Clock), intent(in) :: clock
  984. integer, intent(out), optional :: rc
  985. rc = ESMF_SUCCESS
  986. end subroutine ESMF_ClockStopTimeDisable
  987. !------------------------------------------------------------------------------
  988. !BOP
  989. ! !IROUTINE: ESMF_ClockIsStopTime - Has the clock reached its stop time ?
  990. ! !INTERFACE:
  991. function ESMF_ClockIsStopTime(clock, rc)
  992. !
  993. ! !RETURN VALUE:
  994. logical :: ESMF_ClockIsStopTime
  995. ! !ARGUMENTS:
  996. type(ESMF_Clock), intent(in) :: clock
  997. integer, intent(out), optional :: rc
  998. logical :: positive_timestep
  999. ! !DESCRIPTION:
  1000. ! Return true if {\tt ESMF\_Clock} has reached its stop time, false
  1001. ! otherwise
  1002. !
  1003. ! The arguments are:
  1004. ! \begin{description}
  1005. ! \item[clock]
  1006. ! The object instance to check
  1007. ! \item[{[rc]}]
  1008. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  1009. ! \end{description}
  1010. ! !REQUIREMENTS:
  1011. ! TMG3.5.6
  1012. !EOP
  1013. positive_timestep = ESMF_TimeIntervalIsPositive( clock%clockint%TimeStep )
  1014. IF ( positive_timestep ) THEN
  1015. ! hack for bug in PGI 5.1-x
  1016. ! if ( clock%clockint%CurrTime .GE. clock%clockint%StopTime ) THEN
  1017. if ( ESMF_TimeGE( clock%clockint%CurrTime, &
  1018. clock%clockint%StopTime ) ) THEN
  1019. ESMF_ClockIsStopTime = .TRUE.
  1020. else
  1021. ESMF_ClockIsStopTime = .FALSE.
  1022. endif
  1023. ELSE
  1024. ! hack for bug in PGI 5.1-x
  1025. ! if ( clock%clockint%CurrTime .LE. clock%clockint%StopTime ) THEN
  1026. if ( ESMF_TimeLE( clock%clockint%CurrTime, &
  1027. clock%clockint%StopTime ) ) THEN
  1028. ESMF_ClockIsStopTime = .TRUE.
  1029. else
  1030. ESMF_ClockIsStopTime = .FALSE.
  1031. endif
  1032. ENDIF
  1033. IF ( PRESENT( rc ) ) rc = ESMF_SUCCESS
  1034. end function ESMF_ClockIsStopTime
  1035. !------------------------------------------------------------------------------
  1036. !
  1037. ! This section defines the overridden Read, Write, Validate and Print methods
  1038. ! from the ESMF_Base class
  1039. !
  1040. !------------------------------------------------------------------------------
  1041. !BOP
  1042. ! !IROUTINE: ESMF_ClockRead - Restores a clock
  1043. ! !INTERFACE:
  1044. subroutine ESMF_ClockRead(clock, TimeStep, StartTime, StopTime, &
  1045. RefTime, CurrTime, PrevTime, AdvanceCount, &
  1046. AlarmList, rc)
  1047. ! !ARGUMENTS:
  1048. type(ESMF_Clock), intent(out) :: clock
  1049. type(ESMF_TimeInterval), intent(in) :: TimeStep
  1050. type(ESMF_Time), intent(in) :: StartTime
  1051. type(ESMF_Time), intent(in) :: StopTime
  1052. type(ESMF_Time), intent(in) :: RefTime
  1053. type(ESMF_Time), intent(in) :: CurrTime
  1054. type(ESMF_Time), intent(in) :: PrevTime
  1055. integer(ESMF_KIND_I8), intent(in) :: AdvanceCount
  1056. type(ESMF_Alarm), dimension(MAX_ALARMS), intent(in) :: AlarmList
  1057. integer, intent(out), optional :: rc
  1058. ! !DESCRIPTION:
  1059. ! Restore an {\tt ESMF\_Clock}
  1060. !
  1061. ! The arguments are:
  1062. ! \begin{description}
  1063. ! \item[clock]
  1064. ! The object instance to restore
  1065. ! \item[TimeStep]
  1066. ! The {\tt ESMF\_Clock}'s time step interval
  1067. ! \item[StartTime]
  1068. ! The {\tt ESMF\_Clock}'s starting time
  1069. ! \item[StopTime]
  1070. ! The {\tt ESMF\_Clock}'s stopping time
  1071. ! \item[RefTime]
  1072. ! The {\tt ESMF\_Clock}'s reference time
  1073. ! \item[CurrTime]
  1074. ! The {\tt ESMF\_Clock}'s current time
  1075. ! \item[PrevTime]
  1076. ! The {\tt ESMF\_Clock}'s previous time
  1077. ! \item[AdvanceCount]
  1078. ! The number of times the {\tt ESMF\_Clock} has been advanced
  1079. ! \item[AlarmList]
  1080. ! The {\tt ESMF\_Clock}'s {\tt ESMF\_Alarm} list
  1081. ! \item[{[rc]}]
  1082. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  1083. ! \end{description}
  1084. !
  1085. ! !REQUIREMENTS:
  1086. !EOP
  1087. CALL wrf_error_fatal( 'ESMF_ClockRead not supported' )
  1088. end subroutine ESMF_ClockRead
  1089. !------------------------------------------------------------------------------
  1090. !BOP
  1091. ! !IROUTINE: ESMF_ClockWrite - Saves a clock
  1092. ! !INTERFACE:
  1093. subroutine ESMF_ClockWrite(clock, TimeStep, StartTime, StopTime, &
  1094. RefTime, CurrTime, PrevTime, AdvanceCount, &
  1095. AlarmList, rc)
  1096. ! !ARGUMENTS:
  1097. type(ESMF_Clock), intent(in) :: clock
  1098. type(ESMF_TimeInterval), intent(out) :: TimeStep
  1099. type(ESMF_Time), intent(out) :: StartTime
  1100. type(ESMF_Time), intent(out) :: StopTime
  1101. type(ESMF_Time), intent(out) :: RefTime
  1102. type(ESMF_Time), intent(out) :: CurrTime
  1103. type(ESMF_Time), intent(out) :: PrevTime
  1104. integer(ESMF_KIND_I8), intent(out) :: AdvanceCount
  1105. type(ESMF_Alarm), dimension(MAX_ALARMS), intent(out) :: AlarmList
  1106. integer, intent(out), optional :: rc
  1107. ! !DESCRIPTION:
  1108. ! Save an {\tt ESMF\_Clock}
  1109. !
  1110. ! The arguments are:
  1111. ! \begin{description}
  1112. ! \item[clock]
  1113. ! The object instance to save
  1114. ! \item[TimeStep]
  1115. ! The {\tt ESMF\_Clock}'s time step interval
  1116. ! \item[StartTime]
  1117. ! The {\tt ESMF\_Clock}'s starting time
  1118. ! \item[StopTime]
  1119. ! The {\tt ESMF\_Clock}'s stopping time
  1120. ! \item[RefTime]
  1121. ! The {\tt ESMF\_Clock}'s reference time
  1122. ! \item[CurrTime]
  1123. ! The {\tt ESMF\_Clock}'s current time
  1124. ! \item[PrevTime]
  1125. ! The {\tt ESMF\_Clock}'s previous time
  1126. ! \item[AdvanceCount]
  1127. ! The number of times the {\tt ESMF\_Clock} has been advanced
  1128. ! \item[AlarmList]
  1129. ! The {\tt ESMF\_Clock}'s {\tt ESMF\_Alarm} list
  1130. ! \item[{[rc]}]
  1131. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  1132. ! \end{description}
  1133. !
  1134. ! !REQUIREMENTS:
  1135. !EOP
  1136. CALL wrf_error_fatal( 'ESMF_ClockWrite not supported' )
  1137. end subroutine ESMF_ClockWrite
  1138. !------------------------------------------------------------------------------
  1139. !BOP
  1140. ! !IROUTINE: ESMF_ClockValidate - Validate a Clock's properties
  1141. ! !INTERFACE:
  1142. subroutine ESMF_ClockValidate(clock, opts, rc)
  1143. ! !ARGUMENTS:
  1144. type(ESMF_Clock), intent(in) :: clock
  1145. character (len=*), intent(in), optional :: opts
  1146. integer, intent(out), optional :: rc
  1147. ! !DESCRIPTION:
  1148. ! Perform a validation check on an {\tt ESMF\_Clock}'s properties
  1149. !
  1150. ! The arguments are:
  1151. ! \begin{description}
  1152. ! \item[clock]
  1153. ! {\tt ESMF\_Clock} to validate
  1154. ! \item[{[opts]}]
  1155. ! Validate options
  1156. ! \item[{[rc]}]
  1157. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  1158. ! \end{description}
  1159. !
  1160. ! !REQUIREMENTS:
  1161. ! TMGn.n.n
  1162. !EOP
  1163. CALL wrf_error_fatal( 'ESMF_ClockValidate not supported' )
  1164. end subroutine ESMF_ClockValidate
  1165. !------------------------------------------------------------------------------
  1166. !BOP
  1167. ! !IROUTINE: ESMF_ClockPrint - Print out a Clock's properties
  1168. ! !INTERFACE:
  1169. subroutine ESMF_ClockPrint(clock, opts, rc)
  1170. ! !ARGUMENTS:
  1171. type(ESMF_Clock), intent(in) :: clock
  1172. character (len=*), intent(in), optional :: opts
  1173. integer, intent(out), optional :: rc
  1174. ! !DESCRIPTION:
  1175. ! To support testing/debugging, print out an {\tt ESMF\_Clock}'s
  1176. ! properties.
  1177. !
  1178. ! The arguments are:
  1179. ! \begin{description}
  1180. ! \item[clock]
  1181. ! {\tt ESMF\_Clock} to print out
  1182. ! \item[{[opts]}]
  1183. ! Print options
  1184. ! \item[{[rc]}]
  1185. ! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
  1186. ! \end{description}
  1187. !
  1188. ! !REQUIREMENTS:
  1189. ! TMGn.n.n
  1190. !EOP
  1191. CALL wrf_error_fatal( 'ESMF_ClockPrint not supported' )
  1192. end subroutine ESMF_ClockPrint
  1193. !------------------------------------------------------------------------------
  1194. end module ESMF_ClockMod