subroutine ESMF_ContainerGarbageGetSIL(container, garbageList, &
keywordEnforcer, garbageCount, rc)
!
! !ARGUMENTS:
type(ESMF_Container), intent(in) :: container
type(ESMF_StateItemWrap), pointer :: garbageList(:)
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
integer, intent(out), optional :: garbageCount
integer, intent(out), optional :: rc
!
! !DESCRIPTION:
! Get items from a {\tt ESMF\_Container} object.
!
! The arguments are:
! \begin{description}
! \item[container]
! {\tt ESMF\_Container} object to be queried.
! \item[garbageList]
! List of objects in {\tt container} garbage. This argument has the pointer
! attribute. If the argument comes into this call associated the memory
! allocation is not changed. Instead the size of the memory allocation is
! checked against the total number of elements in the container gargbage,
! and if sufficiently sized the container garbage elements are returned in
! the provided memory allocation. If the argument comes into this call
! unassociated, memory will be allocated internally and filled with the
! container garbage elements. In the latter case the size of the returned
! {\tt garbageList} will be identical to the number of items in the
! container garbage - even if that number is zero.
! In both cases the returned {\tt garbageList} will be associated. It is the
! responsibility of the caller to deallocate the memory.
! \item[{[garbageCount]}]
! Number of objects in {\tt container} garbage.
! \item[{[rc]}]
! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
! \end{description}
!
!EOPI
!------------------------------------------------------------------------------
integer :: localrc ! local return code
integer :: stat
integer :: i, garbageC
type(ESMF_Pointer) :: vector
type(ESMF_StateItemWrap) :: siw
! Initialize return code; assume failure until success is certain
localrc = ESMF_RC_NOT_IMPL
if (present(rc)) rc = ESMF_RC_NOT_IMPL
! Check init status of arguments
ESMF_INIT_CHECK_DEEP_SHORT(ESMF_ContainerGetInit, container, rc)
! Call into the C++ interface
call c_ESMC_ContainerGarbageCount(container, garbageC, localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
if (associated(garbageList)) then
if (size(garbageList) < garbageC) then
call ESMF_LogSetError(rcToCheck=ESMF_RC_ARG_SIZE, &
msg="garbageList is too small", &
ESMF_CONTEXT, rcToReturn=rc)
return ! bail out
endif
else
allocate(garbageList(garbageC), stat=stat)
if (ESMF_LogFoundAllocError(stat, msg= "allocating garbageList", &
ESMF_CONTEXT, rcToReturn=rc)) return ! bail out
endif
! Call into the C++ interface to set up the vector on the C++ side
call c_ESMC_ContainerGarbageGet(container, vector, localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
do i=0, garbageC-1 ! C-style indexing, zero-based
! Call into the C++ interface to get item from vector
call c_ESMC_ContainerGetVSI(container, vector, i, siw, localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
garbageList(i+1) = siw ! makes object passing robust
enddo
! release vector here
! Call into the C++ interface to release the vector on the C++ side
call c_ESMC_ContainerReleaseVector(container, vector, localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
if (present(garbageCount)) then
garbageCount = garbageC
endif
! Return successfully
if (present(rc)) rc = ESMF_SUCCESS
end subroutine ESMF_ContainerGarbageGetSIL