1 | // Part of BNC, a utility for retrieving decoding and
|
---|
2 | // converting GNSS data streams from NTRIP broadcasters.
|
---|
3 | //
|
---|
4 | // Copyright (C) 2007
|
---|
5 | // German Federal Agency for Cartography and Geodesy (BKG)
|
---|
6 | // http://www.bkg.bund.de
|
---|
7 | // Czech Technical University Prague, Department of Geodesy
|
---|
8 | // http://www.fsv.cvut.cz
|
---|
9 | //
|
---|
10 | // Email: euref-ip@bkg.bund.de
|
---|
11 | //
|
---|
12 | // This program is free software; you can redistribute it and/or
|
---|
13 | // modify it under the terms of the GNU General Public License
|
---|
14 | // as published by the Free Software Foundation, version 2.
|
---|
15 | //
|
---|
16 | // This program is distributed in the hope that it will be useful,
|
---|
17 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
18 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
19 | // GNU General Public License for more details.
|
---|
20 | //
|
---|
21 | // You should have received a copy of the GNU General Public License
|
---|
22 | // along with this program; if not, write to the Free Software
|
---|
23 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
---|
24 |
|
---|
25 | /* -------------------------------------------------------------------------
|
---|
26 | * BKG NTRIP Client
|
---|
27 | * -------------------------------------------------------------------------
|
---|
28 | *
|
---|
29 | * Class: t_rnxNavFile
|
---|
30 | *
|
---|
31 | * Purpose: Reads RINEX Navigation File
|
---|
32 | *
|
---|
33 | * Author: L. Mervart
|
---|
34 | *
|
---|
35 | * Created: 24-Jan-2012
|
---|
36 | *
|
---|
37 | * Changes:
|
---|
38 | *
|
---|
39 | * -----------------------------------------------------------------------*/
|
---|
40 |
|
---|
41 | #include <iostream>
|
---|
42 | #include <newmatio.h>
|
---|
43 | #include "rnxnavfile.h"
|
---|
44 | #include "bnccore.h"
|
---|
45 | #include "bncutils.h"
|
---|
46 | #include "ephemeris.h"
|
---|
47 |
|
---|
48 | using namespace std;
|
---|
49 |
|
---|
50 | // Constructor
|
---|
51 | ////////////////////////////////////////////////////////////////////////////
|
---|
52 | t_rnxNavFile::t_rnxNavHeader::t_rnxNavHeader() {
|
---|
53 | _version = 0.0;
|
---|
54 | _glonass = false;
|
---|
55 | }
|
---|
56 |
|
---|
57 | // Destructor
|
---|
58 | ////////////////////////////////////////////////////////////////////////////
|
---|
59 | t_rnxNavFile::t_rnxNavHeader::~t_rnxNavHeader() {
|
---|
60 | }
|
---|
61 |
|
---|
62 | // Read Header
|
---|
63 | ////////////////////////////////////////////////////////////////////////////
|
---|
64 | t_irc t_rnxNavFile::t_rnxNavHeader::read(QTextStream* stream) {
|
---|
65 | while (stream->status() == QTextStream::Ok && !stream->atEnd()) {
|
---|
66 | QString line = stream->readLine();
|
---|
67 | if (line.isEmpty()) {
|
---|
68 | continue;
|
---|
69 | }
|
---|
70 | QString value = line.left(60).trimmed();
|
---|
71 | QString key = line.mid(60).trimmed();
|
---|
72 | if (key == "END OF HEADER") {
|
---|
73 | break;
|
---|
74 | }
|
---|
75 | else if (key == "RINEX VERSION / TYPE") {
|
---|
76 | QTextStream in(value.toLatin1(), QIODevice::ReadOnly);
|
---|
77 | in >> _version;
|
---|
78 | if (value.indexOf("GLONASS") != -1) {
|
---|
79 | _glonass = true;
|
---|
80 | }
|
---|
81 | }
|
---|
82 | else if (key == "COMMENT") {
|
---|
83 | _comments.append(value.trimmed());
|
---|
84 | }
|
---|
85 | else if (key == "PGM / RUN BY / DATE") {
|
---|
86 | _runByDate.append(value.trimmed());
|
---|
87 | }
|
---|
88 | }
|
---|
89 |
|
---|
90 | return success;
|
---|
91 | }
|
---|
92 |
|
---|
93 | // Constructor
|
---|
94 | ////////////////////////////////////////////////////////////////////////////
|
---|
95 | t_rnxNavFile::t_rnxNavFile(const QString& fileName, e_inpOut inpOut) {
|
---|
96 | _inpOut = inpOut;
|
---|
97 | _stream = 0;
|
---|
98 | _file = 0;
|
---|
99 | if (_inpOut == input) {
|
---|
100 | openRead(fileName);
|
---|
101 | }
|
---|
102 | else {
|
---|
103 | openWrite(fileName);
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 | // Open for input
|
---|
108 | ////////////////////////////////////////////////////////////////////////////
|
---|
109 | void t_rnxNavFile::openRead(const QString& fileName) {
|
---|
110 |
|
---|
111 | _fileName = fileName; expandEnvVar(_fileName);
|
---|
112 | _file = new QFile(_fileName);
|
---|
113 | _file->open(QIODevice::ReadOnly | QIODevice::Text);
|
---|
114 | _stream = new QTextStream();
|
---|
115 | _stream->setDevice(_file);
|
---|
116 |
|
---|
117 | _header.read(_stream);
|
---|
118 | this->read(_stream);
|
---|
119 | }
|
---|
120 |
|
---|
121 | // Open for output
|
---|
122 | ////////////////////////////////////////////////////////////////////////////
|
---|
123 | void t_rnxNavFile::openWrite(const QString& fileName) {
|
---|
124 |
|
---|
125 | _fileName = fileName; expandEnvVar(_fileName);
|
---|
126 | _file = new QFile(_fileName);
|
---|
127 | _file->open(QIODevice::WriteOnly | QIODevice::Text);
|
---|
128 | _stream = new QTextStream();
|
---|
129 | _stream->setDevice(_file);
|
---|
130 | }
|
---|
131 |
|
---|
132 | // Destructor
|
---|
133 | ////////////////////////////////////////////////////////////////////////////
|
---|
134 | t_rnxNavFile::~t_rnxNavFile() {
|
---|
135 | close();
|
---|
136 | for (unsigned ii = 0; ii < _ephs.size(); ii++) {
|
---|
137 | delete _ephs[ii];
|
---|
138 | }
|
---|
139 | }
|
---|
140 |
|
---|
141 | // Close
|
---|
142 | ////////////////////////////////////////////////////////////////////////////
|
---|
143 | void t_rnxNavFile::close() {
|
---|
144 | delete _stream; _stream = 0;
|
---|
145 | delete _file; _file = 0;
|
---|
146 | }
|
---|
147 |
|
---|
148 | // Read File Content
|
---|
149 | ////////////////////////////////////////////////////////////////////////////
|
---|
150 | void t_rnxNavFile::read(QTextStream* stream) {
|
---|
151 |
|
---|
152 | while (stream->status() == QTextStream::Ok && !stream->atEnd()) {
|
---|
153 |
|
---|
154 | QString line = stream->readLine();
|
---|
155 | if (line.isEmpty()) {
|
---|
156 | continue;
|
---|
157 | }
|
---|
158 | QString navType;
|
---|
159 | QStringList hlp = line.split(QRegExp("\\s+"), Qt::SkipEmptyParts);
|
---|
160 | QString prn;
|
---|
161 | char sys;
|
---|
162 | QString firstStr = hlp.at(0);
|
---|
163 |
|
---|
164 | // RINEX version 3
|
---|
165 | if (version() >= 3.0 &&
|
---|
166 | version() < 4.0 && firstStr != ">") {
|
---|
167 | prn = firstStr;
|
---|
168 | sys = prn[0].toLatin1();
|
---|
169 | navType = "";
|
---|
170 | }
|
---|
171 | // RINEX version 4
|
---|
172 | else if (version() >= 4.0 && firstStr == ">") {
|
---|
173 | QString key = hlp.at(1);
|
---|
174 | prn = hlp.at(2);
|
---|
175 | sys = prn[0].toLatin1();
|
---|
176 | navType = hlp.at(3);
|
---|
177 |
|
---|
178 | // ALL Non-EPH messages are currently ignored
|
---|
179 | int lines2skip = 0;
|
---|
180 | // STO
|
---|
181 | if (key == "STO") {
|
---|
182 | lines2skip = 2;
|
---|
183 | }
|
---|
184 | // EOP
|
---|
185 | else if (key == "EOP") {
|
---|
186 | lines2skip = 3;
|
---|
187 | }
|
---|
188 | // ION
|
---|
189 | else if (key == "ION") {
|
---|
190 | if (sys == 'R') {
|
---|
191 | lines2skip = 1; //if (navType == "LXOC") {}
|
---|
192 | }
|
---|
193 | else if (sys == 'E') {
|
---|
194 | lines2skip = 2;
|
---|
195 | }
|
---|
196 | else if (sys == 'G' || sys == 'C' ||
|
---|
197 | sys == 'J' || sys == 'I') {
|
---|
198 | lines2skip = 3;
|
---|
199 | if ((sys == 'I' && navType == "L1NV") || // I: KLOB, NEQN
|
---|
200 | (sys == 'J' && navType == "CNVX")) { // J: WIDE, JAPN
|
---|
201 | QString navSubType = hlp.at(4);
|
---|
202 | if (navSubType == "KLOB") {
|
---|
203 | lines2skip += 1;
|
---|
204 | }
|
---|
205 | else if (navSubType == "NEQN") {
|
---|
206 | lines2skip += 4;
|
---|
207 | }
|
---|
208 | }
|
---|
209 | }
|
---|
210 | }
|
---|
211 | if (lines2skip) {
|
---|
212 | for (int ii = 1; ii <= lines2skip; ii++) {
|
---|
213 | stream->readLine();
|
---|
214 | }
|
---|
215 | }
|
---|
216 | continue;
|
---|
217 | }
|
---|
218 | // RINEX version 2
|
---|
219 | else {
|
---|
220 | if (glonass()) {
|
---|
221 | prn = QString("R%1_0").arg(hlp.at(0).toInt(), 2, 10, QChar('0'));
|
---|
222 | }
|
---|
223 | else {
|
---|
224 | prn = QString("G%1_0").arg(hlp.at(0).toInt(), 2, 10, QChar('0'));
|
---|
225 | }
|
---|
226 | }
|
---|
227 |
|
---|
228 | t_eph* eph = 0;
|
---|
229 | QStringList lines;
|
---|
230 | lines << line;
|
---|
231 | if (sys == 'G') {
|
---|
232 | int nLines = 8;
|
---|
233 | if (navType == "CNAV") {
|
---|
234 | nLines += 1;
|
---|
235 | }
|
---|
236 | if (navType == "CNV2") {
|
---|
237 | nLines += 2;
|
---|
238 | }
|
---|
239 | for (int ii = 1; ii < nLines; ii++) {
|
---|
240 | lines << stream->readLine();
|
---|
241 | }
|
---|
242 | eph = new t_ephGPS(version(), lines);
|
---|
243 | }
|
---|
244 | else if (sys == 'R') {
|
---|
245 | int nLines = 4;
|
---|
246 | if (version() >= 3.05) {
|
---|
247 | nLines += 1;
|
---|
248 | }
|
---|
249 | for (int ii = 1; ii < nLines; ii++) {
|
---|
250 | lines << stream->readLine();
|
---|
251 | }
|
---|
252 | eph = new t_ephGlo(version(), lines);
|
---|
253 | }
|
---|
254 | else if (sys == 'E') {
|
---|
255 | for (int ii = 1; ii < 8; ii++) {
|
---|
256 | lines << stream->readLine();
|
---|
257 | }
|
---|
258 | eph = new t_ephGal(version(), lines);
|
---|
259 | }
|
---|
260 | else if (sys == 'J') {
|
---|
261 | int nLines = 8;
|
---|
262 | if (navType == "CNAV") {
|
---|
263 | nLines += 1;
|
---|
264 | }
|
---|
265 | if (navType == "CNV2") {
|
---|
266 | nLines += 2;
|
---|
267 | }
|
---|
268 | for (int ii = 1; ii < nLines; ii++) {
|
---|
269 | lines << stream->readLine();
|
---|
270 | }
|
---|
271 | eph = new t_ephGPS(version(), lines);
|
---|
272 | }
|
---|
273 | else if (sys== 'S') {
|
---|
274 | for (int ii = 1; ii < 4; ii++) {
|
---|
275 | lines << stream->readLine();
|
---|
276 | }
|
---|
277 | eph = new t_ephSBAS(version(), lines);
|
---|
278 | }
|
---|
279 | else if (sys == 'C') {
|
---|
280 | int nLines = 8;
|
---|
281 | if (navType == "CNV1" ||
|
---|
282 | navType == "CNV2") {
|
---|
283 | nLines += 2;
|
---|
284 | }
|
---|
285 | if (navType == "CNV3") {
|
---|
286 | nLines += 1;
|
---|
287 | }
|
---|
288 | for (int ii = 1; ii < nLines; ii++) {
|
---|
289 | lines << stream->readLine();
|
---|
290 | }
|
---|
291 | eph = new t_ephBDS(version(), lines);
|
---|
292 | }
|
---|
293 | else if (sys == 'I') {
|
---|
294 | int nLines = 8;
|
---|
295 | if (navType == "L1NV") {
|
---|
296 | nLines += 1;
|
---|
297 | }
|
---|
298 | for (int ii = 1; ii < nLines; ii++) {
|
---|
299 | lines << stream->readLine();
|
---|
300 | }
|
---|
301 | eph = new t_ephGPS(version(), lines);
|
---|
302 | }
|
---|
303 |
|
---|
304 | if (eph) {
|
---|
305 | eph->setType(navType);
|
---|
306 | _ephs.push_back(eph);
|
---|
307 | }
|
---|
308 |
|
---|
309 | }
|
---|
310 | }
|
---|
311 |
|
---|
312 | // Read Next Ephemeris
|
---|
313 | ////////////////////////////////////////////////////////////////////////////
|
---|
314 | t_eph* t_rnxNavFile::getNextEph(const bncTime& tt,
|
---|
315 | const QMap<QString, unsigned int>* corrIODs) {
|
---|
316 |
|
---|
317 | // Get Ephemeris according to IOD
|
---|
318 | // ------------------------------
|
---|
319 | if (corrIODs) {
|
---|
320 | QMapIterator<QString, unsigned int> itIOD(*corrIODs);
|
---|
321 | while (itIOD.hasNext()) {
|
---|
322 | itIOD.next();
|
---|
323 | QString prn = itIOD.key();
|
---|
324 | unsigned int iod = itIOD.value();
|
---|
325 | vector<t_eph*>::iterator it = _ephs.begin();
|
---|
326 | while (it != _ephs.end()) {
|
---|
327 | t_eph* eph = *it;
|
---|
328 | double dt = eph->TOC() - tt;
|
---|
329 | if (dt < 8*3600.0 && QString(eph->prn().toInternalString().c_str()) == prn && eph->IOD() == iod) {
|
---|
330 | it = _ephs.erase(it);
|
---|
331 | return eph;
|
---|
332 | }
|
---|
333 | ++it;
|
---|
334 | }
|
---|
335 | }
|
---|
336 | }
|
---|
337 |
|
---|
338 | // Get Ephemeris according to time
|
---|
339 | // -------------------------------
|
---|
340 | else {
|
---|
341 | vector<t_eph*>::iterator it = _ephs.begin();
|
---|
342 | while (it != _ephs.end()) {
|
---|
343 | t_eph* eph = *it;
|
---|
344 | double dt = eph->TOC() - tt;
|
---|
345 | if (dt < 2*3600.0) {
|
---|
346 | it = _ephs.erase(it);
|
---|
347 | return eph;
|
---|
348 | }
|
---|
349 | ++it;
|
---|
350 | }
|
---|
351 | }
|
---|
352 |
|
---|
353 | return 0;
|
---|
354 | }
|
---|
355 |
|
---|
356 | //
|
---|
357 | ////////////////////////////////////////////////////////////////////////////
|
---|
358 | void t_rnxNavFile::writeHeader(const QMap<QString, QString>* txtMap, int numMergedFiles, int leapSecs) {
|
---|
359 |
|
---|
360 | QString runBy = BNC_CORE->userName();
|
---|
361 | QStringList comments;
|
---|
362 | QStringList runByDate;
|
---|
363 |
|
---|
364 | if (txtMap) {
|
---|
365 | QMapIterator<QString, QString> it(*txtMap);
|
---|
366 | while (it.hasNext()) {
|
---|
367 | it.next();
|
---|
368 | if (it.key() == "RUN BY") {
|
---|
369 | runBy = it.value();
|
---|
370 | }
|
---|
371 | else if (it.key() == "RUN BY DATE") {
|
---|
372 | runByDate = it.value().split("\\n", Qt::SkipEmptyParts);
|
---|
373 | }
|
---|
374 | else if (it.key() == "COMMENT") {
|
---|
375 | comments = it.value().split("\\n", Qt::SkipEmptyParts);
|
---|
376 | }
|
---|
377 | }
|
---|
378 | }
|
---|
379 |
|
---|
380 | if (version() < 3.0) {
|
---|
381 | const QString fmt = glonass() ? "%1 GLONASS navigation data"
|
---|
382 | : "%1 Navigation data";
|
---|
383 | *_stream << QString(fmt)
|
---|
384 | .arg(_header._version, 9, 'f', 2)
|
---|
385 | .leftJustified(60)
|
---|
386 | << "RINEX VERSION / TYPE\n";
|
---|
387 | }
|
---|
388 | else {
|
---|
389 | QString fmt;
|
---|
390 | t_eph::e_system sys = satSystem();
|
---|
391 | switch(sys) {
|
---|
392 | case t_eph::GPS:
|
---|
393 | fmt.append("%1 N: GNSS NAV DATA G: GPS");
|
---|
394 | break;
|
---|
395 | case t_eph::GLONASS:
|
---|
396 | fmt.append("%1 N: GNSS NAV DATA R: GLONASS");
|
---|
397 | break;
|
---|
398 | case t_eph::Galileo:
|
---|
399 | fmt.append("%1 N: GNSS NAV DATA E: Galileo");
|
---|
400 | break;
|
---|
401 | case t_eph::QZSS:
|
---|
402 | fmt.append("%1 N: GNSS NAV DATA J: QZSS");
|
---|
403 | break;
|
---|
404 | case t_eph::BDS:
|
---|
405 | fmt.append("%1 N: GNSS NAV DATA C: BDS");
|
---|
406 | break;
|
---|
407 | case t_eph::IRNSS:
|
---|
408 | fmt.append("%1 N: GNSS NAV DATA I: IRNSS");
|
---|
409 | break;
|
---|
410 | case t_eph::SBAS:
|
---|
411 | fmt.append("%1 N: GNSS NAV DATA S: SBAS");
|
---|
412 | break;
|
---|
413 | case t_eph::unknown:
|
---|
414 | fmt.append("%1 N: GNSS NAV DATA M: MIXED");
|
---|
415 | break;
|
---|
416 | }
|
---|
417 | *_stream << fmt
|
---|
418 | .arg(_header._version, 9, 'f', 2)
|
---|
419 | .leftJustified(60)
|
---|
420 | << "RINEX VERSION / TYPE\n";
|
---|
421 | }
|
---|
422 |
|
---|
423 | const QString fmtDate = (version() < 3.0) ? "dd-MMM-yy hh:mm"
|
---|
424 | : "yyyyMMdd hhmmss UTC";
|
---|
425 | *_stream << QString("%1%2%3")
|
---|
426 | .arg(BNC_CORE->pgmName(), -20)
|
---|
427 | .arg(runBy.trimmed().left(20), -20)
|
---|
428 | .arg(QDateTime::currentDateTime().toUTC().toString(fmtDate), -20)
|
---|
429 | .leftJustified(60)
|
---|
430 | << "PGM / RUN BY / DATE\n";
|
---|
431 |
|
---|
432 | if (version() >= 4.0) {
|
---|
433 | QStringListIterator itRunByDt(runByDate);
|
---|
434 | while (itRunByDt.hasNext()) {
|
---|
435 | *_stream << itRunByDt.next().trimmed().left(60).leftJustified(60)
|
---|
436 | << "PGM / RUN BY / DATE\n";
|
---|
437 | }
|
---|
438 | *_stream << QString("%1").arg(leapSecs, 6, 10, QLatin1Char(' ')).left(60).leftJustified(60)
|
---|
439 | << "LEAP SECONDS\n";
|
---|
440 |
|
---|
441 | *_stream << QString("%1").arg(numMergedFiles, 19, 10, QLatin1Char(' ')).leftJustified(60)
|
---|
442 | << "MERGED FILE\n";
|
---|
443 | }
|
---|
444 |
|
---|
445 | QStringListIterator itCmnt(comments);
|
---|
446 | while (itCmnt.hasNext()) {
|
---|
447 | *_stream << itCmnt.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
|
---|
448 | }
|
---|
449 |
|
---|
450 | *_stream << QString()
|
---|
451 | .leftJustified(60)
|
---|
452 | << "END OF HEADER\n";
|
---|
453 | }
|
---|
454 |
|
---|
455 | //
|
---|
456 | ////////////////////////////////////////////////////////////////////////////
|
---|
457 | void t_rnxNavFile::writeEph(const t_eph* eph) {
|
---|
458 | *_stream << eph->toString(version());
|
---|
459 | }
|
---|