The main documentation of the Add_Value_Statistics Procedure contains additional explanation of this code listing.
subroutine Add_Value_Statistics (Statistics, Value)
! Use association information.
use Caesar_Numbers_Module, only: one, zero
! Input variables.
type(real), intent(in) :: Value ! Value to be added.
! Input/Output variables.
type(Statistics_type), intent(inout) :: Statistics ! Statistics object.
! Internal variables.
type(real) :: N ! Real version of PE_Count.
!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
! Verify requirements.
VERIFY(Valid_State(Statistics),5) ! Statistics is valid.
VERIFY(Valid_State(Value),5) ! Value is valid.
! Global stats now out of date.
Statistics%Global_Updated = .false.
! Increment sums and count.
Statistics%PE_Count = Statistics%PE_Count + 1
Statistics%PE_Sum = Statistics%PE_Sum + Value
if (Value > zero) then
Statistics%PE_Log_Sum = Statistics%PE_Log_Sum + LOG(Value)
Statistics%PE_Reciprocal_Sum = Statistics%PE_Reciprocal_Sum + one/Value
else
Statistics%PE_Totally_Positive = .false.
end if
Statistics%PE_Squared_Sum = Statistics%PE_Squared_Sum + Value**2
! Update statistics.
N = changetype(real,Statistics%PE_Count)
Statistics%PE_Arithmetic_Mean = Statistics%PE_Sum / N
if (Statistics%PE_Totally_Positive) then
Statistics%PE_Geometric_Mean = EXP(Statistics%PE_Log_Sum / N)
Statistics%PE_Harmonic_Mean = N / Statistics%PE_Reciprocal_Sum
end if
if (Statistics%PE_Count > 1) then
Statistics%PE_Standard_Deviation = &
SQRT( (Statistics%PE_Squared_Sum &
- N * Statistics%PE_Arithmetic_Mean**2) &
/ (N - one) )
end if
! Update extrema.
if (Statistics%PE_Count > 1) then
Statistics%PE_Maximum = MAX(Statistics%PE_Maximum, Value)
Statistics%PE_Minimum = MIN(Statistics%PE_Minimum, Value)
else
Statistics%PE_Maximum = Value
Statistics%PE_Minimum = Value
end if
! Verify guarantees.
VERIFY(Valid_State(Statistics),5) ! Statistics is valid.
! Means are correct.
VERIFY(VeryClose(Statistics%PE_Arithmetic_Mean,Statistics%PE_Sum/N),5)
if (Statistics%PE_Totally_Positive) then
VERIFY(VeryClose(Statistics%PE_Geometric_Mean, dnl
EXP(Statistics%PE_Log_Sum/N)),5)
VERIFY(VeryClose(Statistics%PE_Harmonic_Mean, dnl
N/Statistics%PE_Reciprocal_Sum),5)
end if
return
end subroutine Add_Value_Statistics