arctohgt & cpvoids: add missing <inttypes.h> include
[tecorrec.git] / cpvoids / cpVoids.cpp
blob12ecc1f28d6fd8883dd3f86d93c9121a75f59e72
1 /***************************************************************************
2 * This file is part of Tecorrec. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
4 * *
5 * Tecorrec is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 2 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * Tecorrec is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
14 * *
15 * You should have received a copy of the GNU General Public License *
16 * along with Tecorrec. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
20 #include <QString>
21 #include <QFile>
22 #include <QtDebug>
23 #include <QFileInfo>
25 #include <cmath>
26 #include <inttypes.h>
28 int cpVoids(const QString filename, char* voids)
30 qDebug() << "Reading" << filename;
32 // Find corresponding file in void directory
33 QFileInfo fi(filename);
34 QString name = fi.fileName();
36 QFile srtm(filename);
37 if (srtm.open(QIODevice::ReadWrite))
39 QString pathFname = QString("%1/%2").arg(voids).arg(name);
40 QFile voidfs(pathFname);
41 if (voidfs.open(QIODevice::ReadOnly))
43 // Check they're the same size
44 int len = srtm.size();
45 if (voidfs.size() == len)
47 QDataStream srtmStream(&srtm);
48 QDataStream voidStream(&voidfs);
49 srtmStream.setByteOrder(QDataStream::BigEndian);
50 voidStream.setByteOrder(QDataStream::BigEndian);
51 for (int i = 0; i < len; i += 2)
53 // Read value and voidness
54 uint16_t srtmness;
55 uint16_t voidness;
56 srtmStream >> srtmness;
57 voidStream >> voidness;
59 // Copy voidness over
60 srtmness = (srtmness & 0x7FFF) | (voidness & 0x8000);
61 srtm.seek(i);
62 srtmStream << srtmness;
65 else
67 qDebug() << "Size mismatch with " << filename << " and " << pathFname;
68 return 8;
71 else
73 qDebug() << "Could not access " << pathFname;
74 return 4;
77 else
79 qDebug() << "Could not access " << filename;
80 return 2;
82 return 0;
85 int main(int argc, char** argv)
87 qDebug() << "Welcome to cpVoids";
88 int error = 0;
89 // Copy void data into HGT files specified
90 char * voids = 0;
91 for (int i = 1; i < argc; ++i)
93 if (0 == strcmp(argv[i], "--voids"))
95 // next argument is voids directory
96 if (++i < argc)
98 voids = argv[i];
99 qDebug() << "Using voids from " << voids;
102 else
104 if (0 == voids)
106 qDebug() << "Cannot copy voids into " << argv[i] << ", no void directory specified, use --voids void/dir before HGT files";
107 return 1;
109 error |= cpVoids(argv[i], voids);
112 return error;