f_esmf_fbundlecollectgarbage Subroutine

subroutine f_esmf_fbundlecollectgarbage(fb, rc)

Uses

Arguments

Type IntentOptional Attributes Name
type(ESMF_FieldBundle) :: fb
integer, intent(out) :: rc

Source Code

  subroutine f_esmf_fbundlecollectgarbage(fb, rc)
#undef  ESMF_METHOD
#define ESMF_METHOD "f_esmf_fbundlecollectgarbage"
    use ESMF_UtilTypesMod
    use ESMF_BaseMod
    use ESMF_LogErrMod
    use ESMF_FieldBundleMod

    implicit none

    type(ESMF_FieldBundle):: fb
    integer, intent(out)  :: rc
  
    integer :: localrc
  
    ! initialize return code; assume routine not implemented
    localrc = ESMF_RC_NOT_IMPL
    rc = ESMF_RC_NOT_IMPL

    !print *, "collecting FieldBundle garbage"
  
    if (associated(fb%this)) then
      ! destruct internal data allocations
      call ESMF_FieldBundleDestruct(fb%this, localrc)
      if (ESMF_LogFoundError(localrc, &
        ESMF_ERR_PASSTHRU, &
        ESMF_CONTEXT, &
        rcToReturn=rc)) return
      ! deallocate actual FieldBundleType allocation      
      deallocate(fb%this, stat=localrc)
      if (ESMF_LogFoundAllocError(localrc, msg="Deallocating FieldBundle", &
        ESMF_CONTEXT, &
        rcToReturn=rc)) return
    endif
    nullify(fb%this)

    ! return successfully
    rc = ESMF_SUCCESS

  end subroutine f_esmf_fbundlecollectgarbage