D.8.2 Finalize_Collected_Array Procedure

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

  subroutine Finalize_Collected_Array (CA, status)

    ! Use associations.

    use Caesar_Flags_Module, only: uninitialized_flag

    ! Input/Output variable.

    ! Collected_Array to be finalized.
    type(Collected_Array_type), intent(inout) :: CA

    ! Output variable.

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

    ! Internal variables.

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

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

    ! Verify requirements.

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

    ! Unset initialization flag.

    CA%Initialized = uninitialized_flag

    ! Set deallocation status.

    call Initialize (deallocate_status)
    call Initialize (consolidated_status)

    ! Finalize internals.

    NULLIFY(CA%One_Structure)
    NULLIFY(CA%Many_Structure)
    NULLIFY(CA%Many_of_One_Index)

    select case (CA%A_Dimensionality)
    case (1)
      call Finalize (CA%Values1, deallocate_status(1))
    case (2)            
      call Finalize (CA%Values2, deallocate_status(1))
    case (3)            
      call Finalize (CA%Values3, deallocate_status(1))
    case (4)            
      call Finalize (CA%Values4, deallocate_status(1))
    case (5)            
      call Finalize (CA%Values5, deallocate_status(1))
    !case (-1)
    !  call Finalize (CA%ValuesRR, deallocate_status(1))
    end select
    call Finalize (CA%A_Dimensionality, deallocate_status(2))
    call Finalize (CA%Dimensionality,   deallocate_status(3))
    call Finalize (CA%Dimensions,       deallocate_status(4))
    call Finalize (CA%Name,             deallocate_status(5))
    call Finalize (CA%Version,          deallocate_status(6))

    ! 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(CA),7) ! CA is not valid.

    return
  end subroutine Finalize_Collected_Array



Michael L. Hall