deallocate_array Module Subroutine

recursive module subroutine deallocate_array(this, keep_shape)

Deallocate array

Arguments

Type IntentOptional Attributes Name
class(array_type), intent(inout) :: this

Instance of the array type

logical, intent(in), optional :: keep_shape

Boolean whether to keep shape


Source Code

  recursive module subroutine deallocate_array(this, keep_shape)
    !! Deallocate array
    implicit none

    ! Arguments
    class(array_type), intent(inout) :: this
    !! Instance of the array type
    logical, intent(in), optional :: keep_shape
    !! Boolean whether to keep shape

    ! Local variables
    logical :: keep_shape_
    !! Boolean whether to keep shape

    keep_shape_ = .false.
    if(present(keep_shape)) keep_shape_ = keep_shape

    ! Deallocate all allocatable arrays
    if(allocated(this%val)) deallocate(this%val)
    if(allocated(this%indices)) deallocate(this%indices)
    if(allocated(this%adj_ja)) deallocate(this%adj_ja)
    if(allocated(this%mask)) deallocate(this%mask)
    if(allocated(this%direction)) deallocate(this%direction)
    if(.not.keep_shape_)then
       if(allocated(this%shape)) deallocate(this%shape)
    end if

    this%allocated = .false.
    this%size = 0
    ! write(*,*) "deallocated array loc: ", loc(this)

  end subroutine deallocate_array