-
Notifications
You must be signed in to change notification settings - Fork 1
/
LogManager.cpp
123 lines (107 loc) · 2.97 KB
/
LogManager.cpp
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
//============================================================================
// Name : LogManager.cpp
// Author : Christian Schoppmeyer
// Version :
// Created On : 22.11.2011
// Copyright : EMBOCON Copyright
// Description :
//============================================================================
#include "LogManager.h"
#include "Messages.h"
#include <fstream>
#include <math.h>
using namespace std;
fstream logfile;
fstream measLog;
double round(double x, int digits)
{
return floor(x * pow(10, digits) + 0.5) / pow(10,digits);
}
void openLogFile(char* path)
{
logfile.open(path, ios::out);
logfile << "#GEMS ";
putVersionInfo(logfile);
logfile << " (" __DATE__ ") - Generic EMBOCON Minimal Supervisor" << endl;
}
void openCPUTimeMeasLogFile(char* path)
{
measLog.open(path, ios::out);
measLog << "#GEMS ";
putVersionInfo(measLog);
measLog << " (" __DATE__ ") - Generic EMBOCON Minimal Supervisor" << endl;
}
void writeCMDLineArgsToLog(char* argv[])
{
logfile << endl;
logfile << "# Arguments:";
for(unsigned int i = 0; i < sizeof(argv); i++)
{
logfile << " " << argv[i];
}
logfile << endl;
logfile.flush();
}
void closeLogFile()
{
logfile.flush();
logfile.close();
}
void closeCPUTimeMeasLogFile()
{
measLog.flush();
measLog.close();
}
void writeCPUTimeMeasToLog(char* msg, uint64_t timeElapsed)
{
measLog << msg << "\t" << "with measure CPU time:" << "\t" << timeElapsed << "\t" << "ns" << endl;
}
void writeLineToLog(char* msg)
{
logfile << "#" << msg << endl;
}
void writeTextToLog(char* msg)
{
logfile << msg;
}
void writeNameToLog(char* name)
{
logfile << name;
logfile << "\t";
}
void writeGeneralInfoToLog(unsigned int countState, unsigned int countOutput, unsigned int countInput, unsigned int countParam, unsigned int countOptParam, unsigned int countObsParam, double numberOfsteps)
{
logfile << endl;
logfile << "# GENERAL STATISTICS:" << endl;
logfile << "# number of states: " << countState << endl;
logfile << "# number of outputs: " << countOutput << endl;
logfile << "# number of inputs: " << countInput << endl;
logfile << "# number of parameters: " << countParam << endl;
logfile << "# number of optimizer parameters: " << countOptParam << endl;
logfile << "# number of observer parameters: " << countObsParam << endl;
logfile << "# number of steps: " << numberOfsteps << endl;
logfile << endl;
logfile.flush();
}
void writeStepToLog(double step, double xcur[], unsigned int countState, double ycur[], unsigned int countOutput, double ucur[], unsigned int countInput, double pcur[], unsigned int countParam)
{
logfile << step << "\t";
for(unsigned int i = 0; i < countState; i++)
{
logfile << round(xcur[i],5) << "\t";
}
for(unsigned int i = 0; i < countOutput; i++)
{
logfile << round(ycur[i],5) << "\t";
}
for(unsigned int i = 0; i < countInput; i++)
{
logfile << round(ucur[i],5) << "\t";
}
for(unsigned int i = 0; i < countParam; i++)
{
logfile << round(pcur[i],5) << "\t";
}
logfile << endl;
logfile.flush();
}