source: ntrip/trunk/BNC/src/rinex/rnxnavfile.cpp@ 10573

Last change on this file since 10573 was 10548, checked in by stuerze, 6 weeks ago

replacement of obsolete qt-class members

File size: 11.2 KB
RevLine 
[3645]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 *
[7638]37 * Changes:
[3645]38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iostream>
[3666]42#include <newmatio.h>
[3645]43#include "rnxnavfile.h"
[5070]44#include "bnccore.h"
[3657]45#include "bncutils.h"
[5738]46#include "ephemeris.h"
[3645]47
48using namespace std;
49
50// Constructor
51////////////////////////////////////////////////////////////////////////////
[3657]52t_rnxNavFile::t_rnxNavHeader::t_rnxNavHeader() {
53 _version = 0.0;
[3659]54 _glonass = false;
[3645]55}
56
57// Destructor
58////////////////////////////////////////////////////////////////////////////
[3657]59t_rnxNavFile::t_rnxNavHeader::~t_rnxNavHeader() {
60}
61
62// Read Header
63////////////////////////////////////////////////////////////////////////////
64t_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") {
[8204]76 QTextStream in(value.toLatin1(), QIODevice::ReadOnly);
[3657]77 in >> _version;
[3659]78 if (value.indexOf("GLONASS") != -1) {
79 _glonass = true;
80 }
[3657]81 }
[7999]82 else if (key == "COMMENT") {
83 _comments.append(value.trimmed());
84 }
[9945]85 else if (key == "PGM / RUN BY / DATE") {
86 _runByDate.append(value.trimmed());
87 }
[3657]88 }
89
90 return success;
91}
92
93// Constructor
94////////////////////////////////////////////////////////////////////////////
[3999]95t_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 }
[3657]105}
106
[3999]107// Open for input
108////////////////////////////////////////////////////////////////////////////
109void 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////////////////////////////////////////////////////////////////////////////
123void 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
[3657]132// Destructor
133////////////////////////////////////////////////////////////////////////////
[3645]134t_rnxNavFile::~t_rnxNavFile() {
[3999]135 close();
[3758]136 for (unsigned ii = 0; ii < _ephs.size(); ii++) {
137 delete _ephs[ii];
[7638]138 }
[3645]139}
140
[3999]141// Close
142////////////////////////////////////////////////////////////////////////////
143void t_rnxNavFile::close() {
144 delete _stream; _stream = 0;
145 delete _file; _file = 0;
146}
147
[3746]148// Read File Content
[3659]149////////////////////////////////////////////////////////////////////////////
[3746]150void t_rnxNavFile::read(QTextStream* stream) {
[9765]151 QString navTypeStr;
[3659]152
[3746]153 while (stream->status() == QTextStream::Ok && !stream->atEnd()) {
[9765]154
[3746]155 QString line = stream->readLine();
[3659]156 if (line.isEmpty()) {
157 continue;
158 }
[9765]159
[10548]160 QStringList hlp = line.split(QRegExp("\\s+"), Qt::SkipEmptyParts);
[9765]161 QString firstStr = hlp.at(0);
[3659]162 QString prn;
[9765]163
164 if (version() >= 3.0 && firstStr != ">") {
165 prn = firstStr;
[3659]166 }
[9765]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 }
[3659]188 else {
189 if (glonass()) {
[7638]190 prn = QString("R%1_0").arg(hlp.at(0).toInt(), 2, 10, QChar('0'));
[3659]191 }
192 else {
[7638]193 prn = QString("G%1_0").arg(hlp.at(0).toInt(), 2, 10, QChar('0'));
[3659]194 }
195 }
[7638]196
[3746]197 t_eph* eph = 0;
[3659]198 QStringList lines; lines << line;
199 if (prn[0] == 'G') {
200 for (int ii = 1; ii < 8; ii++) {
[3746]201 lines << stream->readLine();
[3659]202 }
203 eph = new t_ephGPS(version(), lines);
204 }
205 else if (prn[0] == 'R') {
[9366]206 int num = 4;
207 if (version() >= 3.05) {
208 num += 1;
209 }
210 for (int ii = 1; ii < num; ii++) {
[3746]211 lines << stream->readLine();
[3659]212 }
213 eph = new t_ephGlo(version(), lines);
214 }
215 else if (prn[0] == 'E') {
216 for (int ii = 1; ii < 8; ii++) {
[3746]217 lines << stream->readLine();
[3659]218 }
219 eph = new t_ephGal(version(), lines);
220 }
[6377]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 }
[6391]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 }
[6399]233 else if (prn[0] == 'C') {
234 for (int ii = 1; ii < 8; ii++) {
235 lines << stream->readLine();
236 }
[6600]237 eph = new t_ephBDS(version(), lines);
[6399]238 }
[8168]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 }
[10525]245
[10318]246 if (version() >= 4.0) {
[9765]247 if (eph->setNavType(navTypeStr) != success) {
248 delete eph;
249 continue;
250 }
251 }
[10525]252
[10318]253 if (eph) {
254 _ephs.push_back(eph);
255 }
[3659]256 }
[3746]257}
[3659]258
[3746]259// Read Next Ephemeris
260////////////////////////////////////////////////////////////////////////////
[7638]261t_eph* t_rnxNavFile::getNextEph(const bncTime& tt,
[7169]262 const QMap<QString, unsigned int>* corrIODs) {
[3758]263
[3764]264 // Get Ephemeris according to IOD
265 // ------------------------------
[3758]266 if (corrIODs) {
[7169]267 QMapIterator<QString, unsigned int> itIOD(*corrIODs);
[3758]268 while (itIOD.hasNext()) {
269 itIOD.next();
270 QString prn = itIOD.key();
[7169]271 unsigned int iod = itIOD.value();
[3758]272 vector<t_eph*>::iterator it = _ephs.begin();
273 while (it != _ephs.end()) {
274 t_eph* eph = *it;
[4150]275 double dt = eph->TOC() - tt;
[7039]276 if (dt < 8*3600.0 && QString(eph->prn().toInternalString().c_str()) == prn && eph->IOD() == iod) {
[3758]277 it = _ephs.erase(it);
278 return eph;
279 }
280 ++it;
281 }
[3748]282 }
[3746]283 }
[3758]284
[3764]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;
[4018]291 double dt = eph->TOC() - tt;
[3764]292 if (dt < 2*3600.0) {
293 it = _ephs.erase(it);
294 return eph;
295 }
296 ++it;
297 }
298 }
299
[3683]300 return 0;
[3659]301}
[4004]302
[7638]303//
[4004]304////////////////////////////////////////////////////////////////////////////
[9765]305void t_rnxNavFile::writeHeader(const QMap<QString, QString>* txtMap, int numMergedFiles, int leapSecs) {
[4010]306
[5068]307 QString runBy = BNC_CORE->userName();
[4219]308 QStringList comments;
[9945]309 QStringList runByDate;
[4219]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 }
[9945]318 else if (it.key() == "RUN BY DATE") {
[10548]319 runByDate = it.value().split("\\n", Qt::SkipEmptyParts);
[9945]320 }
[4219]321 else if (it.key() == "COMMENT") {
[10548]322 comments = it.value().split("\\n", Qt::SkipEmptyParts);
[4219]323 }
324 }
325 }
326
[4010]327 if (version() < 3.0) {
[7638]328 const QString fmt = glonass() ? "%1 GLONASS navigation data"
[4230]329 : "%1 Navigation data";
330 *_stream << QString(fmt)
[4010]331 .arg(_header._version, 9, 'f', 2)
332 .leftJustified(60)
333 << "RINEX VERSION / TYPE\n";
334 }
335 else {
[8354]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
[4010]365 .arg(_header._version, 9, 'f', 2)
366 .leftJustified(60)
367 << "RINEX VERSION / TYPE\n";
368 }
369
[4232]370 const QString fmtDate = (version() < 3.0) ? "dd-MMM-yy hh:mm"
[4231]371 : "yyyyMMdd hhmmss UTC";
[4010]372 *_stream << QString("%1%2%3")
[5068]373 .arg(BNC_CORE->pgmName(), -20)
[4219]374 .arg(runBy.trimmed().left(20), -20)
[4231]375 .arg(QDateTime::currentDateTime().toUTC().toString(fmtDate), -20)
[4010]376 .leftJustified(60)
377 << "PGM / RUN BY / DATE\n";
378
[9765]379 if (version() >= 4.0) {
[9945]380 QStringListIterator itRunByDt(runByDate);
381 while (itRunByDt.hasNext()) {
382 *_stream << itRunByDt.next().trimmed().left(60).leftJustified(60)
383 << "PGM / RUN BY / DATE\n";
384 }
[9765]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
[4222]392 QStringListIterator itCmnt(comments);
393 while (itCmnt.hasNext()) {
394 *_stream << itCmnt.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
395 }
396
[4010]397 *_stream << QString()
398 .leftJustified(60)
399 << "END OF HEADER\n";
[4004]400}
401
[7638]402//
[4004]403////////////////////////////////////////////////////////////////////////////
404void t_rnxNavFile::writeEph(const t_eph* eph) {
[4013]405 *_stream << eph->toString(version());
[4004]406}
Note: See TracBrowser for help on using the repository browser.