[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>
|
---|
[4361] | 42 | #include <iomanip>
|
---|
[3899] | 43 | #include "reqcanalyze.h"
|
---|
[3973] | 44 | #include "bncapp.h"
|
---|
[3899] | 45 | #include "bncsettings.h"
|
---|
[4254] | 46 | #include "reqcedit.h"
|
---|
[4255] | 47 | #include "bncutils.h"
|
---|
[4262] | 48 | #include "bncpostprocess.h"
|
---|
[4300] | 49 | #include "graphwin.h"
|
---|
[4307] | 50 | #include "polarplot.h"
|
---|
[3899] | 51 |
|
---|
| 52 | using namespace std;
|
---|
| 53 |
|
---|
[4357] | 54 | const double SLIPTRESH = 5.0; // cycle-slip threshold (meters)
|
---|
| 55 |
|
---|
[3899] | 56 | // Constructor
|
---|
| 57 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 58 | t_reqcAnalyze::t_reqcAnalyze(QObject* parent) : QThread(parent) {
|
---|
| 59 |
|
---|
| 60 | bncSettings settings;
|
---|
[4254] | 61 |
|
---|
[4257] | 62 | _logFileName = settings.value("reqcOutLogFile").toString(); expandEnvVar(_logFileName);
|
---|
| 63 | _logFile = 0;
|
---|
| 64 | _log = 0;
|
---|
[4254] | 65 | _obsFileNames = settings.value("reqcObsFile").toString().split(",", QString::SkipEmptyParts);
|
---|
[4257] | 66 | _navFileNames = settings.value("reqcNavFile").toString().split(",", QString::SkipEmptyParts);
|
---|
[4266] | 67 |
|
---|
| 68 | _currEpo = 0;
|
---|
[4300] | 69 |
|
---|
[4450] | 70 | connect(this, SIGNAL(displayGraph(const QString&, QVector<t_polarPoint*>*, QVector<t_polarPoint*>*)),
|
---|
| 71 | this, SLOT(slotDisplayGraph(const QString&, QVector<t_polarPoint*>*, QVector<t_polarPoint*>*)));
|
---|
[3899] | 72 | }
|
---|
| 73 |
|
---|
| 74 | // Destructor
|
---|
| 75 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 76 | t_reqcAnalyze::~t_reqcAnalyze() {
|
---|
[4255] | 77 | for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
|
---|
| 78 | delete _rnxObsFiles[ii];
|
---|
| 79 | }
|
---|
| 80 | for (int ii = 0; ii < _ephs.size(); ii++) {
|
---|
| 81 | delete _ephs[ii];
|
---|
| 82 | }
|
---|
| 83 | delete _log; _log = 0;
|
---|
| 84 | delete _logFile; _logFile = 0;
|
---|
[4452] | 85 | bncApp* app = (bncApp*) qApp;
|
---|
| 86 | if ( app->mode() != bncApp::interactive) {
|
---|
| 87 | app->exit(0);
|
---|
| 88 | }
|
---|
[3899] | 89 | }
|
---|
| 90 |
|
---|
| 91 | //
|
---|
| 92 | ////////////////////////////////////////////////////////////////////////////
|
---|
[4450] | 93 | void t_reqcAnalyze::slotDisplayGraph(const QString& fileName,
|
---|
| 94 | QVector<t_polarPoint*>* dataMP1,
|
---|
[4342] | 95 | QVector<t_polarPoint*>* dataMP2) {
|
---|
| 96 |
|
---|
[4346] | 97 | bncApp* app = dynamic_cast<bncApp*>(qApp);
|
---|
[4448] | 98 | if (app->GUIenabled()) {
|
---|
[4334] | 99 |
|
---|
[4356] | 100 | double maxMP = 0.0;
|
---|
| 101 | for (int ii = 0; ii < dataMP1->size(); ii++) {
|
---|
| 102 | double mp = dataMP1->at(ii)->_value;
|
---|
| 103 | if (maxMP < mp) {
|
---|
| 104 | maxMP = mp;
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
| 107 | for (int ii = 0; ii < dataMP2->size(); ii++) {
|
---|
| 108 | double mp = dataMP2->at(ii)->_value;
|
---|
| 109 | if (maxMP < mp) {
|
---|
| 110 | maxMP = mp;
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
[4357] | 113 | if (maxMP > SLIPTRESH) {
|
---|
[4359] | 114 | maxMP = SLIPTRESH;
|
---|
[4357] | 115 | }
|
---|
| 116 |
|
---|
[4362] | 117 | //// beg test
|
---|
| 118 | maxMP = 2.0;
|
---|
| 119 | //// end test
|
---|
[4356] | 120 |
|
---|
[4362] | 121 | QwtInterval scaleInterval(0.0, maxMP);
|
---|
| 122 |
|
---|
[4356] | 123 | t_polarPlot* plotMP1 = new t_polarPlot(QwtText("MP1"), scaleInterval,
|
---|
| 124 | app->mainWindow());
|
---|
[4342] | 125 | plotMP1->addCurve(dataMP1);
|
---|
[4334] | 126 |
|
---|
[4356] | 127 | t_polarPlot* plotMP2 = new t_polarPlot(QwtText("MP2"), scaleInterval,
|
---|
| 128 | app->mainWindow());
|
---|
[4342] | 129 | plotMP2->addCurve(dataMP2);
|
---|
[4334] | 130 |
|
---|
[4310] | 131 | QVector<QWidget*> plots;
|
---|
[4334] | 132 | plots << plotMP1;
|
---|
| 133 | plots << plotMP2;
|
---|
| 134 |
|
---|
[4450] | 135 | t_graphWin* graphWin = new t_graphWin(0, fileName, plots, scaleInterval);
|
---|
[4334] | 136 |
|
---|
[4445] | 137 | graphWin->show();
|
---|
| 138 |
|
---|
[4451] | 139 | bncSettings settings;
|
---|
| 140 | QString dirName = settings.value("reqcPlotDir").toString();
|
---|
| 141 | if (!dirName.isEmpty()) {
|
---|
| 142 | graphWin->savePNG(dirName);
|
---|
| 143 | }
|
---|
[4308] | 144 | }
|
---|
[4300] | 145 | }
|
---|
| 146 |
|
---|
| 147 | //
|
---|
| 148 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3899] | 149 | void t_reqcAnalyze::run() {
|
---|
| 150 |
|
---|
[4255] | 151 | // Open Log File
|
---|
| 152 | // -------------
|
---|
| 153 | _logFile = new QFile(_logFileName);
|
---|
[4517] | 154 | if (_logFile->open(QIODevice::WriteOnly | QIODevice::Text)) {
|
---|
| 155 | _log = new QTextStream();
|
---|
| 156 | _log->setDevice(_logFile);
|
---|
| 157 | }
|
---|
[4255] | 158 |
|
---|
| 159 | // Initialize RINEX Observation Files
|
---|
| 160 | // ----------------------------------
|
---|
[4525] | 161 | t_reqcEdit::initRnxObsFiles(_obsFileNames, _rnxObsFiles, _log);
|
---|
[3899] | 162 |
|
---|
[4257] | 163 | // Read Ephemerides
|
---|
| 164 | // ----------------
|
---|
| 165 | t_reqcEdit::readEphemerides(_navFileNames, _ephs);
|
---|
| 166 |
|
---|
[4255] | 167 | // Loop over all RINEX Files
|
---|
| 168 | // -------------------------
|
---|
[4254] | 169 | for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
|
---|
| 170 | analyzeFile(_rnxObsFiles[ii]);
|
---|
| 171 | }
|
---|
| 172 |
|
---|
[4255] | 173 | // Exit
|
---|
| 174 | // ----
|
---|
[4452] | 175 | emit finished();
|
---|
| 176 | deleteLater();
|
---|
[3899] | 177 | }
|
---|
[4254] | 178 |
|
---|
| 179 | //
|
---|
| 180 | ////////////////////////////////////////////////////////////////////////////
|
---|
[4260] | 181 | void t_reqcAnalyze::analyzeFile(t_rnxObsFile* obsFile) {
|
---|
[4259] | 182 |
|
---|
[4517] | 183 | if (_log) {
|
---|
| 184 | *_log << "\nAnalyze File\n"
|
---|
| 185 | << "------------\n"
|
---|
| 186 | << obsFile->fileName().toAscii().data() << endl << endl;
|
---|
| 187 | }
|
---|
[4260] | 188 |
|
---|
[4343] | 189 | _satStat.clear();
|
---|
| 190 |
|
---|
[4342] | 191 | // A priori Coordinates
|
---|
| 192 | // --------------------
|
---|
| 193 | ColumnVector xyz = obsFile->xyz();
|
---|
| 194 |
|
---|
[4262] | 195 | // Loop over all Epochs
|
---|
| 196 | // --------------------
|
---|
[4266] | 197 | while ( (_currEpo = obsFile->nextEpoch()) != 0) {
|
---|
[4260] | 198 |
|
---|
[4262] | 199 | // Loop over all satellites
|
---|
| 200 | // ------------------------
|
---|
[4266] | 201 | for (unsigned iObs = 0; iObs < _currEpo->rnxSat.size(); iObs++) {
|
---|
| 202 | const t_rnxObsFile::t_rnxSat& rnxSat = _currEpo->rnxSat[iObs];
|
---|
[4262] | 203 | t_obs obs;
|
---|
[4266] | 204 | t_postProcessing::setObsFromRnx(obsFile, _currEpo, rnxSat, obs);
|
---|
[4260] | 205 |
|
---|
[4262] | 206 | if (obs.satSys == 'R') {
|
---|
[4266] | 207 | continue; // TODO: set channel number
|
---|
[4262] | 208 | }
|
---|
| 209 |
|
---|
[4263] | 210 | QString prn = QString("%1%2").arg(obs.satSys)
|
---|
| 211 | .arg(obs.satNum, 2, 10, QChar('0'));
|
---|
[4266] | 212 |
|
---|
[4268] | 213 | t_satStat& satStat = _satStat[prn];
|
---|
[4338] | 214 |
|
---|
[4355] | 215 | satStat.addObs(obs);
|
---|
[4262] | 216 | }
|
---|
| 217 |
|
---|
[4266] | 218 | } // while (_currEpo)
|
---|
[4262] | 219 |
|
---|
[4268] | 220 | // Analyze the Multipath
|
---|
| 221 | // ---------------------
|
---|
[4350] | 222 | QVector<t_polarPoint*>* dataMP1 = new QVector<t_polarPoint*>;
|
---|
| 223 | QVector<t_polarPoint*>* dataMP2 = new QVector<t_polarPoint*>;
|
---|
[4268] | 224 |
|
---|
| 225 | QMapIterator<QString, t_satStat> it(_satStat);
|
---|
| 226 | while (it.hasNext()) {
|
---|
| 227 | it.next();
|
---|
| 228 | QString prn = it.key();
|
---|
| 229 | const t_satStat& satStat = it.value();
|
---|
[4361] | 230 | analyzeMultipath(prn, satStat, xyz, obsFile->interval(), dataMP1, dataMP2);
|
---|
[4268] | 231 | }
|
---|
| 232 |
|
---|
[4450] | 233 | emit displayGraph(obsFile->fileName(), dataMP1, dataMP2);
|
---|
[4300] | 234 |
|
---|
[4517] | 235 | if (_log) {
|
---|
| 236 | _log->flush();
|
---|
| 237 | }
|
---|
[4254] | 238 | }
|
---|
[4263] | 239 |
|
---|
| 240 | //
|
---|
| 241 | ////////////////////////////////////////////////////////////////////////////
|
---|
[4355] | 242 | void t_reqcAnalyze::t_satStat::addObs(const t_obs& obs) {
|
---|
[4265] | 243 |
|
---|
[4355] | 244 | t_anaObs* newObs = new t_anaObs(obs.GPSWeek, obs.GPSWeeks);
|
---|
[4354] | 245 | bool okFlag = false;
|
---|
[4338] | 246 |
|
---|
[4268] | 247 | // Compute the Multipath
|
---|
| 248 | // ----------------------
|
---|
[4424] | 249 | double L1 = obs.measdata("L1", 3.0);
|
---|
| 250 | double L2 = obs.measdata("L2", 3.0);
|
---|
[4391] | 251 | if (L1 != 0.0 && L2 != 0.0) {
|
---|
[4266] | 252 | double f1 = t_CST::f1(obs.satSys, obs.slotNum);
|
---|
| 253 | double f2 = t_CST::f2(obs.satSys, obs.slotNum);
|
---|
| 254 |
|
---|
[4391] | 255 | L1 = L1 * t_CST::c / f1;
|
---|
| 256 | L2 = L2 * t_CST::c / f2;
|
---|
[4266] | 257 |
|
---|
[4424] | 258 | double P1 = obs.measdata("C1", 3.0);
|
---|
[4391] | 259 | if (P1 != 0.0) {
|
---|
| 260 | newObs->_MP1 = P1 - L1 - 2.0*f2*f2/(f1*f1-f2*f2) * (L1 - L2);
|
---|
[4354] | 261 | okFlag = true;
|
---|
[4361] | 262 |
|
---|
| 263 | //// beg test
|
---|
| 264 | // cout.setf(ios::fixed);
|
---|
| 265 | // cout << obs.satSys << setw(2) << obs.satNum << " "
|
---|
| 266 | // << setprecision(1) << obs.GPSWeeks << " "
|
---|
| 267 | // << setprecision(4) << newObs->_MP1 << endl;
|
---|
| 268 | //// end test
|
---|
[4268] | 269 | }
|
---|
[4424] | 270 | double P2 = obs.measdata("C2", 3.0);
|
---|
[4391] | 271 | if (P2 != 0.0) {
|
---|
| 272 | newObs->_MP2 = P2 - L2 - 2.0*f1*f1/(f1*f1-f2*f2) * (L1 - L2);
|
---|
[4354] | 273 | okFlag = true;
|
---|
[4268] | 274 | }
|
---|
[4265] | 275 | }
|
---|
[4338] | 276 |
|
---|
[4354] | 277 | // Remember the Observation
|
---|
| 278 | // ------------------------
|
---|
| 279 | if (okFlag) {
|
---|
| 280 | anaObs << newObs;
|
---|
| 281 | }
|
---|
| 282 | else {
|
---|
| 283 | delete newObs;
|
---|
| 284 | }
|
---|
[4263] | 285 | }
|
---|
[4350] | 286 |
|
---|
| 287 | //
|
---|
| 288 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 289 | void t_reqcAnalyze::analyzeMultipath(const QString& prn,
|
---|
| 290 | const t_satStat& satStat,
|
---|
[4355] | 291 | const ColumnVector& xyz,
|
---|
[4361] | 292 | double obsInterval,
|
---|
[4350] | 293 | QVector<t_polarPoint*>* dataMP1,
|
---|
| 294 | QVector<t_polarPoint*>* dataMP2) {
|
---|
| 295 |
|
---|
[4361] | 296 | const int chunkStep = 30.0 / obsInterval; // chunk step (30 sec)
|
---|
| 297 | const int numEpo = 600.0 / obsInterval; // # epochs in one chunk (10 min)
|
---|
[4350] | 298 |
|
---|
[4361] | 299 | for (int chunkStart = 0; chunkStart + numEpo < satStat.anaObs.size();
|
---|
| 300 | chunkStart += chunkStep) {
|
---|
[4351] | 301 |
|
---|
| 302 | // Compute Mean
|
---|
| 303 | // ------------
|
---|
[4353] | 304 | bool slipFlag = false;
|
---|
| 305 | double mean1 = 0.0;
|
---|
| 306 | double mean2 = 0.0;
|
---|
| 307 |
|
---|
[4361] | 308 | for (int ii = 0; ii < numEpo; ii++) {
|
---|
[4351] | 309 | int iEpo = chunkStart + ii;
|
---|
| 310 | const t_anaObs* anaObs = satStat.anaObs[iEpo];
|
---|
[4355] | 311 | mean1 += anaObs->_MP1;
|
---|
| 312 | mean2 += anaObs->_MP2;
|
---|
[4353] | 313 |
|
---|
| 314 | // Check Slip
|
---|
| 315 | // ----------
|
---|
| 316 | if (ii > 0) {
|
---|
[4355] | 317 | double diff1 = anaObs->_MP1 - satStat.anaObs[iEpo-1]->_MP1;
|
---|
| 318 | double diff2 = anaObs->_MP2 - satStat.anaObs[iEpo-1]->_MP2;
|
---|
[4357] | 319 | if (fabs(diff1) > SLIPTRESH || fabs(diff2) > SLIPTRESH) {
|
---|
[4353] | 320 | slipFlag = true;
|
---|
| 321 | break;
|
---|
| 322 | }
|
---|
| 323 | }
|
---|
[4351] | 324 | }
|
---|
[4353] | 325 |
|
---|
| 326 | if (slipFlag) {
|
---|
| 327 | continue;
|
---|
| 328 | }
|
---|
| 329 |
|
---|
[4361] | 330 | mean1 /= numEpo;
|
---|
| 331 | mean2 /= numEpo;
|
---|
[4351] | 332 |
|
---|
| 333 | // Compute Standard Deviation
|
---|
| 334 | // --------------------------
|
---|
| 335 | double stddev1 = 0.0;
|
---|
| 336 | double stddev2 = 0.0;
|
---|
[4361] | 337 | for (int ii = 0; ii < numEpo; ii++) {
|
---|
[4351] | 338 | int iEpo = chunkStart + ii;
|
---|
| 339 | const t_anaObs* anaObs = satStat.anaObs[iEpo];
|
---|
[4355] | 340 | double diff1 = anaObs->_MP1 - mean1;
|
---|
| 341 | double diff2 = anaObs->_MP2 - mean2;
|
---|
[4351] | 342 | stddev1 += diff1 * diff1;
|
---|
| 343 | stddev2 += diff2 * diff2;
|
---|
| 344 | }
|
---|
[4361] | 345 | double MP1 = sqrt(stddev1 / (numEpo-1));
|
---|
| 346 | double MP2 = sqrt(stddev2 / (numEpo-1));
|
---|
[4351] | 347 |
|
---|
[4355] | 348 | const t_anaObs* anaObs0 = satStat.anaObs[chunkStart];
|
---|
| 349 |
|
---|
| 350 | // Compute the Azimuth and Zenith Distance
|
---|
| 351 | // ---------------------------------------
|
---|
| 352 | double az = 0.0;
|
---|
| 353 | double zen = 0.0;
|
---|
| 354 | if (xyz.size()) {
|
---|
| 355 | t_eph* eph = 0;
|
---|
| 356 | for (int ie = 0; ie < _ephs.size(); ie++) {
|
---|
| 357 | if (_ephs[ie]->prn() == prn) {
|
---|
| 358 | eph = _ephs[ie];
|
---|
| 359 | break;
|
---|
| 360 | }
|
---|
| 361 | }
|
---|
| 362 |
|
---|
| 363 | if (eph) {
|
---|
| 364 | double xSat, ySat, zSat, clkSat;
|
---|
| 365 | eph->position(anaObs0->_GPSWeek, anaObs0->_GPSWeeks,
|
---|
| 366 | xSat, ySat, zSat, clkSat);
|
---|
| 367 |
|
---|
| 368 | double rho, eleSat, azSat;
|
---|
| 369 | topos(xyz(1), xyz(2), xyz(3), xSat, ySat, zSat, rho, eleSat, azSat);
|
---|
| 370 |
|
---|
| 371 | az = azSat * 180.0/M_PI;
|
---|
| 372 | zen = 90.0 - eleSat * 180.0/M_PI;
|
---|
| 373 | }
|
---|
| 374 | }
|
---|
| 375 |
|
---|
[4353] | 376 | // Add new Point
|
---|
| 377 | // -------------
|
---|
[4355] | 378 | (*dataMP1) << (new t_polarPoint(az, zen, MP1));
|
---|
| 379 | (*dataMP2) << (new t_polarPoint(az, zen, MP2));
|
---|
[4351] | 380 |
|
---|
[4517] | 381 | if (_log) {
|
---|
| 382 | _log->setRealNumberNotation(QTextStream::FixedNotation);
|
---|
[4353] | 383 |
|
---|
[4517] | 384 | _log->setRealNumberPrecision(2);
|
---|
| 385 | *_log << "MP1 " << prn << " " << az << " " << zen << " ";
|
---|
| 386 | _log->setRealNumberPrecision(3);
|
---|
| 387 | *_log << MP1 << endl;
|
---|
[4353] | 388 |
|
---|
[4517] | 389 | _log->setRealNumberPrecision(2);
|
---|
| 390 | *_log << "MP2 " << prn << " " << az << " " << zen << " ";
|
---|
| 391 | _log->setRealNumberPrecision(3);
|
---|
| 392 | *_log << MP2 << endl;
|
---|
| 393 |
|
---|
| 394 | _log->flush();
|
---|
| 395 | }
|
---|
[4350] | 396 | }
|
---|
| 397 | }
|
---|