source: ntrip/trunk/BNC/rinex/reqcedit.cpp@ 4270

Last change on this file since 4270 was 4257, checked in by mervart, 12 years ago
File size: 11.8 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 t_rnxObsFile* rnxObsFile = new t_rnxObsFile(filePath, t_rnxObsFile::input);
118 rnxObsFiles.append(rnxObsFile);
119 }
120 }
121 else {
122 t_rnxObsFile* rnxObsFile = new t_rnxObsFile(fileName, t_rnxObsFile::input);
123 rnxObsFiles.append(rnxObsFile);
124 }
125 }
126 qStableSort(rnxObsFiles.begin(), rnxObsFiles.end(),
127 t_rnxObsFile::earlierStartTime);
128}
129
130//
131////////////////////////////////////////////////////////////////////////////
132void t_reqcEdit::editObservations() {
133
134 // Easy Exit
135 // ---------
136 if (_obsFileNames.isEmpty() || _outObsFileName.isEmpty()) {
137 return;
138 }
139
140 t_reqcEdit::initRnxObsFiles(_obsFileNames, _rnxObsFiles);
141
142 // Initialize output observation file
143 // ----------------------------------
144 t_rnxObsFile outObsFile(_outObsFileName, t_rnxObsFile::output);
145
146 // Loop over all input observation files
147 // -------------------------------------
148 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
149 t_rnxObsFile* obsFile = _rnxObsFiles[ii];
150 if (ii == 0) {
151 outObsFile.setHeader(obsFile->header(), _rnxVersion);
152 if (_begTime.valid() && _begTime > outObsFile.startTime()) {
153 outObsFile.setStartTime(_begTime);
154 }
155 if (_samplingRate > outObsFile.interval()) {
156 outObsFile.setInterval(_samplingRate);
157 }
158 editRnxObsHeader(outObsFile);
159 bncSettings settings;
160 QMap<QString, QString> txtMap;
161 QString runBy = settings.value("reqcRunBy").toString();
162 if (!runBy.isEmpty()) {
163 txtMap["RUN BY"] = runBy;
164 }
165 QString comment = settings.value("reqcComment").toString();
166 if (!comment.isEmpty()) {
167 txtMap["COMMENT"] = comment;
168 }
169 outObsFile.writeHeader(&txtMap);
170 }
171 else {
172 outObsFile.checkNewHeader(obsFile->header());
173 }
174 t_rnxObsFile::t_rnxEpo* epo = 0;
175 while ( (epo = obsFile->nextEpoch()) != 0) {
176 if (_begTime.valid() && epo->tt < _begTime) {
177 continue;
178 }
179 if (_endTime.valid() && epo->tt > _endTime) {
180 break;
181 }
182
183 if (_samplingRate == 0 ||
184 fmod(round(epo->tt.gpssec()), _samplingRate) == 0) {
185 applyLLI(obsFile, epo);
186 outObsFile.writeEpoch(epo);
187 }
188 else {
189 rememberLLI(obsFile, epo);
190 }
191 }
192 }
193}
194
195// Change RINEX Header Content
196////////////////////////////////////////////////////////////////////////////
197void t_reqcEdit::editRnxObsHeader(t_rnxObsFile& obsFile) {
198
199 bncSettings settings;
200
201 QString oldMarkerName = settings.value("reqcOldMarkerName").toString();
202 QString newMarkerName = settings.value("reqcNewMarkerName").toString();
203 if (!newMarkerName.isEmpty()) {
204 if (oldMarkerName.isEmpty() ||
205 QRegExp(oldMarkerName).exactMatch(obsFile.markerName())) {
206 obsFile.setMarkerName(newMarkerName);
207 }
208 }
209
210 QString oldAntennaName = settings.value("reqcOldAntennaName").toString();
211 QString newAntennaName = settings.value("reqcNewAntennaName").toString();
212 if (!newAntennaName.isEmpty()) {
213 if (oldAntennaName.isEmpty() ||
214 QRegExp(oldAntennaName).exactMatch(obsFile.antennaName())) {
215 obsFile.setAntennaName(newAntennaName);
216 }
217 }
218
219 QString oldReceiverType = settings.value("reqcOldReceiverName").toString();
220 QString newReceiverType = settings.value("reqcNewReceiverName").toString();
221 if (!newReceiverType.isEmpty()) {
222 if (oldReceiverType.isEmpty() ||
223 QRegExp(oldReceiverType).exactMatch(obsFile.receiverType())) {
224 obsFile.setReceiverType(newReceiverType);
225 }
226 }
227}
228
229//
230////////////////////////////////////////////////////////////////////////////
231void t_reqcEdit::rememberLLI(const t_rnxObsFile* obsFile,
232 const t_rnxObsFile::t_rnxEpo* epo) {
233
234 if (_samplingRate == 0) {
235 return;
236 }
237
238 for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
239 const t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
240 char sys = rnxSat.satSys;
241 QString prn = QString("%1%2").arg(sys).arg(rnxSat.satNum,2,10,QChar('0'));
242
243 for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
244 if (!_lli[prn].contains(iType)) {
245 _lli[prn][iType] = 0;
246 }
247 if (rnxSat.lli[iType] & 1) {
248 _lli[prn][iType] |= 1;
249 }
250 }
251 }
252}
253
254//
255////////////////////////////////////////////////////////////////////////////
256void t_reqcEdit::applyLLI(const t_rnxObsFile* obsFile,
257 t_rnxObsFile::t_rnxEpo* epo) {
258
259 if (_samplingRate == 0) {
260 return;
261 }
262
263 for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
264 t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
265 char sys = rnxSat.satSys;
266 QString prn = QString("%1%2").arg(sys).arg(rnxSat.satNum,2,10,QChar('0'));
267
268 for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
269 if (_lli[prn].contains(iType) && _lli[prn][iType] & 1) {
270 rnxSat.lli[iType] |= 1;
271 }
272 }
273 }
274
275 _lli.clear();
276}
277
278/// Read All Ephemerides
279////////////////////////////////////////////////////////////////////////////
280void t_reqcEdit::readEphemerides(const QStringList& navFileNames,
281 QVector<t_eph*>& ephs) {
282
283 QStringListIterator it(navFileNames);
284 while (it.hasNext()) {
285 QString fileName = it.next();
286 if (fileName.indexOf('*') != -1 || fileName.indexOf('?') != -1) {
287 QFileInfo fileInfo(fileName);
288 QDir dir = fileInfo.dir();
289 QStringList filters; filters << fileInfo.fileName();
290 QListIterator<QFileInfo> it(dir.entryInfoList(filters));
291 while (it.hasNext()) {
292 QString filePath = it.next().filePath();
293 appendEphemerides(filePath, ephs);
294 }
295 }
296 else {
297 appendEphemerides(fileName, ephs);
298 }
299 }
300 qStableSort(ephs.begin(), ephs.end(), t_eph::earlierTime);
301}
302
303//
304////////////////////////////////////////////////////////////////////////////
305void t_reqcEdit::editEphemerides() {
306
307 // Easy Exit
308 // ---------
309 if (_navFileNames.isEmpty() || _outNavFileName.isEmpty()) {
310 return;
311 }
312
313 // Read Ephemerides
314 // ----------------
315 t_reqcEdit::readEphemerides(_navFileNames, _ephs);
316
317 // Check Satellite Systems
318 // -----------------------
319 bool haveGPS = false;
320 bool haveGlonass = false;
321 for (int ii = 0; ii < _ephs.size(); ii++) {
322 const t_eph* eph = _ephs[ii];
323 if (eph->type() == t_eph::GPS) {
324 haveGPS = true;
325 }
326 else if (eph->type() == t_eph::GLONASS) {
327 haveGlonass = true;
328 }
329 }
330
331 // Initialize output navigation file
332 // ---------------------------------
333 t_rnxNavFile outNavFile(_outNavFileName, t_rnxNavFile::output);
334
335 outNavFile.setGlonass(haveGlonass);
336
337 if (haveGPS && haveGlonass) {
338 outNavFile.setVersion(rnxV3);
339 }
340 else {
341 outNavFile.setVersion(_rnxVersion);
342 }
343
344 bncSettings settings;
345 QMap<QString, QString> txtMap;
346 QString runBy = settings.value("reqcRunBy").toString();
347 if (!runBy.isEmpty()) {
348 txtMap["RUN BY"] = runBy;
349 }
350 QString comment = settings.value("reqcComment").toString();
351 if (!comment.isEmpty()) {
352 txtMap["COMMENT"] = comment;
353 }
354
355 outNavFile.writeHeader(&txtMap);
356
357 // Loop over all ephemerides
358 // -------------------------
359 for (int ii = 0; ii < _ephs.size(); ii++) {
360 const t_eph* eph = _ephs[ii];
361 outNavFile.writeEph(eph);
362 }
363}
364
365//
366////////////////////////////////////////////////////////////////////////////
367void t_reqcEdit::appendEphemerides(const QString& fileName,
368 QVector<t_eph*>& ephs) {
369
370 t_rnxNavFile rnxNavFile(fileName, t_rnxNavFile::input);
371 for (unsigned ii = 0; ii < rnxNavFile.ephs().size(); ii++) {
372 t_eph* eph = rnxNavFile.ephs()[ii];
373 bool isNew = true;
374 for (int iOld = 0; iOld < ephs.size(); iOld++) {
375 const t_eph* ephOld = ephs[iOld];
376 if (ephOld->prn() == eph->prn() && ephOld->TOC() == eph->TOC()) {
377 isNew = false;
378 break;
379 }
380 }
381 if (isNew) {
382 if (eph->type() == t_eph::GPS) {
383 ephs.append(new t_ephGPS(*dynamic_cast<t_ephGPS*>(eph)));
384 }
385 else if (eph->type() == t_eph::GLONASS) {
386 ephs.append(new t_ephGlo(*dynamic_cast<t_ephGlo*>(eph)));
387 }
388 else if (eph->type() == t_eph::Galileo) {
389 ephs.append(new t_ephGal(*dynamic_cast<t_ephGal*>(eph)));
390 }
391 }
392 }
393}
Note: See TracBrowser for help on using the repository browser.