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

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