source: ntrip/trunk/BNC/src/rinex/reqcanalyze.cpp@ 6704

Last change on this file since 6704 was 6563, checked in by stuerze, 10 years ago

try to catch incorrect user input

File size: 33.3 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_reqcAnalyze
30 *
31 * Purpose: Analyze RINEX Files
32 *
33 * Author: L. Mervart
34 *
35 * Created: 11-Apr-2012
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iostream>
42#include <iomanip>
43#include <qwt_plot_renderer.h>
44
45#include "reqcanalyze.h"
46#include "bnccore.h"
47#include "bncsettings.h"
48#include "reqcedit.h"
49#include "bncutils.h"
50#include "graphwin.h"
51#include "polarplot.h"
52#include "availplot.h"
53#include "eleplot.h"
54#include "dopplot.h"
55#include "bncephuser.h"
56
57using namespace std;
58
59// Constructor
60////////////////////////////////////////////////////////////////////////////
61t_reqcAnalyze::t_reqcAnalyze(QObject* parent) : QThread(parent) {
62
63 bncSettings settings;
64
65 _logFileName = settings.value("reqcOutLogFile").toString(); expandEnvVar(_logFileName);
66 _logFile = 0;
67 _log = 0;
68 _currEpo = 0;
69 _obsFileNames = settings.value("reqcObsFile").toString().split(",", QString::SkipEmptyParts);
70 _navFileNames = settings.value("reqcNavFile").toString().split(",", QString::SkipEmptyParts);
71 _reqcPlotSignals = settings.value("reqcSkyPlotSignals").toString();
72 _defaultSignalTypes << "G:1&2" << "R:1&2" << "J:1&2" << "E:1&5" << "S:1&5" << "C:1&7";
73 if (_reqcPlotSignals.isEmpty()) {
74 _reqcPlotSignals = _defaultSignalTypes.join(" ");
75 }
76 analyzePlotSignals(_signalTypes);
77
78 connect(this, SIGNAL(dspSkyPlot(const QString&, const QString&, QVector<t_polarPoint*>*,
79 const QString&, QVector<t_polarPoint*>*,
80 const QByteArray&, double)),
81 this, SLOT(slotDspSkyPlot(const QString&, const QString&, QVector<t_polarPoint*>*,
82 const QString&, QVector<t_polarPoint*>*,
83 const QByteArray&, double)));
84
85 connect(this, SIGNAL(dspAvailPlot(const QString&, const QByteArray&)),
86 this, SLOT(slotDspAvailPlot(const QString&, const QByteArray&)));
87}
88
89// Destructor
90////////////////////////////////////////////////////////////////////////////
91t_reqcAnalyze::~t_reqcAnalyze() {
92 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
93 delete _rnxObsFiles[ii];
94 }
95 for (int ii = 0; ii < _ephs.size(); ii++) {
96 delete _ephs[ii];
97 }
98 delete _log; _log = 0;
99 delete _logFile; _logFile = 0;
100 if (BNC_CORE->mode() != t_bncCore::interactive) {
101 qApp->exit(0);
102 }
103}
104
105//
106////////////////////////////////////////////////////////////////////////////
107void t_reqcAnalyze::run() {
108
109 static const double QC_FORMAT_VERSION = 1.0;
110
111 // Open Log File
112 // -------------
113 _logFile = new QFile(_logFileName);
114 if (_logFile->open(QIODevice::WriteOnly | QIODevice::Text)) {
115 _log = new QTextStream();
116 _log->setDevice(_logFile);
117 }
118 *_log << "QC Format Version : " << QString("%1").arg(QC_FORMAT_VERSION,3,'f',1) << endl << endl;
119
120 // Check Ephemerides
121 // -----------------
122 checkEphemerides();
123
124 // Initialize RINEX Observation Files
125 // ----------------------------------
126 t_reqcEdit::initRnxObsFiles(_obsFileNames, _rnxObsFiles, _log);
127
128 // Read Ephemerides
129 // ----------------
130 t_reqcEdit::readEphemerides(_navFileNames, _ephs);
131
132 // Loop over all RINEX Files
133 // -------------------------
134 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
135 analyzeFile(_rnxObsFiles[ii]);
136 }
137
138 // Exit
139 // ----
140 emit finished();
141 deleteLater();
142}
143
144//
145////////////////////////////////////////////////////////////////////////////
146void t_reqcAnalyze::analyzePlotSignals(QMap<char, QVector<QString> >& signalTypes) {
147
148 QStringList signalsOpt = _reqcPlotSignals.split(" ", QString::SkipEmptyParts);
149
150 for (int ii = 0; ii < signalsOpt.size(); ii++) {
151 QStringList input = signalsOpt.at(ii).split(QRegExp("[:&]"), QString::SkipEmptyParts);
152 if (input.size() > 1 && input[0].length() == 1) {
153 char system = input[0].toAscii().constData()[0];
154 QStringList sysValid = _defaultSignalTypes.filter(QString(system));
155 QStringList defaultSignals = sysValid.at(0).split(QRegExp("[:&]"));
156 if (sysValid.isEmpty()) {continue;}
157 if (input[1][0].isDigit()) {
158 signalTypes[system].append(input[1]);
159 }
160 else {
161 signalTypes[system].append(defaultSignals[1]);
162 }
163 if (input.size() > 2) {
164 if (input[2][0].isDigit()) {
165 signalTypes[system].append(input[2]);
166 }
167 else {
168 signalTypes[system].append(defaultSignals[2]);
169 }
170 } else {
171 signalTypes[system].append(defaultSignals[2]);
172 if (signalTypes[system][0] == signalTypes[system][1]) {
173 signalTypes[system][0] = defaultSignals[1];
174 }
175 }
176 }
177 }
178}
179
180//
181////////////////////////////////////////////////////////////////////////////
182void t_reqcAnalyze::analyzeFile(t_rnxObsFile* obsFile) {
183
184 _qcFile.clear();
185
186 // A priori Coordinates
187 // --------------------
188 ColumnVector xyzSta = obsFile->xyz();
189
190 // Loop over all Epochs
191 // --------------------
192 try {
193 QMap<QString, bncTime> lastObsTime;
194 bool firstEpo = true;
195 while ( (_currEpo = obsFile->nextEpoch()) != 0) {
196 if (firstEpo) {
197 firstEpo = false;
198 _qcFile._startTime = _currEpo->tt;
199 _qcFile._antennaName = obsFile->antennaName();
200 _qcFile._markerName = obsFile->markerName();
201 _qcFile._receiverType = obsFile->receiverType();
202 _qcFile._interval = obsFile->interval();
203 }
204 _qcFile._endTime = _currEpo->tt;
205
206 t_qcEpo qcEpo;
207 qcEpo._epoTime = _currEpo->tt;
208 qcEpo._PDOP = cmpDOP(xyzSta);
209
210 // Loop over all satellites
211 // ------------------------
212 for (unsigned iObs = 0; iObs < _currEpo->rnxSat.size(); iObs++) {
213 const t_rnxObsFile::t_rnxSat& rnxSat = _currEpo->rnxSat[iObs];
214 if (_signalTypes.find(rnxSat.prn.system()) == _signalTypes.end()) {
215 continue;
216 }
217 t_satObs satObs;
218 t_rnxObsFile::setObsFromRnx(obsFile, _currEpo, rnxSat, satObs);
219 t_qcSat& qcSat = qcEpo._qcSat[satObs._prn];
220 setQcObs(qcEpo._epoTime, xyzSta, satObs, lastObsTime, qcSat);
221 updateQcSat(qcSat, _qcFile._qcSatSum[satObs._prn]);
222 }
223 _qcFile._qcEpo.push_back(qcEpo);
224 }
225
226 analyzeMultipath();
227
228 preparePlotData(obsFile);
229
230 printReport(obsFile);
231 }
232 catch (QString str) {
233 if (_log) {
234 *_log << "Exception " << str << endl;
235 }
236 else {
237 qDebug() << str;
238 }
239 }
240}
241
242// Compute Dilution of Precision
243////////////////////////////////////////////////////////////////////////////
244double t_reqcAnalyze::cmpDOP(const ColumnVector& xyzSta) const {
245
246 if ( xyzSta.size() != 3 || (xyzSta[0] == 0.0 && xyzSta[1] == 0.0 && xyzSta[2] == 0.0) ) {
247 return 0.0;
248 }
249
250 unsigned nSat = _currEpo->rnxSat.size();
251
252 if (nSat < 4) {
253 return 0.0;
254 }
255
256 Matrix AA(nSat, 4);
257
258 unsigned nSatUsed = 0;
259 for (unsigned iSat = 0; iSat < nSat; iSat++) {
260
261 const t_rnxObsFile::t_rnxSat& rnxSat = _currEpo->rnxSat[iSat];
262 const t_prn& prn = rnxSat.prn;
263
264 if (_signalTypes.find(prn.system()) == _signalTypes.end()) {
265 continue;
266 }
267
268 t_eph* eph = 0;
269 for (int ie = 0; ie < _ephs.size(); ie++) {
270 if (_ephs[ie]->prn() == prn) {
271 eph = _ephs[ie];
272 break;
273 }
274 }
275 if (eph) {
276 ColumnVector xSat(4);
277 ColumnVector vv(3);
278 if (eph->getCrd(_currEpo->tt, xSat, vv, false) == success) {
279 ++nSatUsed;
280 ColumnVector dx = xSat.Rows(1,3) - xyzSta;
281 double rho = dx.norm_Frobenius();
282 AA(nSatUsed,1) = dx(1) / rho;
283 AA(nSatUsed,2) = dx(2) / rho;
284 AA(nSatUsed,3) = dx(3) / rho;
285 AA(nSatUsed,4) = 1.0;
286 }
287 }
288 }
289
290 if (nSatUsed < 4) {
291 return 0.0;
292 }
293
294 AA = AA.Rows(1, nSatUsed);
295
296 SymmetricMatrix QQ;
297 QQ << AA.t() * AA;
298 QQ = QQ.i();
299
300 return sqrt(QQ.trace());
301}
302
303//
304////////////////////////////////////////////////////////////////////////////
305void t_reqcAnalyze::updateQcSat(const t_qcSat& qcSat, t_qcSatSum& qcSatSum) {
306
307 for (int ii = 0; ii < qcSat._qcFrq.size(); ii++) {
308 const t_qcFrq& qcFrq = qcSat._qcFrq[ii];
309 t_qcFrqSum& qcFrqSum = qcSatSum._qcFrqSum[qcFrq._rnxType2ch];
310 qcFrqSum._numObs += 1;
311 if (qcFrq._slip) {
312 qcFrqSum._numSlipsFlagged += 1;
313 }
314 if (qcFrq._gap) {
315 qcFrqSum._numGaps += 1;
316 }
317 if (qcFrq._SNR > 0.0) {
318 qcFrqSum._numSNR += 1;
319 qcFrqSum._sumSNR += qcFrq._SNR;
320 }
321 }
322}
323
324//
325////////////////////////////////////////////////////////////////////////////
326void t_reqcAnalyze::setQcObs(const bncTime& epoTime, const ColumnVector& xyzSta,
327 const t_satObs& satObs, QMap<QString, bncTime>& lastObsTime,
328 t_qcSat& qcSat) {
329
330 t_eph* eph = 0;
331 for (int ie = 0; ie < _ephs.size(); ie++) {
332 if (_ephs[ie]->prn() == satObs._prn) {
333 eph = _ephs[ie];
334 break;
335 }
336 }
337 if (eph) {
338 ColumnVector xc(4);
339 ColumnVector vv(3);
340 if ( xyzSta.size() == 3 && (xyzSta[0] != 0.0 || xyzSta[1] != 0.0 || xyzSta[2] != 0.0) &&
341 eph->getCrd(epoTime, xc, vv, false) == success) {
342 double rho, eleSat, azSat;
343 topos(xyzSta(1), xyzSta(2), xyzSta(3), xc(1), xc(2), xc(3), rho, eleSat, azSat);
344 qcSat._eleSet = true;
345 qcSat._azDeg = azSat * 180.0/M_PI;
346 qcSat._eleDeg = eleSat * 180.0/M_PI;
347 }
348 if (satObs._prn.system() == 'R') {
349 qcSat._slotSet = true;
350 qcSat._slotNum = eph->slotNum();
351 }
352 }
353
354 // Availability and Slip Flags
355 // ---------------------------
356 for (unsigned ii = 0; ii < satObs._obs.size(); ii++) {
357 const t_frqObs* frqObs = satObs._obs[ii];
358
359 qcSat._qcFrq.push_back(t_qcFrq());
360 t_qcFrq& qcFrq = qcSat._qcFrq.back();
361
362 qcFrq._rnxType2ch = QString(frqObs->_rnxType2ch.c_str());
363 qcFrq._SNR = frqObs->_snr;
364 qcFrq._slip = frqObs->_slip;
365 qcFrq._phaseValid = frqObs->_phaseValid;
366 qcFrq._codeValid = frqObs->_codeValid;
367 // Check Gaps
368 // ----------
369 QString key = QString(satObs._prn.toString().c_str()) + qcFrq._rnxType2ch;
370 if (lastObsTime[key].valid()) {
371 double dt = epoTime - lastObsTime[key];
372 if (dt > 1.5 * _qcFile._interval) {
373 qcFrq._gap = true;
374 }
375 }
376 lastObsTime[key] = epoTime;
377
378 // Compute the Multipath Linear Combination
379 // ----------------------------------------
380 if (frqObs->_codeValid) {
381 t_frequency::type fA = t_frequency::dummy;
382 t_frequency::type fB = t_frequency::dummy;
383 char sys = satObs._prn.system();
384 std::string frqType1, frqType2;
385 if (_signalTypes.find(sys) != _signalTypes.end()) {
386 frqType1.push_back(sys);
387 frqType1.push_back(_signalTypes[sys][0][0].toAscii());
388 frqType2.push_back(sys);
389 frqType2.push_back(_signalTypes[sys][1][0].toAscii());
390 if (frqObs->_rnxType2ch[0] == frqType1[1]) {
391 fA = t_frequency::toInt(frqType1);
392 fB = t_frequency::toInt(frqType2);
393 }
394 else if (frqObs->_rnxType2ch[0] == frqType2[1]) {
395 fA = t_frequency::toInt(frqType2);
396 fB = t_frequency::toInt(frqType1);
397 }
398 }
399 if (fA != t_frequency::dummy && fB != t_frequency::dummy) {
400 double f_a = t_CST::freq(fA, qcSat._slotNum);
401 double f_b = t_CST::freq(fB, qcSat._slotNum);
402 double C_a = frqObs->_code;
403
404 bool foundA = false;
405 double L_a = 0.0;
406 bool foundB = false;
407 double L_b = 0.0;
408 for (unsigned jj = 0; jj < satObs._obs.size(); jj++) {
409 const t_frqObs* frqObsHlp = satObs._obs[jj];
410 if (frqObsHlp->_rnxType2ch[0] == t_frequency::toString(fA)[1] &&
411 frqObsHlp->_phaseValid) {
412 foundA = true;
413 L_a = frqObsHlp->_phase * t_CST::c / f_a;
414 }
415 else if (frqObsHlp->_rnxType2ch[0] == t_frequency::toString(fB)[1] &&
416 frqObsHlp->_phaseValid) {
417 foundB = true;
418 L_b = frqObsHlp->_phase * t_CST::c / f_b;
419 }
420 }
421 if (foundA && foundB) {
422 qcFrq._setMP = true;
423 qcFrq._rawMP = C_a - L_a - 2.0*f_b*f_b/(f_a*f_a-f_b*f_b) * (L_a - L_b);
424 }
425 }
426 }
427 } // satObs loop
428}
429
430//
431////////////////////////////////////////////////////////////////////////////
432void t_reqcAnalyze::analyzeMultipath() {
433
434 const double SLIPTRESH = 10.0; // cycle-slip threshold (meters)
435 const double chunkStep = 600.0; // 10 minutes
436
437 // Loop over all satellites available
438 // ----------------------------------
439 QMutableMapIterator<t_prn, t_qcSatSum> itSat(_qcFile._qcSatSum);
440 while (itSat.hasNext()) {
441 itSat.next();
442 const t_prn& prn = itSat.key();
443 t_qcSatSum& qcSatSum = itSat.value();
444
445 // Loop over all frequencies available
446 // -----------------------------------
447 QMutableMapIterator<QString, t_qcFrqSum> itFrq(qcSatSum._qcFrqSum);
448 while (itFrq.hasNext()) {
449 itFrq.next();
450 const QString& frqType = itFrq.key();
451 t_qcFrqSum& qcFrqSum = itFrq.value();
452
453 // Loop over all Chunks of Data
454 // ----------------------------
455 for (bncTime chunkStart = _qcFile._startTime;
456 chunkStart < _qcFile._endTime; chunkStart += chunkStep) {
457
458 bncTime chunkEnd = chunkStart + chunkStep;
459
460 QVector<t_qcFrq*> frqVec;
461 QVector<double> MP;
462
463 // Loop over all Epochs within one Chunk of Data
464 // ---------------------------------------------
465 for (int iEpo = 0; iEpo < _qcFile._qcEpo.size(); iEpo++) {
466 t_qcEpo& qcEpo = _qcFile._qcEpo[iEpo];
467 if (chunkStart <= qcEpo._epoTime && qcEpo._epoTime < chunkEnd) {
468 if (qcEpo._qcSat.contains(prn)) {
469 t_qcSat& qcSat = qcEpo._qcSat[prn];
470 for (int iFrq = 0; iFrq < qcSat._qcFrq.size(); iFrq++) {
471 t_qcFrq& qcFrq = qcSat._qcFrq[iFrq];
472 if (qcFrq._rnxType2ch == frqType) {
473 frqVec << &qcFrq;
474 if (qcFrq._setMP) {
475 MP << qcFrq._rawMP;
476 }
477 }
478 }
479 }
480 }
481 }
482
483 // Compute the multipath mean and standard deviation
484 // -------------------------------------------------
485 if (MP.size() > 1) {
486 double meanMP = 0.0;
487 for (int ii = 0; ii < MP.size(); ii++) {
488 meanMP += MP[ii];
489 }
490 meanMP /= MP.size();
491
492 bool slipMP = false;
493
494 double stdMP = 0.0;
495 for (int ii = 0; ii < MP.size(); ii++) {
496 double diff = MP[ii] - meanMP;
497 if (fabs(diff) > SLIPTRESH) {
498 slipMP = true;
499 break;
500 }
501 stdMP += diff * diff;
502 }
503
504 if (slipMP) {
505 stdMP = 0.0;
506 stdMP = 0.0;
507 qcFrqSum._numSlipsFound += 1;
508 }
509 else {
510 stdMP = sqrt(stdMP / (MP.size()-1));
511 qcFrqSum._numMP += 1;
512 qcFrqSum._sumMP += stdMP;
513 }
514
515 for (int ii = 0; ii < frqVec.size(); ii++) {
516 t_qcFrq* qcFrq = frqVec[ii];
517 if (slipMP) {
518 qcFrq->_slip = true;
519 }
520 else {
521 qcFrq->_stdMP = stdMP;
522 }
523 }
524 }
525 } // chunk loop
526 } // frq loop
527 } // sat loop
528}
529
530//
531////////////////////////////////////////////////////////////////////////////
532void t_reqcAnalyze::preparePlotData(const t_rnxObsFile* obsFile) {
533
534 QString mp1Title = "Multipath\n";
535 QString mp2Title = "Multipath\n";
536 QString sn1Title = "Signal-to-Noise Ratio\n";
537 QString sn2Title = "Signal-to-Noise Ratio\n";
538
539 for(QMap<char, QVector<QString> >::iterator it = _signalTypes.begin();
540 it != _signalTypes.end(); it++) {
541 mp1Title += QString(it.key()) + ":" + it.value()[0] + " ";
542 sn1Title += QString(it.key()) + ":" + it.value()[0] + " ";
543 mp2Title += QString(it.key()) + ":" + it.value()[1] + " ";
544 sn2Title += QString(it.key()) + ":" + it.value()[1] + " ";
545 }
546
547 QVector<t_polarPoint*>* dataMP1 = new QVector<t_polarPoint*>;
548 QVector<t_polarPoint*>* dataMP2 = new QVector<t_polarPoint*>;
549 QVector<t_polarPoint*>* dataSNR1 = new QVector<t_polarPoint*>;
550 QVector<t_polarPoint*>* dataSNR2 = new QVector<t_polarPoint*>;
551
552 // Loop over all observations
553 // --------------------------
554 for (int iEpo = 0; iEpo < _qcFile._qcEpo.size(); iEpo++) {
555 t_qcEpo& qcEpo = _qcFile._qcEpo[iEpo];
556 QMapIterator<t_prn, t_qcSat> it(qcEpo._qcSat);
557 while (it.hasNext()) {
558 it.next();
559 const t_prn& prn = it.key();
560 const t_qcSat& qcSat = it.value();
561 if (qcSat._eleSet) {
562
563 QString frqType[2];
564
565 for (int iFrq = 0; iFrq < qcSat._qcFrq.size(); iFrq++) {
566 const t_qcFrq& qcFrq = qcSat._qcFrq[iFrq];
567
568 for (int ii = 0; ii < 2; ii++) {
569 if (frqType[ii].isEmpty()) {
570 QMapIterator<char, QVector<QString> > it(_signalTypes);
571 while (it.hasNext()) {
572 it.next();
573 if (it.key() == prn.system()) {
574 if (it.value()[ii] == qcFrq._rnxType2ch || it.value()[ii] == qcFrq._rnxType2ch.left(1)) {
575 frqType[ii] = qcFrq._rnxType2ch;
576 break;
577 }
578 }
579 }
580 }
581 }
582 if (qcFrq._rnxType2ch == frqType[0]) {
583 (*dataSNR1) << (new t_polarPoint(qcSat._azDeg, 90.0 - qcSat._eleDeg, qcFrq._SNR));
584 (*dataMP1) << (new t_polarPoint(qcSat._azDeg, 90.0 - qcSat._eleDeg, qcFrq._stdMP));
585 }
586 else if (qcFrq._rnxType2ch == frqType[1]) {
587 (*dataSNR2) << (new t_polarPoint(qcSat._azDeg, 90.0 - qcSat._eleDeg, qcFrq._SNR));
588 (*dataMP2) << (new t_polarPoint(qcSat._azDeg, 90.0 - qcSat._eleDeg, qcFrq._stdMP));
589 }
590 }
591 }
592 }
593 }
594
595 // Show the plots
596 // --------------
597 if (BNC_CORE->GUIenabled()) {
598 QFileInfo fileInfo(obsFile->fileName());
599 QByteArray title = fileInfo.fileName().toAscii();
600 emit dspSkyPlot(obsFile->fileName(), mp1Title, dataMP1, mp2Title, dataMP2, "Meters", 2.0);
601 emit dspSkyPlot(obsFile->fileName(), sn1Title, dataSNR1, sn2Title, dataSNR2, "dbHz", 54.0);
602 emit dspAvailPlot(obsFile->fileName(), title);
603 }
604 else {
605 for (int ii = 0; ii < dataMP1->size(); ii++) {
606 delete dataMP1->at(ii);
607 }
608 delete dataMP1;
609 for (int ii = 0; ii < dataMP2->size(); ii++) {
610 delete dataMP2->at(ii);
611 }
612 delete dataMP2;
613 for (int ii = 0; ii < dataSNR1->size(); ii++) {
614 delete dataSNR1->at(ii);
615 }
616 delete dataSNR1;
617 for (int ii = 0; ii < dataSNR2->size(); ii++) {
618 delete dataSNR2->at(ii);
619 }
620 delete dataSNR2;
621 }
622}
623
624//
625////////////////////////////////////////////////////////////////////////////
626void t_reqcAnalyze::slotDspSkyPlot(const QString& fileName, const QString& title1,
627 QVector<t_polarPoint*>* data1, const QString& title2,
628 QVector<t_polarPoint*>* data2, const QByteArray& scaleTitle,
629 double maxValue) {
630
631 if (BNC_CORE->GUIenabled()) {
632
633 if (maxValue == 0.0) {
634 if (data1) {
635 for (int ii = 0; ii < data1->size(); ii++) {
636 double val = data1->at(ii)->_value;
637 if (maxValue < val) {
638 maxValue = val;
639 }
640 }
641 }
642 if (data2) {
643 for (int ii = 0; ii < data2->size(); ii++) {
644 double val = data2->at(ii)->_value;
645 if (maxValue < val) {
646 maxValue = val;
647 }
648 }
649 }
650 }
651
652 QwtInterval scaleInterval(0.0, maxValue);
653
654 QVector<QWidget*> plots;
655 if (data1) {
656 QwtText title(title1);
657 QFont font = title.font(); font.setPointSize(font.pointSize()-1); title.setFont(font);
658 t_polarPlot* plot1 = new t_polarPlot(title, scaleInterval, BNC_CORE->mainWindow());
659 plot1->addCurve(data1);
660 plots << plot1;
661 }
662 if (data2) {
663 QwtText title(title2);
664 QFont font = title.font(); font.setPointSize(font.pointSize()-1); title.setFont(font);
665 t_polarPlot* plot2 = new t_polarPlot(title, scaleInterval, BNC_CORE->mainWindow());
666 plot2->addCurve(data2);
667 plots << plot2;
668 }
669
670 t_graphWin* graphWin = new t_graphWin(0, fileName, plots,
671 &scaleTitle, &scaleInterval);
672
673 graphWin->show();
674
675 bncSettings settings;
676 QString dirName = settings.value("reqcPlotDir").toString();
677 if (!dirName.isEmpty()) {
678 QByteArray ext = (scaleTitle == "Meters") ? "_M.png" : "_S.png";
679 graphWin->savePNG(dirName, ext);
680 }
681 }
682}
683
684//
685////////////////////////////////////////////////////////////////////////////
686void t_reqcAnalyze::slotDspAvailPlot(const QString& fileName, const QByteArray& title) {
687
688 t_plotData plotData;
689 QMap<t_prn, t_plotData> plotDataMap;
690
691 for (int ii = 0; ii < _qcFile._qcEpo.size(); ii++) {
692 const t_qcEpo& qcEpo = _qcFile._qcEpo[ii];
693 double mjdX24 = qcEpo._epoTime.mjddec() * 24.0;
694
695 plotData._mjdX24 << mjdX24;
696 plotData._PDOP << qcEpo._PDOP;
697 plotData._numSat << qcEpo._qcSat.size();
698
699 QMapIterator<t_prn, t_qcSat> it(qcEpo._qcSat);
700 while (it.hasNext()) {
701 it.next();
702 const t_prn& prn = it.key();
703 const t_qcSat& qcSat = it.value();
704
705 t_plotData& data = plotDataMap[prn];
706
707 if (qcSat._eleSet) {
708 data._mjdX24 << mjdX24;
709 data._eleDeg << qcSat._eleDeg;
710 }
711
712 char frqChar1 = _signalTypes[prn.system()][0][0].toAscii();
713 char frqChar2 = _signalTypes[prn.system()][1][0].toAscii();
714
715 QString frqType1;
716 QString frqType2;
717 for (int iFrq = 0; iFrq < qcSat._qcFrq.size(); iFrq++) {
718 const t_qcFrq& qcFrq = qcSat._qcFrq[iFrq];
719 if (qcFrq._rnxType2ch[0] == frqChar1 && frqType1.isEmpty()) {
720 frqType1 = qcFrq._rnxType2ch;
721 }
722 if (qcFrq._rnxType2ch[0] == frqChar2 && frqType2.isEmpty()) {
723 frqType2 = qcFrq._rnxType2ch;
724 }
725 if (qcFrq._rnxType2ch == frqType1) {
726 if (qcFrq._slip) {
727 data._L1slip << mjdX24;
728 }
729 else if (qcFrq._gap) {
730 data._L1gap << mjdX24;
731 }
732 else {
733 data._L1ok << mjdX24;
734 }
735 }
736 else if (qcFrq._rnxType2ch == frqType2) {
737 if (qcFrq._slip) {
738 data._L2slip << mjdX24;
739 }
740 else if (qcFrq._gap) {
741 data._L2gap << mjdX24;
742 }
743 else {
744 data._L2ok << mjdX24;
745 }
746 }
747 }
748 }
749 }
750
751 if (BNC_CORE->GUIenabled()) {
752 t_availPlot* plotA = new t_availPlot(0, plotDataMap);
753 plotA->setTitle(title);
754
755 t_elePlot* plotZ = new t_elePlot(0, plotDataMap);
756
757 t_dopPlot* plotD = new t_dopPlot(0, plotData);
758
759 QVector<QWidget*> plots;
760 plots << plotA << plotZ << plotD;
761 t_graphWin* graphWin = new t_graphWin(0, fileName, plots, 0, 0);
762
763 int ww = QFontMetrics(graphWin->font()).width('w');
764 graphWin->setMinimumSize(120*ww, 40*ww);
765
766 graphWin->show();
767
768 bncSettings settings;
769 QString dirName = settings.value("reqcPlotDir").toString();
770 if (!dirName.isEmpty()) {
771 QByteArray ext = "_A.png";
772 graphWin->savePNG(dirName, ext);
773 }
774 }
775}
776
777// Finish the report
778////////////////////////////////////////////////////////////////////////////
779void t_reqcAnalyze::printReport(const t_rnxObsFile* obsFile) {
780
781 if (!_log) {
782 return;
783 }
784
785 QFileInfo obsFi(obsFile->fileName());
786 QString obsFileName = obsFi.fileName();
787
788 // Summary
789 // -------
790 *_log << "Observation File : " << obsFileName << endl
791 << "RINEX Version : " << QString("%1").arg(obsFile->version(),4,'f',2) << endl
792 << "Marker Name : " << _qcFile._markerName << endl
793 << "Marker Number : " << obsFile->markerNumber() << endl
794 << "Receiver : " << _qcFile._receiverType << endl
795 << "Antenna : " << _qcFile._antennaName << endl
796 << "Position XYZ : " << QString("%1 %2 %3").arg(obsFile->xyz()(1), 14, 'f', 4)
797 .arg(obsFile->xyz()(2), 14, 'f', 4)
798 .arg(obsFile->xyz()(3), 14, 'f', 4) << endl
799 << "Antenna dH/dE/dN : " << QString("%1 %2 %3").arg(obsFile->antNEU()(3), 8, 'f', 4)
800 .arg(obsFile->antNEU()(2), 8, 'f', 4)
801 .arg(obsFile->antNEU()(1), 8, 'f', 4) << endl
802 << "Start Time : " << _qcFile._startTime.datestr().c_str() << ' '
803 << _qcFile._startTime.timestr(1,'.').c_str() << endl
804 << "End Time : " << _qcFile._endTime.datestr().c_str() << ' '
805 << _qcFile._endTime.timestr(1,'.').c_str() << endl
806 << "Interval : " << _qcFile._interval << endl;
807
808 // Number of systems
809 // -----------------
810 QMap<QChar, QVector<const t_qcSatSum*> > systemMap;
811 QMapIterator<t_prn, t_qcSatSum> itSat(_qcFile._qcSatSum);
812 while (itSat.hasNext()) {
813 itSat.next();
814 const t_prn& prn = itSat.key();
815 const t_qcSatSum& qcSatSum = itSat.value();
816 systemMap[prn.system()].push_back(&qcSatSum);
817 }
818
819 *_log << "Navigation Systems: " << systemMap.size() << " ";
820 QMapIterator<QChar, QVector<const t_qcSatSum*> > itSys(systemMap);
821 while (itSys.hasNext()) {
822 itSys.next();
823 *_log << ' ' << itSys.key();
824 }
825 *_log << endl;
826
827 itSys.toFront();
828 while (itSys.hasNext()) {
829 itSys.next();
830 const QChar& sys = itSys.key();
831 const QVector<const t_qcSatSum*>& qcSatVec = itSys.value();
832 QString prefixSys = QString(" ") + sys + QString(": ");
833 QMap<QString, QVector<const t_qcFrqSum*> > frqMap;
834 for (int ii = 0; ii < qcSatVec.size(); ii++) {
835 const t_qcSatSum* qcSatSum = qcSatVec[ii];
836 QMapIterator<QString, t_qcFrqSum> itFrq(qcSatSum->_qcFrqSum);
837 while (itFrq.hasNext()) {
838 itFrq.next();
839 QString frqType = itFrq.key(); if (frqType.length() < 2) frqType += '?';
840 const t_qcFrqSum& qcFrqSum = itFrq.value();
841 frqMap[frqType].push_back(&qcFrqSum);
842 }
843 }
844 *_log << endl
845 << prefixSys << "Satellites: " << qcSatVec.size() << endl
846 << prefixSys << "Signals : " << frqMap.size() << " ";
847 QMapIterator<QString, QVector<const t_qcFrqSum*> > itFrq(frqMap);
848 while (itFrq.hasNext()) {
849 itFrq.next();
850 QString frqType = itFrq.key(); if (frqType.length() < 2) frqType += '?';
851 *_log << ' ' << frqType;
852 }
853 *_log << endl;
854 QString prefixSys2 = " " + prefixSys;
855 itFrq.toFront();
856 while (itFrq.hasNext()) {
857 itFrq.next();
858 QString frqType = itFrq.key(); if (frqType.length() < 2) frqType += '?';
859 const QVector<const t_qcFrqSum*> qcFrqVec = itFrq.value();
860 QString prefixFrq = QString(" ") + frqType + QString(": ");
861
862 int numObs = 0;
863 int numSlipsFlagged = 0;
864 int numSlipsFound = 0;
865 int numGaps = 0;
866 int numSNR = 0;
867 int numMP = 0;
868 double sumSNR = 0.0;
869 double sumMP = 0.0;
870 for (int ii = 0; ii < qcFrqVec.size(); ii++) {
871 const t_qcFrqSum* qcFrqSum = qcFrqVec[ii];
872 numObs += qcFrqSum->_numObs ;
873 numSlipsFlagged += qcFrqSum->_numSlipsFlagged;
874 numSlipsFound += qcFrqSum->_numSlipsFound ;
875 numGaps += qcFrqSum->_numGaps ;
876 numSNR += qcFrqSum->_numSNR;
877 numMP += qcFrqSum->_numMP;
878 sumSNR += qcFrqSum->_sumSNR;
879 sumMP += qcFrqSum->_sumMP;
880 }
881 if (numSNR > 0) {
882 sumSNR /= numSNR;
883 }
884 if (numMP > 0) {
885 sumMP /= numMP;
886 }
887 *_log << endl
888 << prefixSys2 << prefixFrq << "Observations : " << QString("%1\n").arg(numObs, 6)
889 << prefixSys2 << prefixFrq << "Slips (file+found): " << QString("%1 +").arg(numSlipsFlagged, 6)
890 << QString("%1\n").arg(numSlipsFound, 6)
891 << prefixSys2 << prefixFrq << "Gaps : " << QString("%1\n").arg(numGaps, 6)
892 << prefixSys2 << prefixFrq << "Mean SNR : " << QString("%1\n").arg(sumSNR, 6, 'f', 1)
893 << prefixSys2 << prefixFrq << "Mean Multipath : " << QString("%1\n").arg(sumMP, 6, 'f', 2);
894 }
895 }
896
897 // Epoch-Specific Output
898 // ---------------------
899 bncSettings settings;
900 if (Qt::CheckState(settings.value("reqcLogSummaryOnly").toInt()) == Qt::Checked) {
901 return;
902 }
903 *_log << endl;
904 for (int iEpo = 0; iEpo < _qcFile._qcEpo.size(); iEpo++) {
905 const t_qcEpo& qcEpo = _qcFile._qcEpo[iEpo];
906
907 unsigned year, month, day, hour, min;
908 double sec;
909 qcEpo._epoTime.civil_date(year, month, day);
910 qcEpo._epoTime.civil_time(hour, min, sec);
911
912 QString dateStr;
913 QTextStream(&dateStr) << QString("> %1 %2 %3 %4 %5%6")
914 .arg(year, 4)
915 .arg(month, 2, 10, QChar('0'))
916 .arg(day, 2, 10, QChar('0'))
917 .arg(hour, 2, 10, QChar('0'))
918 .arg(min, 2, 10, QChar('0'))
919 .arg(sec, 11, 'f', 7);
920
921 *_log << dateStr << QString(" %1").arg(qcEpo._qcSat.size(), 2)
922 << QString(" %1").arg(qcEpo._PDOP, 4, 'f', 1)
923 << endl;
924
925 QMapIterator<t_prn, t_qcSat> itSat(qcEpo._qcSat);
926 while (itSat.hasNext()) {
927 itSat.next();
928 const t_prn& prn = itSat.key();
929 const t_qcSat& qcSat = itSat.value();
930
931 *_log << prn.toString().c_str()
932 << QString(" %1 %2").arg(qcSat._eleDeg, 6, 'f', 2).arg(qcSat._azDeg, 7, 'f', 2);
933
934 int numObsTypes = 0;
935 for (int iFrq = 0; iFrq < qcSat._qcFrq.size(); iFrq++) {
936 const t_qcFrq& qcFrq = qcSat._qcFrq[iFrq];
937 if (qcFrq._phaseValid) {
938 numObsTypes += 1;
939 }
940 if (qcFrq._codeValid) {
941 numObsTypes += 1;
942 }
943 }
944 *_log << QString(" %1").arg(numObsTypes, 2);
945
946 for (int iFrq = 0; iFrq < qcSat._qcFrq.size(); iFrq++) {
947 const t_qcFrq& qcFrq = qcSat._qcFrq[iFrq];
948 if (qcFrq._phaseValid) {
949 *_log << " L" << qcFrq._rnxType2ch << ' ';
950 if (qcFrq._slip) {
951 *_log << 's';
952 }
953 else {
954 *_log << '.';
955 }
956 if (qcFrq._gap) {
957 *_log << 'g';
958 }
959 else {
960 *_log << '.';
961 }
962 *_log << QString(" %1").arg(qcFrq._SNR, 4, 'f', 1);
963 }
964 if (qcFrq._codeValid) {
965 *_log << " C" << qcFrq._rnxType2ch << ' ';
966 if (qcFrq._gap) {
967 *_log << " g";
968 }
969 else {
970 *_log << " .";
971 }
972 *_log << QString(" %1").arg(qcFrq._stdMP, 3, 'f', 2);
973 }
974 }
975 *_log << endl;
976 }
977 }
978 _log->flush();
979}
980
981//
982////////////////////////////////////////////////////////////////////////////
983void t_reqcAnalyze::checkEphemerides() {
984
985 QString navFileName;
986 QStringListIterator namIt(_navFileNames);
987 bool firstName = true;
988 while (namIt.hasNext()) {
989 QFileInfo navFi(namIt.next());
990 if (firstName) {
991 firstName = false;
992 navFileName += navFi.fileName();
993 }
994 else {
995 navFileName += ", " + navFi.fileName();
996 }
997 }
998
999 *_log << "Navigation File(s): " << navFileName << endl;
1000
1001 QStringListIterator it(_navFileNames);
1002 while (it.hasNext()) {
1003 const QString& fileName = it.next();
1004 unsigned numOK = 0;
1005 unsigned numBad = 0;
1006 bncEphUser ephUser(false);
1007 t_rnxNavFile rnxNavFile(fileName, t_rnxNavFile::input);
1008 for (unsigned ii = 0; ii < rnxNavFile.ephs().size(); ii++) {
1009 t_eph* eph = rnxNavFile.ephs()[ii];
1010 ephUser.putNewEph(eph, true);
1011 if (eph->checkState() == t_eph::bad) {
1012 ++numBad;
1013 }
1014 else {
1015 ++numOK;
1016 }
1017 }
1018 *_log << "Ephemeris : " << numOK << " OK " << numBad << " BAD" << endl;
1019 if (numBad > 0) {
1020 for (unsigned ii = 0; ii < rnxNavFile.ephs().size(); ii++) {
1021 t_eph* eph = rnxNavFile.ephs()[ii];
1022 if (eph->checkState() == t_eph::bad) {
1023 QFileInfo navFi(fileName);
1024 *_log << " Bad Ephemeris : " << navFi.fileName() << ' '
1025 << eph->toString(3.0).left(24) << endl;
1026 }
1027 }
1028 }
1029 }
1030
1031 *_log << endl;
1032}
Note: See TracBrowser for help on using the repository browser.