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 "bnccore.h"
|
---|
44 | #include "bncsettings.h"
|
---|
45 | #include "bncutils.h"
|
---|
46 | #include "rnxobsfile.h"
|
---|
47 | #include "rnxnavfile.h"
|
---|
48 |
|
---|
49 | using namespace std;
|
---|
50 |
|
---|
51 | // Constructor
|
---|
52 | ////////////////////////////////////////////////////////////////////////////
|
---|
53 | t_reqcEdit::t_reqcEdit(QObject* parent) : QThread(parent) {
|
---|
54 |
|
---|
55 | bncSettings settings;
|
---|
56 |
|
---|
57 | _logFileName = settings.value("reqcOutLogFile").toString(); expandEnvVar(_logFileName);
|
---|
58 | _logFile = 0;
|
---|
59 | _log = 0;
|
---|
60 | _obsFileNames = settings.value("reqcObsFile").toString().split(",", Qt::SkipEmptyParts);
|
---|
61 | _outObsFileName = settings.value("reqcOutObsFile").toString();
|
---|
62 | _navFileNames = settings.value("reqcNavFile").toString().split(",", Qt::SkipEmptyParts);
|
---|
63 | _outNavFileName = settings.value("reqcOutNavFile").toString();
|
---|
64 | int version = settings.value("reqcRnxVersion").toInt();
|
---|
65 | if (version == 2) {
|
---|
66 | _rnxVersion = defaultRnxObsVersion2;
|
---|
67 | }
|
---|
68 | else if (version == 3) {
|
---|
69 | _rnxVersion = defaultRnxObsVersion3;
|
---|
70 | }
|
---|
71 | else if (version == 4) {
|
---|
72 | _rnxVersion = defaultRnxObsVersion4;
|
---|
73 | }
|
---|
74 | _samplingRate = settings.value("reqcSampling").toString().split("sec").first().toDouble();
|
---|
75 | _begTime = bncTime(settings.value("reqcStartDateTime").toString().toLatin1().data());
|
---|
76 | _endTime = bncTime(settings.value("reqcEndDateTime").toString().toLatin1().data());
|
---|
77 |
|
---|
78 | }
|
---|
79 |
|
---|
80 | // Destructor
|
---|
81 | ////////////////////////////////////////////////////////////////////////////
|
---|
82 | t_reqcEdit::~t_reqcEdit() {
|
---|
83 | for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
|
---|
84 | delete _rnxObsFiles[ii];
|
---|
85 | }
|
---|
86 | for (int ii = 0; ii < _ephs.size(); ii++) {
|
---|
87 | delete _ephs[ii];
|
---|
88 | }
|
---|
89 | delete _log; _log = 0;
|
---|
90 | delete _logFile; _logFile = 0;
|
---|
91 | }
|
---|
92 |
|
---|
93 | //
|
---|
94 | ////////////////////////////////////////////////////////////////////////////
|
---|
95 | void t_reqcEdit::run() {
|
---|
96 |
|
---|
97 | // Open Log File
|
---|
98 | // -------------
|
---|
99 | if (!_logFileName.isEmpty()) {
|
---|
100 | _logFile = new QFile(_logFileName);
|
---|
101 | if (_logFile->open(QIODevice::WriteOnly | QIODevice::Text)) {
|
---|
102 | _log = new QTextStream();
|
---|
103 | _log->setDevice(_logFile);
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 | // Log File Header
|
---|
108 | // ---------------
|
---|
109 | if (_log) {
|
---|
110 | *_log << QByteArray(78, '-') << Qt::endl;
|
---|
111 | *_log << "RINEX File Editing\n";
|
---|
112 | *_log << QByteArray(78, '-') << Qt::endl;
|
---|
113 |
|
---|
114 | *_log << QByteArray("Program").leftJustified(15) << ": "
|
---|
115 | << BNC_CORE->pgmName() << Qt::endl;
|
---|
116 | *_log << QByteArray("Run by").leftJustified(15) << ": "
|
---|
117 | << BNC_CORE->userName() << Qt::endl;
|
---|
118 | *_log << QByteArray("Date").leftJustified(15) << ": "
|
---|
119 | << QDateTime::currentDateTime().toUTC().toString("yyyy-MM-dd hh:mm:ss") << Qt::endl;
|
---|
120 | *_log << QByteArray("RINEX Version").leftJustified(15) << ": "
|
---|
121 | << _rnxVersion << Qt::endl;
|
---|
122 | *_log << QByteArray("Sampling").leftJustified(15) << ": "
|
---|
123 | << _samplingRate << " sec" << Qt::endl;
|
---|
124 | *_log << QByteArray("Start time").leftJustified(15) << ": "
|
---|
125 | << _begTime.datestr().c_str() << ' '
|
---|
126 | << _begTime.timestr(0).c_str() << Qt::endl;
|
---|
127 | *_log << QByteArray("End time").leftJustified(15) << ": "
|
---|
128 | << _endTime.datestr().c_str() << ' '
|
---|
129 | << _endTime.timestr(0).c_str() << Qt::endl;
|
---|
130 | *_log << QByteArray("Input Obs Files").leftJustified(15) << ": "
|
---|
131 | << _obsFileNames.join(",") << Qt::endl;
|
---|
132 | *_log << QByteArray("Input Nav Files").leftJustified(15) << ": "
|
---|
133 | << _navFileNames.join(",") << Qt::endl;
|
---|
134 | *_log << QByteArray("Output Obs File").leftJustified(15) << ": "
|
---|
135 | << _outObsFileName << Qt::endl;
|
---|
136 | *_log << QByteArray("Output Nav File").leftJustified(15) << ": "
|
---|
137 | << _outNavFileName << Qt::endl;
|
---|
138 |
|
---|
139 | *_log << QByteArray(78, '-') << Qt::endl;
|
---|
140 | _log->flush();
|
---|
141 | }
|
---|
142 |
|
---|
143 | // Handle Observation Files
|
---|
144 | // ------------------------
|
---|
145 | editObservations();
|
---|
146 |
|
---|
147 | // Handle Navigations Files
|
---|
148 | // ------------------------
|
---|
149 | editEphemerides();
|
---|
150 |
|
---|
151 | // Exit (thread)
|
---|
152 | // -------------
|
---|
153 | if (BNC_CORE->mode() != t_bncCore::interactive) {
|
---|
154 | qApp->exit(9);
|
---|
155 | msleep(100); //sleep 0.1 sec
|
---|
156 | }
|
---|
157 | else {
|
---|
158 | emit finished();
|
---|
159 | deleteLater();
|
---|
160 | }
|
---|
161 |
|
---|
162 | }
|
---|
163 |
|
---|
164 | // Initialize input observation files, sort them according to start time
|
---|
165 | ////////////////////////////////////////////////////////////////////////////
|
---|
166 | void t_reqcEdit::initRnxObsFiles(const QStringList& obsFileNames,
|
---|
167 | QVector<t_rnxObsFile*>& rnxObsFiles,
|
---|
168 | QTextStream* log) {
|
---|
169 |
|
---|
170 | QStringListIterator it(obsFileNames);
|
---|
171 | while (it.hasNext()) {
|
---|
172 | QString fileName = it.next();
|
---|
173 | if (fileName.indexOf('*') != -1 || fileName.indexOf('?') != -1) {
|
---|
174 | QFileInfo fileInfo(fileName);
|
---|
175 | QDir dir = fileInfo.dir();
|
---|
176 | QStringList filters; filters << fileInfo.fileName();
|
---|
177 | QListIterator<QFileInfo> it(dir.entryInfoList(filters));
|
---|
178 | while (it.hasNext()) {
|
---|
179 | QString filePath = it.next().filePath();
|
---|
180 | t_rnxObsFile* rnxObsFile = 0;
|
---|
181 | try {
|
---|
182 | rnxObsFile = new t_rnxObsFile(filePath, t_rnxObsFile::input);
|
---|
183 | rnxObsFiles.append(rnxObsFile);
|
---|
184 | }
|
---|
185 | catch (...) {
|
---|
186 | delete rnxObsFile;
|
---|
187 | if (log) {
|
---|
188 | *log << "Error in rnxObsFile " << filePath.toLatin1().data() << Qt::endl;
|
---|
189 | }
|
---|
190 | }
|
---|
191 | }
|
---|
192 | }
|
---|
193 | else {
|
---|
194 | t_rnxObsFile* rnxObsFile = 0;
|
---|
195 | try {
|
---|
196 | rnxObsFile = new t_rnxObsFile(fileName, t_rnxObsFile::input);
|
---|
197 | rnxObsFiles.append(rnxObsFile);
|
---|
198 | }
|
---|
199 | catch (...) {
|
---|
200 | if (log) {
|
---|
201 | *log << "Error in rnxObsFile " << fileName.toLatin1().data() << Qt::endl;
|
---|
202 | }
|
---|
203 | }
|
---|
204 | }
|
---|
205 | }
|
---|
206 | std::stable_sort(rnxObsFiles.begin(), rnxObsFiles.end(),
|
---|
207 | t_rnxObsFile::earlierStartTime);
|
---|
208 | }
|
---|
209 |
|
---|
210 | //
|
---|
211 | ////////////////////////////////////////////////////////////////////////////
|
---|
212 | void t_reqcEdit::editObservations() {
|
---|
213 |
|
---|
214 | // Easy Exit
|
---|
215 | // ---------
|
---|
216 | if (_obsFileNames.isEmpty() || _outObsFileName.isEmpty()) {
|
---|
217 | return;
|
---|
218 | }
|
---|
219 |
|
---|
220 | t_reqcEdit::initRnxObsFiles(_obsFileNames, _rnxObsFiles, _log);
|
---|
221 |
|
---|
222 | // Initialize output observation file
|
---|
223 | // ----------------------------------
|
---|
224 | t_rnxObsFile outObsFile(_outObsFileName, t_rnxObsFile::output);
|
---|
225 |
|
---|
226 |
|
---|
227 | // Put together all run by date entries
|
---|
228 | // ------------------------------------
|
---|
229 | QStringList runByDate;
|
---|
230 | if (_rnxVersion >= 4.0 && _rnxObsFiles.size() > 1) {
|
---|
231 | for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
|
---|
232 | t_rnxObsFile* rnxObsFile = _rnxObsFiles[ii];
|
---|
233 | QStringListIterator itRunByDt(rnxObsFile->runByDate());
|
---|
234 | while (itRunByDt.hasNext()) {
|
---|
235 | runByDate.append(itRunByDt.next());
|
---|
236 | }
|
---|
237 | }
|
---|
238 | runByDate.removeDuplicates();
|
---|
239 | }
|
---|
240 |
|
---|
241 | // Select observation types
|
---|
242 | // ------------------------
|
---|
243 | bncSettings settings;
|
---|
244 | QStringList useObsTypes = settings.value("reqcUseObsTypes").toString().split(" ", Qt::SkipEmptyParts);
|
---|
245 |
|
---|
246 | // Put together all observation types
|
---|
247 | // ----------------------------------
|
---|
248 | if (_rnxObsFiles.size() > 1 && useObsTypes.size() == 0) {
|
---|
249 | for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
|
---|
250 | t_rnxObsFile* obsFile = _rnxObsFiles[ii];
|
---|
251 | for (int iSys = 0; iSys < obsFile->numSys(); iSys++) {
|
---|
252 | char sys = obsFile->system(iSys);
|
---|
253 | if (sys != ' ') {
|
---|
254 | for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
|
---|
255 | QString type = obsFile->obsType(sys, iType);
|
---|
256 | if (_rnxVersion < 3.0) {
|
---|
257 | useObsTypes << type;
|
---|
258 | }
|
---|
259 | else {
|
---|
260 | useObsTypes << QString(sys) + ":" + type;
|
---|
261 | }
|
---|
262 | }
|
---|
263 | }
|
---|
264 | }
|
---|
265 | }
|
---|
266 | useObsTypes.removeDuplicates();
|
---|
267 | }
|
---|
268 |
|
---|
269 | // Put together all phase shifts
|
---|
270 | // -----------------------------
|
---|
271 | QStringList phaseShifts;
|
---|
272 | if (_rnxVersion >= 3.0 && _rnxObsFiles.size() > 1) {
|
---|
273 | for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
|
---|
274 | t_rnxObsFile* obsFile = _rnxObsFiles[ii];
|
---|
275 | phaseShifts << obsFile->phaseShifts();
|
---|
276 | }
|
---|
277 | phaseShifts.removeDuplicates();
|
---|
278 | }
|
---|
279 |
|
---|
280 | // Put together all GLONASS biases
|
---|
281 | // -------------------------------
|
---|
282 | QStringList gloBiases;
|
---|
283 | if (_rnxVersion >= 3.0 && _rnxObsFiles.size() > 1) {
|
---|
284 | for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
|
---|
285 | t_rnxObsFile* obsFile = _rnxObsFiles[ii];
|
---|
286 | if (ii == 0 && obsFile->numGloBiases() == 4) {
|
---|
287 | break;
|
---|
288 | }
|
---|
289 | else {
|
---|
290 | gloBiases << obsFile->gloBiases();
|
---|
291 | }
|
---|
292 | }
|
---|
293 | gloBiases.removeDuplicates();
|
---|
294 | }
|
---|
295 |
|
---|
296 | // Put together all GLONASS slots
|
---|
297 | // -----------------------------
|
---|
298 | QStringList gloSlots;
|
---|
299 | if (_rnxVersion >= 3.0 && _rnxObsFiles.size() > 1) {
|
---|
300 | for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
|
---|
301 | t_rnxObsFile* obsFile = _rnxObsFiles[ii];
|
---|
302 | if (ii == 0 &&
|
---|
303 | obsFile->numGloSlots() == signed(t_prn::MAXPRN_GLONASS)) {
|
---|
304 | break;
|
---|
305 | }
|
---|
306 | else {
|
---|
307 | gloSlots << obsFile->gloSlots();
|
---|
308 | }
|
---|
309 | }
|
---|
310 | gloSlots.removeDuplicates();
|
---|
311 | }
|
---|
312 |
|
---|
313 | // Loop over all input observation files
|
---|
314 | // -------------------------------------
|
---|
315 | for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
|
---|
316 | t_rnxObsFile* obsFile = _rnxObsFiles[ii];
|
---|
317 | if (_log) {
|
---|
318 | *_log << "Processing File: " << obsFile->fileName() << " start: "
|
---|
319 | << obsFile->startTime().datestr().c_str() << ' '
|
---|
320 | << obsFile->startTime().timestr(0).c_str() << Qt::endl;
|
---|
321 | }
|
---|
322 | if (ii == 0) {
|
---|
323 | outObsFile.setHeader(obsFile->header(), int(_rnxVersion), &useObsTypes,
|
---|
324 | &phaseShifts, &gloBiases, &gloSlots, &runByDate);
|
---|
325 | if (_begTime.valid() && _begTime > outObsFile.startTime()) {
|
---|
326 | outObsFile.setStartTime(_begTime);
|
---|
327 | }
|
---|
328 | if (_samplingRate > outObsFile.interval()) {
|
---|
329 | outObsFile.setInterval(_samplingRate);
|
---|
330 | }
|
---|
331 | editRnxObsHeader(outObsFile);
|
---|
332 | bncSettings settings;
|
---|
333 | QMap<QString, QString> txtMap;
|
---|
334 | QString runBy = settings.value("reqcRunBy").toString();
|
---|
335 | if (!runBy.isEmpty()) {
|
---|
336 | txtMap["RUN BY"] = runBy;
|
---|
337 | }
|
---|
338 | QString comment = settings.value("reqcComment").toString();
|
---|
339 | if (!comment.isEmpty()) {
|
---|
340 | txtMap["COMMENT"] = comment;
|
---|
341 | }
|
---|
342 | if (int(_rnxVersion) < int(obsFile->header().version())) {
|
---|
343 | addRnxConversionDetails(obsFile, txtMap);
|
---|
344 | }
|
---|
345 | outObsFile.header().write(outObsFile.stream(), &txtMap);
|
---|
346 | }
|
---|
347 | t_rnxObsFile::t_rnxEpo* epo = 0;
|
---|
348 | try {
|
---|
349 | while ( (epo = obsFile->nextEpoch()) != 0) {
|
---|
350 | if (_begTime.valid() && epo->tt < _begTime) {
|
---|
351 | continue;
|
---|
352 | }
|
---|
353 | if (_endTime.valid() && epo->tt > _endTime) {
|
---|
354 | break;
|
---|
355 | }
|
---|
356 |
|
---|
357 | int sec = int(nint(epo->tt.gpssec()*10));
|
---|
358 | if (sec % (int(_samplingRate)*10) == 0) {
|
---|
359 | applyLLI(obsFile, epo);
|
---|
360 | outObsFile.writeEpoch(epo);
|
---|
361 | }
|
---|
362 | else {
|
---|
363 | rememberLLI(obsFile, epo);
|
---|
364 | }
|
---|
365 | }
|
---|
366 | }
|
---|
367 | catch (QString str) {
|
---|
368 | if (_log) {
|
---|
369 | *_log << "Exception " << str << Qt::endl;
|
---|
370 | }
|
---|
371 | else {
|
---|
372 | qDebug() << str;
|
---|
373 | }
|
---|
374 | return;
|
---|
375 | }
|
---|
376 | catch (...) {
|
---|
377 | if (_log) {
|
---|
378 | *_log << "Exception unknown" << Qt::endl;
|
---|
379 | }
|
---|
380 | else {
|
---|
381 | qDebug() << "Exception unknown";
|
---|
382 | }
|
---|
383 | return;
|
---|
384 | }
|
---|
385 | }
|
---|
386 | }
|
---|
387 |
|
---|
388 | // Change RINEX Header Content
|
---|
389 | ////////////////////////////////////////////////////////////////////////////
|
---|
390 | void t_reqcEdit::editRnxObsHeader(t_rnxObsFile& obsFile) {
|
---|
391 |
|
---|
392 | bncSettings settings;
|
---|
393 |
|
---|
394 | QString oldMarkerName = settings.value("reqcOldMarkerName").toString();
|
---|
395 | QString newMarkerName = settings.value("reqcNewMarkerName").toString();
|
---|
396 | if (!newMarkerName.isEmpty()) {
|
---|
397 | if (oldMarkerName.isEmpty() ||
|
---|
398 | QRegExp(oldMarkerName).exactMatch(obsFile.markerName())) {
|
---|
399 | obsFile.setMarkerName(newMarkerName);
|
---|
400 | }
|
---|
401 | }
|
---|
402 |
|
---|
403 | QString oldAntennaName = settings.value("reqcOldAntennaName").toString();
|
---|
404 | QString newAntennaName = settings.value("reqcNewAntennaName").toString();
|
---|
405 | if (!newAntennaName.isEmpty()) {
|
---|
406 | if (oldAntennaName.isEmpty() ||
|
---|
407 | QRegExp(oldAntennaName).exactMatch(obsFile.antennaName())) {
|
---|
408 | obsFile.setAntennaName(newAntennaName);
|
---|
409 | }
|
---|
410 | }
|
---|
411 |
|
---|
412 | QString oldAntennaNumber = settings.value("reqcOldAntennaNumber").toString();
|
---|
413 | QString newAntennaNumber = settings.value("reqcNewAntennaNumber").toString();
|
---|
414 | if (!newAntennaNumber.isEmpty()) {
|
---|
415 | if (oldAntennaNumber.isEmpty() ||
|
---|
416 | QRegExp(oldAntennaNumber).exactMatch(obsFile.antennaNumber())) {
|
---|
417 | obsFile.setAntennaNumber(newAntennaNumber);
|
---|
418 | }
|
---|
419 | }
|
---|
420 |
|
---|
421 | const ColumnVector& obsFileAntNEU = obsFile.antNEU();
|
---|
422 | QString oldAntennadN = settings.value("reqcOldAntennadN").toString();
|
---|
423 | QString newAntennadN = settings.value("reqcNewAntennadN").toString();
|
---|
424 | if(!newAntennadN.isEmpty()) {
|
---|
425 | if (oldAntennadN.isEmpty() ||
|
---|
426 | oldAntennadN.toDouble() == obsFileAntNEU(1)) {
|
---|
427 | obsFile.setAntennaN(newAntennadN.toDouble());
|
---|
428 | }
|
---|
429 | }
|
---|
430 | QString oldAntennadE = settings.value("reqcOldAntennadE").toString();
|
---|
431 | QString newAntennadE = settings.value("reqcNewAntennadE").toString();
|
---|
432 | if(!newAntennadE.isEmpty()) {
|
---|
433 | if (oldAntennadE.isEmpty() ||
|
---|
434 | oldAntennadE.toDouble() == obsFileAntNEU(2)) {
|
---|
435 | obsFile.setAntennaE(newAntennadE.toDouble());
|
---|
436 | }
|
---|
437 | }
|
---|
438 | QString oldAntennadU = settings.value("reqcOldAntennadU").toString();
|
---|
439 | QString newAntennadU = settings.value("reqcNewAntennadU").toString();
|
---|
440 | if(!newAntennadU.isEmpty()) {
|
---|
441 | if (oldAntennadU.isEmpty() ||
|
---|
442 | oldAntennadU.toDouble() == obsFileAntNEU(3)) {
|
---|
443 | obsFile.setAntennaU(newAntennadU.toDouble());
|
---|
444 | }
|
---|
445 | }
|
---|
446 |
|
---|
447 | QString oldReceiverType = settings.value("reqcOldReceiverName").toString();
|
---|
448 | QString newReceiverType = settings.value("reqcNewReceiverName").toString();
|
---|
449 | if (!newReceiverType.isEmpty()) {
|
---|
450 | if (oldReceiverType.isEmpty() ||
|
---|
451 | QRegExp(oldReceiverType).exactMatch(obsFile.receiverType())) {
|
---|
452 | obsFile.setReceiverType(newReceiverType);
|
---|
453 | }
|
---|
454 | }
|
---|
455 |
|
---|
456 | QString oldReceiverNumber = settings.value("reqcOldReceiverNumber").toString();
|
---|
457 | QString newReceiverNumber = settings.value("reqcNewReceiverNumber").toString();
|
---|
458 | if (!newReceiverNumber.isEmpty()) {
|
---|
459 | if (oldReceiverNumber.isEmpty() ||
|
---|
460 | QRegExp(oldReceiverNumber).exactMatch(obsFile.receiverNumber())) {
|
---|
461 | obsFile.setReceiverNumber(newReceiverNumber);
|
---|
462 | }
|
---|
463 | }
|
---|
464 | }
|
---|
465 |
|
---|
466 | //
|
---|
467 | ////////////////////////////////////////////////////////////////////////////
|
---|
468 | void t_reqcEdit::rememberLLI(const t_rnxObsFile* obsFile,
|
---|
469 | const t_rnxObsFile::t_rnxEpo* epo) {
|
---|
470 |
|
---|
471 | if (_samplingRate == 0) {
|
---|
472 | return;
|
---|
473 | }
|
---|
474 |
|
---|
475 | for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
|
---|
476 | const t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
|
---|
477 | char sys = rnxSat.prn.system();
|
---|
478 | QString prn(rnxSat.prn.toString().c_str());
|
---|
479 |
|
---|
480 | for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
|
---|
481 | QString type = obsFile->obsType(sys, iType);
|
---|
482 | if (!_lli[prn].contains(iType)) {
|
---|
483 | _lli[prn][iType] = 0;
|
---|
484 | }
|
---|
485 | if (rnxSat.obs.contains(type) && rnxSat.obs[type].lli & 1) {
|
---|
486 | _lli[prn][iType] |= 1;
|
---|
487 | }
|
---|
488 | }
|
---|
489 | }
|
---|
490 | }
|
---|
491 |
|
---|
492 | //
|
---|
493 | ////////////////////////////////////////////////////////////////////////////
|
---|
494 | void t_reqcEdit::applyLLI(const t_rnxObsFile* obsFile,
|
---|
495 | t_rnxObsFile::t_rnxEpo* epo) {
|
---|
496 |
|
---|
497 | if (_samplingRate == 0) {
|
---|
498 | return;
|
---|
499 | }
|
---|
500 |
|
---|
501 | for (unsigned iSat = 0; iSat < epo->rnxSat.size(); iSat++) {
|
---|
502 | t_rnxObsFile::t_rnxSat& rnxSat = epo->rnxSat[iSat];
|
---|
503 | char sys = rnxSat.prn.system();
|
---|
504 | QString prn(rnxSat.prn.toString().c_str());
|
---|
505 |
|
---|
506 | for (int iType = 0; iType < obsFile->nTypes(sys); iType++) {
|
---|
507 | QString type = obsFile->obsType(sys, iType);
|
---|
508 | if (_lli[prn].contains(iType) && _lli[prn][iType] & 1) {
|
---|
509 | if (rnxSat.obs.contains(type)) {
|
---|
510 | rnxSat.obs[type].lli |= 1;
|
---|
511 | }
|
---|
512 | }
|
---|
513 | }
|
---|
514 | }
|
---|
515 |
|
---|
516 | _lli.clear();
|
---|
517 | }
|
---|
518 |
|
---|
519 | /// Read All Ephemerides
|
---|
520 | ////////////////////////////////////////////////////////////////////////////
|
---|
521 | void t_reqcEdit::readEphemerides(const QStringList& navFileNames,
|
---|
522 | QVector<t_eph*>& ephs) {
|
---|
523 |
|
---|
524 | QStringListIterator it(navFileNames);
|
---|
525 | while (it.hasNext()) {
|
---|
526 | QString fileName = it.next();
|
---|
527 | if (fileName.indexOf('*') != -1 || fileName.indexOf('?') != -1) {
|
---|
528 | QFileInfo fileInfo(fileName);
|
---|
529 | QDir dir = fileInfo.dir();
|
---|
530 | QStringList filters; filters << fileInfo.fileName();
|
---|
531 | QListIterator<QFileInfo> it(dir.entryInfoList(filters));
|
---|
532 | while (it.hasNext()) {
|
---|
533 | QString filePath = it.next().filePath();
|
---|
534 | appendEphemerides(filePath, ephs);
|
---|
535 | }
|
---|
536 | }
|
---|
537 | else {
|
---|
538 | appendEphemerides(fileName, ephs);
|
---|
539 | }
|
---|
540 | }
|
---|
541 | // TODO: enable user decision
|
---|
542 | std::stable_sort(ephs.begin(), ephs.end(), t_eph::earlierTime);
|
---|
543 | //std::stable_sort(ephs.begin(), ephs.end(), t_eph::prnSort);
|
---|
544 | }
|
---|
545 |
|
---|
546 | //
|
---|
547 | ////////////////////////////////////////////////////////////////////////////
|
---|
548 | void t_reqcEdit::editEphemerides() {
|
---|
549 |
|
---|
550 | // Easy Exit
|
---|
551 | // ---------
|
---|
552 | if (_navFileNames.isEmpty() || _outNavFileName.isEmpty()) {
|
---|
553 | return;
|
---|
554 | }
|
---|
555 | // Concatenate all comments and all run by date lines
|
---|
556 | // --------------------------------------------------
|
---|
557 | QStringList comments;
|
---|
558 | QStringList runByDate;
|
---|
559 | bncSettings settings;
|
---|
560 | QString comment = settings.value("reqcComment").toString();
|
---|
561 | if (!comment.isEmpty()) {
|
---|
562 | comments.append(comment);
|
---|
563 | }
|
---|
564 | QStringListIterator it(_navFileNames);
|
---|
565 | while (it.hasNext()) {
|
---|
566 | QString fileName = it.next();
|
---|
567 | t_rnxNavFile rnxNavFile(fileName, t_rnxNavFile::input);
|
---|
568 | QStringListIterator itCmnt(rnxNavFile.comments());
|
---|
569 | while (itCmnt.hasNext()) {
|
---|
570 | comments.append(itCmnt.next());
|
---|
571 | }
|
---|
572 | QStringListIterator itRunByDt(rnxNavFile.runByDate());
|
---|
573 | while (itRunByDt.hasNext()) {
|
---|
574 | runByDate.append(itRunByDt.next());
|
---|
575 | }
|
---|
576 | }
|
---|
577 | comments.removeDuplicates();
|
---|
578 | runByDate.removeDuplicates();
|
---|
579 |
|
---|
580 | // Read Ephemerides
|
---|
581 | // ----------------
|
---|
582 | t_reqcEdit::readEphemerides(_navFileNames, _ephs);
|
---|
583 |
|
---|
584 | // Check Satellite Systems
|
---|
585 | // -----------------------
|
---|
586 | bool haveGPS = false;
|
---|
587 | bool haveGlonass = false;
|
---|
588 | QMap<t_eph::e_type, bool> haveGnss;
|
---|
589 | for (int ii = 0; ii < _ephs.size(); ii++) {
|
---|
590 | const t_eph* eph = _ephs[ii];
|
---|
591 | switch (eph->type()) {
|
---|
592 | case t_eph::GPS:
|
---|
593 | haveGPS = true;
|
---|
594 | haveGnss[t_eph::GPS] = true;
|
---|
595 | break;
|
---|
596 | case t_eph::GLONASS:
|
---|
597 | haveGlonass = true;
|
---|
598 | haveGnss[t_eph::GLONASS] = true;
|
---|
599 | break;
|
---|
600 | case t_eph::Galileo:
|
---|
601 | haveGnss[t_eph::Galileo] = true;
|
---|
602 | break;
|
---|
603 | case t_eph::BDS:
|
---|
604 | haveGnss[t_eph::BDS] = true;
|
---|
605 | break;
|
---|
606 | case t_eph::QZSS:
|
---|
607 | haveGnss[t_eph::QZSS] = true;
|
---|
608 | break;
|
---|
609 | case t_eph::IRNSS:
|
---|
610 | haveGnss[t_eph::IRNSS] = true;
|
---|
611 | break;
|
---|
612 | case t_eph::SBAS:
|
---|
613 | haveGnss[t_eph::SBAS] = true;
|
---|
614 | break;
|
---|
615 | default:
|
---|
616 | haveGnss[t_eph::unknown] = true;
|
---|
617 | }
|
---|
618 | }
|
---|
619 |
|
---|
620 | // Initialize output navigation file
|
---|
621 | // ---------------------------------
|
---|
622 | t_rnxNavFile outNavFile(_outNavFileName, t_rnxNavFile::output);
|
---|
623 |
|
---|
624 | outNavFile.setGlonass(haveGlonass);
|
---|
625 |
|
---|
626 | if (_rnxVersion < 3.0) {
|
---|
627 | if (haveGPS && haveGlonass) {
|
---|
628 | outNavFile.setVersion(defaultRnxNavVersion3);
|
---|
629 | }
|
---|
630 | if (haveGPS && !haveGlonass) {
|
---|
631 | outNavFile.setVersion(defaultRnxNavVersion2);
|
---|
632 | }
|
---|
633 | if (!haveGPS && haveGlonass) {
|
---|
634 | outNavFile.setVersion(defaultRnxNavVersion2);
|
---|
635 | }
|
---|
636 | }
|
---|
637 |
|
---|
638 | if (_rnxVersion >= 3.0 && _rnxVersion < 4.0) {
|
---|
639 | outNavFile.setVersion(defaultRnxNavVersion3);
|
---|
640 | }
|
---|
641 |
|
---|
642 | if (_rnxVersion >= 4.0) {
|
---|
643 | outNavFile.setVersion(defaultRnxNavVersion4);
|
---|
644 | }
|
---|
645 |
|
---|
646 | if (outNavFile.version() > 3.0) {
|
---|
647 | if (haveGnss.size() > 1) {
|
---|
648 | outNavFile.setGnssTypeV3(t_eph::unknown);
|
---|
649 | }
|
---|
650 | else if (haveGnss.size() == 1){
|
---|
651 | outNavFile.setGnssTypeV3(haveGnss.keys().first());
|
---|
652 | }
|
---|
653 | }
|
---|
654 |
|
---|
655 | QMap<QString, QString> txtMap;
|
---|
656 | QString runBy = settings.value("reqcRunBy").toString();
|
---|
657 | if (!runBy.isEmpty()) {
|
---|
658 | txtMap["RUN BY"] = runBy;
|
---|
659 | }
|
---|
660 | if (!runByDate.empty()) {
|
---|
661 | txtMap["RUN BY DATE"] = runByDate.join("\\n");
|
---|
662 | }
|
---|
663 | if (!comments.isEmpty()) {
|
---|
664 | txtMap["COMMENT"] = comments.join("\\n");
|
---|
665 | }
|
---|
666 |
|
---|
667 | int mergedNavFiles = _navFileNames.size();
|
---|
668 | unsigned year, month, day;
|
---|
669 | int gps_utc = 0;
|
---|
670 | if (_ephs.size()) {
|
---|
671 | _ephs.at(0)->TOC().civil_date(year, month, day);
|
---|
672 | gps_utc = gnumleap(year, month, day);
|
---|
673 | }
|
---|
674 | outNavFile.writeHeader(&txtMap, mergedNavFiles, gps_utc);
|
---|
675 |
|
---|
676 | // Loop over all ephemerides
|
---|
677 | // -------------------------
|
---|
678 | for (int ii = 0; ii < _ephs.size(); ii++) {
|
---|
679 | const t_eph* eph = _ephs[ii];
|
---|
680 | bncTime begTime = _begTime;
|
---|
681 | bncTime endTime = _endTime;
|
---|
682 | if (eph->type() == t_eph::BDS) {
|
---|
683 | begTime += 14;
|
---|
684 | endTime += 14;
|
---|
685 | }
|
---|
686 | if (begTime.valid() && eph->TOC() < begTime) {
|
---|
687 | continue;
|
---|
688 | }
|
---|
689 | if (endTime.valid() && eph->TOC() > endTime) {
|
---|
690 | break;
|
---|
691 | }
|
---|
692 | if (eph->checkState() == t_eph::bad) {
|
---|
693 | continue;
|
---|
694 | }
|
---|
695 |
|
---|
696 | if (outNavFile.version() < 3.0) {
|
---|
697 | if (outNavFile.glonass() && eph->type() != t_eph::GLONASS) {
|
---|
698 | continue;
|
---|
699 | }
|
---|
700 | if (!outNavFile.glonass() && eph->type() != t_eph::GPS) {
|
---|
701 | continue;
|
---|
702 | }
|
---|
703 | }
|
---|
704 |
|
---|
705 | if (outNavFile.version() < 4.0) {
|
---|
706 | if (eph->ephType() == t_eph::CNAV ||
|
---|
707 | eph->ephType() == t_eph::CNV1 ||
|
---|
708 | eph->ephType() == t_eph::CNV2 ||
|
---|
709 | eph->ephType() == t_eph::CNV3) {
|
---|
710 | continue;
|
---|
711 | }
|
---|
712 | }
|
---|
713 |
|
---|
714 | if (outNavFile.version() >= 4.0 &&
|
---|
715 | eph->ephType() == t_eph::undefined) { // input files < version 4.0
|
---|
716 | continue;
|
---|
717 | }
|
---|
718 |
|
---|
719 | outNavFile.writeEph(eph);
|
---|
720 | }
|
---|
721 | }
|
---|
722 |
|
---|
723 | //
|
---|
724 | ////////////////////////////////////////////////////////////////////////////
|
---|
725 | void t_reqcEdit::appendEphemerides(const QString& fileName,
|
---|
726 | QVector<t_eph*>& ephs) {
|
---|
727 | t_rnxNavFile rnxNavFile(fileName, t_rnxNavFile::input);
|
---|
728 | for (unsigned ii = 0; ii < rnxNavFile.ephs().size(); ii++) {
|
---|
729 | t_eph* eph = rnxNavFile.ephs()[ii];
|
---|
730 | bool isNew = true;
|
---|
731 | for (int iOld = 0; iOld < ephs.size(); iOld++) {
|
---|
732 | const t_eph* ephOld = ephs[iOld];
|
---|
733 | if (ephOld->prn() == eph->prn() &&
|
---|
734 | ephOld->TOC() == eph->TOC()) {
|
---|
735 | isNew = false;
|
---|
736 | break;
|
---|
737 | }
|
---|
738 | }
|
---|
739 |
|
---|
740 | if (isNew) {
|
---|
741 | if (eph->type() == t_eph::GPS) {
|
---|
742 | ephs.append(new t_ephGPS(*dynamic_cast<t_ephGPS*>(eph)));
|
---|
743 | }
|
---|
744 | else if (eph->type() == t_eph::GLONASS) {
|
---|
745 | ephs.append(new t_ephGlo(*dynamic_cast<t_ephGlo*>(eph)));
|
---|
746 | }
|
---|
747 | else if (eph->type() == t_eph::Galileo) {
|
---|
748 | ephs.append(new t_ephGal(*dynamic_cast<t_ephGal*>(eph)));
|
---|
749 | }
|
---|
750 | else if (eph->type() == t_eph::QZSS) {
|
---|
751 | ephs.append(new t_ephGPS(*dynamic_cast<t_ephGPS*>(eph)));
|
---|
752 | }
|
---|
753 | else if (eph->type() == t_eph::SBAS) {
|
---|
754 | ephs.append(new t_ephSBAS(*dynamic_cast<t_ephSBAS*>(eph)));
|
---|
755 | }
|
---|
756 | else if (eph->type() == t_eph::BDS) {
|
---|
757 | ephs.append(new t_ephBDS(*dynamic_cast<t_ephBDS*>(eph)));
|
---|
758 | }
|
---|
759 | else if (eph->type() == t_eph::IRNSS) {
|
---|
760 | ephs.append(new t_ephGPS(*dynamic_cast<t_ephGPS*>(eph)));
|
---|
761 | }
|
---|
762 | }
|
---|
763 | }
|
---|
764 | }
|
---|
765 |
|
---|
766 | void t_reqcEdit::addRnxConversionDetails(const t_rnxObsFile* obsFile,
|
---|
767 | QMap<QString, QString>& txtMap) {
|
---|
768 |
|
---|
769 | int key = 0;
|
---|
770 | QString systems = obsFile->header().usedSystems();
|
---|
771 | QString comment = QString("Signal priorities for RINEX 3 => 2 conversion:");
|
---|
772 | QString commentKey = QString("COMMENT %1").arg(key, 3, 10, QChar('0'));
|
---|
773 | txtMap.insert(commentKey, comment);
|
---|
774 |
|
---|
775 | for(int ii = 0; ii < obsFile->numSys(); ii++) {
|
---|
776 | char sys = systems[ii].toLatin1();
|
---|
777 | txtMap.insert(commentKey, comment);
|
---|
778 | QMap <char, QString> signalPriorityMap;
|
---|
779 | QStringList preferredAttribListSys = obsFile->signalPriorities(sys);
|
---|
780 | QStringList types = obsFile->header().obsTypes(sys);
|
---|
781 | for (int jj = 0; jj < types.size(); jj++) {
|
---|
782 | QString inType = types[jj];
|
---|
783 | char band = inType[1].toLatin1();
|
---|
784 | for (int ii = 0; ii < preferredAttribListSys.size(); ii++) {
|
---|
785 | QString preferredAttrib;
|
---|
786 | if (preferredAttribListSys[ii].indexOf("&") != -1) {
|
---|
787 | QStringList hlp = preferredAttribListSys[ii].split("&", Qt::SkipEmptyParts);
|
---|
788 | if (hlp.size() == 2 && hlp[0].contains(band)) {
|
---|
789 | preferredAttrib = hlp[1];
|
---|
790 | }
|
---|
791 | }
|
---|
792 | else {
|
---|
793 | preferredAttrib = preferredAttribListSys[ii];
|
---|
794 | }
|
---|
795 | if (!signalPriorityMap.contains(band) && !preferredAttrib.isEmpty()){
|
---|
796 | signalPriorityMap[band] = preferredAttrib;
|
---|
797 | }
|
---|
798 | }
|
---|
799 | }
|
---|
800 | QMapIterator<char, QString> it(signalPriorityMap);
|
---|
801 | while (it.hasNext()) {
|
---|
802 | it.next();
|
---|
803 | key++;
|
---|
804 | comment = QString("%1 band %2: %3").arg(sys).arg(it.key()).arg(it.value());
|
---|
805 | commentKey = QString("COMMENT %1").arg(key, 3, 10, QChar('0'));
|
---|
806 | txtMap.insert(commentKey, comment);
|
---|
807 | }
|
---|
808 | }
|
---|
809 | }
|
---|