1 /***************************************************************************
2 * This file is part of Tecorrec. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
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. *
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. *
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 ***************************************************************************/
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();
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
56 srtmStream
>> srtmness
;
57 voidStream
>> voidness
;
60 srtmness
= (srtmness
& 0x7FFF) | (voidness
& 0x8000);
62 srtmStream
<< srtmness
;
67 qDebug() << "Size mismatch with " << filename
<< " and " << pathFname
;
73 qDebug() << "Could not access " << pathFname
;
79 qDebug() << "Could not access " << filename
;
85 int main(int argc
, char** argv
)
87 qDebug() << "Welcome to cpVoids";
89 // Copy void data into HGT files specified
91 for (int i
= 1; i
< argc
; ++i
)
93 if (0 == strcmp(argv
[i
], "--voids"))
95 // next argument is voids directory
99 qDebug() << "Using voids from " << voids
;
106 qDebug() << "Cannot copy voids into " << argv
[i
] << ", no void directory specified, use --voids void/dir before HGT files";
109 error
|= cpVoids(argv
[i
], voids
);