~ubuntu-branches/ubuntu/utopic/travis/utopic

« back to all changes in this revision

Viewing changes to src/statistics.cpp

  • Committer: Package Import Robot
  • Author(s): Daniel Leidert
  • Date: 2014-01-18 20:07:16 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20140118200716-whsmcg7fa1eyqecq
Tags: 140117-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*****************************************************************************
2
 
    TRAVIS - Trajectory Analyzer and Visualizer
3
 
    http://www.travis-analyzer.de/
4
 
 
5
 
    Copyright (c) 2009-2013 Martin Brehm
6
 
                  2012-2013 Martin Thomas
7
 
 
8
 
    This file written by Martin Brehm.
9
 
 
10
 
    This program is free software: you can redistribute it and/or modify
11
 
    it under the terms of the GNU General Public License as published by
12
 
    the Free Software Foundation, either version 3 of the License, or
13
 
    (at your option) any later version.
14
 
 
15
 
    This program is distributed in the hope that it will be useful,
16
 
    but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 
    GNU General Public License for more details.
19
 
 
20
 
    You should have received a copy of the GNU General Public License
21
 
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
22
 
*****************************************************************************/
23
 
 
24
 
#include "statistics.h"
25
 
 
26
 
 
27
 
CStatistics::CStatistics()
28
 
{
29
 
        m_iSizeX = 0;
30
 
        m_iSizeY = 0;
31
 
        m_pMin = NULL;
32
 
        m_pMax = NULL;
33
 
        m_pAvg = NULL;
34
 
        m_pCount = NULL;
35
 
        m_waXValues.SetName("CStatistics::m_waXValues");
36
 
        m_waYValues.SetName("CStatistics::m_waYValues");
37
 
}
38
 
 
39
 
 
40
 
CStatistics::~CStatistics()
41
 
{
42
 
        if (m_pMin != NULL)
43
 
        {
44
 
                delete[] m_pMin;
45
 
                m_pMin = NULL;
46
 
        }
47
 
        if (m_pMax != NULL)
48
 
        {
49
 
                delete[] m_pMax;
50
 
                m_pMax = NULL;
51
 
        }
52
 
        if (m_pAvg != NULL)
53
 
        {
54
 
                delete[] m_pAvg;
55
 
                m_pAvg = NULL;
56
 
        }
57
 
        if (m_pCount != NULL)
58
 
        {
59
 
                delete[] m_pCount;
60
 
                m_pCount = NULL;
61
 
        }
62
 
}
63
 
 
64
 
 
65
 
void CStatistics::Init(int x, int y)
66
 
{
67
 
        int z;
68
 
 
69
 
        m_iSizeX = x;
70
 
        m_iSizeY = y;
71
 
 
72
 
        try { m_pMin = new double[x*y]; } catch(...) { m_pMin = NULL; }
73
 
        if (m_pMin == NULL) NewException((double)x*y*sizeof(double),__FILE__,__LINE__,__PRETTY_FUNCTION__);
74
 
        
75
 
        try { m_pMax = new double[x*y]; } catch(...) { m_pMax = NULL; }
76
 
        if (m_pMax == NULL) NewException((double)x*y*sizeof(double),__FILE__,__LINE__,__PRETTY_FUNCTION__);
77
 
        
78
 
        try { m_pAvg = new double[x*y]; } catch(...) { m_pAvg = NULL; }
79
 
        if (m_pAvg == NULL) NewException((double)x*y*sizeof(double),__FILE__,__LINE__,__PRETTY_FUNCTION__);
80
 
        
81
 
        try { m_pCount = new double[x*y]; } catch(...) { m_pCount = NULL; }
82
 
        if (m_pCount == NULL) NewException((double)x*y*sizeof(double),__FILE__,__LINE__,__PRETTY_FUNCTION__);
83
 
 
84
 
        for (z=0;z<x*y;z++)
85
 
        {
86
 
                m_pMin[z] = 9999999999.0;
87
 
                m_pMax[z] = 0.0;
88
 
                m_pAvg[z] = 0.0;
89
 
                m_pCount[z] = 0.0;
90
 
        }
91
 
}
92
 
 
93
 
 
94
 
void CStatistics::Evaluate()
95
 
{
96
 
        int z;
97
 
 
98
 
        for (z=0;z<m_iSizeX*m_iSizeY;z++)
99
 
                if (m_pCount[z] != 0)
100
 
                        m_pAvg[z] /= m_pCount[z];
101
 
}
102
 
 
103
 
 
104
 
void CStatistics::Write(const char *pre, const char *s, const char *post)
105
 
{
106
 
        BTIN;
107
 
        FILE *a;
108
 
        int x, y;
109
 
        char buf[256];
110
 
        
111
 
        buf[0] = 0;
112
 
        strcpy(buf,pre);
113
 
        strcat(buf,s);
114
 
        strcat(buf,post);
115
 
 
116
 
        a = OpenFileWrite(buf,true);
117
 
        for (x=0;x<m_iSizeX;x++)
118
 
                for (y=0;y<m_iSizeY;y++)
119
 
                {
120
 
                        fprintf(a,"%8d; %8d; ",m_waXValues[x]+1,m_waYValues[y]+1);
121
 
                        if (m_pCount[y*m_iSizeX+x] == 0)
122
 
                                fprintf(a,"     -    ;      -    ;      -    \n");
123
 
                                        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]);
