SIMLIB/C++ 3.09
Loading...
Searching...
No Matches
tstat.cc
Go to the documentation of this file.
1/////////////////////////////////////////////////////////////////////////////
2//! \file tstat.cc time dependent statistics
3//
4// Copyright (c) 1991-2004 Petr Peringer
5//
6// This library is licensed under GNU Library GPL. See the file COPYING.
7//
8
9//
10// class TStat --- time statistic
11//
12
13////////////////////////////////////////////////////////////////////////////
14// interface
15//
16
17#include "simlib.h"
18#include "internal.h"
19
20////////////////////////////////////////////////////////////////////////////
21// implementation
22//
23
24namespace simlib3 {
25
27
28
29////////////////////////////////////////////////////////////////////////////
30// constructors
31//
32TStat::TStat(double initval):
33 sxt(0), sx2t(0),
34 min(initval), max(initval),
35 t0(Time), tl(Time), // time of initialization and last op
36 xl(initval), // last value
37 n(0UL) // number of records
38{
39 Dprintf(("TStat::TStat()"));
40}
41
42TStat::TStat(const char *name, double initval) :
43 sxt(0), sx2t(0),
44 min(initval), max(initval),
45 t0(Time), tl(Time),
46 xl(initval),
47 n(0UL)
48{
49 Dprintf(("TStat::TStat(\"%s\")",name));
50 SetName(name);
51}
52
53////////////////////////////////////////////////////////////////////////////
54// destructor
55//
57{
58 Dprintf(("TStat::~TStat() // \"%s\" ", Name().c_str()));
59}
60
61////////////////////////////////////////////////////////////////////////////
62// operator ()
63//
64void TStat::operator () (double x)
65{
67 double tt = xl*(double(Time)-tl);
68 sxt += tt;
69 sx2t += xl*tt;
70 xl = x;
71 tl = Time;
72 if(++n==1) min=max=x; // TODO: check
73 else
74 {
75 if(x<min) min = x;
76 if(x>max) max = x;
77 }
78}
79
80////////////////////////////////////////////////////////////////////////////
81// Clear
82//
83void TStat::Clear(double initval)
84{
85 Dprintf(("TStat::Clear() // \"%s\" ", Name().c_str()));
86 sxt = sx2t = 0;
87 min = max = initval;
88 t0 = tl = Time;
89 xl = initval; // last value
90 n = 0UL;
91}
92
93////////////////////////////////////////////////////////////////////////////
94// TStat::MeanValue
95//
96double TStat::MeanValue() const
97{
98// if(n==0) Error(111); // FIXME: error message
99 if(Time<t0)
101 if(Time==t0) return xl;
102 double sumxt = sxt + xl*(double(Time)-tl); // count last period
103 return sumxt/(double(Time)-t0);
104}
105
106}
107// end
108
void SetName(const std::string &name)
assign the name
Definition: object.cc:125
virtual std::string Name() const
get object name
Definition: object.cc:134
double MeanValue() const
Definition: tstat.cc:96
double sx2t
Definition: simlib.h:595
double min
Definition: simlib.h:596
unsigned long n
Definition: simlib.h:601
double xl
Definition: simlib.h:600
virtual void operator()(double x)
record the value
Definition: tstat.cc:64
double tl
Definition: simlib.h:599
TStat(double initval=0.0)
Definition: tstat.cc:32
double t0
Definition: simlib.h:598
virtual void Clear(double initval=0.0)
initialize
Definition: tstat.cc:83
double max
Definition: simlib.h:597
double sxt
Definition: simlib.h:594
@ TStatNotInitialized
Definition: errors.h:40
Internal header file for SIMLIB/C++.
#define Dprintf(f)
Definition: internal.h:100
Implementation of class CalendarList interface is static - using global functions in SQS namespace.
Definition: algloop.cc:32
const double & Time
model time (is NOT the block)
Definition: run.cc:48
void SIMLIB_error(const enum _ErrEnum N)
print error message and abort program
Definition: error.cc:38
SIMLIB_IMPLEMENTATION
Definition: algloop.cc:34
double min(double a, double b)
Definition: internal.h:285
double max(double a, double b)
Definition: internal.h:286
void SIMLIB_warning(const enum _ErrEnum N)
print warning message and continue
Definition: error.cc:74
Main SIMLIB/C++ interface.