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

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