124
 
                }
125
 
        fclose(a);
126
 
        BTOUT;
127
 
}
128
 
 
 
1
/*****************************************************************************
 
2
    TRAVIS - Trajectory Analyzer and Visualizer
 
3
    http://www.travis-analyzer.de/
 
4
 
 
5
    Copyright (c) 2009-2014 Martin Brehm
 
6
                  2012-2014 Martin Thomas
 
7
 
 
8
    This file written by Martin Brehm.
 
9
 
 
10
    This program is free software: you can redistribute it and/or modify
 
11
    it under the terms of the GNU General Public License as published by
 
12
    the Free Software Foundation, either version 3 of the License, or
 
13
    (at your option) any later version.
 
14
 
 
15
    This program is distributed in the hope that it will be useful,
 
16
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
    GNU General Public License for more details.
 
19
 
 
20
    You should have received a copy of the GNU General Public License
 
21
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
22
*****************************************************************************/
 
23
 
 
24
#include "statistics.h"
 
25
 
 
26
 
 
27
CStatistics::CStatistics()
 
28
{
 
29
        m_iSizeX = 0;
 
30
        m_iSizeY = 0;
 
31
        m_pMin = NULL;
 
32
        m_pMax = NULL;
 
33
        m_pAvg = NULL;
 
34
        m_pCount = NULL;
 
35
        m_waXValues.SetName("CStatistics::m_waXValues");
 
36
        m_waYValues.SetName("CStatistics::m_waYValues");
 
37
}
 
38
 
 
39
 
 
40
CStatistics::~CStatistics()
 
41
{
 
42
        if (m_pMin != NULL)
 
43
        {
 
44
                delete[] m_pMin;
 
45
                m_pMin = NULL;
 
46
        }
 
47
        if (m_pMax != NULL)
 
48
        {
 
49
                delete[] m_pMax;
 
50
                m_pMax = NULL;
 
51
        }
 
52
        if (m_pAvg != NULL)
 
53
        {
 
54
                delete[] m_pAvg;
 
55
                m_pAvg = NULL;
 
56
        }
 
57
        if (m_pCount != NULL)
 
58
        {
 
59
                delete[] m_pCount;
 
60
                m_pCount = NULL;
 
61
        }
 
62
}
 
63
 
 
64
 
 
65
void CStatistics::Init(int x, int y)
 
66
{
 
67
        int z;
 
68
 
 
69
        m_iSizeX = x;
 
70
        m_iSizeY = y;
 
71
 
 
72
        try { m_pMin = new double[x*y]; } catch(...) { m_pMin = NULL; }
 
73
        if (m_pMin == NULL) NewException((double)x*y*sizeof(double),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
74
        
 
75
        try { m_pMax = new double[x*y]; } catch(...) { m_pMax = NULL; }
 
76
        if (m_pMax == NULL) NewException((double)x*y*sizeof(double),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
77
        
 
78
        try { m_pAvg = new double[x*y]; } catch(...) { m_pAvg = NULL; }
 
79
        if (m_pAvg == NULL) NewException((double)x*y*sizeof(double),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
80
        
 
81
        try { m_pCount = new double[x*y]; } catch(...) { m_pCount = NULL; }
 
82
        if (m_pCount == NULL) NewException((double)x*y*sizeof(double),__FILE__,__LINE__,__PRETTY_FUNCTION__);
 
83
 
 
84
        for (z=0;z<x*y;z++)
 
85
        {
 
86
                m_pMin[z] = 9999999999.0;
 
87
                m_pMax[z] = 0.0;
 
88
                m_pAvg[z] = 0.0;
 
89
                m_pCount[z] = 0.0;
 
90
        }
 
91
}
 
92
 
 
93
 
 
94
void CStatistics::Evaluate()
 
95
{
 
96
        int z;
 
97
 
 
98
        for (z=0;z<m_iSizeX*m_iSizeY;z++)
 
99
                if (m_pCount[z] != 0)
 
100
                        m_pAvg[z] /= m_pCount[z];
 
101
}
 
102
 
 
103
 
 
104
void CStatistics::Write(const char *pre, const char *s, const char *post)
 
105
{
 
106
        BTIN;
 
107
        FILE *a;
 
108
        int x, y;
 
109
        char buf[256];
 
110
        
 
111
        buf[0] = 0;
 
112
        strcpy(buf,pre);
 
113
        strcat(buf,s);
 
114
        strcat(buf,post);
 
115
 
 
116
        a = OpenFileWrite(buf,true);
 
117
        for (x=0;x<m_iSizeX;x++)
 
118
                for (y=0;y<m_iSizeY;y++)
 
119
                {
 
120
                        fprintf(a,"%8d; %8d; ",m_waXValues[x]+1,m_waYValues[y]+1);
 
121
                        if (m_pCount[y*m_iSizeX+x] == 0)
 
122
                                fprintf(a,"     -    ;      -    ;      -    \n");
 
123
                                        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]);
 
124
                }
 
125
        fclose(a);
 
126
        BTOUT;
 
127
}
 
128