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

Last change on this file since 10617 was 10614, checked in by stuerze, 10 days ago

bug fixes egarding RINEX Editing and QC

File size: 26.6 KB
RevLine 
[3901]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 *
[7474]37 * Changes:
[3901]38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iostream>
42#include "reqcedit.h"
[5070]43#include "bnccore.h"
[3901]44#include "bncsettings.h"
[4516]45#include "bncutils.h"
[5378]46#include "rnxobsfile.h"
47#include "rnxnavfile.h"
[3901]48
49using namespace std;
50
51// Constructor
52////////////////////////////////////////////////////////////////////////////
53t_reqcEdit::t_reqcEdit(QObject* parent) : QThread(parent) {
54
55 bncSettings settings;
56
[4516]57 _logFileName = settings.value("reqcOutLogFile").toString(); expandEnvVar(_logFileName);
58 _logFile = 0;
59 _log = 0;
[10548]60 _obsFileNames = settings.value("reqcObsFile").toString().split(",", Qt::SkipEmptyParts);
[3901]61 _outObsFileName = settings.value("reqcOutObsFile").toString();
[10548]62 _navFileNames = settings.value("reqcNavFile").toString().split(",", Qt::SkipEmptyParts);
[3999]63 _outNavFileName = settings.value("reqcOutNavFile").toString();
[4010]64 int version = settings.value("reqcRnxVersion").toInt();
[9765]65 if (version == 2) {
[8127]66 _rnxVersion = defaultRnxObsVersion2;
[4010]67 }
[9770]68 else if (version == 3) {
[8127]69 _rnxVersion = defaultRnxObsVersion3;
[4010]70 }
[9770]71 else if (version == 4) {
[9765]72 _rnxVersion = defaultRnxObsVersion4;
73 }
[8397]74 _samplingRate = settings.value("reqcSampling").toString().split("sec").first().toDouble();
[8204]75 _begTime = bncTime(settings.value("reqcStartDateTime").toString().toLatin1().data());
76 _endTime = bncTime(settings.value("reqcEndDateTime").toString().toLatin1().data());
[6898]77
[10614]78 _checkEph = false;
79
[3901]80}
81
82// Destructor
83////////////////////////////////////////////////////////////////////////////
84t_reqcEdit::~t_reqcEdit() {
85 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
86 delete _rnxObsFiles[ii];
87 }
[4001]88 for (int ii = 0; ii < _ephs.size(); ii++) {
89 delete _ephs[ii];
90 }
[4516]91 delete _log; _log = 0;
92 delete _logFile; _logFile = 0;
[3901]93}
94
[7474]95//
[3901]96////////////////////////////////////////////////////////////////////////////
97void t_reqcEdit::run() {
[7474]98
[4516]99 // Open Log File
100 // -------------
[7280]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 }
[4518]107 }
[4516]108
[4518]109 // Log File Header
110 // ---------------
111 if (_log) {
[10561]112 *_log << QByteArray(78, '-') << Qt::endl;
[7992]113 *_log << "RINEX File Editing\n";
[10561]114 *_log << QByteArray(78, '-') << Qt::endl;
[4520]115
[4523]116 *_log << QByteArray("Program").leftJustified(15) << ": "
[10561]117 << BNC_CORE->pgmName() << Qt::endl;
[4523]118 *_log << QByteArray("Run by").leftJustified(15) << ": "
[10561]119 << BNC_CORE->userName() << Qt::endl;
[4523]120 *_log << QByteArray("Date").leftJustified(15) << ": "
[10561]121 << QDateTime::currentDateTime().toUTC().toString("yyyy-MM-dd hh:mm:ss") << Qt::endl;
[4523]122 *_log << QByteArray("RINEX Version").leftJustified(15) << ": "
[10561]123 << _rnxVersion << Qt::endl;
[4523]124 *_log << QByteArray("Sampling").leftJustified(15) << ": "
[10561]125 << _samplingRate << " sec" << Qt::endl;
[4523]126 *_log << QByteArray("Start time").leftJustified(15) << ": "
[7474]127 << _begTime.datestr().c_str() << ' '
[10561]128 << _begTime.timestr(0).c_str() << Qt::endl;
[4523]129 *_log << QByteArray("End time").leftJustified(15) << ": "
[7474]130 << _endTime.datestr().c_str() << ' '
[10561]131 << _endTime.timestr(0).c_str() << Qt::endl;
[4523]132 *_log << QByteArray("Input Obs Files").leftJustified(15) << ": "
[10561]133 << _obsFileNames.join(",") << Qt::endl;
[4523]134 *_log << QByteArray("Input Nav Files").leftJustified(15) << ": "
[10561]135 << _navFileNames.join(",") << Qt::endl;
[4523]136 *_log << QByteArray("Output Obs File").leftJustified(15) << ": "
[10561]137 << _outObsFileName << Qt::endl;
[4523]138 *_log << QByteArray("Output Nav File").leftJustified(15) << ": "
[10561]139 << _outNavFileName << Qt::endl;
[4520]140
[10561]141 *_log << QByteArray(78, '-') << Qt::endl;
[4518]142 _log->flush();
143 }
144
[4516]145 // Handle Observation Files
146 // ------------------------
[3998]147 editObservations();
[3901]148
[4516]149 // Handle Navigations Files
150 // ------------------------
[3998]151 editEphemerides();
152
[4516]153 // Exit (thread)
154 // -------------
[5072]155 if (BNC_CORE->mode() != t_bncCore::interactive) {
[9854]156 qApp->exit(9);
[7942]157 msleep(100); //sleep 0.1 sec
[3998]158 }
159 else {
160 emit finished();
161 deleteLater();
162 }
[7980]163
[3998]164}
165
[4254]166// Initialize input observation files, sort them according to start time
[3998]167////////////////////////////////////////////////////////////////////////////
[7474]168void t_reqcEdit::initRnxObsFiles(const QStringList& obsFileNames,
[4525]169 QVector<t_rnxObsFile*>& rnxObsFiles,
170 QTextStream* log) {
[3998]171
[4254]172 QStringListIterator it(obsFileNames);
[3901]173 while (it.hasNext()) {
174 QString fileName = it.next();
[10614]175 if (fileName.indexOf('*') != -1 ||
176 fileName.indexOf('?') != -1) {
[4080]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()) {
[7474]182 QString filePath = it.next().filePath();
[4364]183 t_rnxObsFile* rnxObsFile = 0;
[4363]184 try {
[4364]185 rnxObsFile = new t_rnxObsFile(filePath, t_rnxObsFile::input);
[4363]186 rnxObsFiles.append(rnxObsFile);
187 }
188 catch (...) {
[4364]189 delete rnxObsFile;
[4525]190 if (log) {
[10561]191 *log << "Error in rnxObsFile " << filePath.toLatin1().data() << Qt::endl;
[4525]192 }
[4363]193 }
[4080]194 }
195 }
196 else {
[4364]197 t_rnxObsFile* rnxObsFile = 0;
[4363]198 try {
[4364]199 rnxObsFile = new t_rnxObsFile(fileName, t_rnxObsFile::input);
[4363]200 rnxObsFiles.append(rnxObsFile);
201 }
202 catch (...) {
[4525]203 if (log) {
[10561]204 *log << "Error in rnxObsFile " << fileName.toLatin1().data() << Qt::endl;
[4525]205 }
[4363]206 }
[4080]207 }
[3901]208 }
[10525]209 std::stable_sort(rnxObsFiles.begin(), rnxObsFiles.end(),
[3901]210 t_rnxObsFile::earlierStartTime);
[4254]211}
[3901]212
[7474]213//
[4254]214////////////////////////////////////////////////////////////////////////////
215void t_reqcEdit::editObservations() {
216
217 // Easy Exit
218 // ---------
219 if (_obsFileNames.isEmpty() || _outObsFileName.isEmpty()) {
220 return;
221 }
222
[4525]223 t_reqcEdit::initRnxObsFiles(_obsFileNames, _rnxObsFiles, _log);
[4254]224
[3901]225 // Initialize output observation file
226 // ----------------------------------
227 t_rnxObsFile outObsFile(_outObsFileName, t_rnxObsFile::output);
[7474]228
[9945]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
[6118]244 // Select observation types
245 // ------------------------
246 bncSettings settings;
[10548]247 QStringList useObsTypes = settings.value("reqcUseObsTypes").toString().split(" ", Qt::SkipEmptyParts);
[6118]248
[6130]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 != ' ') {
[6131]257 for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
258 QString type = obsFile->obsType(sys, iType);
[6132]259 if (_rnxVersion < 3.0) {
260 useObsTypes << type;
261 }
262 else {
263 useObsTypes << QString(sys) + ":" + type;
264 }
[6131]265 }
[6130]266 }
267 }
268 }
[6132]269 useObsTypes.removeDuplicates();
[6130]270 }
271
[6841]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 }
[9639]280 phaseShifts.removeDuplicates();
[6841]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
[3901]316 // Loop over all input observation files
317 // -------------------------------------
318 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
319 t_rnxObsFile* obsFile = _rnxObsFiles[ii];
[4524]320 if (_log) {
[10614]321 *_log << "Input Obs File: " << obsFile->fileName() << " start: "
[7474]322 << obsFile->startTime().datestr().c_str() << ' '
[10561]323 << obsFile->startTime().timestr(0).c_str() << Qt::endl;
[4524]324 }
[3901]325 if (ii == 0) {
[6841]326 outObsFile.setHeader(obsFile->header(), int(_rnxVersion), &useObsTypes,
[9945]327 &phaseShifts, &gloBiases, &gloSlots, &runByDate);
[3992]328 if (_begTime.valid() && _begTime > outObsFile.startTime()) {
329 outObsFile.setStartTime(_begTime);
330 }
[4112]331 if (_samplingRate > outObsFile.interval()) {
332 outObsFile.setInterval(_samplingRate);
333 }
[3982]334 editRnxObsHeader(outObsFile);
[4117]335 bncSettings settings;
[4114]336 QMap<QString, QString> txtMap;
[4117]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 }
[7474]345 if (int(_rnxVersion) < int(obsFile->header().version())) {
346 addRnxConversionDetails(obsFile, txtMap);
347 }
[4514]348 outObsFile.header().write(outObsFile.stream(), &txtMap);
[3901]349 }
[3994]350 t_rnxObsFile::t_rnxEpo* epo = 0;
[4541]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 }
[7474]359
[8372]360 int sec = int(nint(epo->tt.gpssec()*10));
[8397]361 if (sec % (int(_samplingRate)*10) == 0) {
[4541]362 applyLLI(obsFile, epo);
363 outObsFile.writeEpoch(epo);
364 }
365 else {
366 rememberLLI(obsFile, epo);
367 }
[3993]368 }
[4541]369 }
370 catch (QString str) {
371 if (_log) {
[10561]372 *_log << "Exception " << str << Qt::endl;
[3993]373 }
[3994]374 else {
[7474]375 qDebug() << str;
[3994]376 }
[4541]377 return;
[3901]378 }
[6130]379 catch (...) {
380 if (_log) {
[10561]381 *_log << "Exception unknown" << Qt::endl;
[6130]382 }
383 else {
384 qDebug() << "Exception unknown";
385 }
386 return;
387 }
[3901]388 }
389}
[3982]390
[7474]391// Change RINEX Header Content
[3982]392////////////////////////////////////////////////////////////////////////////
[3985]393void t_reqcEdit::editRnxObsHeader(t_rnxObsFile& obsFile) {
[3982]394
[3983]395 bncSettings settings;
396
397 QString oldMarkerName = settings.value("reqcOldMarkerName").toString();
398 QString newMarkerName = settings.value("reqcNewMarkerName").toString();
[4090]399 if (!newMarkerName.isEmpty()) {
[7474]400 if (oldMarkerName.isEmpty() ||
[4090]401 QRegExp(oldMarkerName).exactMatch(obsFile.markerName())) {
402 obsFile.setMarkerName(newMarkerName);
403 }
[3985]404 }
405
[3983]406 QString oldAntennaName = settings.value("reqcOldAntennaName").toString();
407 QString newAntennaName = settings.value("reqcNewAntennaName").toString();
[4090]408 if (!newAntennaName.isEmpty()) {
[7474]409 if (oldAntennaName.isEmpty() ||
[4090]410 QRegExp(oldAntennaName).exactMatch(obsFile.antennaName())) {
411 obsFile.setAntennaName(newAntennaName);
412 }
[3985]413 }
[3983]414
[6795]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
[3985]450 QString oldReceiverType = settings.value("reqcOldReceiverName").toString();
451 QString newReceiverType = settings.value("reqcNewReceiverName").toString();
[4090]452 if (!newReceiverType.isEmpty()) {
[7474]453 if (oldReceiverType.isEmpty() ||
[4090]454 QRegExp(oldReceiverType).exactMatch(obsFile.receiverType())) {
455 obsFile.setReceiverType(newReceiverType);
456 }
[3985]457 }
[6795]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 }
[3982]467}
[3994]468
[7474]469//
[3994]470////////////////////////////////////////////////////////////////////////////
[7474]471void t_reqcEdit::rememberLLI(const t_rnxObsFile* obsFile,
[3995]472 const t_rnxObsFile::t_rnxEpo* epo) {
[3994]473
[3995]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];
[6121]480 char sys = rnxSat.prn.system();
481 QString prn(rnxSat.prn.toString().c_str());
[3997]482
[3995]483 for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
[6121]484 QString type = obsFile->obsType(sys, iType);
[3997]485 if (!_lli[prn].contains(iType)) {
486 _lli[prn][iType] = 0;
[3996]487 }
[6121]488 if (rnxSat.obs.contains(type) && rnxSat.obs[type].lli & 1) {
[3997]489 _lli[prn][iType] |= 1;
[3996]490 }
[3995]491 }
492 }
[3994]493}
[7474]494
495//
[3994]496////////////////////////////////////////////////////////////////////////////
[7474]497void t_reqcEdit::applyLLI(const t_rnxObsFile* obsFile,
[3995]498 t_rnxObsFile::t_rnxEpo* epo) {
[7474]499
[3996]500 if (_samplingRate == 0) {
[3995]501 return;
502 }
[3996]503
504 for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
505 t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
[6121]506 char sys = rnxSat.prn.system();
507 QString prn(rnxSat.prn.toString().c_str());
[3997]508
[3996]509 for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
[6121]510 QString type = obsFile->obsType(sys, iType);
[3997]511 if (_lli[prn].contains(iType) && _lli[prn][iType] & 1) {
[6121]512 if (rnxSat.obs.contains(type)) {
513 rnxSat.obs[type].lli |= 1;
514 }
[3996]515 }
516 }
517 }
518
519 _lli.clear();
[3994]520}
[3998]521
[4256]522/// Read All Ephemerides
[3998]523////////////////////////////////////////////////////////////////////////////
[4256]524void t_reqcEdit::readEphemerides(const QStringList& navFileNames,
[10614]525 QVector<t_eph*>& ephs, QTextStream* log,
526 bool checkEph) {
[3998]527
[4256]528 QStringListIterator it(navFileNames);
[3999]529 while (it.hasNext()) {
530 QString fileName = it.next();
[10614]531 if (fileName.indexOf('*') != -1 ||
532 fileName.indexOf('?') != -1) {
[4081]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()) {
[7474]538 QString filePath = it.next().filePath();
[10614]539 appendEphemerides(filePath, ephs, log, checkEph);
[4000]540 }
541 }
[4081]542 else {
[10614]543 appendEphemerides(fileName, ephs, log, checkEph);
[4081]544 }
[3999]545 }
[9366]546 // TODO: enable user decision
[10525]547 std::stable_sort(ephs.begin(), ephs.end(), t_eph::earlierTime);
548 //std::stable_sort(ephs.begin(), ephs.end(), t_eph::prnSort);
[4256]549}
[3999]550
[7474]551//
[4256]552////////////////////////////////////////////////////////////////////////////
553void t_reqcEdit::editEphemerides() {
554
555 // Easy Exit
556 // ---------
557 if (_navFileNames.isEmpty() || _outNavFileName.isEmpty()) {
558 return;
559 }
[9945]560 // Concatenate all comments and all run by date lines
561 // --------------------------------------------------
[7999]562 QStringList comments;
[9945]563 QStringList runByDate;
[7999]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();
[10614]572
[7999]573 t_rnxNavFile rnxNavFile(fileName, t_rnxNavFile::input);
574 QStringListIterator itCmnt(rnxNavFile.comments());
575 while (itCmnt.hasNext()) {
576 comments.append(itCmnt.next());
577 }
[9945]578 QStringListIterator itRunByDt(rnxNavFile.runByDate());
579 while (itRunByDt.hasNext()) {
580 runByDate.append(itRunByDt.next());
581 }
[7999]582 }
583 comments.removeDuplicates();
[9945]584 runByDate.removeDuplicates();
[4256]585
[4257]586 // Read Ephemerides
587 // ----------------
[10614]588 t_reqcEdit::readEphemerides(_navFileNames, _ephs, _log, _checkEph);
[4256]589
[4229]590 // Check Satellite Systems
591 // -----------------------
592 bool haveGPS = false;
593 bool haveGlonass = false;
[10587]594 QMap<t_eph::e_system, bool> haveGnss;
[4229]595 for (int ii = 0; ii < _ephs.size(); ii++) {
596 const t_eph* eph = _ephs[ii];
[10587]597 switch (eph->system()) {
[8354]598 case t_eph::GPS:
599 haveGPS = true;
[8655]600 haveGnss[t_eph::GPS] = true;
[8354]601 break;
602 case t_eph::GLONASS:
603 haveGlonass = true;
[8655]604 haveGnss[t_eph::GLONASS] = true;
[8354]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;
[4229]623 }
624 }
625
[4007]626 // Initialize output navigation file
627 // ---------------------------------
[4004]628 t_rnxNavFile outNavFile(_outNavFileName, t_rnxNavFile::output);
[4229]629
630 outNavFile.setGlonass(haveGlonass);
631
[9765]632 if (_rnxVersion < 3.0) {
633 if (haveGPS && haveGlonass) {
634 outNavFile.setVersion(defaultRnxNavVersion3);
635 }
636 if (haveGPS && !haveGlonass) {
637 outNavFile.setVersion(defaultRnxNavVersion2);
638 }
[9945]639 if (!haveGPS && haveGlonass) {
640 outNavFile.setVersion(defaultRnxNavVersion2);
641 }
[9765]642 }
643
644 if (_rnxVersion >= 3.0 && _rnxVersion < 4.0) {
[8127]645 outNavFile.setVersion(defaultRnxNavVersion3);
[4229]646 }
[9765]647
648 if (_rnxVersion >= 4.0) {
649 outNavFile.setVersion(defaultRnxNavVersion4);
[4229]650 }
651
[8354]652 if (outNavFile.version() > 3.0) {
653 if (haveGnss.size() > 1) {
654 outNavFile.setGnssTypeV3(t_eph::unknown);
655 }
656 else if (haveGnss.size() == 1){
[8355]657 outNavFile.setGnssTypeV3(haveGnss.keys().first());
[8354]658 }
659 }
660
[4221]661 QMap<QString, QString> txtMap;
662 QString runBy = settings.value("reqcRunBy").toString();
663 if (!runBy.isEmpty()) {
664 txtMap["RUN BY"] = runBy;
665 }
[9945]666 if (!runByDate.empty()) {
667 txtMap["RUN BY DATE"] = runByDate.join("\\n");
668 }
[7999]669 if (!comments.isEmpty()) {
670 txtMap["COMMENT"] = comments.join("\\n");
[4221]671 }
[4229]672
[9765]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);
[4009]681
[4004]682 // Loop over all ephemerides
683 // -------------------------
684 for (int ii = 0; ii < _ephs.size(); ii++) {
685 const t_eph* eph = _ephs[ii];
[6954]686 bncTime begTime = _begTime;
687 bncTime endTime = _endTime;
[10587]688 if (eph->system() == t_eph::BDS) {
[6954]689 begTime += 14;
690 endTime += 14;
691 }
692 if (begTime.valid() && eph->TOC() < begTime) {
[6898]693 continue;
694 }
[6954]695 if (endTime.valid() && eph->TOC() > endTime) {
[6898]696 break;
697 }
[8437]698 if (eph->checkState() == t_eph::bad) {
[8368]699 continue;
700 }
[9945]701
702 if (outNavFile.version() < 3.0) {
[10587]703 if (outNavFile.glonass() && eph->system() != t_eph::GLONASS) {
[9945]704 continue;
705 }
[10587]706 if (!outNavFile.glonass() && eph->system() != t_eph::GPS) {
[9945]707 continue;
708 }
709 }
[4229]710 outNavFile.writeEph(eph);
[4004]711 }
[3998]712}
[4081]713
[7474]714//
[4081]715////////////////////////////////////////////////////////////////////////////
[4256]716void t_reqcEdit::appendEphemerides(const QString& fileName,
[10614]717 QVector<t_eph*>& ephs, QTextStream* log,
718 bool checkEph) {
[4081]719 t_rnxNavFile rnxNavFile(fileName, t_rnxNavFile::input);
[10614]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
[4081]733 for (unsigned ii = 0; ii < rnxNavFile.ephs().size(); ii++) {
734 t_eph* eph = rnxNavFile.ephs()[ii];
735 bool isNew = true;
[4256]736 for (int iOld = 0; iOld < ephs.size(); iOld++) {
737 const t_eph* ephOld = ephs[iOld];
[6804]738 if (ephOld->prn() == eph->prn() &&
[6809]739 ephOld->TOC() == eph->TOC()) {
[4081]740 isNew = false;
741 break;
742 }
743 }
[9893]744
[4081]745 if (isNew) {
[10614]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) {
[4256]764 ephs.append(new t_ephGPS(*dynamic_cast<t_ephGPS*>(eph)));
[4081]765 }
[10614]766 else if (eph->system() == t_eph::GLONASS) {
[4256]767 ephs.append(new t_ephGlo(*dynamic_cast<t_ephGlo*>(eph)));
[4081]768 }
[10614]769 else if (eph->system() == t_eph::Galileo) {
[4256]770 ephs.append(new t_ephGal(*dynamic_cast<t_ephGal*>(eph)));
[4081]771 }
[10614]772 else if (eph->system() == t_eph::QZSS) {
[6377]773 ephs.append(new t_ephGPS(*dynamic_cast<t_ephGPS*>(eph)));
774 }
[10614]775 else if (eph->system() == t_eph::SBAS) {
[6391]776 ephs.append(new t_ephSBAS(*dynamic_cast<t_ephSBAS*>(eph)));
777 }
[10614]778 else if (eph->system() == t_eph::BDS) {
[6600]779 ephs.append(new t_ephBDS(*dynamic_cast<t_ephBDS*>(eph)));
[6402]780 }
[10614]781 else if (eph->system() == t_eph::IRNSS) {
[8168]782 ephs.append(new t_ephGPS(*dynamic_cast<t_ephGPS*>(eph)));
783 }
[4081]784 }
785 }
[10614]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 }
[4081]807}
[7474]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();
[7980]814 QString comment = QString("Signal priorities for RINEX 3 => 2 conversion:");
[7474]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++) {
[8204]819 char sys = systems[ii].toLatin1();
[7474]820 txtMap.insert(commentKey, comment);
[7980]821 QMap <char, QString> signalPriorityMap;
822 QStringList preferredAttribListSys = obsFile->signalPriorities(sys);
[7474]823 QStringList types = obsFile->header().obsTypes(sys);
824 for (int jj = 0; jj < types.size(); jj++) {
825 QString inType = types[jj];
[8204]826 char band = inType[1].toLatin1();
[7980]827 for (int ii = 0; ii < preferredAttribListSys.size(); ii++) {
828 QString preferredAttrib;
829 if (preferredAttribListSys[ii].indexOf("&") != -1) {
[10548]830 QStringList hlp = preferredAttribListSys[ii].split("&", Qt::SkipEmptyParts);
[7980]831 if (hlp.size() == 2 && hlp[0].contains(band)) {
832 preferredAttrib = hlp[1];
833 }
[7474]834 }
[7980]835 else {
836 preferredAttrib = preferredAttribListSys[ii];
837 }
838 if (!signalPriorityMap.contains(band) && !preferredAttrib.isEmpty()){
839 signalPriorityMap[band] = preferredAttrib;
840 }
[7474]841 }
842 }
[7980]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 }
[7474]851 }
852}
Note: See TracBrowser for help on using the repository browser.