test7d3_generic Subroutine

subroutine test7d3_generic(rc, minIndex, maxIndex, gridEdgeLWidth, gridEdgeUWidth, regDecomp, distgridToGridMap, staggerloc, gridToFieldMap, ungriddedLBound, ungriddedUBound, totalLWidth, totalUWidth, fieldget)

Arguments

Type IntentOptional Attributes Name
integer, intent(out) :: rc
integer, dimension(:) :: minIndex
integer, dimension(:) :: maxIndex
integer, optional, dimension(:) :: gridEdgeLWidth
integer, optional, dimension(:) :: gridEdgeUWidth
integer, optional, dimension(:) :: regDecomp
integer, optional, dimension(:) :: distgridToGridMap
type(ESMF_StaggerLoc), optional :: staggerloc
integer, optional, dimension(:) :: gridToFieldMap
integer, optional, dimension(:) :: ungriddedLBound
integer, optional, dimension(:) :: ungriddedUBound
integer, optional, dimension(:) :: totalLWidth
integer, optional, dimension(:) :: totalUWidth
logical, optional :: fieldget

Source Code

    subroutine test7d3_generic(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(7), fub(7)

        ! local arguments used to get info from field
        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

        ! local arguments used to verify field get
        integer                                     :: i, 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 :: farray
        real(ESMF_KIND_R8), dimension(:,:,:,:,:,:,:), pointer :: farray1
        real(ESMF_KIND_R8)                          :: n
        integer, dimension(7,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, 7, ESMF_TYPEKIND_R8, rc=localrc)
        if (ESMF_LogFoundError(localrc, &
            ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

        ! create field
        field = ESMF_FieldCreate(grid, arrayspec, &
            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
            allocate(audlb(arank-adimCount), audub(arank-adimCount))
            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, 7
                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 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

            ! 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 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

    end subroutine test7d3_generic