From:	SCOVCB::GALVIN_FX    31-JAN-1989 09:04
To:	ARISIA::EVERHART
Subj:	

with text_io; use text_io;
with UTILITY; use UTILITY; 
with MATH; use MATH; 
with QUEUES;  
with SIMULATION; use SIMULATION; 
pragma ELABORATE (text_io, UTILITY, MATH, QUEUES, SIMULATION);

        ----------
package STATISTICS is
        ----------

-- Limited Private Data Structures :
-- ---------------------------------

   -- The following statistic types will access record types 
   -- consisting information pertaining to count statistics, 
   -- tally statistics, accumulate statistics, histogram 
   -- statistics, and plot statistics :

   type COUNT_STATISTIC is limited private;
   type TALLY_STATISTIC is limited private;
   type ACCUMULATE_STATISTIC is limited private;
   type HISTOGRAM_STATISTIC is limited private;
   type PLOT_STATISTIC is limited private;


-- Count Operators :
-- -----------------

   procedure CREATE_COUNT (COUNT_REF : in out COUNT_STATISTIC;
                           COUNT_TITLE : in string);
      -- This procedure CREATEs a new user-specified simulation
      -- COUNT statistic to be COLLECTed.  While the CREATEd
      -- statistic is internally identified by COUNT_REF, 
      -- COUNT_TITLE is used to identify the COUNT statistic 
      -- in output REPORTs.

   procedure COLLECT_COUNT (COUNT_REF: in out COUNT_STATISTIC);
      -- This procedure is used to COUNT the number of times that 
      -- the COUNT statistic specified by COUNT_REF is referenced

   procedure REPORT_COUNT (COUNT_REF : in COUNT_STATISTIC);
      -- This procedure allows the user to REPORT on an AdaSim
      -- statistic being COLLECTed.


-- Tally Operators :
-- -----------------

   procedure CREATE_TALLY (TALLY_REF : in out TALLY_STATISTIC;
                           TALLY_TITLE : in string);
      -- This procedure CREATEs a new user-specified simulation
      -- statistic to be COLLECTed, identified by TALLY_REF in 
      -- the system and identified by TALLY_TITLE in output 
      -- REPORTs generated.

   procedure COLLECT_TALLY (TALLY_REF : in out TALLY_STATISTIC;
                            TALLY_VALUE : in float);

   procedure COLLECT_TALLY (TALLY_REF : in out TALLY_STATISTIC;
                            TALLY_VALUE : in integer);

      -- Either of the two preceding procedures may be used to
      -- COLLECT the values (floating pt. or integer) pertaining
      -- to a statistic identified by TALLY_REF.

   procedure REPORT_TALLY (TALLY_REF : in TALLY_STATISTIC);
      -- This procedure allows the user to REPORT on an AdaSim
      -- statistic being COLLECTed, identified by TALLY_REF.


-- Accumulate Operators :
-- ----------------------

   procedure CREATE_ACCUMULATE 
             (ACCUMULATE_REF : in out ACCUMULATE_STATISTIC;
             ACCUMULATE_TITLE : in string);
      -- This procedure CREATEs a new user-specified simulation
      -- statistic to be COLLECTed, identified by ACCUMULATE_REF
      -- in the system, and identified by ACCUMULATE_TITLE in 
      -- output REPORTs generated.  

   procedure COLLECT_ACCUMULATE 
             (ACCUMULATE_REF : in out ACCUMULATE_STATISTIC;
             ACCUMULATE_VALUE : in integer);

   procedure COLLECT_ACCUMULATE 
             (ACCUMULATE_REF : in out ACCUMULATE_STATISTIC;
             ACCUMULATE_VALUE : in float);

      -- Either of the preceding two procedures may be used to
      -- COLLECT the values (floating pt. or integer) pertaining
      -- to a statistic identified by ACCUMULATE_REF. 

   procedure REPORT_ACCUMULATE (ACCUMULATE_REF : in 
                                ACCUMULATE_STATISTIC);
      -- This procedure allows the user to REPORT on an AdaSim
      -- statistic being COLLECTed, identified by ACCUMULATE_REF


-- Histogram Operators :
-- ---------------------

   procedure CREATE_HISTOGRAM 
             (HISTOGRAM_REF : in out HISTOGRAM_STATISTIC;
             HISTOGRAM_TITLE : in string;
             NUMBER_OF_CELLS : in integer;
             MIN_VALUE, MAX_VALUE : in float);

   procedure CREATE_HISTOGRAM 
             (HISTOGRAM_REF : in out HISTOGRAM_STATISTIC;
             HISTOGRAM_TITLE : in string;
             NUMBER_OF_CELLS : in integer;
             MIN_VALUE, MAX_VALUE : in integer);

-- Any of the preceding two procedures may be used to CREATE a new 
-- user-specified simulation statistic to be COLLECTed,  identified by 
-- HISTOGRAM_REF in the system and identified by HISTOGRAM_TITLE in output 
-- REPORTs generated.  The NUMBER_OF_CELLS indicates how many intervals 
-- into which the histogram shall be divided.  MIN_VALUE and MAX_VALUE 
-- (floating pt. or integer) specify the bounds of the histogram.

   procedure COLLECT_HISTOGRAM 
             (HISTOGRAM_REF : in out HISTOGRAM_STATISTIC;
             HISTOGRAM_VALUE : in float);

   procedure COLLECT_HISTOGRAM 
             (HISTOGRAM_REF : in out HISTOGRAM_STATISTIC;
             HISTOGRAM_VALUE : in integer);

-- Either of the preceding two procedures may be used to COLLECT
-- the values (floating pt. or integer) pertaining to a statistic
-- identified by HISTOGRAM_REF.

   procedure REPORT_HISTOGRAM 
             (HISTOGRAM_REF : in HISTOGRAM_STATISTIC);
      -- This procedure allows the user to REPORT on an AdaSim
      -- statistic being COLLECTed, identified by HISTOGRAM_REF.


