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

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