PageRenderTime 40ms CodeModel.GetById 20ms 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
  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 this just prints "ERROR: <testname>" in failure case
  1163. !$$$here... also need "expect_fail" to reverse sense of PASS/FAIL message for
  1164. !$$$here... tests that should fail
  1165. ! CALL test_print( t_yy=2001, t_mm=13, t_dd=3, t_h=1, t_m=20, t_s=10, &
  1166. ! res_str='2002-01-03_01:20:10', testname='printT_E1', expect_error=.TRUE. )
  1167. ! Print time intervals
  1168. ! "vanilla" tests
  1169. CALL test_print( ti_yy=0, ti_mm=0, ti_dd=0, ti_h=0, ti_m=0, ti_s=0, &
  1170. res_str='0000000000_000:000:000', testname='printTI_1' )
  1171. CALL test_print( ti_yy=0, ti_mm=0, ti_dd=500, ti_h=0, ti_m=0, ti_s=7270, &
  1172. res_str='0000000500_002:001:010', testname='printTI_2' )
  1173. ! these test default behavior of test harness
  1174. CALL test_print( ti_s=0, &
  1175. res_str='0000000000_000:000:000', testname='printTI_D1' )
  1176. CALL test_print( ti_yy=0, &
  1177. res_str='0000000000_000:000:000', testname='printTI_D2' )
  1178. ! these test negative values
  1179. CALL test_print( ti_yy=0000, ti_mm=0, ti_dd=-3, ti_h=-1, ti_m=-20, ti_s=-10, &
  1180. res_str='-0000000003_001:020:010', testname='printTI_N1' )
  1181. ! these test mixed values
  1182. CALL test_print( ti_yy=0000, ti_mm=0, ti_dd=-3, ti_h=1, ti_m=20, ti_s=10, &
  1183. res_str='-0000000002_022:039:050', testname='printTI_M1' )
  1184. ! fractions
  1185. CALL test_print( ti_yy=0000, ti_mm=0, ti_dd=3, ti_h=1, ti_m=20, ti_s=10, &
  1186. ti_sn=1, ti_sd=3, &
  1187. res_str='0000000003_001:020:010+01/03', testname='printTI_F1' )
  1188. CALL test_print( ti_yy=0000, ti_mm=0, ti_dd=3, ti_h=1, ti_m=20, ti_s=10, &
  1189. ti_sn=5, ti_sd=3, &
  1190. res_str='0000000003_001:020:011+02/03', testname='printTI_F2' )
  1191. CALL test_print( ti_yy=0000, ti_mm=0, ti_dd=-3, ti_h=-1, ti_m=-20, ti_s=-10, &
  1192. ti_sn=-1, ti_sd=3, &
  1193. res_str='-0000000003_001:020:010-01/03', testname='printTI_F3' )
  1194. CALL test_print( ti_yy=0000, ti_mm=0, ti_dd=-3, ti_h=-1, ti_m=-20, ti_s=-10, &
  1195. ti_sn=1, ti_sd=3, &
  1196. res_str='-0000000003_001:020:009-02/03', testname='printTI_F4' )
  1197. ! these test non-normalized values
  1198. ! CALL test_print( ti_yy=2001, ti_mm=1, ti_dd=3, ti_h=1, ti_m=20, ti_s=10, &
  1199. ! res_str='02001-001-003_001:020:010', testname='printTI_NN1', expect_error=.TRUE. )
  1200. ! CALL test_print( ti_yy=2001, ti_mm=12, ti_dd=3, ti_h=1, ti_m=20, ti_s=10, &
  1201. ! res_str='02002-000-003_001:020:010', testname='printTI_NN2', expect_error=.TRUE. )
  1202. ! CALL test_print( ti_yy=2002, ti_mm=5, ti_dd=500, ti_h=0, ti_m=0, ti_s=7270, &
  1203. ! res_str='02002-005-500_002:001:010', testname='printTI_NN3', expect_error=.TRUE. )
  1204. ! Addition tests
  1205. ! ESMF_Time = ESMF_Time + ESMF_TimeInterval
  1206. CALL test_arithmetic( add_op=.TRUE., &
  1207. op1_t_yy=2001, op1_t_mm=12, op1_t_dd=3, op1_t_h=1, op1_t_m=20, op1_t_s=10, &
  1208. op2_ti_yy= 0, op2_ti_mm= 0, op2_ti_dd=0, op2_ti_h=3, op2_ti_m=10, op2_ti_s=10, &
  1209. res_t_yy=2001, res_t_mm=12, res_t_dd=3, res_t_h=4, res_t_m=30, res_t_s=20, &
  1210. testname='AddT_T_TI1' )
  1211. CALL test_arithmetic( add_op=.TRUE., &
  1212. op1_t_yy=2001, op1_t_mm=12, op1_t_dd=31, op1_t_h=22, op1_t_m=30, op1_t_s=00, &
  1213. op2_ti_yy= 0, op2_ti_mm= 0, op2_ti_dd=0, op2_ti_h=4, op2_ti_m=10, op2_ti_s=10, &
  1214. res_t_yy=2002, res_t_mm= 1, res_t_dd=1, res_t_h=2, res_t_m=40, res_t_s=10, &
  1215. testname='AddT_T_TI2' )
  1216. CALL test_arithmetic( add_op=.TRUE., &
  1217. op1_t_yy=2003, op1_t_mm=12, op1_t_dd=31, op1_t_h=22, op1_t_m=30, op1_t_s=00, &
  1218. op2_ti_yy= 0, op2_ti_mm= 0, op2_ti_dd=0, op2_ti_h=4, op2_ti_m=10, op2_ti_s=10, &
  1219. res_t_yy=2004, res_t_mm= 1, res_t_dd=1, res_t_h=2, res_t_m=40, res_t_s=10, &
  1220. testname='AddT_T_TI3' )
  1221. CALL test_arithmetic( add_op=.TRUE., &
  1222. op1_t_yy=2004, op1_t_mm=12, op1_t_dd=31, op1_t_h=22, op1_t_m=30, op1_t_s=00, &
  1223. op2_ti_yy= 0, op2_ti_mm= 0, op2_ti_dd=0, op2_ti_h=4, op2_ti_m=10, op2_ti_s=10, &
  1224. res_t_yy=2005, res_t_mm= 1, res_t_dd=1, res_t_h=2, res_t_m=40, res_t_s=10, &
  1225. testname='AddT_T_TI4' )
  1226. ! this case hung after the CCSM contribution
  1227. CALL test_arithmetic( add_op=.TRUE., &
  1228. op1_t_yy=2004, op1_t_mm=12, op1_t_dd=30, op1_t_h=22, op1_t_m=30, op1_t_s=00, &
  1229. op2_ti_yy= 0, op2_ti_mm= 0, op2_ti_dd=0, op2_ti_h=4, op2_ti_m=10, op2_ti_s=10, &
  1230. res_t_yy=2004, res_t_mm=12, res_t_dd=31, res_t_h=2, res_t_m=40, res_t_s=10, &
  1231. testname='AddT_T_TI5' )
  1232. ! NOTE: CCSM folks need to decide what it means to add "1 month" to Feb. 29. And all the
  1233. ! other very similar cases. Then, write this unit test!
  1234. ! CALL test_arithmetic( add_op=.TRUE., &
  1235. ! op1_t_yy=2004, op1_t_mm=12, op1_t_dd=31, op1_t_h=22, op1_t_m=30, op1_t_s=00, &
  1236. ! op2_ti_yy= 2, op2_ti_mm= 0, op2_ti_dd=0, op2_ti_h=4, op2_ti_m=10, op2_ti_s=10, &
  1237. ! res_t_yy=2007, res_t_mm= 1, res_t_dd=1, res_t_h=2, res_t_m=40, res_t_s=10, &
  1238. ! testname='AddT_T_TI6' )
  1239. CALL test_arithmetic( add_op=.TRUE., &
  1240. op1_t_yy=2004, op1_t_mm=12, op1_t_dd=30, op1_t_h=4, op1_t_m=30, op1_t_s=00, &
  1241. op2_ti_yy= 0, op2_ti_mm= 0, op2_ti_dd=365, op2_ti_h=4, op2_ti_m=10, op2_ti_s=10, &
  1242. res_t_yy=2005, res_t_mm=12, res_t_dd=30, res_t_h=8, res_t_m=40, res_t_s=10, &
  1243. testname='AddT_T_TI7' )
  1244. CALL test_arithmetic( add_op=.TRUE., &
  1245. op1_t_yy=2004, op1_t_mm=12, op1_t_dd=30, op1_t_h=4, op1_t_m=30, op1_t_s=00, &
  1246. op2_ti_yy= 0, op2_ti_mm= 0, op2_ti_dd=367, op2_ti_h=4, op2_ti_m=10, op2_ti_s=10, &
  1247. res_t_yy=2006, res_t_mm=01, res_t_dd=01, res_t_h=8, res_t_m=40, res_t_s=10, &
  1248. testname='AddT_T_TI8' )
  1249. CALL test_arithmetic( add_op=.TRUE., &
  1250. op1_t_yy=2003, op1_t_mm=12, op1_t_dd=30, op1_t_h=4, op1_t_m=30, op1_t_s=00, &
  1251. op2_ti_yy= 0, op2_ti_mm= 0, op2_ti_dd=365, op2_ti_h=4, op2_ti_m=10, op2_ti_s=10, &
  1252. res_t_yy=2004, res_t_mm=12, res_t_dd=29, res_t_h=8, res_t_m=40, res_t_s=10, &
  1253. testname='AddT_T_TI9' )
  1254. CALL test_arithmetic( add_op=.TRUE., &
  1255. op1_t_yy=2003, op1_t_mm=12, op1_t_dd=30, op1_t_h=4, op1_t_m=30, op1_t_s=00, &
  1256. op2_ti_yy= 0, op2_ti_mm= 0, op2_ti_dd=366, op2_ti_h=4, op2_ti_m=10, op2_ti_s=10, &
  1257. res_t_yy=2004, res_t_mm=12, res_t_dd=30, res_t_h=8, res_t_m=40, res_t_s=10, &
  1258. testname='AddT_T_TI10' )
  1259. CALL test_arithmetic( add_op=.TRUE., &
  1260. op1_t_yy=2003, op1_t_mm=12, op1_t_dd=30, op1_t_h=4, op1_t_m=30, op1_t_s=00, &
  1261. op2_ti_yy= 0, op2_ti_mm= 0, op2_ti_dd=367, op2_ti_h=4, op2_ti_m=10, op2_ti_s=10, &
  1262. res_t_yy=2004, res_t_mm=12, res_t_dd=31, res_t_h=8, res_t_m=40, res_t_s=10, &
  1263. testname='AddT_T_TI11' )
  1264. CALL test_arithmetic( add_op=.TRUE., &
  1265. op1_t_yy=2003, op1_t_mm=12, op1_t_dd=30, op1_t_h=4, op1_t_m=30, op1_t_s=00, &
  1266. op2_ti_yy= 0, op2_ti_mm= 0, op2_ti_dd=368, op2_ti_h=4, op2_ti_m=10, op2_ti_s=10, &
  1267. res_t_yy=2005, res_t_mm=01, res_t_dd=01, res_t_h=8, res_t_m=40, res_t_s=10, &
  1268. testname='AddT_T_TI12' )
  1269. CALL test_arithmetic( add_op=.TRUE., &
  1270. op1_t_yy=2004, op1_t_mm=03, op1_t_dd=30, op1_t_h=4, op1_t_m=30, op1_t_s=00, &
  1271. op2_ti_yy= 0, op2_ti_mm= 0, op2_ti_dd=365, op2_ti_h=4, op2_ti_m=10, op2_ti_s=10, &
  1272. res_t_yy=2005, res_t_mm=03, res_t_dd=30, res_t_h=8, res_t_m=40, res_t_s=10, &
  1273. testname='AddT_T_TI13' )
  1274. CALL test_arithmetic( add_op=.TRUE., &
  1275. op1_t_yy=2004, op1_t_mm=03, op1_t_dd=30, op1_t_h=4, op1_t_m=30, op1_t_s=00, &
  1276. op2_ti_yy= 0, op2_ti_mm= 0, op2_ti_dd=365, op2_ti_h=22, op2_ti_m=10, op2_ti_s=10, &
  1277. res_t_yy=2005, res_t_mm=03, res_t_dd=31, res_t_h=2, res_t_m=40, res_t_s=10, &
  1278. testname='AddT_T_TI14' )
  1279. CALL test_arithmetic( add_op=.TRUE., &
  1280. op1_t_yy=2004, op1_t_mm=03, op1_t_dd=30, op1_t_h=4, op1_t_m=30, op1_t_s=00, &
  1281. op2_ti_yy= 0, op2_ti_mm= 0, op2_ti_dd=366, op2_ti_h=22, op2_ti_m=10, op2_ti_s=10, &
  1282. res_t_yy=2005, res_t_mm=04, res_t_dd=01, res_t_h=2, res_t_m=40, res_t_s=10, &
  1283. testname='AddT_T_TI15' )
  1284. ! ESMF_Time = ESMF_Time + ESMF_TimeInterval with fractions
  1285. CALL test_arithmetic( add_op=.TRUE., &
  1286. op1_t_yy=2004, op1_t_mm=12, op1_t_dd=31, op1_t_h=22, op1_t_m=30, op1_t_s=00, &
  1287. op1_t_sn=01, op1_t_sd=03, &
  1288. op2_ti_yy= 0, op2_ti_mm= 0, op2_ti_dd=0, op2_ti_h=4, op2_ti_m=10, op2_ti_s=10, &
  1289. op2_ti_sn=01, op2_ti_sd=03, &
  1290. res_t_yy=2005, res_t_mm= 1, res_t_dd=1, res_t_h=2, res_t_m=40, res_t_s=10, &
  1291. res_t_sn=02, res_t_sd=03, &
  1292. testname='AddT_T_TI_F1' )
  1293. ! this should fail (and does)
  1294. ! CALL test_arithmetic( add_op=.TRUE., &
  1295. ! op1_t_yy=2004, op1_t_mm=12, op1_t_dd=31, op1_t_h=22, op1_t_m=30, op1_t_s=00, &
  1296. ! op1_t_sn=01, op1_t_sd=03, &
  1297. ! op2_ti_yy= 0, op2_ti_mm= 0, op2_ti_dd=0, op2_ti_h=4, op2_ti_m=10, op2_ti_s=10, &
  1298. ! op2_ti_sn=01, op2_ti_sd=03, &
  1299. ! res_t_yy=2005, res_t_mm= 1, res_t_dd=1, res_t_h=2, res_t_m=40, res_t_s=10, &
  1300. ! res_t_sn=01, res_t_sd=03, &
  1301. ! testname='AddT_T_TI_F2' )
  1302. ! ESMF_Time = ESMF_TimeInterval + ESMF_Time
  1303. CALL test_arithmetic( add_op=.TRUE., &
  1304. op1_ti_yy= 0, op1_ti_mm= 0, op1_ti_dd=0, op1_ti_h=3, op1_ti_m=10, op1_ti_s=10, &
  1305. op2_t_yy=2001, op2_t_mm=12, op2_t_dd=3, op2_t_h=1, op2_t_m=20, op2_t_s=10, &
  1306. res_t_yy=2001, res_t_mm=12, res_t_dd=3, res_t_h=4, res_t_m=30, res_t_s=20, &
  1307. testname='AddT_TI_T1' )
  1308. CALL test_arithmetic( add_op=.TRUE., &
  1309. op1_ti_yy= 0, op1_ti_mm= 0, op1_ti_dd=0, op1_ti_h=4, op1_ti_m=10, op1_ti_s=10, &
  1310. op2_t_yy=2001, op2_t_mm=12, op2_t_dd=31, op2_t_h=22, op2_t_m=30, op2_t_s=00, &
  1311. res_t_yy=2002, res_t_mm= 1, res_t_dd=1, res_t_h=2, res_t_m=40, res_t_s=10, &
  1312. testname='AddT_TI_T2' )
  1313. ! ESMF_TimeInterval = ESMF_TimeInterval + ESMF_TimeInterval
  1314. CALL test_arithmetic( add_op=.TRUE., &
  1315. op1_ti_yy=0000, op1_ti_mm=00, op1_ti_dd=3, op1_ti_h=1, op1_ti_m=20, op1_ti_s=10, &
  1316. op2_ti_yy=0000, op2_ti_mm=00, op2_ti_dd=1, op2_ti_h=1, op2_ti_m=10, op2_ti_s=10, &
  1317. res_ti_yy=0000, res_ti_mm=00, res_ti_dd=4, res_ti_h=2, res_ti_m=30, res_ti_s=20, &
  1318. testname='AddTI_TI_TI1' )
  1319. CALL test_arithmetic( add_op=.TRUE., &
  1320. op1_ti_yy=0000, op1_ti_mm=00, op1_ti_dd=-3, op1_ti_h=-1, op1_ti_m=-20, op1_ti_s=-10, &
  1321. op2_ti_yy=0000, op2_ti_mm=00, op2_ti_dd=1, op2_ti_h=1, op2_ti_m=10, op2_ti_s=10, &
  1322. res_ti_yy=0000, res_ti_mm=00, res_ti_dd=-2, res_ti_h=0, res_ti_m=-10, res_ti_s=00, &
  1323. testname='AddTI_TI_TI2' )
  1324. CALL test_arithmetic( add_op=.TRUE., &
  1325. op1_ti_yy=0000, op1_ti_mm=00, op1_ti_dd=-3, op1_ti_h=-1, op1_ti_m=-20, op1_ti_s=-10, &
  1326. op2_ti_yy=0000, op2_ti_mm=00, op2_ti_dd=-1, op2_ti_h=-1, op2_ti_m=-10, op2_ti_s=-10, &
  1327. res_ti_yy=0000, res_ti_mm=00, res_ti_dd=-4, res_ti_h=-2, res_ti_m=-30, res_ti_s=-20, &
  1328. testname='AddTI_TI_TI3' )
  1329. ! Subtraction tests
  1330. ! ESMF_Time = ESMF_Time - ESMF_TimeInterval
  1331. CALL test_arithmetic( add_op=.FALSE., &
  1332. op1_t_yy=2001, op1_t_mm=12, op1_t_dd=3, op1_t_h=1, op1_t_m=20, op1_t_s=10, &
  1333. op2_ti_yy= 0, op2_ti_mm= 0, op2_ti_dd=0, op2_ti_h=3, op2_ti_m=10, op2_ti_s=10, &
  1334. res_t_yy=2001, res_t_mm=12, res_t_dd=2, res_t_h=22, res_t_m=10, res_t_s=0, &
  1335. testname='SubtractT_T_TI1' )
  1336. CALL test_arithmetic( add_op=.FALSE., &
  1337. op1_t_yy=2005, op1_t_mm=1, op1_t_dd=1, op1_t_h=0, op1_t_m=00, op1_t_s=0, &
  1338. op2_ti_yy= 0, op2_ti_mm= 0, op2_ti_dd=0, op2_ti_h=0, op2_ti_m=00, op2_ti_s=10, &
  1339. res_t_yy=2004, res_t_mm=12, res_t_dd=31, res_t_h=23, res_t_m=59, res_t_s=50, &
  1340. testname='SubtractT_T_TI2' )
  1341. CALL test_arithmetic( add_op=.FALSE., &
  1342. op1_t_yy=2004, op1_t_mm=1, op1_t_dd=1, op1_t_h=0, op1_t_m=00, op1_t_s=0, &
  1343. op2_ti_yy= 0, op2_ti_mm= 0, op2_ti_dd=0, op2_ti_h=0, op2_ti_m=00, op2_ti_s=10, &
  1344. res_t_yy=2003, res_t_mm=12, res_t_dd=31, res_t_h=23, res_t_m=59, res_t_s=50, &
  1345. testname='SubtractT_T_TI3' )
  1346. CALL test_arithmetic( add_op=.FALSE., &
  1347. op1_t_yy=2003, op1_t_mm=1, op1_t_dd=1, op1_t_h=0, op1_t_m=00, op1_t_s=0, &
  1348. op2_ti_yy= 0, op2_ti_mm= 0, op2_ti_dd=0, op2_ti_h=0, op2_ti_m=00, op2_ti_s=10, &
  1349. res_t_yy=2002, res_t_mm=12, res_t_dd=31, res_t_h=23, res_t_m=59, res_t_s=50, &
  1350. testname='SubtractT_T_TI4' )
  1351. CALL test_arithmetic( add_op=.FALSE., &
  1352. op1_t_yy=2005, op1_t_mm=04, op1_t_dd=01, op1_t_h=2, op1_t_m=40, op1_t_s=10, &
  1353. op2_ti_yy= 0, op2_ti_mm= 0, op2_ti_dd=366, op2_ti_h=22, op2_ti_m=10, op2_ti_s=10, &
  1354. res_t_yy=2004, res_t_mm=03, res_t_dd=30, res_t_h=4, res_t_m=30, res_t_s=00, &
  1355. testname='SubtractT_T_TI5' )
  1356. CALL test_arithmetic( add_op=.FALSE., &
  1357. op1_t_yy=2006, op1_t_mm=01, op1_t_dd=01, op1_t_h=8, op1_t_m=40, op1_t_s=10, &
  1358. op2_ti_yy= 0, op2_ti_mm= 0, op2_ti_dd=367, op2_ti_h=4, op2_ti_m=10, op2_ti_s=10, &
  1359. res_t_yy=2004, res_t_mm=12, res_t_dd=30, res_t_h=4, res_t_m=30, res_t_s=00, &
  1360. testname='SubtractT_T_TI6' )
  1361. ! ESMF_Time = ESMF_Time - ESMF_TimeInterval with fractions
  1362. CALL test_arithmetic( add_op=.FALSE., &
  1363. op1_t_yy=2005, op1_t_mm=01, op1_t_dd=01, op1_t_h=00, op1_t_m=00, op1_t_s=00, &
  1364. op1_t_sn=00, op1_t_sd=00, &
  1365. op2_ti_yy= 0, op2_ti_mm= 0, op2_ti_dd=0, op2_ti_h=0, op2_ti_m=00, op2_ti_s=01, &
  1366. op2_ti_sn=01, op2_ti_sd=03, &
  1367. res_t_yy=2004, res_t_mm=12, res_t_dd=31, res_t_h=23, res_t_m=59, res_t_s=58, &
  1368. res_t_sn=02, res_t_sd=03, &
  1369. testname='SubtractT_T_TI_F1' )
  1370. ! ESMF_TimeInterval = ESMF_Time - ESMF_Time
  1371. CALL test_arithmetic( add_op=.FALSE., &
  1372. op1_t_yy=2001, op1_t_mm=12, op1_t_dd=3, op1_t_h=1, op1_t_m=20, op1_t_s=10, &
  1373. op2_t_yy=2001, op2_t_mm=12, op2_t_dd=1, op2_t_h=1, op2_t_m=10, op2_t_s=10, &
  1374. res_ti_yy=0000, res_ti_mm=00, res_ti_dd=2, res_ti_h=0, res_ti_m=10, res_ti_s=0, &
  1375. testname='SubtractTI_T_T1' )
  1376. CALL test_arithmetic( add_op=.FALSE., &
  1377. op1_t_yy=2002, op1_t_mm=1, op1_t_dd=1, op1_t_h=0, op1_t_m=00, op1_t_s=00, &
  1378. op2_t_yy=2001, op2_t_mm=12, op2_t_dd=31, op2_t_h=23, op2_t_m=59, op2_t_s=50, &
  1379. res_ti_yy=0000, res_ti_mm=00, res_ti_dd=0, res_ti_h=0, res_ti_m=00, res_ti_s=10, &
  1380. testname='SubtractTI_T_T2' )
  1381. CALL test_arithmetic( add_op=.FALSE., &
  1382. op1_t_yy=2005, op1_t_mm=1, op1_t_dd=1, op1_t_h=0, op1_t_m=00, op1_t_s=00, &
  1383. op2_t_yy=2004, op2_t_mm=12, op2_t_dd=31, op2_t_h=23, op2_t_m=59, op2_t_s=50, &
  1384. res_ti_yy=0000, res_ti_mm=00, res_ti_dd=0, res_ti_h=0, res_ti_m=00, res_ti_s=10, &
  1385. testname='SubtractTI_T_T3' )
  1386. CALL test_arithmetic( add_op=.FALSE., &
  1387. op1_t_yy=2003, op1_t_mm=03, op1_t_dd=01, op1_t_h=00, op1_t_m=00, op1_t_s=00, &
  1388. op2_t_yy=2003, op2_t_mm=02, op2_t_dd=28, op2_t_h=23, op2_t_m=59, op2_t_s=50, &
  1389. res_ti_yy=0000, res_ti_mm=00, res_ti_dd=0, res_ti_h=0, res_ti_m=00, res_ti_s=10, &
  1390. testname='SubtractTI_T_T4' )
  1391. CALL test_arithmetic( add_op=.FALSE., &
  1392. op1_t_yy=2004, op1_t_mm=03, op1_t_dd=01, op1_t_h=00, op1_t_m=00, op1_t_s=00, &
  1393. op2_t_yy=2004, op2_t_mm=02, op2_t_dd=28, op2_t_h=23, op2_t_m=59, op2_t_s=50, &
  1394. res_ti_yy=0000, res_ti_mm=00, res_ti_dd=1, res_ti_h=0, res_ti_m=00, res_ti_s=10, &
  1395. testname='SubtractTI_T_T5' )
  1396. CALL test_arithmetic( add_op=.FALSE., &
  1397. op1_t_yy=2002, op1_t_mm=02, op1_t_dd=28, op1_t_h=00, op1_t_m=00, op1_t_s=00, &
  1398. op2_t_yy=2002, op2_t_mm=02, op2_t_dd=28, op2_t_h=00, op2_t_m=00, op2_t_s=00, &
  1399. res_ti_yy=0000, res_ti_mm=00, res_ti_dd=0, res_ti_h=0, res_ti_m=00, res_ti_s=00, &
  1400. testname='SubtractTI_T_T6' )
  1401. CALL test_arithmetic( add_op=.FALSE., &
  1402. op1_t_yy=2003, op1_t_mm=02, op1_t_dd=28, op1_t_h=00, op1_t_m=00, op1_t_s=00, &
  1403. op2_t_yy=2002, op2_t_mm=02, op2_t_dd=28, op2_t_h=00, op2_t_m=00, op2_t_s=00, &
  1404. res_ti_yy=0000, res_ti_mm=00, res_ti_dd=365, res_ti_h=0, res_ti_m=00, res_ti_s=00, &
  1405. testname='SubtractTI_T_T7' )
  1406. CALL test_arithmetic( add_op=.FALSE., &
  1407. op1_t_yy=2004, op1_t_mm=02, op1_t_dd=28, op1_t_h=00, op1_t_m=00, op1_t_s=00, &
  1408. op2_t_yy=2003, op2_t_mm=02, op2_t_dd=28, op2_t_h=00, op2_t_m=00, op2_t_s=00, &
  1409. res_ti_yy=0000, res_ti_mm=00, res_ti_dd=365, res_ti_h=0, res_ti_m=00, res_ti_s=00, &
  1410. testname='SubtractTI_T_T8' )
  1411. CALL test_arithmetic( add_op=.FALSE., &
  1412. op1_t_yy=2005, op1_t_mm=02, op1_t_dd=28, op1_t_h=00, op1_t_m=00, op1_t_s=00, &
  1413. op2_t_yy=2004, op2_t_mm=02, op2_t_dd=28, op2_t_h=00, op2_t_m=00, op2_t_s=00, &
  1414. res_ti_yy=0000, res_ti_mm=00, res_ti_dd=366, res_ti_h=0, res_ti_m=00, res_ti_s=00, &
  1415. testname='SubtractTI_T_T9' )
  1416. CALL test_arithmetic( add_op=.FALSE., &
  1417. op1_t_yy=2003, op1_t_mm=03, op1_t_dd=01, op1_t_h=00, op1_t_m=00, op1_t_s=00, &
  1418. op2_t_yy=2002, op2_t_mm=02, op2_t_dd=28, op2_t_h=00, op2_t_m=00, op2_t_s=00, &
  1419. res_ti_yy=0000, res_ti_mm=00, res_ti_dd=366, res_ti_h=0, res_ti_m=00, res_ti_s=00, &
  1420. testname='SubtractTI_T_T10' )
  1421. CALL test_arithmetic( add_op=.FALSE., &
  1422. op1_t_yy=2005, op1_t_mm=03, op1_t_dd=01, op1_t_h=00, op1_t_m=00, op1_t_s=00, &
  1423. op2_t_yy=2004, op2_t_mm=02, op2_t_dd=28, op2_t_h=00, op2_t_m=00, op2_t_s=00, &
  1424. res_ti_yy=0000, res_ti_mm=00, res_ti_dd=367, res_ti_h=0, res_ti_m=00, res_ti_s=00, &
  1425. testname='SubtractTI_T_T11' )
  1426. CALL test_arithmetic( add_op=.FALSE., &
  1427. op1_t_yy=2005, op1_t_mm=03, op1_t_dd=01, op1_t_h=00, op1_t_m=00, op1_t_s=00, &
  1428. op2_t_yy=2004, op2_t_mm=02, op2_t_dd=28, op2_t_h=23, op2_t_m=59, op2_t_s=50, &
  1429. res_ti_yy=0000, res_ti_mm=00, res_ti_dd=366, res_ti_h=0, res_ti_m=00, res_ti_s=10, &
  1430. testname='SubtractTI_T_T12' )
  1431. CALL test_arithmetic( add_op=.FALSE., &
  1432. op1_t_yy=2004, op1_t_mm=02, op1_t_dd=28, op1_t_h=23, op1_t_m=59, op1_t_s=50, &
  1433. op2_t_yy=2005, op2_t_mm=03, op2_t_dd=01, op2_t_h=00, op2_t_m=00, op2_t_s=00, &
  1434. res_ti_yy=0000, res_ti_mm=00, res_ti_dd=-366, res_ti_h=0, res_ti_m=00, res_ti_s=-10, &
  1435. testname='SubtractTI_T_T13' )
  1436. CALL test_arithmetic( add_op=.FALSE., &
  1437. op1_t_yy=-2002, op1_t_mm=02, op1_t_dd=28, op1_t_h=00, op1_t_m=00, op1_t_s=00, &
  1438. op2_t_yy=-2002, op2_t_mm=02, op2_t_dd=28, op2_t_h=00, op2_t_m=00, op2_t_s=00, &
  1439. res_ti_yy=0000, res_ti_mm=00, res_ti_dd=0, res_ti_h=0, res_ti_m=00, res_ti_s=00, &
  1440. testname='SubtractTI_T_T14' )
  1441. ! ESMF_TimeInterval = ESMF_TimeInterval - ESMF_TimeInterval
  1442. CALL test_arithmetic( add_op=.FALSE., &
  1443. op1_ti_yy=0000, op1_ti_mm=00, op1_ti_dd=3, op1_ti_h=1, op1_ti_m=20, op1_ti_s=10, &
  1444. op2_ti_yy=0000, op2_ti_mm=00, op2_ti_dd=1, op2_ti_h=1, op2_ti_m=10, op2_ti_s=10, &
  1445. res_ti_yy=0000, res_ti_mm=00, res_ti_dd=2, res_ti_h=0, res_ti_m=10, res_ti_s=0, &
  1446. testname='SubtractTI_TI_TI1' )
  1447. CALL test_arithmetic( add_op=.FALSE., &
  1448. op1_ti_yy=0000, op1_ti_mm=00, op1_ti_dd=3, op1_ti_h=1, op1_ti_m=20, op1_ti_s=10, &
  1449. op2_ti_yy=0000, op2_ti_mm=00, op2_ti_dd=-1, op2_ti_h=-1, op2_ti_m=-10, op2_ti_s=-10, &
  1450. res_ti_yy=0000, res_ti_mm=00, res_ti_dd=4, res_ti_h=2, res_ti_m=30, res_ti_s=20, &
  1451. testname='SubtractTI_TI_TI2' )
  1452. CALL test_arithmetic( add_op=.FALSE., &
  1453. op1_ti_yy=0000, op1_ti_mm=00, op1_ti_dd=-1, op1_ti_h=-1, op1_ti_m=-10, op1_ti_s=-10, &
  1454. op2_ti_yy=0000, op2_ti_mm=00, op2_ti_dd=-3, op2_ti_h=-1, op2_ti_m=-20, op2_ti_s=-10, &
  1455. res_ti_yy=0000, res_ti_mm=00, res_ti_dd=2, res_ti_h=0, res_ti_m=10, res_ti_s=00, &
  1456. testname='SubtractTI_TI_TI3' )
  1457. ! Negative result ESMF_TimeInterval = ESMF_TimeInterval - ESMF_TimeInterval
  1458. CALL test_arithmetic( add_op=.FALSE., &
  1459. op1_ti_yy=0000, op1_ti_mm=00, op1_ti_dd=1, op1_ti_h=1, op1_ti_m=10, op1_ti_s=10, &
  1460. op2_ti_yy=0000, op2_ti_mm=00, op2_ti_dd=3, op2_ti_h=1, op2_ti_m=20, op2_ti_s=10, &
  1461. res_ti_yy=0000, res_ti_mm=00, res_ti_dd=-2, res_ti_h=0, res_ti_m=-10, res_ti_s=0, &
  1462. testname='SubtractTI_TI_TIN1' )
  1463. CALL test_arithmetic( add_op=.FALSE., &
  1464. op1_ti_yy=0000, op1_ti_mm=00, op1_ti_dd=-1, op1_ti_h=-1, op1_ti_m=-10, op1_ti_s=-10, &
  1465. op2_ti_yy=0000, op2_ti_mm=00, op2_ti_dd=3, op2_ti_h=1, op2_ti_m=20, op2_ti_s=10, &
  1466. res_ti_yy=0000, res_ti_mm=00, res_ti_dd=-4, res_ti_h=-2, res_ti_m=-30, res_ti_s=-20, &
  1467. testname='SubtractTI_TI_TIN2' )
  1468. ! Un-normalized ESMF_TimeInterval = ESMF_TimeInterval - ESMF_TimeInterval
  1469. ! this is an error
  1470. ! CALL test_arithmetic( add_op=.FALSE., &
  1471. ! op1_ti_yy=2001, op1_ti_mm=11, op1_ti_dd=3, op1_ti_h=1, op1_ti_m=20, op1_ti_s=10, &
  1472. ! op2_ti_yy=2001, op2_ti_mm=11, op2_ti_dd=1, op2_ti_h=1, op2_ti_m=10, op2_ti_s=10, &
  1473. ! res_ti_yy=0000, res_ti_mm=00, res_ti_dd=2, res_ti_h=0, res_ti_m=10, res_ti_s=0, &
  1474. ! testname='SubtractTI_TI_TIU1', expect_error=.TRUE. )
  1475. ! this one should FAIL, and does
  1476. ! CALL test_arithmetic( add_op=.TRUE., &
  1477. ! op1_t_yy=2001, op1_t_mm=12, op1_t_dd=3, op1_t_h=1, op1_t_m=20, op1_t_s=10, &
  1478. ! op2_ti_yy= 0, op2_ti_mm= 0, op2_ti_dd=0, op2_ti_h=3, op2_ti_m=10, op2_ti_s=10, &
  1479. ! res_t_yy=2002, res_t_mm=12, res_t_dd=3, res_t_h=4, res_t_m=30, res_t_s=20, &
  1480. ! testname='AddTT1' )
  1481. ! Multiplication tests
  1482. ! ESMF_TimeInterval = ESMF_TimeInterval * INTEGER
  1483. CALL test_arithmetic( multiply_op=.TRUE., &
  1484. op1_ti_dd=3, op1_ti_h=12, op1_ti_m=18, op1_ti_s=33, &
  1485. op2_int=2, &
  1486. res_ti_dd=6, res_ti_h=24, res_ti_m=37, res_ti_s=06, &
  1487. testname='MultiplyTI_TI_INT1' )
  1488. CALL test_arithmetic( multiply_op=.TRUE., &
  1489. op1_ti_dd=350, op1_ti_h=23, op1_ti_m=50, op1_ti_s=50, &
  1490. op2_int=2, &
  1491. res_ti_dd=701, res_ti_h=23, res_ti_m=41, res_ti_s=40,&
  1492. testname='MultiplyTI_TI_INT2' )
  1493. CALL test_arithmetic( multiply_op=.TRUE., &
  1494. op1_ti_s=01, op1_ti_sn=03, op1_ti_sd=04, &
  1495. op2_int=8, &
  1496. res_ti_s=14, &
  1497. testname='MultiplyTI_TI_INT3' )
  1498. ! Division tests
  1499. ! ESMF_TimeInterval = ESMF_TimeInterval / INTEGER
  1500. CALL test_arithmetic( multiply_op=.FALSE., &
  1501. op1_ti_dd=3, op1_ti_h=12, op1_ti_m=18, op1_ti_s=33, &
  1502. op2_int=3, &
  1503. res_ti_dd=1, res_ti_h=04, res_ti_m=06, res_ti_s=11, &
  1504. testname='DivideTI_TI_INT1' )
  1505. CALL test_arithmetic( multiply_op=.FALSE., &
  1506. op1_ti_dd=3, op1_ti_h=12, op1_ti_m=18, op1_ti_s=33, &
  1507. op2_int=4, &
  1508. res_ti_dd=0, res_ti_h=21, res_ti_m=04, res_ti_s=38, &
  1509. res_ti_sn=1, res_ti_sd=4, &
  1510. testname='DivideTI_TI_INT2' )
  1511. CALL test_arithmetic( multiply_op=.FALSE., &
  1512. op1_ti_s=01, op1_ti_sn=03, op1_ti_sd=04, &
  1513. op2_int=5, &
  1514. res_ti_s=0, res_ti_sn=7, res_ti_sd=20, &
  1515. testname='DivideTI_TI_INT3' )
  1516. ! INTEGER = ESMF_TimeInterval / ESMF_TimeInterval
  1517. ! this operator truncates to whole integers
  1518. CALL test_arithmetic( multiply_op=.FALSE., &
  1519. op1_ti_dd=3, op1_ti_h=12, op1_ti_m=18, op1_ti_s=33, &
  1520. op2_ti_dd=3, op2_ti_h=12, op2_ti_m=18, op2_ti_s=33, &
  1521. res_int=1, &
  1522. testname='DivideINT_TI_TI1' )
  1523. CALL test_arithmetic( multiply_op=.FALSE., &
  1524. op1_ti_dd=6, op1_ti_h=24, op1_ti_m=36, op1_ti_s=66, &
  1525. op2_ti_dd=3, op2_ti_h=12, op2_ti_m=18, op2_ti_s=33, &
  1526. res_int=2, &
  1527. testname='DivideINT_TI_TI2' )
  1528. CALL test_arithmetic( multiply_op=.FALSE., &
  1529. op1_ti_dd=0, op1_ti_h=00, op1_ti_m=00, op1_ti_s=00, &
  1530. op2_ti_dd=3, op2_ti_h=12, op2_ti_m=18, op2_ti_s=33, &
  1531. res_int=0, &
  1532. testname='DivideINT_TI_TI3' )
  1533. CALL test_arithmetic( multiply_op=.FALSE., &
  1534. op1_ti_dd=1, op1_ti_h=00, op1_ti_m=00, op1_ti_s=00, &
  1535. op2_ti_dd=0, op2_ti_h=01, op2_ti_m=00, op2_ti_s=00, &
  1536. res_int=24, &
  1537. testname='DivideINT_TI_TI4' )
  1538. CALL test_arithmetic( multiply_op=.FALSE., &
  1539. op1_ti_dd=1, op1_ti_h=00, op1_ti_m=00, op1_ti_s=00, &
  1540. op2_ti_dd=0, op2_ti_h=00, op2_ti_m=01, op2_ti_s=00, &
  1541. res_int=1440, &
  1542. testname='DivideINT_TI_TI5' )
  1543. CALL test_arithmetic( multiply_op=.FALSE., &
  1544. op1_ti_dd=1, op1_ti_h=00, op1_ti_m=00, op1_ti_s=00, &
  1545. op2_ti_dd=0, op2_ti_h=00, op2_ti_m=00, op2_ti_s=01, &
  1546. res_int=86400, &
  1547. testname='DivideINT_TI_TI6' )
  1548. ! rounding
  1549. CALL test_arithmetic( multiply_op=.FALSE., &
  1550. op1_ti_dd=0, op1_ti_h=00, op1_ti_m=00, op1_ti_s=03, &
  1551. op2_ti_dd=0, op2_ti_h=00, op2_ti_m=00, op2_ti_s=02, &
  1552. res_int=1, &
  1553. testname='DivideINT_TI_TIR1' )
  1554. CALL test_arithmetic( multiply_op=.FALSE., &
  1555. op1_ti_dd=1, op1_ti_h=00, op1_ti_m=00, op1_ti_s=02, &
  1556. op2_ti_dd=1, op2_ti_h=00, op2_ti_m=00, op2_ti_s=03, &
  1557. res_int=0, &
  1558. testname='DivideINT_TI_TIR2' )
  1559. ! fractional operands
  1560. CALL test_arithmetic( multiply_op=.FALSE., &
  1561. op1_ti_m=00, op1_ti_s=00, op1_ti_sn=03, op1_ti_sd=04, &
  1562. op2_ti_m=00, op2_ti_s=00, op2_ti_sn=03, op2_ti_sd=04, &
  1563. res_int=1, &
  1564. testname='DivideINT_TI_TIF1' )
  1565. CALL test_arithmetic( multiply_op=.FALSE., &
  1566. op1_ti_m=00, op1_ti_s=00, op1_ti_sn=06, op1_ti_sd=08, &
  1567. op2_ti_m=00, op2_ti_s=00, op2_ti_sn=03, op2_ti_sd=04, &
  1568. res_int=1, &
  1569. testname='DivideINT_TI_TIF2' )
  1570. CALL test_arithmetic( multiply_op=.FALSE., &
  1571. op1_ti_m=00, op1_ti_s=00, op1_ti_sn=03, op1_ti_sd=04, &
  1572. op2_ti_m=00, op2_ti_s=00, op2_ti_sn=04, op2_ti_sd=03, &
  1573. res_int=0, &
  1574. testname='DivideINT_TI_TIF3' )
  1575. CALL test_arithmetic( multiply_op=.FALSE., &
  1576. op1_ti_m=00, op1_ti_s=02, op1_ti_sn=03, op1_ti_sd=04, &
  1577. op2_ti_m=00, op2_ti_s=01, op2_ti_sn=01, op2_ti_sd=03, &
  1578. res_int=2, &
  1579. testname='DivideINT_TI_TIF4' )
  1580. ! negative operands
  1581. CALL test_arithmetic( multiply_op=.FALSE., &
  1582. op1_ti_dd=-6, op1_ti_h=-24, op1_ti_m=-36, op1_ti_s=-66, &
  1583. op2_ti_dd=3, op2_ti_h=12, op2_ti_m=18, op2_ti_s=33, &
  1584. res_int=-2, &
  1585. testname='DivideINT_TI_TIN1' )
  1586. CALL test_arithmetic( multiply_op=.FALSE., &
  1587. op1_ti_dd=6, op1_ti_h=24, op1_ti_m=36, op1_ti_s=66, &
  1588. op2_ti_dd=-3, op2_ti_h=-12, op2_ti_m=-18, op2_ti_s=-33, &
  1589. res_int=-2, &
  1590. testname='DivideINT_TI_TIN2' )
  1591. CALL test_arithmetic( multiply_op=.FALSE., &
  1592. op1_ti_dd=-6, op1_ti_h=-24, op1_ti_m=-36, op1_ti_s=-66, &
  1593. op2_ti_dd=-3, op2_ti_h=-12, op2_ti_m=-18, op2_ti_s=-33, &
  1594. res_int=2, &
  1595. testname='DivideINT_TI_TIN3' )
  1596. !$$$here... modify these to add self-test PASS/FAIL output
  1597. CALL test_clock_advance( &
  1598. start_yy=2002, start_mm=12, start_dd=27, start_h=3, start_m=0, start_s=0, &
  1599. stop_yy=2002, stop_mm=12, stop_dd=28, stop_h=8, stop_m=0, stop_s=0, &
  1600. timestep_d=0, timestep_h=0, timestep_m=0, timestep_s=600, &
  1601. testname="SimpleClockAdvance" )
  1602. CALL test_clock_advance( &
  1603. start_yy=2003, start_mm=12, start_dd=29, start_h=9, start_m=0, start_s=0, &
  1604. stop_yy=2004, stop_mm=1, stop_dd=2, stop_h=9, stop_m=0, stop_s=0, &
  1605. timestep_d=0, timestep_h=0, timestep_m=0, timestep_s=3600, &
  1606. testname="StdYearClockAdvance", increment_S=10 )
  1607. CALL test_clock_advance( &
  1608. start_yy=2004, start_mm=12, start_dd=29, start_h=9, start_m=0, start_s=0, &
  1609. stop_yy=2005, stop_mm=1, stop_dd=2, stop_h=9, stop_m=0, stop_s=0, &
  1610. timestep_d=0, timestep_h=0, timestep_m=0, timestep_s=3600, &
  1611. testname="LeapYearClockAdvance", increment_S=10 )
  1612. ! NRCM domain 3 case: 120 seconds / 9
  1613. ! 18 timesteps through end of leap year
  1614. CALL test_clock_advance( &
  1615. start_yy=2004, start_mm=12, start_dd=31, start_h=23, start_m=58, start_s=0,&
  1616. stop_yy=2005, stop_mm=1, stop_dd=1, stop_h=0, stop_m=2, stop_s=0, &
  1617. timestep_d=0, timestep_h=0, timestep_m=0, timestep_s=13, &
  1618. timestep_sn=1, timestep_sd=3, &
  1619. testname="LeapYearFractionClockAdvance", &
  1620. increment_S=1, increment_Sn=1, increment_Sd=3 )
  1621. CALL ESMF_Finalize( rc=rc )
  1622. CALL test_check_error( ESMF_SUCCESS, rc, &
  1623. 'ESMF_Finalize() ', &
  1624. __FILE__ , &
  1625. __LINE__ )
  1626. PRINT *,'END TEST SUITE'
  1627. END PROGRAM time_manager_test