[3716] | 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_rnxObsFile
|
---|
| 30 | *
|
---|
| 31 | * Purpose: Reads RINEX Observation File
|
---|
| 32 | *
|
---|
| 33 | * Author: L. Mervart
|
---|
| 34 | *
|
---|
| 35 | * Created: 24-Jan-2012
|
---|
| 36 | *
|
---|
| 37 | * Changes:
|
---|
| 38 | *
|
---|
| 39 | * -----------------------------------------------------------------------*/
|
---|
| 40 |
|
---|
| 41 | #include <iostream>
|
---|
| 42 | #include <iomanip>
|
---|
| 43 | #include <sstream>
|
---|
[3722] | 44 | #include "rnxobsfile.h"
|
---|
[3716] | 45 | #include "bncutils.h"
|
---|
[5070] | 46 | #include "bnccore.h"
|
---|
[3716] | 47 |
|
---|
| 48 | using namespace std;
|
---|
| 49 |
|
---|
[6119] | 50 | const QString t_rnxObsHeader::defaultSystems = "GRES";
|
---|
[3716] | 51 |
|
---|
| 52 | // Constructor
|
---|
| 53 | ////////////////////////////////////////////////////////////////////////////
|
---|
[4480] | 54 | t_rnxObsHeader::t_rnxObsHeader() {
|
---|
[3716] | 55 | _antNEU.ReSize(3); _antNEU = 0.0;
|
---|
| 56 | _antXYZ.ReSize(3); _antXYZ = 0.0;
|
---|
| 57 | _antBSG.ReSize(3); _antBSG = 0.0;
|
---|
| 58 | _xyz.ReSize(3); _xyz = 0.0;
|
---|
| 59 | _version = 0.0;
|
---|
| 60 | _interval = 0.0;
|
---|
[5742] | 61 | for (unsigned iPrn = 1; iPrn <= t_prn::MAXPRN_GPS; iPrn++) {
|
---|
[3716] | 62 | _wlFactorsL1[iPrn] = 1;
|
---|
| 63 | _wlFactorsL2[iPrn] = 1;
|
---|
| 64 | }
|
---|
| 65 | }
|
---|
| 66 |
|
---|
| 67 | // Destructor
|
---|
| 68 | ////////////////////////////////////////////////////////////////////////////
|
---|
[4480] | 69 | t_rnxObsHeader::~t_rnxObsHeader() {
|
---|
[3716] | 70 | }
|
---|
| 71 |
|
---|
| 72 | // Read Header
|
---|
| 73 | ////////////////////////////////////////////////////////////////////////////
|
---|
[4480] | 74 | t_irc t_rnxObsHeader::read(QTextStream* stream, int maxLines) {
|
---|
[4534] | 75 | _comments.clear();
|
---|
[3716] | 76 | int numLines = 0;
|
---|
[3718] | 77 | while ( stream->status() == QTextStream::Ok && !stream->atEnd() ) {
|
---|
| 78 | QString line = stream->readLine(); ++ numLines;
|
---|
| 79 | if (line.isEmpty()) {
|
---|
[3716] | 80 | continue;
|
---|
| 81 | }
|
---|
[3718] | 82 | if (line.indexOf("END OF FILE") != -1) {
|
---|
[3716] | 83 | break;
|
---|
| 84 | }
|
---|
[3718] | 85 | QString value = line.mid(0,60).trimmed();
|
---|
| 86 | QString key = line.mid(60).trimmed();
|
---|
[3716] | 87 | if (key == "END OF HEADER") {
|
---|
| 88 | break;
|
---|
| 89 | }
|
---|
| 90 | else if (key == "RINEX VERSION / TYPE") {
|
---|
[3718] | 91 | QTextStream in(value.toAscii(), QIODevice::ReadOnly);
|
---|
[3716] | 92 | in >> _version;
|
---|
| 93 | }
|
---|
| 94 | else if (key == "MARKER NAME") {
|
---|
| 95 | _markerName = value;
|
---|
| 96 | }
|
---|
[3930] | 97 | else if (key == "MARKER NUMBER") {
|
---|
| 98 | _markerNumber = line.mid(0,20).trimmed();
|
---|
| 99 | }
|
---|
[3716] | 100 | else if (key == "ANT # / TYPE") {
|
---|
[3930] | 101 | _antennaNumber = line.mid( 0,20).trimmed();
|
---|
| 102 | _antennaName = line.mid(20,20).trimmed();
|
---|
[3716] | 103 | }
|
---|
[3930] | 104 | else if (key == "OBSERVER / AGENCY") {
|
---|
| 105 | _observer = line.mid( 0,20).trimmed();
|
---|
| 106 | _agency = line.mid(20,40).trimmed();
|
---|
| 107 | }
|
---|
| 108 | else if (key == "REC # / TYPE / VERS") {
|
---|
| 109 | _receiverNumber = line.mid( 0,20).trimmed();
|
---|
| 110 | _receiverType = line.mid(20,20).trimmed();
|
---|
| 111 | _receiverVersion = line.mid(40,20).trimmed();
|
---|
| 112 | }
|
---|
[3716] | 113 | else if (key == "INTERVAL") {
|
---|
[3718] | 114 | QTextStream in(value.toAscii(), QIODevice::ReadOnly);
|
---|
[3716] | 115 | in >> _interval;
|
---|
| 116 | }
|
---|
[4494] | 117 | else if (key == "COMMENT") {
|
---|
| 118 | _comments << line.mid(0,60).trimmed();
|
---|
| 119 | }
|
---|
[3716] | 120 | else if (key == "WAVELENGTH FACT L1/2") {
|
---|
[3718] | 121 | QTextStream in(value.toAscii(), QIODevice::ReadOnly);
|
---|
[3716] | 122 | int wlFactL1 = 0;
|
---|
| 123 | int wlFactL2 = 0;
|
---|
| 124 | int numSat = 0;
|
---|
| 125 | in >> wlFactL1 >> wlFactL2 >> numSat;
|
---|
| 126 | if (numSat == 0) {
|
---|
[5742] | 127 | for (unsigned iPrn = 1; iPrn <= t_prn::MAXPRN_GPS; iPrn++) {
|
---|
[3716] | 128 | _wlFactorsL1[iPrn] = wlFactL1;
|
---|
| 129 | _wlFactorsL2[iPrn] = wlFactL2;
|
---|
| 130 | }
|
---|
| 131 | }
|
---|
| 132 | else {
|
---|
| 133 | for (int ii = 0; ii < numSat; ii++) {
|
---|
[3718] | 134 | QString prn; in >> prn;
|
---|
[3716] | 135 | if (prn[0] == 'G') {
|
---|
| 136 | int iPrn;
|
---|
| 137 | readInt(prn, 1, 2, iPrn);
|
---|
| 138 | _wlFactorsL1[iPrn] = wlFactL1;
|
---|
| 139 | _wlFactorsL2[iPrn] = wlFactL2;
|
---|
| 140 | }
|
---|
| 141 | }
|
---|
| 142 | }
|
---|
| 143 | }
|
---|
| 144 | else if (key == "APPROX POSITION XYZ") {
|
---|
[3718] | 145 | QTextStream in(value.toAscii(), QIODevice::ReadOnly);
|
---|
[3716] | 146 | in >> _xyz[0] >> _xyz[1] >> _xyz[2];
|
---|
| 147 | }
|
---|
| 148 | else if (key == "ANTENNA: DELTA H/E/N") {
|
---|
[3718] | 149 | QTextStream in(value.toAscii(), QIODevice::ReadOnly);
|
---|
[3716] | 150 | in >> _antNEU[2] >> _antNEU[1] >> _antNEU[0];
|
---|
| 151 | }
|
---|
| 152 | else if (key == "ANTENNA: DELTA X/Y/Z") {
|
---|
[3718] | 153 | QTextStream in(value.toAscii(), QIODevice::ReadOnly);
|
---|
[3716] | 154 | in >> _antXYZ[0] >> _antXYZ[1] >> _antXYZ[2];
|
---|
| 155 | }
|
---|
| 156 | else if (key == "ANTENNA: B.SIGHT XYZ") {
|
---|
[3718] | 157 | QTextStream in(value.toAscii(), QIODevice::ReadOnly);
|
---|
[3716] | 158 | in >> _antBSG[0] >> _antBSG[1] >> _antBSG[2];
|
---|
| 159 | }
|
---|
| 160 | else if (key == "# / TYPES OF OBSERV") {
|
---|
[3864] | 161 | QTextStream* in = new QTextStream(value.toAscii(), QIODevice::ReadOnly);
|
---|
[3716] | 162 | int nTypes;
|
---|
[3864] | 163 | *in >> nTypes;
|
---|
[6125] | 164 | char sys0 = defaultSystems[0].toAscii();
|
---|
| 165 | _obsTypes[sys0].clear();
|
---|
[3716] | 166 | for (int ii = 0; ii < nTypes; ii++) {
|
---|
[3864] | 167 | if (ii > 0 && ii % 9 == 0) {
|
---|
| 168 | line = stream->readLine(); ++numLines;
|
---|
| 169 | delete in;
|
---|
[4152] | 170 | in = new QTextStream(line.left(60).toAscii(), QIODevice::ReadOnly);
|
---|
[3864] | 171 | }
|
---|
[3718] | 172 | QString hlp;
|
---|
[3864] | 173 | *in >> hlp;
|
---|
[6125] | 174 | _obsTypes[sys0].append(hlp);
|
---|
[3716] | 175 | }
|
---|
[6119] | 176 | for (int ii = 1; ii < defaultSystems.length(); ii++) {
|
---|
[6125] | 177 | char sysI = defaultSystems[ii].toAscii();
|
---|
| 178 | _obsTypes[sysI] = _obsTypes[sys0];
|
---|
[6119] | 179 | }
|
---|
[3716] | 180 | }
|
---|
| 181 | else if (key == "SYS / # / OBS TYPES") {
|
---|
[3718] | 182 | QTextStream* in = new QTextStream(value.toAscii(), QIODevice::ReadOnly);
|
---|
[3716] | 183 | char sys;
|
---|
| 184 | int nTypes;
|
---|
| 185 | *in >> sys >> nTypes;
|
---|
[6119] | 186 | _obsTypes[sys].clear();
|
---|
[3716] | 187 | for (int ii = 0; ii < nTypes; ii++) {
|
---|
| 188 | if (ii > 0 && ii % 13 == 0) {
|
---|
[3718] | 189 | line = stream->readLine(); ++numLines;
|
---|
[3716] | 190 | delete in;
|
---|
[3718] | 191 | in = new QTextStream(line.toAscii(), QIODevice::ReadOnly);
|
---|
[3716] | 192 | }
|
---|
[3718] | 193 | QString hlp;
|
---|
[3716] | 194 | *in >> hlp;
|
---|
[6119] | 195 | _obsTypes[sys].push_back(hlp);
|
---|
[3716] | 196 | }
|
---|
| 197 | delete in;
|
---|
| 198 | }
|
---|
[3837] | 199 | else if (key == "TIME OF FIRST OBS") {
|
---|
| 200 | QTextStream in(value.toAscii(), QIODevice::ReadOnly);
|
---|
| 201 | int year, month, day, hour, min;
|
---|
| 202 | double sec;
|
---|
| 203 | in >> year >> month >> day >> hour >> min >> sec;
|
---|
| 204 | _startTime.set(year, month, day, hour, min, sec);
|
---|
| 205 | }
|
---|
[3716] | 206 | if (maxLines > 0 && numLines == maxLines) {
|
---|
| 207 | break;
|
---|
| 208 | }
|
---|
| 209 | }
|
---|
| 210 |
|
---|
| 211 | return success;
|
---|
| 212 | }
|
---|
| 213 |
|
---|
[4481] | 214 | // Write Header
|
---|
| 215 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 216 | void t_rnxObsHeader::write(QTextStream* stream,
|
---|
| 217 | const QMap<QString, QString>* txtMap) const {
|
---|
| 218 |
|
---|
[4493] | 219 | QStringList newComments;
|
---|
[5068] | 220 | QString runBy = BNC_CORE->userName();
|
---|
[4481] | 221 |
|
---|
| 222 | if (txtMap) {
|
---|
| 223 | QMapIterator<QString, QString> it(*txtMap);
|
---|
| 224 | while (it.hasNext()) {
|
---|
| 225 | it.next();
|
---|
| 226 | if (it.key() == "RUN BY") {
|
---|
| 227 | runBy = it.value();
|
---|
| 228 | }
|
---|
| 229 | else if (it.key() == "COMMENT") {
|
---|
[4493] | 230 | newComments = it.value().split("\\n", QString::SkipEmptyParts);
|
---|
[4481] | 231 | }
|
---|
| 232 | }
|
---|
| 233 | }
|
---|
| 234 |
|
---|
| 235 | *stream << QString("%1 Observation data Mixed")
|
---|
| 236 | .arg(_version, 9, 'f', 2)
|
---|
| 237 | .leftJustified(60)
|
---|
| 238 | << "RINEX VERSION / TYPE\n";
|
---|
| 239 |
|
---|
| 240 | const QString fmtDate = (_version < 3.0) ? "dd-MMM-yy hh:mm"
|
---|
| 241 | : "yyyyMMdd hhmmss UTC";
|
---|
| 242 | *stream << QString("%1%2%3")
|
---|
[5068] | 243 | .arg(BNC_CORE->pgmName(), -20)
|
---|
[4481] | 244 | .arg(runBy.trimmed().left(20), -20)
|
---|
| 245 | .arg(QDateTime::currentDateTime().toUTC().toString(fmtDate), -20)
|
---|
| 246 | .leftJustified(60)
|
---|
| 247 | << "PGM / RUN BY / DATE\n";
|
---|
| 248 |
|
---|
[4493] | 249 | QStringListIterator itCmnt(_comments + newComments);
|
---|
[4481] | 250 | while (itCmnt.hasNext()) {
|
---|
| 251 | *stream << itCmnt.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
|
---|
| 252 | }
|
---|
| 253 |
|
---|
| 254 | *stream << QString("%1")
|
---|
| 255 | .arg(_markerName, -60)
|
---|
| 256 | .leftJustified(60)
|
---|
| 257 | << "MARKER NAME\n";
|
---|
| 258 |
|
---|
| 259 | if (!_markerNumber.isEmpty()) {
|
---|
| 260 | *stream << QString("%1")
|
---|
| 261 | .arg(_markerNumber, -20)
|
---|
| 262 | .leftJustified(60)
|
---|
| 263 | << "MARKER NUMBER\n";
|
---|
| 264 | }
|
---|
| 265 |
|
---|
| 266 | *stream << QString("%1%2")
|
---|
[4529] | 267 | .arg(_observer, -20)
|
---|
| 268 | .arg(_agency, -40)
|
---|
[4481] | 269 | .leftJustified(60)
|
---|
| 270 | << "OBSERVER / AGENCY\n";
|
---|
| 271 |
|
---|
| 272 | *stream << QString("%1%2%3")
|
---|
[4529] | 273 | .arg(_receiverNumber, -20)
|
---|
| 274 | .arg(_receiverType, -20)
|
---|
| 275 | .arg(_receiverVersion, -20)
|
---|
[4481] | 276 | .leftJustified(60)
|
---|
| 277 | << "REC # / TYPE / VERS\n";
|
---|
| 278 |
|
---|
| 279 | *stream << QString("%1%2")
|
---|
[4529] | 280 | .arg(_antennaNumber, -20)
|
---|
| 281 | .arg(_antennaName, -20)
|
---|
[4481] | 282 | .leftJustified(60)
|
---|
| 283 | << "ANT # / TYPE\n";
|
---|
| 284 |
|
---|
| 285 | *stream << QString("%1%2%3")
|
---|
| 286 | .arg(_xyz(1), 14, 'f', 4)
|
---|
| 287 | .arg(_xyz(2), 14, 'f', 4)
|
---|
| 288 | .arg(_xyz(3), 14, 'f', 4)
|
---|
| 289 | .leftJustified(60)
|
---|
| 290 | << "APPROX POSITION XYZ\n";
|
---|
| 291 |
|
---|
| 292 | *stream << QString("%1%2%3")
|
---|
| 293 | .arg(_antNEU(3), 14, 'f', 4)
|
---|
| 294 | .arg(_antNEU(2), 14, 'f', 4)
|
---|
| 295 | .arg(_antNEU(1), 14, 'f', 4)
|
---|
| 296 | .leftJustified(60)
|
---|
| 297 | << "ANTENNA: DELTA H/E/N\n";
|
---|
| 298 |
|
---|
| 299 | if (_version < 3.0) {
|
---|
| 300 | int defaultWlFact1 = _wlFactorsL1[1];
|
---|
| 301 | int defaultWlFact2 = _wlFactorsL2[1]; // TODO check all prns
|
---|
| 302 | *stream << QString("%1%2")
|
---|
| 303 | .arg(defaultWlFact1, 6)
|
---|
| 304 | .arg(defaultWlFact2, 6)
|
---|
| 305 | .leftJustified(60)
|
---|
| 306 | << "WAVELENGTH FACT L1/2\n";
|
---|
| 307 | }
|
---|
| 308 |
|
---|
| 309 | *stream << obsTypesStrings().join("");
|
---|
| 310 |
|
---|
[4484] | 311 | if (_interval > 0) {
|
---|
| 312 | *stream << QString("%1")
|
---|
| 313 | .arg(_interval, 10, 'f', 3)
|
---|
| 314 | .leftJustified(60)
|
---|
| 315 | << "INTERVAL\n";
|
---|
| 316 | }
|
---|
[4481] | 317 |
|
---|
| 318 | unsigned year, month, day, hour, min;
|
---|
| 319 | double sec;
|
---|
| 320 | _startTime.civil_date(year, month, day);
|
---|
| 321 | _startTime.civil_time(hour, min, sec);
|
---|
| 322 | *stream << QString("%1%2%3%4%5%6%7")
|
---|
| 323 | .arg(year, 6)
|
---|
| 324 | .arg(month, 6)
|
---|
| 325 | .arg(day, 6)
|
---|
| 326 | .arg(hour, 6)
|
---|
| 327 | .arg(min, 6)
|
---|
| 328 | .arg(sec, 13, 'f', 7)
|
---|
| 329 | .arg("GPS", 8)
|
---|
| 330 | .leftJustified(60)
|
---|
| 331 | << "TIME OF FIRST OBS\n";
|
---|
| 332 |
|
---|
| 333 | *stream << QString()
|
---|
| 334 | .leftJustified(60)
|
---|
| 335 | << "END OF HEADER\n";
|
---|
| 336 | }
|
---|
| 337 |
|
---|
[6119] | 338 | // Number of Different Systems
|
---|
| 339 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 340 | int t_rnxObsHeader::numSys() const {
|
---|
| 341 | return _obsTypes.size();
|
---|
| 342 | }
|
---|
| 343 |
|
---|
[3716] | 344 | // Number of Observation Types (satellite-system specific)
|
---|
| 345 | ////////////////////////////////////////////////////////////////////////////
|
---|
[4480] | 346 | int t_rnxObsHeader::nTypes(char sys) const {
|
---|
[6119] | 347 | if (_obsTypes.contains(sys)) {
|
---|
| 348 | return _obsTypes[sys].size();
|
---|
[3716] | 349 | }
|
---|
| 350 | else {
|
---|
[6119] | 351 | return 0;
|
---|
[3716] | 352 | }
|
---|
| 353 | }
|
---|
| 354 |
|
---|
| 355 | // Observation Type (satellite-system specific)
|
---|
| 356 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6126] | 357 | QString t_rnxObsHeader::obsType(char sys, int index, double version) const {
|
---|
| 358 |
|
---|
| 359 | if (version == 0.0) {
|
---|
| 360 | version = _version;
|
---|
| 361 | }
|
---|
[6119] | 362 | if (_obsTypes.contains(sys)) {
|
---|
[6126] | 363 | QString origType = _obsTypes[sys].at(index);
|
---|
| 364 | if (int(version) == int(_version)) {
|
---|
| 365 | return origType;
|
---|
| 366 | }
|
---|
| 367 | else if (int(version) == 2) {
|
---|
| 368 | return t_rnxObsFile::type3to2(origType);
|
---|
| 369 | }
|
---|
| 370 | else if (int(version) == 3) {
|
---|
| 371 | return t_rnxObsFile::type2to3(sys, origType);
|
---|
| 372 | }
|
---|
[3716] | 373 | }
|
---|
[6126] | 374 | return "";
|
---|
[3716] | 375 | }
|
---|
| 376 |
|
---|
[4481] | 377 | // Write Observation Types
|
---|
| 378 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 379 | QStringList t_rnxObsHeader::obsTypesStrings() const {
|
---|
| 380 |
|
---|
| 381 | QStringList strList;
|
---|
| 382 |
|
---|
| 383 | if (_version < 3.0) {
|
---|
[6125] | 384 | char sys0 = defaultSystems[0].toAscii();
|
---|
[4481] | 385 | QString hlp;
|
---|
[6125] | 386 | QTextStream(&hlp) << QString("%1").arg(_obsTypes[sys0].size(), 6);
|
---|
| 387 | for (int ii = 0; ii < _obsTypes[sys0].size(); ii++) {
|
---|
| 388 | QTextStream(&hlp) << QString("%1").arg(_obsTypes[sys0][ii], 6);
|
---|
| 389 | if ((ii+1) % 9 == 0 || ii == _obsTypes[sys0].size()-1) {
|
---|
[4481] | 390 | strList.append(hlp.leftJustified(60) + "# / TYPES OF OBSERV\n");
|
---|
| 391 | hlp = QString().leftJustified(6);
|
---|
| 392 | }
|
---|
| 393 | }
|
---|
| 394 | }
|
---|
| 395 | else {
|
---|
[6119] | 396 | QMapIterator<char, QVector<QString> > it(_obsTypes);
|
---|
[4481] | 397 | while (it.hasNext()) {
|
---|
| 398 | it.next();
|
---|
| 399 | char sys = it.key();
|
---|
| 400 | const QVector<QString>& types = it.value();
|
---|
| 401 | QString hlp;
|
---|
| 402 | QTextStream(&hlp) << QString("%1 %2").arg(sys).arg(types.size(), 3);
|
---|
| 403 | for (int ii = 0; ii < types.size(); ii++) {
|
---|
| 404 | QTextStream(&hlp) << QString(" %1").arg(types[ii], -3);
|
---|
| 405 | if ((ii+1) % 13 == 0 || ii == types.size()-1) {
|
---|
| 406 | strList.append(hlp.leftJustified(60) + "SYS / # / OBS TYPES\n");
|
---|
| 407 | hlp = QString().leftJustified(6);
|
---|
| 408 | }
|
---|
| 409 | }
|
---|
| 410 | }
|
---|
| 411 | }
|
---|
| 412 |
|
---|
| 413 | return strList;
|
---|
| 414 | }
|
---|
| 415 |
|
---|
[3716] | 416 | // Constructor
|
---|
| 417 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3843] | 418 | t_rnxObsFile::t_rnxObsFile(const QString& fileName, e_inpOut inpOut) {
|
---|
| 419 | _inpOut = inpOut;
|
---|
[3716] | 420 | _stream = 0;
|
---|
| 421 | _flgPowerFail = false;
|
---|
[3843] | 422 | if (_inpOut == input) {
|
---|
| 423 | openRead(fileName);
|
---|
| 424 | }
|
---|
| 425 | else {
|
---|
[3845] | 426 | openWrite(fileName);
|
---|
[3843] | 427 | }
|
---|
[3716] | 428 | }
|
---|
| 429 |
|
---|
[3845] | 430 | // Open for input
|
---|
[3716] | 431 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3843] | 432 | void t_rnxObsFile::openRead(const QString& fileName) {
|
---|
[3718] | 433 |
|
---|
| 434 | _fileName = fileName; expandEnvVar(_fileName);
|
---|
| 435 | _file = new QFile(_fileName);
|
---|
| 436 | _file->open(QIODevice::ReadOnly | QIODevice::Text);
|
---|
| 437 | _stream = new QTextStream();
|
---|
| 438 | _stream->setDevice(_file);
|
---|
| 439 |
|
---|
[3716] | 440 | _header.read(_stream);
|
---|
| 441 |
|
---|
| 442 | // Guess Observation Interval
|
---|
| 443 | // --------------------------
|
---|
| 444 | if (_header._interval == 0.0) {
|
---|
| 445 | bncTime ttPrev;
|
---|
| 446 | for (int iEpo = 0; iEpo < 10; iEpo++) {
|
---|
| 447 | const t_rnxEpo* rnxEpo = nextEpoch();
|
---|
| 448 | if (!rnxEpo) {
|
---|
[3718] | 449 | throw QString("t_rnxObsFile: not enough epochs");
|
---|
[3716] | 450 | }
|
---|
| 451 | if (iEpo > 0) {
|
---|
| 452 | double dt = rnxEpo->tt - ttPrev;
|
---|
| 453 | if (_header._interval == 0.0 || dt < _header._interval) {
|
---|
| 454 | _header._interval = dt;
|
---|
| 455 | }
|
---|
| 456 | }
|
---|
| 457 | ttPrev = rnxEpo->tt;
|
---|
| 458 | }
|
---|
[3719] | 459 | _stream->seek(0);
|
---|
[3716] | 460 | _header.read(_stream);
|
---|
| 461 | }
|
---|
[3837] | 462 |
|
---|
| 463 | // Time of first observation
|
---|
| 464 | // -------------------------
|
---|
| 465 | if (!_header._startTime.valid()) {
|
---|
| 466 | const t_rnxEpo* rnxEpo = nextEpoch();
|
---|
| 467 | if (!rnxEpo) {
|
---|
| 468 | throw QString("t_rnxObsFile: not enough epochs");
|
---|
| 469 | }
|
---|
| 470 | _header._startTime = rnxEpo->tt;
|
---|
| 471 | _stream->seek(0);
|
---|
| 472 | _header.read(_stream);
|
---|
| 473 | }
|
---|
[3716] | 474 | }
|
---|
| 475 |
|
---|
[3845] | 476 | // Open for output
|
---|
| 477 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 478 | void t_rnxObsFile::openWrite(const QString& fileName) {
|
---|
| 479 |
|
---|
| 480 | _fileName = fileName; expandEnvVar(_fileName);
|
---|
| 481 | _file = new QFile(_fileName);
|
---|
| 482 | _file->open(QIODevice::WriteOnly | QIODevice::Text);
|
---|
| 483 | _stream = new QTextStream();
|
---|
| 484 | _stream->setDevice(_file);
|
---|
| 485 | }
|
---|
| 486 |
|
---|
[3716] | 487 | // Destructor
|
---|
| 488 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 489 | t_rnxObsFile::~t_rnxObsFile() {
|
---|
| 490 | close();
|
---|
| 491 | }
|
---|
| 492 |
|
---|
| 493 | // Close
|
---|
| 494 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 495 | void t_rnxObsFile::close() {
|
---|
| 496 | delete _stream; _stream = 0;
|
---|
[3718] | 497 | delete _file; _file = 0;
|
---|
[3716] | 498 | }
|
---|
| 499 |
|
---|
| 500 | // Handle Special Epoch Flag
|
---|
| 501 | ////////////////////////////////////////////////////////////////////////////
|
---|
[4540] | 502 | void t_rnxObsFile::handleEpochFlag(int flag, const QString& line,
|
---|
| 503 | bool& headerReRead) {
|
---|
[3716] | 504 |
|
---|
[4540] | 505 | headerReRead = false;
|
---|
| 506 |
|
---|
[3716] | 507 | // Power Failure
|
---|
| 508 | // -------------
|
---|
| 509 | if (flag == 1) {
|
---|
| 510 | _flgPowerFail = true;
|
---|
| 511 | }
|
---|
| 512 |
|
---|
| 513 | // Start moving antenna
|
---|
| 514 | // --------------------
|
---|
| 515 | else if (flag == 2) {
|
---|
| 516 | // no action
|
---|
| 517 | }
|
---|
| 518 |
|
---|
| 519 | // Re-Read Header
|
---|
| 520 | // --------------
|
---|
[5468] | 521 | else if (flag == 3 || flag == 4 || flag == 5) {
|
---|
[3716] | 522 | int numLines = 0;
|
---|
| 523 | if (version() < 3.0) {
|
---|
| 524 | readInt(line, 29, 3, numLines);
|
---|
| 525 | }
|
---|
| 526 | else {
|
---|
| 527 | readInt(line, 32, 3, numLines);
|
---|
| 528 | }
|
---|
[5468] | 529 | if (flag == 3 || flag == 4) {
|
---|
| 530 | _header.read(_stream, numLines);
|
---|
| 531 | headerReRead = true;
|
---|
| 532 | }
|
---|
| 533 | else {
|
---|
| 534 | for (int ii = 0; ii < numLines; ii++) {
|
---|
| 535 | _stream->readLine();
|
---|
| 536 | }
|
---|
| 537 | }
|
---|
[3716] | 538 | }
|
---|
| 539 |
|
---|
| 540 | // Unhandled Flag
|
---|
| 541 | // --------------
|
---|
| 542 | else {
|
---|
[3718] | 543 | throw QString("t_rnxObsFile: unhandled flag\n" + line);
|
---|
[3716] | 544 | }
|
---|
| 545 | }
|
---|
| 546 |
|
---|
| 547 | // Retrieve single Epoch
|
---|
| 548 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3994] | 549 | t_rnxObsFile::t_rnxEpo* t_rnxObsFile::nextEpoch() {
|
---|
[3716] | 550 | _currEpo.clear();
|
---|
| 551 | if (version() < 3.0) {
|
---|
| 552 | return nextEpochV2();
|
---|
| 553 | }
|
---|
| 554 | else {
|
---|
| 555 | return nextEpochV3();
|
---|
| 556 | }
|
---|
| 557 | }
|
---|
| 558 |
|
---|
| 559 | // Retrieve single Epoch (RINEX Version 3)
|
---|
| 560 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3994] | 561 | t_rnxObsFile::t_rnxEpo* t_rnxObsFile::nextEpochV3() {
|
---|
[3716] | 562 |
|
---|
[3719] | 563 | while ( _stream->status() == QTextStream::Ok && !_stream->atEnd() ) {
|
---|
[3716] | 564 |
|
---|
[3718] | 565 | QString line = _stream->readLine();
|
---|
[3716] | 566 |
|
---|
[3718] | 567 | if (line.isEmpty()) {
|
---|
[3716] | 568 | continue;
|
---|
| 569 | }
|
---|
| 570 |
|
---|
| 571 | int flag = 0;
|
---|
| 572 | readInt(line, 31, 1, flag);
|
---|
| 573 | if (flag > 0) {
|
---|
[4540] | 574 | bool headerReRead = false;
|
---|
| 575 | handleEpochFlag(flag, line, headerReRead);
|
---|
| 576 | if (headerReRead) {
|
---|
| 577 | continue;
|
---|
| 578 | }
|
---|
[3716] | 579 | }
|
---|
| 580 |
|
---|
[3718] | 581 | QTextStream in(line.mid(1).toAscii(), QIODevice::ReadOnly);
|
---|
[3716] | 582 |
|
---|
| 583 | // Epoch Time
|
---|
| 584 | // ----------
|
---|
| 585 | int year, month, day, hour, min;
|
---|
| 586 | double sec;
|
---|
| 587 | in >> year >> month >> day >> hour >> min >> sec;
|
---|
[3720] | 588 | _currEpo.tt.set(year, month, day, hour, min, sec);
|
---|
[3716] | 589 |
|
---|
| 590 | // Number of Satellites
|
---|
| 591 | // --------------------
|
---|
| 592 | int numSat;
|
---|
| 593 | readInt(line, 32, 3, numSat);
|
---|
| 594 |
|
---|
| 595 | _currEpo.rnxSat.resize(numSat);
|
---|
[6126] | 596 | _currEpo.version = _header._version;
|
---|
[3716] | 597 |
|
---|
| 598 | // Observations
|
---|
| 599 | // ------------
|
---|
| 600 | for (int iSat = 0; iSat < numSat; iSat++) {
|
---|
[3718] | 601 | line = _stream->readLine();
|
---|
[6119] | 602 | t_prn prn; prn.set(line.left(3).toAscii().data());
|
---|
| 603 | _currEpo.rnxSat[iSat].prn = prn;
|
---|
| 604 | char sys = prn.system();
|
---|
[3716] | 605 | for (int iType = 0; iType < _header.nTypes(sys); iType++) {
|
---|
| 606 | int pos = 3 + 16*iType;
|
---|
| 607 | double obsValue = 0.0;
|
---|
| 608 | int lli = 0;
|
---|
| 609 | int snr = 0;
|
---|
| 610 | readDbl(line, pos, 14, obsValue);
|
---|
| 611 | readInt(line, pos + 14, 1, lli);
|
---|
| 612 | readInt(line, pos + 15, 1, snr);
|
---|
| 613 | if (_flgPowerFail) {
|
---|
| 614 | lli |= 1;
|
---|
| 615 | }
|
---|
[6119] | 616 | QString type = obsType(sys, iType);
|
---|
| 617 | _currEpo.rnxSat[iSat].obs[type].value = obsValue;
|
---|
| 618 | _currEpo.rnxSat[iSat].obs[type].lli = lli;
|
---|
| 619 | _currEpo.rnxSat[iSat].obs[type].snr = snr;
|
---|
[3716] | 620 | }
|
---|
| 621 | }
|
---|
| 622 |
|
---|
| 623 | _flgPowerFail = false;
|
---|
| 624 |
|
---|
| 625 | return &_currEpo;
|
---|
| 626 | }
|
---|
| 627 |
|
---|
| 628 | return 0;
|
---|
| 629 | }
|
---|
| 630 |
|
---|
| 631 | // Retrieve single Epoch (RINEX Version 2)
|
---|
| 632 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3994] | 633 | t_rnxObsFile::t_rnxEpo* t_rnxObsFile::nextEpochV2() {
|
---|
[3716] | 634 |
|
---|
[3719] | 635 | while ( _stream->status() == QTextStream::Ok && !_stream->atEnd() ) {
|
---|
[3716] | 636 |
|
---|
[3718] | 637 | QString line = _stream->readLine();
|
---|
[3716] | 638 |
|
---|
[3718] | 639 | if (line.isEmpty()) {
|
---|
[3716] | 640 | continue;
|
---|
| 641 | }
|
---|
| 642 |
|
---|
| 643 | int flag = 0;
|
---|
| 644 | readInt(line, 28, 1, flag);
|
---|
| 645 | if (flag > 0) {
|
---|
[4540] | 646 | bool headerReRead = false;
|
---|
| 647 | handleEpochFlag(flag, line, headerReRead);
|
---|
| 648 | if (headerReRead) {
|
---|
| 649 | continue;
|
---|
| 650 | }
|
---|
[3716] | 651 | }
|
---|
| 652 |
|
---|
[3718] | 653 | QTextStream in(line.toAscii(), QIODevice::ReadOnly);
|
---|
[3716] | 654 |
|
---|
| 655 | // Epoch Time
|
---|
| 656 | // ----------
|
---|
| 657 | int year, month, day, hour, min;
|
---|
| 658 | double sec;
|
---|
| 659 | in >> year >> month >> day >> hour >> min >> sec;
|
---|
| 660 | if (year < 80) {
|
---|
| 661 | year += 2000;
|
---|
| 662 | }
|
---|
| 663 | else if (year < 100) {
|
---|
| 664 | year += 1900;
|
---|
| 665 | }
|
---|
[3720] | 666 | _currEpo.tt.set(year, month, day, hour, min, sec);
|
---|
[3716] | 667 |
|
---|
| 668 | // Number of Satellites
|
---|
| 669 | // --------------------
|
---|
| 670 | int numSat;
|
---|
| 671 | readInt(line, 29, 3, numSat);
|
---|
| 672 |
|
---|
| 673 | _currEpo.rnxSat.resize(numSat);
|
---|
[6126] | 674 | _currEpo.version = _header._version;
|
---|
[3716] | 675 |
|
---|
| 676 | // Read Satellite Numbers
|
---|
| 677 | // ----------------------
|
---|
| 678 | int pos = 32;
|
---|
| 679 | for (int iSat = 0; iSat < numSat; iSat++) {
|
---|
| 680 | if (iSat > 0 && iSat % 12 == 0) {
|
---|
[3718] | 681 | line = _stream->readLine();
|
---|
[3716] | 682 | pos = 32;
|
---|
| 683 | }
|
---|
| 684 |
|
---|
[6119] | 685 | char sys = line.toAscii()[pos];
|
---|
| 686 | int satNum; readInt(line, pos + 1, 2, satNum);
|
---|
| 687 | _currEpo.rnxSat[iSat].prn.set(sys, satNum);
|
---|
| 688 |
|
---|
[3716] | 689 | pos += 3;
|
---|
| 690 | }
|
---|
| 691 |
|
---|
| 692 | // Read Observation Records
|
---|
| 693 | // ------------------------
|
---|
| 694 | for (int iSat = 0; iSat < numSat; iSat++) {
|
---|
[6119] | 695 | char sys = _currEpo.rnxSat[iSat].prn.system();
|
---|
[3718] | 696 | line = _stream->readLine();
|
---|
[3716] | 697 | pos = 0;
|
---|
[6119] | 698 | for (int iType = 0; iType < _header.nTypes(sys); iType++) {
|
---|
[3716] | 699 | if (iType > 0 && iType % 5 == 0) {
|
---|
[3718] | 700 | line = _stream->readLine();
|
---|
[3716] | 701 | pos = 0;
|
---|
| 702 | }
|
---|
| 703 | double obsValue = 0.0;
|
---|
| 704 | int lli = 0;
|
---|
| 705 | int snr = 0;
|
---|
| 706 | readDbl(line, pos, 14, obsValue);
|
---|
| 707 | readInt(line, pos + 14, 1, lli);
|
---|
| 708 | readInt(line, pos + 15, 1, snr);
|
---|
| 709 |
|
---|
| 710 | if (_flgPowerFail) {
|
---|
| 711 | lli |= 1;
|
---|
| 712 | }
|
---|
| 713 |
|
---|
[6119] | 714 | QString type = obsType(sys, iType);
|
---|
| 715 | _currEpo.rnxSat[iSat].obs[type].value = obsValue;
|
---|
| 716 | _currEpo.rnxSat[iSat].obs[type].lli = lli;
|
---|
| 717 | _currEpo.rnxSat[iSat].obs[type].snr = snr;
|
---|
[3716] | 718 |
|
---|
| 719 | pos += 16;
|
---|
| 720 | }
|
---|
| 721 | }
|
---|
| 722 |
|
---|
| 723 | _flgPowerFail = false;
|
---|
| 724 |
|
---|
| 725 | return &_currEpo;
|
---|
| 726 | }
|
---|
| 727 |
|
---|
| 728 | return 0;
|
---|
| 729 | }
|
---|
| 730 |
|
---|
[3844] | 731 | // Set Header Information
|
---|
| 732 | ////////////////////////////////////////////////////////////////////////////
|
---|
[6119] | 733 | void t_rnxObsFile::setHeader(const t_rnxObsHeader& header, double version,
|
---|
| 734 | const QStringList& useObsTypes) {
|
---|
[3956] | 735 |
|
---|
[6120] | 736 | if (version < 3.0) {
|
---|
| 737 | _header._version = t_rnxObsHeader::defaultRnxObsVersion2;
|
---|
[3956] | 738 | }
|
---|
| 739 | else {
|
---|
[6120] | 740 | _header._version = t_rnxObsHeader::defaultRnxObsVersion3;
|
---|
[3956] | 741 | }
|
---|
[3930] | 742 | _header._interval = header._interval;
|
---|
| 743 | _header._antennaNumber = header._antennaNumber;
|
---|
| 744 | _header._antennaName = header._antennaName;
|
---|
| 745 | _header._markerName = header._markerName;
|
---|
| 746 | _header._markerNumber = header._markerNumber;
|
---|
| 747 | _header._antNEU = header._antNEU;
|
---|
| 748 | _header._antXYZ = header._antXYZ;
|
---|
| 749 | _header._antBSG = header._antBSG;
|
---|
| 750 | _header._xyz = header._xyz;
|
---|
| 751 | _header._observer = header._observer;
|
---|
| 752 | _header._agency = header._agency;
|
---|
| 753 | _header._receiverNumber = header._receiverNumber;
|
---|
| 754 | _header._receiverType = header._receiverType;
|
---|
| 755 | _header._receiverVersion = header._receiverVersion;
|
---|
[6119] | 756 | _header._startTime = header._startTime;
|
---|
[5742] | 757 | for (unsigned iPrn = 1; iPrn <= t_prn::MAXPRN_GPS; iPrn++) {
|
---|
[3844] | 758 | _header._wlFactorsL1[iPrn] = header._wlFactorsL1[iPrn];
|
---|
| 759 | _header._wlFactorsL2[iPrn] = header._wlFactorsL2[iPrn];
|
---|
| 760 | }
|
---|
[3956] | 761 |
|
---|
[6119] | 762 | // Set observation types
|
---|
| 763 | // ---------------------
|
---|
| 764 | _header._obsTypes.clear();
|
---|
| 765 | if (useObsTypes.size() == 0) {
|
---|
| 766 | _header._obsTypes = header._obsTypes;
|
---|
[3844] | 767 | }
|
---|
[6119] | 768 | else {
|
---|
| 769 | if (_header._version < 3.0) {
|
---|
[6125] | 770 | char sys0 = t_rnxObsHeader::defaultSystems[0].toAscii();
|
---|
[6119] | 771 | for (int ii = 0; ii < useObsTypes.size(); ii++) {
|
---|
[6125] | 772 | _header._obsTypes[sys0].push_back(useObsTypes[ii]);
|
---|
[3956] | 773 | }
|
---|
[6119] | 774 | for (int ii = 1; ii < t_rnxObsHeader::defaultSystems.length(); ii++) {
|
---|
[6125] | 775 | char sysI = t_rnxObsHeader::defaultSystems[ii].toAscii();
|
---|
| 776 | _header._obsTypes[sysI] = _header._obsTypes[sys0];
|
---|
[6119] | 777 | }
|
---|
[3956] | 778 | }
|
---|
[6119] | 779 | else {
|
---|
| 780 | for (int ii = 0; ii < useObsTypes.size(); ii++) {
|
---|
[6124] | 781 | if (useObsTypes[ii].indexOf(":") != -1) {
|
---|
| 782 | QStringList hlp = useObsTypes[ii].split(":", QString::SkipEmptyParts);
|
---|
| 783 | if (hlp.size() == 2 && hlp[0].length() == 1) {
|
---|
| 784 | char sys = hlp[0][0].toAscii();
|
---|
| 785 | QString type = hlp[1];
|
---|
| 786 | _header._obsTypes[sys].push_back(type);
|
---|
| 787 | }
|
---|
[3965] | 788 | }
|
---|
[6124] | 789 | else {
|
---|
| 790 | QString type = useObsTypes[ii];
|
---|
| 791 | for (int ii = 0; ii < t_rnxObsHeader::defaultSystems.length(); ii++) {
|
---|
| 792 | char sys = t_rnxObsHeader::defaultSystems[ii].toAscii();
|
---|
| 793 | _header._obsTypes[sys].push_back(type);
|
---|
| 794 | }
|
---|
| 795 | }
|
---|
[3965] | 796 | }
|
---|
| 797 | }
|
---|
[3956] | 798 | }
|
---|
[3844] | 799 | }
|
---|
[3845] | 800 |
|
---|
| 801 | // Write Data Epoch
|
---|
| 802 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 803 | void t_rnxObsFile::writeEpoch(const t_rnxEpo* epo) {
|
---|
[3866] | 804 | if (version() < 3.0) {
|
---|
| 805 | return writeEpochV2(epo);
|
---|
| 806 | }
|
---|
| 807 | else {
|
---|
| 808 | return writeEpochV3(epo);
|
---|
| 809 | }
|
---|
| 810 | }
|
---|
[3855] | 811 |
|
---|
[3866] | 812 | // Write Data Epoch (RINEX Version 2)
|
---|
| 813 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 814 | void t_rnxObsFile::writeEpochV2(const t_rnxEpo* epo) {
|
---|
| 815 |
|
---|
[3855] | 816 | unsigned year, month, day, hour, min;
|
---|
| 817 | double sec;
|
---|
| 818 | epo->tt.civil_date(year, month, day);
|
---|
| 819 | epo->tt.civil_time(hour, min, sec);
|
---|
| 820 |
|
---|
| 821 | QString dateStr;
|
---|
[3868] | 822 | QTextStream(&dateStr) << QString(" %1 %2 %3 %4 %5%6")
|
---|
[3856] | 823 | .arg(int(fmod(year, 100)), 2, 10, QChar('0'))
|
---|
[3868] | 824 | .arg(month, 2, 10, QChar('0'))
|
---|
| 825 | .arg(day, 2, 10, QChar('0'))
|
---|
| 826 | .arg(hour, 2, 10, QChar('0'))
|
---|
| 827 | .arg(min, 2, 10, QChar('0'))
|
---|
| 828 | .arg(sec, 11, 'f', 7);
|
---|
[3855] | 829 |
|
---|
[3857] | 830 | int flag = 0;
|
---|
[6123] | 831 | *_stream << dateStr << QString("%1%2").arg(flag, 3).arg(epo->rnxSat.size(), 3);
|
---|
[3858] | 832 | for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
|
---|
[3869] | 833 | const t_rnxSat& rnxSat = epo->rnxSat[iSat];
|
---|
[3858] | 834 | if (iSat > 0 && iSat % 12 == 0) {
|
---|
[3857] | 835 | *_stream << endl << QString().leftJustified(32);
|
---|
| 836 | }
|
---|
[6123] | 837 | *_stream << rnxSat.prn.toString().c_str();
|
---|
[3857] | 838 | }
|
---|
| 839 | *_stream << endl;
|
---|
[3858] | 840 | for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
|
---|
[3967] | 841 |
|
---|
[3858] | 842 | const t_rnxSat& rnxSat = epo->rnxSat[iSat];
|
---|
[6119] | 843 | char sys = rnxSat.prn.system();
|
---|
[3966] | 844 |
|
---|
[6119] | 845 | for (int iType = 0; iType < nTypes(sys); iType++) {
|
---|
| 846 | if (iType > 0 && iType % 5 == 0) {
|
---|
[3967] | 847 | *_stream << endl;
|
---|
| 848 | }
|
---|
[6126] | 849 | QString type = obsType(sys, iType, epo->version);
|
---|
[6119] | 850 | if (!rnxSat.obs.contains(type)) {
|
---|
[3858] | 851 | *_stream << QString().leftJustified(16);
|
---|
| 852 | }
|
---|
| 853 | else {
|
---|
[6119] | 854 | const t_rnxObs& rnxObs = rnxSat.obs[type];
|
---|
| 855 | *_stream << QString("%1").arg(rnxObs.value, 14, 'f', 3);
|
---|
| 856 | if (rnxObs.lli != 0.0) {
|
---|
| 857 | *_stream << QString("%1").arg(rnxObs.lli,1);
|
---|
[3979] | 858 | }
|
---|
| 859 | else {
|
---|
| 860 | *_stream << ' ';
|
---|
| 861 | }
|
---|
[6119] | 862 | if (rnxObs.snr != 0.0) {
|
---|
| 863 | *_stream << QString("%1").arg(rnxObs.snr,1);
|
---|
[3979] | 864 | }
|
---|
| 865 | else {
|
---|
| 866 | *_stream << ' ';
|
---|
| 867 | }
|
---|
[3858] | 868 | }
|
---|
| 869 | }
|
---|
| 870 | *_stream << endl;
|
---|
| 871 | }
|
---|
[3845] | 872 | }
|
---|
[3866] | 873 |
|
---|
| 874 | // Write Data Epoch (RINEX Version 3)
|
---|
| 875 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 876 | void t_rnxObsFile::writeEpochV3(const t_rnxEpo* epo) {
|
---|
| 877 |
|
---|
| 878 | unsigned year, month, day, hour, min;
|
---|
| 879 | double sec;
|
---|
| 880 | epo->tt.civil_date(year, month, day);
|
---|
| 881 | epo->tt.civil_time(hour, min, sec);
|
---|
| 882 |
|
---|
[3867] | 883 | QString dateStr;
|
---|
[3868] | 884 | QTextStream(&dateStr) << QString("> %1 %2 %3 %4 %5%6")
|
---|
[3867] | 885 | .arg(year, 4)
|
---|
| 886 | .arg(month, 2, 10, QChar('0'))
|
---|
| 887 | .arg(day, 2, 10, QChar('0'))
|
---|
| 888 | .arg(hour, 2, 10, QChar('0'))
|
---|
| 889 | .arg(min, 2, 10, QChar('0'))
|
---|
| 890 | .arg(sec, 11, 'f', 7);
|
---|
[3866] | 891 |
|
---|
[3867] | 892 | int flag = 0;
|
---|
[6123] | 893 | *_stream << dateStr << QString("%1%2\n").arg(flag, 3).arg(epo->rnxSat.size(), 3);
|
---|
[3867] | 894 |
|
---|
[3869] | 895 | for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
|
---|
| 896 | const t_rnxSat& rnxSat = epo->rnxSat[iSat];
|
---|
[6119] | 897 | char sys = rnxSat.prn.system();
|
---|
[3964] | 898 |
|
---|
[6123] | 899 | *_stream << rnxSat.prn.toString().c_str();
|
---|
[6119] | 900 | for (int iType = 0; iType < nTypes(sys); iType++) {
|
---|
[6126] | 901 | QString type = obsType(sys, iType, epo->version);
|
---|
[6119] | 902 | if (!rnxSat.obs.contains(type)) {
|
---|
[3869] | 903 | *_stream << QString().leftJustified(16);
|
---|
| 904 | }
|
---|
| 905 | else {
|
---|
[6119] | 906 | const t_rnxObs& rnxObs = rnxSat.obs[type];
|
---|
| 907 | *_stream << QString("%1").arg(rnxObs.value, 14, 'f', 3);
|
---|
| 908 | if (rnxObs.lli != 0.0) {
|
---|
| 909 | *_stream << QString("%1").arg(rnxObs.lli,1);
|
---|
[3979] | 910 | }
|
---|
| 911 | else {
|
---|
| 912 | *_stream << ' ';
|
---|
| 913 | }
|
---|
[6119] | 914 | if (rnxObs.snr != 0.0) {
|
---|
| 915 | *_stream << QString("%1").arg(rnxObs.snr,1);
|
---|
[3979] | 916 | }
|
---|
| 917 | else {
|
---|
| 918 | *_stream << ' ';
|
---|
| 919 | }
|
---|
[3869] | 920 | }
|
---|
| 921 | }
|
---|
| 922 | *_stream << endl;
|
---|
| 923 | }
|
---|
[3866] | 924 | }
|
---|
[3956] | 925 |
|
---|
| 926 | // Translate Observation Type v2 --> v3
|
---|
| 927 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 928 | QString t_rnxObsFile::type2to3(char sys, const QString& typeV2) {
|
---|
| 929 |
|
---|
| 930 | if (sys == 'G') {
|
---|
| 931 | if (typeV2 == "C1") return "C1C";
|
---|
| 932 | if (typeV2 == "C2") return "C2C";
|
---|
| 933 | if (typeV2 == "C5") return "C5C";
|
---|
| 934 | if (typeV2 == "P1") return "C1P";
|
---|
| 935 | if (typeV2 == "P2") return "C2P";
|
---|
| 936 | if (typeV2 == "L1") return "L1";
|
---|
| 937 | if (typeV2 == "L2") return "L2";
|
---|
| 938 | if (typeV2 == "L5") return "L5";
|
---|
| 939 | if (typeV2 == "D1") return "D1";
|
---|
| 940 | if (typeV2 == "D2") return "D2";
|
---|
| 941 | if (typeV2 == "D5") return "D5";
|
---|
| 942 | if (typeV2 == "S1") return "S1";
|
---|
| 943 | if (typeV2 == "S2") return "S2";
|
---|
| 944 | if (typeV2 == "S5") return "S5";
|
---|
| 945 | }
|
---|
| 946 |
|
---|
| 947 | else if (sys == 'R') {
|
---|
| 948 | if (typeV2 == "C1") return "C1C";
|
---|
| 949 | if (typeV2 == "C2") return "C2C";
|
---|
| 950 | if (typeV2 == "P1") return "C1P";
|
---|
| 951 | if (typeV2 == "P2") return "C2P";
|
---|
| 952 | if (typeV2 == "L1") return "L1";
|
---|
| 953 | if (typeV2 == "L2") return "L2";
|
---|
| 954 | if (typeV2 == "D1") return "D1";
|
---|
| 955 | if (typeV2 == "D2") return "D2";
|
---|
| 956 | if (typeV2 == "S1") return "S1";
|
---|
| 957 | if (typeV2 == "S2") return "S2";
|
---|
| 958 | }
|
---|
| 959 |
|
---|
| 960 | else if (sys == 'E') {
|
---|
| 961 | if (typeV2 == "C1") return "C1";
|
---|
| 962 | if (typeV2 == "C5") return "C5";
|
---|
| 963 | if (typeV2 == "C6") return "C6";
|
---|
| 964 | if (typeV2 == "C7") return "C7";
|
---|
| 965 | if (typeV2 == "C8") return "C8";
|
---|
| 966 | if (typeV2 == "L1") return "L1";
|
---|
| 967 | if (typeV2 == "L5") return "L5";
|
---|
| 968 | if (typeV2 == "L6") return "L6";
|
---|
| 969 | if (typeV2 == "L7") return "L7";
|
---|
| 970 | if (typeV2 == "L8") return "L8";
|
---|
| 971 | if (typeV2 == "D1") return "D1";
|
---|
| 972 | if (typeV2 == "D5") return "D5";
|
---|
| 973 | if (typeV2 == "D6") return "D6";
|
---|
| 974 | if (typeV2 == "D7") return "D7";
|
---|
| 975 | if (typeV2 == "D8") return "D8";
|
---|
| 976 | if (typeV2 == "S1") return "S1";
|
---|
| 977 | if (typeV2 == "S5") return "S5";
|
---|
| 978 | if (typeV2 == "S6") return "S6";
|
---|
| 979 | if (typeV2 == "S7") return "S7";
|
---|
| 980 | if (typeV2 == "S8") return "S8";
|
---|
| 981 | }
|
---|
| 982 |
|
---|
| 983 | else if (sys == 'S') {
|
---|
| 984 | if (typeV2 == "C1") return "C1C";
|
---|
| 985 | if (typeV2 == "C5") return "C5C";
|
---|
| 986 | if (typeV2 == "L1") return "L1";
|
---|
| 987 | if (typeV2 == "L5") return "L5";
|
---|
| 988 | if (typeV2 == "D1") return "D1";
|
---|
| 989 | if (typeV2 == "D5") return "D5";
|
---|
| 990 | if (typeV2 == "S1") return "S1";
|
---|
| 991 | if (typeV2 == "S5") return "S5";
|
---|
| 992 | }
|
---|
| 993 |
|
---|
| 994 | return "";
|
---|
| 995 | }
|
---|
[3962] | 996 |
|
---|
| 997 | // Translate Observation Type v3 --> v2
|
---|
| 998 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 999 | QString t_rnxObsFile::type3to2(const QString& typeV3) {
|
---|
| 1000 | if (typeV3 == "C1P") {
|
---|
| 1001 | return "P1";
|
---|
| 1002 | }
|
---|
| 1003 | else if (typeV3 == "C2P") {
|
---|
| 1004 | return "P2";
|
---|
| 1005 | }
|
---|
| 1006 | else {
|
---|
| 1007 | return typeV3.left(2);
|
---|
| 1008 | }
|
---|
[3965] | 1009 |
|
---|
| 1010 | return "";
|
---|
[3962] | 1011 | }
|
---|
[4053] | 1012 |
|
---|
| 1013 | // Check for Changes in Header
|
---|
| 1014 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 1015 | void t_rnxObsFile::checkNewHeader(const t_rnxObsHeader& header) {
|
---|
| 1016 |
|
---|
| 1017 | t_rnxObsHeader oldHeader(_header);
|
---|
[6119] | 1018 | setHeader(header, oldHeader._version, QStringList());
|
---|
[4053] | 1019 |
|
---|
[4054] | 1020 | // Check Observation Types
|
---|
| 1021 | // -----------------------
|
---|
| 1022 | bool same = true;
|
---|
[6119] | 1023 | QMapIterator<char, QVector<QString> > it(_header._obsTypes);
|
---|
| 1024 | while (it.hasNext()) {
|
---|
| 1025 | it.next();
|
---|
| 1026 | char sys = it.key();
|
---|
| 1027 | const QVector<QString>& types = it.value();
|
---|
| 1028 | if (!oldHeader._obsTypes.contains(sys) || oldHeader._obsTypes[sys] != types) {
|
---|
[4054] | 1029 | same = false;
|
---|
[6119] | 1030 | break;
|
---|
[4054] | 1031 | }
|
---|
| 1032 | }
|
---|
[4053] | 1033 |
|
---|
[4054] | 1034 | if (!same) {
|
---|
[4481] | 1035 | QStringList strLst = _header.obsTypesStrings();
|
---|
[4748] | 1036 | if (_header._version < 3.0) {
|
---|
| 1037 | *_stream << QString().leftJustified(26);
|
---|
| 1038 | }
|
---|
| 1039 | else {
|
---|
| 1040 | *_stream << '>' << QString().leftJustified(28);
|
---|
| 1041 | }
|
---|
| 1042 | *_stream << QString(" 4%1\n").arg(strLst.size(), 3)
|
---|
[4056] | 1043 | << strLst.join("");
|
---|
[4053] | 1044 | }
|
---|
| 1045 | }
|
---|
[5883] | 1046 |
|
---|
| 1047 | // Set Observations from RINEX File
|
---|
| 1048 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 1049 | void t_rnxObsFile::setObsFromRnx(const t_rnxObsFile* rnxObsFile,
|
---|
| 1050 | const t_rnxObsFile::t_rnxEpo* epo,
|
---|
| 1051 | const t_rnxObsFile::t_rnxSat& rnxSat,
|
---|
| 1052 | t_obs& obs) {
|
---|
| 1053 |
|
---|
| 1054 | strncpy(obs.StatID, rnxObsFile->markerName().toAscii().constData(),
|
---|
| 1055 | sizeof(obs.StatID));
|
---|
| 1056 |
|
---|
[6119] | 1057 | obs.satSys = rnxSat.prn.system();
|
---|
| 1058 | obs.satNum = rnxSat.prn.number();
|
---|
[5883] | 1059 | obs.GPSWeek = epo->tt.gpsw();
|
---|
| 1060 | obs.GPSWeeks = epo->tt.gpssec();
|
---|
| 1061 |
|
---|
| 1062 | for (int iType = 0; iType < rnxObsFile->nTypes(obs.satSys); iType++) {
|
---|
[6119] | 1063 | QString type = rnxObsFile->obsType(obs.satSys, iType);
|
---|
| 1064 | if (rnxSat.obs.contains(type)) {
|
---|
| 1065 | const t_rnxObs& rnxObs = rnxSat.obs[type];
|
---|
| 1066 | obs.setMeasdata(type, rnxObsFile->version(), rnxObs.value);
|
---|
| 1067 | if (type.indexOf("L1") == 0) {
|
---|
| 1068 | obs.snrL1 = rnxObs.snr;
|
---|
| 1069 | obs.slipL1 = (rnxObs.lli & 1);
|
---|
| 1070 | }
|
---|
| 1071 | else if (type.indexOf("L2") == 0) {
|
---|
| 1072 | obs.snrL2 = rnxObs.snr;
|
---|
| 1073 | obs.slipL2 = (rnxObs.lli & 1);
|
---|
| 1074 | }
|
---|
| 1075 | else if (type.indexOf("L5") == 0) {
|
---|
| 1076 | obs.snrL5 = rnxObs.snr;
|
---|
| 1077 | obs.slipL5 = (rnxObs.lli & 1);
|
---|
| 1078 | }
|
---|
[5883] | 1079 | }
|
---|
[6119] | 1080 | }
|
---|
| 1081 | }
|
---|
| 1082 |
|
---|