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

Last change on this file since 4350 was 4350, checked in by mervart, 12 years ago
File size: 8.4 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 << "Analyze 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_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
185 t_satStat& satStat = _satStat[prn];
186
187 satStat.addObs(obs, eph, xyz);
188 }
189
190 } // while (_currEpo)
191
192 // Analyze the Multipath
193 // ---------------------
194 QVector<t_polarPoint*>* dataMP1 = new QVector<t_polarPoint*>;
195 QVector<t_polarPoint*>* dataMP2 = new QVector<t_polarPoint*>;
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();
202 analyzeMultipath(prn, satStat, dataMP1, dataMP2);
203 }
204
205 emit displayGraph(dataMP1, dataMP2);
206
207 _log->flush();
208}
209
210//
211////////////////////////////////////////////////////////////////////////////
212void t_reqcAnalyze::t_satStat::addObs(const t_obs& obs, const t_eph* eph,
213 const ColumnVector& xyz) {
214
215 t_anaObs* newObs = new t_anaObs(obs);
216 anaObs << newObs;
217
218 // Compute the Multipath
219 // ----------------------
220 if (obs.l1() != 0.0 && obs.l2() != 0.0) {
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
227 if (obs.p1() != 0.0) {
228 newObs->MP1 = obs.p1() - L1 - 2.0*f2*f2/(f1*f1-f2*f2) * (L1 - L2);
229 }
230 if (obs.p2() != 0.0) {
231 newObs->MP2 = obs.p2() - L2 - 2.0*f1*f1/(f1*f1-f2*f2) * (L1 - L2);
232 }
233 }
234
235 // Compute the Azimuth and Zenith Distance
236 // ---------------------------------------
237 if (eph && xyz.size()) {
238 double xSat, ySat, zSat, clkSat;
239 eph->position(obs.GPSWeek, obs.GPSWeeks, xSat, ySat, zSat, clkSat);
240
241 double rho, eleSat, azSat;
242 topos(xyz(1), xyz(2), xyz(3), xSat, ySat, zSat, rho, eleSat, azSat);
243
244 newObs->az = azSat * 180.0/M_PI;
245 newObs->zen = 90.0 - eleSat * 180.0/M_PI;
246 }
247}
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
256 int numVal = satStat.anaObs.size();
257 if (numVal < 2) {
258 return;
259 }
260
261 double mean1 = 0.0;
262 double mean2 = 0.0;
263 for (int ii = 0; ii < numVal; ii++) {
264 const t_anaObs* anaObs = satStat.anaObs[ii];
265 mean1 += anaObs->MP1;
266 mean2 += anaObs->MP2;
267 }
268 mean1 /= numVal;
269 mean2 /= numVal;
270 double stddev1 = 0.0;
271 double stddev2 = 0.0;
272 for (int ii = 0; ii < numVal; ii++) {
273 const t_anaObs* anaObs = satStat.anaObs[ii];
274 double diff1 = anaObs->MP1 - mean1;
275 double diff2 = anaObs->MP2 - mean2;
276 stddev1 += diff1 * diff1;
277 stddev2 += diff2 * diff2;
278 //// beg test
279 double bla = anaObs->zen/90.0;
280 (*dataMP1) << (new t_polarPoint(anaObs->az, anaObs->zen, bla));
281 (*dataMP2) << (new t_polarPoint(anaObs->az, anaObs->zen, bla));
282 //// end test
283 }
284 double MP1 = sqrt(stddev1 / (numVal-1));
285 double MP2 = sqrt(stddev2 / (numVal-1));
286
287 _log->setRealNumberNotation(QTextStream::FixedNotation);
288 _log->setRealNumberPrecision(2);
289
290 *_log << "MP1 " << prn << " " << MP1 << endl;
291 *_log << "MP2 " << prn << " " << MP2 << endl;
292}
Note: See TracBrowser for help on using the repository browser.