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 |
|
---|
51 | using namespace std;
|
---|
52 |
|
---|
53 | // Constructor
|
---|
54 | ////////////////////////////////////////////////////////////////////////////
|
---|
55 | t_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 | _dataMP1 = 0;
|
---|
67 | _dataMP2 = 0;
|
---|
68 |
|
---|
69 | connect(this, SIGNAL(displayGraph()), this, SLOT(slotDisplayGraph()));
|
---|
70 | }
|
---|
71 |
|
---|
72 | // Destructor
|
---|
73 | ////////////////////////////////////////////////////////////////////////////
|
---|
74 | t_reqcAnalyze::~t_reqcAnalyze() {
|
---|
75 | for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
|
---|
76 | delete _rnxObsFiles[ii];
|
---|
77 | }
|
---|
78 | for (int ii = 0; ii < _ephs.size(); ii++) {
|
---|
79 | delete _ephs[ii];
|
---|
80 | }
|
---|
81 | delete _log; _log = 0;
|
---|
82 | delete _logFile; _logFile = 0;
|
---|
83 | }
|
---|
84 |
|
---|
85 | //
|
---|
86 | ////////////////////////////////////////////////////////////////////////////
|
---|
87 | void t_reqcAnalyze::slotDisplayGraph() {
|
---|
88 | if (((bncApp*) qApp)->mode() == bncApp::interactive) {
|
---|
89 |
|
---|
90 | t_polarPlot* plotMP1 = new t_polarPlot(0);
|
---|
91 | plotMP1->addCurve(_dataMP1);
|
---|
92 | _dataMP1 = 0;
|
---|
93 |
|
---|
94 | t_polarPlot* plotMP2 = new t_polarPlot(0);
|
---|
95 | plotMP2->addCurve(_dataMP2);
|
---|
96 | _dataMP2 = 0;
|
---|
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 | ////////////////////////////////////////////////////////////////////////////
|
---|
110 | void 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 | ////////////////////////////////////////////////////////////////////////////
|
---|
147 | void t_reqcAnalyze::analyzeFile(t_rnxObsFile* obsFile) {
|
---|
148 |
|
---|
149 | *_log << "Analyze File\n"
|
---|
150 | << "------------\n"
|
---|
151 | << obsFile->fileName().toAscii().data() << endl << endl;
|
---|
152 |
|
---|
153 | // Loop over all Epochs
|
---|
154 | // --------------------
|
---|
155 | while ( (_currEpo = obsFile->nextEpoch()) != 0) {
|
---|
156 |
|
---|
157 | // Loop over all satellites
|
---|
158 | // ------------------------
|
---|
159 | for (unsigned iObs = 0; iObs < _currEpo->rnxSat.size(); iObs++) {
|
---|
160 | const t_rnxObsFile::t_rnxSat& rnxSat = _currEpo->rnxSat[iObs];
|
---|
161 | t_obs obs;
|
---|
162 | t_postProcessing::setObsFromRnx(obsFile, _currEpo, rnxSat, obs);
|
---|
163 |
|
---|
164 | if (obs.satSys == 'R') {
|
---|
165 | continue; // TODO: set channel number
|
---|
166 | }
|
---|
167 |
|
---|
168 | QString prn = QString("%1%2").arg(obs.satSys)
|
---|
169 | .arg(obs.satNum, 2, 10, QChar('0'));
|
---|
170 |
|
---|
171 | t_eph* eph = 0;
|
---|
172 | for (int ie = 0; ie < _ephs.size(); ie++) {
|
---|
173 | if (_ephs[ie]->prn() == prn) {
|
---|
174 | eph = _ephs[ie];
|
---|
175 | break;
|
---|
176 | }
|
---|
177 | }
|
---|
178 |
|
---|
179 | t_satStat& satStat = _satStat[prn];
|
---|
180 |
|
---|
181 | satStat.addObs(eph, obs);
|
---|
182 | }
|
---|
183 |
|
---|
184 | } // while (_currEpo)
|
---|
185 |
|
---|
186 | // Analyze the Multipath
|
---|
187 | // ---------------------
|
---|
188 | _log->setRealNumberNotation(QTextStream::FixedNotation);
|
---|
189 | _log->setRealNumberPrecision(2);
|
---|
190 |
|
---|
191 | delete _dataMP1; _dataMP1 = new QVector<t_polarPoint*>;
|
---|
192 | delete _dataMP2; _dataMP2 = new QVector<t_polarPoint*>;
|
---|
193 |
|
---|
194 | QMapIterator<QString, t_satStat> it(_satStat);
|
---|
195 | while (it.hasNext()) {
|
---|
196 | it.next();
|
---|
197 | QString prn = it.key();
|
---|
198 | const t_satStat& satStat = it.value();
|
---|
199 |
|
---|
200 | int numVal = satStat.anaObs.size();
|
---|
201 | if (numVal > 1) {
|
---|
202 | double mean1 = 0.0;
|
---|
203 | double mean2 = 0.0;
|
---|
204 | for (int ii = 0; ii < numVal; ii++) {
|
---|
205 | const t_anaObs* anaObs = satStat.anaObs[ii];
|
---|
206 | mean1 += anaObs->MP1;
|
---|
207 | mean2 += anaObs->MP2;
|
---|
208 | }
|
---|
209 | mean1 /= numVal;
|
---|
210 | mean2 /= numVal;
|
---|
211 | double stddev1 = 0.0;
|
---|
212 | double stddev2 = 0.0;
|
---|
213 | for (int ii = 0; ii < numVal; ii++) {
|
---|
214 | const t_anaObs* anaObs = satStat.anaObs[ii];
|
---|
215 | double diff1 = anaObs->MP1 - mean1;
|
---|
216 | double diff2 = anaObs->MP2 - mean2;
|
---|
217 | stddev1 += diff1 * diff1;
|
---|
218 | stddev2 += diff2 * diff2;
|
---|
219 | //// beg test
|
---|
220 | (*_dataMP1) << (new t_polarPoint(anaObs->az, anaObs->zen, 0.5));
|
---|
221 | (*_dataMP2) << (new t_polarPoint(anaObs->az, anaObs->zen, 1.0));
|
---|
222 | //// end test
|
---|
223 | }
|
---|
224 | double MP1 = sqrt(stddev1 / (numVal-1));
|
---|
225 | double MP2 = sqrt(stddev2 / (numVal-1));
|
---|
226 |
|
---|
227 | *_log << "MP1 " << prn << " " << MP1 << endl;
|
---|
228 | *_log << "MP2 " << prn << " " << MP2 << endl;
|
---|
229 | }
|
---|
230 | }
|
---|
231 |
|
---|
232 | emit displayGraph();
|
---|
233 |
|
---|
234 | _log->flush();
|
---|
235 | }
|
---|
236 |
|
---|
237 | //
|
---|
238 | ////////////////////////////////////////////////////////////////////////////
|
---|
239 | void t_reqcAnalyze::t_satStat::addObs(const t_eph* eph, const t_obs& obs) {
|
---|
240 |
|
---|
241 | t_anaObs* newObs = new t_anaObs(obs);
|
---|
242 | anaObs << newObs;
|
---|
243 |
|
---|
244 | // Compute the Multipath
|
---|
245 | // ----------------------
|
---|
246 | if (obs.l1() != 0.0 && obs.l2() != 0.0) {
|
---|
247 | double f1 = t_CST::f1(obs.satSys, obs.slotNum);
|
---|
248 | double f2 = t_CST::f2(obs.satSys, obs.slotNum);
|
---|
249 |
|
---|
250 | double L1 = obs.l1() * t_CST::c / f1;
|
---|
251 | double L2 = obs.l2() * t_CST::c / f2;
|
---|
252 |
|
---|
253 | if (obs.p1() != 0.0) {
|
---|
254 | newObs->MP1 = obs.p1() - L1 - 2.0*f2*f2/(f1*f1-f2*f2) * (L1 - L2);
|
---|
255 | }
|
---|
256 | if (obs.p2() != 0.0) {
|
---|
257 | newObs->MP2 = obs.p2() - L2 - 2.0*f1*f1/(f1*f1-f2*f2) * (L1 - L2);
|
---|
258 | }
|
---|
259 | }
|
---|
260 |
|
---|
261 | // Compute the Azimuth and Zenith Distance
|
---|
262 | // ---------------------------------------
|
---|
263 | if (eph) {
|
---|
264 | double xSat, ySat, zSat, clkSat;
|
---|
265 | eph->position(obs.GPSWeek, obs.GPSWeeks, xSat, ySat, zSat, clkSat);
|
---|
266 |
|
---|
267 | //// beg test
|
---|
268 | double xRec = -3947762.7496;
|
---|
269 | double yRec = 3364399.8789;
|
---|
270 | double zRec = 3699428.5111;
|
---|
271 | //// end test
|
---|
272 |
|
---|
273 | double rho, eleSat, azSat;
|
---|
274 | topos(xRec, yRec, zRec, xSat, ySat, zSat, rho, eleSat, azSat);
|
---|
275 | }
|
---|
276 | }
|
---|