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