subroutine user_run(comp, importState, exportState, clock, rc)
type(ESMF_GridComp) :: comp
type(ESMF_State) :: importState, exportState
type(ESMF_Clock) :: clock
integer, intent(out) :: rc
! Local variables
real(ESMF_KIND_R8) :: pi
type(ESMF_Array) :: array
real(ESMF_KIND_R8), pointer :: farrayPtr(:,:,:) ! matching F90 array pointer
real(ESMF_KIND_R8) :: diff
integer :: i, j, k
character(1024) :: msgString
! Initialize return code
rc = ESMF_SUCCESS
print *, "User Comp2 Run starting"
pi = 3.14159d0
! Get the destination Array from the import State
call ESMF_StateGet(importState, "array data", array, rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
! Gain access to actual data via F90 array pointer
call ESMF_ArrayGet(array, localDe=0, farrayPtr=farrayPtr, rc=rc)
if (rc/=ESMF_SUCCESS) return ! bail out
! Test Array in import state against exact solution
do k = lbound(farrayPtr, 3), ubound(farrayPtr, 3)
do j = lbound(farrayPtr, 2), ubound(farrayPtr, 2)
do i = lbound(farrayPtr, 1), ubound(farrayPtr, 1)
diff = abs(farrayPtr(i,j,k) - (10.0d0 &
+ 5.0d0 * sin(real(i,ESMF_KIND_R8)/100.d0*pi) &
+ 2.0d0 * sin(real(j,ESMF_KIND_R8)/150.d0*pi) &
+ 3.0d0 * sin(real(k,ESMF_KIND_R8)/4.d0 *pi)))
if (diff > 1.d-8) then
write(msgString,*) "Detected difference above tolerance: ", diff
call ESMF_LogSetError(ESMF_RC_VAL_OUTOFRANGE, msg=trim(msgString), &
rcToReturn=rc)
return ! bail out
endif
enddo
enddo
enddo
print *, "User Comp2 Run returning"
end subroutine user_run