function ESMF_MeshCreateFromMeshes(MeshA, MeshB, MeshOp, areaThreshold, name, rc)
!
!
! !RETURN VALUE:
type(ESMF_Mesh) :: ESMF_MeshCreateFromMeshes
! !ARGUMENTS:
type(ESMF_Mesh), intent(in) :: MeshA
type(ESMF_Mesh), intent(in) :: MeshB
type(ESMF_MeshOp_Flag), intent(in) :: MeshOp
real(ESMF_KIND_R8), intent(in), optional :: areaThreshold
character(len=*), intent(in), optional :: name
integer, intent(out), optional :: rc
!
! !DESCRIPTION:
! Create a Mesh from two source Meshes with spatial operations. These spatial operations
! treat the points in the two Meshes as point sets. The returned Mesh is either intersection,
! union, or difference of the point sets of two source Meshes.
!
! \begin{description}
! \item [MeshA]
! The first source Mesh containing the first point set.
! \item [MeshB]
! The second source Mesh containing the second point set.
! \item [MeshOp]
! Mesh spatial operation flag. Currently only ESMF_MESHOP_DIFFERENCE is supported.
! Please refer to section {\ref const:meshop}
! \item [areaThreshold]
! Minimum cell area to be accepted to create the resulting Mesh. Cells with area
! less than this threshold value are discarded. This is a user tunable parameter
! to handle roundoff error when computing with floating point numbers. The default
! value is 0.
! \item [{[name]}]
! The name of the Mesh.
! \item [{[rc]}]
! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
! \end{description}
!
!EOPI
!------------------------------------------------------------------------------
integer :: localrc
integer :: numNode, numElem
real(ESMF_KIND_R8) :: l_threshold
l_threshold = 0.
if(present(areaThreshold)) l_threshold = areaThreshold
call C_ESMC_MeshCreateFromMeshes(meshA, meshB, ESMF_MeshCreateFromMeshes, &
MeshOp, l_threshold, localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! these should be set inside MeshCap
! Create two distgrids, one for nodes and one for elements
call C_ESMC_MeshCreateNodeDistGrid(ESMF_MeshCreateFromMeshes, localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
call C_ESMC_MeshCreateElemDistGrid(ESMF_MeshCreateFromMeshes, localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Set Status
call C_ESMC_MeshSetStatus(ESMF_MeshCreateFromMeshes, ESMF_MESHSTATUS_COMPLETE)
! Set the name in Base object
if (present(name)) then
call c_ESMC_SetName(ESMF_MeshCreateFromMeshes, "Mesh", name, localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
endif
ESMF_INIT_SET_CREATED(ESMF_MeshCreateFromMeshes)
if (present(rc)) rc=ESMF_SUCCESS
return
end function ESMF_MeshCreateFromMeshes