subroutine ESMF_ArrayBundleHaloStore(arraybundle, routehandle, &
keywordEnforcer, startregion, haloLDepth, haloUDepth, rc)
!
! !ARGUMENTS:
type(ESMF_ArrayBundle), intent(inout) :: arraybundle
type(ESMF_RouteHandle), intent(inout) :: routehandle
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
type(ESMF_StartRegion_Flag),intent(in), optional :: startregion
integer, intent(in), optional :: haloLDepth(:)
integer, intent(in), optional :: haloUDepth(:)
integer, intent(out), optional :: rc
!
! !STATUS:
! \begin{itemize}
! \item\apiStatusCompatibleVersion{5.2.0r}
! \end{itemize}
!
! !DESCRIPTION:
! \begin{sloppypar}
! Store an ArrayBundle halo operation over the data in {\tt arraybundle}. By
! default, i.e. without specifying {\tt startregion}, {\tt haloLDepth}
! and {\tt haloUDepth}, all elements in the total Array regions that lie
! outside the exclusive regions will be considered potential destination
! elements for the halo operation. However, only those elements that have a corresponding
! halo source element, i.e. an exclusive element on one of the DEs, will be
! updated under the halo operation. Elements that have no associated source
! remain unchanged under halo.
! \end{sloppypar}
!
! Specifying {\tt startregion} allows to change the shape of the
! effective halo region from the inside. Setting this flag to
! {\tt ESMF\_STARTREGION\_COMPUTATIONAL} means that only elements outside
! the computational region for each Array are considered for potential
! destination elements for the halo operation. The default is
! {\tt ESMF\_STARTREGION\_EXCLUSIVE}.
!
! The {\tt haloLDepth} and {\tt haloUDepth} arguments allow to reduce
! the extent of the effective halo region. Starting at the region specified
! by {\tt startregion}, the {\tt haloLDepth} and {\tt haloUDepth}
! define a halo depth in each direction. Note that the maximum halo region is
! limited by the total region for each Array, independent of the actual
! {\tt haloLDepth} and {\tt haloUDepth} setting. The total Array regions are
! local DE specific. The {\tt haloLDepth} and {\tt haloUDepth} are interpreted
! as the maximum desired extent, reducing the potentially larger region
! available for the halo operation.
!
! The routine returns an {\tt ESMF\_RouteHandle} that can be used to call
! {\tt ESMF\_ArrayBundleHalo()} on any pair of ArrayBundles that matches
! {\tt srcArrayBundle} and {\tt dstArrayBundle} in {\em type}, {\em kind},
! and memory layout of the {\em distributed} dimensions. However, the size,
! number, and index order of {\em undistributed} dimensions may be different.
! See section \ref{RH:Reusability} for a more detailed discussion of
! RouteHandle reusability.
!
! This call is {\em collective} across the current VM.
!
! \begin{description}
! \item [arraybundle]
! {\tt ESMF\_ArrayBundle} containing data to be haloed. The data in the halo
! regions may be destroyed by this call.
! \item [routehandle]
! Handle to the precomputed Route.
! \item [{[startregion]}]
! \begin{sloppypar}
! The start of the effective halo region on every DE. The default
! setting is {\tt ESMF\_STARTREGION\_EXCLUSIVE}, rendering all non-exclusive
! elements potential halo destination elements.
! See section \ref{const:startregion} for a complete list of
! valid settings.
! \end{sloppypar}
! \item[{[haloLDepth]}]
! This vector specifies the lower corner of the effective halo
! region with respect to the lower corner of {\tt startregion}.
! The size of {\tt haloLDepth} must equal the number of distributed Array
! dimensions.
! \item[{[haloUDepth]}]
! This vector specifies the upper corner of the effective halo
! region with respect to the upper corner of {\tt startregion}.
! The size of {\tt haloUDepth} must equal the number of distributed Array
! dimensions.
! \item [{[rc]}]
! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
! \end{description}
!
!EOP
!------------------------------------------------------------------------------
integer :: localrc ! local return code
type(ESMF_StartRegion_Flag) :: opt_startregion ! helper variable
type(ESMF_InterArray) :: haloLDepthArg ! helper variable
type(ESMF_InterArray) :: haloUDepthArg ! helper variable
! initialize return code; assume routine not implemented
localrc = ESMF_RC_NOT_IMPL
if (present(rc)) rc = ESMF_RC_NOT_IMPL
! Check init status of arguments
ESMF_INIT_CHECK_DEEP_SHORT(ESMF_ArrayBundleGetInit, arraybundle, rc)
! Set default flags
opt_startregion = ESMF_STARTREGION_EXCLUSIVE
if (present(startregion)) opt_startregion = startregion
! Deal with (optional) array arguments
haloLDepthArg = ESMF_InterArrayCreate(haloLDepth, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
haloUDepthArg = ESMF_InterArrayCreate(haloUDepth, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Call into the C++ interface, which will sort out optional arguments
call c_ESMC_ArrayBundleHaloStore(arraybundle, routehandle, &
opt_startregion, haloLDepthArg, haloUDepthArg, localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! garbage collection
call ESMF_InterArrayDestroy(haloLDepthArg, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
call ESMF_InterArrayDestroy(haloUDepthArg, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Mark routehandle object as being created
call ESMF_RouteHandleSetInitCreated(routehandle, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! return successfully
if (present(rc)) rc = ESMF_SUCCESS
end subroutine ESMF_ArrayBundleHaloStore