[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>
|
---|
| 42 | #include "reqcanalyze.h"
|
---|
[3973] | 43 | #include "bncapp.h"
|
---|
[3899] | 44 | #include "bncsettings.h"
|
---|
[4254] | 45 | #include "reqcedit.h"
|
---|
[4255] | 46 | #include "bncutils.h"
|
---|
[4262] | 47 | #include "bncpostprocess.h"
|
---|
[4300] | 48 | #include "graphwin.h"
|
---|
[4307] | 49 | #include "polarplot.h"
|
---|
[3899] | 50 |
|
---|
| 51 | using namespace std;
|
---|
| 52 |
|
---|
| 53 | // Constructor
|
---|
| 54 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 55 | t_reqcAnalyze::t_reqcAnalyze(QObject* parent) : QThread(parent) {
|
---|
| 56 |
|
---|
| 57 | bncSettings settings;
|
---|
[4254] | 58 |
|
---|
[4257] | 59 | _logFileName = settings.value("reqcOutLogFile").toString(); expandEnvVar(_logFileName);
|
---|
| 60 | _logFile = 0;
|
---|
| 61 | _log = 0;
|
---|
[4254] | 62 | _obsFileNames = settings.value("reqcObsFile").toString().split(",", QString::SkipEmptyParts);
|
---|
[4257] | 63 | _navFileNames = settings.value("reqcNavFile").toString().split(",", QString::SkipEmptyParts);
|
---|
[4266] | 64 |
|
---|
| 65 | _currEpo = 0;
|
---|
[4300] | 66 |
|
---|
[4342] | 67 | connect(this, SIGNAL(displayGraph(QVector<t_polarPoint*>*, QVector<t_polarPoint*>*)),
|
---|
| 68 | this, SLOT(slotDisplayGraph(QVector<t_polarPoint*>*, QVector<t_polarPoint*>*)));
|
---|
[3899] | 69 | }
|
---|
| 70 |
|
---|
| 71 | // Destructor
|
---|
| 72 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 73 | t_reqcAnalyze::~t_reqcAnalyze() {
|
---|
[4255] | 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;
|
---|
[3899] | 82 | }
|
---|
| 83 |
|
---|
| 84 | //
|
---|
| 85 | ////////////////////////////////////////////////////////////////////////////
|
---|
[4342] | 86 | void t_reqcAnalyze::slotDisplayGraph(QVector<t_polarPoint*>* dataMP1,
|
---|
| 87 | QVector<t_polarPoint*>* dataMP2) {
|
---|
| 88 |
|
---|
[4346] | 89 | bncApp* app = dynamic_cast<bncApp*>(qApp);
|
---|
| 90 | if (app->mode() == bncApp::interactive) {
|
---|
[4334] | 91 |
|
---|
[4346] | 92 | t_polarPlot* plotMP1 = new t_polarPlot(QwtText("MP1"), app->mainWindow());
|
---|
[4342] | 93 | plotMP1->addCurve(dataMP1);
|
---|
[4334] | 94 |
|
---|
[4346] | 95 | t_polarPlot* plotMP2 = new t_polarPlot(QwtText("MP2"), app->mainWindow());
|
---|
[4342] | 96 | plotMP2->addCurve(dataMP2);
|
---|
[4334] | 97 |
|
---|
[4310] | 98 | QVector<QWidget*> plots;
|
---|
[4334] | 99 | plots << plotMP1;
|
---|
| 100 | plots << plotMP2;
|
---|
| 101 |
|
---|
[4308] | 102 | t_graphWin* graphWin = new t_graphWin(0, plots);
|
---|
[4334] | 103 |
|
---|
[4347] | 104 | graphWin->show();
|
---|
[4308] | 105 | }
|
---|
[4300] | 106 | }
|
---|
| 107 |
|
---|
| 108 | //
|
---|
| 109 | ////////////////////////////////////////////////////////////////////////////
|
---|
[3899] | 110 | void t_reqcAnalyze::run() {
|
---|
| 111 |
|
---|
[4255] | 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 | // ----------------------------------
|
---|
[4254] | 121 | t_reqcEdit::initRnxObsFiles(_obsFileNames, _rnxObsFiles);
|
---|
[3899] | 122 |
|
---|
[4257] | 123 | // Read Ephemerides
|
---|
| 124 | // ----------------
|
---|
| 125 | t_reqcEdit::readEphemerides(_navFileNames, _ephs);
|
---|
| 126 |
|
---|
[4255] | 127 | // Loop over all RINEX Files
|
---|
| 128 | // -------------------------
|
---|
[4254] | 129 | for (int ii = 0; ii < _rnxObsFiles.size(); ii++) {
|
---|
| 130 | analyzeFile(_rnxObsFiles[ii]);
|
---|
| 131 | }
|
---|
| 132 |
|
---|
[4255] | 133 | // Exit
|
---|
| 134 | // ----
|
---|
[3973] | 135 | bncApp* app = (bncApp*) qApp;
|
---|
| 136 | if ( app->mode() != bncApp::interactive) {
|
---|
| 137 | app->exit(0);
|
---|
| 138 | }
|
---|
| 139 | else {
|
---|
| 140 | emit finished();
|
---|
| 141 | deleteLater();
|
---|
| 142 | }
|
---|
[3899] | 143 | }
|
---|
[4254] | 144 |
|
---|
| 145 | //
|
---|
| 146 | ////////////////////////////////////////////////////////////////////////////
|
---|
[4260] | 147 | void t_reqcAnalyze::analyzeFile(t_rnxObsFile* obsFile) {
|
---|
[4259] | 148 |
|
---|
[4352] | 149 | *_log << "\nAnalyze File\n"
|
---|
| 150 | << "------------\n"
|
---|
[4260] | 151 | << obsFile->fileName().toAscii().data() << endl << endl;
|
---|
| 152 |
|
---|
[4343] | 153 | _satStat.clear();
|
---|
| 154 |
|
---|
[4342] | 155 | // A priori Coordinates
|
---|
| 156 | // --------------------
|
---|
| 157 | ColumnVector xyz = obsFile->xyz();
|
---|
| 158 |
|
---|
[4262] | 159 | // Loop over all Epochs
|
---|
| 160 | // --------------------
|
---|
[4266] | 161 | while ( (_currEpo = obsFile->nextEpoch()) != 0) {
|
---|
[4260] | 162 |
|
---|
[4262] | 163 | // Loop over all satellites
|
---|
| 164 | // ------------------------
|
---|
[4266] | 165 | for (unsigned iObs = 0; iObs < _currEpo->rnxSat.size(); iObs++) {
|
---|
| 166 | const t_rnxObsFile::t_rnxSat& rnxSat = _currEpo->rnxSat[iObs];
|
---|
[4262] | 167 | t_obs obs;
|
---|
[4266] | 168 | t_postProcessing::setObsFromRnx(obsFile, _currEpo, rnxSat, obs);
|
---|
[4260] | 169 |
|
---|
[4262] | 170 | if (obs.satSys == 'R') {
|
---|
[4266] | 171 | continue; // TODO: set channel number
|
---|
[4262] | 172 | }
|
---|
| 173 |
|
---|
[4263] | 174 | QString prn = QString("%1%2").arg(obs.satSys)
|
---|
| 175 | .arg(obs.satNum, 2, 10, QChar('0'));
|
---|
[4266] | 176 |
|
---|
[4338] | 177 | t_eph* eph = 0;
|
---|
| 178 | for (int ie = 0; ie < _ephs.size(); ie++) {
|
---|
| 179 | if (_ephs[ie]->prn() == prn) {
|
---|
| 180 | eph = _ephs[ie];
|
---|
| 181 | break;
|
---|
| 182 | }
|
---|
| 183 | }
|
---|
| 184 |
|
---|
[4268] | 185 | t_satStat& satStat = _satStat[prn];
|
---|
[4338] | 186 |
|
---|
[4342] | 187 | satStat.addObs(obs, eph, xyz);
|
---|
[4262] | 188 | }
|
---|
| 189 |
|
---|
[4266] | 190 | } // while (_currEpo)
|
---|
[4262] | 191 |
|
---|
[4268] | 192 | // Analyze the Multipath
|
---|
| 193 | // ---------------------
|
---|
[4350] | 194 | QVector<t_polarPoint*>* dataMP1 = new QVector<t_polarPoint*>;
|
---|
| 195 | QVector<t_polarPoint*>* dataMP2 = new QVector<t_polarPoint*>;
|
---|
[4268] | 196 |
|
---|
| 197 | QMapIterator<QString, t_satStat> it(_satStat);
|
---|
| 198 | while (it.hasNext()) {
|
---|
| 199 | it.next();
|
---|
| 200 | QString prn = it.key();
|
---|
| 201 | const t_satStat& satStat = it.value();
|
---|
[4350] | 202 | analyzeMultipath(prn, satStat, dataMP1, dataMP2);
|
---|
[4268] | 203 | }
|
---|
| 204 |
|
---|
[4342] | 205 | emit displayGraph(dataMP1, dataMP2);
|
---|
[4300] | 206 |
|
---|
[4259] | 207 | _log->flush();
|
---|
[4254] | 208 | }
|
---|
[4263] | 209 |
|
---|
| 210 | //
|
---|
| 211 | ////////////////////////////////////////////////////////////////////////////
|
---|
[4342] | 212 | void t_reqcAnalyze::t_satStat::addObs(const t_obs& obs, const t_eph* eph,
|
---|
| 213 | const ColumnVector& xyz) {
|
---|
[4265] | 214 |
|
---|
[4338] | 215 | t_anaObs* newObs = new t_anaObs(obs);
|
---|
[4354] | 216 | bool okFlag = false;
|
---|
[4338] | 217 |
|
---|
[4268] | 218 | // Compute the Multipath
|
---|
| 219 | // ----------------------
|
---|
| 220 | if (obs.l1() != 0.0 && obs.l2() != 0.0) {
|
---|
[4266] | 221 | double f1 = t_CST::f1(obs.satSys, obs.slotNum);
|
---|
| 222 | double f2 = t_CST::f2(obs.satSys, obs.slotNum);
|
---|
| 223 |
|
---|
| 224 | double L1 = obs.l1() * t_CST::c / f1;
|
---|
| 225 | double L2 = obs.l2() * t_CST::c / f2;
|
---|
| 226 |
|
---|
[4268] | 227 | if (obs.p1() != 0.0) {
|
---|
[4338] | 228 | newObs->MP1 = obs.p1() - L1 - 2.0*f2*f2/(f1*f1-f2*f2) * (L1 - L2);
|
---|
[4354] | 229 | okFlag = true;
|
---|
[4268] | 230 | }
|
---|
| 231 | if (obs.p2() != 0.0) {
|
---|
[4338] | 232 | newObs->MP2 = obs.p2() - L2 - 2.0*f1*f1/(f1*f1-f2*f2) * (L1 - L2);
|
---|
[4354] | 233 | okFlag = true;
|
---|
[4268] | 234 | }
|
---|
[4265] | 235 | }
|
---|
[4338] | 236 |
|
---|
[4354] | 237 | // Remember the Observation
|
---|
| 238 | // ------------------------
|
---|
| 239 | if (okFlag) {
|
---|
| 240 | anaObs << newObs;
|
---|
| 241 | }
|
---|
| 242 | else {
|
---|
| 243 | delete newObs;
|
---|
| 244 | return;
|
---|
| 245 | }
|
---|
| 246 |
|
---|
[4338] | 247 | // Compute the Azimuth and Zenith Distance
|
---|
| 248 | // ---------------------------------------
|
---|
[4342] | 249 | if (eph && xyz.size()) {
|
---|
[4339] | 250 | double xSat, ySat, zSat, clkSat;
|
---|
| 251 | eph->position(obs.GPSWeek, obs.GPSWeeks, xSat, ySat, zSat, clkSat);
|
---|
[4340] | 252 |
|
---|
| 253 | double rho, eleSat, azSat;
|
---|
[4342] | 254 | topos(xyz(1), xyz(2), xyz(3), xSat, ySat, zSat, rho, eleSat, azSat);
|
---|
[4341] | 255 |
|
---|
| 256 | newObs->az = azSat * 180.0/M_PI;
|
---|
| 257 | newObs->zen = 90.0 - eleSat * 180.0/M_PI;
|
---|
[4338] | 258 | }
|
---|
[4263] | 259 | }
|
---|
[4350] | 260 |
|
---|
| 261 | //
|
---|
| 262 | ////////////////////////////////////////////////////////////////////////////
|
---|
| 263 | void t_reqcAnalyze::analyzeMultipath(const QString& prn,
|
---|
| 264 | const t_satStat& satStat,
|
---|
| 265 | QVector<t_polarPoint*>* dataMP1,
|
---|
| 266 | QVector<t_polarPoint*>* dataMP2) {
|
---|
| 267 |
|
---|
[4353] | 268 | const int LENGTH = 10; // number of epochs in one chunk
|
---|
| 269 | const double SLIP = 5.0; // cycle-slip threshold
|
---|
[4350] | 270 |
|
---|
[4351] | 271 | int numEpo = satStat.anaObs.size();
|
---|
| 272 |
|
---|
| 273 | for (int chunkStart = 0; chunkStart + LENGTH < numEpo; chunkStart += LENGTH) {
|
---|
| 274 |
|
---|
| 275 | // Compute Mean
|
---|
| 276 | // ------------
|
---|
[4353] | 277 | bool slipFlag = false;
|
---|
| 278 | double mean1 = 0.0;
|
---|
| 279 | double mean2 = 0.0;
|
---|
| 280 |
|
---|
[4351] | 281 | for (int ii = 0; ii < LENGTH; ii++) {
|
---|
| 282 | int iEpo = chunkStart + ii;
|
---|
| 283 | const t_anaObs* anaObs = satStat.anaObs[iEpo];
|
---|
| 284 | mean1 += anaObs->MP1;
|
---|
| 285 | mean2 += anaObs->MP2;
|
---|
[4353] | 286 |
|
---|
| 287 | // Check Slip
|
---|
| 288 | // ----------
|
---|
| 289 | if (ii > 0) {
|
---|
| 290 | double diff1 = anaObs->MP1 - satStat.anaObs[iEpo-1]->MP1;
|
---|
| 291 | double diff2 = anaObs->MP2 - satStat.anaObs[iEpo-1]->MP2;
|
---|
| 292 | if (fabs(diff1) > SLIP || fabs(diff2) > SLIP) {
|
---|
| 293 | slipFlag = true;
|
---|
| 294 | break;
|
---|
| 295 | }
|
---|
| 296 | }
|
---|
[4351] | 297 | }
|
---|
[4353] | 298 |
|
---|
| 299 | if (slipFlag) {
|
---|
| 300 | continue;
|
---|
| 301 | }
|
---|
| 302 |
|
---|
[4351] | 303 | mean1 /= LENGTH;
|
---|
| 304 | mean2 /= LENGTH;
|
---|
| 305 |
|
---|
| 306 | // Compute Standard Deviation
|
---|
| 307 | // --------------------------
|
---|
| 308 | double stddev1 = 0.0;
|
---|
| 309 | double stddev2 = 0.0;
|
---|
| 310 | for (int ii = 0; ii < LENGTH; ii++) {
|
---|
| 311 | int iEpo = chunkStart + ii;
|
---|
| 312 | const t_anaObs* anaObs = satStat.anaObs[iEpo];
|
---|
| 313 | double diff1 = anaObs->MP1 - mean1;
|
---|
| 314 | double diff2 = anaObs->MP2 - mean2;
|
---|
| 315 | stddev1 += diff1 * diff1;
|
---|
| 316 | stddev2 += diff2 * diff2;
|
---|
| 317 | }
|
---|
| 318 | double MP1 = sqrt(stddev1 / (LENGTH-1));
|
---|
| 319 | double MP2 = sqrt(stddev2 / (LENGTH-1));
|
---|
| 320 |
|
---|
[4353] | 321 | // Add new Point
|
---|
| 322 | // -------------
|
---|
[4351] | 323 | const t_anaObs* anaObs = satStat.anaObs[chunkStart];
|
---|
| 324 | (*dataMP1) << (new t_polarPoint(anaObs->az, anaObs->zen, MP1));
|
---|
| 325 | (*dataMP2) << (new t_polarPoint(anaObs->az, anaObs->zen, MP2));
|
---|
| 326 |
|
---|
| 327 | _log->setRealNumberNotation(QTextStream::FixedNotation);
|
---|
[4353] | 328 |
|
---|
[4351] | 329 | _log->setRealNumberPrecision(2);
|
---|
[4353] | 330 | *_log << "MP1 " << prn << " " << anaObs->az << " " << anaObs->zen << " ";
|
---|
| 331 | _log->setRealNumberPrecision(3);
|
---|
| 332 | *_log << MP1 << endl;
|
---|
| 333 |
|
---|
| 334 | _log->setRealNumberPrecision(2);
|
---|
| 335 | *_log << "MP2 " << prn << " " << anaObs->az << " " << anaObs->zen << " ";
|
---|
| 336 | _log->setRealNumberPrecision(3);
|
---|
| 337 | *_log << MP2 << endl;
|
---|
[4350] | 338 | }
|
---|
| 339 | }
|
---|