ESMF_MeshGet Subroutine

public subroutine ESMF_MeshGet(mesh, parametricDim, spatialDim, nodeCount, nodeIds, nodeCoords, nodeOwners, nodeMaskIsPresent, nodeMask, elementCount, elementIds, elementTypes, elementConnCount, elementConn, elementMaskIsPresent, elementMask, elementAreaIsPresent, elementArea, elementCoordsIsPresent, elementCoords, nodalDistgridIsPresent, nodalDistgrid, elementDistgridIsPresent, elementDistgrid, numOwnedNodes, ownedNodeCoords, numOwnedElements, ownedElemCoords, elemMaskArray, elemAreaArray, isMemFreed, coordSys, status, name, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_Mesh), intent(in) :: mesh
integer, intent(out), optional :: parametricDim
integer, intent(out), optional :: spatialDim
integer, intent(out), optional :: nodeCount
integer, intent(out), optional :: nodeIds(:)
real(kind=ESMF_KIND_R8), intent(out), optional :: nodeCoords(:)
integer, intent(out), optional :: nodeOwners(:)
logical, intent(out), optional :: nodeMaskIsPresent
integer, intent(out), optional :: nodeMask(:)
integer, intent(out), optional :: elementCount
integer, intent(out), optional :: elementIds(:)
integer, intent(out), optional :: elementTypes(:)
integer, intent(out), optional :: elementConnCount
integer, intent(out), optional :: elementConn(:)
logical, intent(out), optional :: elementMaskIsPresent
integer, intent(out), optional :: elementMask(:)
logical, intent(out), optional :: elementAreaIsPresent
real(kind=ESMF_KIND_R8), intent(out), optional :: elementArea(:)
logical, intent(out), optional :: elementCoordsIsPresent
real(kind=ESMF_KIND_R8), intent(out), optional :: elementCoords(:)
logical, intent(out), optional :: nodalDistgridIsPresent
type(ESMF_DistGrid), intent(out), optional :: nodalDistgrid
logical, intent(out), optional :: elementDistgridIsPresent
type(ESMF_DistGrid), intent(out), optional :: elementDistgrid
integer, intent(out), optional :: numOwnedNodes
real(kind=ESMF_KIND_R8), intent(out), optional :: ownedNodeCoords(:)
integer, intent(out), optional :: numOwnedElements
real(kind=ESMF_KIND_R8), intent(out), optional :: ownedElemCoords(:)
type(ESMF_Array), intent(inout), optional :: elemMaskArray
type(ESMF_Array), intent(inout), optional :: elemAreaArray
logical, intent(out), optional :: isMemFreed
type(ESMF_CoordSys_Flag), intent(out), optional :: coordSys
type(ESMF_MeshStatus_Flag), intent(out), optional :: status
character(len=*), intent(out), optional :: name
integer, intent(out), optional :: rc

Source Code

      subroutine ESMF_MeshGet(mesh, parametricDim, spatialDim, &
                   nodeCount, nodeIds, nodeCoords, nodeOwners, &
                   nodeMaskIsPresent, nodeMask,&
                   elementCount, elementIds, elementTypes, &
                   elementConnCount, elementConn, &
                   elementMaskIsPresent,elementMask, &
                   elementAreaIsPresent, elementArea, &
                   elementCoordsIsPresent, elementCoords, &
                   nodalDistgridIsPresent, nodalDistgrid, &
                   elementDistgridIsPresent, elementDistgrid, &
                   numOwnedNodes, ownedNodeCoords, &
                   numOwnedElements, ownedElemCoords, &
                   elemMaskArray, elemAreaArray, &
                   isMemFreed, coordSys, status, name, rc)
