program ESMF_InternalStateEx
!-------------------------------------------------------------------------
#include "ESMF.h"
! !USES:
!BOC
! ESMF Framework module
use ESMF
use ESMF_TestMod
implicit none
type(ESMF_GridComp) :: comp
integer :: rc, finalrc
! Internal State Variables
type testData
sequence
integer :: testValue
real :: testScaling
end type
type dataWrapper
sequence
type(testData), pointer :: p
end type
type(dataWrapper) :: wrap1, wrap2
type(testData), target :: data
type(testData), pointer :: datap ! extra level of indirection
!EOC
integer :: result
character(ESMF_MAXSTR) :: testname
character(ESMF_MAXSTR) :: failMsg
!-------------------------------------------------------------------------
!-------------------------------------------------------------------------
write(failMsg, *) "Example failure"
write(testname, *) "Example ESMF_InternalStateEx"
!-------------------------------------------------------------------------
!-------------------------------------------------------------------------
finalrc = ESMF_SUCCESS
!BOC
!-------------------------------------------------------------------------
call ESMF_Initialize(defaultlogfilename="InternalStateEx.Log", &
logkindflag=ESMF_LOGKIND_MULTI, rc=rc)
if (rc /= ESMF_SUCCESS) call ESMF_Finalize(endflag=ESMF_END_ABORT)
!-------------------------------------------------------------------------
! Creation of a Component
comp = ESMF_GridCompCreate(name="test", rc=rc)
if (rc .ne. ESMF_SUCCESS) finalrc = ESMF_FAILURE
!-------------------------------------------------------------------------
! This could be called, for example, during a Component's initialize phase.
! Initialize private data block
data%testValue = 4567
data%testScaling = 0.5
! Set Internal State
wrap1%p => data
call ESMF_GridCompSetInternalState(comp, wrap1, rc)
if (rc .ne. ESMF_SUCCESS) finalrc = ESMF_FAILURE
!-------------------------------------------------------------------------
! This could be called, for example, during a Component's run phase.
! Get Internal State
call ESMF_GridCompGetInternalState(comp, wrap2, rc)
if (rc .ne. ESMF_SUCCESS) finalrc = ESMF_FAILURE
! Access private data block and verify data
datap => wrap2%p
if ((datap%testValue .ne. 4567) .or. (datap%testScaling .ne. 0.5)) then
print *, "did not get same values back"
finalrc = ESMF_FAILURE
else
print *, "got same values back from GetInternalState as original"
endif
!EOC
!-------------------------------------------------------------------------
call ESMF_GridCompDestroy(comp, rc=rc)
if (rc .ne. ESMF_SUCCESS) finalrc = ESMF_FAILURE
! IMPORTANT: ESMF_STest() prints the PASS string and the # of processors in the log
! file that the scripts grep for.
call ESMF_STest((finalrc.eq.ESMF_SUCCESS), testname, failMsg, result, ESMF_SRCLINE)
call ESMF_Finalize(rc=rc)
if (rc .ne. ESMF_SUCCESS) finalrc = ESMF_FAILURE
if (finalrc .eq. ESMF_SUCCESS) then
print *, "PASS: ESMF_InternalStateEx.F90"
else
print *, "FAIL: ESMF_InternalStateEx.F90"
end if
end program ESMF_InternalStateEx