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

Last change on this file since 4344 was 4344, checked in by mervart, 12 years ago
File size: 8.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 "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 if (((bncApp*) qApp)->mode() == bncApp::interactive) {
90
91 t_polarPlot* plotMP1 = new t_polarPlot(0);
92 plotMP1->addCurve(dataMP1);
93
94 t_polarPlot* plotMP2 = new t_polarPlot(0);
95 plotMP2->addCurve(dataMP2);
96
97 QVector<QWidget*> plots;
98 plots << plotMP1;
99 plots << plotMP2;
100
101 t_graphWin* graphWin = new t_graphWin(0, plots);
102
103 graphWin->show();
104 }
105}
106
107//
108////////////////////////////////////////////////////////////////////////////
109void t_reqcAnalyze::run() {
110
111 // Open Log File
112 // -------------
113 _logFile = new QFile(_logFileName);
114 _logFile->open(QIODevice::WriteOnly | QIODevice::Text);
115 _log = new QTextStream();
116 _log->setDevice(_logFile);
117
118 // Initialize RINEX Observation Files
119 // ----------------------------------
120 t_reqcEdit::initRnxObsFiles(_obsFileNames, _rnxObsFiles);
121
122 // Read Ephemerides
123 // ----------------
124 t_reqcEdit::readEphemerides(_navFileNames, _ephs);
125
126 // Loop over all RINEX Files
127 // -------------------------
128 for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
129 analyzeFile(_rnxObsFiles[ii]);
130 }
131
132 // Exit
133 // ----
134 bncApp* app = (bncApp*) qApp;
135 if ( app->mode() != bncApp::interactive) {
136 app->exit(0);
137 }
138 else {
139 emit finished();
140 deleteLater();
141 }
142}
143
144//
145////////////////////////////////////////////////////////////////////////////
146void t_reqcAnalyze::analyzeFile(t_rnxObsFile* obsFile) {
147
148 *_log << "Analyze File\n"
149 << "------------\n"
150 << obsFile->fileName().toAscii().data() << endl << endl;
151
152 _satStat.clear();
153
154 // A priori Coordinates
155 // --------------------
156 ColumnVector xyz = obsFile->xyz();
157
158 // Loop over all Epochs
159 // --------------------
160 while ( (_currEpo = obsFile->nextEpoch()) != 0) {
161
162 // Loop over all satellites
163 // ------------------------
164 for (unsigned iObs = 0; iObs < _currEpo->rnxSat.size(); iObs++) {
165 const t_rnxObsFile::t_rnxSat& rnxSat = _currEpo->rnxSat[iObs];
166 t_obs obs;
167 t_postProcessing::setObsFromRnx(obsFile, _currEpo, rnxSat, obs);
168
169 if (obs.satSys == 'R') {
170 continue; // TODO: set channel number
171 }
172
173 QString prn = QString("%1%2").arg(obs.satSys)
174 .arg(obs.satNum, 2, 10, QChar('0'));
175
176 t_eph* eph = 0;
177 for (int ie = 0; ie < _ephs.size(); ie++) {
178 if (_ephs[ie]->prn() == prn) {
179 eph = _ephs[ie];
180 break;
181 }
182 }
183
184 t_satStat& satStat = _satStat[prn];
185
186 satStat.addObs(obs, eph, xyz);
187 }
188
189 } // while (_currEpo)
190
191 // Analyze the Multipath
192 // ---------------------
193 _log->setRealNumberNotation(QTextStream::FixedNotation);
194 _log->setRealNumberPrecision(2);
195
196 QVector<t_polarPoint*>* dataMP1 = new QVector<t_polarPoint*>;
197 QVector<t_polarPoint*>* dataMP2 = new QVector<t_polarPoint*>;
198
199 QMapIterator<QString, t_satStat> it(_satStat);
200 while (it.hasNext()) {
201 it.next();
202 QString prn = it.key();
203 const t_satStat& satStat = it.value();
204
205 int numVal = satStat.anaObs.size();
206 if (numVal > 1) {
207 double mean1 = 0.0;
208 double mean2 = 0.0;
209 for (int ii = 0; ii < numVal; ii++) {
210 const t_anaObs* anaObs = satStat.anaObs[ii];
211 mean1 += anaObs->MP1;
212 mean2 += anaObs->MP2;
213 }
214 mean1 /= numVal;
215 mean2 /= numVal;
216 double stddev1 = 0.0;
217 double stddev2 = 0.0;
218 for (int ii = 0; ii < numVal; ii++) {
219 const t_anaObs* anaObs = satStat.anaObs[ii];
220 double diff1 = anaObs->MP1 - mean1;
221 double diff2 = anaObs->MP2 - mean2;
222 stddev1 += diff1 * diff1;
223 stddev2 += diff2 * diff2;
224 //// beg test
225 double bla = anaObs->zen/90.0;
226 (*dataMP1) << (new t_polarPoint(anaObs->az, anaObs->zen, bla));
227 (*dataMP2) << (new t_polarPoint(anaObs->az, anaObs->zen, bla));
228 //// end test
229 }
230 double MP1 = sqrt(stddev1 / (numVal-1));
231 double MP2 = sqrt(stddev2 / (numVal-1));
232
233 *_log << "MP1 " << prn << " " << MP1 << endl;
234 *_log << "MP2 " << prn << " " << MP2 << endl;
235 }
236 }
237
238 emit displayGraph(dataMP1, dataMP2);
239
240 _log->flush();
241}
242
243//
244////////////////////////////////////////////////////////////////////////////
245void t_reqcAnalyze::t_satStat::addObs(const t_obs& obs, const t_eph* eph,
246 const ColumnVector& xyz) {
247
248 t_anaObs* newObs = new t_anaObs(obs);
249 anaObs << newObs;
250
251 // Compute the Multipath
252 // ----------------------
253 if (obs.l1() != 0.0 && obs.l2() != 0.0) {
254 double f1 = t_CST::f1(obs.satSys, obs.slotNum);
255 double f2 = t_CST::f2(obs.satSys, obs.slotNum);
256
257 double L1 = obs.l1() * t_CST::c / f1;
258 double L2 = obs.l2() * t_CST::c / f2;
259
260 if (obs.p1() != 0.0) {
261 newObs->MP1 = obs.p1() - L1 - 2.0*f2*f2/(f1*f1-f2*f2) * (L1 - L2);
262 }
263 if (obs.p2() != 0.0) {
264 newObs->MP2 = obs.p2() - L2 - 2.0*f1*f1/(f1*f1-f2*f2) * (L1 - L2);
265 }
266 }
267
268 // Compute the Azimuth and Zenith Distance
269 // ---------------------------------------
270 if (eph && xyz.size()) {
271 double xSat, ySat, zSat, clkSat;
272 eph->position(obs.GPSWeek, obs.GPSWeeks, xSat, ySat, zSat, clkSat);
273
274 double rho, eleSat, azSat;
275 topos(xyz(1), xyz(2), xyz(3), xSat, ySat, zSat, rho, eleSat, azSat);
276
277 newObs->az = azSat * 180.0/M_PI;
278 newObs->zen = 90.0 - eleSat * 180.0/M_PI;
279 }
280}
Note: See TracBrowser for help on using the repository browser.