subroutine getMeshWithNodesOnFieldLoc(field, maskValues, &
createdTmpMesh, mesh, turnedOnMeshNodeMask, rc)
type(ESMF_Field), intent(in) :: field
integer(ESMF_KIND_I4), intent(in), optional :: maskValues(:)
logical, intent(out) :: createdTmpMesh
logical, intent(out) :: turnedOnMeshNodeMask
type(ESMF_Mesh), intent(out) :: mesh
integer, intent(out), optional :: rc
integer :: localrc
type(ESMF_GeomType_Flag) :: geomtype
type(ESMF_Grid) :: grid
type(ESMF_XGrid) :: xgrid
type(ESMF_Mesh) :: tmpMesh
type(ESMF_MeshLoc) :: meshloc
type(ESMF_StaggerLoc) :: staggerLoc
! Init variable
createdTmpMesh=.false.
turnedOnMeshNodeMask=.false.
! Get information from field that we need to create the mesh
call ESMF_FieldGet(field, geomtype=geomtype, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Get the mesh based on the geomtype
if (geomtype .eq. ESMF_GEOMTYPE_GRID) then
! Get information about Grid from Field
call ESMF_FieldGet(field, grid=grid, &
staggerloc=staggerloc, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Create Mesh from Grid
mesh=b_or_p_GridToMesh(grid,staggerloc,maskValues, &
turnedOnMeshNodeMask, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Record that we created the mesh
createdTmpMesh=.true.
else if (geomtype .eq. ESMF_GEOMTYPE_MESH) then
! Get information about mesh from field
call ESMF_FieldGet(field, mesh=tmpMesh, meshloc=meshloc, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Get or create the mesh depending on the meshloc
if (meshloc .eq. ESMF_MESHLOC_NODE) then
! If the field is already built on nodes then just pass out mesh
mesh = tmpMesh
! Mark that we didn't create it
createdTmpMesh=.false.
else if (meshloc .eq. ESMF_MESHLOC_ELEMENT) then
! If the field is built on element centers, then create a new
! mesh on centers instead
mesh=ESMF_MeshCreateDual(tmpMesh, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Record that we created the mesh
createdTmpMesh=.true.
else
call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_BAD, &
msg=" Unrecognized mesh location.", &
ESMF_CONTEXT, rcToReturn=rc)
return
endif
! Turn on masking
if (present(maskValues)) then
call ESMF_MeshTurnOnNodeMask(mesh, maskValues=maskValues, rc=localrc);
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Record that we turned on the masking
turnedOnMeshNodeMask=.true.
endif
else if (geomtype .eq. ESMF_GEOMTYPE_XGRID) then
! Get information about XGrid from field
call ESMF_FieldGet(field, xgrid=xgrid, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Get XGrid Mesh
call ESMF_XGridGet(xgrid, mesh=tmpMesh, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! We don't have a location for XGrids right now, so assume centers
mesh=ESMF_MeshCreateDual(tmpMesh, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Record that we created the mesh
createdTmpMesh=.true.
else if (geomtype .eq. ESMF_GEOMTYPE_LOCSTREAM) then
call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_BAD, &
msg=" This regrid method not supported for an ESMF_Field built on an ESMF_LocStream.", &
ESMF_CONTEXT, rcToReturn=rc)
return
else
call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_BAD, &
msg=" Unrecognized geometry type in ESMF Field", &
ESMF_CONTEXT, rcToReturn=rc)
return
endif
end subroutine getMeshWithNodesOnFieldLoc