@@ -6,6 +6,7 @@ module test_CNFireFactory
66 use unittestSubgridMod, only : bounds
77 use FireMethodType , only : fire_method_type
88 use CNFireFactoryMod
9+ use ESMF, only : ESMF_SUCCESS
910 use shr_kind_mod , only : r8 => shr_kind_r8
1011 use clm_varctl, only : use_cn, iulog
1112
@@ -30,15 +31,25 @@ module test_CNFireFactory
3031
3132 subroutine setUp(this)
3233 use shr_log_mod, only : shr_log_setLogUnit
33- use ESMF, only : ESMF_Initialize
34+ use ESMF, only : ESMF_Initialize, ESMF_IsInitialized
3435 use shr_sys_mod, only : shr_sys_system
3536 class(TestCNFireFactory), intent(inout) :: this
3637
3738 integer :: unitn
3839 logical :: file_exists
3940 integer :: rc
41+ logical :: esmf_initialized
4042
41- call ESMF_Initialize()
43+ esmf_initialized = ESMF_IsInitialized( rc=rc )
44+ if (rc /= ESMF_SUCCESS) then
45+ stop 'Error in ESMF_IsInitialized'
46+ end if
47+ if ( .not. esmf_initialized )then
48+ call ESMF_Initialize( rc=rc )
49+ if (rc /= ESMF_SUCCESS) then
50+ stop 'Error in ESMF_Initialize'
51+ end if
52+ end if
4253 use_cn = .true.
4354 iulog = 6
4455 ! Create an exmpty namelist file for lifire namelist reading
@@ -67,6 +78,8 @@ module test_CNFireFactory
6778 call this%cnfire_method%FireClean()
6879 deallocate( this%cnfire_method )
6980 end if
81+ ! IMPORTANT NOTE: DO NOT CALL ESMF_Finalize HERE!
82+ ! Calling ESMF_Finalize here, with full ESMF, means you couldn't call ESMF_Initialize again
7083 ! Remove the namelist file
7184 call shr_sys_system( "/bin/rm -f "//trim(NLFilename), rc )
7285 !@assertEqual( rc, 0, "error in removal of temporary lifire namelist file")
0 commit comments