Add protocol version plus some identation fixes
[agianapa.git] / qt / mkspdata / main.cpp
blobddd270030659ad80ae9587bd2bf0efa04c245f64
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 int main(int argc, char *argv[])
12 QFile file;
13 float x, y, z, xR, yR, zR, t;
14 quint32 i, magicNumber, protVersion;
16 file.setFileName(argv[1]);
18 // Open file for writing
19 file.open(QIODevice::WriteOnly);
20 QDataStream out(&file);
22 // Write a header with a "magic number" and a protocol version
23 out << (quint32)MAGIC_NUMBER;
24 out << (quint32)PROT_VERSION;
26 // Write actual data
27 for (i = 0; i < 100; i++) {
28 for (t = 0.0; t < 50.0; t += 1.0) {
29 out << (float) (5.0 * t * t) << 0.0f << 0.0f
30 << (float) (cos(t) * 180.0) << 0.0f << 0.0f;
33 file.close();
35 // Open file for reading
36 file.open(QIODevice::ReadOnly);
37 QDataStream in(&file);
39 // Read "magic number" and protocol version
40 in >> magicNumber;
41 if (magicNumber != 0xA0B0C0D0) {
42 std::cout << "Magic number mismatch\n";
43 exit(EXIT_FAILURE);
46 in >> protVersion;
47 if (protVersion != PROT_VERSION) {
48 std::cout << "Protocol version mismatch\n";
49 exit(EXIT_FAILURE);
52 std::cout << "Magic number = 0x" << std::hex << magicNumber << "\n";
53 std::cout << "Protocol version = 0x" << std::hex << protVersion << "\n";
55 // Read data
56 while (!in.atEnd()) {
57 in >> x >> y >> z >> xR >> yR >> zR;
58 std::cout << "x = " << x
59 << "\ty = " << y
60 << "\tz = " << z
61 << "\txR = " << xR
62 << "\tyR = " << yR
63 << "\tzR = " << zR << "\n";
65 file.close();
67 return EXIT_SUCCESS;