ESMF_InterArrayDestroy Subroutine

public recursive subroutine ESMF_InterArrayDestroy(array, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_InterArray), intent(inout) :: array
integer, intent(out), optional :: rc

Source Code

  recursive subroutine ESMF_InterArrayDestroy(array, rc)
!
! !ARGUMENTS:
    type(ESMF_InterArray), intent(inout)         :: array
    integer,                 intent(out), optional :: rc
!
!
! !DESCRIPTION:
!   Destroy an {\tt ESMF\_InterArray} object. Deallocate Fortran arrays
!   whose ownership was transferred to the InterArray object.
!
!   The arguments are:
!   \begin{description}
!   \item[array]
!     {\tt ESMF\_InterArray} object.
!   \item[{[rc]}]
!     Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
!   \end{description}
!
!EOPI
!------------------------------------------------------------------------------
    integer                 :: localrc      ! local return code
    integer                 :: stat         ! Fortran return code

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

    ! deallocate Fortran arrays if ownership was transferred
    if (array%owner) then
      if (associated(array%farray1D)) then
        deallocate(array%farray1D, stat=stat)
        if (ESMF_LogFoundDeallocError(stat, msg="deallocating array%farray1D", &
          ESMF_CONTEXT)) &
          return  ! bail out
      endif
      if (associated(array%farray2D)) then
        deallocate(array%farray2D, stat=stat)
        if (ESMF_LogFoundDeallocError(stat, msg="deallocating array%farray2D", &
          ESMF_CONTEXT)) &
          return  ! bail out
      endif
      if (associated(array%farray3D)) then
        deallocate(array%farray3D, stat=stat)
        if (ESMF_LogFoundDeallocError(stat, msg="deallocating array%farray3D", &
          ESMF_CONTEXT)) &
          return  ! bail out
      endif
      if (associated(array%farray1DI8)) then
        deallocate(array%farray1DI8, stat=stat)
        if (ESMF_LogFoundDeallocError(stat, msg="deallocating array%farray1DI8", &
          ESMF_CONTEXT)) &
          return  ! bail out
      endif
      if (associated(array%farray2DI8)) then
        deallocate(array%farray2DI8, stat=stat)
        if (ESMF_LogFoundDeallocError(stat, msg="deallocating array%farray2DI8", &
          ESMF_CONTEXT)) &
          return  ! bail out
      endif
      if (associated(array%farray3DI8)) then
        deallocate(array%farray3DI8, stat=stat)
        if (ESMF_LogFoundDeallocError(stat, msg="deallocating array%farray3DI8", &
          ESMF_CONTEXT)) &
          return  ! bail out
      endif

      if (associated(array%farray1DR8)) then
        deallocate(array%farray1DR8, stat=stat)
        if (ESMF_LogFoundDeallocError(stat, msg="deallocating array%farray1DR8", &
          ESMF_CONTEXT)) &
          return  ! bail out
      endif
      if (associated(array%farray2DR8)) then
        deallocate(array%farray2DR8, stat=stat)
        if (ESMF_LogFoundDeallocError(stat, msg="deallocating array%farray2DR8", &
          ESMF_CONTEXT)) &
          return  ! bail out
      endif
      if (associated(array%farray3DR8)) then
        deallocate(array%farray3DR8, stat=stat)
        if (ESMF_LogFoundDeallocError(stat, msg="deallocating array%farray3DR8", &
          ESMF_CONTEXT)) &
          return  ! bail out
      endif
    endif

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

  end subroutine ESMF_InterArrayDestroy