f_esmf_compcollectgarbage2 Subroutine

recursive subroutine f_esmf_compcollectgarbage2(comp, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_CWrap) :: comp
integer, intent(out) :: rc

Source Code

recursive subroutine f_esmf_compcollectgarbage2(comp, rc)
  use ESMF_UtilTypesMod
  use ESMF_BaseMod
  use ESMF_LogErrMod
  use ESMF_CompMod
  
  implicit none

  type(ESMF_CWrap)     :: comp
  integer, intent(out) :: rc

  integer :: localrc
  integer :: timeout
  logical :: timeoutFlag

  ! initialize return code; assume routine not implemented
  localrc = ESMF_RC_NOT_IMPL
  rc = ESMF_RC_NOT_IMPL

  !print *, "collecting Component garbage #2"

  ! destruct internal data allocations and perform full shut down, making this
  ! call collective on some MPI implementations
  timeout = 10  ! allow for 10s timeout
  ! calling with 'timeoutFlag' prevents timeout to propagate as error condition
  call ESMF_CompDestruct(comp%compp, interCompComm=.false., &
    fullShutdown=.true., timeout=timeout, timeoutFlag=timeoutFlag, rc=localrc)
  if (ESMF_LogFoundError(localrc, &
    ESMF_ERR_PASSTHRU, &
    ESMF_CONTEXT, rcToReturn=rc)) return

  ! deallocate actual CompClass allocation      
  if (associated(comp%compp)) then
    deallocate(comp%compp, stat=localrc)
    if (ESMF_LogFoundAllocError(localrc, msg="Deallocating Comp", &
      ESMF_CONTEXT, rcToReturn=rc)) return
  endif
  nullify(comp%compp)

  ! return successfully  
  rc = ESMF_SUCCESS

end subroutine f_esmf_compcollectgarbage2