1 #include <cstdlib> // For ``EXIT_FAILURE'' constant
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
[])
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
);
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
;
43 // Open file for reading
44 file
.open(QIODevice::ReadOnly
);
45 QDataStream
in(&file
);
47 // Read "magic number" and protocol version
49 if (magicNumber
!= 0xA0B0C0D0) {
50 std::cout
<< "Magic number mismatch\n";
55 if (protVersion
!= PROT_VERSION
) {
56 std::cout
<< "Protocol version mismatch\n";
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";
70 in
>> x
>> y
>> z
>> xR
>> yR
>> zR
;
71 std::cout
<< "x = " << x
76 << "\tzR = " << zR
<< "\n";