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

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