E.2.1 Initialize_Statistics Procedure

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

  subroutine Initialize_Statistics (Statistics, Name, status)

    ! Use association information.

    use Caesar_Flags_Module, only: initialized_flag
    use Caesar_Numbers_Module, only: zero

    ! Input variables.

    type(character,*), intent(in) :: Name  ! Statistics name.

    ! Output variables.

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

    ! Internal variables.

    type(Status_type), dimension(25) :: allocate_status ! Allocation Status.
    type(Status_type) :: consolidated_status            ! Consolidated Status.

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

    ! Verify requirements.

    VERIFY(.not.Valid_State(Statistics),5)  ! Statistics is not valid.
    VERIFY(Valid_State(Name),5)             ! Name is valid.

    ! Allocations and initializations.

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

    ! Set up internals.

    Statistics%Name = Name

    ! Make sure that initial values are correct.

    Statistics%PE_Count= 0
    Statistics%PE_Arithmetic_Mean = zero
    Statistics%PE_Sum = zero
    Statistics%PE_Geometric_Mean = zero
    Statistics%PE_Log_Sum = zero
    Statistics%PE_Harmonic_Mean = zero
    Statistics%PE_Reciprocal_Sum = zero
    Statistics%PE_Standard_Deviation = zero
    Statistics%PE_Squared_Sum = zero
    Statistics%PE_Maximum = zero
    Statistics%PE_Minimum = zero
    Statistics%PE_Totally_Positive = .true.
    Statistics%Global_Count= 0
    Statistics%Global_Arithmetic_Mean = zero
    Statistics%Global_Sum = zero
    Statistics%Global_Geometric_Mean = zero
    Statistics%Global_Log_Sum = zero
    Statistics%Global_Harmonic_Mean = zero
    Statistics%Global_Reciprocal_Sum = zero
    Statistics%Global_Standard_Deviation = zero
    Statistics%Global_Squared_Sum = zero
    Statistics%Global_Maximum = zero
    Statistics%Global_Minimum = zero
    Statistics%Global_Updated = .false.
    Statistics%Global_Totally_Positive = .true.

    ! Process status variables.

    consolidated_status = allocate_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 (allocate_status)

    ! Set initialization flag.

    Statistics%Initialized = initialized_flag

    ! Verify guarantees.

    VERIFY(Valid_State(Statistics),5)  ! Statistics is now valid.

    return
  end subroutine Initialize_Statistics



Michael L. Hall