source: ntrip/trunk/BNC/src/rinex/rnxobsfile.cpp@ 7665

Last change on this file since 7665 was 7665, checked in by stuerze, 8 years ago

minor changes ragarding rinex obs file writing with incomplete skl file

File size: 45.7 KB
RevLine 
[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 *
[7474]37 * Changes:
[3716]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"
[6242]47#include "bncsettings.h"
[3716]48
49using namespace std;
50
51// Constructor
52////////////////////////////////////////////////////////////////////////////
[4480]53t_rnxObsHeader::t_rnxObsHeader() {
[6247]54 _usedSystems = "GREJCS";
[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 }
[7665]65 bncSettings settings;
66 _writeRinexOnlyWithSklObsTypes = settings.value("rnxOnlyWithSKL").toBool();
[3716]67}
68
69// Destructor
70////////////////////////////////////////////////////////////////////////////
[4480]71t_rnxObsHeader::~t_rnxObsHeader() {
[3716]72}
73
74// Read Header
75////////////////////////////////////////////////////////////////////////////
[4480]76t_irc t_rnxObsHeader::read(QTextStream* stream, int maxLines) {
[4534]77 _comments.clear();
[3716]78 int numLines = 0;
[6815]79
[3718]80 while ( stream->status() == QTextStream::Ok && !stream->atEnd() ) {
81 QString line = stream->readLine(); ++ numLines;
82 if (line.isEmpty()) {
[3716]83 continue;
84 }
[3718]85 if (line.indexOf("END OF FILE") != -1) {
[3716]86 break;
87 }
[3718]88 QString value = line.mid(0,60).trimmed();
89 QString key = line.mid(60).trimmed();
[3716]90 if (key == "END OF HEADER") {
91 break;
92 }
93 else if (key == "RINEX VERSION / TYPE") {
[3718]94 QTextStream in(value.toAscii(), QIODevice::ReadOnly);
[3716]95 in >> _version;
96 }
97 else if (key == "MARKER NAME") {
98 _markerName = value;
99 }
[6941]100 else if (key == "MARKER TYPE") {
101 _markerType = value;
102 }
[3930]103 else if (key == "MARKER NUMBER") {
104 _markerNumber = line.mid(0,20).trimmed();
105 }
[3716]106 else if (key == "ANT # / TYPE") {
[3930]107 _antennaNumber = line.mid( 0,20).trimmed();
108 _antennaName = line.mid(20,20).trimmed();
[3716]109 }
[3930]110 else if (key == "OBSERVER / AGENCY") {
111 _observer = line.mid( 0,20).trimmed();
112 _agency = line.mid(20,40).trimmed();
113 }
114 else if (key == "REC # / TYPE / VERS") {
115 _receiverNumber = line.mid( 0,20).trimmed();
116 _receiverType = line.mid(20,20).trimmed();
117 _receiverVersion = line.mid(40,20).trimmed();
118 }
[3716]119 else if (key == "INTERVAL") {
[3718]120 QTextStream in(value.toAscii(), QIODevice::ReadOnly);
[3716]121 in >> _interval;
122 }
[4494]123 else if (key == "COMMENT") {
124 _comments << line.mid(0,60).trimmed();
125 }
[3716]126 else if (key == "WAVELENGTH FACT L1/2") {
[3718]127 QTextStream in(value.toAscii(), QIODevice::ReadOnly);
[3716]128 int wlFactL1 = 0;
129 int wlFactL2 = 0;
130 int numSat = 0;
131 in >> wlFactL1 >> wlFactL2 >> numSat;
132 if (numSat == 0) {
[5742]133 for (unsigned iPrn = 1; iPrn <= t_prn::MAXPRN_GPS; iPrn++) {
[3716]134 _wlFactorsL1[iPrn] = wlFactL1;
135 _wlFactorsL2[iPrn] = wlFactL2;
136 }
137 }
138 else {
139 for (int ii = 0; ii < numSat; ii++) {
[3718]140 QString prn; in >> prn;
[3716]141 if (prn[0] == 'G') {
142 int iPrn;
143 readInt(prn, 1, 2, iPrn);
144 _wlFactorsL1[iPrn] = wlFactL1;
145 _wlFactorsL2[iPrn] = wlFactL2;
146 }
147 }
148 }
149 }
150 else if (key == "APPROX POSITION XYZ") {
[3718]151 QTextStream in(value.toAscii(), QIODevice::ReadOnly);
[3716]152 in >> _xyz[0] >> _xyz[1] >> _xyz[2];
153 }
154 else if (key == "ANTENNA: DELTA H/E/N") {
[3718]155 QTextStream in(value.toAscii(), QIODevice::ReadOnly);
[3716]156 in >> _antNEU[2] >> _antNEU[1] >> _antNEU[0];
157 }
158 else if (key == "ANTENNA: DELTA X/Y/Z") {
[3718]159 QTextStream in(value.toAscii(), QIODevice::ReadOnly);
[3716]160 in >> _antXYZ[0] >> _antXYZ[1] >> _antXYZ[2];
161 }
162 else if (key == "ANTENNA: B.SIGHT XYZ") {
[3718]163 QTextStream in(value.toAscii(), QIODevice::ReadOnly);
[3716]164 in >> _antBSG[0] >> _antBSG[1] >> _antBSG[2];
165 }
166 else if (key == "# / TYPES OF OBSERV") {
[6223]167 if (_version == 0.0) {
168 _version = t_rnxObsHeader::defaultRnxObsVersion2;
169 }
[3864]170 QTextStream* in = new QTextStream(value.toAscii(), QIODevice::ReadOnly);
[3716]171 int nTypes;
[3864]172 *in >> nTypes;
[6245]173 char sys0 = _usedSystems[0].toAscii();
[6125]174 _obsTypes[sys0].clear();
[3716]175 for (int ii = 0; ii < nTypes; ii++) {
[3864]176 if (ii > 0 && ii % 9 == 0) {
177 line = stream->readLine(); ++numLines;
178 delete in;
[4152]179 in = new QTextStream(line.left(60).toAscii(), QIODevice::ReadOnly);
[3864]180 }
[3718]181 QString hlp;
[3864]182 *in >> hlp;
[6125]183 _obsTypes[sys0].append(hlp);
[3716]184 }
[6245]185 for (int ii = 1; ii < _usedSystems.length(); ii++) {
186 char sysI = _usedSystems[ii].toAscii();
[6125]187 _obsTypes[sysI] = _obsTypes[sys0];
[6119]188 }
[3716]189 }
190 else if (key == "SYS / # / OBS TYPES") {
[6223]191 if (_version == 0.0) {
[6228]192 _version = t_rnxObsHeader::defaultRnxObsVersion3;
[6223]193 }
[3718]194 QTextStream* in = new QTextStream(value.toAscii(), QIODevice::ReadOnly);
[3716]195 char sys;
196 int nTypes;
197 *in >> sys >> nTypes;
[6119]198 _obsTypes[sys].clear();
[3716]199 for (int ii = 0; ii < nTypes; ii++) {
200 if (ii > 0 && ii % 13 == 0) {
[3718]201 line = stream->readLine(); ++numLines;
[3716]202 delete in;
[3718]203 in = new QTextStream(line.toAscii(), QIODevice::ReadOnly);
[3716]204 }
[3718]205 QString hlp;
[3716]206 *in >> hlp;
[6817]207 if (sys == 'C' && _version < 3.03) {
[6816]208 hlp.replace('1', '2');
209 }
[6119]210 _obsTypes[sys].push_back(hlp);
[3716]211 }
212 delete in;
213 }
[3837]214 else if (key == "TIME OF FIRST OBS") {
215 QTextStream in(value.toAscii(), QIODevice::ReadOnly);
216 int year, month, day, hour, min;
217 double sec;
218 in >> year >> month >> day >> hour >> min >> sec;
219 _startTime.set(year, month, day, hour, min, sec);
220 }
[6719]221 else if (key == "SYS / PHASE SHIFT"){
[6815]222 QTextStream* in = new QTextStream(value.toAscii(), QIODevice::ReadOnly);
223 char sys;
224 QString obstype;
225 double shift;
226 int satnum = 0;
227 QStringList satList;
228 QString sat;
229 *in >> sys >> obstype >> shift >> satnum;
230 if (obstype.size()) {
231 for (int ii = 0; ii < satnum; ii++) {
232 if (ii > 0 && ii % 10 == 0) {
233 line = stream->readLine(); ++numLines;
234 delete in;
235 in = new QTextStream(line.left(60).toAscii(), QIODevice::ReadOnly);
236 }
237 *in >> sat;
238 satList.append(sat);
239 }
240 delete in;
241 }
[6871]242 _phaseShifts.insert(sys+obstype, QPair<double, QStringList>(shift, satList));
[6719]243 }
244 else if (key == "GLONASS COD/PHS/BIS"){
245 QTextStream in(value.toAscii(), QIODevice::ReadOnly);
246 for (int ii = 0; ii < 4; ii++) {
247 QString type;
248 double value;
249 in >> type >> value;
250 if (type.size())
[6841]251 _gloBiases[type] = value;
[6719]252 }
253 }
254 else if (key == "GLONASS SLOT / FRQ #") {
255 QTextStream* in = new QTextStream(value.toAscii(), QIODevice::ReadOnly);
256 int nSlots = 0;
257 *in >> nSlots;
258 for (int ii = 0; ii < nSlots; ii++) {
259 if (ii > 0 && ii % 8 == 0) {
260 line = stream->readLine(); ++numLines;
261 delete in;
262 in = new QTextStream(line.left(60).toAscii(), QIODevice::ReadOnly);
263 }
264 QString sat;
265 int slot;
266 *in >> sat >> slot;
267 t_prn prn;
268 prn.set(sat.toStdString());
269 if(sat.size())
270 _gloSlots[prn] = slot;
271 }
272 delete in;
273 }
[3716]274 if (maxLines > 0 && numLines == maxLines) {
275 break;
276 }
277 }
278
[6719]279 // set default observation types if empty in input file
280 // ----------------------------------------------------
[6704]281 if (_obsTypes.empty()) {
[7665]282 if (!_writeRinexOnlyWithSklObsTypes) {
283 setDefault(_markerName, _version);
284 }
285 else {
286 return failure;
287 }
[6704]288 }
289
[6245]290 // Systems used
291 // ------------
292 _usedSystems.clear();
293 QMapIterator<char, QStringList> it(_obsTypes);
294 while (it.hasNext()) {
295 it.next();
296 _usedSystems += QChar(it.key());
297 }
298
[3716]299 return success;
300}
301
[6222]302// Set Default Header
303////////////////////////////////////////////////////////////////////////////
304void t_rnxObsHeader::setDefault(const QString& markerName, int version) {
305
306 _markerName = markerName;
307
308 if (version <= 2) {
309 _version = t_rnxObsHeader::defaultRnxObsVersion2;
310 }
311 else {
312 _version = t_rnxObsHeader::defaultRnxObsVersion3;
313 }
314
315 _comments << "Default set of observation types used";
316
317 _obsTypes.clear();
318 if (_version < 3.0) {
[7474]319 _obsTypes['G'] << "C1" << "P1" << "L1" << "S1"
[6222]320 << "C2" << "P2" << "L2" << "S2";
321 _obsTypes['R'] = _obsTypes['G'];
322 _obsTypes['E'] = _obsTypes['G'];
323 _obsTypes['J'] = _obsTypes['G'];
324 _obsTypes['S'] = _obsTypes['G'];
325 _obsTypes['C'] = _obsTypes['G'];
326 }
327 else {
[7474]328 _obsTypes['G'] << "C1C" << "L1C" << "S1C"
[6815]329 << "C1W" << "L1W" << "S1W"
330 << "C2X" << "L2X" << "S2X"
[7474]331 << "C2W" << "L2W" << "S2W"
[6815]332 << "C5X" << "L5X" << "S5X";
333
[6222]334 _obsTypes['J'] = _obsTypes['G'];
[7474]335
336 _obsTypes['R'] << "C1C" << "L1C" << "S1C"
[6222]337 << "C2P" << "L2P" << "S2P";
[7474]338
[6815]339 _obsTypes['E'] << "C1X" << "L1X" << "SX1"
340 << "C5X" << "L5X" << "SX5"
341 << "C7X" << "L7X" << "SX7"
342 << "C8X" << "L8X" << "SX8";
[7474]343
[6815]344 _obsTypes['S'] << "C1C" << "L1C" << "S1C"
345 << "C5I" << "L5I" << "S5I"
346 << "C5Q" << "L5Q" << "S5Q";
[7474]347
[6815]348 _obsTypes['C'] << "C2I" << "L2I" << "S2I"
349 << "C6I" << "L6I" << "S6I"
350 << "C7I" << "L7I" << "S7I";
[6222]351 }
352}
353
354// Copy header
355////////////////////////////////////////////////////////////////////////////
356void t_rnxObsHeader::set(const t_rnxObsHeader& header, int version,
[6841]357 const QStringList* useObsTypes,
358 const QStringList* phaseShifts,
359 const QStringList* gloBiases,
360 const QStringList* gloSlots) {
[6222]361
362 if (version <= 2) {
363 _version = t_rnxObsHeader::defaultRnxObsVersion2;
364 }
365 else {
366 _version = t_rnxObsHeader::defaultRnxObsVersion3;
367 }
[7474]368 _interval = header._interval;
369 _antennaNumber = header._antennaNumber;
370 _antennaName = header._antennaName;
371 _markerName = header._markerName;
372 _markerNumber = header._markerNumber;
[6943]373 _markerType = header._markerType;
[7474]374 _antNEU = header._antNEU;
375 _antXYZ = header._antXYZ;
376 _antBSG = header._antBSG;
377 _xyz = header._xyz;
378 _observer = header._observer;
379 _agency = header._agency;
380 _receiverNumber = header._receiverNumber;
381 _receiverType = header._receiverType;
[6222]382 _receiverVersion = header._receiverVersion;
[7474]383 _startTime = header._startTime;
[6224]384 _comments = header._comments;
[6245]385 _usedSystems = header._usedSystems;
[6841]386
[6222]387 for (unsigned iPrn = 1; iPrn <= t_prn::MAXPRN_GPS; iPrn++) {
[7474]388 _wlFactorsL1[iPrn] = header._wlFactorsL1[iPrn];
389 _wlFactorsL2[iPrn] = header._wlFactorsL2[iPrn];
[6222]390 }
391
392 // Set observation types
393 // ---------------------
394 _obsTypes.clear();
395 if (!useObsTypes || useObsTypes->size() == 0) {
396 if (int(_version) == int(header._version)) {
397 _obsTypes = header._obsTypes;
398 }
399 else {
[6250]400 if (_version >= 3.0) {
401 for (int iSys = 0; iSys < header.numSys(); iSys++) {
402 char sys = header.system(iSys);
403 for (int iType = 0; iType < header.nTypes(sys); iType++) {
404 QString type = header.obsType(sys, iType, _version);
405 if (!_obsTypes[sys].contains(type)) {
406 _obsTypes[sys].push_back(type);
407 }
[6249]408 }
[6250]409 }
410 }
411 else {
412 for (int iSys = 0; iSys < header.numSys(); iSys++) {
413 char sys = header.system(iSys);
414 for (int iType = 0; iType < header.nTypes(sys); iType++) {
415 QString type = header.obsType(sys, iType, _version);
[6249]416 for (int jSys = 0; jSys < _usedSystems.length(); jSys++) {
417 char thisSys = _usedSystems[jSys].toAscii();
418 if (!_obsTypes[thisSys].contains(type)) {
419 _obsTypes[thisSys].push_back(type);
420 }
421 }
422 }
[6222]423 }
424 }
425 }
426 }
427 else {
428 for (int iType = 0; iType < useObsTypes->size(); iType++) {
429 if (useObsTypes->at(iType).indexOf(":") != -1) {
430 QStringList hlp = useObsTypes->at(iType).split(":", QString::SkipEmptyParts);
431 if (hlp.size() == 2 && hlp[0].length() == 1) {
[6248]432 if (_version >= 3.0) {
433 char sys = hlp[0][0].toAscii();
434 QString type = t_rnxObsFile::type2to3(sys, hlp[1]);
435 if (!_obsTypes[sys].contains(type)) {
436 _obsTypes[sys].push_back(type);
437 }
438 }
439 else {
440 for (int iSys = 0; iSys < _usedSystems.length(); iSys++) {
441 char sys = _usedSystems[iSys].toAscii();
442 QString type = t_rnxObsFile::type3to2(sys, hlp[1]);
443 if (!_obsTypes[sys].contains(type)) {
444 _obsTypes[sys].push_back(type);
445 }
446 }
447 }
[6222]448 }
449 }
450 else {
[6245]451 for (int iSys = 0; iSys < _usedSystems.length(); iSys++) {
[6248]452 char sys = _usedSystems[iSys].toAscii();
[7474]453 QString type = _version >= 3.0 ? t_rnxObsFile::type2to3(sys, useObsTypes->at(iType)) :
[6248]454 t_rnxObsFile::type3to2(sys, useObsTypes->at(iType));
455 if (!_obsTypes[sys].contains(type)) {
456 _obsTypes[sys].push_back(type);
457 }
[6222]458 }
459 }
460 }
[6245]461 _usedSystems.clear();
[6244]462 QMapIterator<char, QStringList> it(_obsTypes);
463 while (it.hasNext()) {
464 it.next();
[6245]465 _usedSystems += QChar(it.key());
[6244]466 }
[6222]467 }
[6841]468
469 if (_version >= 3.0) {
470 // set phase shifts
471 if (!phaseShifts || phaseShifts->empty()) {
472 _phaseShifts = header._phaseShifts;
473 }
474 else {
475 foreach (const QString &str, *phaseShifts) {
476 QStringList hlp = str.split("_", QString::SkipEmptyParts);
477 QStringList hlp1 = hlp.last().split(":", QString::SkipEmptyParts);
478 QString type = hlp.first();
479 double shift = hlp1.first().toDouble();
480 hlp1.removeFirst();
481 QStringList &satList = hlp1;
482 QMap<QString, QPair<double, QStringList> >::iterator it = _phaseShifts.find(type);
483 if ( it != _phaseShifts.end()) {
484 it.value().second.append(satList);
485 it.value().second.removeDuplicates();
486 }
487 else {
488 _phaseShifts.insert(type, QPair<double, QStringList>(shift, satList));
489 }
490 }
491 }
492 // set GLONASS biases
493 if (!gloBiases || gloBiases->empty()) {
494 _gloBiases = header._gloBiases;
495 }
496 else {
497 foreach (const QString &str, *gloBiases) {
498 QStringList hlp = str.split(":", QString::SkipEmptyParts);
499 QString type = hlp.first();;
500 double value = hlp.last().toDouble();
501 if (type.size())
502 _gloBiases[type] = value;
503 }
504 }
505 // set GLONASS slots
506 if (!gloSlots || gloSlots->empty()) {
507 _gloSlots = header._gloSlots;
508 }
509 else {
510 foreach (const QString &str, *gloSlots) {
511 QStringList hlp = str.split(":", QString::SkipEmptyParts);
512 QString sat = hlp.first();
513 int slot = hlp.last().toInt();
514 t_prn prn;
515 prn.set(sat.toStdString());
516 if(sat.size())
517 _gloSlots[prn] = slot;
518 }
519 }
520 }
[6222]521}
522
[4481]523// Write Header
524////////////////////////////////////////////////////////////////////////////
525void t_rnxObsHeader::write(QTextStream* stream,
526 const QMap<QString, QString>* txtMap) const {
527
[4493]528 QStringList newComments;
[5068]529 QString runBy = BNC_CORE->userName();
[4481]530
531 if (txtMap) {
[7474]532 QMapIterator<QString, QString> it(*txtMap);
[4481]533 while (it.hasNext()) {
534 it.next();
535 if (it.key() == "RUN BY") {
536 runBy = it.value();
537 }
[7474]538 else if ((it.key().indexOf("COMMENT")) != -1) {
539 newComments += it.value().split("\\n", QString::SkipEmptyParts);
[4481]540 }
541 }
542 }
543
[6941]544 *stream << QString("%1 OBSERVATION DATA M")
[4481]545 .arg(_version, 9, 'f', 2)
546 .leftJustified(60)
547 << "RINEX VERSION / TYPE\n";
548
549 const QString fmtDate = (_version < 3.0) ? "dd-MMM-yy hh:mm"
550 : "yyyyMMdd hhmmss UTC";
551 *stream << QString("%1%2%3")
[5068]552 .arg(BNC_CORE->pgmName(), -20)
[4481]553 .arg(runBy.trimmed().left(20), -20)
554 .arg(QDateTime::currentDateTime().toUTC().toString(fmtDate), -20)
555 .leftJustified(60)
556 << "PGM / RUN BY / DATE\n";
557
[4493]558 QStringListIterator itCmnt(_comments + newComments);
[4481]559 while (itCmnt.hasNext()) {
560 *stream << itCmnt.next().trimmed().left(60).leftJustified(60) << "COMMENT\n";
561 }
562
563 *stream << QString("%1")
564 .arg(_markerName, -60)
565 .leftJustified(60)
566 << "MARKER NAME\n";
567
568 if (!_markerNumber.isEmpty()) {
569 *stream << QString("%1")
570 .arg(_markerNumber, -20)
571 .leftJustified(60)
572 << "MARKER NUMBER\n";
573 }
574
[6941]575 *stream << QString("%1")
576 .arg(_markerType, -60)
577 .leftJustified(60)
578 << "MARKER TYPE\n";
[7474]579
[4481]580 *stream << QString("%1%2")
[4529]581 .arg(_observer, -20)
582 .arg(_agency, -40)
[4481]583 .leftJustified(60)
584 << "OBSERVER / AGENCY\n";
585
586 *stream << QString("%1%2%3")
[4529]587 .arg(_receiverNumber, -20)
588 .arg(_receiverType, -20)
589 .arg(_receiverVersion, -20)
[4481]590 .leftJustified(60)
591 << "REC # / TYPE / VERS\n";
592
593 *stream << QString("%1%2")
[4529]594 .arg(_antennaNumber, -20)
595 .arg(_antennaName, -20)
[4481]596 .leftJustified(60)
597 << "ANT # / TYPE\n";
598
599 *stream << QString("%1%2%3")
600 .arg(_xyz(1), 14, 'f', 4)
601 .arg(_xyz(2), 14, 'f', 4)
602 .arg(_xyz(3), 14, 'f', 4)
603 .leftJustified(60)
604 << "APPROX POSITION XYZ\n";
605
606 *stream << QString("%1%2%3")
607 .arg(_antNEU(3), 14, 'f', 4)
608 .arg(_antNEU(2), 14, 'f', 4)
609 .arg(_antNEU(1), 14, 'f', 4)
610 .leftJustified(60)
611 << "ANTENNA: DELTA H/E/N\n";
612
613 if (_version < 3.0) {
614 int defaultWlFact1 = _wlFactorsL1[1];
615 int defaultWlFact2 = _wlFactorsL2[1]; // TODO check all prns
616 *stream << QString("%1%2")
617 .arg(defaultWlFact1, 6)
618 .arg(defaultWlFact2, 6)
619 .leftJustified(60)
620 << "WAVELENGTH FACT L1/2\n";
621 }
622
623 *stream << obsTypesStrings().join("");
624
[4484]625 if (_interval > 0) {
626 *stream << QString("%1")
627 .arg(_interval, 10, 'f', 3)
628 .leftJustified(60)
629 << "INTERVAL\n";
630 }
[4481]631
632 unsigned year, month, day, hour, min;
633 double sec;
634 _startTime.civil_date(year, month, day);
635 _startTime.civil_time(hour, min, sec);
636 *stream << QString("%1%2%3%4%5%6%7")
637 .arg(year, 6)
638 .arg(month, 6)
639 .arg(day, 6)
640 .arg(hour, 6)
641 .arg(min, 6)
642 .arg(sec, 13, 'f', 7)
643 .arg("GPS", 8)
644 .leftJustified(60)
645 << "TIME OF FIRST OBS\n";
646
[6719]647 if (_version >= 3.0) {
648 if (_phaseShifts.empty()) {
[6815]649 QMap<char, QStringList>::const_iterator it;
650 for (it = _obsTypes.begin(); it != _obsTypes.end(); ++it) {
651 char sys = it.key();
652 double shift = 0.0;
653 foreach (const QString &obstype, it.value()) {
654 if (obstype.left(1).contains('L')) {
[6866]655 *stream << QString("%1%2%3")
[6815]656 .arg(sys, 0)
[6866]657 .arg(obstype, 4)
[6815]658 .arg(shift, 9, 'f', 5)
659 .leftJustified(60)
660 << "SYS / PHASE SHIFT\n";
661 }
662 }
[6719]663 }
664 } else {
[6815]665 QMap<QString, QPair<double, QStringList> >::const_iterator it;
666 QString emptyFillStr;
667 for(it = _phaseShifts.begin(); it!= _phaseShifts.end(); ++it) {
668 QString sys = it.key().left(1);
669 QString obstype = it.key().mid(1);
670 double shift = it.value().first;
[6865]671 QStringList satList = it.value().second;
[6870]672 QString hlp;
673 if (obstype.isEmpty()) {
674 hlp = QString("%1")
675 .arg(sys.toStdString().c_str(), 0);
676 }
677 else {
678 hlp = QString("%1%2%3")
679 .arg(sys.toStdString().c_str(), 0)
680 .arg(obstype, 4)
681 .arg(shift, 9, 'f', 5);
682 }
[6815]683 if (!satList.empty()) {
[6865]684 hlp += QString("%1").arg(satList.size(), 4);
[6815]685 }
686 else {
687 *stream << QString("%1")
688 .arg(hlp, 0)
689 .leftJustified(60)
690 << "SYS / PHASE SHIFT\n";
691 hlp = "";
692 }
693 int ii = 0;
694 QStringList::const_iterator it_s;
695 for (it_s = satList.begin(); it_s != satList.end(); ++it_s) {
696 (hlp.contains(obstype)) ?
[6865]697 emptyFillStr = "": emptyFillStr = " ";
698 hlp += QString("%1").arg(*it_s, 4);
[6815]699 ii++;
700 if (ii % 10 == 0) {
701 *stream << QString("%1%2")
702 .arg(emptyFillStr, 0)
703 .arg(hlp, 0)
704 .leftJustified(60)
705 << "SYS / PHASE SHIFT\n";
706 hlp = "";
707 }
708 }
709 if (hlp.size()) {
[6865]710 (hlp.contains(obstype)) ?
711 emptyFillStr = "": emptyFillStr = " ";
[6815]712 *stream << QString("%1%2")
713 .arg(emptyFillStr, 0)
714 .arg(hlp, 0)
[6719]715 .leftJustified(60)
[6815]716 << "SYS / PHASE SHIFT\n";
717 }
[6719]718 }
719 }
720 }
721
722 if (_version >= 3.0) {
723 QString hlp = "";
[6841]724 QMap<QString, double>::const_iterator it = _gloBiases.begin();
725 while (it != _gloBiases.end()){
[6719]726 hlp += QString("%1%2").arg(it.key(), 4).arg(it.value(), 9, 'f', 3);
727 it++;
728 }
729 *stream << QString("%1")
730 .arg(hlp, 0)
731 .leftJustified(60)
732 << "GLONASS COD/PHS/BIS\n";
733 }
734
735 if (_version >= 3.0) {
736 QString number = QString::number(_gloSlots.size());
737 QString hlp = "";
738 int ii = 0;
739 QMap<t_prn, int>::const_iterator it = _gloSlots.begin();
740 while (it != _gloSlots.end()) {
741 QString prn(it.key().toString().c_str());
742 hlp += QString("%1%2").arg(prn, 4).arg(it.value(), 3);
743 it++;
744 ii++;
745 if (ii % 8 == 0) {
746 *stream << QString("%1%2")
747 .arg(number, 3)
748 .arg(hlp, 0)
749 .leftJustified(60)
750 << "GLONASS SLOT / FRQ #\n";
751 ii = 0;
752 hlp = number = "";
753 }
754 }
755 if (hlp.size() || !_gloSlots.size()) {
756 *stream << QString("%1%2")
757 .arg(number, 3)
758 .arg(hlp, 0)
759 .leftJustified(60)
760 << "GLONASS SLOT / FRQ #\n";
761 }
762 }
763
[4481]764 *stream << QString()
765 .leftJustified(60)
766 << "END OF HEADER\n";
767}
768
[6119]769// Number of Different Systems
770////////////////////////////////////////////////////////////////////////////
771int t_rnxObsHeader::numSys() const {
772 return _obsTypes.size();
773}
774
[7474]775//
[6130]776////////////////////////////////////////////////////////////////////////////
777char t_rnxObsHeader::system(int iSys) const {
778 int iSysLocal = -1;
[6230]779 QMapIterator<char, QStringList> it(_obsTypes);
[6130]780 while (it.hasNext()) {
781 ++iSysLocal;
782 it.next();
783 if (iSysLocal == iSys) {
784 return it.key();
785 }
786 }
787 return ' ';
788}
789
[7474]790//
791////////////////////////////////////////////////////////////////////////////
792QString t_rnxObsHeader::usedSystems(void) const {
793 return _usedSystems;
794}
795
796QStringList t_rnxObsHeader::obsTypes(char sys) const {
797 if (_obsTypes.contains(sys)) {
798 return _obsTypes[sys];
799 }
800 else {
801 return QStringList();
802 }
803}
804
[3716]805// Number of Observation Types (satellite-system specific)
806////////////////////////////////////////////////////////////////////////////
[4480]807int t_rnxObsHeader::nTypes(char sys) const {
[6119]808 if (_obsTypes.contains(sys)) {
809 return _obsTypes[sys].size();
[3716]810 }
811 else {
[6119]812 return 0;
[3716]813 }
814}
815
[6841]816// Number of GLONASS biases
817////////////////////////////////////////////////////////////////////////////
818int t_rnxObsHeader::numGloBiases() const {
819 return _gloBiases.size();
820}
821
[6842]822// Number of GLONASS slots
[6841]823////////////////////////////////////////////////////////////////////////////
824int t_rnxObsHeader::numGloSlots() const {
825 return _gloSlots.size();
826}
827
[3716]828// Observation Type (satellite-system specific)
829////////////////////////////////////////////////////////////////////////////
[6126]830QString t_rnxObsHeader::obsType(char sys, int index, double version) const {
831
832 if (version == 0.0) {
833 version = _version;
834 }
[6119]835 if (_obsTypes.contains(sys)) {
[6126]836 QString origType = _obsTypes[sys].at(index);
837 if (int(version) == int(_version)) {
838 return origType;
839 }
840 else if (int(version) == 2) {
[6192]841 return t_rnxObsFile::type3to2(sys, origType);
[6126]842 }
843 else if (int(version) == 3) {
[6192]844 return t_rnxObsFile::type2to3(sys, origType);
[6126]845 }
[3716]846 }
[6126]847 return "";
[3716]848}
849
[6841]850//
851////////////////////////////////////////////////////////////////////////////
852QStringList t_rnxObsHeader::phaseShifts() const {
853 QStringList strList;
854 QMap<QString, QPair<double, QStringList> >::const_iterator it = _phaseShifts.begin();
855 while (it != _phaseShifts.end()) {
856 strList.append(QString("%1_%2:%3").arg(it.key(), 3).arg(it.value().first, 9, 'f', 3).arg(it.value().second.join("")));
857 it++;
858 }
859 return strList;
860}
861
862//
863////////////////////////////////////////////////////////////////////////////
864QStringList t_rnxObsHeader::gloBiases() const {
865 QStringList strList;
866 QMap<QString, double>::const_iterator it = _gloBiases.begin();
867 while (it != _gloBiases.end()) {
868 strList.append(QString("%1:%2").arg(it.key(), 3).arg(it.value(), 9, 'f', 3));
869 it++;
870 }
871 return strList;
872}
873
874//
875////////////////////////////////////////////////////////////////////////////
876QStringList t_rnxObsHeader::gloSlots() const {
877 QStringList strList;
878 QMap<t_prn, int>::const_iterator it = _gloSlots.begin();
879 while (it != _gloSlots.end()){
880 QString prn(it.key().toString().c_str());
881 strList.append(QString("%1:%2").arg(prn, 3).arg(it.value()));
882 it++;
883 }
884 return strList;
885}
886
[4481]887// Write Observation Types
888////////////////////////////////////////////////////////////////////////////
889QStringList t_rnxObsHeader::obsTypesStrings() const {
890
891 QStringList strList;
892 if (_version < 3.0) {
[6245]893 char sys0 = _usedSystems[0].toAscii();
[4481]894 QString hlp;
[6125]895 QTextStream(&hlp) << QString("%1").arg(_obsTypes[sys0].size(), 6);
896 for (int ii = 0; ii < _obsTypes[sys0].size(); ii++) {
[7474]897 QTextStream(&hlp) << QString("%1").arg(_obsTypes[sys0][ii], 6);
[6125]898 if ((ii+1) % 9 == 0 || ii == _obsTypes[sys0].size()-1) {
[4481]899 strList.append(hlp.leftJustified(60) + "# / TYPES OF OBSERV\n");
900 hlp = QString().leftJustified(6);
901 }
902 }
903 }
904 else {
[6219]905 for (int iSys = 0; iSys < numSys(); iSys++) {
906 char sys = system(iSys);
[4481]907 QString hlp;
[6219]908 QTextStream(&hlp) << QString("%1 %2").arg(sys).arg(nTypes(sys), 3);
909 for (int iType = 0; iType < nTypes(sys); iType++) {
[6221]910 QString type = obsType(sys, iType);
[7474]911 QTextStream(&hlp) << QString(" %1").arg(type, -3);
[6219]912 if ((iType+1) % 13 == 0 || iType == nTypes(sys)-1) {
[4481]913 strList.append(hlp.leftJustified(60) + "SYS / # / OBS TYPES\n");
914 hlp = QString().leftJustified(6);
915 }
916 }
917 }
918 }
919
920 return strList;
921}
922
[3716]923// Constructor
924////////////////////////////////////////////////////////////////////////////
[3843]925t_rnxObsFile::t_rnxObsFile(const QString& fileName, e_inpOut inpOut) {
926 _inpOut = inpOut;
[3716]927 _stream = 0;
928 _flgPowerFail = false;
[3843]929 if (_inpOut == input) {
930 openRead(fileName);
931 }
932 else {
[3845]933 openWrite(fileName);
[3843]934 }
[3716]935}
936
[3845]937// Open for input
[3716]938////////////////////////////////////////////////////////////////////////////
[3843]939void t_rnxObsFile::openRead(const QString& fileName) {
[3718]940
941 _fileName = fileName; expandEnvVar(_fileName);
942 _file = new QFile(_fileName);
943 _file->open(QIODevice::ReadOnly | QIODevice::Text);
944 _stream = new QTextStream();
945 _stream->setDevice(_file);
946
[3716]947 _header.read(_stream);
948
949 // Guess Observation Interval
950 // --------------------------
951 if (_header._interval == 0.0) {
952 bncTime ttPrev;
953 for (int iEpo = 0; iEpo < 10; iEpo++) {
954 const t_rnxEpo* rnxEpo = nextEpoch();
955 if (!rnxEpo) {
[3718]956 throw QString("t_rnxObsFile: not enough epochs");
[3716]957 }
958 if (iEpo > 0) {
959 double dt = rnxEpo->tt - ttPrev;
960 if (_header._interval == 0.0 || dt < _header._interval) {
961 _header._interval = dt;
962 }
963 }
964 ttPrev = rnxEpo->tt;
965 }
[3719]966 _stream->seek(0);
[3716]967 _header.read(_stream);
968 }
[3837]969
970 // Time of first observation
971 // -------------------------
972 if (!_header._startTime.valid()) {
973 const t_rnxEpo* rnxEpo = nextEpoch();
974 if (!rnxEpo) {
975 throw QString("t_rnxObsFile: not enough epochs");
976 }
977 _header._startTime = rnxEpo->tt;
978 _stream->seek(0);
979 _header.read(_stream);
980 }
[3716]981}
982
[3845]983// Open for output
984////////////////////////////////////////////////////////////////////////////
985void t_rnxObsFile::openWrite(const QString& fileName) {
986
987 _fileName = fileName; expandEnvVar(_fileName);
988 _file = new QFile(_fileName);
989 _file->open(QIODevice::WriteOnly | QIODevice::Text);
990 _stream = new QTextStream();
991 _stream->setDevice(_file);
992}
993
[3716]994// Destructor
995////////////////////////////////////////////////////////////////////////////
996t_rnxObsFile::~t_rnxObsFile() {
997 close();
998}
999
1000// Close
1001////////////////////////////////////////////////////////////////////////////
1002void t_rnxObsFile::close() {
1003 delete _stream; _stream = 0;
[3718]1004 delete _file; _file = 0;
[3716]1005}
1006
1007// Handle Special Epoch Flag
1008////////////////////////////////////////////////////////////////////////////
[7474]1009void t_rnxObsFile::handleEpochFlag(int flag, const QString& line,
[4540]1010 bool& headerReRead) {
[3716]1011
[4540]1012 headerReRead = false;
1013
[3716]1014 // Power Failure
1015 // -------------
1016 if (flag == 1) {
1017 _flgPowerFail = true;
1018 }
1019
1020 // Start moving antenna
1021 // --------------------
1022 else if (flag == 2) {
1023 // no action
1024 }
1025
1026 // Re-Read Header
[7474]1027 // --------------
[5468]1028 else if (flag == 3 || flag == 4 || flag == 5) {
[3716]1029 int numLines = 0;
1030 if (version() < 3.0) {
1031 readInt(line, 29, 3, numLines);
1032 }
1033 else {
1034 readInt(line, 32, 3, numLines);
1035 }
[5468]1036 if (flag == 3 || flag == 4) {
1037 _header.read(_stream, numLines);
1038 headerReRead = true;
1039 }
1040 else {
1041 for (int ii = 0; ii < numLines; ii++) {
1042 _stream->readLine();
1043 }
1044 }
[3716]1045 }
1046
1047 // Unhandled Flag
1048 // --------------
1049 else {
[3718]1050 throw QString("t_rnxObsFile: unhandled flag\n" + line);
[3716]1051 }
1052}
1053
1054// Retrieve single Epoch
1055////////////////////////////////////////////////////////////////////////////
[3994]1056t_rnxObsFile::t_rnxEpo* t_rnxObsFile::nextEpoch() {
[3716]1057 _currEpo.clear();
1058 if (version() < 3.0) {
1059 return nextEpochV2();
1060 }
1061 else {
1062 return nextEpochV3();
1063 }
1064}
1065
1066// Retrieve single Epoch (RINEX Version 3)
1067////////////////////////////////////////////////////////////////////////////
[3994]1068t_rnxObsFile::t_rnxEpo* t_rnxObsFile::nextEpochV3() {
[3716]1069
[3719]1070 while ( _stream->status() == QTextStream::Ok && !_stream->atEnd() ) {
[3716]1071
[3718]1072 QString line = _stream->readLine();
[3716]1073
[3718]1074 if (line.isEmpty()) {
[3716]1075 continue;
1076 }
1077
1078 int flag = 0;
1079 readInt(line, 31, 1, flag);
1080 if (flag > 0) {
[4540]1081 bool headerReRead = false;
1082 handleEpochFlag(flag, line, headerReRead);
1083 if (headerReRead) {
1084 continue;
1085 }
[3716]1086 }
1087
[3718]1088 QTextStream in(line.mid(1).toAscii(), QIODevice::ReadOnly);
[3716]1089
1090 // Epoch Time
1091 // ----------
1092 int year, month, day, hour, min;
1093 double sec;
1094 in >> year >> month >> day >> hour >> min >> sec;
[3720]1095 _currEpo.tt.set(year, month, day, hour, min, sec);
[3716]1096
1097 // Number of Satellites
1098 // --------------------
1099 int numSat;
1100 readInt(line, 32, 3, numSat);
[7474]1101
[3716]1102 _currEpo.rnxSat.resize(numSat);
1103
1104 // Observations
1105 // ------------
1106 for (int iSat = 0; iSat < numSat; iSat++) {
[3718]1107 line = _stream->readLine();
[6119]1108 t_prn prn; prn.set(line.left(3).toAscii().data());
1109 _currEpo.rnxSat[iSat].prn = prn;
1110 char sys = prn.system();
[3716]1111 for (int iType = 0; iType < _header.nTypes(sys); iType++) {
1112 int pos = 3 + 16*iType;
1113 double obsValue = 0.0;
[7474]1114 int lli = 0;
[3716]1115 int snr = 0;
1116 readDbl(line, pos, 14, obsValue);
1117 readInt(line, pos + 14, 1, lli);
1118 readInt(line, pos + 15, 1, snr);
1119 if (_flgPowerFail) {
1120 lli |= 1;
1121 }
[6119]1122 QString type = obsType(sys, iType);
1123 _currEpo.rnxSat[iSat].obs[type].value = obsValue;
1124 _currEpo.rnxSat[iSat].obs[type].lli = lli;
1125 _currEpo.rnxSat[iSat].obs[type].snr = snr;
[3716]1126 }
1127 }
1128
1129 _flgPowerFail = false;
1130
1131 return &_currEpo;
1132 }
1133
1134 return 0;
1135}
1136
1137// Retrieve single Epoch (RINEX Version 2)
1138////////////////////////////////////////////////////////////////////////////
[3994]1139t_rnxObsFile::t_rnxEpo* t_rnxObsFile::nextEpochV2() {
[3716]1140
[3719]1141 while ( _stream->status() == QTextStream::Ok && !_stream->atEnd() ) {
[3716]1142
[3718]1143 QString line = _stream->readLine();
[3716]1144
[3718]1145 if (line.isEmpty()) {
[3716]1146 continue;
1147 }
1148
1149 int flag = 0;
1150 readInt(line, 28, 1, flag);
1151 if (flag > 0) {
[4540]1152 bool headerReRead = false;
1153 handleEpochFlag(flag, line, headerReRead);
1154 if (headerReRead) {
1155 continue;
1156 }
[3716]1157 }
1158
[3718]1159 QTextStream in(line.toAscii(), QIODevice::ReadOnly);
[3716]1160
1161 // Epoch Time
1162 // ----------
1163 int year, month, day, hour, min;
1164 double sec;
1165 in >> year >> month >> day >> hour >> min >> sec;
1166 if (year < 80) {
1167 year += 2000;
1168 }
1169 else if (year < 100) {
1170 year += 1900;
1171 }
[3720]1172 _currEpo.tt.set(year, month, day, hour, min, sec);
[3716]1173
1174 // Number of Satellites
1175 // --------------------
1176 int numSat;
1177 readInt(line, 29, 3, numSat);
[7474]1178
[3716]1179 _currEpo.rnxSat.resize(numSat);
1180
1181 // Read Satellite Numbers
1182 // ----------------------
1183 int pos = 32;
1184 for (int iSat = 0; iSat < numSat; iSat++) {
1185 if (iSat > 0 && iSat % 12 == 0) {
[3718]1186 line = _stream->readLine();
[3716]1187 pos = 32;
1188 }
1189
[6119]1190 char sys = line.toAscii()[pos];
[6258]1191 if (sys == ' ') {
1192 sys = 'G';
1193 }
[6119]1194 int satNum; readInt(line, pos + 1, 2, satNum);
1195 _currEpo.rnxSat[iSat].prn.set(sys, satNum);
[7474]1196
[3716]1197 pos += 3;
1198 }
1199
1200 // Read Observation Records
1201 // ------------------------
1202 for (int iSat = 0; iSat < numSat; iSat++) {
[6119]1203 char sys = _currEpo.rnxSat[iSat].prn.system();
[3718]1204 line = _stream->readLine();
[3716]1205 pos = 0;
[6119]1206 for (int iType = 0; iType < _header.nTypes(sys); iType++) {
[3716]1207 if (iType > 0 && iType % 5 == 0) {
[3718]1208 line = _stream->readLine();
[3716]1209 pos = 0;
1210 }
1211 double obsValue = 0.0;
1212 int lli = 0;
1213 int snr = 0;
1214 readDbl(line, pos, 14, obsValue);
1215 readInt(line, pos + 14, 1, lli);
1216 readInt(line, pos + 15, 1, snr);
1217
1218 if (_flgPowerFail) {
1219 lli |= 1;
1220 }
1221
[6119]1222 QString type = obsType(sys, iType);
1223 _currEpo.rnxSat[iSat].obs[type].value = obsValue;
1224 _currEpo.rnxSat[iSat].obs[type].lli = lli;
1225 _currEpo.rnxSat[iSat].obs[type].snr = snr;
[3716]1226
1227 pos += 16;
1228 }
1229 }
[7474]1230
[3716]1231 _flgPowerFail = false;
1232
1233 return &_currEpo;
1234 }
[7474]1235
[3716]1236 return 0;
1237}
1238
[3845]1239// Write Data Epoch
1240////////////////////////////////////////////////////////////////////////////
1241void t_rnxObsFile::writeEpoch(const t_rnxEpo* epo) {
[6246]1242 if (epo == 0) {
1243 return;
1244 }
1245 t_rnxEpo epoLocal;
1246 epoLocal.tt = epo->tt;
1247 for (unsigned ii = 0; ii < epo->rnxSat.size(); ii++) {
1248 const t_rnxSat& rnxSat = epo->rnxSat[ii];
1249 if (_header._obsTypes[rnxSat.prn.system()].size() > 0) {
[7474]1250 epoLocal.rnxSat.push_back(rnxSat);
[6246]1251 }
1252 }
1253
[3866]1254 if (version() < 3.0) {
[6246]1255 return writeEpochV2(_stream, _header, &epoLocal);
[3866]1256 }
1257 else {
[6246]1258 return writeEpochV3(_stream, _header, &epoLocal);
[3866]1259 }
1260}
[3855]1261
[3866]1262// Write Data Epoch (RINEX Version 2)
1263////////////////////////////////////////////////////////////////////////////
[7474]1264void t_rnxObsFile::writeEpochV2(QTextStream* stream, const t_rnxObsHeader& header,
[6222]1265 const t_rnxEpo* epo) {
[3866]1266
[3855]1267 unsigned year, month, day, hour, min;
1268 double sec;
1269 epo->tt.civil_date(year, month, day);
1270 epo->tt.civil_time(hour, min, sec);
1271
1272 QString dateStr;
[3868]1273 QTextStream(&dateStr) << QString(" %1 %2 %3 %4 %5%6")
[3856]1274 .arg(int(fmod(year, 100)), 2, 10, QChar('0'))
[3868]1275 .arg(month, 2, 10, QChar('0'))
1276 .arg(day, 2, 10, QChar('0'))
1277 .arg(hour, 2, 10, QChar('0'))
1278 .arg(min, 2, 10, QChar('0'))
1279 .arg(sec, 11, 'f', 7);
[3855]1280
[3857]1281 int flag = 0;
[6222]1282 *stream << dateStr << QString("%1%2").arg(flag, 3).arg(epo->rnxSat.size(), 3);
[3858]1283 for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
[3869]1284 const t_rnxSat& rnxSat = epo->rnxSat[iSat];
[3858]1285 if (iSat > 0 && iSat % 12 == 0) {
[6222]1286 *stream << endl << QString().leftJustified(32);
[3857]1287 }
[6222]1288 *stream << rnxSat.prn.toString().c_str();
[3857]1289 }
[6222]1290 *stream << endl;
[3858]1291 for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
[3967]1292
[3858]1293 const t_rnxSat& rnxSat = epo->rnxSat[iSat];
[6119]1294 char sys = rnxSat.prn.system();
[3966]1295
[6222]1296 for (int iTypeV2 = 0; iTypeV2 < header.nTypes(sys); iTypeV2++) {
[6216]1297 if (iTypeV2 > 0 && iTypeV2 % 5 == 0) {
[6222]1298 *stream << endl;
[3967]1299 }
[6222]1300 QString typeV2 = header.obsType(sys, iTypeV2);
[6216]1301 bool found = false;
[7474]1302
[6241]1303 QString preferredAttrib = signalPriorities(sys);
[6231]1304 for (int iPref = 0; iPref < preferredAttrib.length(); iPref++) {
1305 QMapIterator<QString, t_rnxObs> itObs(rnxSat.obs);
1306 while (itObs.hasNext()) {
1307 itObs.next();
1308 const QString& type = itObs.key();
1309 const t_rnxObs& rnxObs = itObs.value();
[6232]1310 if ( preferredAttrib[iPref] == '?' ||
[6241]1311 (type.length() == 2 && preferredAttrib[iPref] == '_' ) ||
[6232]1312 (type.length() == 3 && preferredAttrib[iPref] == type[2]) ) {
1313 if (typeV2 == type3to2(sys, type)) {
1314 found = true;
1315 if (rnxObs.value == 0.0) {
1316 *stream << QString().leftJustified(16);
[6231]1317 }
1318 else {
[6232]1319 *stream << QString("%1").arg(rnxObs.value, 14, 'f', 3);
1320 if (rnxObs.lli != 0.0) {
1321 *stream << QString("%1").arg(rnxObs.lli,1);
1322 }
1323 else {
1324 *stream << ' ';
1325 }
1326 if (rnxObs.snr != 0.0) {
1327 *stream << QString("%1").arg(rnxObs.snr,1);
1328 }
1329 else {
1330 *stream << ' ';
1331 }
[6231]1332 }
[6251]1333 goto end_loop_iPref;
[6216]1334 }
[6127]1335 }
[6231]1336 }
[6251]1337 } end_loop_iPref:
[6216]1338 if (!found) {
[6222]1339 *stream << QString().leftJustified(16);
[6216]1340 }
[3858]1341 }
[6222]1342 *stream << endl;
[3858]1343 }
[3845]1344}
[3866]1345
1346// Write Data Epoch (RINEX Version 3)
1347////////////////////////////////////////////////////////////////////////////
[7474]1348void t_rnxObsFile::writeEpochV3(QTextStream* stream, const t_rnxObsHeader& header,
[6222]1349 const t_rnxEpo* epo) {
[3866]1350
1351 unsigned year, month, day, hour, min;
1352 double sec;
1353 epo->tt.civil_date(year, month, day);
1354 epo->tt.civil_time(hour, min, sec);
1355
[3867]1356 QString dateStr;
[3868]1357 QTextStream(&dateStr) << QString("> %1 %2 %3 %4 %5%6")
[7478]1358 .arg(year, 4)
1359 .arg(month, 2, 10, QChar('0'))
1360 .arg(day, 2, 10, QChar('0'))
1361 .arg(hour, 2, 10, QChar('0'))
1362 .arg(min, 2, 10, QChar('0'))
1363 .arg(sec, 11, 'f', 7);
[3866]1364
[3867]1365 int flag = 0;
[6222]1366 *stream << dateStr << QString("%1%2\n").arg(flag, 3).arg(epo->rnxSat.size(), 3);
[3867]1367
[3869]1368 for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
[6588]1369 const t_rnxSat& rnxSat = epo->rnxSat[iSat];
[7478]1370 char sys = rnxSat.prn.system();
[3964]1371
[6585]1372 const t_rnxObs* hlp[header.nTypes(sys)];
[6222]1373 for (int iTypeV3 = 0; iTypeV3 < header.nTypes(sys); iTypeV3++) {
[6585]1374 hlp[iTypeV3] = 0;
[6222]1375 QString typeV3 = header.obsType(sys, iTypeV3);
[6220]1376 QMapIterator<QString, t_rnxObs> itObs(rnxSat.obs);
[6586]1377
1378 // Exact match
1379 // -----------
[6220]1380 while (itObs.hasNext()) {
1381 itObs.next();
[7478]1382 const QString& type = itObs.key();
[6220]1383 const t_rnxObs& rnxObs = itObs.value();
[6586]1384 if (typeV3 == type2to3(sys, type) && rnxObs.value != 0.0) {
[6585]1385 hlp[iTypeV3] = &itObs.value();
[3979]1386 }
[3869]1387 }
[6586]1388
1389 // Non-Exact match
1390 // ---------------
1391 itObs.toFront();
1392 while (itObs.hasNext()) {
1393 itObs.next();
[7478]1394 const QString& type = itObs.key();
[6586]1395 const t_rnxObs& rnxObs = itObs.value();
1396 if (hlp[iTypeV3] == 0 && typeV3 == type2to3(sys, type).left(2) && rnxObs.value != 0.0) {
1397 hlp[iTypeV3] = &itObs.value();
1398 }
1399 }
[6585]1400 }
1401
[7478]1402 if (header.nTypes(sys)) {
1403 *stream << rnxSat.prn.toString().c_str();
1404 for (int iTypeV3 = 0; iTypeV3 < header.nTypes(sys); iTypeV3++) {
1405 const t_rnxObs* rnxObs = hlp[iTypeV3];
1406 if (rnxObs == 0) {
1407 *stream << QString().leftJustified(16);
[6585]1408 }
1409 else {
[7478]1410 *stream << QString("%1").arg(rnxObs->value, 14, 'f', 3);
1411 if (rnxObs->lli != 0.0) {
1412 *stream << QString("%1").arg(rnxObs->lli, 1);
1413 }
1414 else {
1415 *stream << ' ';
1416 }
1417 if (rnxObs->snr != 0.0) {
1418 *stream << QString("%1").arg(rnxObs->snr, 1);
1419 }
1420 else {
1421 *stream << ' ';
1422 }
[6585]1423 }
1424 }
[7478]1425 *stream << endl;
[3869]1426 }
1427 }
[3866]1428}
[3956]1429
1430// Translate Observation Type v2 --> v3
1431////////////////////////////////////////////////////////////////////////////
[6193]1432QString t_rnxObsFile::type2to3(char sys, const QString& typeV2) {
[6147]1433 if (typeV2 == "P1") {
[6193]1434 return (sys == 'G') ? "C1W" : "C1P";
[3956]1435 }
[6147]1436 else if (typeV2 == "P2") {
[6193]1437 return (sys == 'G') ? "C2W" : "C2P";
[3956]1438 }
[6147]1439 return typeV2;
[3956]1440}
[3962]1441
1442// Translate Observation Type v3 --> v2
1443////////////////////////////////////////////////////////////////////////////
[6192]1444QString t_rnxObsFile::type3to2(char /* sys */, const QString& typeV3) {
[6193]1445 if (typeV3 == "C1P" || typeV3 == "C1W") {
[3962]1446 return "P1";
1447 }
[6193]1448 else if (typeV3 == "C2P" || typeV3 == "C2W") {
[3962]1449 return "P2";
1450 }
[6147]1451 return typeV3.left(2);
[3962]1452}
[4053]1453
[5883]1454// Set Observations from RINEX File
1455////////////////////////////////////////////////////////////////////////////
[7474]1456void t_rnxObsFile::setObsFromRnx(const t_rnxObsFile* rnxObsFile, const t_rnxObsFile::t_rnxEpo* epo,
[6137]1457 const t_rnxObsFile::t_rnxSat& rnxSat, t_satObs& obs) {
1458 obs._staID = rnxObsFile->markerName().toAscii().constData();
1459 obs._prn = rnxSat.prn;
1460 obs._time = epo->tt;
[5883]1461
[6137]1462 char sys = rnxSat.prn.system();
[5883]1463
[6259]1464 QChar addToL2;
[6137]1465 for (int iType = 0; iType < rnxObsFile->nTypes(sys); iType++) {
[6253]1466 QString type = rnxObsFile->obsType(sys, iType);
1467 QString typeV3 = rnxObsFile->obsType(sys, iType, 3.0); // may or may not differ from type
[6259]1468 if (rnxSat.obs.contains(type) && rnxSat.obs[type].value != 0.0) {
1469 if (type == "P2" && typeV3.length() > 2) {
1470 addToL2 = typeV3[2];
1471 break;
1472 }
1473 }
1474 }
1475
1476 for (int iType = 0; iType < rnxObsFile->nTypes(sys); iType++) {
1477 QString type = rnxObsFile->obsType(sys, iType);
1478 QString typeV3 = rnxObsFile->obsType(sys, iType, 3.0); // may or may not differ from type
1479 if (type == "L2") {
1480 typeV3 += addToL2;
1481 }
[6119]1482 if (rnxSat.obs.contains(type)) {
1483 const t_rnxObs& rnxObs = rnxSat.obs[type];
[6188]1484 if (rnxObs.value != 0.0) {
[6253]1485 string type2ch(typeV3.mid(1).toAscii().data());
[7474]1486
[6188]1487 t_frqObs* frqObs = 0;
1488 for (unsigned iFrq = 0; iFrq < obs._obs.size(); iFrq++) {
1489 if (obs._obs[iFrq]->_rnxType2ch == type2ch) {
1490 frqObs = obs._obs[iFrq];
1491 break;
1492 }
1493 }
1494 if (frqObs == 0) {
1495 frqObs = new t_frqObs;
1496 frqObs->_rnxType2ch = type2ch;
1497 obs._obs.push_back(frqObs);
1498 }
[7474]1499
[6253]1500 switch( typeV3.toAscii().data()[0] ) {
[6188]1501 case 'C':
1502 frqObs->_codeValid = true;
1503 frqObs->_code = rnxObs.value;
[6137]1504 break;
[6188]1505 case 'L':
1506 frqObs->_phaseValid = true;
1507 frqObs->_phase = rnxObs.value;
1508 frqObs->_slip = (rnxObs.lli & 1);
1509 break;
1510 case 'D':
1511 frqObs->_dopplerValid = true;
1512 frqObs->_doppler = rnxObs.value;
1513 break;
1514 case 'S':
1515 frqObs->_snrValid = true;
1516 frqObs->_snr = rnxObs.value;
1517 break;
[6137]1518 }
[6260]1519
1520 // Handle old-fashioned SNR values
1521 // -------------------------------
1522 if (rnxObs.snr != 0 && !frqObs->_snrValid) {
1523 frqObs->_snrValid = true;
[6263]1524 frqObs->_snr = rnxObs.snr * 6.0 + 2.5;
[6260]1525 }
[6119]1526 }
[5883]1527 }
[6119]1528 }
1529}
1530
[6241]1531// Tracking Mode Priorities
1532////////////////////////////////////////////////////////////////////////////
1533QString t_rnxObsFile::signalPriorities(char sys) {
[6242]1534
1535 bncSettings settings;
[6675]1536
1537 QStringList priorList;
1538 QString reqcAction = settings.value("reqcAction").toString();
1539
1540 // Priorities in Edit/Concatenate (post processing) mode
1541 // ---------------------------------------------------
1542 if (reqcAction == "Edit/Concatenate") {
1543 priorList = settings.value("reqcV2Priority").toString().split(" ", QString::SkipEmptyParts);
1544 }
1545
1546 // Priorities in real-time mode
1547 // ----------------------------
1548 else {
1549 priorList = settings.value("rnxV2Priority").toString().split(" ", QString::SkipEmptyParts);
1550 }
1551
[6243]1552 if (priorList.empty()) {
1553 priorList << "CWPX_?";
1554 }
[6242]1555
1556 QString result;
1557 for (int ii = 0; ii < priorList.size(); ii++) {
1558 if (priorList[ii].indexOf(":") != -1) {
1559 QStringList hlp = priorList[ii].split(":", QString::SkipEmptyParts);
1560 if (hlp.size() == 2 && hlp[0].length() == 1 && hlp[0][0] == sys) {
1561 result = hlp[1];
1562 break;
1563 }
1564 }
1565 else {
1566 result = priorList[ii];
1567 }
1568 }
1569
1570 return result;
[6241]1571}
Note: See TracBrowser for help on using the repository browser.