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

Last change on this file since 5066 was 5066, checked in by mervart, 11 years ago
File size: 14.9 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 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iostream>
42#include "reqcedit.h"
[3972]43#include "bncapp.h"
[3901]44#include "bncsettings.h"
[4516]45#include "bncutils.h"
[3901]46
47using namespace std;
48
[4229]49const double rnxV2 = 2.11;
50const double rnxV3 = 3.01;
51
[3901]52// Constructor
53////////////////////////////////////////////////////////////////////////////
54t_reqcEdit::t_reqcEdit(QObject* parent) : QThread(parent) {
55
56 bncSettings settings;
57
[4516]58 _logFileName = settings.value("reqcOutLogFile").toString(); expandEnvVar(_logFileName);
59 _logFile = 0;
60 _log = 0;
[3901]61 _obsFileNames = settings.value("reqcObsFile").toString().split(",", QString::SkipEmptyParts);
62 _outObsFileName = settings.value("reqcOutObsFile").toString();
[3999]63 _navFileNames = settings.value("reqcNavFile").toString().split(",", QString::SkipEmptyParts);
64 _outNavFileName = settings.value("reqcOutNavFile").toString();
[4010]65 int version = settings.value("reqcRnxVersion").toInt();
66 if (version < 3) {
[4229]67 _rnxVersion = rnxV2;
[4010]68 }
69 else {
[4229]70 _rnxVersion = rnxV3;
[4010]71 }
[3981]72 _samplingRate = settings.value("reqcSampling").toInt();
[3989]73 _begTime = bncTime(settings.value("reqcStartDateTime").toString().toAscii().data());
74 _endTime = bncTime(settings.value("reqcEndDateTime").toString().toAscii().data());
[3901]75}
76
77// Destructor
78////////////////////////////////////////////////////////////////////////////
79t_reqcEdit::~t_reqcEdit() {
80 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
81 delete _rnxObsFiles[ii];
82 }
[4001]83 for (int ii = 0; ii < _ephs.size(); ii++) {
84 delete _ephs[ii];
85 }
[4516]86 delete _log; _log = 0;
87 delete _logFile; _logFile = 0;
[3901]88}
89
90//
91////////////////////////////////////////////////////////////////////////////
92void t_reqcEdit::run() {
[3998]93
[4516]94 // Open Log File
95 // -------------
96 _logFile = new QFile(_logFileName);
[4518]97 if (_logFile->open(QIODevice::WriteOnly | QIODevice::Text)) {
98 _log = new QTextStream();
99 _log->setDevice(_logFile);
100 }
[4516]101
[4518]102 // Log File Header
103 // ---------------
104 if (_log) {
[4519]105 *_log << QByteArray(78, '-') << endl;
[4518]106 *_log << "Concatenation of RINEX Observation and/or Navigation Files\n";
[4519]107 *_log << QByteArray(78, '-') << endl;
[4520]108
[4523]109 *_log << QByteArray("Program").leftJustified(15) << ": "
[5066]110 << PGM_CORE->pgmName() << endl;
[4523]111 *_log << QByteArray("Run by").leftJustified(15) << ": "
[5066]112 << PGM_CORE->userName() << endl;
[4523]113 *_log << QByteArray("Date").leftJustified(15) << ": "
[4521]114 << QDateTime::currentDateTime().toUTC().toString("yyyy-MM-dd hh:mm:ss") << endl;
[4523]115 *_log << QByteArray("RINEX Version").leftJustified(15) << ": "
[4522]116 << _rnxVersion << endl;
[4523]117 *_log << QByteArray("Sampling").leftJustified(15) << ": "
[4522]118 << _samplingRate << endl;
[4523]119 *_log << QByteArray("Start time").leftJustified(15) << ": "
[4522]120 << _begTime.datestr().c_str() << ' '
121 << _begTime.timestr(0).c_str() << endl;
[4523]122 *_log << QByteArray("End time").leftJustified(15) << ": "
[4522]123 << _endTime.datestr().c_str() << ' '
124 << _endTime.timestr(0).c_str() << endl;
[4523]125 *_log << QByteArray("Input Obs Files").leftJustified(15) << ": "
126 << _obsFileNames.join(",") << endl;
127 *_log << QByteArray("Input Nav Files").leftJustified(15) << ": "
128 << _navFileNames.join(",") << endl;
129 *_log << QByteArray("Output Obs File").leftJustified(15) << ": "
130 << _outObsFileName << endl;
131 *_log << QByteArray("Output Nav File").leftJustified(15) << ": "
132 << _outNavFileName << endl;
[4520]133
134 *_log << QByteArray(78, '-') << endl;
[4518]135 _log->flush();
136 }
137
[4516]138 // Handle Observation Files
139 // ------------------------
[3998]140 editObservations();
[3901]141
[4516]142 // Handle Navigations Files
143 // ------------------------
[3998]144 editEphemerides();
145
[4516]146 // Exit (thread)
147 // -------------
[5066]148 if (PGM_CORE->mode() != t_pgmCore::interactive) {
149 qApp->exit(0);
[3998]150 }
151 else {
152 emit finished();
153 deleteLater();
154 }
155}
156
[4254]157// Initialize input observation files, sort them according to start time
[3998]158////////////////////////////////////////////////////////////////////////////
[4254]159void t_reqcEdit::initRnxObsFiles(const QStringList& obsFileNames,
[4525]160 QVector<t_rnxObsFile*>& rnxObsFiles,
161 QTextStream* log) {
[3998]162
[4254]163 QStringListIterator it(obsFileNames);
[3901]164 while (it.hasNext()) {
165 QString fileName = it.next();
[4080]166 if (fileName.indexOf('*') != -1 || fileName.indexOf('?') != -1) {
167 QFileInfo fileInfo(fileName);
168 QDir dir = fileInfo.dir();
169 QStringList filters; filters << fileInfo.fileName();
170 QListIterator<QFileInfo> it(dir.entryInfoList(filters));
171 while (it.hasNext()) {
172 QString filePath = it.next().filePath();
[4364]173 t_rnxObsFile* rnxObsFile = 0;
[4363]174 try {
[4364]175 rnxObsFile = new t_rnxObsFile(filePath, t_rnxObsFile::input);
[4363]176 rnxObsFiles.append(rnxObsFile);
177 }
178 catch (...) {
[4364]179 delete rnxObsFile;
[4525]180 if (log) {
181 *log << "Error in rnxObsFile " << filePath.toAscii().data() << endl;
182 }
[4363]183 }
[4080]184 }
185 }
186 else {
[4364]187 t_rnxObsFile* rnxObsFile = 0;
[4363]188 try {
[4364]189 rnxObsFile = new t_rnxObsFile(fileName, t_rnxObsFile::input);
[4363]190 rnxObsFiles.append(rnxObsFile);
191 }
192 catch (...) {
[4525]193 if (log) {
194 *log << "Error in rnxObsFile " << fileName.toAscii().data() << endl;
195 }
[4363]196 }
[4080]197 }
[3901]198 }
[4254]199 qStableSort(rnxObsFiles.begin(), rnxObsFiles.end(),
[3901]200 t_rnxObsFile::earlierStartTime);
[4254]201}
[3901]202
[4254]203//
204////////////////////////////////////////////////////////////////////////////
205void t_reqcEdit::editObservations() {
206
207 // Easy Exit
208 // ---------
209 if (_obsFileNames.isEmpty() || _outObsFileName.isEmpty()) {
210 return;
211 }
212
[4525]213 t_reqcEdit::initRnxObsFiles(_obsFileNames, _rnxObsFiles, _log);
[4254]214
[3901]215 // Initialize output observation file
216 // ----------------------------------
217 t_rnxObsFile outObsFile(_outObsFileName, t_rnxObsFile::output);
218
219 // Loop over all input observation files
220 // -------------------------------------
221 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
222 t_rnxObsFile* obsFile = _rnxObsFiles[ii];
[4524]223 if (_log) {
224 *_log << "Processing File: " << obsFile->fileName() << " start: "
225 << obsFile->startTime().datestr().c_str() << ' '
226 << obsFile->startTime().timestr(0).c_str() << endl;
227 }
[3901]228 if (ii == 0) {
[3956]229 outObsFile.setHeader(obsFile->header(), _rnxVersion);
[3992]230 if (_begTime.valid() && _begTime > outObsFile.startTime()) {
231 outObsFile.setStartTime(_begTime);
232 }
[4112]233 if (_samplingRate > outObsFile.interval()) {
234 outObsFile.setInterval(_samplingRate);
235 }
[3982]236 editRnxObsHeader(outObsFile);
[4117]237 bncSettings settings;
[4114]238 QMap<QString, QString> txtMap;
[4117]239 QString runBy = settings.value("reqcRunBy").toString();
240 if (!runBy.isEmpty()) {
241 txtMap["RUN BY"] = runBy;
242 }
243 QString comment = settings.value("reqcComment").toString();
244 if (!comment.isEmpty()) {
245 txtMap["COMMENT"] = comment;
246 }
[4514]247 outObsFile.header().write(outObsFile.stream(), &txtMap);
[3901]248 }
[4054]249 else {
250 outObsFile.checkNewHeader(obsFile->header());
251 }
[3994]252 t_rnxObsFile::t_rnxEpo* epo = 0;
[4541]253 try {
254 while ( (epo = obsFile->nextEpoch()) != 0) {
255 if (_begTime.valid() && epo->tt < _begTime) {
256 continue;
257 }
258 if (_endTime.valid() && epo->tt > _endTime) {
259 break;
260 }
261
262 if (_samplingRate == 0 ||
263 fmod(round(epo->tt.gpssec()), _samplingRate) == 0) {
264 applyLLI(obsFile, epo);
265 outObsFile.writeEpoch(epo);
266 }
267 else {
268 rememberLLI(obsFile, epo);
269 }
[3993]270 }
[4541]271 }
272 catch (QString str) {
273 if (_log) {
274 *_log << "Exception " << str << endl;
[3993]275 }
[3994]276 else {
[4541]277 qDebug() << str;
[3994]278 }
[4541]279 return;
[3901]280 }
281 }
282}
[3982]283
284// Change RINEX Header Content
285////////////////////////////////////////////////////////////////////////////
[3985]286void t_reqcEdit::editRnxObsHeader(t_rnxObsFile& obsFile) {
[3982]287
[3983]288 bncSettings settings;
289
290 QString oldMarkerName = settings.value("reqcOldMarkerName").toString();
291 QString newMarkerName = settings.value("reqcNewMarkerName").toString();
[4090]292 if (!newMarkerName.isEmpty()) {
293 if (oldMarkerName.isEmpty() ||
294 QRegExp(oldMarkerName).exactMatch(obsFile.markerName())) {
295 obsFile.setMarkerName(newMarkerName);
296 }
[3985]297 }
298
[3983]299 QString oldAntennaName = settings.value("reqcOldAntennaName").toString();
300 QString newAntennaName = settings.value("reqcNewAntennaName").toString();
[4090]301 if (!newAntennaName.isEmpty()) {
302 if (oldAntennaName.isEmpty() ||
303 QRegExp(oldAntennaName).exactMatch(obsFile.antennaName())) {
304 obsFile.setAntennaName(newAntennaName);
305 }
[3985]306 }
[3983]307
[3985]308 QString oldReceiverType = settings.value("reqcOldReceiverName").toString();
309 QString newReceiverType = settings.value("reqcNewReceiverName").toString();
[4090]310 if (!newReceiverType.isEmpty()) {
311 if (oldReceiverType.isEmpty() ||
312 QRegExp(oldReceiverType).exactMatch(obsFile.receiverType())) {
313 obsFile.setReceiverType(newReceiverType);
314 }
[3985]315 }
[3982]316}
[3994]317
318//
319////////////////////////////////////////////////////////////////////////////
[3995]320void t_reqcEdit::rememberLLI(const t_rnxObsFile* obsFile,
321 const t_rnxObsFile::t_rnxEpo* epo) {
[3994]322
[3995]323 if (_samplingRate == 0) {
324 return;
325 }
326
327 for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
328 const t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
329 char sys = rnxSat.satSys;
[3997]330 QString prn = QString("%1%2").arg(sys).arg(rnxSat.satNum,2,10,QChar('0'));
331
[3995]332 for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
[3997]333 if (!_lli[prn].contains(iType)) {
334 _lli[prn][iType] = 0;
[3996]335 }
336 if (rnxSat.lli[iType] & 1) {
[3997]337 _lli[prn][iType] |= 1;
[3996]338 }
[3995]339 }
340 }
[3994]341}
342
343//
344////////////////////////////////////////////////////////////////////////////
[3995]345void t_reqcEdit::applyLLI(const t_rnxObsFile* obsFile,
346 t_rnxObsFile::t_rnxEpo* epo) {
[3996]347
348 if (_samplingRate == 0) {
[3995]349 return;
350 }
[3996]351
352 for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
353 t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
354 char sys = rnxSat.satSys;
[3997]355 QString prn = QString("%1%2").arg(sys).arg(rnxSat.satNum,2,10,QChar('0'));
356
[3996]357 for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
[3997]358 if (_lli[prn].contains(iType) && _lli[prn][iType] & 1) {
[3996]359 rnxSat.lli[iType] |= 1;
360 }
361 }
362 }
363
364 _lli.clear();
[3994]365}
[3998]366
[4256]367/// Read All Ephemerides
[3998]368////////////////////////////////////////////////////////////////////////////
[4256]369void t_reqcEdit::readEphemerides(const QStringList& navFileNames,
370 QVector<t_eph*>& ephs) {
[3998]371
[4256]372 QStringListIterator it(navFileNames);
[3999]373 while (it.hasNext()) {
374 QString fileName = it.next();
[4081]375 if (fileName.indexOf('*') != -1 || fileName.indexOf('?') != -1) {
376 QFileInfo fileInfo(fileName);
377 QDir dir = fileInfo.dir();
378 QStringList filters; filters << fileInfo.fileName();
379 QListIterator<QFileInfo> it(dir.entryInfoList(filters));
380 while (it.hasNext()) {
381 QString filePath = it.next().filePath();
[4256]382 appendEphemerides(filePath, ephs);
[4000]383 }
384 }
[4081]385 else {
[4256]386 appendEphemerides(fileName, ephs);
[4081]387 }
[3999]388 }
[4256]389 qStableSort(ephs.begin(), ephs.end(), t_eph::earlierTime);
390}
[3999]391
[4256]392//
393////////////////////////////////////////////////////////////////////////////
394void t_reqcEdit::editEphemerides() {
395
396 // Easy Exit
397 // ---------
398 if (_navFileNames.isEmpty() || _outNavFileName.isEmpty()) {
399 return;
400 }
401
[4257]402 // Read Ephemerides
403 // ----------------
[4256]404 t_reqcEdit::readEphemerides(_navFileNames, _ephs);
405
[4229]406 // Check Satellite Systems
407 // -----------------------
408 bool haveGPS = false;
409 bool haveGlonass = false;
410 for (int ii = 0; ii < _ephs.size(); ii++) {
411 const t_eph* eph = _ephs[ii];
412 if (eph->type() == t_eph::GPS) {
413 haveGPS = true;
414 }
415 else if (eph->type() == t_eph::GLONASS) {
416 haveGlonass = true;
417 }
418 }
419
[4007]420 // Initialize output navigation file
421 // ---------------------------------
[4004]422 t_rnxNavFile outNavFile(_outNavFileName, t_rnxNavFile::output);
[4229]423
424 outNavFile.setGlonass(haveGlonass);
425
426 if (haveGPS && haveGlonass) {
427 outNavFile.setVersion(rnxV3);
428 }
429 else {
430 outNavFile.setVersion(_rnxVersion);
431 }
432
[4221]433 bncSettings settings;
434 QMap<QString, QString> txtMap;
435 QString runBy = settings.value("reqcRunBy").toString();
436 if (!runBy.isEmpty()) {
437 txtMap["RUN BY"] = runBy;
438 }
439 QString comment = settings.value("reqcComment").toString();
440 if (!comment.isEmpty()) {
441 txtMap["COMMENT"] = comment;
442 }
[4229]443
[4221]444 outNavFile.writeHeader(&txtMap);
[4009]445
[4004]446 // Loop over all ephemerides
447 // -------------------------
448 for (int ii = 0; ii < _ephs.size(); ii++) {
449 const t_eph* eph = _ephs[ii];
[4229]450 outNavFile.writeEph(eph);
[4004]451 }
[3998]452}
[4081]453
454//
455////////////////////////////////////////////////////////////////////////////
[4256]456void t_reqcEdit::appendEphemerides(const QString& fileName,
457 QVector<t_eph*>& ephs) {
[4081]458
459 t_rnxNavFile rnxNavFile(fileName, t_rnxNavFile::input);
460 for (unsigned ii = 0; ii < rnxNavFile.ephs().size(); ii++) {
461 t_eph* eph = rnxNavFile.ephs()[ii];
462 bool isNew = true;
[4256]463 for (int iOld = 0; iOld < ephs.size(); iOld++) {
464 const t_eph* ephOld = ephs[iOld];
[4236]465 if (ephOld->prn() == eph->prn() && ephOld->TOC() == eph->TOC()) {
[4081]466 isNew = false;
467 break;
468 }
469 }
470 if (isNew) {
471 if (eph->type() == t_eph::GPS) {
[4256]472 ephs.append(new t_ephGPS(*dynamic_cast<t_ephGPS*>(eph)));
[4081]473 }
474 else if (eph->type() == t_eph::GLONASS) {
[4256]475 ephs.append(new t_ephGlo(*dynamic_cast<t_ephGlo*>(eph)));
[4081]476 }
477 else if (eph->type() == t_eph::Galileo) {
[4256]478 ephs.append(new t_ephGal(*dynamic_cast<t_ephGal*>(eph)));
[4081]479 }
480 }
481 }
482}
Note: See TracBrowser for help on using the repository browser.