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

Last change on this file since 7908 was 7638, checked in by stuerze, 9 years ago

minor changes

File size: 8.7 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") {
76 QTextStream in(value.toAscii(), QIODevice::ReadOnly);
77 in >> _version;
[3659]78 if (value.indexOf("GLONASS") != -1) {
79 _glonass = true;
80 }
[3657]81 }
82 }
83
84 return success;
85}
86
87// Constructor
88////////////////////////////////////////////////////////////////////////////
[3999]89t_rnxNavFile::t_rnxNavFile(const QString& fileName, e_inpOut inpOut) {
90 _inpOut = inpOut;
91 _stream = 0;
92 _file = 0;
93 if (_inpOut == input) {
94 openRead(fileName);
95 }
96 else {
97 openWrite(fileName);
98 }
[3657]99}
100
[3999]101// Open for input
102////////////////////////////////////////////////////////////////////////////
103void t_rnxNavFile::openRead(const QString& fileName) {
104
105 _fileName = fileName; expandEnvVar(_fileName);
106 _file = new QFile(_fileName);
107 _file->open(QIODevice::ReadOnly | QIODevice::Text);
108 _stream = new QTextStream();
109 _stream->setDevice(_file);
110
111 _header.read(_stream);
112 this->read(_stream);
113}
114
115// Open for output
116////////////////////////////////////////////////////////////////////////////
117void t_rnxNavFile::openWrite(const QString& fileName) {
118
119 _fileName = fileName; expandEnvVar(_fileName);
120 _file = new QFile(_fileName);
121 _file->open(QIODevice::WriteOnly | QIODevice::Text);
122 _stream = new QTextStream();
123 _stream->setDevice(_file);
124}
125
[3657]126// Destructor
127////////////////////////////////////////////////////////////////////////////
[3645]128t_rnxNavFile::~t_rnxNavFile() {
[3999]129 close();
[3758]130 for (unsigned ii = 0; ii < _ephs.size(); ii++) {
131 delete _ephs[ii];
[7638]132 }
[3645]133}
134
[3999]135// Close
136////////////////////////////////////////////////////////////////////////////
137void t_rnxNavFile::close() {
138 delete _stream; _stream = 0;
139 delete _file; _file = 0;
140}
141
[3746]142// Read File Content
[3659]143////////////////////////////////////////////////////////////////////////////
[3746]144void t_rnxNavFile::read(QTextStream* stream) {
[3659]145
[3746]146 while (stream->status() == QTextStream::Ok && !stream->atEnd()) {
147 QString line = stream->readLine();
[3659]148 if (line.isEmpty()) {
149 continue;
150 }
151 QStringList hlp = line.split(QRegExp("\\s+"), QString::SkipEmptyParts);
152 QString prn;
153 if (version() >= 3.0) {
154 prn = hlp.at(0);
155 }
156 else {
157 if (glonass()) {
[7638]158 prn = QString("R%1_0").arg(hlp.at(0).toInt(), 2, 10, QChar('0'));
[3659]159 }
160 else {
[7638]161 prn = QString("G%1_0").arg(hlp.at(0).toInt(), 2, 10, QChar('0'));
[3659]162 }
163 }
[7638]164
[3746]165 t_eph* eph = 0;
[3659]166 QStringList lines; lines << line;
167 if (prn[0] == 'G') {
168 for (int ii = 1; ii < 8; ii++) {
[3746]169 lines << stream->readLine();
[3659]170 }
171 eph = new t_ephGPS(version(), lines);
172 }
173 else if (prn[0] == 'R') {
174 for (int ii = 1; ii < 4; ii++) {
[3746]175 lines << stream->readLine();
[3659]176 }
177 eph = new t_ephGlo(version(), lines);
178 }
179 else if (prn[0] == 'E') {
180 for (int ii = 1; ii < 8; ii++) {
[3746]181 lines << stream->readLine();
[3659]182 }
183 eph = new t_ephGal(version(), lines);
184 }
[6377]185 else if (prn[0] == 'J') {
186 for (int ii = 1; ii < 8; ii++) {
187 lines << stream->readLine();
188 }
189 eph = new t_ephGPS(version(), lines);
190 }
[6391]191 else if (prn[0] == 'S') {
192 for (int ii = 1; ii < 4; ii++) {
193 lines << stream->readLine();
194 }
195 eph = new t_ephSBAS(version(), lines);
196 }
[6399]197 else if (prn[0] == 'C') {
198 for (int ii = 1; ii < 8; ii++) {
199 lines << stream->readLine();
200 }
[6600]201 eph = new t_ephBDS(version(), lines);
[6399]202 }
[7208]203 if (eph &&
204 eph->checkState() != t_eph::bad &&
205 eph->checkState() != t_eph::outdated) {
[3758]206 _ephs.push_back(eph);
[3659]207 }
[3746]208 else {
209 delete eph;
210 }
[3659]211 }
[3746]212}
[3659]213
[3746]214// Read Next Ephemeris
215////////////////////////////////////////////////////////////////////////////
[7638]216t_eph* t_rnxNavFile::getNextEph(const bncTime& tt,
[7169]217 const QMap<QString, unsigned int>* corrIODs) {
[3758]218
[3764]219 // Get Ephemeris according to IOD
220 // ------------------------------
[3758]221 if (corrIODs) {
[7169]222 QMapIterator<QString, unsigned int> itIOD(*corrIODs);
[3758]223 while (itIOD.hasNext()) {
224 itIOD.next();
225 QString prn = itIOD.key();
[7169]226 unsigned int iod = itIOD.value();
[3758]227 vector<t_eph*>::iterator it = _ephs.begin();
228 while (it != _ephs.end()) {
229 t_eph* eph = *it;
[4150]230 double dt = eph->TOC() - tt;
[7039]231 if (dt < 8*3600.0 && QString(eph->prn().toInternalString().c_str()) == prn && eph->IOD() == iod) {
[3758]232 it = _ephs.erase(it);
233 return eph;
234 }
235 ++it;
236 }
[3748]237 }
[3746]238 }
[3758]239
[3764]240 // Get Ephemeris according to time
241 // -------------------------------
242 else {
243 vector<t_eph*>::iterator it = _ephs.begin();
244 while (it != _ephs.end()) {
245 t_eph* eph = *it;
[4018]246 double dt = eph->TOC() - tt;
[3764]247 if (dt < 2*3600.0) {
248 it = _ephs.erase(it);
249 return eph;
250 }
251 ++it;
252 }
253 }
254
[3683]255 return 0;
[3659]256}
[4004]257
[7638]258//
[4004]259////////////////////////////////////////////////////////////////////////////
[4219]260void t_rnxNavFile::writeHeader(const QMap<QString, QString>* txtMap) {
[4010]261
[5068]262 QString runBy = BNC_CORE->userName();
[4219]263 QStringList comments;
264
265 if (txtMap) {
266 QMapIterator<QString, QString> it(*txtMap);
267 while (it.hasNext()) {
268 it.next();
269 if (it.key() == "RUN BY") {
270 runBy = it.value();
271 }
272 else if (it.key() == "COMMENT") {
273 comments = it.value().split("\\n", QString::SkipEmptyParts);
274 }
275 }
276 }
277
[4010]278 if (version() < 3.0) {
[7638]279 const QString fmt = glonass() ? "%1 GLONASS navigation data"
[4230]280 : "%1 Navigation data";
281 *_stream << QString(fmt)
[4010]282 .arg(_header._version, 9, 'f', 2)
283 .leftJustified(60)
284 << "RINEX VERSION / TYPE\n";
285 }
286 else {
[6942]287 *_stream << QString("%1 N: GNSS NAV DATA M: MIXED")
[4010]288 .arg(_header._version, 9, 'f', 2)
289 .leftJustified(60)
290 << "RINEX VERSION / TYPE\n";
291 }
292
[4232]293 const QString fmtDate = (version() < 3.0) ? "dd-MMM-yy hh:mm"
[4231]294 : "yyyyMMdd hhmmss UTC";
[4010]295 *_stream << QString("%1%2%3")
[5068]296 .arg(BNC_CORE->pgmName(), -20)
[4219]297 .arg(runBy.trimmed().left(20), -20)
[4231]298 .arg(QDateTime::currentDateTime().toUTC().toString(fmtDate), -20)
[4010]299 .leftJustified(60)
300 << "PGM / RUN BY / DATE\n";
301
[4222]302 QStringListIterator itCmnt(comments);
303 while (itCmnt.hasNext()) {
304 *_stream << itCmnt.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
305 }
306
[4010]307 *_stream << QString()
308 .leftJustified(60)
309 << "END OF HEADER\n";
[4004]310}
311
[7638]312//
[4004]313////////////////////////////////////////////////////////////////////////////
314void t_rnxNavFile::writeEph(const t_eph* eph) {
[4013]315 *_stream << eph->toString(version());
[4004]316}
Note: See TracBrowser for help on using the repository browser.