subroutine test7d2_generic(rc, minindex, maxindex, &
gridEdgeLWidth, gridEdgeUWidth, &
regDecomp, &
distgridToGridMap, &
datacopyflag, &
staggerloc, &
gridToFieldMap, &
ungriddedLBound, ungriddedUBound, &
totalLWidth, totalUWidth, &
fieldget)
integer, intent(out) :: rc
integer, dimension(:) :: minIndex
integer, dimension(:) :: maxIndex
integer, dimension(:), optional :: gridEdgeLWidth, gridEdgeUWidth
integer, dimension(:), optional :: regDecomp
integer, dimension(:), optional :: distgridToGridMap
type(ESMF_DataCopy_Flag), optional :: datacopyflag
type(ESMF_STAGGERLOC), optional :: staggerloc
integer, dimension(:), optional :: gridToFieldMap
integer, dimension(:), optional :: ungriddedLBound, ungriddedUBound
integer, dimension(:), optional :: totalLWidth, totalUWidth
logical, optional :: fieldget
real(ESMF_KIND_R8), dimension(:,:,:,:,:,:,:), allocatable :: farray
type(ESMF_Field) :: field, dstField
type(ESMF_Grid) :: grid
type(ESMF_DistGrid) :: distgrid
integer :: localrc
integer :: flb(7), fub(7)
type(ESMF_Grid) :: grid1
type(ESMF_Array) :: array
type(ESMF_TypeKind_Flag) :: typekind
integer :: dimCount
type(ESMF_StaggerLoc) :: lstaggerloc
integer, dimension(7) :: lgridToFieldMap
integer, dimension(7) :: lungriddedLBound
integer, dimension(7) :: lungriddedUBound
integer, dimension(7,1) :: ltotalLWidth
integer, dimension(7,1) :: ltotalUWidth
integer :: ii, ij, ik, il, im, io, ip
integer, dimension(7) :: felb, feub, fclb, fcub, ftlb, ftub
integer, dimension(7) :: fec, fcc, ftc
real(ESMF_KIND_R8), dimension(:,:,:,:,:,:,:), pointer :: farray1
real(ESMF_KIND_R8) :: n
localrc = ESMF_SUCCESS
rc = ESMF_SUCCESS
distgrid = ESMF_DistGridCreate(minIndex=minIndex, maxIndex=maxIndex, &
regDecomp=regDecomp, rc=localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
grid = ESMF_GridCreate(distgrid=distgrid, name="grid", &
distgridToGridMap=distgridToGridMap, &
gridEdgeLWidth=gridEdgeLWidth, gridEdgeUWidth=gridEdgeUWidth, &
rc=localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
call ESMF_GridGetFieldBounds(grid, localDe=0, staggerloc=staggerloc, &
ungriddedLBound=ungriddedLBound, ungriddedUBound=ungriddedUBound, &
totalLWidth=totalLWidth, totalUWidth=totalUWidth, &
gridToFieldMap=gridToFieldMap, &
totalLBound=flb, totalUBound=fub, &
rc=localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
allocate(farray(flb(1):fub(1), flb(2):fub(2), flb(3):fub(3), &
flb(4):fub(4), flb(5):fub(5), flb(6):fub(6), flb(7):fub(7)) )
if(present(fieldget)) then
if(fieldget) then
! reverse looping order to make this a little faster by improving data locality
do ip = flb(7), fub(7)
do io = flb(6), fub(6)
do im = flb(5), fub(5)
do il = flb(4), fub(4)
do ik = flb(3), fub(3)
do ij = flb(2), fub(2)
do ii = flb(1), fub(1)
farray(ii,ij,ik,il,im,io,ip) = ii+ij*2+ik+il*2+im+io*2+ip
enddo
enddo
enddo
enddo
enddo
enddo
enddo
endif
endif
field = ESMF_FieldCreate(grid, farray=farray, indexflag=ESMF_INDEX_DELOCAL, &
ungriddedLBound=ungriddedLBound, ungriddedUBound=ungriddedUBound, &
totalLWidth=totalLWidth, totalUWidth=totalUWidth, &
gridToFieldMap=gridToFieldMap, &
datacopyflag=datacopyflag, &
staggerloc=staggerloc, &
rc=localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
dstField = ESMF_FieldCreate(grid, farray=farray, indexflag=ESMF_INDEX_DELOCAL, &
ungriddedLBound=ungriddedLBound, ungriddedUBound=ungriddedUBound, &
totalLWidth=totalLWidth, totalUWidth=totalUWidth, &
gridToFieldMap=gridToFieldMap, &
datacopyflag=ESMF_DATACOPY_VALUE, &
staggerloc=staggerloc, &
rc=localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
call ESMF_FieldGet(dstField, localDe=0, farrayPtr=farray1, &
totalLBound=ftlb, totalUBound=ftub, rc=localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
farray1 = 0.
call ESMF_FieldCopy(dstField, field, rc=localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Verify fieldCopy copies the values correctly
if(present(fieldget)) then
if(fieldget) then
do ip = ftlb(7), ftub(7)
do io = ftlb(6), ftub(6)
do im = ftlb(5), ftub(5)
do il = ftlb(4), ftub(4)
do ik = ftlb(3), ftub(3)
do ij = ftlb(2), ftub(2)
do ii = ftlb(1), ftub(1)
n = ii+ij*2+ik+il*2+im+io*2+ip
if(farray1(ii,ij,ik,il,im,io,ip) /= n) then
call ESMF_LogSetError(ESMF_RC_PTR_BAD, &
msg="- dst Field pointer value is different from src Field value", &
ESMF_CONTEXT, rcToReturn=rc)
return
endif
enddo
enddo
enddo
enddo
enddo
enddo
enddo
endif
endif
if(present(fieldget)) then
if(fieldget) then
call ESMF_FieldGet(field, grid=grid1, array=array, typekind=typekind, &
dimCount=dimCount, staggerloc=lstaggerloc, gridToFieldMap=lgridToFieldMap, &
ungriddedLBound=lungriddedLBound, ungriddedUBound=lungriddedUBound, &
totalLWidth=ltotalLWidth, totalUWidth=ltotalUWidth, &
rc=localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
call ESMF_FieldGet(field, localDe=0, farrayPtr=farray1, &
exclusiveLBound=felb, exclusiveUBound=feub, exclusiveCount=fec, &
computationalLBound=fclb, computationalUBound=fcub, computationalCount=fcc, &
totalLBound=ftlb, totalUBound=ftub, totalCount=ftc, &
rc=localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! reverse looping order to make this a little faster by improving data locality
do ip = ftlb(7), ftub(7)
do io = ftlb(6), ftub(6)
do im = ftlb(5), ftub(5)
do il = ftlb(4), ftub(4)
do ik = ftlb(3), ftub(3)
do ij = ftlb(2), ftub(2)
do ii = ftlb(1), ftub(1)
n = ii+ij*2+ik+il*2+im+io*2+ip
if(farray1(ii,ij,ik,il,im,io,ip) .ne. n ) localrc = ESMF_FAILURE
enddo
enddo
enddo
enddo
enddo
enddo
enddo
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
endif ! fieldget = .true.
endif ! present(fieldget) = .true.
call ESMF_FieldDestroy(field, rc=localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
call ESMF_GridDestroy(grid, rc=localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
call ESMF_DistGridDestroy(distgrid, rc=localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
deallocate(farray)
end subroutine test7d2_generic