source: ntrip/trunk/BNC/src/rinex/reqcedit.cpp@ 10615

Last change on this file since 10615 was 10614, checked in by stuerze, 4 days ago

bug fixes egarding RINEX Editing and QC

File size: 26.6 KB
Line 
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_reqcEdit
30 *
31 * Purpose: Edit/Concatenate RINEX Files
32 *
33 * Author: L. Mervart
34 *
35 * Created: 11-Apr-2012
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iostream>
42#include "reqcedit.h"
43#include "bnccore.h"
44#include "bncsettings.h"
45#include "bncutils.h"
46#include "rnxobsfile.h"
47#include "rnxnavfile.h"
48
49using namespace std;
50
51// Constructor
52////////////////////////////////////////////////////////////////////////////
53t_reqcEdit::t_reqcEdit(QObject* parent) : QThread(parent) {
54
55 bncSettings settings;
56
57 _logFileName = settings.value("reqcOutLogFile").toString(); expandEnvVar(_logFileName);
58 _logFile = 0;
59 _log = 0;
60 _obsFileNames = settings.value("reqcObsFile").toString().split(",", Qt::SkipEmptyParts);
61 _outObsFileName = settings.value("reqcOutObsFile").toString();
62 _navFileNames = settings.value("reqcNavFile").toString().split(",", Qt::SkipEmptyParts);
63 _outNavFileName = settings.value("reqcOutNavFile").toString();
64 int version = settings.value("reqcRnxVersion").toInt();
65 if (version == 2) {
66 _rnxVersion = defaultRnxObsVersion2;
67 }
68 else if (version == 3) {
69 _rnxVersion = defaultRnxObsVersion3;
70 }
71 else if (version == 4) {
72 _rnxVersion = defaultRnxObsVersion4;
73 }
74 _samplingRate = settings.value("reqcSampling").toString().split("sec").first().toDouble();
75 _begTime = bncTime(settings.value("reqcStartDateTime").toString().toLatin1().data());
76 _endTime = bncTime(settings.value("reqcEndDateTime").toString().toLatin1().data());
77
78 _checkEph = false;
79
80}
81
82// Destructor
83////////////////////////////////////////////////////////////////////////////
84t_reqcEdit::~t_reqcEdit() {
85 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
86 delete _rnxObsFiles[ii];
87 }
88 for (int ii = 0; ii < _ephs.size(); ii++) {
89 delete _ephs[ii];
90 }
91 delete _log; _log = 0;
92 delete _logFile; _logFile = 0;
93}
94
95//
96////////////////////////////////////////////////////////////////////////////
97void t_reqcEdit::run() {
98
99 // Open Log File
100 // -------------
101 if (!_logFileName.isEmpty()) {
102 _logFile = new QFile(_logFileName);
103 if (_logFile->open(QIODevice::WriteOnly | QIODevice::Text)) {
104 _log = new QTextStream();
105 _log->setDevice(_logFile);
106 }
107 }
108
109 // Log File Header
110 // ---------------
111 if (_log) {
112 *_log << QByteArray(78, '-') << Qt::endl;
113 *_log << "RINEX File Editing\n";
114 *_log << QByteArray(78, '-') << Qt::endl;
115
116 *_log << QByteArray("Program").leftJustified(15) << ": "
117 << BNC_CORE->pgmName() << Qt::endl;
118 *_log << QByteArray("Run by").leftJustified(15) << ": "
119 << BNC_CORE->userName() << Qt::endl;
120 *_log << QByteArray("Date").leftJustified(15) << ": "
121 << QDateTime::currentDateTime().toUTC().toString("yyyy-MM-dd hh:mm:ss") << Qt::endl;
122 *_log << QByteArray("RINEX Version").leftJustified(15) << ": "
123 << _rnxVersion << Qt::endl;
124 *_log << QByteArray("Sampling").leftJustified(15) << ": "
125 << _samplingRate << " sec" << Qt::endl;
126 *_log << QByteArray("Start time").leftJustified(15) << ": "
127 << _begTime.datestr().c_str() << ' '
128 << _begTime.timestr(0).c_str() << Qt::endl;
129 *_log << QByteArray("End time").leftJustified(15) << ": "
130 << _endTime.datestr().c_str() << ' '
131 << _endTime.timestr(0).c_str() << Qt::endl;
132 *_log << QByteArray("Input Obs Files").leftJustified(15) << ": "
133 << _obsFileNames.join(",") << Qt::endl;
134 *_log << QByteArray("Input Nav Files").leftJustified(15) << ": "
135 << _navFileNames.join(",") << Qt::endl;
136 *_log << QByteArray("Output Obs File").leftJustified(15) << ": "
137 << _outObsFileName << Qt::endl;
138 *_log << QByteArray("Output Nav File").leftJustified(15) << ": "
139 << _outNavFileName << Qt::endl;
140
141 *_log << QByteArray(78, '-') << Qt::endl;
142 _log->flush();
143 }
144
145 // Handle Observation Files
146 // ------------------------
147 editObservations();
148
149 // Handle Navigations Files
150 // ------------------------
151 editEphemerides();
152
153 // Exit (thread)
154 // -------------
155 if (BNC_CORE->mode() != t_bncCore::interactive) {
156 qApp->exit(9);
157 msleep(100); //sleep 0.1 sec
158 }
159 else {
160 emit finished();
161 deleteLater();
162 }
163
164}
165
166// Initialize input observation files, sort them according to start time
167////////////////////////////////////////////////////////////////////////////
168void t_reqcEdit::initRnxObsFiles(const QStringList& obsFileNames,
169 QVector<t_rnxObsFile*>& rnxObsFiles,
170 QTextStream* log) {
171
172 QStringListIterator it(obsFileNames);
173 while (it.hasNext()) {
174 QString fileName = it.next();
175 if (fileName.indexOf('*') != -1 ||
176 fileName.indexOf('?') != -1) {
177 QFileInfo fileInfo(fileName);
178 QDir dir = fileInfo.dir();
179 QStringList filters; filters << fileInfo.fileName();
180 QListIterator<QFileInfo> it(dir.entryInfoList(filters));
181 while (it.hasNext()) {
182 QString filePath = it.next().filePath();
183 t_rnxObsFile* rnxObsFile = 0;
184 try {
185 rnxObsFile = new t_rnxObsFile(filePath, t_rnxObsFile::input);
186 rnxObsFiles.append(rnxObsFile);
187 }
188 catch (...) {
189 delete rnxObsFile;
190 if (log) {
191 *log << "Error in rnxObsFile " << filePath.toLatin1().data() << Qt::endl;
192 }
193 }
194 }
195 }
196 else {
197 t_rnxObsFile* rnxObsFile = 0;
198 try {
199 rnxObsFile = new t_rnxObsFile(fileName, t_rnxObsFile::input);
200 rnxObsFiles.append(rnxObsFile);
201 }
202 catch (...) {
203 if (log) {
204 *log << "Error in rnxObsFile " << fileName.toLatin1().data() << Qt::endl;
205 }
206 }
207 }
208 }
209 std::stable_sort(rnxObsFiles.begin(), rnxObsFiles.end(),
210 t_rnxObsFile::earlierStartTime);
211}
212
213//
214////////////////////////////////////////////////////////////////////////////
215void t_reqcEdit::editObservations() {
216
217 // Easy Exit
218 // ---------
219 if (_obsFileNames.isEmpty() || _outObsFileName.isEmpty()) {
220 return;
221 }
222
223 t_reqcEdit::initRnxObsFiles(_obsFileNames, _rnxObsFiles, _log);
224
225 // Initialize output observation file
226 // ----------------------------------
227 t_rnxObsFile outObsFile(_outObsFileName, t_rnxObsFile::output);
228
229
230 // Put together all run by date entries
231 // ------------------------------------
232 QStringList runByDate;
233 if (_rnxVersion >= 4.0 && _rnxObsFiles.size() > 1) {
234 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
235 t_rnxObsFile* rnxObsFile = _rnxObsFiles[ii];
236 QStringListIterator itRunByDt(rnxObsFile->runByDate());
237 while (itRunByDt.hasNext()) {
238 runByDate.append(itRunByDt.next());
239 }
240 }
241 runByDate.removeDuplicates();
242 }
243
244 // Select observation types
245 // ------------------------
246 bncSettings settings;
247 QStringList useObsTypes = settings.value("reqcUseObsTypes").toString().split(" ", Qt::SkipEmptyParts);
248
249 // Put together all observation types
250 // ----------------------------------
251 if (_rnxObsFiles.size() > 1 && useObsTypes.size() == 0) {
252 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
253 t_rnxObsFile* obsFile = _rnxObsFiles[ii];
254 for (int iSys = 0; iSys < obsFile->numSys(); iSys++) {
255 char sys = obsFile->system(iSys);
256 if (sys != ' ') {
257 for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
258 QString type = obsFile->obsType(sys, iType);
259 if (_rnxVersion < 3.0) {
260 useObsTypes << type;
261 }
262 else {
263 useObsTypes << QString(sys) + ":" + type;
264 }
265 }
266 }
267 }
268 }
269 useObsTypes.removeDuplicates();
270 }
271
272 // Put together all phase shifts
273 // -----------------------------
274 QStringList phaseShifts;
275 if (_rnxVersion >= 3.0 && _rnxObsFiles.size() > 1) {
276 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
277 t_rnxObsFile* obsFile = _rnxObsFiles[ii];
278 phaseShifts << obsFile->phaseShifts();
279 }
280 phaseShifts.removeDuplicates();
281 }
282
283 // Put together all GLONASS biases
284 // -------------------------------
285 QStringList gloBiases;
286 if (_rnxVersion >= 3.0 && _rnxObsFiles.size() > 1) {
287 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
288 t_rnxObsFile* obsFile = _rnxObsFiles[ii];
289 if (ii == 0 && obsFile->numGloBiases() == 4) {
290 break;
291 }
292 else {
293 gloBiases << obsFile->gloBiases();
294 }
295 }
296 gloBiases.removeDuplicates();
297 }
298
299 // Put together all GLONASS slots
300 // -----------------------------
301 QStringList gloSlots;
302 if (_rnxVersion >= 3.0 && _rnxObsFiles.size() > 1) {
303 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
304 t_rnxObsFile* obsFile = _rnxObsFiles[ii];
305 if (ii == 0 &&
306 obsFile->numGloSlots() == signed(t_prn::MAXPRN_GLONASS)) {
307 break;
308 }
309 else {
310 gloSlots << obsFile->gloSlots();
311 }
312 }
313 gloSlots.removeDuplicates();
314 }
315
316 // Loop over all input observation files
317 // -------------------------------------
318 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
319 t_rnxObsFile* obsFile = _rnxObsFiles[ii];
320 if (_log) {
321 *_log << "Input Obs File: " << obsFile->fileName() << " start: "
322 << obsFile->startTime().datestr().c_str() << ' '
323 << obsFile->startTime().timestr(0).c_str() << Qt::endl;
324 }
325 if (ii == 0) {
326 outObsFile.setHeader(obsFile->header(), int(_rnxVersion), &useObsTypes,
327 &phaseShifts, &gloBiases, &gloSlots, &runByDate);
328 if (_begTime.valid() && _begTime > outObsFile.startTime()) {
329 outObsFile.setStartTime(_begTime);
330 }
331 if (_samplingRate > outObsFile.interval()) {
332 outObsFile.setInterval(_samplingRate);
333 }
334 editRnxObsHeader(outObsFile);
335 bncSettings settings;
336 QMap<QString, QString> txtMap;
337 QString runBy = settings.value("reqcRunBy").toString();
338 if (!runBy.isEmpty()) {
339 txtMap["RUN BY"] = runBy;
340 }
341 QString comment = settings.value("reqcComment").toString();
342 if (!comment.isEmpty()) {
343 txtMap["COMMENT"] = comment;
344 }
345 if (int(_rnxVersion) < int(obsFile->header().version())) {
346 addRnxConversionDetails(obsFile, txtMap);
347 }
348 outObsFile.header().write(outObsFile.stream(), &txtMap);
349 }
350 t_rnxObsFile::t_rnxEpo* epo = 0;
351 try {
352 while ( (epo = obsFile->nextEpoch()) != 0) {
353 if (_begTime.valid() && epo->tt < _begTime) {
354 continue;
355 }
356 if (_endTime.valid() && epo->tt > _endTime) {
357 break;
358 }
359
360 int sec = int(nint(epo->tt.gpssec()*10));
361 if (sec % (int(_samplingRate)*10) == 0) {
362 applyLLI(obsFile, epo);
363 outObsFile.writeEpoch(epo);
364 }
365 else {
366 rememberLLI(obsFile, epo);
367 }
368 }
369 }
370 catch (QString str) {
371 if (_log) {
372 *_log << "Exception " << str << Qt::endl;
373 }
374 else {
375 qDebug() << str;
376 }
377 return;
378 }
379 catch (...) {
380 if (_log) {
381 *_log << "Exception unknown" << Qt::endl;
382 }
383 else {
384 qDebug() << "Exception unknown";
385 }
386 return;
387 }
388 }
389}
390
391// Change RINEX Header Content
392////////////////////////////////////////////////////////////////////////////
393void t_reqcEdit::editRnxObsHeader(t_rnxObsFile& obsFile) {
394
395 bncSettings settings;
396
397 QString oldMarkerName = settings.value("reqcOldMarkerName").toString();
398 QString newMarkerName = settings.value("reqcNewMarkerName").toString();
399 if (!newMarkerName.isEmpty()) {
400 if (oldMarkerName.isEmpty() ||
401 QRegExp(oldMarkerName).exactMatch(obsFile.markerName())) {
402 obsFile.setMarkerName(newMarkerName);
403 }
404 }
405
406 QString oldAntennaName = settings.value("reqcOldAntennaName").toString();
407 QString newAntennaName = settings.value("reqcNewAntennaName").toString();
408 if (!newAntennaName.isEmpty()) {
409 if (oldAntennaName.isEmpty() ||
410 QRegExp(oldAntennaName).exactMatch(obsFile.antennaName())) {
411 obsFile.setAntennaName(newAntennaName);
412 }
413 }
414
415 QString oldAntennaNumber = settings.value("reqcOldAntennaNumber").toString();
416 QString newAntennaNumber = settings.value("reqcNewAntennaNumber").toString();
417 if (!newAntennaNumber.isEmpty()) {
418 if (oldAntennaNumber.isEmpty() ||
419 QRegExp(oldAntennaNumber).exactMatch(obsFile.antennaNumber())) {
420 obsFile.setAntennaNumber(newAntennaNumber);
421 }
422 }
423
424 const ColumnVector& obsFileAntNEU = obsFile.antNEU();
425 QString oldAntennadN = settings.value("reqcOldAntennadN").toString();
426 QString newAntennadN = settings.value("reqcNewAntennadN").toString();
427 if(!newAntennadN.isEmpty()) {
428 if (oldAntennadN.isEmpty() ||
429 oldAntennadN.toDouble() == obsFileAntNEU(1)) {
430 obsFile.setAntennaN(newAntennadN.toDouble());
431 }
432 }
433 QString oldAntennadE = settings.value("reqcOldAntennadE").toString();
434 QString newAntennadE = settings.value("reqcNewAntennadE").toString();
435 if(!newAntennadE.isEmpty()) {
436 if (oldAntennadE.isEmpty() ||
437 oldAntennadE.toDouble() == obsFileAntNEU(2)) {
438 obsFile.setAntennaE(newAntennadE.toDouble());
439 }
440 }
441 QString oldAntennadU = settings.value("reqcOldAntennadU").toString();
442 QString newAntennadU = settings.value("reqcNewAntennadU").toString();
443 if(!newAntennadU.isEmpty()) {
444 if (oldAntennadU.isEmpty() ||
445 oldAntennadU.toDouble() == obsFileAntNEU(3)) {
446 obsFile.setAntennaU(newAntennadU.toDouble());
447 }
448 }
449
450 QString oldReceiverType = settings.value("reqcOldReceiverName").toString();
451 QString newReceiverType = settings.value("reqcNewReceiverName").toString();
452 if (!newReceiverType.isEmpty()) {
453 if (oldReceiverType.isEmpty() ||
454 QRegExp(oldReceiverType).exactMatch(obsFile.receiverType())) {
455 obsFile.setReceiverType(newReceiverType);
456 }
457 }
458
459 QString oldReceiverNumber = settings.value("reqcOldReceiverNumber").toString();
460 QString newReceiverNumber = settings.value("reqcNewReceiverNumber").toString();
461 if (!newReceiverNumber.isEmpty()) {
462 if (oldReceiverNumber.isEmpty() ||
463 QRegExp(oldReceiverNumber).exactMatch(obsFile.receiverNumber())) {
464 obsFile.setReceiverNumber(newReceiverNumber);
465 }
466 }
467}
468
469//
470////////////////////////////////////////////////////////////////////////////
471void t_reqcEdit::rememberLLI(const t_rnxObsFile* obsFile,
472 const t_rnxObsFile::t_rnxEpo* epo) {
473
474 if (_samplingRate == 0) {
475 return;
476 }
477
478 for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
479 const t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
480 char sys = rnxSat.prn.system();
481 QString prn(rnxSat.prn.toString().c_str());
482
483 for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
484 QString type = obsFile->obsType(sys, iType);
485 if (!_lli[prn].contains(iType)) {
486 _lli[prn][iType] = 0;
487 }
488 if (rnxSat.obs.contains(type) && rnxSat.obs[type].lli & 1) {
489 _lli[prn][iType] |= 1;
490 }
491 }
492 }
493}
494
495//
496////////////////////////////////////////////////////////////////////////////
497void t_reqcEdit::applyLLI(const t_rnxObsFile* obsFile,
498 t_rnxObsFile::t_rnxEpo* epo) {
499
500 if (_samplingRate == 0) {
501 return;
502 }
503
504 for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
505 t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
506 char sys = rnxSat.prn.system();
507 QString prn(rnxSat.prn.toString().c_str());
508
509 for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
510 QString type = obsFile->obsType(sys, iType);
511 if (_lli[prn].contains(iType) && _lli[prn][iType] & 1) {
512 if (rnxSat.obs.contains(type)) {
513 rnxSat.obs[type].lli |= 1;
514 }
515 }
516 }
517 }
518
519 _lli.clear();
520}
521
522/// Read All Ephemerides
523////////////////////////////////////////////////////////////////////////////
524void t_reqcEdit::readEphemerides(const QStringList& navFileNames,
525 QVector<t_eph*>& ephs, QTextStream* log,
526 bool checkEph) {
527
528 QStringListIterator it(navFileNames);
529 while (it.hasNext()) {
530 QString fileName = it.next();
531 if (fileName.indexOf('*') != -1 ||
532 fileName.indexOf('?') != -1) {
533 QFileInfo fileInfo(fileName);
534 QDir dir = fileInfo.dir();
535 QStringList filters; filters << fileInfo.fileName();
536 QListIterator<QFileInfo> it(dir.entryInfoList(filters));
537 while (it.hasNext()) {
538 QString filePath = it.next().filePath();
539 appendEphemerides(filePath, ephs, log, checkEph);
540 }
541 }
542 else {
543 appendEphemerides(fileName, ephs, log, checkEph);
544 }
545 }
546 // TODO: enable user decision
547 std::stable_sort(ephs.begin(), ephs.end(), t_eph::earlierTime);
548 //std::stable_sort(ephs.begin(), ephs.end(), t_eph::prnSort);
549}
550
551//
552////////////////////////////////////////////////////////////////////////////
553void t_reqcEdit::editEphemerides() {
554
555 // Easy Exit
556 // ---------
557 if (_navFileNames.isEmpty() || _outNavFileName.isEmpty()) {
558 return;
559 }
560 // Concatenate all comments and all run by date lines
561 // --------------------------------------------------
562 QStringList comments;
563 QStringList runByDate;
564 bncSettings settings;
565 QString comment = settings.value("reqcComment").toString();
566 if (!comment.isEmpty()) {
567 comments.append(comment);
568 }
569 QStringListIterator it(_navFileNames);
570 while (it.hasNext()) {
571 QString fileName = it.next();
572
573 t_rnxNavFile rnxNavFile(fileName, t_rnxNavFile::input);
574 QStringListIterator itCmnt(rnxNavFile.comments());
575 while (itCmnt.hasNext()) {
576 comments.append(itCmnt.next());
577 }
578 QStringListIterator itRunByDt(rnxNavFile.runByDate());
579 while (itRunByDt.hasNext()) {
580 runByDate.append(itRunByDt.next());
581 }
582 }
583 comments.removeDuplicates();
584 runByDate.removeDuplicates();
585
586 // Read Ephemerides
587 // ----------------
588 t_reqcEdit::readEphemerides(_navFileNames, _ephs, _log, _checkEph);
589
590 // Check Satellite Systems
591 // -----------------------
592 bool haveGPS = false;
593 bool haveGlonass = false;
594 QMap<t_eph::e_system, bool> haveGnss;
595 for (int ii = 0; ii < _ephs.size(); ii++) {
596 const t_eph* eph = _ephs[ii];
597 switch (eph->system()) {
598 case t_eph::GPS:
599 haveGPS = true;
600 haveGnss[t_eph::GPS] = true;
601 break;
602 case t_eph::GLONASS:
603 haveGlonass = true;
604 haveGnss[t_eph::GLONASS] = true;
605 break;
606 case t_eph::Galileo:
607 haveGnss[t_eph::Galileo] = true;
608 break;
609 case t_eph::BDS:
610 haveGnss[t_eph::BDS] = true;
611 break;
612 case t_eph::QZSS:
613 haveGnss[t_eph::QZSS] = true;
614 break;
615 case t_eph::IRNSS:
616 haveGnss[t_eph::IRNSS] = true;
617 break;
618 case t_eph::SBAS:
619 haveGnss[t_eph::SBAS] = true;
620 break;
621 default:
622 haveGnss[t_eph::unknown] = true;
623 }
624 }
625
626 // Initialize output navigation file
627 // ---------------------------------
628 t_rnxNavFile outNavFile(_outNavFileName, t_rnxNavFile::output);
629
630 outNavFile.setGlonass(haveGlonass);
631
632 if (_rnxVersion < 3.0) {
633 if (haveGPS && haveGlonass) {
634 outNavFile.setVersion(defaultRnxNavVersion3);
635 }
636 if (haveGPS && !haveGlonass) {
637 outNavFile.setVersion(defaultRnxNavVersion2);
638 }
639 if (!haveGPS && haveGlonass) {
640 outNavFile.setVersion(defaultRnxNavVersion2);
641 }
642 }
643
644 if (_rnxVersion >= 3.0 && _rnxVersion < 4.0) {
645 outNavFile.setVersion(defaultRnxNavVersion3);
646 }
647
648 if (_rnxVersion >= 4.0) {
649 outNavFile.setVersion(defaultRnxNavVersion4);
650 }
651
652 if (outNavFile.version() > 3.0) {
653 if (haveGnss.size() > 1) {
654 outNavFile.setGnssTypeV3(t_eph::unknown);
655 }
656 else if (haveGnss.size() == 1){
657 outNavFile.setGnssTypeV3(haveGnss.keys().first());
658 }
659 }
660
661 QMap<QString, QString> txtMap;
662 QString runBy = settings.value("reqcRunBy").toString();
663 if (!runBy.isEmpty()) {
664 txtMap["RUN BY"] = runBy;
665 }
666 if (!runByDate.empty()) {
667 txtMap["RUN BY DATE"] = runByDate.join("\\n");
668 }
669 if (!comments.isEmpty()) {
670 txtMap["COMMENT"] = comments.join("\\n");
671 }
672
673 int mergedNavFiles = _navFileNames.size();
674 unsigned year, month, day;
675 int gps_utc = 0;
676 if (_ephs.size()) {
677 _ephs.at(0)->TOC().civil_date(year, month, day);
678 gps_utc = gnumleap(year, month, day);
679 }
680 outNavFile.writeHeader(&txtMap, mergedNavFiles, gps_utc);
681
682 // Loop over all ephemerides
683 // -------------------------
684 for (int ii = 0; ii < _ephs.size(); ii++) {
685 const t_eph* eph = _ephs[ii];
686 bncTime begTime = _begTime;
687 bncTime endTime = _endTime;
688 if (eph->system() == t_eph::BDS) {
689 begTime += 14;
690 endTime += 14;
691 }
692 if (begTime.valid() && eph->TOC() < begTime) {
693 continue;
694 }
695 if (endTime.valid() && eph->TOC() > endTime) {
696 break;
697 }
698 if (eph->checkState() == t_eph::bad) {
699 continue;
700 }
701
702 if (outNavFile.version() < 3.0) {
703 if (outNavFile.glonass() && eph->system() != t_eph::GLONASS) {
704 continue;
705 }
706 if (!outNavFile.glonass() && eph->system() != t_eph::GPS) {
707 continue;
708 }
709 }
710 outNavFile.writeEph(eph);
711 }
712}
713
714//
715////////////////////////////////////////////////////////////////////////////
716void t_reqcEdit::appendEphemerides(const QString& fileName,
717 QVector<t_eph*>& ephs, QTextStream* log,
718 bool checkEph) {
719 t_rnxNavFile rnxNavFile(fileName, t_rnxNavFile::input);
720 unsigned numOK = 0;
721 unsigned numBad = 0;
722 unsigned numUnhealthy = 0;
723 bncEphUser ephUser(false);
724
725 if (log) {
726 QFileInfo navFi(rnxNavFile.fileName());
727 *log << "Input Nav File : " << navFi.fileName() << Qt::endl;
728 if (checkEph) {
729 *log << "RINEX Version : " << rnxNavFile.version() << Qt::endl;
730 }
731 }
732
733 for (unsigned ii = 0; ii < rnxNavFile.ephs().size(); ii++) {
734 t_eph* eph = rnxNavFile.ephs()[ii];
735 bool isNew = true;
736 for (int iOld = 0; iOld < ephs.size(); iOld++) {
737 const t_eph* ephOld = ephs[iOld];
738 if (ephOld->prn() == eph->prn() &&
739 ephOld->TOC() == eph->TOC()) {
740 isNew = false;
741 break;
742 }
743 }
744
745 if (isNew) {
746
747 if (checkEph) {
748 ephUser.putNewEph(eph, false);
749 if (eph->checkState() == t_eph::bad) {
750 ++numBad;
751 }
752 else if (eph->checkState() == t_eph::unhealthy) {
753 ++numUnhealthy;
754 }
755 else {
756 ++numOK;
757 }
758 if (eph->checkState() == t_eph::bad) {
759 continue;
760 }
761 }
762
763 if (eph->system() == t_eph::GPS) {
764 ephs.append(new t_ephGPS(*dynamic_cast<t_ephGPS*>(eph)));
765 }
766 else if (eph->system() == t_eph::GLONASS) {
767 ephs.append(new t_ephGlo(*dynamic_cast<t_ephGlo*>(eph)));
768 }
769 else if (eph->system() == t_eph::Galileo) {
770 ephs.append(new t_ephGal(*dynamic_cast<t_ephGal*>(eph)));
771 }
772 else if (eph->system() == t_eph::QZSS) {
773 ephs.append(new t_ephGPS(*dynamic_cast<t_ephGPS*>(eph)));
774 }
775 else if (eph->system() == t_eph::SBAS) {
776 ephs.append(new t_ephSBAS(*dynamic_cast<t_ephSBAS*>(eph)));
777 }
778 else if (eph->system() == t_eph::BDS) {
779 ephs.append(new t_ephBDS(*dynamic_cast<t_ephBDS*>(eph)));
780 }
781 else if (eph->system() == t_eph::IRNSS) {
782 ephs.append(new t_ephGPS(*dynamic_cast<t_ephGPS*>(eph)));
783 }
784 }
785 }
786
787 if (log && checkEph) {
788 *log << "Ephemeris Check : " << numOK << " OK "
789 << numUnhealthy << " UNHEALTHY "
790 << numBad << " WRONG\n";
791 if (numBad > 0) {
792 for (unsigned ii = 0; ii < rnxNavFile.ephs().size(); ii++) {
793 t_eph* eph = rnxNavFile.ephs()[ii];
794 QFileInfo navFi(fileName);
795 if (eph->checkState() == t_eph::bad) {
796 if (log) {
797 *log << " : "
798 << QString("WRONG %2:%3\n")
799 .arg(eph->typeStr(eph->type(), eph->prn(), 99.0))
800 .arg(eph->rinexDateStr(eph->TOC(), eph->prn(), 99.0)).toLatin1();
801 }
802 }
803 }
804 }
805 *log << Qt::endl;
806 }
807}
808
809void t_reqcEdit::addRnxConversionDetails(const t_rnxObsFile* obsFile,
810 QMap<QString, QString>& txtMap) {
811
812 int key = 0;
813 QString systems = obsFile->header().usedSystems();
814 QString comment = QString("Signal priorities for RINEX 3 => 2 conversion:");
815 QString commentKey = QString("COMMENT %1").arg(key, 3, 10, QChar('0'));
816 txtMap.insert(commentKey, comment);
817
818 for(int ii = 0; ii < obsFile->numSys(); ii++) {
819 char sys = systems[ii].toLatin1();
820 txtMap.insert(commentKey, comment);
821 QMap <char, QString> signalPriorityMap;
822 QStringList preferredAttribListSys = obsFile->signalPriorities(sys);
823 QStringList types = obsFile->header().obsTypes(sys);
824 for (int jj = 0; jj < types.size(); jj++) {
825 QString inType = types[jj];
826 char band = inType[1].toLatin1();
827 for (int ii = 0; ii < preferredAttribListSys.size(); ii++) {
828 QString preferredAttrib;
829 if (preferredAttribListSys[ii].indexOf("&") != -1) {
830 QStringList hlp = preferredAttribListSys[ii].split("&", Qt::SkipEmptyParts);
831 if (hlp.size() == 2 && hlp[0].contains(band)) {
832 preferredAttrib = hlp[1];
833 }
834 }
835 else {
836 preferredAttrib = preferredAttribListSys[ii];
837 }
838 if (!signalPriorityMap.contains(band) && !preferredAttrib.isEmpty()){
839 signalPriorityMap[band] = preferredAttrib;
840 }
841 }
842 }
843 QMapIterator<char, QString> it(signalPriorityMap);
844 while (it.hasNext()) {
845 it.next();
846 key++;
847 comment = QString("%1 band %2: %3").arg(sys).arg(it.key()).arg(it.value());
848 commentKey = QString("COMMENT %1").arg(key, 3, 10, QChar('0'));
849 txtMap.insert(commentKey, comment);
850 }
851 }
852}
Note: See TracBrowser for help on using the repository browser.