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

Last change on this file since 4352 was 4352, checked in by mervart, 12 years ago
File size: 8.9 KB
RevLine 
[3899]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"
[3973]43#include "bncapp.h"
[3899]44#include "bncsettings.h"
[4254]45#include "reqcedit.h"
[4255]46#include "bncutils.h"
[4262]47#include "bncpostprocess.h"
[4300]48#include "graphwin.h"
[4307]49#include "polarplot.h"
[3899]50
51using namespace std;
52
53// Constructor
54////////////////////////////////////////////////////////////////////////////
55t_reqcAnalyze::t_reqcAnalyze(QObject* parent) : QThread(parent) {
56
57 bncSettings settings;
[4254]58
[4257]59 _logFileName = settings.value("reqcOutLogFile").toString(); expandEnvVar(_logFileName);
60 _logFile = 0;
61 _log = 0;
[4254]62 _obsFileNames = settings.value("reqcObsFile").toString().split(",", QString::SkipEmptyParts);
[4257]63 _navFileNames = settings.value("reqcNavFile").toString().split(",", QString::SkipEmptyParts);
[4266]64
65 _currEpo = 0;
[4300]66
[4342]67 connect(this, SIGNAL(displayGraph(QVector<t_polarPoint*>*, QVector<t_polarPoint*>*)),
68 this, SLOT(slotDisplayGraph(QVector<t_polarPoint*>*, QVector<t_polarPoint*>*)));
[3899]69}
70
71// Destructor
72////////////////////////////////////////////////////////////////////////////
73t_reqcAnalyze::~t_reqcAnalyze() {
[4255]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;
[3899]82}
83
84//
85////////////////////////////////////////////////////////////////////////////
[4342]86void t_reqcAnalyze::slotDisplayGraph(QVector<t_polarPoint*>* dataMP1,
87 QVector<t_polarPoint*>* dataMP2) {
88
[4346]89 bncApp* app = dynamic_cast<bncApp*>(qApp);
90 if (app->mode() == bncApp::interactive) {
[4334]91
[4346]92 t_polarPlot* plotMP1 = new t_polarPlot(QwtText("MP1"), app->mainWindow());
[4342]93 plotMP1->addCurve(dataMP1);
[4334]94
[4346]95 t_polarPlot* plotMP2 = new t_polarPlot(QwtText("MP2"), app->mainWindow());
[4342]96 plotMP2->addCurve(dataMP2);
[4334]97
[4310]98 QVector<QWidget*> plots;
[4334]99 plots << plotMP1;
100 plots << plotMP2;
101
[4308]102 t_graphWin* graphWin = new t_graphWin(0, plots);
[4334]103
[4347]104 graphWin->show();
[4308]105 }
[4300]106}
107
108//
109////////////////////////////////////////////////////////////////////////////
[3899]110void t_reqcAnalyze::run() {
111
[4255]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 // ----------------------------------
[4254]121 t_reqcEdit::initRnxObsFiles(_obsFileNames, _rnxObsFiles);
[3899]122
[4257]123 // Read Ephemerides
124 // ----------------
125 t_reqcEdit::readEphemerides(_navFileNames, _ephs);
126
[4255]127 // Loop over all RINEX Files
128 // -------------------------
[4254]129 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
130 analyzeFile(_rnxObsFiles[ii]);
131 }
132
[4255]133 // Exit
134 // ----
[3973]135 bncApp* app = (bncApp*) qApp;
136 if ( app->mode() != bncApp::interactive) {
137 app->exit(0);
138 }
139 else {
140 emit finished();
141 deleteLater();
142 }
[3899]143}
[4254]144
145//
146////////////////////////////////////////////////////////////////////////////
[4260]147void t_reqcAnalyze::analyzeFile(t_rnxObsFile* obsFile) {
[4259]148
[4352]149 *_log << "\nAnalyze File\n"
150 << "------------\n"
[4260]151 << obsFile->fileName().toAscii().data() << endl << endl;
152
[4343]153 _satStat.clear();
154
[4342]155 // A priori Coordinates
156 // --------------------
157 ColumnVector xyz = obsFile->xyz();
158
[4262]159 // Loop over all Epochs
160 // --------------------
[4266]161 while ( (_currEpo = obsFile->nextEpoch()) != 0) {
[4260]162
[4262]163 // Loop over all satellites
164 // ------------------------
[4266]165 for (unsigned iObs = 0; iObs < _currEpo->rnxSat.size(); iObs++) {
166 const t_rnxObsFile::t_rnxSat& rnxSat = _currEpo->rnxSat[iObs];
[4262]167 t_obs obs;
[4266]168 t_postProcessing::setObsFromRnx(obsFile, _currEpo, rnxSat, obs);
[4260]169
[4262]170 if (obs.satSys == 'R') {
[4266]171 continue; // TODO: set channel number
[4262]172 }
173
[4263]174 QString prn = QString("%1%2").arg(obs.satSys)
175 .arg(obs.satNum, 2, 10, QChar('0'));
[4266]176
[4338]177 t_eph* eph = 0;
178 for (int ie = 0; ie < _ephs.size(); ie++) {
179 if (_ephs[ie]->prn() == prn) {
180 eph = _ephs[ie];
181 break;
182 }
183 }
184
[4268]185 t_satStat& satStat = _satStat[prn];
[4338]186
[4342]187 satStat.addObs(obs, eph, xyz);
[4262]188 }
189
[4266]190 } // while (_currEpo)
[4262]191
[4268]192 // Analyze the Multipath
193 // ---------------------
[4350]194 QVector<t_polarPoint*>* dataMP1 = new QVector<t_polarPoint*>;
195 QVector<t_polarPoint*>* dataMP2 = new QVector<t_polarPoint*>;
[4268]196
197 QMapIterator<QString, t_satStat> it(_satStat);
198 while (it.hasNext()) {
199 it.next();
200 QString prn = it.key();
201 const t_satStat& satStat = it.value();
[4350]202 analyzeMultipath(prn, satStat, dataMP1, dataMP2);
[4268]203 }
204
[4342]205 emit displayGraph(dataMP1, dataMP2);
[4300]206
[4259]207 _log->flush();
[4254]208}
[4263]209
210//
211////////////////////////////////////////////////////////////////////////////
[4342]212void t_reqcAnalyze::t_satStat::addObs(const t_obs& obs, const t_eph* eph,
213 const ColumnVector& xyz) {
[4265]214
[4338]215 t_anaObs* newObs = new t_anaObs(obs);
216 anaObs << newObs;
217
[4268]218 // Compute the Multipath
219 // ----------------------
220 if (obs.l1() != 0.0 && obs.l2() != 0.0) {
[4266]221 double f1 = t_CST::f1(obs.satSys, obs.slotNum);
222 double f2 = t_CST::f2(obs.satSys, obs.slotNum);
223
224 double L1 = obs.l1() * t_CST::c / f1;
225 double L2 = obs.l2() * t_CST::c / f2;
226
[4268]227 if (obs.p1() != 0.0) {
[4338]228 newObs->MP1 = obs.p1() - L1 - 2.0*f2*f2/(f1*f1-f2*f2) * (L1 - L2);
[4268]229 }
230 if (obs.p2() != 0.0) {
[4338]231 newObs->MP2 = obs.p2() - L2 - 2.0*f1*f1/(f1*f1-f2*f2) * (L1 - L2);
[4268]232 }
[4265]233 }
[4338]234
235 // Compute the Azimuth and Zenith Distance
236 // ---------------------------------------
[4342]237 if (eph && xyz.size()) {
[4339]238 double xSat, ySat, zSat, clkSat;
239 eph->position(obs.GPSWeek, obs.GPSWeeks, xSat, ySat, zSat, clkSat);
[4340]240
241 double rho, eleSat, azSat;
[4342]242 topos(xyz(1), xyz(2), xyz(3), xSat, ySat, zSat, rho, eleSat, azSat);
[4341]243
244 newObs->az = azSat * 180.0/M_PI;
245 newObs->zen = 90.0 - eleSat * 180.0/M_PI;
[4338]246 }
[4263]247}
[4350]248
249//
250////////////////////////////////////////////////////////////////////////////
251void t_reqcAnalyze::analyzeMultipath(const QString& prn,
252 const t_satStat& satStat,
253 QVector<t_polarPoint*>* dataMP1,
254 QVector<t_polarPoint*>* dataMP2) {
255
[4352]256 const int LENGTH = 10; // number of epochs in one chunk
[4350]257
[4351]258 int numEpo = satStat.anaObs.size();
259
260 for (int chunkStart = 0; chunkStart + LENGTH < numEpo; chunkStart += LENGTH) {
261
262 // Compute Mean
263 // ------------
264 double mean1 = 0.0;
265 double mean2 = 0.0;
266 for (int ii = 0; ii < LENGTH; ii++) {
267 int iEpo = chunkStart + ii;
268 const t_anaObs* anaObs = satStat.anaObs[iEpo];
269 mean1 += anaObs->MP1;
270 mean2 += anaObs->MP2;
271 }
272 mean1 /= LENGTH;
273 mean2 /= LENGTH;
274
275 // Compute Standard Deviation
276 // --------------------------
277 double stddev1 = 0.0;
278 double stddev2 = 0.0;
279 for (int ii = 0; ii < LENGTH; ii++) {
280 int iEpo = chunkStart + ii;
281 const t_anaObs* anaObs = satStat.anaObs[iEpo];
282 double diff1 = anaObs->MP1 - mean1;
283 double diff2 = anaObs->MP2 - mean2;
284 stddev1 += diff1 * diff1;
285 stddev2 += diff2 * diff2;
286 }
287 double MP1 = sqrt(stddev1 / (LENGTH-1));
288 double MP2 = sqrt(stddev2 / (LENGTH-1));
289
290 const t_anaObs* anaObs = satStat.anaObs[chunkStart];
291 (*dataMP1) << (new t_polarPoint(anaObs->az, anaObs->zen, MP1));
292 (*dataMP2) << (new t_polarPoint(anaObs->az, anaObs->zen, MP2));
293
294 _log->setRealNumberNotation(QTextStream::FixedNotation);
295 _log->setRealNumberPrecision(2);
[4352]296 *_log << "MP1 " << prn << " " << anaObs->az << " " << anaObs->zen << " "
297 << MP1 << endl;
298 *_log << "MP2 " << prn << " " << anaObs->az << " " << anaObs->zen << " "
299 << MP2 << endl;
[4350]300 }
301}
Note: See TracBrowser for help on using the repository browser.