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

Last change on this file since 4334 was 4334, checked in by mervart, 12 years ago
File size: 7.9 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()), this, SLOT(slotDisplayGraph()));
68}
69
70// Destructor
71////////////////////////////////////////////////////////////////////////////
72t_reqcAnalyze::~t_reqcAnalyze() {
73 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
74 delete _rnxObsFiles[ii];
75 }
76 for (int ii = 0; ii < _ephs.size(); ii++) {
77 delete _ephs[ii];
78 }
79 delete _log; _log = 0;
80 delete _logFile; _logFile = 0;
81}
82
83//
84////////////////////////////////////////////////////////////////////////////
85void t_reqcAnalyze::slotDisplayGraph() {
86 if (((bncApp*) qApp)->mode() == bncApp::interactive) {
87
88 QVector<t_polarPoint*>* data1 = new QVector<t_polarPoint*>;
89
90 //// beg test
91 {
92 const QwtInterval zenithInterval(0.0, 90.0);
93 const QwtInterval azimuthInterval(0.0, 360.0 );
94 const int numPoints = 1000;
95 const double stepA = 4 * azimuthInterval.width() / numPoints;
96 const double stepR = zenithInterval.width() / numPoints;
97 for (int ii = 0; ii < numPoints; ii++) {
98 double aa = azimuthInterval.minValue() + ii * stepA;
99 double rr = zenithInterval.minValue() + ii * stepR;
100 double vv = static_cast<double>(ii) / numPoints;
101 (*data1) << (new t_polarPoint(aa, rr, vv));
102 }
103 }
104 //// end test
105
106 t_polarPlot* plotMP1 = new t_polarPlot(0);
107 plotMP1->addCurve(data1);
108
109 QVector<t_polarPoint*>* data2 = new QVector<t_polarPoint*>;
110
111 //// beg test
112 {
113 const QwtInterval zenithInterval(0.0, 90.0);
114 const QwtInterval azimuthInterval(0.0, 360.0 );
115 const int numPoints = 1000;
116 const double stepA = 4 * azimuthInterval.width() / numPoints;
117 const double stepR = zenithInterval.width() / numPoints;
118 for (int ii = 0; ii < numPoints; ii++) {
119 double aa = azimuthInterval.minValue() + ii * stepA;
120 double rr = zenithInterval.minValue() + ii * stepR;
121 double vv = static_cast<double>(ii) / numPoints;
122 (*data2) << (new t_polarPoint(aa, rr, vv));
123 }
124 }
125 //// end test
126
127 t_polarPlot* plotMP2 = new t_polarPlot(0);
128 plotMP2->addCurve(data2);
129
130 QVector<QWidget*> plots;
131 plots << plotMP1;
132 plots << plotMP2;
133
134 t_graphWin* graphWin = new t_graphWin(0, plots);
135
136 graphWin->show();
137 }
138}
139
140//
141////////////////////////////////////////////////////////////////////////////
142void t_reqcAnalyze::run() {
143
144 // Open Log File
145 // -------------
146 _logFile = new QFile(_logFileName);
147 _logFile->open(QIODevice::WriteOnly | QIODevice::Text);
148 _log = new QTextStream();
149 _log->setDevice(_logFile);
150
151 // Initialize RINEX Observation Files
152 // ----------------------------------
153 t_reqcEdit::initRnxObsFiles(_obsFileNames, _rnxObsFiles);
154
155 // Read Ephemerides
156 // ----------------
157 t_reqcEdit::readEphemerides(_navFileNames, _ephs);
158
159 // Loop over all RINEX Files
160 // -------------------------
161 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
162 analyzeFile(_rnxObsFiles[ii]);
163 }
164
165 // Exit
166 // ----
167 bncApp* app = (bncApp*) qApp;
168 if ( app->mode() != bncApp::interactive) {
169 app->exit(0);
170 }
171 else {
172 emit finished();
173 deleteLater();
174 }
175}
176
177//
178////////////////////////////////////////////////////////////////////////////
179void t_reqcAnalyze::analyzeFile(t_rnxObsFile* obsFile) {
180
181 *_log << "Analyze File\n"
182 << "------------\n"
183 << obsFile->fileName().toAscii().data() << endl << endl;
184
185 // Loop over all Epochs
186 // --------------------
187 while ( (_currEpo = obsFile->nextEpoch()) != 0) {
188
189 // Loop over all satellites
190 // ------------------------
191 for (unsigned iObs = 0; iObs < _currEpo->rnxSat.size(); iObs++) {
192 const t_rnxObsFile::t_rnxSat& rnxSat = _currEpo->rnxSat[iObs];
193 t_obs obs;
194 t_postProcessing::setObsFromRnx(obsFile, _currEpo, rnxSat, obs);
195
196 if (obs.satSys == 'R') {
197 continue; // TODO: set channel number
198 }
199
200 QString prn = QString("%1%2").arg(obs.satSys)
201 .arg(obs.satNum, 2, 10, QChar('0'));
202
203 t_satStat& satStat = _satStat[prn];
204 satStat.addObs(obs);
205 }
206
207 } // while (_currEpo)
208
209 // Analyze the Multipath
210 // ---------------------
211 _log->setRealNumberNotation(QTextStream::FixedNotation);
212 _log->setRealNumberPrecision(2);
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
220 for (int im = 1; im <= 2; im++) {
221 const QVector<double>& MP = (im == 1) ? satStat.MP1 : satStat.MP2;
222 if (MP.size() > 1) {
223 double mean = 0.0;
224 for (int ii = 0; ii < MP.size(); ii++) {
225 mean += MP[ii];
226 }
227 mean /= MP.size();
228 double stddev = 0.0;
229 for (int ii = 0; ii < MP.size(); ii++) {
230 double diff = MP[ii] - mean;
231 stddev += diff * diff;
232 }
233 double multipath = sqrt(stddev / (MP.size()-1));
234
235 *_log << "MP" << im << " " << prn << " " << multipath << endl;
236 }
237 }
238
239 }
240
241 emit displayGraph();
242
243 _log->flush();
244}
245
246//
247////////////////////////////////////////////////////////////////////////////
248void t_reqcAnalyze::t_satStat::addObs(const t_obs& obs) {
249 if (currObs) {
250 delete prevObs;
251 prevObs = currObs;
252 }
253 currObs = new t_anaObs(obs);
254
255 // Compute the Multipath
256 // ----------------------
257 if (obs.l1() != 0.0 && obs.l2() != 0.0) {
258 double f1 = t_CST::f1(obs.satSys, obs.slotNum);
259 double f2 = t_CST::f2(obs.satSys, obs.slotNum);
260
261 double L1 = obs.l1() * t_CST::c / f1;
262 double L2 = obs.l2() * t_CST::c / f2;
263
264 if (obs.p1() != 0.0) {
265 currObs->M1 = obs.p1() - L1 - 2.0*f2*f2/(f1*f1-f2*f2) * (L1 - L2);
266 MP1 << currObs->M1;
267 }
268 if (obs.p2() != 0.0) {
269 currObs->M2 = obs.p2() - L2 - 2.0*f1*f1/(f1*f1-f2*f2) * (L1 - L2);
270 MP2 << currObs->M2;
271 }
272 }
273}
Note: See TracBrowser for help on using the repository browser.