Repository navigation
Expand file tree
/
Copy pathDataWriter.cpp
More file actions
116 lines (97 loc) · 2.61 KB
/
Copy pathDataWriter.cpp
File metadata and controls
116 lines (97 loc) · 2.61 KB
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
//Modified to add target inputs, 9/10/2012 AW
#include <ctime>
#include <iomanip>
#include <iostream>
#include <sstream>
#include "DataWriter.h"
using namespace std;
DataWriter::DataWriter(TrackSYSCONFIG *sysconfig, const char* filename)
{
//record current date/time
time_t current_time = time(0);
tm* ltm = localtime(¤t_time);
stringstream ss1, ss2, ss3;
ss1 << setw(4) << setfill('0') << ltm->tm_year + 1900;
ss1 << setw(2) << setfill('0') << ltm->tm_mon + 1;
ss1 << setw(2) << setfill('0') << ltm->tm_mday;
ss2 << setw(2) << setfill('0') << ltm->tm_hour;
ss2 << setw(2) << setfill('0') << ltm->tm_min;
ss2 << setw(2) << setfill('0') << ltm->tm_sec;
// If no filename was supplied, use the date and time
if (filename == NULL)
{
ss3 << ss1.str() << "_" << ss2.str() << ".dat";
file.open(ss3.str(), ios::out);
}
else
{
//append timestamp to prevent overwrites
ss3 << filename << "_" << ss1.str() << ss2.str() << ".dat";
file.open(ss3.str(), ios::out);
}
// Write headers to file
if (file.is_open())
{
//write current date
file << "Date " << ss1.str() << endl;
file << "Time " << ss2.str() << endl;
//write bird config parameters of interest
file << "Tracker: " << (sysconfig->trackType ? "TrakStar" : "FOB") << endl;
file << "Number_of_Birds " << sysconfig->birdCount << endl;
file << "Sampling_Rate " << sysconfig->measureRate << endl;
file << "Report_Rate " << sysconfig->reportRate << endl;
file << "--" << endl;
file << "Device_Num "
<< "TrackerTime "
<< "Trial "
<< "HandX "
<< "HandY "
<< "Velocity "
<< "StartX "
<< "StartY "
<< "TargetX "
<< "TargetY "
<< "TargetX2 "
<< "TargetY2 "
<< "TrType "
<< "VelMin "
<< "VelMax "
<< "TrialScore "
<< endl;
file << "-----" << endl; //flag designator for finding start of the data stream. everything above is header
}
}
DataWriter::~DataWriter()
{
file.close();
}
void DataWriter::Record(int deviceNo, TrackDATAFRAME frame, TargetFrame Target)
{
// Write data
if (file.is_open())
{
file << deviceNo << " "
<< std::fixed << showpoint << std::setprecision(5)
<< frame.time << " "
<< std::resetiosflags( std::ios::fixed | std::ios::showpoint )
<< Target.trial << " "
<< frame.x << " "
<< frame.y << " "
<< frame.vel << " "
<< Target.startx << " "
<< Target.starty << " "
<< Target.tgtx << " "
<< Target.tgty << " "
<< Target.tgtx2 << " "
<< Target.tgty2 << " "
<< Target.TrType << " "
<< Target.velmin << " "
<< Target.velmax << " "
<< Target.score << " "
<< endl;
}
}
void DataWriter::Close()
{
file.close();
}