The main documentation of the Output_Statistics Procedure contains additional explanation of this code listing.
subroutine Output_Statistics (Statistics, Global, Verbose, Unit) use Caesar_Numbers_Module, only: ten, zero ! Input variables. type(Statistics_type), intent(inout) :: Statistics ! Variable to be output. type(logical), intent(in), optional :: Global ! Global flag. type(logical), intent(in), optional :: Verbose ! Verbosity flag. type(integer), intent(in), optional :: Unit ! Output unit. ! Internal variables. type(logical) :: A_Global ! Actual global flag. type(logical) :: A_Verbose ! Actual verbosity flag. type(integer) :: A_Unit ! Actual output unit. type(integer) :: Stat_Count ! Statistics count. type(real) :: Stat_Geometric_Mean ! Statistics geom mean. type(real) :: Stat_Harmonic_Mean ! Statistics harmonic mean. type(real) :: Stat_Maximum ! Statistics maximum. type(real) :: Stat_Mean ! Statistics mean. type(real) :: Stat_Minimum ! Statistics minimum. type(character,80) :: Stat_Name ! Statistics name. type(real) :: Stat_Standard_Deviation ! Statistics std deviation. !~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ! Verify requirements. VERIFY(Valid_State(Statistics),5) ! Statistics is valid. ! Set unit number. if (PRESENT(Unit)) then A_Unit = Unit else A_Unit = 6 end if ! Set global flag. if (PRESENT(Global)) then A_Global = Global else A_Global = .false. end if ! Set verbosity flag. if (PRESENT(Verbose)) then A_Verbose = Verbose else A_Verbose = .false. end if ! Do a global update if called for. if (A_Global) then call Update_Global (Statistics) end if ! These are evaluated on all PEs -- NOT inside an IO PE block -- because ! they contain validity checks on Statistics and thus require global ! communication. Stat_Count = Count(Statistics, A_Global) Stat_Name = Name(Statistics) Stat_Maximum = Maximum(Statistics, A_Global) Stat_Minimum = Minimum(Statistics, A_Global) Stat_Mean = Mean(Statistics, A_Global) Stat_Standard_Deviation = Standard_Deviation(Statistics, A_Global) if ((.not. A_Global .and. Statistics%PE_Totally_Positive) .or. & (A_Global .and. Statistics%Global_Totally_Positive)) then Stat_Geometric_Mean = Geometric_Mean(Statistics, A_Global) Stat_Harmonic_Mean = Harmonic_Mean(Statistics, A_Global) end if ! Output Statistics Info. if (this_is_IO_PE) then if (A_Verbose) then write (A_Unit,100) TRIM(Stat_Name), ':' if (A_Global) then write (A_Unit,101) '*Global values*' else write (A_Unit,101) '*Values for IO PE*' end if write (A_Unit,101) 'Number of values = ', Stat_Count write (A_Unit,102) & 'Range = [[', & Stat_Minimum, ', ', & Stat_Maximum, ' ]]' if (Stat_Mean /= zero .and. & ABS(Stat_Standard_Deviation / Stat_Mean) <= ten) then write (A_Unit,103) & 'Arithmetic Mean = ', & Stat_Mean, ' +/- ', & Stat_Standard_Deviation, ' ( +/- ', & Stat_Standard_Deviation / & Stat_Mean * 100.d0, '% )' else write (A_Unit,103) & 'Arithmetic Mean = ', & Stat_Mean, ' +/- ', & Stat_Standard_Deviation end if if ((.not. A_Global .and. Statistics%PE_Totally_Positive) .or. & (A_Global .and. Statistics%Global_Totally_Positive)) then write (A_Unit,103) & 'Geometric Mean = ', Stat_Geometric_Mean write (A_Unit,103) & 'Harmonic Mean = ', Stat_Harmonic_Mean end if else if (Stat_Mean /= zero .and. & ABS(Stat_Standard_Deviation / Stat_Mean) <= ten) then write (A_Unit,104) & TRIM(Stat_Name), ' = ', & Stat_Mean, ' +/- ', & Stat_Standard_Deviation, ' ( +/- ', & Stat_Standard_Deviation / & Stat_Mean * 100.d0, '% )' else write (A_Unit,104) & TRIM(Stat_Name), ' = ', & Stat_Mean, ' +/- ', & Stat_Standard_Deviation end if end if end if ! Format statements. 100 format (a,a) 101 format (2x,a,i7) 102 format (2x,a,1pe14.7,a,1pe15.7,a) 103 format (2x,a,1pe15.7,:,a,1pe13.7,a,0pf8.4,a) 104 format (a,a,1pe15.7,a,1pe13.7,a,0pf7.4,a) ! Verify guarantees - none. return end subroutine Output_Statistics