subroutine ESMF_ContainerAddReplaceFL(container, itemList, keywordEnforcer, &
rc)
!
! !ARGUMENTS:
type(ESMF_Container), intent(inout) :: container
type(ESMF_Field), intent(in) :: itemList(:)
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
integer, intent(out), optional :: rc
!
! !DESCRIPTION:
! Elements in {\tt itemList} that do not match any items by name in
! {\tt container} are added to the Container. Elements in {\tt itemList}
! that match by name items in {\tt container} replaced those items.
!
! This method defines garbage as those elements in {\tt container} that
! were replaced as a consequence of this operation.
!
! The arguments are:
! \begin{description}
! \item[container]
! {\tt ESMF\_Container} object to be added to.
! \item[itemList]
! Elements to be added or used to replace items with.
! \item[{[rc]}]
! Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
! \end{description}
!
!EOPI
!------------------------------------------------------------------------------
integer :: localrc ! local return code
integer :: i, stat
character(len=ESMF_MAXSTR) :: name
type(ESMF_Pointer) :: vector
type(ESMF_Field) :: field
! 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)
do i=1, size(itemList)
! Check init status of arguments
ESMF_INIT_CHECK_DEEP_SHORT(ESMF_FieldGetInit, itemList(i), rc)
! Get the name of the Field
call ESMF_FieldGet(itemList(i), name=name, rc=localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
! Call into the C++ interface layer
field = itemList(i) ! makes object passing robust
call c_ESMC_ContainerAddReplace(container, trim(name), field, localrc)
if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU, &
ESMF_CONTEXT, rcToReturn=rc)) return
enddo
! Return successfully
if (present(rc)) rc = ESMF_SUCCESS
end subroutine ESMF_ContainerAddReplaceFL