D.1.2 Finalize_Trace Procedure

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

  subroutine Finalize_Trace (Trace, status)

    ! Input/Output variable.

    ! Trace to be finalized.
    type(Trace_type), intent(inout) :: Trace

    ! Output variable.

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

    ! Internal variables.

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

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

    ! Verify requirements.

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

    ! Unset initialization flag.

    call Finalize (Trace%Initialized)

    ! Set deallocation status.

    call Initialize (deallocate_status)
    call Initialize (consolidated_status)

    ! PGSLib Trace deallocation.
    
    ifdef([USE_PGSLIB],[
      call PGSLib_Deallocate_Trace (Trace%Trace)
    ])

    ! Finalize internals.

    select case (Trace%Dimensionality)
    case (1)
      call Finalize (Trace%Index1,  deallocate_status(1))
      call Finalize (Trace%Mask1,   deallocate_status(2))
    case (2)                        
      call Finalize (Trace%Index2,  deallocate_status(1))
      call Finalize (Trace%Mask2,   deallocate_status(2))
    end select

    call Finalize (Trace%Dimensionality, deallocate_status(3))

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

    return
  end subroutine Finalize_Trace



Michael L. Hall