function ESMF_GeomMatch(geom1, geom2, keywordEnforcer, rc)
!
! !RETURN VALUE:
type(ESMF_GeomMatch_Flag) :: ESMF_GeomMatch
! !ARGUMENTS:
type(ESMF_Geom), intent(in) :: geom1
type(ESMF_Geom), intent(in) :: geom2
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
integer, intent(out), optional :: rc
!
!
! !DESCRIPTION:
! Check if {\tt geom1} and {\tt geom2} match. Returns a range of values of type
! ESMF\_GeomMatch indicating how closely the Geoms match. For a description of
! the possible return values, please see~\ref{const:geommatch}.
! Please also note that by default this call is not collective and only
! returns the match for the piece of the Geoms on the local PET. In this case,
! it is possible for this call to return a different match on different PETs
! for the same Geoms.
!
! The arguments are:
! \begin{description}
! \item[geom1]
! {\tt ESMF\_Geom} object.
! \item[geom2]
! {\tt ESMF\_Geom} object.
! \item[{[rc]}]
! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
! \end{description}
!
!EOP
!------------------------------------------------------------------------------
integer :: localrc ! local return code
integer :: matchResult
integer(ESMF_KIND_I4) :: localResult(1), globalResult(1)
logical :: l_global
integer :: npet
type(ESMF_VM) :: vm
type(ESMF_GeomType_Flag) :: type
! initialize return code; assume routine not implemented
localrc = ESMF_RC_NOT_IMPL
if (present(rc)) rc = ESMF_RC_NOT_IMPL
! init to one setting in case of error
ESMF_GeomMatch = ESMF_GEOMMATCH_INVALID
! Check init status of arguments
ESMF_INIT_CHECK_DEEP(ESMF_GeomGetInit, geom1, rc)
ESMF_INIT_CHECK_DEEP(ESMF_GeomGetInit, geom2, rc)
! Check for Alias
if (geom1 == geom2) then
ESMF_GeomMatch=ESMF_GEOMMATCH_ALIAS
endif
! If not alias, check for geom alias
if (ESMF_GeomMatch == ESMF_GEOMMATCH_INVALID) then
! If types not equal, not geom alias
type = geom1%gbcp%type
if (type == geom2%gbcp%type) then
if (type == ESMF_GEOMTYPE_GRID) then
if (geom1%gbcp%grid == geom2%gbcp%grid) ESMF_GeomMatch=ESMF_GEOMMATCH_GEOMALIAS
else if (type == ESMF_GEOMTYPE_MESH) then
if (geom1%gbcp%mesh == geom2%gbcp%mesh) ESMF_GeomMatch=ESMF_GEOMMATCH_GEOMALIAS
else if (type == ESMF_GEOMTYPE_LOCSTREAM) then
if (geom1%gbcp%locstream == geom2%gbcp%locstream) ESMF_GeomMatch=ESMF_GEOMMATCH_GEOMALIAS
else if (type == ESMF_GEOMTYPE_XGRID) then
if (geom1%gbcp%xgrid == geom2%gbcp%xgrid) ESMF_GeomMatch=ESMF_GEOMMATCH_GEOMALIAS
endif
endif
endif
! If we're still invalid, then nothing has matched, so set to none
if (ESMF_GeomMatch == ESMF_GEOMMATCH_INVALID) ESMF_GeomMatch=ESMF_GEOMMATCH_NONE
! Take this out for now, because it's not clear how the handle different kinds
! of matching.
#if 0
! Check global result
l_global = .false.
if(present(globalflag)) l_global = globalflag
if(l_global) then
call ESMF_VMGetCurrent(vm, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
call ESMF_VMGet(vm, petCount=npet, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
localResult(1) = matchResult
globalResult(1) = 0
call ESMF_VMAllReduce(vm, localResult, globalResult, &
1, ESMF_REDUCE_SUM, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
if(globalResult(1) == npet) then
ESMF_GridMatch = ESMF_GRIDMATCH_EXACT
else
ESMF_GridMatch = ESMF_GRIDMATCH_NONE
endif
endif
#endif
! return successfully
if (present(rc)) rc = ESMF_SUCCESS
end function ESMF_GeomMatch