D.6.2 Finalize_Distributed_Vector Procedure

The main documentation of the Finalize_Distributed_Vector Procedure contains additional explanation of this code listing.

  subroutine Finalize_Distributed_Vector (DV, status)

    ! Use associations.

    use Caesar_Flags_Module, only: uninitialized_flag

    ! Input/Output variable.

    ! Distributed_Vector to be finalized.
    type(Distributed_Vector_type), intent(inout) :: DV

    ! Output variable.

    type(Status_type), intent(out), optional :: status   ! Exit status.

    ! Internal variables.

    type(Status_type), dimension(8) :: deallocate_status ! Deallocation Status.
    type(Status_type) :: consolidated_status             ! Consolidated Status.

    !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    ! Verify requirements.

    VERIFY(Valid_State(DV),7) ! DV is valid.

    ! Unset initialization flag.

    DV%Initialized = uninitialized_flag

    ! Set deallocation status.

    call Initialize (deallocate_status)
    call Initialize (consolidated_status)

    ! Finalize internals.

    NULLIFY(DV%Structure)
    select case (DV%Dimensionality)
    case (1)
      call Finalize (DV%Values1, deallocate_status(1))
    case (2)
      call Finalize (DV%Values2, deallocate_status(1))
    case (3)
      call Finalize (DV%Values3, deallocate_status(1))
    case (4)
      call Finalize (DV%Values4, deallocate_status(1))
    !case (-1)
    !  call Finalize (DV%ValuesRR, deallocate_status(1))
    end select
    call Finalize (DV%Dimensionality, deallocate_status(2))
    call Finalize (DV%Dimensions,     deallocate_status(3))
    call Finalize (DV%NValues_PE,     deallocate_status(4))
    call Finalize (DV%NValues_Total,  deallocate_status(5))
    call Finalize (DV%NValues_Vector, deallocate_status(6))
    call Finalize (DV%Name,           deallocate_status(7))
    call Finalize (DV%Version,        deallocate_status(8))

    ! Process status variables.

    consolidated_status = deallocate_status
    if (PRESENT(status)) then
      WARN_IF(Error(consolidated_status), 5)
      status = consolidated_status
    else
      VERIFY(Normal(consolidated_status), 5)
    end if
    call Finalize (consolidated_status)
    call Finalize (deallocate_status)

    ! Verify guarantees.

    VERIFY(.not.Valid_State(DV),7) ! DV is not valid.

    return
  end subroutine Finalize_Distributed_Vector



Michael L. Hall