The main documentation of the Update_Global_Statistics Procedure contains additional explanation of this code listing.
subroutine Update_Global_Statistics (Statistics)
! Use association information.
use Caesar_Numbers_Module, only: one
! Input/Output variables.
type(Statistics_type), intent(inout) :: Statistics ! Statistics object.
! Internal variables.
type(real) :: N ! Real version of Global_Count.
!~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
! Verify requirements.
VERIFY(Valid_State(Statistics),5) ! Statistics is valid.
! Check to see if the update has already been done.
if (Statistics%Global_Updated) return
! Increment sums and count.
Statistics%Global_Count = Global_Sum(Statistics%PE_Count)
Statistics%Global_Sum = Global_Sum(Statistics%PE_Sum)
Statistics%Global_Log_Sum = Global_Sum(Statistics%PE_Log_Sum)
Statistics%Global_Reciprocal_Sum = &
Global_Sum(Statistics%PE_Reciprocal_Sum)
Statistics%Global_Squared_Sum = &
Global_Sum(Statistics%PE_Squared_Sum)
Statistics%Global_Totally_Positive = &
Global_ALL(Statistics%PE_Totally_Positive)
! Update statistics.
N = changetype(real,Statistics%Global_Count)
Statistics%Global_Arithmetic_Mean = Statistics%Global_Sum / N
if (Statistics%Global_Totally_Positive) then
Statistics%Global_Geometric_Mean = EXP(Statistics%Global_Log_Sum / N)
Statistics%Global_Harmonic_Mean = N / Statistics%Global_Reciprocal_Sum
end if
if (Statistics%Global_Count > 1) then
Statistics%Global_Standard_Deviation = &
SQRT( (Statistics%Global_Squared_Sum &
- N * Statistics%Global_Arithmetic_Mean**2) &
/ (N - one) )
end if
! Update extrema.
Statistics%Global_Maximum = Global_MaxVal(Statistics%PE_Maximum)
Statistics%Global_Minimum = Global_MinVal(Statistics%PE_Minimum)
! Set update flag.
Statistics%Global_Updated = .true.
! Verify guarantees.
VERIFY(Valid_State(Statistics),5) ! Statistics is valid.
! Means are correct.
VERIFY(VeryClose(Statistics%Global_Arithmetic_Mean, dnl
Statistics%Global_Sum/N),5)
if (Statistics%Global_Totally_Positive) then
VERIFY(VeryClose(Statistics%Global_Geometric_Mean, dnl
EXP(Statistics%Global_Log_Sum/N)),5)
VERIFY(VeryClose(Statistics%Global_Harmonic_Mean, dnl
N/Statistics%Global_Reciprocal_Sum),5)
end if
return
end subroutine Update_Global_Statistics