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

Last change on this file since 4363 was 4363, checked in by mervart, 12 years ago
File size: 12.1 KB
Line 
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"
43#include "bncapp.h"
44#include "bncsettings.h"
45
46using namespace std;
47
48const double rnxV2 = 2.11;
49const double rnxV3 = 3.01;
50
51// Constructor
52////////////////////////////////////////////////////////////////////////////
53t_reqcEdit::t_reqcEdit(QObject* parent) : QThread(parent) {
54
55 bncSettings settings;
56
57 _obsFileNames = settings.value("reqcObsFile").toString().split(",", QString::SkipEmptyParts);
58 _outObsFileName = settings.value("reqcOutObsFile").toString();
59 _navFileNames = settings.value("reqcNavFile").toString().split(",", QString::SkipEmptyParts);
60 _outNavFileName = settings.value("reqcOutNavFile").toString();
61 int version = settings.value("reqcRnxVersion").toInt();
62 if (version < 3) {
63 _rnxVersion = rnxV2;
64 }
65 else {
66 _rnxVersion = rnxV3;
67 }
68 _samplingRate = settings.value("reqcSampling").toInt();
69 _begTime = bncTime(settings.value("reqcStartDateTime").toString().toAscii().data());
70 _endTime = bncTime(settings.value("reqcEndDateTime").toString().toAscii().data());
71}
72
73// Destructor
74////////////////////////////////////////////////////////////////////////////
75t_reqcEdit::~t_reqcEdit() {
76 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
77 delete _rnxObsFiles[ii];
78 }
79 for (int ii = 0; ii < _ephs.size(); ii++) {
80 delete _ephs[ii];
81 }
82}
83
84//
85////////////////////////////////////////////////////////////////////////////
86void t_reqcEdit::run() {
87
88 editObservations();
89
90 editEphemerides();
91
92 bncApp* app = (bncApp*) qApp;
93 if ( app->mode() != bncApp::interactive) {
94 app->exit(0);
95 }
96 else {
97 emit finished();
98 deleteLater();
99 }
100}
101
102// Initialize input observation files, sort them according to start time
103////////////////////////////////////////////////////////////////////////////
104void t_reqcEdit::initRnxObsFiles(const QStringList& obsFileNames,
105 QVector<t_rnxObsFile*>& rnxObsFiles) {
106
107 QStringListIterator it(obsFileNames);
108 while (it.hasNext()) {
109 QString fileName = it.next();
110 if (fileName.indexOf('*') != -1 || fileName.indexOf('?') != -1) {
111 QFileInfo fileInfo(fileName);
112 QDir dir = fileInfo.dir();
113 QStringList filters; filters << fileInfo.fileName();
114 QListIterator<QFileInfo> it(dir.entryInfoList(filters));
115 while (it.hasNext()) {
116 QString filePath = it.next().filePath();
117 try {
118 t_rnxObsFile* rnxObsFile = new t_rnxObsFile(filePath, t_rnxObsFile::input);
119 rnxObsFiles.append(rnxObsFile);
120 }
121 catch (...) {
122 cerr << "Error in rnxObsFile initialization" << endl;
123 }
124 }
125 }
126 else {
127 try {
128 t_rnxObsFile* rnxObsFile = new t_rnxObsFile(fileName, t_rnxObsFile::input);
129 rnxObsFiles.append(rnxObsFile);
130 }
131 catch (...) {
132 cerr << "Error in rnxObsFile initialization" << endl;
133 }
134 }
135 }
136 qStableSort(rnxObsFiles.begin(), rnxObsFiles.end(),
137 t_rnxObsFile::earlierStartTime);
138}
139
140//
141////////////////////////////////////////////////////////////////////////////
142void t_reqcEdit::editObservations() {
143
144 // Easy Exit
145 // ---------
146 if (_obsFileNames.isEmpty() || _outObsFileName.isEmpty()) {
147 return;
148 }
149
150 t_reqcEdit::initRnxObsFiles(_obsFileNames, _rnxObsFiles);
151
152 // Initialize output observation file
153 // ----------------------------------
154 t_rnxObsFile outObsFile(_outObsFileName, t_rnxObsFile::output);
155
156 // Loop over all input observation files
157 // -------------------------------------
158 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
159 t_rnxObsFile* obsFile = _rnxObsFiles[ii];
160 if (ii == 0) {
161 outObsFile.setHeader(obsFile->header(), _rnxVersion);
162 if (_begTime.valid() && _begTime > outObsFile.startTime()) {
163 outObsFile.setStartTime(_begTime);
164 }
165 if (_samplingRate > outObsFile.interval()) {
166 outObsFile.setInterval(_samplingRate);
167 }
168 editRnxObsHeader(outObsFile);
169 bncSettings settings;
170 QMap<QString, QString> txtMap;
171 QString runBy = settings.value("reqcRunBy").toString();
172 if (!runBy.isEmpty()) {
173 txtMap["RUN BY"] = runBy;
174 }
175 QString comment = settings.value("reqcComment").toString();
176 if (!comment.isEmpty()) {
177 txtMap["COMMENT"] = comment;
178 }
179 outObsFile.writeHeader(&txtMap);
180 }
181 else {
182 outObsFile.checkNewHeader(obsFile->header());
183 }
184 t_rnxObsFile::t_rnxEpo* epo = 0;
185 while ( (epo = obsFile->nextEpoch()) != 0) {
186 if (_begTime.valid() && epo->tt < _begTime) {
187 continue;
188 }
189 if (_endTime.valid() && epo->tt > _endTime) {
190 break;
191 }
192
193 if (_samplingRate == 0 ||
194 fmod(round(epo->tt.gpssec()), _samplingRate) == 0) {
195 applyLLI(obsFile, epo);
196 outObsFile.writeEpoch(epo);
197 }
198 else {
199 rememberLLI(obsFile, epo);
200 }
201 }
202 }
203}
204
205// Change RINEX Header Content
206////////////////////////////////////////////////////////////////////////////
207void t_reqcEdit::editRnxObsHeader(t_rnxObsFile& obsFile) {
208
209 bncSettings settings;
210
211 QString oldMarkerName = settings.value("reqcOldMarkerName").toString();
212 QString newMarkerName = settings.value("reqcNewMarkerName").toString();
213 if (!newMarkerName.isEmpty()) {
214 if (oldMarkerName.isEmpty() ||
215 QRegExp(oldMarkerName).exactMatch(obsFile.markerName())) {
216 obsFile.setMarkerName(newMarkerName);
217 }
218 }
219
220 QString oldAntennaName = settings.value("reqcOldAntennaName").toString();
221 QString newAntennaName = settings.value("reqcNewAntennaName").toString();
222 if (!newAntennaName.isEmpty()) {
223 if (oldAntennaName.isEmpty() ||
224 QRegExp(oldAntennaName).exactMatch(obsFile.antennaName())) {
225 obsFile.setAntennaName(newAntennaName);
226 }
227 }
228
229 QString oldReceiverType = settings.value("reqcOldReceiverName").toString();
230 QString newReceiverType = settings.value("reqcNewReceiverName").toString();
231 if (!newReceiverType.isEmpty()) {
232 if (oldReceiverType.isEmpty() ||
233 QRegExp(oldReceiverType).exactMatch(obsFile.receiverType())) {
234 obsFile.setReceiverType(newReceiverType);
235 }
236 }
237}
238
239//
240////////////////////////////////////////////////////////////////////////////
241void t_reqcEdit::rememberLLI(const t_rnxObsFile* obsFile,
242 const t_rnxObsFile::t_rnxEpo* epo) {
243
244 if (_samplingRate == 0) {
245 return;
246 }
247
248 for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
249 const t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
250 char sys = rnxSat.satSys;
251 QString prn = QString("%1%2").arg(sys).arg(rnxSat.satNum,2,10,QChar('0'));
252
253 for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
254 if (!_lli[prn].contains(iType)) {
255 _lli[prn][iType] = 0;
256 }
257 if (rnxSat.lli[iType] & 1) {
258 _lli[prn][iType] |= 1;
259 }
260 }
261 }
262}
263
264//
265////////////////////////////////////////////////////////////////////////////
266void t_reqcEdit::applyLLI(const t_rnxObsFile* obsFile,
267 t_rnxObsFile::t_rnxEpo* epo) {
268
269 if (_samplingRate == 0) {
270 return;
271 }
272
273 for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
274 t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
275 char sys = rnxSat.satSys;
276 QString prn = QString("%1%2").arg(sys).arg(rnxSat.satNum,2,10,QChar('0'));
277
278 for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
279 if (_lli[prn].contains(iType) && _lli[prn][iType] & 1) {
280 rnxSat.lli[iType] |= 1;
281 }
282 }
283 }
284
285 _lli.clear();
286}
287
288/// Read All Ephemerides
289////////////////////////////////////////////////////////////////////////////
290void t_reqcEdit::readEphemerides(const QStringList& navFileNames,
291 QVector<t_eph*>& ephs) {
292
293 QStringListIterator it(navFileNames);
294 while (it.hasNext()) {
295 QString fileName = it.next();
296 if (fileName.indexOf('*') != -1 || fileName.indexOf('?') != -1) {
297 QFileInfo fileInfo(fileName);
298 QDir dir = fileInfo.dir();
299 QStringList filters; filters << fileInfo.fileName();
300 QListIterator<QFileInfo> it(dir.entryInfoList(filters));
301 while (it.hasNext()) {
302 QString filePath = it.next().filePath();
303 appendEphemerides(filePath, ephs);
304 }
305 }
306 else {
307 appendEphemerides(fileName, ephs);
308 }
309 }
310 qStableSort(ephs.begin(), ephs.end(), t_eph::earlierTime);
311}
312
313//
314////////////////////////////////////////////////////////////////////////////
315void t_reqcEdit::editEphemerides() {
316
317 // Easy Exit
318 // ---------
319 if (_navFileNames.isEmpty() || _outNavFileName.isEmpty()) {
320 return;
321 }
322
323 // Read Ephemerides
324 // ----------------
325 t_reqcEdit::readEphemerides(_navFileNames, _ephs);
326
327 // Check Satellite Systems
328 // -----------------------
329 bool haveGPS = false;
330 bool haveGlonass = false;
331 for (int ii = 0; ii < _ephs.size(); ii++) {
332 const t_eph* eph = _ephs[ii];
333 if (eph->type() == t_eph::GPS) {
334 haveGPS = true;
335 }
336 else if (eph->type() == t_eph::GLONASS) {
337 haveGlonass = true;
338 }
339 }
340
341 // Initialize output navigation file
342 // ---------------------------------
343 t_rnxNavFile outNavFile(_outNavFileName, t_rnxNavFile::output);
344
345 outNavFile.setGlonass(haveGlonass);
346
347 if (haveGPS && haveGlonass) {
348 outNavFile.setVersion(rnxV3);
349 }
350 else {
351 outNavFile.setVersion(_rnxVersion);
352 }
353
354 bncSettings settings;
355 QMap<QString, QString> txtMap;
356 QString runBy = settings.value("reqcRunBy").toString();
357 if (!runBy.isEmpty()) {
358 txtMap["RUN BY"] = runBy;
359 }
360 QString comment = settings.value("reqcComment").toString();
361 if (!comment.isEmpty()) {
362 txtMap["COMMENT"] = comment;
363 }
364
365 outNavFile.writeHeader(&txtMap);
366
367 // Loop over all ephemerides
368 // -------------------------
369 for (int ii = 0; ii < _ephs.size(); ii++) {
370 const t_eph* eph = _ephs[ii];
371 outNavFile.writeEph(eph);
372 }
373}
374
375//
376////////////////////////////////////////////////////////////////////////////
377void t_reqcEdit::appendEphemerides(const QString& fileName,
378 QVector<t_eph*>& ephs) {
379
380 t_rnxNavFile rnxNavFile(fileName, t_rnxNavFile::input);
381 for (unsigned ii = 0; ii < rnxNavFile.ephs().size(); ii++) {
382 t_eph* eph = rnxNavFile.ephs()[ii];
383 bool isNew = true;
384 for (int iOld = 0; iOld < ephs.size(); iOld++) {
385 const t_eph* ephOld = ephs[iOld];
386 if (ephOld->prn() == eph->prn() && ephOld->TOC() == eph->TOC()) {
387 isNew = false;
388 break;
389 }
390 }
391 if (isNew) {
392 if (eph->type() == t_eph::GPS) {
393 ephs.append(new t_ephGPS(*dynamic_cast<t_ephGPS*>(eph)));
394 }
395 else if (eph->type() == t_eph::GLONASS) {
396 ephs.append(new t_ephGlo(*dynamic_cast<t_ephGlo*>(eph)));
397 }
398 else if (eph->type() == t_eph::Galileo) {
399 ephs.append(new t_ephGal(*dynamic_cast<t_ephGal*>(eph)));
400 }
401 }
402 }
403}
Note: See TracBrowser for help on using the repository browser.