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

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