D.4.2 Finalize_Data_Index Procedure

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

  subroutine Finalize_Data_Index (Index, status)

    ! Use associations.

    use Caesar_Flags_Module, only: uninitialized_flag

    ! Input/Output variable.

    ! Data_Index to be finalized.
    type(Data_Index_type), intent(inout) :: Index

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

    ! Unset initialization flag.

    Index%Initialized = uninitialized_flag

    ! Set deallocation status.

    call Initialize (deallocate_status)
    call Initialize (consolidated_status)

    ! Finalize internals.


    select case (Index%Dimensionality)
    case (1)
      call Finalize (Index%Index1,  deallocate_status(1))
    case (2)                        
      call Finalize (Index%Index2,  deallocate_status(1))
    !case (-1)                      
    !  call Finalize (Index%IndexRR, deallocate_status(1))
    end select

    call Finalize (Index%Dimensionality, deallocate_status(2))
    call Finalize (Index%NOff_PE,        deallocate_status(3))
    call Finalize (Index%Off_PE_Index,   deallocate_status(4))
    if (Initialized(Index%Off_PE_Trace)) then
      call Finalize (Index%Off_PE_Trace, deallocate_status(5))
    end if
    call Finalize (Index%Trace,          deallocate_status(6))

    ! Process status variables.

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

    ! Verify guarantees.

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

  end subroutine Finalize_Data_Index

Michael L. Hall