test2a_isalloc Subroutine

subroutine test2a_isalloc(datacopyflag, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_DataCopy_Flag), intent(in) :: datacopyflag
integer, intent(out) :: rc

Source Code

    subroutine test2a_isalloc(datacopyflag, rc)
        type(ESMF_DataCopy_Flag), intent(in) :: datacopyflag        
        integer, intent(out)  :: rc
        integer               :: localrc
        type(ESMF_Field)      :: field
        type(ESMF_Grid)       :: grid
        type(ESMF_StaggerLoc) :: sloc
        real, dimension(:,:), allocatable :: farray
        integer, dimension(2) :: ec
        logical               :: isESMFAllocated

        grid = ESMF_GridCreateNoPeriDim(minIndex=(/1,1/), maxIndex=(/16,20/), &
                                  regDecomp=(/4,1/), name="testgrid", rc=localrc)
        if (ESMF_LogFoundError(localrc, &
            ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

        call ESMF_GridGet(grid, localDe=0, staggerloc=sloc, &
           exclusiveCount=ec, rc=localrc)
        if (ESMF_LogFoundError(localrc, &
            ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

        allocate(farray(ec(1), ec(2)))

        field = ESMF_FieldCreate(grid, farray, indexflag=ESMF_INDEX_DELOCAL, &
           datacopyflag=datacopyflag, staggerloc=sloc, rc=localrc)
        if (ESMF_LogFoundError(localrc, &
            ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

        call ESMF_FieldGet(field, isESMFAllocated=isESMFAllocated, rc=localrc)
        if (ESMF_LogFoundError(localrc, &
            ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return
       
        if ((datacopyflag == ESMF_DATACOPY_VALUE) .and. isESMFAllocated ) then 
           localrc = ESMF_FAILURE
        end if
        if ((datacopyflag == ESMF_DATACOPY_REFERENCE) .and. .not.isESMFAllocated) then
           localrc = ESMF_FAILURE
        end if
        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

        call ESMF_GridDestroy(grid, rc=localrc)
        if (ESMF_LogFoundError(localrc, &
            ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

        deallocate(farray)

    end subroutine test2a_isalloc