subroutine ESMF_VMGetCurrent(vm, keywordEnforcer, rc)
!
! !ARGUMENTS:
type(ESMF_VM), intent(out) :: vm
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
integer, intent(out), optional :: rc
!
! !STATUS:
! \begin{itemize}
! \item\apiStatusCompatibleVersion{5.2.0r}
! \end{itemize}
!
! !DESCRIPTION:
! \begin{sloppypar}
! Get the {\tt ESMF\_VM} object of the current execution context. Calling
! {\tt ESMF\_VMGetCurrent()} within an ESMF Component, will return the
! same VM object as
! {\tt ESMF\_GridCompGet(..., vm=vm, ...)} or
! {\tt ESMF\_CplCompGet(..., vm=vm, ...)}.
! \end{sloppypar}
!
! The main purpose of providing {\tt ESMF\_VMGetCurrent()} is to simplify ESMF
! adoption in legacy code. Specifically, code that uses {\tt MPI\_COMM\_WORLD}
! deep within its calling tree can easily be modified to use the correct MPI
! communicator of the current ESMF execution context. The advantage is that
! these modifications are very local, and do not require wide reaching
! interface changes in the legacy code to pass down the ESMF component object,
! or the MPI communicator.
!
! The use of {\tt ESMF\_VMGetCurrent()} is strongly discouraged in newly
! written Component code. Instead, the ESMF Component object should be used as
! the appropriate container of ESMF context information. This object should be
! passed between the subroutines of a Component, and be queried for any
! Component specific information.
!
! Outside of a Component context, i.e. within the driver context, the call
! to {\tt ESMF\_VMGetCurrent()} is identical to {\tt ESMF\_VMGetGlobal()}.
!
! The arguments are:
! \begin{description}
! \item[vm]
! Upon return this holds the {\tt ESMF\_VM} object of the current execution
! context.
! \item[{[rc]}]
! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
! \end{description}
!
!EOP
!------------------------------------------------------------------------------
integer :: localrc ! local return code
! initialize return code; assume routine not implemented
localrc = ESMF_RC_NOT_IMPL
if (present(rc)) rc = ESMF_RC_NOT_IMPL
! Call into the C++ interface.
call c_ESMC_VMGetCurrent(vm, localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Set init code
ESMF_INIT_SET_CREATED(vm)
! return successfully
if (present(rc)) rc = ESMF_SUCCESS
end subroutine ESMF_VMGetCurrent