Towards a sane implementation
[agianapa.git] / qt / mkspdata / main.cpp
blob2a0b246a25f2fd18b4593b6ffb95d7ddb6d35e5d
1 #include <cstdlib> // For ``EXIT_FAILURE'' constant
2 #include <iostream>
3 #include <QDataStream>
4 #include <QFile>
5 #include <math.h>
7 #define MAGIC_NUMBER 0xA0B0C0D0
8 #define PROT_VERSION 0x1
10 #define TIME_STEP 1.0f
11 #define START_TIME 0.0f
12 #define END_TIME 50.0f
13 #define NUM_REPLAYS 100
14 #define DURATION 10000 // msec
16 int main(int argc, char *argv[])
18 QFile file;
19 float x, y, z, xR, yR, zR, t;
20 quint32 i, duration, magicNumber, protVersion, numRecords;
22 file.setFileName(argv[1]);
24 // Open file for writing
25 file.open(QIODevice::WriteOnly);
26 QDataStream out(&file);
28 // Write a header with a "magic number" and a protocol version
29 out << (quint32) MAGIC_NUMBER;
30 out << (quint32) PROT_VERSION;
31 out << (quint32) DURATION; // msec
32 out << (quint32) (NUM_REPLAYS * (END_TIME - START_TIME) / TIME_STEP);
34 // Write actual data
35 for (i = 0; i < NUM_REPLAYS; i++) {
36 for (t = START_TIME; t < END_TIME; t += TIME_STEP) {
37 out << (float) (5.0 * t * t) << 0.0f << 0.0f
38 << (float) (cos(t) * 180.0) << 0.0f << 0.0f;
41 file.close();
43 // Open file for reading
44 file.open(QIODevice::ReadOnly);
45 QDataStream in(&file);
47 // Read "magic number" and protocol version
48 in >> magicNumber;
49 if (magicNumber != 0xA0B0C0D0) {
50 std::cout << "Magic number mismatch\n";
51 exit(EXIT_FAILURE);
54 in >> protVersion;
55 if (protVersion != PROT_VERSION) {
56 std::cout << "Protocol version mismatch\n";
57 exit(EXIT_FAILURE);
60 in >> duration;
61 in >> numRecords;
63 std::cout << "Magic number = 0x" << std::hex << magicNumber << "\n";
64 std::cout << "Protocol version = 0x" << protVersion << "\n";
65 std::cout << "Duration in msec = " << std::dec << duration << "\n";
66 std::cout << "Number of records = " << numRecords << "\n";
68 // Read data
69 while (!in.atEnd()) {
70 in >> x >> y >> z >> xR >> yR >> zR;
71 std::cout << "x = " << x
72 << "\ty = " << y
73 << "\tz = " << z
74 << "\txR = " << xR
75 << "\tyR = " << yR
76 << "\tzR = " << zR << "\n";
78 file.close();
80 return EXIT_SUCCESS;