!
! !RETURN VALUE:
!
! !ARGUMENTS:
    type(ESMF_Mesh),          intent(in)            :: mesh
    integer,                  intent(out), optional :: parametricDim
    integer,                  intent(out), optional :: spatialDim
    integer,                  intent(out), optional :: nodeCount
    integer,                  intent(out), optional :: nodeIds(:)
    real(ESMF_KIND_R8),       intent(out), optional :: nodeCoords(:)
    integer,                  intent(out), optional :: nodeOwners(:)
    logical,                  intent(out), optional :: nodeMaskIsPresent
    integer,                  intent(out), optional :: nodeMask(:)
    integer,                  intent(out), optional :: elementCount
    integer,                  intent(out), optional :: elementIds(:)
    integer,                  intent(out), optional :: elementTypes(:)
    integer,                  intent(out), optional :: elementConnCount
    integer,                  intent(out), optional :: elementConn(:)
    logical,                  intent(out), optional :: elementMaskIsPresent
    integer,                  intent(out), optional :: elementMask(:)
    logical,                  intent(out), optional :: elementAreaIsPresent
    real(ESMF_KIND_R8),       intent(out), optional :: elementArea(:)
    logical,                  intent(out), optional :: elementCoordsIsPresent
    real(ESMF_KIND_R8),       intent(out), optional :: elementCoords(:)
    logical,                  intent(out), optional :: nodalDistgridIsPresent
    type(ESMF_DistGrid),      intent(out), optional :: nodalDistgrid
    logical,                  intent(out), optional :: elementDistgridIsPresent
    type(ESMF_DistGrid),      intent(out), optional :: elementDistgrid
    integer,                  intent(out), optional :: numOwnedNodes
    real(ESMF_KIND_R8),       intent(out), optional :: ownedNodeCoords(:)
    integer,                  intent(out), optional :: numOwnedElements
    real(ESMF_KIND_R8),       intent(out), optional :: ownedElemCoords(:)
    logical,                  intent(out), optional :: isMemFreed
    type(ESMF_Array),         intent(inout), optional :: elemMaskArray
    type(ESMF_Array),         intent(inout), optional :: elemAreaArray
    type(ESMF_CoordSys_Flag), intent(out), optional :: coordSys
    type(ESMF_MeshStatus_Flag),intent(out), optional :: status
    character(len=*),         intent(out), optional :: name
    integer,                  intent(out), optional :: rc
