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

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