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

Last change on this file since 4538 was 4525, checked in by mervart, 14 years ago
File size: 14.7 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;
[3901]256 while ( (epo = obsFile->nextEpoch()) != 0) {
[3993]257 if (_begTime.valid() && epo->tt < _begTime) {
258 continue;
259 }
260 if (_endTime.valid() && epo->tt > _endTime) {
261 break;
262 }
263
264 if (_samplingRate == 0 ||
265 fmod(round(epo->tt.gpssec()), _samplingRate) == 0) {
[3995]266 applyLLI(obsFile, epo);
[3990]267 outObsFile.writeEpoch(epo);
268 }
[3994]269 else {
[3995]270 rememberLLI(obsFile, epo);
[3994]271 }
[3901]272 }
273 }
274}
[3982]275
276// Change RINEX Header Content
277////////////////////////////////////////////////////////////////////////////
[3985]278void t_reqcEdit::editRnxObsHeader(t_rnxObsFile& obsFile) {
[3982]279
[3983]280 bncSettings settings;
281
282 QString oldMarkerName = settings.value("reqcOldMarkerName").toString();
283 QString newMarkerName = settings.value("reqcNewMarkerName").toString();
[4090]284 if (!newMarkerName.isEmpty()) {
285 if (oldMarkerName.isEmpty() ||
286 QRegExp(oldMarkerName).exactMatch(obsFile.markerName())) {
287 obsFile.setMarkerName(newMarkerName);
288 }
[3985]289 }
290
[3983]291 QString oldAntennaName = settings.value("reqcOldAntennaName").toString();
292 QString newAntennaName = settings.value("reqcNewAntennaName").toString();
[4090]293 if (!newAntennaName.isEmpty()) {
294 if (oldAntennaName.isEmpty() ||
295 QRegExp(oldAntennaName).exactMatch(obsFile.antennaName())) {
296 obsFile.setAntennaName(newAntennaName);
297 }
[3985]298 }
[3983]299
[3985]300 QString oldReceiverType = settings.value("reqcOldReceiverName").toString();
301 QString newReceiverType = settings.value("reqcNewReceiverName").toString();
[4090]302 if (!newReceiverType.isEmpty()) {
303 if (oldReceiverType.isEmpty() ||
304 QRegExp(oldReceiverType).exactMatch(obsFile.receiverType())) {
305 obsFile.setReceiverType(newReceiverType);
306 }
[3985]307 }
[3982]308}
[3994]309
310//
311////////////////////////////////////////////////////////////////////////////
[3995]312void t_reqcEdit::rememberLLI(const t_rnxObsFile* obsFile,
313 const t_rnxObsFile::t_rnxEpo* epo) {
[3994]314
[3995]315 if (_samplingRate == 0) {
316 return;
317 }
318
319 for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
320 const t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
321 char sys = rnxSat.satSys;
[3997]322 QString prn = QString("%1%2").arg(sys).arg(rnxSat.satNum,2,10,QChar('0'));
323
[3995]324 for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
[3997]325 if (!_lli[prn].contains(iType)) {
326 _lli[prn][iType] = 0;
[3996]327 }
328 if (rnxSat.lli[iType] & 1) {
[3997]329 _lli[prn][iType] |= 1;
[3996]330 }
[3995]331 }
332 }
[3994]333}
334
335//
336////////////////////////////////////////////////////////////////////////////
[3995]337void t_reqcEdit::applyLLI(const t_rnxObsFile* obsFile,
338 t_rnxObsFile::t_rnxEpo* epo) {
[3996]339
340 if (_samplingRate == 0) {
[3995]341 return;
342 }
[3996]343
344 for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
345 t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
346 char sys = rnxSat.satSys;
[3997]347 QString prn = QString("%1%2").arg(sys).arg(rnxSat.satNum,2,10,QChar('0'));
348
[3996]349 for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
[3997]350 if (_lli[prn].contains(iType) && _lli[prn][iType] & 1) {
[3996]351 rnxSat.lli[iType] |= 1;
352 }
353 }
354 }
355
356 _lli.clear();
[3994]357}
[3998]358
[4256]359/// Read All Ephemerides
[3998]360////////////////////////////////////////////////////////////////////////////
[4256]361void t_reqcEdit::readEphemerides(const QStringList& navFileNames,
362 QVector<t_eph*>& ephs) {
[3998]363
[4256]364 QStringListIterator it(navFileNames);
[3999]365 while (it.hasNext()) {
366 QString fileName = it.next();
[4081]367 if (fileName.indexOf('*') != -1 || fileName.indexOf('?') != -1) {
368 QFileInfo fileInfo(fileName);
369 QDir dir = fileInfo.dir();
370 QStringList filters; filters << fileInfo.fileName();
371 QListIterator<QFileInfo> it(dir.entryInfoList(filters));
372 while (it.hasNext()) {
373 QString filePath = it.next().filePath();
[4256]374 appendEphemerides(filePath, ephs);
[4000]375 }
376 }
[4081]377 else {
[4256]378 appendEphemerides(fileName, ephs);
[4081]379 }
[3999]380 }
[4256]381 qStableSort(ephs.begin(), ephs.end(), t_eph::earlierTime);
382}
[3999]383
[4256]384//
385////////////////////////////////////////////////////////////////////////////
386void t_reqcEdit::editEphemerides() {
387
388 // Easy Exit
389 // ---------
390 if (_navFileNames.isEmpty() || _outNavFileName.isEmpty()) {
391 return;
392 }
393
[4257]394 // Read Ephemerides
395 // ----------------
[4256]396 t_reqcEdit::readEphemerides(_navFileNames, _ephs);
397
[4229]398 // Check Satellite Systems
399 // -----------------------
400 bool haveGPS = false;
401 bool haveGlonass = false;
402 for (int ii = 0; ii < _ephs.size(); ii++) {
403 const t_eph* eph = _ephs[ii];
404 if (eph->type() == t_eph::GPS) {
405 haveGPS = true;
406 }
407 else if (eph->type() == t_eph::GLONASS) {
408 haveGlonass = true;
409 }
410 }
411
[4007]412 // Initialize output navigation file
413 // ---------------------------------
[4004]414 t_rnxNavFile outNavFile(_outNavFileName, t_rnxNavFile::output);
[4229]415
416 outNavFile.setGlonass(haveGlonass);
417
418 if (haveGPS && haveGlonass) {
419 outNavFile.setVersion(rnxV3);
420 }
421 else {
422 outNavFile.setVersion(_rnxVersion);
423 }
424
[4221]425 bncSettings settings;
426 QMap<QString, QString> txtMap;
427 QString runBy = settings.value("reqcRunBy").toString();
428 if (!runBy.isEmpty()) {
429 txtMap["RUN BY"] = runBy;
430 }
431 QString comment = settings.value("reqcComment").toString();
432 if (!comment.isEmpty()) {
433 txtMap["COMMENT"] = comment;
434 }
[4229]435
[4221]436 outNavFile.writeHeader(&txtMap);
[4009]437
[4004]438 // Loop over all ephemerides
439 // -------------------------
440 for (int ii = 0; ii < _ephs.size(); ii++) {
441 const t_eph* eph = _ephs[ii];
[4229]442 outNavFile.writeEph(eph);
[4004]443 }
[3998]444}
[4081]445
446//
447////////////////////////////////////////////////////////////////////////////
[4256]448void t_reqcEdit::appendEphemerides(const QString& fileName,
449 QVector<t_eph*>& ephs) {
[4081]450
451 t_rnxNavFile rnxNavFile(fileName, t_rnxNavFile::input);
452 for (unsigned ii = 0; ii < rnxNavFile.ephs().size(); ii++) {
453 t_eph* eph = rnxNavFile.ephs()[ii];
454 bool isNew = true;
[4256]455 for (int iOld = 0; iOld < ephs.size(); iOld++) {
456 const t_eph* ephOld = ephs[iOld];
[4236]457 if (ephOld->prn() == eph->prn() && ephOld->TOC() == eph->TOC()) {
[4081]458 isNew = false;
459 break;
460 }
461 }
462 if (isNew) {
463 if (eph->type() == t_eph::GPS) {
[4256]464 ephs.append(new t_ephGPS(*dynamic_cast<t_ephGPS*>(eph)));
[4081]465 }
466 else if (eph->type() == t_eph::GLONASS) {
[4256]467 ephs.append(new t_ephGlo(*dynamic_cast<t_ephGlo*>(eph)));
[4081]468 }
469 else if (eph->type() == t_eph::Galileo) {
[4256]470 ephs.append(new t_ephGal(*dynamic_cast<t_ephGal*>(eph)));
[4081]471 }
472 }
473 }
474}
Note: See TracBrowser for help on using the repository browser.