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

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