test_localglobalbounds Subroutine

subroutine test_localglobalbounds(rc)

Arguments

Type IntentOptional Attributes Name
integer, intent(out) :: rc

Source Code

    subroutine test_localglobalbounds(rc)
        integer, intent(out)  :: rc
        integer                 :: localrc
        type(ESMF_Field)        :: field
        type(ESMF_Grid)         :: grid
        real (ESMF_KIND_R8), pointer   :: farray(:,:)
        logical                   :: correct
        integer                 :: gminIndex(3), gmaxIndex(3), geleCount(3)
        integer                 :: lminIndex(3), lmaxIndex(3), leleCount(3)

        type(ESMF_VM)                   :: vm
        integer                         :: localPet, petCount

        rc = ESMF_SUCCESS
        localrc = ESMF_SUCCESS
        correct=.true.
        call ESMF_VMGetCurrent(vm, rc=rc)
        if (ESMF_LogFoundError(rc, &
            ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return
        call ESMF_VMGet(vm, localPet=localPet, petCount=petCount, rc=rc)
        if (ESMF_LogFoundError(rc, &
            ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

        grid = ESMF_GridCreateNoPeriDimUfrm(maxIndex=(/80, 100/), &
        minCornerCoord=(/0._ESMF_KIND_R8,  -90._ESMF_KIND_R8/), &
        maxCornerCoord=(/360._ESMF_KIND_R8, 90._ESMF_KIND_R8/), &
        staggerLocList=(/ESMF_STAGGERLOC_CENTER, ESMF_STAGGERLOC_CORNER/), rc=localrc)
        if (ESMF_LogFoundError(localrc, &
            ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return
        field = ESMF_FieldCreate(grid, &
          gridToFieldMap=(/2,3/), &
          ungriddedLBound=(/1/), ungriddedUBound=(/10/), & 
          typekind=ESMF_TYPEKIND_R8, &
          rc=localrc)
        if (ESMF_LogFoundError(localrc, &
            ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

        call ESMF_FieldGet(field, minIndex = gminIndex, maxIndex = gmaxIndex, &
                                elementCount = geleCount, &
                                localMinIndex = lminIndex, &
                                localMaxIndex = lmaxIndex, &
                                localelementCount = leleCount, &
                                rc=localrc)
        if (ESMF_LogFoundError(localrc, &
            ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

       if(localPet .eq. 0) then
         if(leleCount(1) .ne. 10) correct = .false.
         if(leleCount(2) .ne. 20)  correct = .false.
         if(leleCount(3) .ne. 100)  correct = .false.
       else if(localPet .eq. 1) then
         if(leleCount(1) .ne. 10) correct = .false.
         if(leleCount(2) .ne. 20)  correct = .false.
         if(leleCount(3) .ne. 100)  correct = .false.
       else if(localPet .eq. 2) then
         if(leleCount(1) .ne. 10) correct = .false.
         if(leleCount(2) .ne. 20)  correct = .false.
         if(leleCount(3) .ne. 100)  correct = .false.
       else if(localPet .eq. 3) then
         if(leleCount(1) .ne. 10) correct = .false.
         if(leleCount(2) .ne. 20)  correct = .false.
         if(leleCount(3) .ne. 100)  correct = .false.
       endif


        call ESMF_GridDestroy(grid, rc=localrc)
        if (ESMF_LogFoundError(localrc, &
            ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return
        call ESMF_FieldDestroy(field, rc=localrc)
        if (ESMF_LogFoundError(localrc, &
            ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return
       ! return rc based on correct
       if (correct) then
         rc=ESMF_SUCCESS
       else
         rc=ESMF_FAILURE
       endif
    end subroutine test_localglobalbounds