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

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