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_FieldBundle):: fieldbundle
type(ESMF_Field) :: field, fields(3)
type(ESMF_Array) :: array
type(ESMF_Grid) :: grid
real(ESMF_KIND_R8), pointer :: farrayPtr(:,:,:) ! matching F90 array pointer
integer :: i, j, k
integer :: compLBnd(2),compUBnd(2)
! Initialize return code
rc = ESMF_SUCCESS
print *, "User Comp2 Run starting"
pi = 3.14159d0
! Get the destination Field from the import State
call ESMF_StateGet(importState, itemName="fieldbundle data", fieldbundle=fieldbundle, rc=rc)
if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
! Get the Grid from the FieldBundle
call ESMF_FieldBundleGet(fieldbundle, grid=grid, rc=rc)
if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
! Get Bounds
call ESMF_GridGet(grid, localDe=0, staggerloc=ESMF_STAGGERLOC_CENTER, &
computationalLBound=compLBnd, computationalUBound=compUBnd, rc=rc)
if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
! Gain access to actual data via F90 array pointer
call ESMF_FieldBundleGet(fieldbundle, farrayPtr=farrayPtr, rc=rc)
if (rc/=ESMF_SUCCESS) call ESMF_Finalize(rc=rc, endflag=ESMF_END_ABORT)
do k = 1, 3
! Test FieldBundle in import state against exact solution
do j = compLBnd(2), compUBnd(2)
do i = compLBnd(1), compUbnd(1)
if (abs(farrayPtr(k,i,j) - (real(k,ESMF_KIND_R8) * 10.0d0 &
+ 5.0d0 * sin(real(i,ESMF_KIND_R8)/100.d0*pi) &
+ 2.0d0 * sin(real(j,ESMF_KIND_R8)/150.d0*pi))) > 1.d-8) then
rc=ESMF_FAILURE
write(*,*) "HERE!!!!!!"
return ! bail out
endif
enddo
enddo
enddo
print *, "User Comp2 Run returning"
end subroutine user_run