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

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