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

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