ESMF_ConfigDestroy Subroutine

public subroutine ESMF_ConfigDestroy(config, keywordEnforcer, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_Config), intent(inout) :: config
type(ESMF_KeywordEnforcer), optional :: keywordEnforcer
integer, intent(out), optional :: rc

Source Code

    subroutine ESMF_ConfigDestroy(config, keywordEnforcer, rc)

! !ARGUMENTS:
      type(ESMF_Config), intent(inout)          :: config
type(ESMF_KeywordEnforcer), optional:: keywordEnforcer ! must use keywords below
      integer,           intent(out),  optional :: rc
!
!
! !STATUS:
! \begin{itemize}
! \item\apiStatusCompatibleVersion{5.2.0r}
! \end{itemize}
!
! !DESCRIPTION: 
!    Destroys the {\tt config} object.
!
!   The arguments are:
!   \begin{description}
!   \item [config]
!     Already created {\tt ESMF\_Config} object.
!   \item [{[rc]}]
!     Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
!   \end{description}
!
!EOP -------------------------------------------------------------------
      integer :: i, localrc
      integer :: memstat

      ! Initialize return code; assume routine not implemented
      if (present(rc)) rc = ESMF_RC_NOT_IMPL

      !check variables
      ESMF_INIT_CHECK_DEEP(ESMF_ConfigGetInit,config,rc)

      memstat = 0

      ! TODO: Absoft 9/Jazz bug necessitates this separate deallocate statement
      ! before the other (must be in reverse order of allocation)
      do, i=1, size (config%cptr%attr_used)
        if (associated (config%cptr%attr_used(i)%label)) then
          deallocate(config%cptr%attr_used(i)%label, stat=memstat)
          if (ESMF_LogFoundDeallocError(memstat, msg="Deallocating local buffer 3", &
                                     ESMF_CONTEXT, rcToReturn=rc)) return
        end if
      end do

      deallocate(config%cptr%attr_used, stat=memstat)
      if (ESMF_LogFoundDeallocError(memstat, msg="Deallocating local buffer 2", &
        ESMF_CONTEXT, rcToReturn=rc)) return

      deallocate(config%cptr%buffer, config%cptr%this_line, stat = memstat)
      if (ESMF_LogFoundDeallocError(memstat, msg="Deallocating local buffer 1", &
        ESMF_CONTEXT, rcToReturn=rc)) return

      if (config%cptr%hconfig_owner) then
        call ESMF_HConfigDestroy(config%cptr%hconfig, rc=localrc)
        if (ESMF_LogFoundError(localrc, ESMF_ERR_PASSTHRU,  &
          ESMF_CONTEXT, rcToReturn=rc)) return
      endif

      deallocate(config%cptr, stat = memstat)
      if (ESMF_LogFoundDeallocError(memstat, msg="Deallocating config type", &
                                     ESMF_CONTEXT, rcToReturn=rc)) return
      nullify(config%cptr)

      ! return successfully
      if (present(rc)) rc = ESMF_SUCCESS

      ESMF_INIT_SET_DELETED(config)

     end subroutine ESMF_ConfigDestroy