E.2.2 Finalize_Statistics Procedure

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

  subroutine Finalize_Statistics (Statistics, status)

    ! Use associations.

    use Caesar_Flags_Module, only: uninitialized_flag

    ! Input/Output variable.

    ! Statistics to be finalized.
    type(Statistics_type), intent(inout) :: Statistics  

    ! Output variables.

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

    ! Internal variables.

    type(Status_type), dimension(26) :: deallocate_status ! Deallocat'n Status.
    type(Status_type) :: consolidated_status             ! Consolidated Status.

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

    ! Verify requirements.

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

    ! Unset initialization flag.

    Statistics%Initialized = uninitialized_flag

    ! Deallocations and finalizations.

    ! Set deallocation status.

    call Initialize (deallocate_status)
    call Initialize (consolidated_status)

    ! Finalize internals.

    call Finalize (Statistics%PE_Count, deallocate_status(1))
    call Finalize (Statistics%PE_Arithmetic_Mean, deallocate_status(2))
    call Finalize (Statistics%PE_Sum, deallocate_status(3))
    call Finalize (Statistics%PE_Geometric_Mean, deallocate_status(4))
    call Finalize (Statistics%PE_Log_Sum, deallocate_status(5))
    call Finalize (Statistics%PE_Harmonic_Mean, deallocate_status(6))
    call Finalize (Statistics%PE_Reciprocal_Sum, deallocate_status(7))
    call Finalize (Statistics%PE_Standard_Deviation, deallocate_status(8))
    call Finalize (Statistics%PE_Squared_Sum, deallocate_status(9))
    call Finalize (Statistics%PE_Maximum, deallocate_status(10))
    call Finalize (Statistics%PE_Minimum, deallocate_status(11))
    call Finalize (Statistics%PE_Totally_Positive, deallocate_status(12))
    call Finalize (Statistics%Global_Count, deallocate_status(13))
    call Finalize (Statistics%Global_Arithmetic_Mean, deallocate_status(14))
    call Finalize (Statistics%Global_Sum, deallocate_status(15))
    call Finalize (Statistics%Global_Geometric_Mean, deallocate_status(16))
    call Finalize (Statistics%Global_Log_Sum, deallocate_status(17))
    call Finalize (Statistics%Global_Harmonic_Mean, deallocate_status(18))
    call Finalize (Statistics%Global_Reciprocal_Sum, deallocate_status(19))
    call Finalize (Statistics%Global_Standard_Deviation, deallocate_status(20))
    call Finalize (Statistics%Global_Squared_Sum, deallocate_status(21))
    call Finalize (Statistics%Global_Maximum, deallocate_status(22))
    call Finalize (Statistics%Global_Minimum, deallocate_status(23))
    call Finalize (Statistics%Global_Updated, deallocate_status(24))
    call Finalize (Statistics%Global_Totally_Positive, deallocate_status(25))
    call Finalize (Statistics%Name, deallocate_status(26))

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

    return
  end subroutine Finalize_Statistics



Michael L. Hall