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

Last change on this file since 10577 was 10577, checked in by stuerze, 9 hours ago

updates regarding RINEX version 4.02 navigation information

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