[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 |
|
---|
| 48 | using namespace std;
|
---|
| 49 |
|
---|
| 50 | // Constructor
|
---|
| 51 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3657] | 52 | t_rnxNavFile::t_rnxNavHeader::t_rnxNavHeader() {
|
---|
| 53 | _version = 0.0;
|
---|
[3659] | 54 | _glonass = false;
|
---|
[3645] | 55 | }
|
---|
| 56 |
|
---|
| 57 | // Destructor
|
---|
| 58 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3657] | 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.toAscii(), QIODevice::ReadOnly);
|
---|
| 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 | }
|
---|
[3657] | 85 | }
|
---|
| 86 |
|
---|
| 87 | return success;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | // Constructor
|
---|
| 91 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3999] | 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 | }
|
---|
[3657] | 102 | }
|
---|
| 103 |
|
---|
[3999] | 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 |
|
---|
[3657] | 129 | // Destructor
|
---|
| 130 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3645] | 131 | t_rnxNavFile::~t_rnxNavFile() {
|
---|
[3999] | 132 | close();
|
---|
[3758] | 133 | for (unsigned ii = 0; ii < _ephs.size(); ii++) {
|
---|
| 134 | delete _ephs[ii];
|
---|
[7638] | 135 | }
|
---|
[3645] | 136 | }
|
---|
| 137 |
|
---|
[3999] | 138 | // Close
|
---|
| 139 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 140 | void t_rnxNavFile::close() {
|
---|
| 141 | delete _stream; _stream = 0;
|
---|
| 142 | delete _file; _file = 0;
|
---|
| 143 | }
|
---|
| 144 |
|
---|
[3746] | 145 | // Read File Content
|
---|
[3659] | 146 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3746] | 147 | void t_rnxNavFile::read(QTextStream* stream) {
|
---|
[3659] | 148 |
|
---|
[3746] | 149 | while (stream->status() == QTextStream::Ok && !stream->atEnd()) {
|
---|
| 150 | QString line = stream->readLine();
|
---|
[3659] | 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()) {
|
---|
[7638] | 161 | prn = QString("R%1_0").arg(hlp.at(0).toInt(), 2, 10, QChar('0'));
|
---|
[3659] | 162 | }
|
---|
| 163 | else {
|
---|
[7638] | 164 | prn = QString("G%1_0").arg(hlp.at(0).toInt(), 2, 10, QChar('0'));
|
---|
[3659] | 165 | }
|
---|
| 166 | }
|
---|
[7638] | 167 |
|
---|
[3746] | 168 | t_eph* eph = 0;
|
---|
[3659] | 169 | QStringList lines; lines << line;
|
---|
| 170 | if (prn[0] == 'G') {
|
---|
| 171 | for (int ii = 1; ii < 8; ii++) {
|
---|
[3746] | 172 | lines << stream->readLine();
|
---|
[3659] | 173 | }
|
---|
| 174 | eph = new t_ephGPS(version(), lines);
|
---|
| 175 | }
|
---|
| 176 | else if (prn[0] == 'R') {
|
---|
| 177 | for (int ii = 1; ii < 4; ii++) {
|
---|
[3746] | 178 | lines << stream->readLine();
|
---|
[3659] | 179 | }
|
---|
| 180 | eph = new t_ephGlo(version(), lines);
|
---|
| 181 | }
|
---|
| 182 | else if (prn[0] == 'E') {
|
---|
| 183 | for (int ii = 1; ii < 8; ii++) {
|
---|
[3746] | 184 | lines << stream->readLine();
|
---|
[3659] | 185 | }
|
---|
| 186 | eph = new t_ephGal(version(), lines);
|
---|
| 187 | }
|
---|
[6377] | 188 | else if (prn[0] == 'J') {
|
---|
| 189 | for (int ii = 1; ii < 8; ii++) {
|
---|
| 190 | lines << stream->readLine();
|
---|
| 191 | }
|
---|
| 192 | eph = new t_ephGPS(version(), lines);
|
---|
| 193 | }
|
---|
[6391] | 194 | else if (prn[0] == 'S') {
|
---|
| 195 | for (int ii = 1; ii < 4; ii++) {
|
---|
| 196 | lines << stream->readLine();
|
---|
| 197 | }
|
---|
| 198 | eph = new t_ephSBAS(version(), lines);
|
---|
| 199 | }
|
---|
[6399] | 200 | else if (prn[0] == 'C') {
|
---|
| 201 | for (int ii = 1; ii < 8; ii++) {
|
---|
| 202 | lines << stream->readLine();
|
---|
| 203 | }
|
---|
[6600] | 204 | eph = new t_ephBDS(version(), lines);
|
---|
[6399] | 205 | }
|
---|
[7208] | 206 | if (eph &&
|
---|
| 207 | eph->checkState() != t_eph::bad &&
|
---|
| 208 | eph->checkState() != t_eph::outdated) {
|
---|
[3758] | 209 | _ephs.push_back(eph);
|
---|
[3659] | 210 | }
|
---|
[3746] | 211 | else {
|
---|
| 212 | delete eph;
|
---|
| 213 | }
|
---|
[3659] | 214 | }
|
---|
[3746] | 215 | }
|
---|
[3659] | 216 |
|
---|
[3746] | 217 | // Read Next Ephemeris
|
---|
| 218 | ////////////////////////////////////////////////////////////////////////////
|
---|
[7638] | 219 | t_eph* t_rnxNavFile::getNextEph(const bncTime& tt,
|
---|
[7169] | 220 | const QMap<QString, unsigned int>* corrIODs) {
|
---|
[3758] | 221 |
|
---|
[3764] | 222 | // Get Ephemeris according to IOD
|
---|
| 223 | // ------------------------------
|
---|
[3758] | 224 | if (corrIODs) {
|
---|
[7169] | 225 | QMapIterator<QString, unsigned int> itIOD(*corrIODs);
|
---|
[3758] | 226 | while (itIOD.hasNext()) {
|
---|
| 227 | itIOD.next();
|
---|
| 228 | QString prn = itIOD.key();
|
---|
[7169] | 229 | unsigned int iod = itIOD.value();
|
---|
[3758] | 230 | vector<t_eph*>::iterator it = _ephs.begin();
|
---|
| 231 | while (it != _ephs.end()) {
|
---|
| 232 | t_eph* eph = *it;
|
---|
[4150] | 233 | double dt = eph->TOC() - tt;
|
---|
[7039] | 234 | if (dt < 8*3600.0 && QString(eph->prn().toInternalString().c_str()) == prn && eph->IOD() == iod) {
|
---|
[3758] | 235 | it = _ephs.erase(it);
|
---|
| 236 | return eph;
|
---|
| 237 | }
|
---|
| 238 | ++it;
|
---|
| 239 | }
|
---|
[3748] | 240 | }
|
---|
[3746] | 241 | }
|
---|
[3758] | 242 |
|
---|
[3764] | 243 | // Get Ephemeris according to time
|
---|
| 244 | // -------------------------------
|
---|
| 245 | else {
|
---|
| 246 | vector<t_eph*>::iterator it = _ephs.begin();
|
---|
| 247 | while (it != _ephs.end()) {
|
---|
| 248 | t_eph* eph = *it;
|
---|
[4018] | 249 | double dt = eph->TOC() - tt;
|
---|
[3764] | 250 | if (dt < 2*3600.0) {
|
---|
| 251 | it = _ephs.erase(it);
|
---|
| 252 | return eph;
|
---|
| 253 | }
|
---|
| 254 | ++it;
|
---|
| 255 | }
|
---|
| 256 | }
|
---|
| 257 |
|
---|
[3683] | 258 | return 0;
|
---|
[3659] | 259 | }
|
---|
[4004] | 260 |
|
---|
[7638] | 261 | //
|
---|
[4004] | 262 | ////////////////////////////////////////////////////////////////////////////
|
---|
[4219] | 263 | void t_rnxNavFile::writeHeader(const QMap<QString, QString>* txtMap) {
|
---|
[4010] | 264 |
|
---|
[5068] | 265 | QString runBy = BNC_CORE->userName();
|
---|
[4219] | 266 | QStringList comments;
|
---|
| 267 |
|
---|
| 268 | if (txtMap) {
|
---|
| 269 | QMapIterator<QString, QString> it(*txtMap);
|
---|
| 270 | while (it.hasNext()) {
|
---|
| 271 | it.next();
|
---|
| 272 | if (it.key() == "RUN BY") {
|
---|
| 273 | runBy = it.value();
|
---|
| 274 | }
|
---|
| 275 | else if (it.key() == "COMMENT") {
|
---|
| 276 | comments = it.value().split("\\n", QString::SkipEmptyParts);
|
---|
| 277 | }
|
---|
| 278 | }
|
---|
| 279 | }
|
---|
| 280 |
|
---|
[4010] | 281 | if (version() < 3.0) {
|
---|
[7638] | 282 | const QString fmt = glonass() ? "%1 GLONASS navigation data"
|
---|
[4230] | 283 | : "%1 Navigation data";
|
---|
| 284 | *_stream << QString(fmt)
|
---|
[4010] | 285 | .arg(_header._version, 9, 'f', 2)
|
---|
| 286 | .leftJustified(60)
|
---|
| 287 | << "RINEX VERSION / TYPE\n";
|
---|
| 288 | }
|
---|
| 289 | else {
|
---|
[6942] | 290 | *_stream << QString("%1 N: GNSS NAV DATA M: MIXED")
|
---|
[4010] | 291 | .arg(_header._version, 9, 'f', 2)
|
---|
| 292 | .leftJustified(60)
|
---|
| 293 | << "RINEX VERSION / TYPE\n";
|
---|
| 294 | }
|
---|
| 295 |
|
---|
[4232] | 296 | const QString fmtDate = (version() < 3.0) ? "dd-MMM-yy hh:mm"
|
---|
[4231] | 297 | : "yyyyMMdd hhmmss UTC";
|
---|
[4010] | 298 | *_stream << QString("%1%2%3")
|
---|
[5068] | 299 | .arg(BNC_CORE->pgmName(), -20)
|
---|
[4219] | 300 | .arg(runBy.trimmed().left(20), -20)
|
---|
[4231] | 301 | .arg(QDateTime::currentDateTime().toUTC().toString(fmtDate), -20)
|
---|
[4010] | 302 | .leftJustified(60)
|
---|
| 303 | << "PGM / RUN BY / DATE\n";
|
---|
| 304 |
|
---|
[4222] | 305 | QStringListIterator itCmnt(comments);
|
---|
| 306 | while (itCmnt.hasNext()) {
|
---|
| 307 | *_stream << itCmnt.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
|
---|
| 308 | }
|
---|
| 309 |
|
---|
[4010] | 310 | *_stream << QString()
|
---|
| 311 | .leftJustified(60)
|
---|
| 312 | << "END OF HEADER\n";
|
---|
[4004] | 313 | }
|
---|
| 314 |
|
---|
[7638] | 315 | //
|
---|
[4004] | 316 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 317 | void t_rnxNavFile::writeEph(const t_eph* eph) {
|
---|
[4013] | 318 | *_stream << eph->toString(version());
|
---|
[4004] | 319 | }
|
---|