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