function ESMF_DistGridMatch(distgrid1, distgrid2, keywordEnforcer, rc)
!
! !RETURN VALUE:
type(ESMF_DistGridMatch_Flag) :: ESMF_DistGridMatch
! !ARGUMENTS:
type(ESMF_DistGrid), intent(in) :: distgrid1
type(ESMF_DistGrid), intent(in) :: distgrid2
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
integer, intent(out), optional :: rc
!
! !DESCRIPTION:
! Determine to which level {\tt distgrid1} and {\tt distgrid2} match.
!
! Returns a range of values of type {\tt ESMF\_DistGridMatch\_Flag},
! indicating how closely the DistGrids match. For a description of the
! possible return values, see~\ref{const:distgridmatch}.
! Note that this call only performs PET local matching. Different return values
! may be returned on different PETs for the same DistGrid pair.
!
! The arguments are:
! \begin{description}
! \item[distgrid1]
! {\tt ESMF\_DistGrid} object.
! \item[distgrid2]
! {\tt ESMF\_DistGrid} object.
! \item[{[rc]}]
! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
! \end{description}
!
!EOP
!------------------------------------------------------------------------------
integer :: localrc ! local return code
type(ESMF_DistGridMatch_Flag) :: matchResult
! initialize return code; assume routine not implemented
localrc = ESMF_RC_NOT_IMPL
if (present(rc)) rc = ESMF_RC_NOT_IMPL
! Initialize return value to invalid, in case of bail-out
ESMF_DistGridMatch = ESMF_DISTGRIDMATCH_INVALID
! Check init status of arguments
ESMF_INIT_CHECK_DEEP(ESMF_DistGridGetInit, distgrid1, rc)
ESMF_INIT_CHECK_DEEP(ESMF_DistGridGetInit, distgrid2, rc)
! Call into the C++ interface, which will sort out optional arguments.
call c_ESMC_DistGridMatch(distgrid1, distgrid2, matchResult, localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Set the actual return value
ESMF_DistGridMatch = matchResult
! return successfully
if (present(rc)) rc = ESMF_SUCCESS
end function ESMF_DistGridMatch