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

Last change on this file since 8168 was 8168, checked in by stuerze, 7 years ago

IRNSS support is added in RINEX QC

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