f_esmf_statecollectgarbage Subroutine

subroutine f_esmf_statecollectgarbage(state, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_State) :: state
integer, intent(out) :: rc

Source Code

  subroutine f_esmf_statecollectgarbage(state, rc)
#undef  ESMF_METHOD
#define ESMF_METHOD "f_esmf_statecollectgarbage"
    use ESMF_UtilTypesMod
    use ESMF_BaseMod
    use ESMF_LogErrMod
    use ESMF_StateTypesMod
    use ESMF_StateMod
    
    implicit none
    
    type(ESMF_State)     :: state
    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 State garbage"

    if (associated(state%statep)) then
      ! destruct internal data allocations
      call ESMF_StateDestruct(state%statep, rc=localrc)
      if (ESMF_LogFoundError(localrc, &
        ESMF_ERR_PASSTHRU, &
        ESMF_CONTEXT, &
        rcToReturn=rc)) return
      ! deallocate actual StateClass allocation      
      deallocate(state%statep, stat=localrc)
      localrc = merge (ESMF_SUCCESS, ESMF_RC_MEM_DEALLOCATE, localrc == 0)
      if (ESMF_LogFoundAllocError(localrc, msg="Deallocating State", &
        ESMF_CONTEXT, &
        rcToReturn=rc)) return
    endif
    nullify(state%statep)

    ! return successfully  
    rc = ESMF_SUCCESS

  end subroutine f_esmf_statecollectgarbage