function ESMF_MeshCreateFromGrid(grid, name, rc)
!
!
! !RETURN VALUE:
type(ESMF_Mesh) :: ESMF_MeshCreateFromGrid
! !ARGUMENTS:
type(ESMF_Grid), intent(in) :: grid
character(len=*), intent(in), optional :: name
integer, intent(out), optional :: rc
!
! !DESCRIPTION:
! Create an ESMF Mesh from an ESMF Grid. This method creates the elements of
! the Mesh from the cells of the Grid, and the nodes of the Mesh from the corners of
! the Grid. Corresponding locations in the Grid and new Mesh will have the same
! coordinates, sequence indices, masking, and area information.
!
! This method currently only works for 2D Grids. In addition, this method requires
! the input Grid to have coordinates in the corner stagger location.
!
! \begin{description}
! \item [grid]
! The ESMF Grid from which to create the Mesh.
! \item [{[name]}]
! The name of the Mesh.
! \item [{[rc]}]
! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
! \end{description}
!
!EOP
!------------------------------------------------------------------------------
integer :: localrc
integer :: numNode, numElem
! Create C side Mesh
! Optional name argument requires separate calls into C++
if (present(name)) then
call C_ESMC_MeshCreateFromGrid(ESMF_MeshCreateFromGrid%this, &
grid, name, localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
else
call C_ESMC_MeshCreateFromGrid(ESMF_MeshCreateFromGrid%this, &
grid, "", localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
endif
! these should be set inside MeshCap
! Create nodal distgrid
call C_ESMC_MeshCreateNodeDistGrid(ESMF_MeshCreateFromGrid, localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Create element distgrid
call C_ESMC_MeshCreateElemDistGrid(ESMF_MeshCreateFromGrid, localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Set Status
call C_ESMC_MeshSetStatus(ESMF_MeshCreateFromGrid, ESMF_MESHSTATUS_COMPLETE)
! Set init status of mesh
ESMF_INIT_SET_CREATED(ESMF_MeshCreateFromGrid)
! Return success
if (present(rc)) rc=ESMF_SUCCESS
return
end function ESMF_MeshCreateFromGrid