ESMF_GridGetIndex Subroutine

public subroutine ESMF_GridGetIndex(grid, tileNo, minIndex, maxIndex, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_Grid), intent(in) :: grid
integer, intent(in), optional :: tileNo
integer, intent(out), optional, target :: minIndex(:)
integer, intent(out), target :: maxIndex(:)
integer, intent(out), optional :: rc

Source Code

      subroutine ESMF_GridGetIndex(grid, tileNo, minIndex, maxIndex, rc)

!
! !Arguments:
        type(ESMF_Grid),  intent(in)            :: grid
        integer,          intent(in),  optional :: tileNo
        integer,target,   intent(out), optional :: minIndex(:)
        integer,target,   intent(out)           :: maxIndex(:)
        integer,          intent(out), optional :: rc
!
! !DESCRIPTON:
!  This method gets the minimal index and maximal index of a given tile of the grid

!The arguments are:
!\begin{description}
!\item[{grid}]
!    Grid to get the information from.
!\item[{[tileNo]}]
!     The tile number from which to get the information. The default is 0.
!\item[{[minIndex]}]
!     The minimal grid index for the given tile.
!\item[{[maxIndex]}]
!     The maximal grid index for the given tile.
!\item[{[rc]}]
!     The return value.

!\end{description}
!
!EOPI

    integer :: localrc ! local error status
    type(ESMF_InterArray) :: minIndexArg ! helper variable
    type(ESMF_InterArray) :: maxIndexArg ! helper variable      
    type(ESMF_GridDecompType) :: decompType
    integer :: localTileNo ! local TileNo       

    ! Initialize return code
    localrc = ESMF_RC_NOT_IMPL
    if (present(rc)) rc = ESMF_RC_NOT_IMPL

    ! Check init status of arguments
    ESMF_INIT_CHECK_DEEP_SHORT(ESMF_GridGetInit, grid, rc)

    if (present(tileNo)) then
        ! Get Grid decomposition type
        call ESMF_GridGetDecompType(grid, decompType, rc=localrc)
        if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
          ESMF_CONTEXT, rcToReturn=rc)) return
        if ((decompType == ESMF_GRID_ARBITRARY) .and. &
            (tileNo /= 1)) then
          call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_WRONG, &
              msg="- tileNo has to be 1 for arbitrarily distributed grid", &
              ESMF_CONTEXT, rcToReturn=rc)
          return
        elseif (tileNo /= 1) then
          call ESMF_LogSetError(rcToCheck=ESMF_RC_NOT_IMPL, &
              msg="- multiple tiles is not implemented", &
              ESMF_CONTEXT, rcToReturn=rc)
          return
      endif
      localTileNo = tileNo
    else
      localTileNo = 1
    endif

    ! process optional arguments
    minIndexArg=ESMF_InterArrayCreate(minIndex, rc=localrc)
    if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return
    maxIndexArg=ESMF_InterArrayCreate(maxIndex, rc=localrc)
    if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return

     call c_ESMC_gridgetindex(grid, localTileNo, minIndexArg, maxIndexArg, localrc)
    if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
       ESMF_CONTEXT, rcToReturn=rc)) return

    ! Deallocate interface ints
    call ESMF_InterArrayDestroy(minIndexArg, rc=localrc)
    if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return
    call ESMF_InterArrayDestroy(maxIndexArg, rc=localrc)
    if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return

    ! Return successfully
    if (present(rc)) rc = ESMF_SUCCESS

      end subroutine ESMF_GridGetIndex