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

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