subroutine ESMF_XGridDG(xgridgeombase, distgrid, factorIndexList, dim, rc)
!
! !DESCRIPTION:
! Compute distgrid on the XGrid locally matching the grid on the same set of PETs;
! This allows local SMM optimization. To be completed.
!
! The arguments are:
! \begin{description}
! \item [xgridgeombase]
! xgridgeombase object spanning a set of PETs.
! \item [distgrid]
! distgrid object spanning the same set of PETs.
! \item [factorIndexList]
! indices used to construct the arb index list.
! \item [dim]
! dimension of the indices used to retrieve the seq. index list.
! \item [{[rc]}]
! Return code; equals {\tt ESMF\_SUCCESS} only if successful.
! \end{description}
!
!EOPI
type(ESMF_XGridGeomBase), intent(in) :: xgridgeombase
type(ESMF_DistGrid), intent(inout) :: distgrid
integer, pointer :: factorIndexList(:,:)
integer, intent(in) :: dim
integer, intent(out), optional :: rc
integer :: localrc, nidx_src, nidx_dst
! Initialize
localrc = ESMF_RC_NOT_IMPL
! Initialize return code
if(present(rc)) rc = ESMF_RC_NOT_IMPL
!print *, dim, size(factorIndexList, 2), factorIndexList(dim, :)
distgrid = ESMF_DistGridCreate(factorIndexList(dim,:), rc=localrc)
if (ESMF_LogFoundAllocError(localrc, &
msg="- Creating distgrid from factorIndexList", &
ESMF_CONTEXT, rcToReturn=rc)) return
if(present(rc)) rc = ESMF_SUCCESS
end subroutine ESMF_XGridDG