!
! !DESCRIPTION:
!   Get various information from a mesh.
!
! The arguments are:
! \begin{description}
! \item [mesh]
! Mesh object to retrieve information from.
! \item [{[parametricDim]}]
! Dimension of the topology of the Mesh. (E.g. a mesh constructed of squares would
! have a parametric dimension of 2, whereas a Mesh constructed of cubes would have one
! of 3.)
! \item[{[spatialDim]}]
! The number of coordinate dimensions needed to describe the locations of the nodes
! making up the Mesh. For a manifold, the spatial dimension can be larger than the
! parametric dim (e.g. the 2D surface of a sphere in 3D space), but it can't be smaller.
! \item [{[nodeCount]}]
! The number of local nodes in the mesh (both owned and shared with another PET).
! \item [{[nodeIds]}]
! An array of ids for each local node in the mesh. The nodeIds array should be of size nodeCount.
! \item [{[nodeCoords]}]
! An array of  coordinates for each local node in the mesh. The nodeCoords array should be of size (spatialDim*nodeCount).
! \item [{[nodeOwners]}]
! An array of the PET numbers that own each local node in the mesh. The nodeOwners array should be of size nodeCount.
! \item [{[nodeMaskIsPresent]}]
! .true. if node masking was set in mesh, .false. otherwise.
! \item [{[nodeMask]}]
! An array of mask values for each local node in the mesh. The nodeOwners array should be of size nodeCount.
! \item [{[elementCount]}]
! The number of local elements in the mesh (both owned and shared with another PET).
! \item [{[elementIds]}]
! An array of ids for each local element in the mesh. The elementIds array should be of size elementCount.
! \item [{[elementTypes]}]
! An array of types for each local element in the mesh. Please see
! section~\ref{const:meshelemtype} for the list of options. The elementTypes array should be of size elementCount.
! \item [{[elementConnCount]}]
! The number of entries elementConn array. Provided as a convenience.
! \item[elementConn]
!         An array containing the indexes of the sets of nodes to be connected together to form the
!         elements to be created on this PET. The entries in this list are NOT node global ids,
!         but rather each entry is a local index (1 based) into the list of nodes to be
!         created on this PET by this call.
!         In other words, an entry of 1 indicates that this element contains the node
!         described by {\tt nodeIds(1)}, {\tt nodeCoords(1)}, etc. on this PET. It is also
!         important to note that the order of the nodes in an element connectivity list
!         matters. Please see Section~\ref{const:meshelemtype} for diagrams illustrating
!         the correct order of nodes in a element. This input consists of a 1D array with
!         a total size equal to the sum of the number of nodes contained in each element on
!         this PET (also provided by elementConnCount). The number of nodes in each element 
!         is implied by its element type in
!         {\tt elementTypes}. The nodes for each element
!         are in sequence in this array (e.g. the nodes for element 1 are elementConn(1),
!         elementConn(2), etc.).
! \item [{[elementMaskIsPresent]}]
! .true. if element masking was set in mesh, .false. otherwise.
! \item [{[elementMask]}]
! An array of mask values for each local element in the mesh. The elementMask array should be of size elementCount.
! \item [{[elementAreaIsPresent]}]
! .true. if element areas were set in mesh, .false. otherwise.
! \item [{[elementArea]}]
! An array of area values for each local element in the mesh. The elementArea array should be of size elementCount.
! \item [{[elementCoordsIsPresent]}]
! .true. if element coordinates were set in mesh, .false. otherwise.
! \item [{[elementCoords]}]
! An array of coordinate values for each local element in the mesh. The elementCoord array should be of size (spatialDim*elementCount).
! \item [{[nodalDistgridIsPresent]}]
! .true. if nodalDistgrid was set in Mesh object, .false. otherwise.
! \item [{[nodalDistgrid]}]
! A Distgrid describing the distribution of the nodes across the PETs. Note that
! on each PET the distgrid will only contain entries for nodes owned by that PET.
! This is the DistGrid that would be used to construct the Array in a Field that is constructed
! on {\tt mesh}.
! \item [{[elementDistgridIsPresent]}]
! .true. if elementDistgrid was set in Mesh object, .false. otherwise.
! \item [{[elementDistgrid]}]
! A Distgrid describing the distribution of elements across the PETs. Note that
! on each PET the distgrid will only contain entries for elements owned by that PET.
! \item [{[numOwnedNodes]}]
! The number of local nodes which are owned by this PET. This is the number of PET local entries in
! the nodalDistgrid.
! \item [{[ownedNodeCoords]}]
! The coordinates for the local nodes. These coordinates will be in the proper order to correspond
! with the nodes in the {\tt nodalDistgrid} returned by this call, and hence with a Field built on
! {\tt mesh}. The size of the input array should be the spatial dim of {\tt mesh} times
! {\tt numOwnedNodes}.
! \item [{[numOwnedElements]}]
! The number of local elements which are owned by this PET. Note that every element is owned by
! the PET it resides on, so unlike for nodes, {\tt numOwnedElements} is identical to the number of elements on
! the PET. It is also the number of PET local entries in the elementDistgrid.
! \item [{[ownedElemCoords]}]
! The center coordinates for the local elements. These coordinates will be in the proper order to correspond
! with the elements in the {\tt elementDistgrid} returned by this call, and hence with a Field built on the
! center of {\tt mesh}. The size of the input array should be the spatial dim of {\tt mesh} times
! {\tt numOwnedElements}.
! \item [{[elemMaskArray]}]
! The mask information for elements put into an ESMF Array. The ESMF Array must be build on a DistGrid which
! matches the elementDistgrid.
! \item [{[elemAreaArray]}]
! The area information for elements put into an ESMF Array. The ESMF Array must be build on a DistGrid which
! matches the elementDistgrid.
! \item [{[isMemFreed]}]
! Indicates if the coordinate and connection memory been freed from {\tt mesh}. If so, it
! can no longer be used as part of an {\tt ESMF\_FieldRegridStore()} call.
! \item[{[coordSys]}]
!  The coordinate system of the grid coordinate data.
! \item[{[status]}]
!    Flag indicating the status of the Mesh. Please
!    see Section~\ref{const:meshstatus} for the list of options.
! \item [{[name]}]
!    Name of the Mesh object.
! \item [{[rc]}]
!         Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
! \end{description}
!
!EOP
    integer :: localrc
    type(ESMF_Logical) :: isfree
    type(ESMF_MeshStatus_Flag) :: local_status
    integer :: sdim, pdim
    integer :: numNode, numElem
    type(ESMF_CoordSys_Flag) :: coordSysIn
    logical  :: isPresent
    type(ESMF_Logical) :: isPresentAux
    integer, parameter :: maxElemArrays=2
    integer            :: numElemArrays
    type(ESMF_Pointer) :: elemArrays(maxElemArrays)
    integer :: infoTypeElemArrays(maxElemArrays)
    integer,parameter :: infoTypeElem_Mask=1
    integer,parameter :: infoTypeElem_Area=2
    type(ESMF_InterArray) :: elementIdsIA
    type(ESMF_InterArray) :: elementTypesIA
    type(ESMF_InterArray) :: elementConnIA
    type(ESMF_InterArray) :: elementMaskIA
    type(ESMF_InterArray) :: elementAreaIA
    type(ESMF_InterArray) :: elementCoordsIA
    type(ESMF_InterArray) :: nodeIdsIA
    type(ESMF_InterArray) :: nodeCoordsIA
    type(ESMF_InterArray) :: nodeOwnersIA
    type(ESMF_InterArray) :: nodeMaskIA
    integer :: nodeMaskIsPresentI
    integer :: elemMaskIsPresentI
    integer :: elemAreaIsPresentI
    integer :: elemCoordsIsPresentI
    type(ESMF_DistGrid) :: nodeDistGrid, elemDistGrid, elemDistGrid2

    ! Init local rc
    localrc = ESMF_SUCCESS

    !!! Error check status of Mesh versus what's being asked for !!!

    ! Make sure mesh is initialized
    ESMF_INIT_CHECK_DEEP(ESMF_MeshGetInit, mesh, rc)

    ! If mesh has not been fully created, make sure that the user
    ! isn't asking for something that requires a fully created mesh
    call C_ESMC_MeshGetStatus(mesh, local_status)
    if (local_status .ne. ESMF_MESHSTATUS_COMPLETE) then

       ! Check one set of variables
       if (present(parametricDim) .or. &
            present(spatialDim) .or. &
            present(numOwnedNodes) .or. &
            present(ownedNodeCoords) .or. &
            present(numOwnedElements) .or. &
            present(ownedElemCoords) .or. &
            present(elemMaskArray) .or. &
            present(elemAreaArray) .or. &
            present(coordSys)) then

          call ESMF_LogSetError(rcToCheck=ESMF_RC_OBJ_WRONG, &
               msg="- the mesh has not been fully created", &
               ESMF_CONTEXT, rcToReturn=rc)
          return
       endif

       ! Check another set, just so the length of the if isn't so big
       if (present(nodeCount) .or. &
            present(nodeIds) .or. &
            present(nodeCoords) .or. &
            present(nodeOwners) .or. &
            present(nodeMaskIsPresent) .or. &
            present(nodeMask)) then

          call ESMF_LogSetError(rcToCheck=ESMF_RC_OBJ_WRONG, &
               msg="- the mesh has not been fully created", &
               ESMF_CONTEXT, rcToReturn=rc)
          return
       endif


       ! Check another set, just so the length of the if isn't so big
       if (present(elementCount) .or. &
            present(elementIds) .or. &
            present(elementTypes) .or. &
            present(elementConnCount) .or. &
            present(elementConn) .or. &
            present(elementMaskIsPresent) .or. &
            present(elementMask) .or. &
            present(elementAreaIsPresent) .or. &
            present(elementArea) .or. &
            present(elementCoordsIsPresent) .or. &
            present(elementCoords)) then

          call ESMF_LogSetError(rcToCheck=ESMF_RC_OBJ_WRONG, &
               msg="- the mesh has not been fully created", &
               ESMF_CONTEXT, rcToReturn=rc)
          return
       endif
    endif

    ! XMRKX !
    ! TODO: Rearrange all the info gets below to fit in to the 3 categories below 
    
    !!!!!!!! Get Misc info from Mesh !!!!!!!!

    !!!!!!!! Get Node info from Mesh !!!!!!!!

    call C_ESMC_MeshGetDimensions(mesh, sdim, pdim, coordSysIn, localrc)
    if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
        ESMF_CONTEXT, rcToReturn=rc)) return
    
    call C_ESMC_MeshGetOwnedNodeCount(mesh, numNode, localrc)
    if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
        ESMF_CONTEXT, rcToReturn=rc)) return

    call C_ESMC_MeshGetOwnedElemCount(mesh, numElem, localrc)
    if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
        ESMF_CONTEXT, rcToReturn=rc)) return

    ! Get parametric dim
    if (present(parametricDim)) parametricDim=pdim

    ! Get spatial dim
    if (present(spatialDim)) spatialDim=sdim

    ! Get number owned nodes
    if (present(numOwnedNodes)) numOwnedNodes = numNode

    ! Get number owned elements
    if (present(numOwnedElements)) numOwnedElements = numElem

    ! Get Node Count
    if (present(nodeCount)) then
       ! Make call to get info
       call C_ESMC_MeshGetNodeCount(mesh, &
            nodeCount, localrc)
       if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return
    endif

    ! Get information about whether various node information is present
    if (present(nodeMaskIsPresent)) then

       ! Init integer variables for getting logical info from C
       nodeMaskIsPresentI=0

       ! Call into C
       call C_ESMC_MeshGetNodeInfoPresence(mesh, &
            nodeMaskIsPresentI, &
            localrc)
       if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

       ! Set variables from C info
       if (present(nodeMaskIsPresent)) then
          nodeMaskIsPresent=.false.
          if (nodeMaskIsPresentI .ne. 0) nodeMaskIsPresent=.true.
       endif
    endif


    ! Get node creation info
    if (present(nodeIds) .or. &
        present(nodeCoords) .or. &
        present(nodeOwners) .or. &
        present(nodeMask)) then

       ! Create interface arrays
        nodeIdsIA = ESMF_InterArrayCreate(nodeIds, rc=localrc)
        if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
          ESMF_CONTEXT, rcToReturn=rc)) return       

        nodeCoordsIA = ESMF_InterArrayCreate(farray1DR8=nodeCoords, rc=localrc)
        if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
          ESMF_CONTEXT, rcToReturn=rc)) return       

        nodeOwnersIA = ESMF_InterArrayCreate(nodeOwners, rc=localrc)
        if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
          ESMF_CONTEXT, rcToReturn=rc)) return       

        nodeMaskIA = ESMF_InterArrayCreate(nodeMask, rc=localrc)
        if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
          ESMF_CONTEXT, rcToReturn=rc)) return       

       ! Call into C
       call C_ESMC_MeshGetNodeCreateInfo(mesh, &
            nodeIdsIA, nodeCoordsIA, &
            nodeOwnersIA, nodeMaskIA, &
            localrc)
       if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

       ! Destroy interface arrays
       call ESMF_InterArrayDestroy(nodeIdsIA, rc=localrc)
       if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

       call ESMF_InterArrayDestroy(nodeCoordsIA, rc=localrc)
       if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

       call ESMF_InterArrayDestroy(nodeOwnersIA, rc=localrc)
       if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

       call ESMF_InterArrayDestroy(nodeMaskIA, rc=localrc)
       if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return
    endif



    !!!!!!!! Get Elem info from Mesh !!!!!!!!

    ! Get Element Count
    if (present(elementCount)) then
       ! Make call to get info
       call C_ESMC_MeshGetElemCount(mesh, elementCount, localrc)
       if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return
    endif

    ! Get Element Connection Count
    if (present(elementConnCount)) then
       ! Make call to get info
       call C_ESMC_MeshGetElemConnCount(mesh, elementConnCount, localrc)
       if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return
    endif


    ! Get information about whether various elem information is present
    if (present(elementMaskIsPresent) .or. &
        present(elementAreaIsPresent) .or. &
        present(elementCoordsIsPresent)) then

       ! Init integer variables for getting logical info from C
       elemMaskIsPresentI=0
       elemAreaIsPresentI=0
       elemCoordsIsPresentI=0

       ! Call into C
       call C_ESMC_MeshGetElemInfoPresence(mesh, &
            elemMaskIsPresentI, &
            elemAreaIsPresentI, &
            elemCoordsIsPresentI, &
            localrc)
       if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

       ! Set variables from C info
       if (present(elementMaskIsPresent)) then
          elementMaskIsPresent=.false.
          if (elemMaskIsPresentI .ne. 0) elementMaskIsPresent=.true.
       endif

       if (present(elementAreaIsPresent)) then
          elementAreaIsPresent=.false.
          if (elemAreaIsPresentI .ne. 0) elementAreaIsPresent=.true.
       endif

       if (present(elementCoordsIsPresent)) then
          elementCoordsIsPresent=.false.
          if (elemCoordsIsPresentI .ne. 0) elementCoordsIsPresent=.true.
       endif
    endif

   ! Get elem creation info
    if (present(elementIds) .or. &
        present(elementTypes) .or. &
        present(elementConn) .or. &
        present(elementMask) .or. &
        present(elementArea) .or. &
        present(elementCoords)) then

       ! Create interface arrays
        elementIdsIA = ESMF_InterArrayCreate(elementIds, rc=localrc)
        if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
          ESMF_CONTEXT, rcToReturn=rc)) return       

        elementTypesIA = ESMF_InterArrayCreate(elementTypes, rc=localrc)
        if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
          ESMF_CONTEXT, rcToReturn=rc)) return       

        elementConnIA = ESMF_InterArrayCreate(elementConn, rc=localrc)
        if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
          ESMF_CONTEXT, rcToReturn=rc)) return       

        elementMaskIA = ESMF_InterArrayCreate(elementMask, rc=localrc)
        if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
          ESMF_CONTEXT, rcToReturn=rc)) return       

        elementAreaIA = ESMF_InterArrayCreate(farray1DR8=elementArea, rc=localrc)
        if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
          ESMF_CONTEXT, rcToReturn=rc)) return       

        elementCoordsIA = ESMF_InterArrayCreate(farray1DR8=elementCoords, rc=localrc)
        if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
          ESMF_CONTEXT, rcToReturn=rc)) return       


       ! Call into C
       call C_ESMC_MeshGetElemCreateInfo(mesh, &
            elementIdsIA, elementTypesIA, &
            elementConnIA, elementMaskIA, &
            elementAreaIA, elementCoordsIA, &
            localrc)
       if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

       ! Destroy interface arrays
       call ESMF_InterArrayDestroy(elementIdsIA, rc=localrc)
       if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

       call ESMF_InterArrayDestroy(elementTypesIA, rc=localrc)
       if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

       call ESMF_InterArrayDestroy(elementConnIA, rc=localrc)
       if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

       call ESMF_InterArrayDestroy(elementMaskIA, rc=localrc)
       if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

       call ESMF_InterArrayDestroy(elementAreaIA, rc=localrc)
       if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

       call ESMF_InterArrayDestroy(elementCoordsIA, rc=localrc)
       if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return
    endif
    

    ! Get node coords
    if (present(ownedNodeCoords)) then
       call C_ESMC_MeshGetIsFree(mesh, isfree)
       if (isfree == ESMF_TRUE) then
          call ESMF_LogSetError(rcToCheck=ESMF_RC_OBJ_WRONG, &
                msg="- the mesh internals have been freed", &
                ESMF_CONTEXT, rcToReturn=rc)
          return
       endif

       ! Check array size
       if (size(ownedNodeCoords)<numNode*sdim) then
          call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_WRONG, &
                msg="- ownedNodeCoords too small to hold coordinates", &
                ESMF_CONTEXT, rcToReturn=rc)
          return
       endif

       ! Get coords from C
       call C_ESMC_GetLocalCoords(mesh, ownedNodeCoords, sdim, localrc)
       if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
           ESMF_CONTEXT, rcToReturn=rc)) return
    endif

    if (present(ownedElemCoords)) then
       call C_ESMC_MeshGetIsFree(mesh, isfree)
       if (isfree == ESMF_TRUE) then
          call ESMF_LogSetError(rcToCheck=ESMF_RC_OBJ_WRONG, &
                msg="- the mesh internals have been freed", &
                ESMF_CONTEXT, rcToReturn=rc)
          return
       endif

       ! Check array size
       if (size(ownedElemCoords)<numElem*sdim) then
          call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_WRONG, &
                msg="- ownedElemCoords too small to hold coordinates", &
                ESMF_CONTEXT, rcToReturn=rc)
          return
       endif

       ! Get coords from C
       call C_ESMC_GetLocalElemCoords(mesh, ownedElemCoords, sdim, localrc)
       if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
           ESMF_CONTEXT, rcToReturn=rc)) return
    endif

    isPresent = .false.
    ! Get nodal Distgrid presence
    if (present(nodalDistgridIsPresent)) then

        call c_ESMC_MeshGetNodeDistGridPresent(mesh, isPresentAux, localrc)
        if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

       ! Output state
       nodalDistgridIsPresent=isPresentAux
    endif

    isPresent = .false.
    ! Get nodal Distgrid
    if (present(nodalDistgrid)) then

        call c_ESMC_MeshGetNodeDistGridPresent(mesh, isPresentAux, localrc)
        if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

        if (isPresentAux==ESMF_TRUE) then

            call c_ESMC_MeshGetNodeDistGrid(mesh, nodeDistGrid, localrc)
            if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
                ESMF_CONTEXT, rcToReturn=rc)) return

            ! Set init code for deep C++ DistGrid object
            call ESMF_DistGridSetInitCreated(nodeDistGrid, rc=localrc)
            if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
              ESMF_CONTEXT, rcToReturn=rc)) return

            ! Output distgrid
            nodalDistgrid = nodeDistGrid
        else
            call ESMF_LogSetError(rcToCheck=ESMF_RC_OBJ_NOT_CREATED, &
                          msg="- this mesh doesn't contain a nodal distgrid", &
                          ESMF_CONTEXT, rcToReturn=rc)
            return
        endif
    endif

    isPresent = .false.
    ! Get element Distgrid presence
    if (present(elementDistgridIsPresent)) then

        call c_ESMC_MeshGetElemDistGridPresent(mesh, isPresentAux, localrc)
        if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

        ! Output state
        elementDistgridIsPresent=isPresentAux
    endif

    isPresent = .false.
    ! Get element Distgrid
    if (present(elementDistgrid)) then

        call c_ESMC_MeshGetElemDistGridPresent(mesh, isPresentAux, localrc)
        if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return

        if (isPresentAux==ESMF_TRUE) then

            call c_ESMC_MeshGetElemDistGrid(mesh, elemDistGrid, localrc)
            if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
                ESMF_CONTEXT, rcToReturn=rc)) return

            ! Set init code for deep C++ DistGrid object
            call ESMF_DistGridSetInitCreated(elemDistGrid, rc=localrc)
            if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
                ESMF_CONTEXT, rcToReturn=rc)) return

            ! Output distgrid
            elementDistgrid = elemDistGrid
        else
            call ESMF_LogSetError(rcToCheck=ESMF_RC_OBJ_NOT_CREATED, &
                          msg="- this mesh doesn't contain an elemental distgrid", &
                          ESMF_CONTEXT, rcToReturn=rc)
            return
        endif
    endif

    ! Init number of elem arrays for which user is asking
    numElemArrays=0

    ! Get elem mask information
    if (present(elemMaskArray)) then

       ! Make sure mesh is initialized
       ESMF_INIT_CHECK_DEEP(ESMF_ArrayGetInit, elemMaskArray, rc)

       ! Set number of elem info request
       numElemArrays=numElemArrays+1

       ! Load info type
       infoTypeElemArrays(numElemArrays)=infoTypeElem_Mask

       ! Load Array
       call ESMF_ArrayGetThis(elemMaskArray,elemArrays(numElemArrays),rc=localrc)
       if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return
    endif


    ! Get elem area information
    if (present(elemAreaArray)) then

       ! Make sure mesh is initialzed
       ESMF_INIT_CHECK_DEEP(ESMF_ArrayGetInit, elemAreaArray, rc)

       ! Set number of elem info request
       numElemArrays=numElemArrays+1

       ! Load info type
       infoTypeElemArrays(numElemArrays)=infoTypeElem_Area

       ! Load Array
       call ESMF_ArrayGetThis(elemAreaArray,elemArrays(numElemArrays),rc=localrc)
       if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return
    endif


    ! Get mask or area info for elems
    if (numElemArrays .gt. 0) then

        call c_ESMC_MeshGetElemDistGrid(mesh, elemDistGrid2, localrc)
        if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
             ESMF_CONTEXT, rcToReturn=rc)) return
             
       ! Make call to get info
       call C_ESMC_GetElemInfoIntoArray(mesh, &
            elemDistGrid2, &
            numElemArrays, &
            infoTypeElemArrays, &
            elemArrays, &
            localrc)
       if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
            ESMF_CONTEXT, rcToReturn=rc)) return
    endif

    ! Get freed status
    if (present(isMemFreed)) then
      call C_ESMC_MeshGetIsFree(mesh, isfree)
      isMemFreed=isfree
    endif

    ! Get coord system
    if (present(coordSys)) coordSys = coordSysIn

    ! Get status
    if (present(status)) status=local_status

    ! Special call to get name out of Base class
    if (present(name)) then
      call c_ESMC_GetName(mesh, name, localrc)
      if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
        ESMF_CONTEXT, rcToReturn=rc)) return
    endif
    
    ! Error output
    if (present(rc)) rc = localrc

    end subroutine ESMF_MeshGet