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

Last change on this file since 4254 was 4254, checked in by mervart, 12 years ago
File size: 11.5 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//
279////////////////////////////////////////////////////////////////////////////
280void t_reqcEdit::editEphemerides() {
281
282 // Easy Exit
283 // ---------
284 if (_navFileNames.isEmpty() || _outNavFileName.isEmpty()) {
285 return;
286 }
287
288 // Read All Ephemerides
289 // --------------------
290 QStringListIterator it(_navFileNames);
291 while (it.hasNext()) {
292 QString fileName = it.next();
293 if (fileName.indexOf('*') != -1 || fileName.indexOf('?') != -1) {
294 QFileInfo fileInfo(fileName);
295 QDir dir = fileInfo.dir();
296 QStringList filters; filters << fileInfo.fileName();
297 QListIterator<QFileInfo> it(dir.entryInfoList(filters));
298 while (it.hasNext()) {
299 QString filePath = it.next().filePath();
300 appendEphemerides(filePath);
301 }
302 }
303 else {
304 appendEphemerides(fileName);
305 }
306 }
307 qStableSort(_ephs.begin(), _ephs.end(), t_eph::earlierTime);
308
309 // Check Satellite Systems
310 // -----------------------
311 bool haveGPS = false;
312 bool haveGlonass = false;
313 for (int ii = 0; ii < _ephs.size(); ii++) {
314 const t_eph* eph = _ephs[ii];
315 if (eph->type() == t_eph::GPS) {
316 haveGPS = true;
317 }
318 else if (eph->type() == t_eph::GLONASS) {
319 haveGlonass = true;
320 }
321 }
322
323 // Initialize output navigation file
324 // ---------------------------------
325 t_rnxNavFile outNavFile(_outNavFileName, t_rnxNavFile::output);
326
327 outNavFile.setGlonass(haveGlonass);
328
329 if (haveGPS && haveGlonass) {
330 outNavFile.setVersion(rnxV3);
331 }
332 else {
333 outNavFile.setVersion(_rnxVersion);
334 }
335
336 bncSettings settings;
337 QMap<QString, QString> txtMap;
338 QString runBy = settings.value("reqcRunBy").toString();
339 if (!runBy.isEmpty()) {
340 txtMap["RUN BY"] = runBy;
341 }
342 QString comment = settings.value("reqcComment").toString();
343 if (!comment.isEmpty()) {
344 txtMap["COMMENT"] = comment;
345 }
346
347 outNavFile.writeHeader(&txtMap);
348
349 // Loop over all ephemerides
350 // -------------------------
351 for (int ii = 0; ii < _ephs.size(); ii++) {
352 const t_eph* eph = _ephs[ii];
353 outNavFile.writeEph(eph);
354 }
355}
356
357//
358////////////////////////////////////////////////////////////////////////////
359void t_reqcEdit::appendEphemerides(const QString& fileName) {
360
361 t_rnxNavFile rnxNavFile(fileName, t_rnxNavFile::input);
362 for (unsigned ii = 0; ii < rnxNavFile.ephs().size(); ii++) {
363 t_eph* eph = rnxNavFile.ephs()[ii];
364 bool isNew = true;
365 for (int iOld = 0; iOld < _ephs.size(); iOld++) {
366 const t_eph* ephOld = _ephs[iOld];
367 if (ephOld->prn() == eph->prn() && ephOld->TOC() == eph->TOC()) {
368 isNew = false;
369 break;
370 }
371 }
372 if (isNew) {
373 if (eph->type() == t_eph::GPS) {
374 _ephs.append(new t_ephGPS(*dynamic_cast<t_ephGPS*>(eph)));
375 }
376 else if (eph->type() == t_eph::GLONASS) {
377 _ephs.append(new t_ephGlo(*dynamic_cast<t_ephGlo*>(eph)));
378 }
379 else if (eph->type() == t_eph::Galileo) {
380 _ephs.append(new t_ephGal(*dynamic_cast<t_ephGal*>(eph)));
381 }
382 }
383 }
384}
Note: See TracBrowser for help on using the repository browser.