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 | }
|
---|
86 |
|
---|
87 | return success;
|
---|
88 | }
|
---|
89 |
|
---|
90 | // Constructor
|
---|
91 | ////////////////////////////////////////////////////////////////////////////
|
---|
92 | t_rnxNavFile::t_rnxNavFile(const QString& fileName, e_inpOut inpOut) {
|
---|
93 | _inpOut = inpOut;
|
---|
94 | _stream = 0;
|
---|
95 | _file = 0;
|
---|
96 | if (_inpOut == input) {
|
---|
97 | openRead(fileName);
|
---|
98 | }
|
---|
99 | else {
|
---|
100 | openWrite(fileName);
|
---|
101 | }
|
---|
102 | }
|
---|
103 |
|
---|
104 | // Open for input
|
---|
105 | ////////////////////////////////////////////////////////////////////////////
|
---|
106 | void t_rnxNavFile::openRead(const QString& fileName) {
|
---|
107 |
|
---|
108 | _fileName = fileName; expandEnvVar(_fileName);
|
---|
109 | _file = new QFile(_fileName);
|
---|
110 | _file->open(QIODevice::ReadOnly | QIODevice::Text);
|
---|
111 | _stream = new QTextStream();
|
---|
112 | _stream->setDevice(_file);
|
---|
113 |
|
---|
114 | _header.read(_stream);
|
---|
115 | this->read(_stream);
|
---|
116 | }
|
---|
117 |
|
---|
118 | // Open for output
|
---|
119 | ////////////////////////////////////////////////////////////////////////////
|
---|
120 | void t_rnxNavFile::openWrite(const QString& fileName) {
|
---|
121 |
|
---|
122 | _fileName = fileName; expandEnvVar(_fileName);
|
---|
123 | _file = new QFile(_fileName);
|
---|
124 | _file->open(QIODevice::WriteOnly | QIODevice::Text);
|
---|
125 | _stream = new QTextStream();
|
---|
126 | _stream->setDevice(_file);
|
---|
127 | }
|
---|
128 |
|
---|
129 | // Destructor
|
---|
130 | ////////////////////////////////////////////////////////////////////////////
|
---|
131 | t_rnxNavFile::~t_rnxNavFile() {
|
---|
132 | close();
|
---|
133 | for (unsigned ii = 0; ii < _ephs.size(); ii++) {
|
---|
134 | delete _ephs[ii];
|
---|
135 | }
|
---|
136 | }
|
---|
137 |
|
---|
138 | // Close
|
---|
139 | ////////////////////////////////////////////////////////////////////////////
|
---|
140 | void t_rnxNavFile::close() {
|
---|
141 | delete _stream; _stream = 0;
|
---|
142 | delete _file; _file = 0;
|
---|
143 | }
|
---|
144 |
|
---|
145 | // Read File Content
|
---|
146 | ////////////////////////////////////////////////////////////////////////////
|
---|
147 | void t_rnxNavFile::read(QTextStream* stream) {
|
---|
148 | QString navTypeStr;
|
---|
149 |
|
---|
150 | while (stream->status() == QTextStream::Ok && !stream->atEnd()) {
|
---|
151 |
|
---|
152 | QString line = stream->readLine();
|
---|
153 | if (line.isEmpty()) {
|
---|
154 | continue;
|
---|
155 | }
|
---|
156 |
|
---|
157 | QStringList hlp = line.split(QRegExp("\\s+"), QString::SkipEmptyParts);
|
---|
158 | QString firstStr = hlp.at(0);
|
---|
159 | QString prn;
|
---|
160 |
|
---|
161 | if (version() >= 3.0 && firstStr != ">") {
|
---|
162 | prn = firstStr;
|
---|
163 | }
|
---|
164 | else if (version() >= 4.0 && firstStr == ">") {
|
---|
165 | int lines2skip = 0;
|
---|
166 | QString key = hlp.at(1);
|
---|
167 | // EPH is used
|
---|
168 | if (key == "EPH") {
|
---|
169 | navTypeStr = hlp.at(3);
|
---|
170 | }
|
---|
171 | // all others are currently ignored
|
---|
172 | else if (key == "STO") {
|
---|
173 | lines2skip = 2;
|
---|
174 | }
|
---|
175 | else if (key == "EOP" || key == "ION") {
|
---|
176 | lines2skip = 3;
|
---|
177 | }
|
---|
178 | if (lines2skip) {
|
---|
179 | for (int ii = 1; ii < lines2skip; ii++) {
|
---|
180 | stream->readLine();
|
---|
181 | }
|
---|
182 | }
|
---|
183 | continue;
|
---|
184 | }
|
---|
185 | else {
|
---|
186 | if (glonass()) {
|
---|
187 | prn = QString("R%1_0").arg(hlp.at(0).toInt(), 2, 10, QChar('0'));
|
---|
188 | }
|
---|
189 | else {
|
---|
190 | prn = QString("G%1_0").arg(hlp.at(0).toInt(), 2, 10, QChar('0'));
|
---|
191 | }
|
---|
192 | }
|
---|
193 |
|
---|
194 | t_eph* eph = 0;
|
---|
195 | QStringList lines; lines << line;
|
---|
196 | if (prn[0] == 'G') {
|
---|
197 | for (int ii = 1; ii < 8; ii++) {
|
---|
198 | lines << stream->readLine();
|
---|
199 | }
|
---|
200 | eph = new t_ephGPS(version(), lines);
|
---|
201 | }
|
---|
202 | else if (prn[0] == 'R') {
|
---|
203 | int num = 4;
|
---|
204 | if (version() >= 3.05) {
|
---|
205 | num += 1;
|
---|
206 | }
|
---|
207 | for (int ii = 1; ii < num; ii++) {
|
---|
208 | lines << stream->readLine();
|
---|
209 | }
|
---|
210 | eph = new t_ephGlo(version(), lines);
|
---|
211 | }
|
---|
212 | else if (prn[0] == 'E') {
|
---|
213 | for (int ii = 1; ii < 8; ii++) {
|
---|
214 | lines << stream->readLine();
|
---|
215 | }
|
---|
216 | eph = new t_ephGal(version(), lines);
|
---|
217 | }
|
---|
218 | else if (prn[0] == 'J') {
|
---|
219 | for (int ii = 1; ii < 8; ii++) {
|
---|
220 | lines << stream->readLine();
|
---|
221 | }
|
---|
222 | eph = new t_ephGPS(version(), lines);
|
---|
223 | }
|
---|
224 | else if (prn[0] == 'S') {
|
---|
225 | for (int ii = 1; ii < 4; ii++) {
|
---|
226 | lines << stream->readLine();
|
---|
227 | }
|
---|
228 | eph = new t_ephSBAS(version(), lines);
|
---|
229 | }
|
---|
230 | else if (prn[0] == 'C') {
|
---|
231 | for (int ii = 1; ii < 8; ii++) {
|
---|
232 | lines << stream->readLine();
|
---|
233 | }
|
---|
234 | eph = new t_ephBDS(version(), lines);
|
---|
235 | }
|
---|
236 | else if (prn[0] == 'I') {
|
---|
237 | for (int ii = 1; ii < 8; ii++) {
|
---|
238 | lines << stream->readLine();
|
---|
239 | }
|
---|
240 | eph = new t_ephGPS(version(), lines);
|
---|
241 | }
|
---|
242 | else {
|
---|
243 | continue;
|
---|
244 | }
|
---|
245 | if (version() >= 4.0) {
|
---|
246 | if (eph->setNavType(navTypeStr) != success) {
|
---|
247 | delete eph;
|
---|
248 | continue;
|
---|
249 | }
|
---|
250 | }
|
---|
251 | _ephs.push_back(eph);
|
---|
252 | }
|
---|
253 | }
|
---|
254 |
|
---|
255 | // Read Next Ephemeris
|
---|
256 | ////////////////////////////////////////////////////////////////////////////
|
---|
257 | t_eph* t_rnxNavFile::getNextEph(const bncTime& tt,
|
---|
258 | const QMap<QString, unsigned int>* corrIODs) {
|
---|
259 |
|
---|
260 | // Get Ephemeris according to IOD
|
---|
261 | // ------------------------------
|
---|
262 | if (corrIODs) {
|
---|
263 | QMapIterator<QString, unsigned int> itIOD(*corrIODs);
|
---|
264 | while (itIOD.hasNext()) {
|
---|
265 | itIOD.next();
|
---|
266 | QString prn = itIOD.key();
|
---|
267 | unsigned int iod = itIOD.value();
|
---|
268 | vector<t_eph*>::iterator it = _ephs.begin();
|
---|
269 | while (it != _ephs.end()) {
|
---|
270 | t_eph* eph = *it;
|
---|
271 | double dt = eph->TOC() - tt;
|
---|
272 | if (dt < 8*3600.0 && QString(eph->prn().toInternalString().c_str()) == prn && eph->IOD() == iod) {
|
---|
273 | it = _ephs.erase(it);
|
---|
274 | return eph;
|
---|
275 | }
|
---|
276 | ++it;
|
---|
277 | }
|
---|
278 | }
|
---|
279 | }
|
---|
280 |
|
---|
281 | // Get Ephemeris according to time
|
---|
282 | // -------------------------------
|
---|
283 | else {
|
---|
284 | vector<t_eph*>::iterator it = _ephs.begin();
|
---|
285 | while (it != _ephs.end()) {
|
---|
286 | t_eph* eph = *it;
|
---|
287 | double dt = eph->TOC() - tt;
|
---|
288 | if (dt < 2*3600.0) {
|
---|
289 | it = _ephs.erase(it);
|
---|
290 | return eph;
|
---|
291 | }
|
---|
292 | ++it;
|
---|
293 | }
|
---|
294 | }
|
---|
295 |
|
---|
296 | return 0;
|
---|
297 | }
|
---|
298 |
|
---|
299 | //
|
---|
300 | ////////////////////////////////////////////////////////////////////////////
|
---|
301 | void t_rnxNavFile::writeHeader(const QMap<QString, QString>* txtMap, int numMergedFiles, int leapSecs) {
|
---|
302 |
|
---|
303 | QString runBy = BNC_CORE->userName();
|
---|
304 | QStringList comments;
|
---|
305 |
|
---|
306 | if (txtMap) {
|
---|
307 | QMapIterator<QString, QString> it(*txtMap);
|
---|
308 | while (it.hasNext()) {
|
---|
309 | it.next();
|
---|
310 | if (it.key() == "RUN BY") {
|
---|
311 | runBy = it.value();
|
---|
312 | }
|
---|
313 | else if (it.key() == "COMMENT") {
|
---|
314 | comments = it.value().split("\\n", QString::SkipEmptyParts);
|
---|
315 | }
|
---|
316 | }
|
---|
317 | }
|
---|
318 |
|
---|
319 | if (version() < 3.0) {
|
---|
320 | const QString fmt = glonass() ? "%1 GLONASS navigation data"
|
---|
321 | : "%1 Navigation data";
|
---|
322 | *_stream << QString(fmt)
|
---|
323 | .arg(_header._version, 9, 'f', 2)
|
---|
324 | .leftJustified(60)
|
---|
325 | << "RINEX VERSION / TYPE\n";
|
---|
326 | }
|
---|
327 | else {
|
---|
328 | QString fmt;
|
---|
329 | t_eph::e_type sys = satSystem();
|
---|
330 | switch(sys) {
|
---|
331 | case t_eph::GPS:
|
---|
332 | fmt.append("%1 N: GNSS NAV DATA G: GPS");
|
---|
333 | break;
|
---|
334 | case t_eph::GLONASS:
|
---|
335 | fmt.append("%1 N: GNSS NAV DATA R: GLONASS");
|
---|
336 | break;
|
---|
337 | case t_eph::Galileo:
|
---|
338 | fmt.append("%1 N: GNSS NAV DATA E: Galileo");
|
---|
339 | break;
|
---|
340 | case t_eph::QZSS:
|
---|
341 | fmt.append("%1 N: GNSS NAV DATA J: QZSS");
|
---|
342 | break;
|
---|
343 | case t_eph::BDS:
|
---|
344 | fmt.append("%1 N: GNSS NAV DATA C: BDS");
|
---|
345 | break;
|
---|
346 | case t_eph::IRNSS:
|
---|
347 | fmt.append("%1 N: GNSS NAV DATA I: IRNSS");
|
---|
348 | break;
|
---|
349 | case t_eph::SBAS:
|
---|
350 | fmt.append("%1 N: GNSS NAV DATA S: SBAS");
|
---|
351 | break;
|
---|
352 | case t_eph::unknown:
|
---|
353 | fmt.append("%1 N: GNSS NAV DATA M: MIXED");
|
---|
354 | break;
|
---|
355 | }
|
---|
356 | *_stream << fmt
|
---|
357 | .arg(_header._version, 9, 'f', 2)
|
---|
358 | .leftJustified(60)
|
---|
359 | << "RINEX VERSION / TYPE\n";
|
---|
360 | }
|
---|
361 |
|
---|
362 | const QString fmtDate = (version() < 3.0) ? "dd-MMM-yy hh:mm"
|
---|
363 | : "yyyyMMdd hhmmss UTC";
|
---|
364 | *_stream << QString("%1%2%3")
|
---|
365 | .arg(BNC_CORE->pgmName(), -20)
|
---|
366 | .arg(runBy.trimmed().left(20), -20)
|
---|
367 | .arg(QDateTime::currentDateTime().toUTC().toString(fmtDate), -20)
|
---|
368 | .leftJustified(60)
|
---|
369 | << "PGM / RUN BY / DATE\n";
|
---|
370 |
|
---|
371 | if (version() >= 4.0) {
|
---|
372 | *_stream << QString("%1").arg(leapSecs, 6, 10, QLatin1Char(' ')).left(60).leftJustified(60)
|
---|
373 | << "LEAP SECONDS\n";
|
---|
374 |
|
---|
375 | *_stream << QString("%1").arg(numMergedFiles, 19, 10, QLatin1Char(' ')).leftJustified(60)
|
---|
376 | << "MERGED FILE\n";
|
---|
377 | }
|
---|
378 |
|
---|
379 | QStringListIterator itCmnt(comments);
|
---|
380 | while (itCmnt.hasNext()) {
|
---|
381 | *_stream << itCmnt.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
|
---|
382 | }
|
---|
383 |
|
---|
384 |
|
---|
385 | *_stream << QString()
|
---|
386 | .leftJustified(60)
|
---|
387 | << "END OF HEADER\n";
|
---|
388 | }
|
---|
389 |
|
---|
390 | //
|
---|
391 | ////////////////////////////////////////////////////////////////////////////
|
---|
392 | void t_rnxNavFile::writeEph(const t_eph* eph) {
|
---|
393 | if (version() < 4.0) {
|
---|
394 | if (eph->navType() == t_eph::CNAV ||
|
---|
395 | eph->navType() == t_eph::CNV1 ||
|
---|
396 | eph->navType() == t_eph::CNV2 ||
|
---|
397 | eph->navType() == t_eph::CNV3) {
|
---|
398 | return;
|
---|
399 | }
|
---|
400 | }
|
---|
401 | *_stream << eph->toString(version());
|
---|
402 | }
|
---|