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 | QString navType;
|
---|
152 |
|
---|
153 | while (stream->status() == QTextStream::Ok && !stream->atEnd()) {
|
---|
154 |
|
---|
155 | QString line = stream->readLine();
|
---|
156 | if (line.isEmpty()) {
|
---|
157 | continue;
|
---|
158 | }
|
---|
159 |
|
---|
160 | QStringList hlp = line.split(QRegExp("\\s+"), Qt::SkipEmptyParts);
|
---|
161 | QString key, prn, navSubType;
|
---|
162 | char sys;
|
---|
163 |
|
---|
164 | QString firstStr = hlp.at(0);
|
---|
165 | if (version() >= 3.0 && firstStr != ">") {
|
---|
166 | prn = firstStr;
|
---|
167 | sys = prn[0].toLatin1();
|
---|
168 | }
|
---|
169 | else if (version() >= 4.0 && firstStr == ">") {
|
---|
170 | key = hlp.at(1);
|
---|
171 | prn = hlp.at(2);
|
---|
172 | sys = prn[0].toLatin1();
|
---|
173 | navType = hlp.at(3);
|
---|
174 |
|
---|
175 | // ALL Non-EPH messages are currently ignored
|
---|
176 | int lines2skip = 0;
|
---|
177 | // STO
|
---|
178 | if (key == "STO") {
|
---|
179 | lines2skip = 2;
|
---|
180 | }
|
---|
181 | // EOP
|
---|
182 | else if (key == "EOP") {
|
---|
183 | lines2skip = 3;
|
---|
184 | }
|
---|
185 | // ION
|
---|
186 | else if (key == "ION") {
|
---|
187 | if (sys == 'R') {
|
---|
188 | lines2skip = 1; //if (navType == "LXOC") {}
|
---|
189 | }
|
---|
190 | else if (sys == 'E') {
|
---|
191 | lines2skip = 2;
|
---|
192 | }
|
---|
193 | else if (sys == 'G' || sys == 'C' ||
|
---|
194 | sys == 'J' || sys == 'I') {
|
---|
195 | lines2skip = 3;
|
---|
196 | if (sys == 'I' && navType == "L1NV" || // I: KLOB, NEQN
|
---|
197 | sys == 'J' && navType == "CNVX") { // J: WIDE, JAPN
|
---|
198 | navSubType = hlp.at(4);
|
---|
199 | if (navSubType == "KLOB") {
|
---|
200 | lines2skip += 1;
|
---|
201 | }
|
---|
202 | else if (navSubType == "NEQN") {
|
---|
203 | lines2skip += 4;
|
---|
204 | }
|
---|
205 | }
|
---|
206 | }
|
---|
207 | }
|
---|
208 | if (lines2skip) {
|
---|
209 | for (int ii = 1; ii <= lines2skip; ii++) {
|
---|
210 | stream->readLine();
|
---|
211 | }
|
---|
212 | }
|
---|
213 | continue;
|
---|
214 | }
|
---|
215 | else {
|
---|
216 | if (glonass()) {
|
---|
217 | prn = QString("R%1_0").arg(hlp.at(0).toInt(), 2, 10, QChar('0'));
|
---|
218 | }
|
---|
219 | else {
|
---|
220 | prn = QString("G%1_0").arg(hlp.at(0).toInt(), 2, 10, QChar('0'));
|
---|
221 | }
|
---|
222 | }
|
---|
223 |
|
---|
224 | t_eph* eph = 0;
|
---|
225 | QStringList lines;
|
---|
226 | lines << line;
|
---|
227 | if (sys == 'G') {
|
---|
228 | for (int ii = 1; ii < 8; ii++) {
|
---|
229 | lines << stream->readLine();
|
---|
230 | }
|
---|
231 | eph = new t_ephGPS(version(), lines);
|
---|
232 | }
|
---|
233 | else if (sys == 'R') {
|
---|
234 | int num = 4;
|
---|
235 | if (version() >= 3.05) {
|
---|
236 | num += 1;
|
---|
237 | }
|
---|
238 | for (int ii = 1; ii < num; ii++) {
|
---|
239 | lines << stream->readLine();
|
---|
240 | }
|
---|
241 | eph = new t_ephGlo(version(), lines);
|
---|
242 | }
|
---|
243 | else if (sys == 'E') {
|
---|
244 | for (int ii = 1; ii < 8; ii++) {
|
---|
245 | lines << stream->readLine();
|
---|
246 | }
|
---|
247 | eph = new t_ephGal(version(), lines);
|
---|
248 | }
|
---|
249 | else if (sys == 'J') {
|
---|
250 | for (int ii = 1; ii < 8; ii++) {
|
---|
251 | lines << stream->readLine();
|
---|
252 | }
|
---|
253 | eph = new t_ephGPS(version(), lines);
|
---|
254 | }
|
---|
255 | else if (sys== 'S') {
|
---|
256 | for (int ii = 1; ii < 4; ii++) {
|
---|
257 | lines << stream->readLine();
|
---|
258 | }
|
---|
259 | eph = new t_ephSBAS(version(), lines);
|
---|
260 | }
|
---|
261 | else if (sys == 'C') {
|
---|
262 | for (int ii = 1; ii < 8; ii++) {
|
---|
263 | lines << stream->readLine();
|
---|
264 | }
|
---|
265 | eph = new t_ephBDS(version(), lines);
|
---|
266 | }
|
---|
267 | else if (sys == 'I') {
|
---|
268 | for (int ii = 1; ii < 8; ii++) {
|
---|
269 | lines << stream->readLine();
|
---|
270 | }
|
---|
271 | eph = new t_ephGPS(version(), lines);
|
---|
272 | }
|
---|
273 |
|
---|
274 | if (version() >= 4.0 && key == "EPH") {
|
---|
275 | if (eph->setNavType(navType) != success) {
|
---|
276 | delete eph;
|
---|
277 | continue;
|
---|
278 | }
|
---|
279 | }
|
---|
280 |
|
---|
281 | if (eph) {
|
---|
282 | _ephs.push_back(eph);
|
---|
283 | }
|
---|
284 | }
|
---|
285 | }
|
---|
286 |
|
---|
287 | // Read Next Ephemeris
|
---|
288 | ////////////////////////////////////////////////////////////////////////////
|
---|
289 | t_eph* t_rnxNavFile::getNextEph(const bncTime& tt,
|
---|
290 | const QMap<QString, unsigned int>* corrIODs) {
|
---|
291 |
|
---|
292 | // Get Ephemeris according to IOD
|
---|
293 | // ------------------------------
|
---|
294 | if (corrIODs) {
|
---|
295 | QMapIterator<QString, unsigned int> itIOD(*corrIODs);
|
---|
296 | while (itIOD.hasNext()) {
|
---|
297 | itIOD.next();
|
---|
298 | QString prn = itIOD.key();
|
---|
299 | unsigned int iod = itIOD.value();
|
---|
300 | vector<t_eph*>::iterator it = _ephs.begin();
|
---|
301 | while (it != _ephs.end()) {
|
---|
302 | t_eph* eph = *it;
|
---|
303 | double dt = eph->TOC() - tt;
|
---|
304 | if (dt < 8*3600.0 && QString(eph->prn().toInternalString().c_str()) == prn && eph->IOD() == iod) {
|
---|
305 | it = _ephs.erase(it);
|
---|
306 | return eph;
|
---|
307 | }
|
---|
308 | ++it;
|
---|
309 | }
|
---|
310 | }
|
---|
311 | }
|
---|
312 |
|
---|
313 | // Get Ephemeris according to time
|
---|
314 | // -------------------------------
|
---|
315 | else {
|
---|
316 | vector<t_eph*>::iterator it = _ephs.begin();
|
---|
317 | while (it != _ephs.end()) {
|
---|
318 | t_eph* eph = *it;
|
---|
319 | double dt = eph->TOC() - tt;
|
---|
320 | if (dt < 2*3600.0) {
|
---|
321 | it = _ephs.erase(it);
|
---|
322 | return eph;
|
---|
323 | }
|
---|
324 | ++it;
|
---|
325 | }
|
---|
326 | }
|
---|
327 |
|
---|
328 | return 0;
|
---|
329 | }
|
---|
330 |
|
---|
331 | //
|
---|
332 | ////////////////////////////////////////////////////////////////////////////
|
---|
333 | void t_rnxNavFile::writeHeader(const QMap<QString, QString>* txtMap, int numMergedFiles, int leapSecs) {
|
---|
334 |
|
---|
335 | QString runBy = BNC_CORE->userName();
|
---|
336 | QStringList comments;
|
---|
337 | QStringList runByDate;
|
---|
338 |
|
---|
339 | if (txtMap) {
|
---|
340 | QMapIterator<QString, QString> it(*txtMap);
|
---|
341 | while (it.hasNext()) {
|
---|
342 | it.next();
|
---|
343 | if (it.key() == "RUN BY") {
|
---|
344 | runBy = it.value();
|
---|
345 | }
|
---|
346 | else if (it.key() == "RUN BY DATE") {
|
---|
347 | runByDate = it.value().split("\\n", Qt::SkipEmptyParts);
|
---|
348 | }
|
---|
349 | else if (it.key() == "COMMENT") {
|
---|
350 | comments = it.value().split("\\n", Qt::SkipEmptyParts);
|
---|
351 | }
|
---|
352 | }
|
---|
353 | }
|
---|
354 |
|
---|
355 | if (version() < 3.0) {
|
---|
356 | const QString fmt = glonass() ? "%1 GLONASS navigation data"
|
---|
357 | : "%1 Navigation data";
|
---|
358 | *_stream << QString(fmt)
|
---|
359 | .arg(_header._version, 9, 'f', 2)
|
---|
360 | .leftJustified(60)
|
---|
361 | << "RINEX VERSION / TYPE\n";
|
---|
362 | }
|
---|
363 | else {
|
---|
364 | QString fmt;
|
---|
365 | t_eph::e_type sys = satSystem();
|
---|
366 | switch(sys) {
|
---|
367 | case t_eph::GPS:
|
---|
368 | fmt.append("%1 N: GNSS NAV DATA G: GPS");
|
---|
369 | break;
|
---|
370 | case t_eph::GLONASS:
|
---|
371 | fmt.append("%1 N: GNSS NAV DATA R: GLONASS");
|
---|
372 | break;
|
---|
373 | case t_eph::Galileo:
|
---|
374 | fmt.append("%1 N: GNSS NAV DATA E: Galileo");
|
---|
375 | break;
|
---|
376 | case t_eph::QZSS:
|
---|
377 | fmt.append("%1 N: GNSS NAV DATA J: QZSS");
|
---|
378 | break;
|
---|
379 | case t_eph::BDS:
|
---|
380 | fmt.append("%1 N: GNSS NAV DATA C: BDS");
|
---|
381 | break;
|
---|
382 | case t_eph::IRNSS:
|
---|
383 | fmt.append("%1 N: GNSS NAV DATA I: IRNSS");
|
---|
384 | break;
|
---|
385 | case t_eph::SBAS:
|
---|
386 | fmt.append("%1 N: GNSS NAV DATA S: SBAS");
|
---|
387 | break;
|
---|
388 | case t_eph::unknown:
|
---|
389 | fmt.append("%1 N: GNSS NAV DATA M: MIXED");
|
---|
390 | break;
|
---|
391 | }
|
---|
392 | *_stream << fmt
|
---|
393 | .arg(_header._version, 9, 'f', 2)
|
---|
394 | .leftJustified(60)
|
---|
395 | << "RINEX VERSION / TYPE\n";
|
---|
396 | }
|
---|
397 |
|
---|
398 | const QString fmtDate = (version() < 3.0) ? "dd-MMM-yy hh:mm"
|
---|
399 | : "yyyyMMdd hhmmss UTC";
|
---|
400 | *_stream << QString("%1%2%3")
|
---|
401 | .arg(BNC_CORE->pgmName(), -20)
|
---|
402 | .arg(runBy.trimmed().left(20), -20)
|
---|
403 | .arg(QDateTime::currentDateTime().toUTC().toString(fmtDate), -20)
|
---|
404 | .leftJustified(60)
|
---|
405 | << "PGM / RUN BY / DATE\n";
|
---|
406 |
|
---|
407 | if (version() >= 4.0) {
|
---|
408 | QStringListIterator itRunByDt(runByDate);
|
---|
409 | while (itRunByDt.hasNext()) {
|
---|
410 | *_stream << itRunByDt.next().trimmed().left(60).leftJustified(60)
|
---|
411 | << "PGM / RUN BY / DATE\n";
|
---|
412 | }
|
---|
413 | *_stream << QString("%1").arg(leapSecs, 6, 10, QLatin1Char(' ')).left(60).leftJustified(60)
|
---|
414 | << "LEAP SECONDS\n";
|
---|
415 |
|
---|
416 | *_stream << QString("%1").arg(numMergedFiles, 19, 10, QLatin1Char(' ')).leftJustified(60)
|
---|
417 | << "MERGED FILE\n";
|
---|
418 | }
|
---|
419 |
|
---|
420 | QStringListIterator itCmnt(comments);
|
---|
421 | while (itCmnt.hasNext()) {
|
---|
422 | *_stream << itCmnt.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
|
---|
423 | }
|
---|
424 |
|
---|
425 | *_stream << QString()
|
---|
426 | .leftJustified(60)
|
---|
427 | << "END OF HEADER\n";
|
---|
428 | }
|
---|
429 |
|
---|
430 | //
|
---|
431 | ////////////////////////////////////////////////////////////////////////////
|
---|
432 | void t_rnxNavFile::writeEph(const t_eph* eph) {
|
---|
433 | *_stream << eph->toString(version());
|
---|
434 | }
|
---|