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 |
|
---|
149 | while (stream->status() == QTextStream::Ok && !stream->atEnd()) {
|
---|
150 | QString line = stream->readLine();
|
---|
151 | if (line.isEmpty()) {
|
---|
152 | continue;
|
---|
153 | }
|
---|
154 | QStringList hlp = line.split(QRegExp("\\s+"), QString::SkipEmptyParts);
|
---|
155 | QString prn;
|
---|
156 | if (version() >= 3.0) {
|
---|
157 | prn = hlp.at(0);
|
---|
158 | }
|
---|
159 | else {
|
---|
160 | if (glonass()) {
|
---|
161 | prn = QString("R%1_0").arg(hlp.at(0).toInt(), 2, 10, QChar('0'));
|
---|
162 | }
|
---|
163 | else {
|
---|
164 | prn = QString("G%1_0").arg(hlp.at(0).toInt(), 2, 10, QChar('0'));
|
---|
165 | }
|
---|
166 | }
|
---|
167 |
|
---|
168 | t_eph* eph = 0;
|
---|
169 | QStringList lines; lines << line;
|
---|
170 | if (prn[0] == 'G') {
|
---|
171 | for (int ii = 1; ii < 8; ii++) {
|
---|
172 | lines << stream->readLine();
|
---|
173 | }
|
---|
174 | eph = new t_ephGPS(version(), lines);
|
---|
175 | }
|
---|
176 | else if (prn[0] == 'R') {
|
---|
177 | int num = 4;
|
---|
178 | if (version() >= 3.05) {
|
---|
179 | num += 1;
|
---|
180 | }
|
---|
181 | for (int ii = 1; ii < num; ii++) {
|
---|
182 | lines << stream->readLine();
|
---|
183 | }
|
---|
184 | eph = new t_ephGlo(version(), lines);
|
---|
185 | }
|
---|
186 | else if (prn[0] == 'E') {
|
---|
187 | for (int ii = 1; ii < 8; ii++) {
|
---|
188 | lines << stream->readLine();
|
---|
189 | }
|
---|
190 | eph = new t_ephGal(version(), lines);
|
---|
191 | }
|
---|
192 | else if (prn[0] == 'J') {
|
---|
193 | for (int ii = 1; ii < 8; ii++) {
|
---|
194 | lines << stream->readLine();
|
---|
195 | }
|
---|
196 | eph = new t_ephGPS(version(), lines);
|
---|
197 | }
|
---|
198 | else if (prn[0] == 'S') {
|
---|
199 | for (int ii = 1; ii < 4; ii++) {
|
---|
200 | lines << stream->readLine();
|
---|
201 | }
|
---|
202 | eph = new t_ephSBAS(version(), lines);
|
---|
203 | }
|
---|
204 | else if (prn[0] == 'C') {
|
---|
205 | for (int ii = 1; ii < 8; ii++) {
|
---|
206 | lines << stream->readLine();
|
---|
207 | }
|
---|
208 | eph = new t_ephBDS(version(), lines);
|
---|
209 | }
|
---|
210 | else if (prn[0] == 'I') {
|
---|
211 | for (int ii = 1; ii < 8; ii++) {
|
---|
212 | lines << stream->readLine();
|
---|
213 | }
|
---|
214 | eph = new t_ephGPS(version(), lines);
|
---|
215 | }
|
---|
216 | _ephs.push_back(eph);
|
---|
217 | }
|
---|
218 | }
|
---|
219 |
|
---|
220 | // Read Next Ephemeris
|
---|
221 | ////////////////////////////////////////////////////////////////////////////
|
---|
222 | t_eph* t_rnxNavFile::getNextEph(const bncTime& tt,
|
---|
223 | const QMap<QString, unsigned int>* corrIODs) {
|
---|
224 |
|
---|
225 | // Get Ephemeris according to IOD
|
---|
226 | // ------------------------------
|
---|
227 | if (corrIODs) {
|
---|
228 | QMapIterator<QString, unsigned int> itIOD(*corrIODs);
|
---|
229 | while (itIOD.hasNext()) {
|
---|
230 | itIOD.next();
|
---|
231 | QString prn = itIOD.key();
|
---|
232 | unsigned int iod = itIOD.value();
|
---|
233 | vector<t_eph*>::iterator it = _ephs.begin();
|
---|
234 | while (it != _ephs.end()) {
|
---|
235 | t_eph* eph = *it;
|
---|
236 | double dt = eph->TOC() - tt;
|
---|
237 | if (dt < 8*3600.0 && QString(eph->prn().toInternalString().c_str()) == prn && eph->IOD() == iod) {
|
---|
238 | it = _ephs.erase(it);
|
---|
239 | return eph;
|
---|
240 | }
|
---|
241 | ++it;
|
---|
242 | }
|
---|
243 | }
|
---|
244 | }
|
---|
245 |
|
---|
246 | // Get Ephemeris according to time
|
---|
247 | // -------------------------------
|
---|
248 | else {
|
---|
249 | vector<t_eph*>::iterator it = _ephs.begin();
|
---|
250 | while (it != _ephs.end()) {
|
---|
251 | t_eph* eph = *it;
|
---|
252 | double dt = eph->TOC() - tt;
|
---|
253 | if (dt < 2*3600.0) {
|
---|
254 | it = _ephs.erase(it);
|
---|
255 | return eph;
|
---|
256 | }
|
---|
257 | ++it;
|
---|
258 | }
|
---|
259 | }
|
---|
260 |
|
---|
261 | return 0;
|
---|
262 | }
|
---|
263 |
|
---|
264 | //
|
---|
265 | ////////////////////////////////////////////////////////////////////////////
|
---|
266 | void t_rnxNavFile::writeHeader(const QMap<QString, QString>* txtMap) {
|
---|
267 |
|
---|
268 | QString runBy = BNC_CORE->userName();
|
---|
269 | QStringList comments;
|
---|
270 |
|
---|
271 | if (txtMap) {
|
---|
272 | QMapIterator<QString, QString> it(*txtMap);
|
---|
273 | while (it.hasNext()) {
|
---|
274 | it.next();
|
---|
275 | if (it.key() == "RUN BY") {
|
---|
276 | runBy = it.value();
|
---|
277 | }
|
---|
278 | else if (it.key() == "COMMENT") {
|
---|
279 | comments = it.value().split("\\n", QString::SkipEmptyParts);
|
---|
280 | }
|
---|
281 | }
|
---|
282 | }
|
---|
283 |
|
---|
284 | if (version() < 3.0) {
|
---|
285 | const QString fmt = glonass() ? "%1 GLONASS navigation data"
|
---|
286 | : "%1 Navigation data";
|
---|
287 | *_stream << QString(fmt)
|
---|
288 | .arg(_header._version, 9, 'f', 2)
|
---|
289 | .leftJustified(60)
|
---|
290 | << "RINEX VERSION / TYPE\n";
|
---|
291 | }
|
---|
292 | else {
|
---|
293 | QString fmt;
|
---|
294 | t_eph::e_type sys = satSystem();
|
---|
295 | switch(sys) {
|
---|
296 | case t_eph::GPS:
|
---|
297 | fmt.append("%1 N: GNSS NAV DATA G: GPS");
|
---|
298 | break;
|
---|
299 | case t_eph::GLONASS:
|
---|
300 | fmt.append("%1 N: GNSS NAV DATA R: GLONASS");
|
---|
301 | break;
|
---|
302 | case t_eph::Galileo:
|
---|
303 | fmt.append("%1 N: GNSS NAV DATA E: Galileo");
|
---|
304 | break;
|
---|
305 | case t_eph::QZSS:
|
---|
306 | fmt.append("%1 N: GNSS NAV DATA J: QZSS");
|
---|
307 | break;
|
---|
308 | case t_eph::BDS:
|
---|
309 | fmt.append("%1 N: GNSS NAV DATA C: BDS");
|
---|
310 | break;
|
---|
311 | case t_eph::IRNSS:
|
---|
312 | fmt.append("%1 N: GNSS NAV DATA I: IRNSS");
|
---|
313 | break;
|
---|
314 | case t_eph::SBAS:
|
---|
315 | fmt.append("%1 N: GNSS NAV DATA S: SBAS");
|
---|
316 | break;
|
---|
317 | case t_eph::unknown:
|
---|
318 | fmt.append("%1 N: GNSS NAV DATA M: MIXED");
|
---|
319 | break;
|
---|
320 | }
|
---|
321 | *_stream << fmt
|
---|
322 | .arg(_header._version, 9, 'f', 2)
|
---|
323 | .leftJustified(60)
|
---|
324 | << "RINEX VERSION / TYPE\n";
|
---|
325 | }
|
---|
326 |
|
---|
327 | const QString fmtDate = (version() < 3.0) ? "dd-MMM-yy hh:mm"
|
---|
328 | : "yyyyMMdd hhmmss UTC";
|
---|
329 | *_stream << QString("%1%2%3")
|
---|
330 | .arg(BNC_CORE->pgmName(), -20)
|
---|
331 | .arg(runBy.trimmed().left(20), -20)
|
---|
332 | .arg(QDateTime::currentDateTime().toUTC().toString(fmtDate), -20)
|
---|
333 | .leftJustified(60)
|
---|
334 | << "PGM / RUN BY / DATE\n";
|
---|
335 |
|
---|
336 | QStringListIterator itCmnt(comments);
|
---|
337 | while (itCmnt.hasNext()) {
|
---|
338 | *_stream << itCmnt.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
|
---|
339 | }
|
---|
340 |
|
---|
341 | *_stream << QString()
|
---|
342 | .leftJustified(60)
|
---|
343 | << "END OF HEADER\n";
|
---|
344 | }
|
---|
345 |
|
---|
346 | //
|
---|
347 | ////////////////////////////////////////////////////////////////////////////
|
---|
348 | void t_rnxNavFile::writeEph(const t_eph* eph) {
|
---|
349 | *_stream << eph->toString(version());
|
---|
350 | }
|
---|