subroutine getMeshOnCornersWFieldOnCenter(field, maskValues, &
createdTmpMesh, mesh, turnedOnMeshElemMask, rc)
type(ESMF_Field), intent(in) :: field
integer(ESMF_KIND_I4), intent(in), optional :: maskValues(:)
logical, intent(out) :: createdTmpMesh
type(ESMF_Mesh), intent(out) :: mesh
logical, intent(out) :: turnedOnMeshElemMask
integer, intent(out), optional :: rc
integer :: localrc
type(ESMF_GeomType_Flag) :: geomtype
type(ESMF_Grid) :: grid
type(ESMF_Mesh) :: tmpMesh
type(ESMF_MeshLoc) :: meshloc
type(ESMF_StaggerLoc) :: staggerLoc
type(ESMF_XGrid) :: xgrid
! Init variables
createdTmpMesh=.false.
turnedOnMeshElemMask=.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
! Field needs to be on center
if (staggerloc .ne. ESMF_STAGGERLOC_CENTER) then
call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_BAD, &
msg=" conservative regrid methods only supported on Fields built on staggerloc=ESMF_STAGGERLOC_CENTER.", &
ESMF_CONTEXT, rcToReturn=rc)
return
endif
! Create Mesh from Grid
mesh=conserve_GridToMesh(grid, maskValues, &
turnedOnMeshElemMask, 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 mesh and other info from Field
call ESMF_FieldGet(field, mesh=mesh, meshloc=meshloc, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Error if mesh not built on elemenent location
if (meshloc .ne. ESMF_MESHLOC_ELEMENT) then
call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_BAD, &
msg=" conservative regrid methods only supported on Fields built on meshloc=ESMF_MESHLOC_ELEMENT.", &
ESMF_CONTEXT, rcToReturn=rc)
return
endif
! Mark that we didn't create it
createdTmpMesh=.false.
! Turn on masking
if (present(maskValues)) then
call ESMF_MeshTurnOnCellMask(mesh, maskValues=maskValues, rc=localrc);
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
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=mesh, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Record that we didn't create it
createdTmpMesh=.false.
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 getMeshOnCornersWFieldOnCenter