program ESMF_DirectCouplingSTest
#define ESMF_METHOD "program ESMF_DirectCouplingSTest"
#include "ESMF.h"
! ESMF Framework module
use ESMF
use ESMF_TestMod
! Application components
use ioCompMod, only : ioCompSetVM, ioCompReg
use modelCompMod, only : modelCompSetVM, modelCompReg
use cplCompMod, only : cplCompSetVM, cplCompReg
implicit none
! Local variables
integer :: localPet, petCount, userrc, localrc, rc=ESMF_SUCCESS
type(ESMF_VM):: vm
type(ESMF_GridComp) :: ioComp, modelComp
type(ESMF_CplComp) :: cplComp
type(ESMF_State) :: ioExp, ioImp, modelExp, modelImp
! Test variables
integer :: result = 0 ! all pass
character(ESMF_MAXSTR) :: testname
character(ESMF_MAXSTR) :: failMsg, finalMsg
!-------------------------------------------------------------------------
!-------------------------------------------------------------------------
write(failMsg, *) "System Test failure"
write(testname, *) "System Test ESMF_DirectCouplingSTest"
!-------------------------------------------------------------------------
!-------------------------------------------------------------------------
print *, "--------------------------------------- "
print *, "Start of ", trim(testname)
print *, "--------------------------------------- "
!-------------------------------------------------------------------------
!-------------------------------------------------------------------------
! Startup ESMF
!-------------------------------------------------------------------------
!-------------------------------------------------------------------------
! Initialize framework and get back default global VM
call ESMF_Initialize(vm=vm, defaultlogfilename="DirectCouplingSTest.Log", &
logkindflag=ESMF_LOGKIND_MULTI, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
call ESMF_LogSet (flush=.true.)
! Get number of PETs and local PET this driver is running on
call ESMF_VMGet(vm, petCount=petCount, localPet=localPet, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
! Check for correct number of PETs
if ( petCount < 6 ) then
call ESMF_LogSetError(ESMF_RC_ARG_BAD,&
msg="This system test does not run on fewer than 6 PETs.",&
ESMF_CONTEXT, rcToReturn=rc)
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
endif
!-------------------------------------------------------------------------
!-------------------------------------------------------------------------
! Create Components
!-------------------------------------------------------------------------
!-------------------------------------------------------------------------
! ioComp on PET 0
ioComp = ESMF_GridCompCreate(name="ioComp", petList=(/0/), rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
! modelComp on PET 1,2,3,4,5
modelComp = ESMF_GridCompCreate(name="modelComp", petList=(/1,2,3,4,5/), &
rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
! cplComp on all PETs
cplComp = ESMF_CplCompCreate(name="cplComp", rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
!-------------------------------------------------------------------------
!-------------------------------------------------------------------------
! SetServices for Components
!-------------------------------------------------------------------------
!-------------------------------------------------------------------------
call ESMF_GridCompSetVM(ioComp, userRoutine=ioCompSetVM, &
userRc=userrc, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
if (ESMF_LogFoundError(userrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
call ESMF_GridCompSetServices(ioComp, userRoutine=ioCompReg, &
userRc=userrc, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
if (ESMF_LogFoundError(userrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
call ESMF_GridCompSetVM(modelComp, userRoutine=modelCompSetVM, &
userRc=userrc, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
if (ESMF_LogFoundError(userrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
call ESMF_GridCompSetServices(modelComp, userRoutine=modelCompReg, &
userRc=userrc, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
if (ESMF_LogFoundError(userrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
call ESMF_CplCompSetVM(cplComp, userRoutine=cplCompSetVM, &
userRc=userrc, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
if (ESMF_LogFoundError(userrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
call ESMF_CplCompSetServices(cplComp, userRoutine=cplCompReg, &
userRc=userrc, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
if (ESMF_LogFoundError(userrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
!-------------------------------------------------------------------------
!-------------------------------------------------------------------------
! Create States and initialize Components
!-------------------------------------------------------------------------
!-------------------------------------------------------------------------
! ioComp
ioImp = ESMF_StateCreate(name="ioComp import", &
stateintent=ESMF_STATEINTENT_IMPORT, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
ioExp = ESMF_StateCreate(name="ioComp export", &
stateintent=ESMF_STATEINTENT_EXPORT, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
call ESMF_GridCompInitialize(ioComp, importState=ioImp, exportState=ioExp, &
userRC=userrc, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
if (ESMF_LogFoundError(userrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
! modelComp
modelImp = ESMF_StateCreate(name="modelComp import", &
stateintent=ESMF_STATEINTENT_IMPORT, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
modelExp = ESMF_StateCreate(name="modelComp export", &
stateintent=ESMF_STATEINTENT_EXPORT, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
call ESMF_GridCompInitialize(modelComp, importState=modelImp, &
exportState=modelExp, userRC=userrc, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
if (ESMF_LogFoundError(userrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
! ioComp->modelComp coupling
call ESMF_CplCompInitialize(cplComp, importState=ioExp, &
exportState=modelImp, phase=1, userRC=userrc, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
if (ESMF_LogFoundError(userrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
! modelComp->ioComp coupling
call ESMF_CplCompInitialize(cplComp, importState=modelExp, &
exportState=ioImp, phase=2, userRC=userrc, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
if (ESMF_LogFoundError(userrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
!-------------------------------------------------------------------------
!-------------------------------------------------------------------------
! Run io and model Components concurrently -> direct coupling between Components
!-------------------------------------------------------------------------
!-------------------------------------------------------------------------
! ioComp
call ESMF_GridCompRun(ioComp, importState=ioImp, exportState=ioExp, &
userRc=userrc, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
if (ESMF_LogFoundError(userrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
! modelComp
call ESMF_GridCompRun(modelComp, importState=modelImp, exportState=modelExp, &
userRc=userrc, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
if (ESMF_LogFoundError(userrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
!-------------------------------------------------------------------------
!-------------------------------------------------------------------------
! Finalize Components
!-------------------------------------------------------------------------
!-------------------------------------------------------------------------
! ioComp->modelComp coupling
call ESMF_CplCompFinalize(cplComp, importState=ioExp, &
exportState=modelImp, phase=1, userRc=userrc, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
if (ESMF_LogFoundError(userrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
! modelComp->ioComp coupling
call ESMF_CplCompFinalize(cplComp, importState=modelExp, &
exportState=ioImp, phase=2, userRc=userrc, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
if (ESMF_LogFoundError(userrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
! ioComp
call ESMF_GridCompFinalize(ioComp, importState=ioImp, exportState=ioExp, &
userRc=userrc, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
if (ESMF_LogFoundError(userrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
! modelComp
call ESMF_GridCompFinalize(modelComp, importState=modelImp, &
exportState=modelExp, userRc=userrc, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
if (ESMF_LogFoundError(userrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
!-------------------------------------------------------------------------
!-------------------------------------------------------------------------
! Destroy Components and States
!-------------------------------------------------------------------------
!-------------------------------------------------------------------------
call ESMF_GridCompDestroy(ioComp, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
call ESMF_GridCompDestroy(modelComp, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
call ESMF_CplCompDestroy(cplComp, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
call ESMF_StateDestroy(ioExp, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
call ESMF_StateDestroy(ioImp, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
call ESMF_StateDestroy(modelExp, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
call ESMF_StateDestroy(modelImp, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) &
call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
!-------------------------------------------------------------------------
!-------------------------------------------------------------------------
10 continue
! Normal ESMF Test output
print *, testname, " complete."
if (rc .eq. ESMF_SUCCESS) then
! Separate message to console, for quick confirmation of success/failure
write(finalMsg, *) "SUCCESS: ",trim(testname)," finished correctly."
write(0, *) ""
write(0, *) trim(testname)
write(0, *) trim(finalMsg)
write(0, *) ""
endif
print *, "------------------------------------------------------------"
print *, "------------------------------------------------------------"
print *, "Test finished, localPet = ", localPet
print *, "------------------------------------------------------------"
print *, "------------------------------------------------------------"
! IMPORTANT: ESMF_STest() prints the PASS string and the # of processors in the log
! file that the scripts grep for.
call ESMF_STest((rc.eq.ESMF_SUCCESS), testname, failMsg, result, ESMF_SRCLINE)
call ESMF_Finalize()
end program ESMF_DirectCouplingSTest