File: statistics.cpp

package info (click to toggle)
travis 190101-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 7,472 kB
  • sloc: cpp: 121,608; makefile: 39
file content (161 lines) | stat: -rwxr-xr-x 3,694 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
/*****************************************************************************

    TRAVIS - Trajectory Analyzer and Visualizer

    http://www.travis-analyzer.de/

    Copyright (c) 2009-2019 Martin Brehm
                  2012-2019 Martin Thomas
                  2016-2019 Sascha Gehrke

    This file was written by Martin Brehm.

    ---------------------------------------------------------------------------

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

*****************************************************************************/


// This must always be the first include directive
#include "config.h"

#include "statistics.h"
#include "xstring.h"


const char *GetRevisionInfo_statistics(unsigned int len) {
	static char buf[256];
	GET_REVISION_INFO( buf, len );
	return buf;
}


const char *GetSourceVersion_statistics() {
	static char buf[256];
	GET_SOURCE_VERSION( buf );
	return buf;
}


CStatistics::CStatistics()
{
	m_iSizeX = 0;
	m_iSizeY = 0;
	m_pMin = NULL;
	m_pMax = NULL;
	m_pAvg = NULL;
	m_pCount = NULL;
	m_waXValues.SetName("CStatistics::m_waXValues");
	m_waYValues.SetName("CStatistics::m_waYValues");
}


CStatistics::~CStatistics()
{
	if (m_pMin != NULL)
	{
		delete[] m_pMin;
		m_pMin = NULL;
	}
	if (m_pMax != NULL)
	{
		delete[] m_pMax;
		m_pMax = NULL;
	}
	if (m_pAvg != NULL)
	{
		delete[] m_pAvg;
		m_pAvg = NULL;
	}
	if (m_pCount != NULL)
	{
		delete[] m_pCount;
		m_pCount = NULL;
	}
}


void CStatistics::Init(int x, int y)
{
	int z;

	m_iSizeX = x;
	m_iSizeY = y;

	try { m_pMin = new double[x*y]; } catch(...) { m_pMin = NULL; }
	if (m_pMin == NULL) NewException((double)x*y*sizeof(double),__FILE__,__LINE__,__PRETTY_FUNCTION__);
	
	try { m_pMax = new double[x*y]; } catch(...) { m_pMax = NULL; }
	if (m_pMax == NULL) NewException((double)x*y*sizeof(double),__FILE__,__LINE__,__PRETTY_FUNCTION__);
	
	try { m_pAvg = new double[x*y]; } catch(...) { m_pAvg = NULL; }
	if (m_pAvg == NULL) NewException((double)x*y*sizeof(double),__FILE__,__LINE__,__PRETTY_FUNCTION__);
	
	try { m_pCount = new double[x*y]; } catch(...) { m_pCount = NULL; }
	if (m_pCount == NULL) NewException((double)x*y*sizeof(double),__FILE__,__LINE__,__PRETTY_FUNCTION__);

	for (z=0;z<x*y;z++)
	{
		m_pMin[z] = 9999999999.0;
		m_pMax[z] = 0.0;
		m_pAvg[z] = 0.0;
		m_pCount[z] = 0.0;
	}
}


void CStatistics::Evaluate()
{
	int z;

	for (z=0;z<m_iSizeX*m_iSizeY;z++)
		if (m_pCount[z] != 0)
			m_pAvg[z] /= m_pCount[z];
}


void CStatistics::Write(const char *pre, const char *s, const char *post)
{
	BTIN;
	FILE *a;
	int x, y;
//	char buf[256];
	CxString buf;
	
//	buf[0] = 0;
//	strcpy(buf,pre);
//	strcat(buf,s);
//	strcat(buf,post);

	buf.strcpy(pre);
	buf.strcat(s);
	buf.strcat(post);

	a = OpenFileWrite(buf,true);
	for (x=0;x<m_iSizeX;x++)
	{
		for (y=0;y<m_iSizeY;y++)
		{
			fprintf(a,"%8d; %8d; ",m_waXValues[x]+1,m_waYValues[y]+1);
			if (m_pCount[y*m_iSizeX+x] == 0)
				fprintf(a,"     -    ;      -    ;      -    \n");
			else
				fprintf(a,"%10.3f; %10.3f; %10.3f\n",m_pMin[y*m_iSizeX+x],m_pMax[y*m_iSizeX+x],m_pAvg[y*m_iSizeX+x]);
		}
	}
	fclose(a);
	BTOUT;
}