PageRenderTime 59ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 1ms

/wrfv2_fire/external/esmf_time_f90/Test1.F90

http://github.com/jbeezley/wrf-fire
FORTRAN Modern | 1718 lines | 1448 code | 91 blank | 179 comment | 11 complexity | ddb4b3d0d2d3b7c4ee321177a45049fb MD5 | raw file
Possible License(s): AGPL-1.0

Large files files are truncated, but you can click here to view the full file

  1. !
  2. ! Sub-system tests for esmf_time_f90
  3. !
  4. ! Someday, switch over to funit!
  5. !
  6. MODULE my_tests
  7. USE ESMF_Mod
  8. IMPLICIT NONE
  9. ! Set this to .TRUE. to make wrf_error_fatal3() print a message on failure
  10. ! instead of stopping the program. Use for testing only (since we cannot
  11. ! catch exceptions in Fortran90!!)
  12. LOGICAL :: WRF_ERROR_FATAL_PRINT = .FALSE.
  13. CONTAINS
  14. ! Test printing of an ESMF_Time or ESMF_TimeInterval object.
  15. !
  16. ! Correct results are also passed in through this interface and compared
  17. ! with computed results. PASS/FAIL messages are printed.
  18. !
  19. SUBROUTINE test_print( t_yy, t_mm, t_dd, t_h, t_m, t_s, t_sn, t_sd, &
  20. ti_yy, ti_mm, ti_dd, ti_h, ti_m, ti_s, ti_sn, ti_sd, &
  21. res_str, testname, expect_error )
  22. INTEGER, INTENT(IN), OPTIONAL :: t_YY
  23. INTEGER, INTENT(IN), OPTIONAL :: t_MM ! month
  24. INTEGER, INTENT(IN), OPTIONAL :: t_DD ! day of month
  25. INTEGER, INTENT(IN), OPTIONAL :: t_H
  26. INTEGER, INTENT(IN), OPTIONAL :: t_M
  27. INTEGER, INTENT(IN), OPTIONAL :: t_S
  28. INTEGER, INTENT(IN), OPTIONAL :: t_Sn
  29. INTEGER, INTENT(IN), OPTIONAL :: t_Sd
  30. INTEGER, INTENT(IN), OPTIONAL :: ti_YY
  31. INTEGER, INTENT(IN), OPTIONAL :: ti_MM ! month
  32. INTEGER, INTENT(IN), OPTIONAL :: ti_DD ! day of month
  33. INTEGER, INTENT(IN), OPTIONAL :: ti_H
  34. INTEGER, INTENT(IN), OPTIONAL :: ti_M
  35. INTEGER, INTENT(IN), OPTIONAL :: ti_S
  36. INTEGER, INTENT(IN), OPTIONAL :: ti_Sn
  37. INTEGER, INTENT(IN), OPTIONAL :: ti_Sd
  38. CHARACTER (LEN=*), INTENT(IN) :: res_str
  39. CHARACTER (LEN=*), INTENT(IN), OPTIONAL :: testname
  40. LOGICAL, OPTIONAL, INTENT(IN) :: expect_error
  41. ! locals
  42. INTEGER :: it_YY
  43. INTEGER :: it_MM ! month
  44. INTEGER :: it_DD ! day of month
  45. INTEGER :: it_H
  46. INTEGER :: it_M
  47. INTEGER :: it_S
  48. INTEGER :: it_Sn
  49. INTEGER :: it_Sd
  50. INTEGER :: iti_YY
  51. INTEGER :: iti_MM ! month
  52. INTEGER :: iti_DD ! day of month
  53. INTEGER :: iti_H
  54. INTEGER :: iti_M
  55. INTEGER :: iti_S
  56. INTEGER :: iti_Sn
  57. INTEGER :: iti_Sd
  58. LOGICAL :: is_t
  59. LOGICAL :: is_ti
  60. CHARACTER (LEN=512) :: itestname
  61. LOGICAL :: iexpect_error
  62. INTEGER rc
  63. TYPE(ESMF_Time) :: t
  64. TYPE(ESMF_TimeInterval) :: ti
  65. CHARACTER(LEN=ESMF_MAXSTR) :: str, computed_str, frac_str
  66. CHARACTER(LEN=17) :: type_str
  67. INTEGER :: res_len, computed_len, Sn, Sd
  68. LOGICAL :: test_passed
  69. ! PRINT *,'DEBUG: BEGIN test_print()'
  70. it_YY = 0
  71. it_MM = 1
  72. it_DD = 1
  73. it_H = 0
  74. it_M = 0
  75. it_S = 0
  76. it_Sn = 0
  77. it_Sd = 0
  78. iti_YY = 0
  79. iti_MM = 0
  80. iti_DD = 0
  81. iti_H = 0
  82. iti_M = 0
  83. iti_S = 0
  84. iti_Sn = 0
  85. iti_Sd = 0
  86. itestname = ''
  87. iexpect_error = .FALSE.
  88. IF ( PRESENT( t_YY ) ) it_YY = t_YY
  89. IF ( PRESENT( t_MM ) ) it_MM = t_MM
  90. IF ( PRESENT( t_DD ) ) it_DD = t_DD
  91. IF ( PRESENT( t_H ) ) it_H = t_H
  92. IF ( PRESENT( t_M ) ) it_M = t_M
  93. IF ( PRESENT( t_S ) ) it_S = t_S
  94. IF ( PRESENT( t_Sn ) ) it_Sn = t_Sn
  95. IF ( PRESENT( t_Sd ) ) it_Sd = t_Sd
  96. IF ( PRESENT( ti_YY ) ) iti_YY = ti_YY
  97. IF ( PRESENT( ti_MM ) ) iti_MM = ti_MM
  98. IF ( PRESENT( ti_DD ) ) iti_DD = ti_DD
  99. IF ( PRESENT( ti_H ) ) iti_H = ti_H
  100. IF ( PRESENT( ti_M ) ) iti_M = ti_M
  101. IF ( PRESENT( ti_S ) ) iti_S = ti_S
  102. IF ( PRESENT( ti_Sn ) ) iti_Sn = ti_Sn
  103. IF ( PRESENT( ti_Sd ) ) iti_Sd = ti_Sd
  104. IF ( PRESENT( testname ) ) itestname = TRIM(testname)
  105. IF ( PRESENT( expect_error ) ) iexpect_error = expect_error
  106. ! Ensure that optional arguments are consistent...
  107. is_t = ( PRESENT( t_YY ) .OR. PRESENT( t_MM ) .OR. &
  108. PRESENT( t_DD ) .OR. PRESENT( t_H ) .OR. &
  109. PRESENT( t_M ) .OR. PRESENT( t_S ) .OR. &
  110. PRESENT( t_Sn ) .OR. PRESENT( t_Sd ) )
  111. is_ti = ( PRESENT( ti_YY ) .OR. PRESENT( ti_MM ) .OR. &
  112. PRESENT( ti_DD ) .OR. PRESENT( ti_H ) .OR. &
  113. PRESENT( ti_M ) .OR. PRESENT( ti_S ) .OR. &
  114. PRESENT( ti_Sn ) .OR. PRESENT( ti_Sd ) )
  115. IF ( is_t .EQV. is_ti ) THEN
  116. CALL wrf_error_fatal3( __FILE__ , __LINE__ , &
  117. 'ERROR test_print: inconsistent args' )
  118. ENDIF
  119. !PRINT *,'DEBUG: test_print(): init objects'
  120. ! Initialize object to be tested
  121. ! modify behavior of wrf_error_fatal3 for tests expected to fail
  122. IF ( iexpect_error ) WRF_ERROR_FATAL_PRINT = .TRUE.
  123. Sn = 0
  124. Sd = 0
  125. IF ( is_t ) THEN
  126. type_str = 'ESMF_Time'
  127. !PRINT *,'DEBUG: test_print(): calling ESMF_TimeSet()'
  128. !PRINT *,'DEBUG: test_print(): YY,MM,DD,H,M,S,Sn,Sd = ', it_YY,it_MM,it_DD,it_H,it_M,it_S,it_Sn,it_Sd
  129. CALL ESMF_TimeSet( t, YY=it_YY, MM=it_MM, DD=it_DD , &
  130. H=it_H, M=it_M, S=it_S, Sn=it_Sn, Sd=it_Sd, rc=rc )
  131. !PRINT *,'DEBUG: test_print(): back from ESMF_TimeSet()'
  132. CALL test_check_error( ESMF_SUCCESS, rc, &
  133. TRIM(itestname)//'ESMF_TimeSet() ', &
  134. __FILE__ , &
  135. __LINE__ )
  136. !PRINT *,'DEBUG: test_print(): calling ESMF_TimeGet()'
  137. CALL ESMF_TimeGet( t, timeString=computed_str, Sn=Sn, Sd=Sd, rc=rc )
  138. CALL test_check_error( ESMF_SUCCESS, rc, &
  139. TRIM(itestname)//'ESMF_TimeGet() ', &
  140. __FILE__ , &
  141. __LINE__ )
  142. !PRINT *,'DEBUG: test_print(): back from ESMF_TimeGet(), computed_str = ',TRIM(computed_str)
  143. ELSE
  144. type_str = 'ESMF_TimeInterval'
  145. !PRINT *,'DEBUG: test_print(): calling ESMF_TimeIntervalSet()'
  146. CALL ESMF_TimeIntervalSet( ti, YY=iti_YY, MM=iti_MM, &
  147. D=iti_DD , &
  148. H=iti_H, M=iti_M, &
  149. S=iti_S, Sn=iti_Sn, Sd=iti_Sd, rc=rc )
  150. CALL test_check_error( ESMF_SUCCESS, rc, &
  151. TRIM(itestname)//'ESMF_TimeIntervalSet() ', &
  152. __FILE__ , &
  153. __LINE__ )
  154. !PRINT *,'DEBUG: test_print(): calling ESMF_TimeIntervalGet()'
  155. CALL ESMF_TimeIntervalGet( ti, timeString=computed_str, Sn=Sn, Sd=Sd, rc=rc )
  156. CALL test_check_error( ESMF_SUCCESS, rc, &
  157. TRIM(itestname)//'ESMF_TimeGet() ', &
  158. __FILE__ , &
  159. __LINE__ )
  160. ENDIF
  161. ! handle fractions
  162. IF ( Sd > 0 ) THEN
  163. IF ( Sn > 0 ) THEN
  164. WRITE(frac_str,FMT="('+',I2.2,'/',I2.2)") abs(Sn), Sd
  165. ELSE IF ( Sn < 0 ) THEN
  166. WRITE(frac_str,FMT="('-',I2.2,'/',I2.2)") abs(Sn), Sd
  167. ELSE
  168. frac_str = ''
  169. ENDIF
  170. computed_str = TRIM(computed_str)//TRIM(frac_str)
  171. ENDIF
  172. ! restore default behavior of wrf_error_fatal3
  173. IF ( iexpect_error ) WRF_ERROR_FATAL_PRINT = .FALSE.
  174. !PRINT *,'DEBUG: test_print(): done init objects'
  175. !PRINT *,'DEBUG: test_print(): check result'
  176. ! check result
  177. test_passed = .FALSE.
  178. res_len = LEN_TRIM(res_str)
  179. computed_len = LEN_TRIM(computed_str)
  180. IF ( res_len == computed_len ) THEN
  181. IF ( computed_str(1:computed_len) == res_str(1:res_len) ) THEN
  182. test_passed = .TRUE.
  183. ENDIF
  184. ENDIF
  185. IF ( test_passed ) THEN
  186. WRITE(*,FMT='(A)') 'PASS: '//TRIM(itestname)
  187. ELSE
  188. WRITE(*,'(9A)') 'FAIL: ',TRIM(itestname),': printing ',TRIM(type_str), &
  189. ' expected <', TRIM(res_str),'> but computed <',TRIM(computed_str),'>'
  190. ENDIF
  191. !PRINT *,'DEBUG: END test_print()'
  192. END SUBROUTINE test_print
  193. ! Test the following arithmetic operations on ESMF_Time and
  194. ! ESMF_TimeInterval objects:
  195. ! ESMF_Time = ESMF_Time + ESMF_TimeInterval
  196. ! ESMF_Time = ESMF_TimeInterval + ESMF_Time
  197. ! ESMF_Time = ESMF_Time - ESMF_TimeInterval
  198. ! ESMF_TimeInterval = ESMF_Time - ESMF_Time
  199. ! ESMF_TimeInterval = ESMF_TimeInterval + ESMF_TimeInterval
  200. ! ESMF_TimeInterval = ESMF_TimeInterval - ESMF_TimeInterval
  201. ! ESMF_TimeInterval = ESMF_TimeInterval * INTEGER
  202. ! ESMF_TimeInterval = ESMF_TimeInterval / INTEGER
  203. !
  204. ! Correct results are also passed in through this interface and compared
  205. ! with computed results. PASS/FAIL messages are printed.
  206. !
  207. ! Operations are expressed as res = op1 +|- op2
  208. !
  209. SUBROUTINE test_arithmetic( add_op, multiply_op, &
  210. op1_t_yy, op1_t_mm, op1_t_dd, op1_t_h, op1_t_m, op1_t_s, op1_t_sn, op1_t_sd, &
  211. op1_ti_yy, op1_ti_mm, op1_ti_dd, op1_ti_h, op1_ti_m, op1_ti_s, op1_ti_sn, op1_ti_sd, &
  212. op2_t_yy, op2_t_mm, op2_t_dd, op2_t_h, op2_t_m, op2_t_s, op2_t_sn, op2_t_sd, &
  213. op2_ti_yy, op2_ti_mm, op2_ti_dd, op2_ti_h, op2_ti_m, op2_ti_s, op2_ti_sn, op2_ti_sd, &
  214. op2_int, &
  215. res_t_yy, res_t_mm, res_t_dd, res_t_h, res_t_m, res_t_s, res_t_sn, res_t_sd, &
  216. res_ti_yy, res_ti_mm, res_ti_dd, res_ti_h, res_ti_m, res_ti_s, res_ti_sn, res_ti_sd, &
  217. res_int, testname, expect_error )
  218. LOGICAL, INTENT(IN), OPTIONAL :: add_op ! .TRUE.=add, .FALSE.=subtract
  219. LOGICAL, INTENT(IN), OPTIONAL :: multiply_op ! .TRUE.=multiply, .FALSE.=divide
  220. INTEGER, INTENT(IN), OPTIONAL :: op1_t_YY
  221. INTEGER, INTENT(IN), OPTIONAL :: op1_t_MM ! month
  222. INTEGER, INTENT(IN), OPTIONAL :: op1_t_DD ! day of month
  223. INTEGER, INTENT(IN), OPTIONAL :: op1_t_H
  224. INTEGER, INTENT(IN), OPTIONAL :: op1_t_M
  225. INTEGER, INTENT(IN), OPTIONAL :: op1_t_S
  226. INTEGER, INTENT(IN), OPTIONAL :: op1_t_Sn
  227. INTEGER, INTENT(IN), OPTIONAL :: op1_t_Sd
  228. INTEGER, INTENT(IN), OPTIONAL :: op1_ti_YY
  229. INTEGER, INTENT(IN), OPTIONAL :: op1_ti_MM ! month
  230. INTEGER, INTENT(IN), OPTIONAL :: op1_ti_DD ! day of month
  231. INTEGER, INTENT(IN), OPTIONAL :: op1_ti_H
  232. INTEGER, INTENT(IN), OPTIONAL :: op1_ti_M
  233. INTEGER, INTENT(IN), OPTIONAL :: op1_ti_S
  234. INTEGER, INTENT(IN), OPTIONAL :: op1_ti_Sn
  235. INTEGER, INTENT(IN), OPTIONAL :: op1_ti_Sd
  236. INTEGER, INTENT(IN), OPTIONAL :: op2_t_YY
  237. INTEGER, INTENT(IN), OPTIONAL :: op2_t_MM ! month
  238. INTEGER, INTENT(IN), OPTIONAL :: op2_t_DD ! day of month
  239. INTEGER, INTENT(IN), OPTIONAL :: op2_t_H
  240. INTEGER, INTENT(IN), OPTIONAL :: op2_t_M
  241. INTEGER, INTENT(IN), OPTIONAL :: op2_t_S
  242. INTEGER, INTENT(IN), OPTIONAL :: op2_t_Sn
  243. INTEGER, INTENT(IN), OPTIONAL :: op2_t_Sd
  244. INTEGER, INTENT(IN), OPTIONAL :: op2_ti_YY
  245. INTEGER, INTENT(IN), OPTIONAL :: op2_ti_MM ! month
  246. INTEGER, INTENT(IN), OPTIONAL :: op2_ti_DD ! day of month
  247. INTEGER, INTENT(IN), OPTIONAL :: op2_ti_H
  248. INTEGER, INTENT(IN), OPTIONAL :: op2_ti_M
  249. INTEGER, INTENT(IN), OPTIONAL :: op2_ti_S
  250. INTEGER, INTENT(IN), OPTIONAL :: op2_ti_Sn
  251. INTEGER, INTENT(IN), OPTIONAL :: op2_ti_Sd
  252. INTEGER, INTENT(IN), OPTIONAL :: op2_int
  253. INTEGER, INTENT(IN), OPTIONAL :: res_t_YY
  254. INTEGER, INTENT(IN), OPTIONAL :: res_t_MM ! month
  255. INTEGER, INTENT(IN), OPTIONAL :: res_t_DD ! day of month
  256. INTEGER, INTENT(IN), OPTIONAL :: res_t_H
  257. INTEGER, INTENT(IN), OPTIONAL :: res_t_M
  258. INTEGER, INTENT(IN), OPTIONAL :: res_t_S
  259. INTEGER, INTENT(IN), OPTIONAL :: res_t_Sn
  260. INTEGER, INTENT(IN), OPTIONAL :: res_t_Sd
  261. INTEGER, INTENT(IN), OPTIONAL :: res_ti_YY
  262. INTEGER, INTENT(IN), OPTIONAL :: res_ti_MM ! month
  263. INTEGER, INTENT(IN), OPTIONAL :: res_ti_DD ! day of month
  264. INTEGER, INTENT(IN), OPTIONAL :: res_ti_H
  265. INTEGER, INTENT(IN), OPTIONAL :: res_ti_M
  266. INTEGER, INTENT(IN), OPTIONAL :: res_ti_S
  267. INTEGER, INTENT(IN), OPTIONAL :: res_ti_Sn
  268. INTEGER, INTENT(IN), OPTIONAL :: res_ti_Sd
  269. INTEGER, INTENT(IN), OPTIONAL :: res_int
  270. CHARACTER (LEN=*), OPTIONAL, INTENT(IN) :: testname
  271. LOGICAL, OPTIONAL, INTENT(IN) :: expect_error
  272. ! locals
  273. LOGICAL :: iadd_op
  274. LOGICAL :: isubtract_op
  275. LOGICAL :: imultiply_op
  276. LOGICAL :: idivide_op
  277. INTEGER :: iop1_t_YY
  278. INTEGER :: iop1_t_MM ! month
  279. INTEGER :: iop1_t_DD ! day of month
  280. INTEGER :: iop1_t_H
  281. INTEGER :: iop1_t_M
  282. INTEGER :: iop1_t_S
  283. INTEGER :: iop1_t_Sn
  284. INTEGER :: iop1_t_Sd
  285. INTEGER :: iop1_ti_YY
  286. INTEGER :: iop1_ti_MM ! month
  287. INTEGER :: iop1_ti_DD ! day of month
  288. INTEGER :: iop1_ti_H
  289. INTEGER :: iop1_ti_M
  290. INTEGER :: iop1_ti_S
  291. INTEGER :: iop1_ti_Sn
  292. INTEGER :: iop1_ti_Sd
  293. INTEGER :: iop2_t_YY
  294. INTEGER :: iop2_t_MM ! month
  295. INTEGER :: iop2_t_DD ! day of month
  296. INTEGER :: iop2_t_H
  297. INTEGER :: iop2_t_M
  298. INTEGER :: iop2_t_S
  299. INTEGER :: iop2_t_Sn
  300. INTEGER :: iop2_t_Sd
  301. INTEGER :: iop2_ti_YY
  302. INTEGER :: iop2_ti_MM ! month
  303. INTEGER :: iop2_ti_DD ! day of month
  304. INTEGER :: iop2_ti_H
  305. INTEGER :: iop2_ti_M
  306. INTEGER :: iop2_ti_S
  307. INTEGER :: iop2_ti_Sn
  308. INTEGER :: iop2_ti_Sd
  309. INTEGER :: ires_t_YY
  310. INTEGER :: ires_t_MM ! month
  311. INTEGER :: ires_t_DD ! day of month
  312. INTEGER :: ires_t_H
  313. INTEGER :: ires_t_M
  314. INTEGER :: ires_t_S
  315. INTEGER :: ires_t_Sn
  316. INTEGER :: ires_t_Sd
  317. INTEGER :: ires_ti_YY
  318. INTEGER :: ires_ti_MM ! month
  319. INTEGER :: ires_ti_DD ! day of month
  320. INTEGER :: ires_ti_H
  321. INTEGER :: ires_ti_M
  322. INTEGER :: ires_ti_S
  323. INTEGER :: ires_ti_Sn
  324. INTEGER :: ires_ti_Sd
  325. LOGICAL :: op1_is_t , op2_is_t , res_is_t
  326. LOGICAL :: op1_is_ti, op2_is_ti, res_is_ti, op2_is_int
  327. LOGICAL :: res_is_int
  328. INTEGER :: num_ops, num_op1, num_op2, num_res
  329. LOGICAL :: unsupported_op, test_passed
  330. CHARACTER (LEN=512) :: itestname
  331. LOGICAL :: iexpect_error
  332. INTEGER :: rc
  333. INTEGER :: computed_int, Sn, Sd
  334. TYPE(ESMF_Time) :: op1_t , op2_t , res_t, computed_t
  335. TYPE(ESMF_TimeInterval) :: op1_ti, op2_ti, res_ti, computed_ti
  336. CHARACTER(LEN=ESMF_MAXSTR) :: str, op1_str, op2_str, res_str, computed_str, frac_str
  337. CHARACTER(LEN=1) :: op_str
  338. CHARACTER(LEN=17) :: op1_type_str, op2_type_str, res_type_str
  339. iadd_op = .FALSE.
  340. isubtract_op = .FALSE.
  341. imultiply_op = .FALSE.
  342. idivide_op = .FALSE.
  343. iop1_t_YY = 0
  344. iop1_t_MM = 1
  345. iop1_t_DD = 1
  346. iop1_t_H = 0
  347. iop1_t_M = 0
  348. iop1_t_S = 0
  349. iop1_t_Sn = 0
  350. iop1_t_Sd = 0
  351. iop1_ti_YY = 0
  352. iop1_ti_MM = 0
  353. iop1_ti_DD = 0
  354. iop1_ti_H = 0
  355. iop1_ti_M = 0
  356. iop1_ti_S = 0
  357. iop1_ti_Sn = 0
  358. iop1_ti_Sd = 0
  359. iop2_t_YY = 0
  360. iop2_t_MM = 1
  361. iop2_t_DD = 1
  362. iop2_t_H = 0
  363. iop2_t_M = 0
  364. iop2_t_S = 0
  365. iop2_t_Sn = 0
  366. iop2_t_Sd = 0
  367. iop2_ti_YY = 0
  368. iop2_ti_MM = 0
  369. iop2_ti_DD = 0
  370. iop2_ti_H = 0
  371. iop2_ti_M = 0
  372. iop2_ti_S = 0
  373. iop2_ti_Sn = 0
  374. iop2_ti_Sd = 0
  375. ires_t_YY = 0
  376. ires_t_MM = 1
  377. ires_t_DD = 1
  378. ires_t_H = 0
  379. ires_t_M = 0
  380. ires_t_S = 0
  381. ires_t_Sn = 0
  382. ires_t_Sd = 0
  383. ires_ti_YY = 0
  384. ires_ti_MM = 0
  385. ires_ti_DD = 0
  386. ires_ti_H = 0
  387. ires_ti_M = 0
  388. ires_ti_S = 0
  389. ires_ti_Sn = 0
  390. ires_ti_Sd = 0
  391. itestname = ''
  392. iexpect_error = .FALSE.
  393. IF ( PRESENT( add_op ) ) THEN
  394. iadd_op = add_op
  395. isubtract_op = ( .NOT. add_op )
  396. ENDIF
  397. IF ( PRESENT( multiply_op ) ) THEN
  398. imultiply_op = multiply_op
  399. idivide_op = ( .NOT. multiply_op )
  400. ENDIF
  401. num_ops = 0
  402. IF ( iadd_op ) num_ops = num_ops + 1
  403. IF ( isubtract_op ) num_ops = num_ops + 1
  404. IF ( imultiply_op ) num_ops = num_ops + 1
  405. IF ( idivide_op ) num_ops = num_ops + 1
  406. IF ( num_ops /= 1 ) THEN
  407. CALL wrf_error_fatal3( __FILE__ , __LINE__ , &
  408. 'ERROR test_arithmetic: inconsistent operation' )
  409. ENDIF
  410. IF ( PRESENT( op1_t_YY ) ) iop1_t_YY = op1_t_YY
  411. IF ( PRESENT( op1_t_MM ) ) iop1_t_MM = op1_t_MM
  412. IF ( PRESENT( op1_t_DD ) ) iop1_t_DD = op1_t_DD
  413. IF ( PRESENT( op1_t_H ) ) iop1_t_H = op1_t_H
  414. IF ( PRESENT( op1_t_M ) ) iop1_t_M = op1_t_M
  415. IF ( PRESENT( op1_t_S ) ) iop1_t_S = op1_t_S
  416. IF ( PRESENT( op1_t_Sn ) ) iop1_t_Sn = op1_t_Sn
  417. IF ( PRESENT( op1_t_Sd ) ) iop1_t_Sd = op1_t_Sd
  418. IF ( PRESENT( op1_ti_YY ) ) iop1_ti_YY = op1_ti_YY
  419. IF ( PRESENT( op1_ti_MM ) ) iop1_ti_MM = op1_ti_MM
  420. IF ( PRESENT( op1_ti_DD ) ) iop1_ti_DD = op1_ti_DD
  421. IF ( PRESENT( op1_ti_H ) ) iop1_ti_H = op1_ti_H
  422. IF ( PRESENT( op1_ti_M ) ) iop1_ti_M = op1_ti_M
  423. IF ( PRESENT( op1_ti_S ) ) iop1_ti_S = op1_ti_S
  424. IF ( PRESENT( op1_ti_Sn ) ) iop1_ti_Sn = op1_ti_Sn
  425. IF ( PRESENT( op1_ti_Sd ) ) iop1_ti_Sd = op1_ti_Sd
  426. IF ( PRESENT( op2_t_YY ) ) iop2_t_YY = op2_t_YY
  427. IF ( PRESENT( op2_t_MM ) ) iop2_t_MM = op2_t_MM
  428. IF ( PRESENT( op2_t_DD ) ) iop2_t_DD = op2_t_DD
  429. IF ( PRESENT( op2_t_H ) ) iop2_t_H = op2_t_H
  430. IF ( PRESENT( op2_t_M ) ) iop2_t_M = op2_t_M
  431. IF ( PRESENT( op2_t_S ) ) iop2_t_S = op2_t_S
  432. IF ( PRESENT( op2_t_Sn ) ) iop2_t_Sn = op2_t_Sn
  433. IF ( PRESENT( op2_t_Sd ) ) iop2_t_Sd = op2_t_Sd
  434. IF ( PRESENT( op2_ti_YY ) ) iop2_ti_YY = op2_ti_YY
  435. IF ( PRESENT( op2_ti_MM ) ) iop2_ti_MM = op2_ti_MM
  436. IF ( PRESENT( op2_ti_DD ) ) iop2_ti_DD = op2_ti_DD
  437. IF ( PRESENT( op2_ti_H ) ) iop2_ti_H = op2_ti_H
  438. IF ( PRESENT( op2_ti_M ) ) iop2_ti_M = op2_ti_M
  439. IF ( PRESENT( op2_ti_S ) ) iop2_ti_S = op2_ti_S
  440. IF ( PRESENT( op2_ti_Sn ) ) iop2_ti_Sn = op2_ti_Sn
  441. IF ( PRESENT( op2_ti_Sd ) ) iop2_ti_Sd = op2_ti_Sd
  442. IF ( PRESENT( res_t_YY ) ) ires_t_YY = res_t_YY
  443. IF ( PRESENT( res_t_MM ) ) ires_t_MM = res_t_MM
  444. IF ( PRESENT( res_t_DD ) ) ires_t_DD = res_t_DD
  445. IF ( PRESENT( res_t_H ) ) ires_t_H = res_t_H
  446. IF ( PRESENT( res_t_M ) ) ires_t_M = res_t_M
  447. IF ( PRESENT( res_t_S ) ) ires_t_S = res_t_S
  448. IF ( PRESENT( res_t_Sn ) ) ires_t_Sn = res_t_Sn
  449. IF ( PRESENT( res_t_Sd ) ) ires_t_Sd = res_t_Sd
  450. IF ( PRESENT( res_ti_YY ) ) ires_ti_YY = res_ti_YY
  451. IF ( PRESENT( res_ti_MM ) ) ires_ti_MM = res_ti_MM
  452. IF ( PRESENT( res_ti_DD ) ) ires_ti_DD = res_ti_DD
  453. IF ( PRESENT( res_ti_H ) ) ires_ti_H = res_ti_H
  454. IF ( PRESENT( res_ti_M ) ) ires_ti_M = res_ti_M
  455. IF ( PRESENT( res_ti_S ) ) ires_ti_S = res_ti_S
  456. IF ( PRESENT( res_ti_Sn ) ) ires_ti_Sn = res_ti_Sn
  457. IF ( PRESENT( res_ti_Sd ) ) ires_ti_Sd = res_ti_Sd
  458. IF ( PRESENT( testname ) ) itestname = TRIM(testname)
  459. IF ( PRESENT( expect_error ) ) iexpect_error = expect_error
  460. ! Ensure that optional arguments are consistent...
  461. op1_is_t = ( PRESENT( op1_t_YY ) .OR. PRESENT( op1_t_MM ) .OR. &
  462. PRESENT( op1_t_DD ) .OR. PRESENT( op1_t_H ) .OR. &
  463. PRESENT( op1_t_M ) .OR. PRESENT( op1_t_S ) .OR. &
  464. PRESENT( op1_t_Sn ) .OR. PRESENT( op1_t_Sd ) )
  465. op1_is_ti = ( PRESENT( op1_ti_YY ) .OR. PRESENT( op1_ti_MM ) .OR. &
  466. PRESENT( op1_ti_DD ) .OR. PRESENT( op1_ti_H ) .OR. &
  467. PRESENT( op1_ti_M ) .OR. PRESENT( op1_ti_S ) .OR. &
  468. PRESENT( op1_ti_Sn ) .OR. PRESENT( op1_ti_Sd ) )
  469. op2_is_t = ( PRESENT( op2_t_YY ) .OR. PRESENT( op2_t_MM ) .OR. &
  470. PRESENT( op2_t_DD ) .OR. PRESENT( op2_t_H ) .OR. &
  471. PRESENT( op2_t_M ) .OR. PRESENT( op2_t_S ) .OR. &
  472. PRESENT( op2_t_Sn ) .OR. PRESENT( op2_t_Sd ) )
  473. op2_is_ti = ( PRESENT( op2_ti_YY ) .OR. PRESENT( op2_ti_MM ) .OR. &
  474. PRESENT( op2_ti_DD ) .OR. PRESENT( op2_ti_H ) .OR. &
  475. PRESENT( op2_ti_M ) .OR. PRESENT( op2_ti_S ) .OR. &
  476. PRESENT( op2_ti_Sn ) .OR. PRESENT( op2_ti_Sd ) )
  477. op2_is_int = ( PRESENT( op2_int ) )
  478. res_is_t = ( PRESENT( res_t_YY ) .OR. PRESENT( res_t_MM ) .OR. &
  479. PRESENT( res_t_DD ) .OR. PRESENT( res_t_H ) .OR. &
  480. PRESENT( res_t_M ) .OR. PRESENT( res_t_S ) .OR. &
  481. PRESENT( res_t_Sn ) .OR. PRESENT( res_t_Sd ) )
  482. res_is_ti = ( PRESENT( res_ti_YY ) .OR. PRESENT( res_ti_MM ) .OR. &
  483. PRESENT( res_ti_DD ) .OR. PRESENT( res_ti_H ) .OR. &
  484. PRESENT( res_ti_M ) .OR. PRESENT( res_ti_S ) .OR. &
  485. PRESENT( res_ti_Sn ) .OR. PRESENT( res_ti_Sd ) )
  486. res_is_int = ( PRESENT( res_int ) )
  487. num_op1 = 0
  488. IF ( op1_is_t ) num_op1 = num_op1 + 1
  489. IF ( op1_is_ti ) num_op1 = num_op1 + 1
  490. IF ( num_op1 /= 1 ) THEN
  491. CALL wrf_error_fatal3( __FILE__ , __LINE__ , &
  492. 'ERROR test_arithmetic: inconsistent args for op1' )
  493. ENDIF
  494. num_op2 = 0
  495. IF ( op2_is_t ) num_op2 = num_op2 + 1
  496. IF ( op2_is_ti ) num_op2 = num_op2 + 1
  497. IF ( op2_is_int ) num_op2 = num_op2 + 1
  498. IF ( num_op2 /= 1 ) THEN
  499. CALL wrf_error_fatal3( __FILE__ , __LINE__ , &
  500. 'ERROR test_arithmetic: inconsistent args for op2' )
  501. ENDIF
  502. num_res = 0
  503. IF ( res_is_t ) num_res = num_res + 1
  504. IF ( res_is_ti ) num_res = num_res + 1
  505. IF ( res_is_int ) num_res = num_res + 1
  506. IF ( num_res /= 1 ) THEN
  507. CALL wrf_error_fatal3( __FILE__ , __LINE__ , &
  508. 'ERROR test_arithmetic: inconsistent args for result' )
  509. ENDIF
  510. ! Initialize op1
  511. IF ( op1_is_t ) THEN
  512. op1_type_str = 'ESMF_Time'
  513. CALL ESMF_TimeSet( op1_t, YY=iop1_t_YY, MM=iop1_t_MM, DD=iop1_t_DD , &
  514. H=iop1_t_H, M=iop1_t_M, S=iop1_t_S, Sn=iop1_t_Sn, Sd=iop1_t_Sd, rc=rc )
  515. CALL test_check_error( ESMF_SUCCESS, rc, &
  516. TRIM(itestname)//'ESMF_TimeSet() ', &
  517. __FILE__ , &
  518. __LINE__ )
  519. CALL ESMF_TimeGet( op1_t, timeString=op1_str, Sn=Sn, Sd=Sd, rc=rc )
  520. CALL test_check_error( ESMF_SUCCESS, rc, &
  521. TRIM(itestname)//'ESMF_TimeGet() ', &
  522. __FILE__ , &
  523. __LINE__ )
  524. ! handle fractions
  525. CALL fraction_to_string( Sn, Sd, frac_str )
  526. op1_str = TRIM(op1_str)//TRIM(frac_str)
  527. ELSE
  528. op1_type_str = 'ESMF_TimeInterval'
  529. CALL ESMF_TimeIntervalSet( op1_ti, YY=iop1_ti_YY, MM=iop1_ti_MM, &
  530. D=iop1_ti_DD , &
  531. H=iop1_ti_H, M=iop1_ti_M, &
  532. S=iop1_ti_S, Sn=iop1_ti_Sn, Sd=iop1_ti_Sd, rc=rc )
  533. CALL test_check_error( ESMF_SUCCESS, rc, &
  534. TRIM(itestname)//'ESMF_TimeIntervalSet() ', &
  535. __FILE__ , &
  536. __LINE__ )
  537. CALL ESMF_TimeIntervalGet( op1_ti, timeString=op1_str, Sn=Sn, Sd=Sd, rc=rc )
  538. CALL test_check_error( ESMF_SUCCESS, rc, &
  539. TRIM(itestname)//'ESMF_TimeGet() ', &
  540. __FILE__ , &
  541. __LINE__ )
  542. ! handle fractions
  543. CALL fraction_to_string( Sn, Sd, frac_str )
  544. op1_str = TRIM(op1_str)//TRIM(frac_str)
  545. ENDIF
  546. ! Initialize op2
  547. IF ( op2_is_t ) THEN
  548. op2_type_str = 'ESMF_Time'
  549. CALL ESMF_TimeSet( op2_t, YY=iop2_t_YY, MM=iop2_t_MM, DD=iop2_t_DD , &
  550. H=iop2_t_H, M=iop2_t_M, S=iop2_t_S, Sn=iop2_t_Sn, Sd=iop2_t_Sd, rc=rc )
  551. CALL test_check_error( ESMF_SUCCESS, rc, &
  552. TRIM(itestname)//'ESMF_TimeSet() ', &
  553. __FILE__ , &
  554. __LINE__ )
  555. CALL ESMF_TimeGet( op2_t, timeString=op2_str, Sn=Sn, Sd=Sd, rc=rc )
  556. CALL test_check_error( ESMF_SUCCESS, rc, &
  557. TRIM(itestname)//'ESMF_TimeGet() ', &
  558. __FILE__ , &
  559. __LINE__ )
  560. ! handle fractions
  561. CALL fraction_to_string( Sn, Sd, frac_str )
  562. op2_str = TRIM(op2_str)//TRIM(frac_str)
  563. ELSE IF ( op2_is_ti ) THEN
  564. op2_type_str = 'ESMF_TimeInterval'
  565. CALL ESMF_TimeIntervalSet( op2_ti, YY=iop2_ti_YY, MM=iop2_ti_MM, &
  566. D=iop2_ti_DD , &
  567. H=iop2_ti_H, M=iop2_ti_M, &
  568. S=iop2_ti_S, Sn=iop2_ti_Sn, Sd=iop2_ti_Sd, rc=rc )
  569. CALL test_check_error( ESMF_SUCCESS, rc, &
  570. TRIM(itestname)//'ESMF_TimeIntervalSet() ', &
  571. __FILE__ , &
  572. __LINE__ )
  573. CALL ESMF_TimeIntervalGet( op2_ti, timeString=op2_str, Sn=Sn, Sd=Sd, rc=rc )
  574. CALL test_check_error( ESMF_SUCCESS, rc, &
  575. TRIM(itestname)//'ESMF_TimeGet() ', &
  576. __FILE__ , &
  577. __LINE__ )
  578. ! handle fractions
  579. CALL fraction_to_string( Sn, Sd, frac_str )
  580. op2_str = TRIM(op2_str)//TRIM(frac_str)
  581. ELSE
  582. op2_type_str = 'INTEGER'
  583. IF ( op2_int > 0 ) THEN
  584. WRITE(op2_str,FMT="('+',I8.8)") ABS(op2_int)
  585. ELSE
  586. WRITE(op2_str,FMT="('-',I8.8)") ABS(op2_int)
  587. ENDIF
  588. ENDIF
  589. ! Initialize res
  590. IF ( res_is_t ) THEN ! result is ESMF_Time
  591. res_type_str = 'ESMF_Time'
  592. CALL ESMF_TimeSet( res_t, YY=ires_t_YY, MM=ires_t_MM, DD=ires_t_DD , &
  593. H=ires_t_H, M=ires_t_M, S=ires_t_S, Sn=ires_t_Sn, Sd=ires_t_Sd, rc=rc )
  594. CALL test_check_error( ESMF_SUCCESS, rc, &
  595. TRIM(itestname)//'ESMF_TimeSet() ', &
  596. __FILE__ , &
  597. __LINE__ )
  598. CALL ESMF_TimeGet( res_t, timeString=res_str, Sn=Sn, Sd=Sd, rc=rc )
  599. CALL test_check_error( ESMF_SUCCESS, rc, &
  600. TRIM(itestname)//'ESMF_TimeGet() ', &
  601. __FILE__ , &
  602. __LINE__ )
  603. ! handle fractions
  604. CALL fraction_to_string( Sn, Sd, frac_str )
  605. res_str = TRIM(res_str)//TRIM(frac_str)
  606. ELSE IF ( res_is_ti ) THEN ! result is ESMF_TimeInterval
  607. res_type_str = 'ESMF_TimeInterval'
  608. CALL ESMF_TimeIntervalSet( res_ti, YY=ires_ti_YY, MM=ires_ti_MM, &
  609. D=ires_ti_DD , &
  610. H=ires_ti_H, M=ires_ti_M, &
  611. S=ires_ti_S, Sn=ires_ti_Sn, Sd=ires_ti_Sd, rc=rc )
  612. CALL test_check_error( ESMF_SUCCESS, rc, &
  613. TRIM(itestname)//'ESMF_TimeIntervalSet() ', &
  614. __FILE__ , &
  615. __LINE__ )
  616. CALL ESMF_TimeIntervalGet( res_ti, timeString=res_str, Sn=Sn, Sd=Sd, rc=rc )
  617. CALL test_check_error( ESMF_SUCCESS, rc, &
  618. TRIM(itestname)//'ESMF_TimeGet() ', &
  619. __FILE__ , &
  620. __LINE__ )
  621. ! handle fractions
  622. CALL fraction_to_string( Sn, Sd, frac_str )
  623. res_str = TRIM(res_str)//TRIM(frac_str)
  624. ELSE ! result is INTEGER
  625. res_type_str = 'INTEGER'
  626. IF ( res_int > 0 ) THEN
  627. WRITE(res_str,FMT="('+',I8.8)") ABS(res_int)
  628. ELSE
  629. WRITE(res_str,FMT="('-',I8.8)") ABS(res_int)
  630. ENDIF
  631. ENDIF
  632. ! perform requested operation
  633. unsupported_op = .FALSE.
  634. ! modify behavior of wrf_error_fatal3 for operator being tested
  635. IF ( iexpect_error ) WRF_ERROR_FATAL_PRINT = .TRUE.
  636. ! add
  637. IF ( iadd_op ) THEN
  638. op_str = '+'
  639. IF ( res_is_t ) THEN ! result is ESMF_Time
  640. IF ( op1_is_t .AND. op2_is_ti ) THEN
  641. ! ESMF_Time = ESMF_Time + ESMF_TimeInterval
  642. computed_t = op1_t + op2_ti
  643. ELSE IF ( op1_is_ti .AND. op2_is_t ) THEN
  644. ! ESMF_Time = ESMF_TimeInterval + ESMF_Time
  645. computed_t = op1_ti + op2_t
  646. ELSE
  647. unsupported_op = .TRUE.
  648. ENDIF
  649. ELSE ! result is ESMF_TimeInterval
  650. IF ( op1_is_ti .AND. op2_is_ti ) THEN
  651. ! ESMF_TimeInterval = ESMF_TimeInterval + ESMF_TimeInterval
  652. computed_ti = op1_ti + op2_ti
  653. ELSE
  654. unsupported_op = .TRUE.
  655. ENDIF
  656. ENDIF
  657. ! subtract
  658. ELSE IF ( isubtract_op ) THEN
  659. op_str = '-'
  660. IF ( res_is_t ) THEN ! result is ESMF_Time
  661. IF ( op1_is_t .AND. op2_is_ti ) THEN
  662. ! ESMF_Time = ESMF_Time - ESMF_TimeInterval
  663. computed_t = op1_t - op2_ti
  664. ELSE
  665. unsupported_op = .TRUE.
  666. ENDIF
  667. ELSE ! result is ESMF_TimeInterval
  668. IF ( op1_is_t .AND. op2_is_t ) THEN
  669. ! ESMF_TimeInterval = ESMF_Time - ESMF_Time
  670. computed_ti = op1_t - op2_t
  671. ELSE IF ( op1_is_ti .AND. op2_is_ti ) THEN
  672. ! ESMF_TimeInterval = ESMF_TimeInterval - ESMF_TimeInterval
  673. computed_ti = op1_ti - op2_ti
  674. ELSE
  675. unsupported_op = .TRUE.
  676. ENDIF
  677. ENDIF
  678. ELSE IF ( imultiply_op ) THEN
  679. op_str = '*'
  680. IF ( res_is_ti ) THEN ! result is ESMF_TimeInterval
  681. IF ( op1_is_ti .AND. op2_is_int ) THEN
  682. ! ESMF_TimeInterval = ESMF_TimeInterval * INTEGER
  683. computed_ti = op1_ti * op2_int
  684. ELSE
  685. unsupported_op = .TRUE.
  686. ENDIF
  687. ENDIF
  688. ELSE IF ( idivide_op ) THEN
  689. op_str = '/'
  690. IF ( res_is_ti ) THEN ! result is ESMF_TimeInterval
  691. IF ( op1_is_ti .AND. op2_is_int ) THEN
  692. ! ESMF_TimeInterval = ESMF_TimeInterval / INTEGER
  693. computed_ti = op1_ti / op2_int
  694. ELSE
  695. unsupported_op = .TRUE.
  696. ENDIF
  697. ELSE IF ( res_is_int ) THEN ! result is INTEGER
  698. IF ( op1_is_ti .AND. op2_is_ti ) THEN
  699. ! INTEGER = ESMF_TimeInterval / ESMF_TimeInterval
  700. ! number of whole time intervals
  701. computed_int = ESMF_TimeIntervalDIVQuot( op1_ti , op2_ti )
  702. ELSE
  703. unsupported_op = .TRUE.
  704. ENDIF
  705. ENDIF
  706. ENDIF
  707. ! restore default behavior of wrf_error_fatal3
  708. IF ( iexpect_error ) WRF_ERROR_FATAL_PRINT = .FALSE.
  709. IF ( unsupported_op ) THEN
  710. WRITE(str,*) 'ERROR test_arithmetic ',TRIM(itestname), &
  711. ': unsupported operation (', &
  712. TRIM(res_type_str),' = ',TRIM(op1_type_str),' ',TRIM(op_str),' ', &
  713. TRIM(op2_type_str),')'
  714. CALL wrf_error_fatal3( __FILE__ , __LINE__ , str )
  715. ENDIF
  716. ! check result
  717. test_passed = .FALSE.
  718. IF ( res_is_t ) THEN ! result is ESMF_Time
  719. IF ( computed_t == res_t ) THEN
  720. test_passed = .TRUE.
  721. ELSE
  722. CALL ESMF_TimeGet( computed_t, timeString=computed_str, Sn=Sn, Sd=Sd, rc=rc )
  723. CALL test_check_error( ESMF_SUCCESS, rc, &
  724. TRIM(itestname)//'ESMF_TimeGet() ', &
  725. __FILE__ , &
  726. __LINE__ )
  727. ! handle fractions
  728. CALL fraction_to_string( Sn, Sd, frac_str )
  729. computed_str = TRIM(computed_str)//TRIM(frac_str)
  730. ENDIF
  731. ELSE IF ( res_is_ti ) THEN ! result is ESMF_TimeInterval
  732. IF ( computed_ti == res_ti ) THEN
  733. test_passed = .TRUE.
  734. ELSE
  735. CALL ESMF_TimeIntervalGet( computed_ti, timeString=computed_str, Sn=Sn, Sd=Sd, rc=rc )
  736. CALL test_check_error( ESMF_SUCCESS, rc, &
  737. TRIM(itestname)//'ESMF_TimeGet() ', &
  738. __FILE__ , &
  739. __LINE__ )
  740. ! handle fractions
  741. CALL fraction_to_string( Sn, Sd, frac_str )
  742. computed_str = TRIM(computed_str)//TRIM(frac_str)
  743. ENDIF
  744. ELSE ! result is INTEGER
  745. IF ( computed_int == res_int ) THEN
  746. test_passed = .TRUE.
  747. ELSE
  748. IF ( computed_int > 0 ) THEN
  749. WRITE(computed_str,FMT="('+',I8.8)") ABS(computed_int)
  750. ELSE
  751. WRITE(computed_str,FMT="('-',I8.8)") ABS(computed_int)
  752. ENDIF
  753. ENDIF
  754. ENDIF
  755. IF ( test_passed ) THEN
  756. WRITE(*,FMT='(A)') 'PASS: '//TRIM(itestname)
  757. ELSE
  758. WRITE(*,*) 'FAIL: ',TRIM(itestname),': (', &
  759. TRIM(res_type_str),' = ',TRIM(op1_type_str),' ',TRIM(op_str),' ', &
  760. TRIM(op2_type_str),') expected ', &
  761. TRIM(res_str),' = ',TRIM(op1_str),' ',TRIM(op_str),' ', &
  762. TRIM(op2_str),' but computed ',TRIM(computed_str)
  763. ENDIF
  764. END SUBROUTINE test_arithmetic
  765. ! simple clock creation and advance with add-subtract tests thrown in
  766. ! no self checks (yet)
  767. SUBROUTINE test_clock_advance( &
  768. start_yy, start_mm, start_dd, start_h, start_m, start_s, &
  769. stop_yy, stop_mm, stop_dd, stop_h, stop_m, stop_s, &
  770. timestep_d, timestep_h, timestep_m, timestep_s, timestep_sn, timestep_sd, &
  771. testname, increment_S, increment_Sn, increment_Sd )
  772. INTEGER, INTENT(IN), OPTIONAL :: start_YY
  773. INTEGER, INTENT(IN), OPTIONAL :: start_MM ! month
  774. INTEGER, INTENT(IN), OPTIONAL :: start_DD ! day of month
  775. INTEGER, INTENT(IN), OPTIONAL :: start_H
  776. INTEGER, INTENT(IN), OPTIONAL :: start_M
  777. INTEGER, INTENT(IN), OPTIONAL :: start_S
  778. INTEGER, INTENT(IN), OPTIONAL :: stop_YY
  779. INTEGER, INTENT(IN), OPTIONAL :: stop_MM ! month
  780. INTEGER, INTENT(IN), OPTIONAL :: stop_DD ! day of month
  781. INTEGER, INTENT(IN), OPTIONAL :: stop_H
  782. INTEGER, INTENT(IN), OPTIONAL :: stop_M
  783. INTEGER, INTENT(IN), OPTIONAL :: stop_S
  784. INTEGER, INTENT(IN), OPTIONAL :: timestep_D ! day
  785. INTEGER, INTENT(IN), OPTIONAL :: timestep_H
  786. INTEGER, INTENT(IN), OPTIONAL :: timestep_M
  787. INTEGER, INTENT(IN), OPTIONAL :: timestep_S
  788. INTEGER, INTENT(IN), OPTIONAL :: timestep_Sn
  789. INTEGER, INTENT(IN), OPTIONAL :: timestep_Sd
  790. CHARACTER (LEN=*), OPTIONAL, INTENT(IN) :: testname
  791. INTEGER, INTENT(IN), OPTIONAL :: increment_S ! add and subtract this
  792. INTEGER, INTENT(IN), OPTIONAL :: increment_Sn ! value each time step
  793. INTEGER, INTENT(IN), OPTIONAL :: increment_Sd
  794. ! locals
  795. INTEGER :: istart_YY
  796. INTEGER :: istart_MM ! month
  797. INTEGER :: istart_DD ! day of month
  798. INTEGER :: istart_H
  799. INTEGER :: istart_M
  800. INTEGER :: istart_S
  801. INTEGER :: istop_YY
  802. INTEGER :: istop_MM ! month
  803. INTEGER :: istop_DD ! day of month
  804. INTEGER :: istop_H
  805. INTEGER :: istop_M
  806. INTEGER :: istop_S
  807. INTEGER :: itimestep_D ! day
  808. INTEGER :: itimestep_H
  809. INTEGER :: itimestep_M
  810. INTEGER :: itimestep_S
  811. INTEGER :: itimestep_Sn
  812. INTEGER :: itimestep_Sd
  813. CHARACTER (LEN=512) :: itestname, itestfullname
  814. INTEGER :: iincrement_S
  815. INTEGER :: iincrement_Sn
  816. INTEGER :: iincrement_Sd
  817. INTEGER :: Sn, Sd
  818. INTEGER rc
  819. TYPE(ESMF_Time) :: start_time, stop_time, current_time
  820. TYPE(ESMF_Clock), POINTER :: domain_clock
  821. TYPE(ESMF_TimeInterval) :: timestep, increment
  822. TYPE(ESMF_Time) :: add_time, subtract_time
  823. INTEGER :: itimestep
  824. REAL(ESMF_KIND_R8) :: dayr8
  825. CHARACTER(LEN=ESMF_MAXSTR) :: str, frac_str
  826. istart_YY = 0
  827. istart_MM = 1
  828. istart_DD = 1
  829. istart_H = 0
  830. istart_M = 0
  831. istart_S = 0
  832. istop_YY = 0
  833. istop_MM = 1
  834. istop_DD = 1
  835. istop_H = 0
  836. istop_M = 0
  837. istop_S = 0
  838. itimestep_D = 0
  839. itimestep_H = 0
  840. itimestep_M = 0
  841. itimestep_S = 0
  842. itimestep_Sn = 0
  843. itimestep_Sd = 0
  844. itestname = ''
  845. iincrement_S = 0
  846. iincrement_Sn = 0
  847. iincrement_Sd = 0
  848. IF ( PRESENT( start_YY ) ) istart_YY = start_YY
  849. IF ( PRESENT( start_MM ) ) istart_MM = start_MM
  850. IF ( PRESENT( start_DD ) ) istart_DD = start_DD
  851. IF ( PRESENT( start_H ) ) istart_H = start_H
  852. IF ( PRESENT( start_M ) ) istart_M = start_M
  853. IF ( PRESENT( start_S ) ) istart_S = start_S
  854. IF ( PRESENT( stop_YY ) ) istop_YY = stop_YY
  855. IF ( PRESENT( stop_MM ) ) istop_MM = stop_MM
  856. IF ( PRESENT( stop_DD ) ) istop_DD = stop_DD
  857. IF ( PRESENT( stop_H ) ) istop_H = stop_H
  858. IF ( PRESENT( stop_M ) ) istop_M = stop_M
  859. IF ( PRESENT( stop_S ) ) istop_S = stop_S
  860. IF ( PRESENT( timestep_D ) ) itimestep_D = timestep_D
  861. IF ( PRESENT( timestep_H ) ) itimestep_H = timestep_H
  862. IF ( PRESENT( timestep_M ) ) itimestep_M = timestep_M
  863. IF ( PRESENT( timestep_S ) ) itimestep_S = timestep_S
  864. IF ( PRESENT( timestep_Sn ) ) itimestep_Sn = timestep_Sn
  865. IF ( PRESENT( timestep_Sd ) ) itimestep_Sd = timestep_Sd
  866. IF ( PRESENT( testname ) ) itestname = TRIM(testname)//'_'
  867. IF ( PRESENT( increment_S ) ) iincrement_S = increment_S
  868. IF ( PRESENT( increment_Sn ) ) iincrement_Sn = increment_Sn
  869. IF ( PRESENT( increment_Sd ) ) iincrement_Sd = increment_Sd
  870. ! Initialize start time, stop time, time step, clock for simple case.
  871. itestfullname = TRIM(itestname)//'SETUP'
  872. CALL ESMF_TimeSet( start_time, YY=istart_YY, MM=istart_MM, DD=istart_DD , &
  873. H=istart_H, M=istart_M, S=istart_S, rc=rc )
  874. CALL test_check_error( ESMF_SUCCESS, rc, &
  875. TRIM(itestfullname)//'ESMF_TimeSet() ', &
  876. __FILE__ , &
  877. __LINE__ )
  878. CALL ESMF_TimeGet( start_time, timeString=str, rc=rc )
  879. CALL test_check_error( ESMF_SUCCESS, rc, &
  880. TRIM(itestfullname)//'ESMF_TimeGet() ', &
  881. __FILE__ , &
  882. __LINE__ )
  883. WRITE(*,FMT='(A,A,A,A)') TRIM(itestfullname),': start_time = <',TRIM(str),'>'
  884. CALL ESMF_TimeSet( stop_time, YY=istop_YY, MM=istop_MM, DD=istop_DD , &
  885. H=istop_H, M=istop_M, S=istop_S, rc=rc )
  886. CALL test_check_error( ESMF_SUCCESS, rc, &
  887. TRIM(itestfullname)//'ESMF_TimeSet() ', &
  888. __FILE__ , &
  889. __LINE__ )
  890. CALL ESMF_TimeGet( stop_time, timeString=str, rc=rc )
  891. CALL test_check_error( ESMF_SUCCESS, rc, &
  892. TRIM(itestfullname)//'ESMF_TimeGet() ', &
  893. __FILE__ , &
  894. __LINE__ )
  895. WRITE(*,FMT='(A,A,A,A)') TRIM(itestfullname),': stop_time = <',TRIM(str),'>'
  896. CALL ESMF_TimeIntervalSet( timestep, D=itimestep_D, H=itimestep_H, &
  897. M=itimestep_M, S=itimestep_S, &
  898. Sn=itimestep_Sn, Sd=itimestep_Sd, rc=rc )
  899. CALL test_check_error( ESMF_SUCCESS, rc, &
  900. TRIM(itestfullname)//'ESMF_TimeIntervalSet() ', &
  901. __FILE__ , &
  902. __LINE__ )
  903. CALL ESMF_TimeIntervalGet( timestep, timeString=str, Sn=Sn, Sd=Sd, rc=rc )
  904. CALL test_check_error( ESMF_SUCCESS, rc, &
  905. TRIM(itestfullname)//'ESMF_TimeIntervalGet() ', &
  906. __FILE__ , &
  907. __LINE__ )
  908. ! handle fractions
  909. CALL fraction_to_string( Sn, Sd, frac_str )
  910. str = TRIM(str)//TRIM(frac_str)
  911. WRITE(*,FMT='(A,A,A,A)') TRIM(itestfullname),': timestep = <',TRIM(str),'>'
  912. CALL ESMF_TimeIntervalSet( increment, S=iincrement_S, &
  913. Sn=iincrement_Sn, Sd=iincrement_Sd, rc=rc )
  914. CALL test_check_error( ESMF_SUCCESS, rc, &
  915. TRIM(itestfullname)//'ESMF_TimeIntervalSet() ', &
  916. __FILE__ , &
  917. __LINE__ )
  918. CALL ESMF_TimeIntervalGet( increment, timeString=str, Sn=Sn, Sd=Sd, rc=rc )
  919. CALL test_check_error( ESMF_SUCCESS, rc, &
  920. TRIM(itestfullname)//'ESMF_TimeIntervalGet() ', &
  921. __FILE__ , &
  922. __LINE__ )
  923. ! handle fractions
  924. CALL fraction_to_string( Sn, Sd, frac_str )
  925. str = TRIM(str)//TRIM(frac_str)
  926. WRITE(*,FMT='(A,A,A,A)') TRIM(itestfullname),': increment = <',TRIM(str),'>'
  927. ALLOCATE( domain_clock )
  928. domain_clock = ESMF_ClockCreate( TimeStep= timestep, &
  929. StartTime=start_time, &
  930. StopTime= stop_time, &
  931. rc=rc )
  932. CALL test_check_error( ESMF_SUCCESS, rc, &
  933. TRIM(itestfullname)//'ESMF_ClockCreate() ', &
  934. __FILE__ , &
  935. __LINE__ )
  936. CALL ESMF_ClockGet( domain_clock, CurrTime=current_time, &
  937. rc=rc )
  938. CALL test_check_error( ESMF_SUCCESS, rc, &
  939. TRIM(itestfullname)//'ESMF_ClockGet() ', &
  940. __FILE__ , &
  941. __LINE__ )
  942. CALL ESMF_TimeGet( current_time, timeString=str, Sn=Sn, Sd=Sd, rc=rc )
  943. CALL test_check_error( ESMF_SUCCESS, rc, &
  944. TRIM(itestfullname)//'ESMF_TimeGet() ', &
  945. __FILE__ , &
  946. __LINE__ )
  947. CALL fraction_to_string( Sn, Sd, frac_str )
  948. str = TRIM(str)//TRIM(frac_str)
  949. WRITE(*,FMT='(A,A,A,A)') TRIM(itestfullname),': clock current_time = <',TRIM(str),'>'
  950. CALL ESMF_TimeGet( current_time, dayOfYear_r8=dayr8, rc=rc )
  951. CALL test_check_error( ESMF_SUCCESS, rc, &
  952. TRIM(itestfullname)//'ESMF_TimeGet() ', &
  953. __FILE__ , &
  954. __LINE__ )
  955. WRITE(*,FMT='(A,A,F10.6,A)') TRIM(itestfullname),': current_time dayOfYear_r8 = < ',dayr8,' >'
  956. subtract_time = current_time - increment
  957. CALL ESMF_TimeGet( subtract_time, timeString=str, Sn=Sn, Sd=Sd, rc=rc )
  958. CALL test_check_error( ESMF_SUCCESS, rc, &
  959. TRIM(itestfullname)//'ESMF_TimeGet() ', &
  960. __FILE__ , &
  961. __LINE__ )
  962. CALL fraction_to_string( Sn, Sd, frac_str )
  963. str = TRIM(str)//TRIM(frac_str)
  964. WRITE(*,FMT='(A,A,A,A)') TRIM(itestfullname),': current_time-increment = <',TRIM(str),'>'
  965. add_time = current_time + increment
  966. CALL ESMF_TimeGet( add_time, timeString=str, Sn=Sn, Sd=Sd, rc=rc )
  967. CALL test_check_error( ESMF_SUCCESS, rc, &
  968. TRIM(itestfullname)//'ESMF_TimeGet() ', &
  969. __FILE__ , &
  970. __LINE__ )
  971. CALL fraction_to_string( Sn, Sd, frac_str )
  972. str = TRIM(str)//TRIM(frac_str)
  973. WRITE(*,FMT='(A,A,A,A)') TRIM(itestfullname),': current_time+increment = <',TRIM(str),'>'
  974. ! Advance clock.
  975. itestfullname = TRIM(itestname)//'ADVANCE'
  976. itimestep = 0
  977. DO WHILE ( .NOT. ESMF_ClockIsStopTime(domain_clock ,rc=rc) )
  978. CALL test_check_error( ESMF_SUCCESS, rc, &
  979. TRIM(itestfullname)//'ESMF_ClockIsStopTime() ', &
  980. __FILE__ , &
  981. __LINE__ )
  982. itimestep = itimestep + 1
  983. CALL ESMF_ClockAdvance( domain_clock, rc=rc )
  984. CALL test_check_error( ESMF_SUCCESS, rc, &
  985. TRIM(itestfullname)//'ESMF_ClockAdvance() ', &
  986. __FILE__ , &
  987. __LINE__ )
  988. CALL ESMF_ClockGet( domain_clock, CurrTime=current_time, &
  989. rc=rc )
  990. CALL test_check_error( ESMF_SUCCESS, rc, &
  991. TRIM(itestfullname)//'ESMF_ClockGet() ', &
  992. __FILE__ , &
  993. __LINE__ )
  994. CALL ESMF_TimeGet( current_time, timeString=str, Sn=Sn, Sd=Sd, rc=rc )
  995. CALL test_check_error( ESMF_SUCCESS, rc, &
  996. TRIM(itestfullname)//'ESMF_TimeGet() ', &
  997. __FILE__ , &
  998. __LINE__ )
  999. CALL fraction_to_string( Sn, Sd, frac_str )
  1000. str = TRIM(str)//TRIM(frac_str)
  1001. WRITE(*,FMT='(A,A,I6.6,A,A,A)') TRIM(itestfullname),': count = ', &
  1002. itimestep,' current_time = <',TRIM(str),'>'
  1003. subtract_time = current_time - increment
  1004. CALL ESMF_TimeGet( subtract_time, timeString=str, Sn=Sn, Sd=Sd, rc=rc )
  1005. CALL test_check_error( ESMF_SUCCESS, rc, &
  1006. TRIM(itestfullname)//'ESMF_TimeGet() ', &
  1007. __FILE__ , &
  1008. __LINE__ )
  1009. CALL fraction_to_string( Sn, Sd, frac_str )
  1010. str = TRIM(str)//TRIM(frac_str)
  1011. WRITE(*,FMT='(A,A,A,A)') TRIM(itestfullname),': current_time-increment = <',TRIM(str),'>'
  1012. add_time = current_time + increment
  1013. CALL ESMF_TimeGet( add_time, timeString=str, Sn=Sn, Sd=Sd, rc=rc )
  1014. CALL test_check_error( ESMF_SUCCESS, rc, &
  1015. TRIM(itestfullname)//'ESMF_TimeGet() ', &
  1016. __FILE__ , &
  1017. __LINE__ )
  1018. CALL fraction_to_string( Sn, Sd, frac_str )
  1019. str = TRIM(str)//TRIM(frac_str)
  1020. WRITE(*,FMT='(A,A,A,A)') TRIM(itestfullname),': current_time+increment = <',TRIM(str),'>'
  1021. ENDDO
  1022. DEALLOCATE( domain_clock )
  1023. END SUBROUTINE test_clock_advance
  1024. END MODULE my_tests
  1025. #if defined( TIME_F90_ONLY )
  1026. ! TBH: Improve the build of Test1.exe to use WRF versions of these
  1027. ! TBH: routines and remove these hacked-in duplicates!!
  1028. SUBROUTINE wrf_abort
  1029. IMPLICIT NONE
  1030. #if defined( DM_PARALLEL ) && ! defined( STUBMPI )
  1031. INCLUDE 'mpif.h'
  1032. INTEGER ierr
  1033. CALL mpi_abort(MPI_COMM_WORLD,1,ierr)
  1034. #else
  1035. STOP
  1036. #endif
  1037. END SUBROUTINE wrf_abort
  1038. SUBROUTINE wrf_message( str )
  1039. IMPLICIT NONE
  1040. CHARACTER*(*) str
  1041. #if defined( DM_PARALLEL ) && ! defined( STUBMPI)
  1042. write(0,*) str
  1043. #endif
  1044. print*, str
  1045. END SUBROUTINE wrf_message
  1046. ! intentionally write to stderr only
  1047. SUBROUTINE wrf_message2( str )
  1048. IMPLICIT NONE
  1049. CHARACTER*(*) str
  1050. write(0,*) str
  1051. END SUBROUTINE wrf_message2
  1052. SUBROUTINE wrf_error_fatal3( file_str, line, str )
  1053. USE my_tests
  1054. IMPLICIT NONE
  1055. CHARACTER*(*) file_str
  1056. INTEGER , INTENT (IN) :: line ! only print file and line if line > 0
  1057. CHARACTER*(*) str
  1058. CHARACTER*256 :: line_str
  1059. write(line_str,'(i6)') line
  1060. ! special behavior for testing since Fortran cannot catch exceptions
  1061. IF ( WRF_ERROR_FATAL_PRINT ) THEN
  1062. ! just print message and continue
  1063. CALL wrf_message( 'ERROR IN FILE: '//TRIM(file_str)//' LINE: '//TRIM(line_str) )
  1064. ELSE
  1065. ! normal behavior
  1066. #if defined( DM_PARALLEL ) && ! defined( STUBMPI )
  1067. CALL wrf_message( '-------------- FATAL CALLED ---------------' )
  1068. ! only print file and line if line is positive
  1069. IF ( line > 0 ) THEN
  1070. CALL wrf_message( 'FATAL CALLED FROM FILE: '//file_str//' LINE: '//TRIM(line_str) )
  1071. ENDIF
  1072. CALL wrf_message( str )
  1073. CALL wrf_message( '-------------------------------------------' )
  1074. #else
  1075. CALL wrf_message2( '-------------- FATAL CALLED ---------------' )
  1076. ! only print file and line if line is positive
  1077. IF ( line > 0 ) THEN
  1078. CALL wrf_message( 'FATAL CALLED FROM FILE: '//file_str//' LINE: '//TRIM(line_str) )
  1079. ENDIF
  1080. CALL wrf_message2( str )
  1081. CALL wrf_message2( '-------------------------------------------' )
  1082. #endif
  1083. CALL wrf_abort
  1084. ENDIF
  1085. END SUBROUTINE wrf_error_fatal3
  1086. SUBROUTINE wrf_error_fatal( str )
  1087. IMPLICIT NONE
  1088. CHARACTER*(*) str
  1089. CALL wrf_error_fatal3 ( ' ', 0, str )
  1090. END SUBROUTINE wrf_error_fatal
  1091. #endif
  1092. ! Check to see if expected value == actual value
  1093. ! If not, print message and exit.
  1094. SUBROUTINE test_check_error( expected, actual, str, file_str, line )
  1095. IMPLICIT NONE
  1096. INTEGER , INTENT (IN) :: expected
  1097. INTEGER , INTENT (IN) :: actual
  1098. CHARACTER*(*) str
  1099. CHARACTER*(*) file_str
  1100. INTEGER , INTENT (IN) :: line
  1101. CHARACTER (LEN=512) :: rc_str
  1102. CHARACTER (LEN=512) :: str_with_rc
  1103. IF ( expected .ne. actual ) THEN
  1104. WRITE (rc_str,*) ' Routine returned error code = ',actual
  1105. str_with_rc = 'FAIL: '//TRIM(str)//TRIM(rc_str)
  1106. CALL wrf_error_fatal3( file_str, line, str_with_rc )
  1107. ENDIF
  1108. END SUBROUTINE test_check_error
  1109. PROGRAM time_manager_test
  1110. USE ESMF_Mod
  1111. USE my_tests
  1112. IMPLICIT NONE
  1113. INTEGER :: rc
  1114. PRINT *,'BEGIN TEST SUITE'
  1115. CALL ESMF_Initialize( defaultCalendar=ESMF_CAL_GREGORIAN, rc=rc )
  1116. CALL test_check_error( ESMF_SUCCESS, rc, &
  1117. 'ESMF_Initialize() ', &
  1118. __FILE__ , &
  1119. __LINE__ )
  1120. ! PRINT *,'DEBUG: back from ESMF_Initialize(), rc = ',rc
  1121. ! CALL test_print( t_yy, t_mm, t_dd, t_h, t_m, t_s, &
  1122. ! ti_yy, ti_mm, ti_dd, ti_h, ti_m, ti_s, &
  1123. ! res_str, testname )
  1124. ! Print times
  1125. ! "vanilla" tests
  1126. ! PRINT *,'DEBUG: calling 1st test_print()'
  1127. CALL test_print( t_yy=2001, t_mm=12, t_dd=3, t_h=1, t_m=20, t_s=10, &
  1128. res_str='2001-12-03_01:20:10', testname='printT_1' )
  1129. ! PRINT *,'DEBUG: back from 1st test_print()'
  1130. CALL test_print( t_yy=0, t_mm=1, t_dd=1, t_h=0, t_m=0, t_s=0, &
  1131. res_str='0000-01-01_00:00:00', testname='printT_2' )
  1132. CALL test_print( t_yy=2003, t_mm=12, t_dd=30, t_h=23, t_m=59, t_s=50, &
  1133. res_str='2003-12-30_23:59:50', testname='printT_3' )
  1134. CALL test_print( t_yy=2003, t_mm=12, t_dd=31, t_h=23, t_m=59, t_s=50, &
  1135. res_str='2003-12-31_23:59:50', testname='printT_4' )
  1136. CALL test_print( t_yy=2004, t_mm=12, t_dd=30, t_h=23, t_m=59, t_s=50, &
  1137. res_str='2004-12-30_23:59:50', testname='printT_5' )
  1138. CALL test_print( t_yy=2004, t_mm=12, t_dd=31, t_h=23, t_m=59, t_s=50, &
  1139. res_str='2004-12-31_23:59:50', testname='printT_6' )
  1140. !$$$ NOTE that this fails -- need to fix up output string for negative year
  1141. ! CALL test_print( t_yy=-2004, t_mm=12, t_dd=31, t_h=23, t_m=59, t_s=50, &
  1142. ! res_str='-2004-12-31_23:59:50', testname='printT_6' )
  1143. ! these test default behavior of test harness
  1144. CALL test_print( t_s=0, &
  1145. res_str='0000-01-01_00:00:00', testname='printT_D1' )
  1146. CALL test_print( t_yy=0, &
  1147. res_str='0000-01-01_00:00:00', testname='printT_D2' )
  1148. ! fractions
  1149. CALL test_print( t_yy=2001, t_mm=12, t_dd=3, t_h=1, t_m=20, t_s=10, &
  1150. t_sn=1, t_sd=3, &
  1151. res_str='2001-12-03_01:20:10+01/03', testname='printT_F1' )
  1152. CALL test_print( t_yy=2001, t_mm=12, t_dd=3, t_h=1, t_m=20, t_s=10, &
  1153. t_sn=4, t_sd=3, &
  1154. res_str='2001-12-03_01:20:11+01/03', testname='printT_F2' )
  1155. CALL test_print( t_yy=2001, t_mm=12, t_dd=3, t_h=1, t_m=20, t_s=10, &
  1156. t_sn=12, t_sd=3, &
  1157. res_str='2001-12-03_01:20:14', testname='printT_F3' )
  1158. CALL test_print( t_yy=2001, t_mm=12, t_dd=3, t_h=1, t_m=20, t_s=10, &
  1159. t_sn=-1, t_sd=3, &
  1160. res_str='2001-12-03_01:20:09+02/03', testname='printT_F4' )
  1161. ! ERROR, MM out of range
  1162. !$$$here... fix so th

Large files files are truncated, but you can click here to view the full file