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

Last change on this file since 4541 was 4541, checked in by mervart, 12 years ago
File size: 11.4 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 "reqcanalyze.h"
44#include "bncapp.h"
45#include "bncsettings.h"
46#include "reqcedit.h"
47#include "bncutils.h"
48#include "bncpostprocess.h"
49#include "graphwin.h"
50#include "polarplot.h"
51
52using namespace std;
53
54const double SLIPTRESH = 5.0; // cycle-slip threshold (meters)
55
56// Constructor
57////////////////////////////////////////////////////////////////////////////
58t_reqcAnalyze::t_reqcAnalyze(QObject* parent) : QThread(parent) {
59
60 bncSettings settings;
61
62 _logFileName = settings.value("reqcOutLogFile").toString(); expandEnvVar(_logFileName);
63 _logFile = 0;
64 _log = 0;
65 _obsFileNames = settings.value("reqcObsFile").toString().split(",", QString::SkipEmptyParts);
66 _navFileNames = settings.value("reqcNavFile").toString().split(",", QString::SkipEmptyParts);
67
68 _currEpo = 0;
69
70 connect(this, SIGNAL(displayGraph(const QString&, QVector<t_polarPoint*>*, QVector<t_polarPoint*>*)),
71 this, SLOT(slotDisplayGraph(const QString&, QVector<t_polarPoint*>*, QVector<t_polarPoint*>*)));
72}
73
74// Destructor
75////////////////////////////////////////////////////////////////////////////
76t_reqcAnalyze::~t_reqcAnalyze() {
77 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
78 delete _rnxObsFiles[ii];
79 }
80 for (int ii = 0; ii < _ephs.size(); ii++) {
81 delete _ephs[ii];
82 }
83 delete _log; _log = 0;
84 delete _logFile; _logFile = 0;
85 bncApp* app = (bncApp*) qApp;
86 if ( app->mode() != bncApp::interactive) {
87 app->exit(0);
88 }
89}
90
91//
92////////////////////////////////////////////////////////////////////////////
93void t_reqcAnalyze::slotDisplayGraph(const QString& fileName,
94 QVector<t_polarPoint*>* dataMP1,
95 QVector<t_polarPoint*>* dataMP2) {
96
97 bncApp* app = dynamic_cast<bncApp*>(qApp);
98 if (app->GUIenabled()) {
99
100 double maxMP = 0.0;
101 for (int ii = 0; ii < dataMP1->size(); ii++) {
102 double mp = dataMP1->at(ii)->_value;
103 if (maxMP < mp) {
104 maxMP = mp;
105 }
106 }
107 for (int ii = 0; ii < dataMP2->size(); ii++) {
108 double mp = dataMP2->at(ii)->_value;
109 if (maxMP < mp) {
110 maxMP = mp;
111 }
112 }
113 if (maxMP > SLIPTRESH) {
114 maxMP = SLIPTRESH;
115 }
116
117 //// beg test
118 maxMP = 2.0;
119 //// end test
120
121 QwtInterval scaleInterval(0.0, maxMP);
122
123 t_polarPlot* plotMP1 = new t_polarPlot(QwtText("MP1"), scaleInterval,
124 app->mainWindow());
125 plotMP1->addCurve(dataMP1);
126
127 t_polarPlot* plotMP2 = new t_polarPlot(QwtText("MP2"), scaleInterval,
128 app->mainWindow());
129 plotMP2->addCurve(dataMP2);
130
131 QVector<QWidget*> plots;
132 plots << plotMP1;
133 plots << plotMP2;
134
135 t_graphWin* graphWin = new t_graphWin(0, fileName, plots, scaleInterval);
136
137 graphWin->show();
138
139 bncSettings settings;
140 QString dirName = settings.value("reqcPlotDir").toString();
141 if (!dirName.isEmpty()) {
142 graphWin->savePNG(dirName);
143 }
144 }
145}
146
147//
148////////////////////////////////////////////////////////////////////////////
149void t_reqcAnalyze::run() {
150
151 // Open Log File
152 // -------------
153 _logFile = new QFile(_logFileName);
154 if (_logFile->open(QIODevice::WriteOnly | QIODevice::Text)) {
155 _log = new QTextStream();
156 _log->setDevice(_logFile);
157 }
158
159 // Initialize RINEX Observation Files
160 // ----------------------------------
161 t_reqcEdit::initRnxObsFiles(_obsFileNames, _rnxObsFiles, _log);
162
163 // Read Ephemerides
164 // ----------------
165 t_reqcEdit::readEphemerides(_navFileNames, _ephs);
166
167 // Loop over all RINEX Files
168 // -------------------------
169 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
170 analyzeFile(_rnxObsFiles[ii]);
171 }
172
173 // Exit
174 // ----
175 emit finished();
176 deleteLater();
177}
178
179//
180////////////////////////////////////////////////////////////////////////////
181void t_reqcAnalyze::analyzeFile(t_rnxObsFile* obsFile) {
182
183 if (_log) {
184 *_log << "\nAnalyze File\n"
185 << "------------\n"
186 << obsFile->fileName().toAscii().data() << endl << endl;
187 }
188
189 _satStat.clear();
190
191 // A priori Coordinates
192 // --------------------
193 ColumnVector xyz = obsFile->xyz();
194
195 // Loop over all Epochs
196 // --------------------
197 try {
198 while ( (_currEpo = obsFile->nextEpoch()) != 0) {
199
200 // Loop over all satellites
201 // ------------------------
202 for (unsigned iObs = 0; iObs < _currEpo->rnxSat.size(); iObs++) {
203 const t_rnxObsFile::t_rnxSat& rnxSat = _currEpo->rnxSat[iObs];
204 t_obs obs;
205 t_postProcessing::setObsFromRnx(obsFile, _currEpo, rnxSat, obs);
206
207 if (obs.satSys == 'R') {
208 continue; // TODO: set channel number
209 }
210
211 QString prn = QString("%1%2").arg(obs.satSys)
212 .arg(obs.satNum, 2, 10, QChar('0'));
213
214 t_satStat& satStat = _satStat[prn];
215
216 satStat.addObs(obs);
217 }
218
219 } // while (_currEpo)
220 }
221 catch (QString str) {
222 if (_log) {
223 *_log << "Exception " << str << endl;
224 }
225 else {
226 qDebug() << str;
227 }
228 return;
229 }
230
231 // Analyze the Multipath
232 // ---------------------
233 QVector<t_polarPoint*>* dataMP1 = new QVector<t_polarPoint*>;
234 QVector<t_polarPoint*>* dataMP2 = new QVector<t_polarPoint*>;
235
236 QMapIterator<QString, t_satStat> it(_satStat);
237 while (it.hasNext()) {
238 it.next();
239 QString prn = it.key();
240 const t_satStat& satStat = it.value();
241 analyzeMultipath(prn, satStat, xyz, obsFile->interval(), dataMP1, dataMP2);
242 }
243
244 emit displayGraph(obsFile->fileName(), dataMP1, dataMP2);
245
246 if (_log) {
247 _log->flush();
248 }
249}
250
251//
252////////////////////////////////////////////////////////////////////////////
253void t_reqcAnalyze::t_satStat::addObs(const t_obs& obs) {
254
255 t_anaObs* newObs = new t_anaObs(obs.GPSWeek, obs.GPSWeeks);
256 bool okFlag = false;
257
258 // Compute the Multipath
259 // ----------------------
260 double L1 = obs.measdata("L1", 3.0);
261 double L2 = obs.measdata("L2", 3.0);
262 if (L1 != 0.0 && L2 != 0.0) {
263 double f1 = t_CST::f1(obs.satSys, obs.slotNum);
264 double f2 = t_CST::f2(obs.satSys, obs.slotNum);
265
266 L1 = L1 * t_CST::c / f1;
267 L2 = L2 * t_CST::c / f2;
268
269 double P1 = obs.measdata("C1", 3.0);
270 if (P1 != 0.0) {
271 newObs->_MP1 = P1 - L1 - 2.0*f2*f2/(f1*f1-f2*f2) * (L1 - L2);
272 okFlag = true;
273
274 //// beg test
275 // cout.setf(ios::fixed);
276 // cout << obs.satSys << setw(2) << obs.satNum << " "
277 // << setprecision(1) << obs.GPSWeeks << " "
278 // << setprecision(4) << newObs->_MP1 << endl;
279 //// end test
280 }
281 double P2 = obs.measdata("C2", 3.0);
282 if (P2 != 0.0) {
283 newObs->_MP2 = P2 - L2 - 2.0*f1*f1/(f1*f1-f2*f2) * (L1 - L2);
284 okFlag = true;
285 }
286 }
287
288 // Remember the Observation
289 // ------------------------
290 if (okFlag) {
291 anaObs << newObs;
292 }
293 else {
294 delete newObs;
295 }
296}
297
298//
299////////////////////////////////////////////////////////////////////////////
300void t_reqcAnalyze::analyzeMultipath(const QString& prn,
301 const t_satStat& satStat,
302 const ColumnVector& xyz,
303 double obsInterval,
304 QVector<t_polarPoint*>* dataMP1,
305 QVector<t_polarPoint*>* dataMP2) {
306
307 const int chunkStep = 30.0 / obsInterval; // chunk step (30 sec)
308 const int numEpo = 600.0 / obsInterval; // # epochs in one chunk (10 min)
309
310 for (int chunkStart = 0; chunkStart + numEpo < satStat.anaObs.size();
311 chunkStart += chunkStep) {
312
313 // Compute Mean
314 // ------------
315 bool slipFlag = false;
316 double mean1 = 0.0;
317 double mean2 = 0.0;
318
319 for (int ii = 0; ii < numEpo; ii++) {
320 int iEpo = chunkStart + ii;
321 const t_anaObs* anaObs = satStat.anaObs[iEpo];
322 mean1 += anaObs->_MP1;
323 mean2 += anaObs->_MP2;
324
325 // Check Slip
326 // ----------
327 if (ii > 0) {
328 double diff1 = anaObs->_MP1 - satStat.anaObs[iEpo-1]->_MP1;
329 double diff2 = anaObs->_MP2 - satStat.anaObs[iEpo-1]->_MP2;
330 if (fabs(diff1) > SLIPTRESH || fabs(diff2) > SLIPTRESH) {
331 slipFlag = true;
332 break;
333 }
334 }
335 }
336
337 if (slipFlag) {
338 continue;
339 }
340
341 mean1 /= numEpo;
342 mean2 /= numEpo;
343
344 // Compute Standard Deviation
345 // --------------------------
346 double stddev1 = 0.0;
347 double stddev2 = 0.0;
348 for (int ii = 0; ii < numEpo; ii++) {
349 int iEpo = chunkStart + ii;
350 const t_anaObs* anaObs = satStat.anaObs[iEpo];
351 double diff1 = anaObs->_MP1 - mean1;
352 double diff2 = anaObs->_MP2 - mean2;
353 stddev1 += diff1 * diff1;
354 stddev2 += diff2 * diff2;
355 }
356 double MP1 = sqrt(stddev1 / (numEpo-1));
357 double MP2 = sqrt(stddev2 / (numEpo-1));
358
359 const t_anaObs* anaObs0 = satStat.anaObs[chunkStart];
360
361 // Compute the Azimuth and Zenith Distance
362 // ---------------------------------------
363 double az = 0.0;
364 double zen = 0.0;
365 if (xyz.size()) {
366 t_eph* eph = 0;
367 for (int ie = 0; ie < _ephs.size(); ie++) {
368 if (_ephs[ie]->prn() == prn) {
369 eph = _ephs[ie];
370 break;
371 }
372 }
373
374 if (eph) {
375 double xSat, ySat, zSat, clkSat;
376 eph->position(anaObs0->_GPSWeek, anaObs0->_GPSWeeks,
377 xSat, ySat, zSat, clkSat);
378
379 double rho, eleSat, azSat;
380 topos(xyz(1), xyz(2), xyz(3), xSat, ySat, zSat, rho, eleSat, azSat);
381
382 az = azSat * 180.0/M_PI;
383 zen = 90.0 - eleSat * 180.0/M_PI;
384 }
385 }
386
387 // Add new Point
388 // -------------
389 (*dataMP1) << (new t_polarPoint(az, zen, MP1));
390 (*dataMP2) << (new t_polarPoint(az, zen, MP2));
391
392 if (_log) {
393 _log->setRealNumberNotation(QTextStream::FixedNotation);
394
395 _log->setRealNumberPrecision(2);
396 *_log << "MP1 " << prn << " " << az << " " << zen << " ";
397 _log->setRealNumberPrecision(3);
398 *_log << MP1 << endl;
399
400 _log->setRealNumberPrecision(2);
401 *_log << "MP2 " << prn << " " << az << " " << zen << " ";
402 _log->setRealNumberPrecision(3);
403 *_log << MP2 << endl;
404
405 _log->flush();
406 }
407 }
408}
Note: See TracBrowser for help on using the repository browser.