1 #include <cstdlib> // For `EXIT_FAILURE' constant
5 #include <getopt.h> // FIXME: make it portable
8 #define MAGIC_NUMBER 0xA0B0C0D0
9 #define PROT_VERSION 0x1
11 /* Function prototypes */
12 void usage(const char *pname
);
14 int main(int argc
, char *argv
[])
17 float duration
, endTime
, startTime
, timeStep
, x
, y
, z
, xR
, yR
, zR
, t
;
18 quint32 i
, cnt
, magicNumber
, protVersion
, numRecords
;
23 while ((opt
= getopt(argc
, argv
, "f:s:e:t:r::")) != -1) {
26 file
.setFileName(optarg
);
29 startTime
= atof(optarg
);
32 endTime
= atof(optarg
);
35 timeStep
= atof(optarg
);
38 numReplays
= atoi(optarg
);
46 /* optind shows to the argv[] index of the first non-option element */
48 fprintf(stderr
, "non-option argv[]-elements: ");
50 fprintf(stderr
, "%s ", argv
[optind
++]);
51 fprintf(stderr
, "\n");
55 qDebug("Start time = %f\tEnd time = %f\tTime step = %f\tReplays = %d\n",
56 startTime
, endTime
, timeStep
, numReplays
);
59 // Open file for writing
60 file
.open(QIODevice::WriteOnly
);
61 QDataStream
out(&file
);
63 // Write a header with a "magic number" and a protocol version
64 duration
= (endTime
- startTime
) * numReplays
;
65 out
<< (quint32
) MAGIC_NUMBER
;
66 out
<< (quint32
) PROT_VERSION
;
67 out
<< (float) duration
;
68 out
<< (quint32
) (numReplays
* (endTime
- startTime
) / timeStep
);
71 for (i
= 0, cnt
= 0; i
< numReplays
; i
++) {
72 for (t
= startTime
; t
< endTime
; t
+= timeStep
, cnt
++) {
73 out
<< (float) cnt
/ duration
74 << (float) (5.0 * t
* t
) << 0.0f
<< 0.0f
75 << (float) (cos(t
) * 180.0) << 0.0f
<< 0.0f
;
82 // Open file for reading
83 file
.open(QIODevice::ReadOnly
);
84 QDataStream
in(&file
);
86 // Read "magic number" and protocol version
88 if (magicNumber
!= MAGIC_NUMBER
) {
89 std::cout
<< "Magic number mismatch\n";
94 if (protVersion
!= PROT_VERSION
) {
95 std::cout
<< "Protocol version mismatch\n";
102 std::cout
<< "Magic number = 0x" << std::hex
<< magicNumber
<< "\n";
103 std::cout
<< "Protocol version = 0x" << protVersion
<< "\n";
104 std::cout
<< "Duration in sec = " << std::dec
<< duration
<< "\n";
105 std::cout
<< "Number of records = " << numRecords
<< "\n";
108 while (!in
.atEnd()) {
109 in
>> t
>> x
>> y
>> z
>> xR
>> yR
>> zR
;
110 std::cout
<< "t = " << t
116 << "\tzR = " << zR
<< "\n";
119 // Done -- close file
125 void usage(const char *pname
)
127 fprintf(stderr
, "Usage: %s -f fileName -s startTime -e endTime -t timeStep"
128 " [-r replays]\n", pname
);