subroutine test3d_generic_repdim_sct(rc, minindex, maxindex, &
gridEdgeLWidth, gridEdgeUWidth, &
regDecomp, &
distgridToGridMap, &
staggerloc, &
gridToFieldMap, &
ungriddedLBound, ungriddedUBound, &
totalLWidth, totalUWidth, &
fieldget)
! input arguments
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_STAGGERLOC), optional :: staggerloc
integer, dimension(:), optional :: gridToFieldMap
integer, dimension(:), optional :: ungriddedLBound, ungriddedUBound
integer, dimension(:), optional :: totalLWidth, totalUWidth
logical, optional :: fieldget
! local arguments used to create field
type(ESMF_Field) :: field
type(ESMF_Grid) :: grid
type(ESMF_DistGrid) :: distgrid
type(ESMF_ArraySpec):: arrayspec
integer :: localrc
integer :: flb(3), fub(3)
! local arguments used to get info from field
type(ESMF_Grid) :: grid1
type(ESMF_Array) :: array
type(ESMF_TypeKind_Flag) :: typekind
integer :: dimCount, gridrank_repdim
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
! local arguments used to verify field get
integer :: i, ii, ij, ik
integer, dimension(3) :: felb, feub, fclb, fcub, ftlb, ftub
integer, dimension(3) :: fec, fcc, ftc
real(ESMF_KIND_R8), dimension(:,:,:), allocatable :: farray_cr
real(ESMF_KIND_R8), dimension(:,:,:), pointer :: farray
real(ESMF_KIND_R8), dimension(:,:,:), pointer :: farray1
real(ESMF_KIND_R8) :: n
integer, dimension(3,1) :: aelb, aeub, aclb, acub, atlb, atub
integer :: ldec, ldel(1)
integer, dimension(:), allocatable :: audlb, audub
integer :: arank, adimCount
localrc = ESMF_SUCCESS
rc = ESMF_SUCCESS
! create distgrid
distgrid = ESMF_DistGridCreate(minIndex=minIndex, maxIndex=maxIndex, &
regDecomp=regDecomp, rc=localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! create grid
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
! create arrayspec
call ESMF_ArraySpecSet(arrayspec, 3, ESMF_TYPEKIND_R8, rc=localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! create field
field = ESMF_FieldEmptyCreate(name="field", rc=localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
allocate(farray_cr(flb(1):fub(1), flb(2):fub(2), flb(3):fub(3)))
call ESMF_FieldEmptyComplete(field, grid, farray_cr, &
indexflag=ESMF_INDEX_DELOCAL, gridToFieldMap=gridToFieldMap, &
ungriddedLBound=ungriddedLBound, ungriddedUBound=ungriddedUBound, &
totalLWidth=totalLWidth, totalUWidth=totalUWidth, &
staggerloc=staggerloc, &
rc=localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
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=farray, &
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
! verify that the field and array bounds agree with each other
call ESMF_ArrayGet(array, rank=arank, dimCount=adimCount, rc=localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
gridrank_repdim = 0
if(present(gridToFieldMap)) then
do i = 1, size(gridToFieldMap)
if(gridToFieldMap(i) == 0) gridrank_repdim = gridrank_repdim + 1
enddo
endif
allocate(audlb(arank-adimCount+gridrank_repdim), audub(arank-adimCount+gridrank_repdim))
call ESMF_ArrayGet(array, exclusiveLBound=aelb, exclusiveUBound=aeub, &
computationalLBound=aclb, computationalUBound=acub, &
totalLBound=atlb, totalUBound=atub, &
localDeCount=ldec, localDeToDeMap=ldel, &
undistLBound=audlb, undistUBound=audub, &
rc=localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! verify the numbers returned are correct
if(ldec .ne. 1) localrc = ESMF_FAILURE
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
!ldel(1) is PET dependent
!if(ldel(1) .ne. 0) localrc = ESMF_FAILURE
!if (ESMF_LogFoundError(localrc, &
! ESMF_ERR_PASSTHRU, &
! ESMF_CONTEXT, rcToReturn=rc)) return
do i = 1, arank-adimCount
if(lungriddedLBound(i) .ne. audlb(i) ) &
localrc = ESMF_FAILURE
enddo
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
do i = 1, arank-adimCount
if(lungriddedUBound(i) .ne. audub(i) ) &
localrc = ESMF_FAILURE
enddo
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! compare the total bounds computed from FieldGetAllocBounds and FieldGetDataBounds
do i = 1, 3
if( (ftlb(i) .ne. flb(i)) .or. (ftub(i) .ne. fub(i)) ) &
localrc = ESMF_FAILURE
enddo
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! verify the data in the created Field can be accessed, updated and verified
! access and update
do ik = flb(3), fub(3)
do ij = flb(2), fub(2)
do ii = flb(1), fub(1)
farray(ii,ij,ik) = ii+ij*2+ik
enddo
enddo
enddo
! access and verify
call ESMF_FieldGet(field, localDe=0, farrayPtr=farray1, &
rc=localrc)
if (ESMF_LogFoundError(localrc, &
ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
do ik = ftlb(3), ftub(3)
do ij = ftlb(2), ftub(2)
do ii = ftlb(1), ftub(1)
n = ii+ij*2+ik
if(farray1(ii,ij,ik) .ne. n ) localrc = ESMF_FAILURE
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_cr)
end subroutine test3d_generic_repdim_sct