-- PLOT Operators :
-- ----------------

   procedure CREATE_PLOT (PLOT_REF : in out PLOT_STATISTIC;
                          PLOT_TITLE : in string;
                          X_TITLE, Y_TITLE : in string;
                          X_DELTA : in float;
                          MIN_X_VALUE : in float := float'first;
                          MAX_X_VALUE : in float := float'last;
                          MIN_Y_VALUE : in float := float'first;
                          MAX_Y_VALUE : in float := float'last);

   procedure CREATE_PLOT (PLOT_REF : in out PLOT_STATISTIC;
                      PLOT_TITLE : in string;
                      X_TITLE, Y_TITLE : in string;
                      X_DELTA : in integer;
                      MIN_X_VALUE : in integer := integer'first;
                      MAX_X_VALUE : in integer := integer'last;
                      MIN_Y_VALUE : in integer := integer'first;
                      MAX_Y_VALUE : in integer := integer'last);

-- Either of these procedures may be used to CREATE a new user-specified 
-- simulation statistic to be COLLECTed, identified by PLOT_REF in the
-- system and identified by PLOT_TITLE in output REPORTs.  The x-axis and 
-- y-axis will be labeled by X_TITLE and Y_TITLE, respectively.

   procedure COLLECT_PLOT (PLOT_REF : in out PLOT_STATISTIC;
                           X_VALUE, Y_VALUE : in float);

   procedure COLLECT_PLOT (PLOT_REF : in out PLOT_STATISTIC;
                           X_VALUE, Y_VALUE : in integer);

      -- Any of the preceding two procedures may be used to 
      -- COLLECT the values (floating pt. or integer)
      -- pertaining to a statistic identified by PLOT_REF.

   procedure REPORT_PLOT (PLOT_REF : in PLOT_STATISTIC);
      -- This procedure allows the user to REPORT on an AdaSim
      -- statistic being COLLECTed, identified by PLOT_REF.


-- Report/Trace Output Operators :
-- ------------------------------------

   procedure SET_STATISTICS_REPORT_OPTION 
             (REPORT_OPTION : in UTILITY.OPTION := UTILITY.ON);

   procedure SET_STATISTICS_TRACE_OPTION 
             (TRACE_OPTION : in UTILITY.OPTION := UTILITY.OFF);

   procedure REPORT_STATISTICS;



-- Exception :
-- -----------

   STATISTIC_DOES_NOT_EXIST : exception;
      -- An exception will be raised if the user attempts
      -- to COLLECT or REPORT on a non-existent statistic.

   COUNT_REDECLARATION_ERROR, TALLY_REDECLARATION_ERROR,
   ACCUMULATE_REDECLARATION_ERROR, HISTOGRAM_REDECLARATION_ERROR,
   PLOT_REDECLARATION_ERROR : exception;
      -- Errors shall occur if the user attempts to create a new
      -- statistics from a non-null COUNTER, TALLY, ACCUMULATE,
      -- HISTOGRAM, or PLOT statistics.

   PLOT_VALUE_INVALID : exception;
      -- An exception will be raised if the value of the plot
      -- independant variable is not greater that its previous 
      -- value.


-- Private Data Structures :
-- -------------------------

private
   subtype TITLE_STRING is string (1..60);

   type COUNT_REC is
      record
         COUNT : integer;
         TITLE : TITLE_STRING;
      end record;
   type COUNT_STATISTIC is access COUNT_REC;


   type TALLY_REC is
      record
         TITLE : TITLE_STRING;
         SUM_TALLIED, SUM_OF_SQUARES : float;
            -- used for computing mean and standard deviation.
         MIN_TALLIED, MAX_TALLIED : float;
         NUMBER_TALLIED : integer;
      end record;
   type TALLY_STATISTIC is access TALLY_REC;

   type ACCUMULATE_REC is
      record
         TITLE : TITLE_STRING;
         WEIGHTED_SUM, WEIGHTED_SUM_OF_SQUARES : float;
            -- used for computing mean and standard deviation.
         MIN_ACCUMULATED, MAX_ACCUMULATED : float;
         NUMBER_ACCUMULATED : integer;
         COLLECT_TIME : float;
         VALUE : float;
      end record;
   type ACCUMULATE_STATISTIC is access ACCUMULATE_REC;

   type CELL_TYPE is array (integer range <>) of integer;
   type HISTOGRAM_REC (NUMBER_OF_CELLS : integer) is
      record
         TITLE : TITLE_STRING;
         MIN_VALUE, MAX_VALUE, CELL_WIDTH : float;
         CELL : CELL_TYPE (1 .. NUMBER_OF_CELLS);
      end record;
   type HISTOGRAM_STATISTIC is access HISTOGRAM_REC;

   type COORDINATES_REC;
   type COORDINATES is access COORDINATES_REC;
   type COORDINATES_REC is
      record
         X_COORDINATE, Y_COORDINATE : float;
         NEXT : COORDINATES := null;
      end record;

   type PLOT_REC is
      record
         PLOT_TITLE : TITLE_STRING;
         X_TITLE, Y_TITLE : UTILITY.CHAR_STRING;
         DELTA_X : float;
         USER_MIN_X, USER_MAX_X, USER_MIN_Y, USER_MAX_Y : float;
         MIN_X, MIN_Y : float := float'last;
         MAX_X, MAX_Y : float := float'first;
         NUMBER_OF_POINTS : integer;
         COORDINATES_LIST : COORDINATES := null;
      end record;
   type PLOT_STATISTIC is access PLOT_REC;

end STATISTICS;
