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

Last change on this file since 9945 was 9945, checked in by stuerze, 16 months ago

multiple 'run by date' entries for rinex version 4 added

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
[3659]160 QStringList hlp = line.split(QRegExp("\\s+"), QString::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 }
[9765]245 else {
246 continue;
247 }
248 if (version() >= 4.0) {
249 if (eph->setNavType(navTypeStr) != success) {
250 delete eph;
251 continue;
252 }
253 }
[8368]254 _ephs.push_back(eph);
[3659]255 }
[3746]256}
[3659]257
[3746]258// Read Next Ephemeris
259////////////////////////////////////////////////////////////////////////////
[7638]260t_eph* t_rnxNavFile::getNextEph(const bncTime& tt,
[7169]261 const QMap<QString, unsigned int>* corrIODs) {
[3758]262
[3764]263 // Get Ephemeris according to IOD
264 // ------------------------------
[3758]265 if (corrIODs) {
[7169]266 QMapIterator<QString, unsigned int> itIOD(*corrIODs);
[3758]267 while (itIOD.hasNext()) {
268 itIOD.next();
269 QString prn = itIOD.key();
[7169]270 unsigned int iod = itIOD.value();
[3758]271 vector<t_eph*>::iterator it = _ephs.begin();
272 while (it != _ephs.end()) {
273 t_eph* eph = *it;
[4150]274 double dt = eph->TOC() - tt;
[7039]275 if (dt < 8*3600.0 && QString(eph->prn().toInternalString().c_str()) == prn && eph->IOD() == iod) {
[3758]276 it = _ephs.erase(it);
277 return eph;
278 }
279 ++it;
280 }
[3748]281 }
[3746]282 }
[3758]283
[3764]284 // Get Ephemeris according to time
285 // -------------------------------
286 else {
287 vector<t_eph*>::iterator it = _ephs.begin();
288 while (it != _ephs.end()) {
289 t_eph* eph = *it;
[4018]290 double dt = eph->TOC() - tt;
[3764]291 if (dt < 2*3600.0) {
292 it = _ephs.erase(it);
293 return eph;
294 }
295 ++it;
296 }
297 }
298
[3683]299 return 0;
[3659]300}
[4004]301
[7638]302//
[4004]303////////////////////////////////////////////////////////////////////////////
[9765]304void t_rnxNavFile::writeHeader(const QMap<QString, QString>* txtMap, int numMergedFiles, int leapSecs) {
[4010]305
[5068]306 QString runBy = BNC_CORE->userName();
[4219]307 QStringList comments;
[9945]308 QStringList runByDate;
[4219]309
310 if (txtMap) {
311 QMapIterator<QString, QString> it(*txtMap);
312 while (it.hasNext()) {
313 it.next();
314 if (it.key() == "RUN BY") {
315 runBy = it.value();
316 }
[9945]317 else if (it.key() == "RUN BY DATE") {
318 runByDate = it.value().split("\\n", QString::SkipEmptyParts);
319 }
[4219]320 else if (it.key() == "COMMENT") {
321 comments = it.value().split("\\n", QString::SkipEmptyParts);
322 }
323 }
324 }
325
[4010]326 if (version() < 3.0) {
[7638]327 const QString fmt = glonass() ? "%1 GLONASS navigation data"
[4230]328 : "%1 Navigation data";
329 *_stream << QString(fmt)
[4010]330 .arg(_header._version, 9, 'f', 2)
331 .leftJustified(60)
332 << "RINEX VERSION / TYPE\n";
333 }
334 else {
[8354]335 QString fmt;
336 t_eph::e_type sys = satSystem();
337 switch(sys) {
338 case t_eph::GPS:
339 fmt.append("%1 N: GNSS NAV DATA G: GPS");
340 break;
341 case t_eph::GLONASS:
342 fmt.append("%1 N: GNSS NAV DATA R: GLONASS");
343 break;
344 case t_eph::Galileo:
345 fmt.append("%1 N: GNSS NAV DATA E: Galileo");
346 break;
347 case t_eph::QZSS:
348 fmt.append("%1 N: GNSS NAV DATA J: QZSS");
349 break;
350 case t_eph::BDS:
351 fmt.append("%1 N: GNSS NAV DATA C: BDS");
352 break;
353 case t_eph::IRNSS:
354 fmt.append("%1 N: GNSS NAV DATA I: IRNSS");
355 break;
356 case t_eph::SBAS:
357 fmt.append("%1 N: GNSS NAV DATA S: SBAS");
358 break;
359 case t_eph::unknown:
360 fmt.append("%1 N: GNSS NAV DATA M: MIXED");
361 break;
362 }
363 *_stream << fmt
[4010]364 .arg(_header._version, 9, 'f', 2)
365 .leftJustified(60)
366 << "RINEX VERSION / TYPE\n";
367 }
368
[4232]369 const QString fmtDate = (version() < 3.0) ? "dd-MMM-yy hh:mm"
[4231]370 : "yyyyMMdd hhmmss UTC";
[4010]371 *_stream << QString("%1%2%3")
[5068]372 .arg(BNC_CORE->pgmName(), -20)
[4219]373 .arg(runBy.trimmed().left(20), -20)
[4231]374 .arg(QDateTime::currentDateTime().toUTC().toString(fmtDate), -20)
[4010]375 .leftJustified(60)
376 << "PGM / RUN BY / DATE\n";
377
[9765]378 if (version() >= 4.0) {
[9945]379 QStringListIterator itRunByDt(runByDate);
380 while (itRunByDt.hasNext()) {
381 *_stream << itRunByDt.next().trimmed().left(60).leftJustified(60)
382 << "PGM / RUN BY / DATE\n";
383 }
[9765]384 *_stream << QString("%1").arg(leapSecs, 6, 10, QLatin1Char(' ')).left(60).leftJustified(60)
385 << "LEAP SECONDS\n";
386
387 *_stream << QString("%1").arg(numMergedFiles, 19, 10, QLatin1Char(' ')).leftJustified(60)
388 << "MERGED FILE\n";
389 }
390
[4222]391 QStringListIterator itCmnt(comments);
392 while (itCmnt.hasNext()) {
393 *_stream << itCmnt.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
394 }
395
[4010]396 *_stream << QString()
397 .leftJustified(60)
398 << "END OF HEADER\n";
[4004]399}
400
[7638]401//
[4004]402////////////////////////////////////////////////////////////////////////////
403void t_rnxNavFile::writeEph(const t_eph* eph) {
[4013]404 *_stream << eph->toString(version());
[4004]405}
Note: See TracBrowser for help on using the repository browser.