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