source: ntrip/trunk/BNC/src/combination/bnccomb.cpp@ 6157

Last change on this file since 6157 was 6157, checked in by mervart, 10 years ago
File size: 33.2 KB
RevLine 
[2898]1/* -------------------------------------------------------------------------
2 * BKG NTRIP Client
3 * -------------------------------------------------------------------------
4 *
5 * Class: bncComb
6 *
7 * Purpose: Combinations of Orbit/Clock Corrections
8 *
9 * Author: L. Mervart
10 *
11 * Created: 22-Jan-2011
12 *
13 * Changes:
14 *
15 * -----------------------------------------------------------------------*/
16
[2933]17#include <newmatio.h>
[2921]18#include <iomanip>
[3214]19#include <sstream>
[2898]20
21#include "bnccomb.h"
[5070]22#include "bnccore.h"
[3201]23#include "upload/bncrtnetdecoder.h"
[2910]24#include "bncsettings.h"
[2988]25#include "bncutils.h"
[3181]26#include "bncsp3.h"
[3052]27#include "bncantex.h"
[5742]28#include "t_prn.h"
[2898]29
[3455]30const double sig0_offAC = 1000.0;
31const double sig0_offACSat = 100.0;
[3468]32const double sigP_offACSat = 0.01;
[3455]33const double sig0_clkSat = 100.0;
34
35const double sigObs = 0.05;
36
37using namespace std;
38
[2898]39// Constructor
40////////////////////////////////////////////////////////////////////////////
[6155]41bncComb::cmbParam::cmbParam(parType type_, int index_, const QString& ac_, const QString& prn_) {
[3032]42
[3433]43 type = type_;
44 index = index_;
45 AC = ac_;
46 prn = prn_;
47 xx = 0.0;
[3455]48 eph = 0;
[3429]49
[3485]50 if (type == offACgps) {
[3455]51 epoSpec = true;
52 sig0 = sig0_offAC;
53 sigP = sig0;
[3429]54 }
[3485]55 else if (type == offACglo) {
56 epoSpec = true;
57 sig0 = sig0_offAC;
58 sigP = sig0;
59 }
[3429]60 else if (type == offACSat) {
[3455]61 epoSpec = false;
62 sig0 = sig0_offACSat;
63 sigP = sigP_offACSat;
[3429]64 }
65 else if (type == clkSat) {
[3455]66 epoSpec = true;
67 sig0 = sig0_clkSat;
68 sigP = sig0;
[3429]69 }
[2933]70}
71
72// Destructor
73////////////////////////////////////////////////////////////////////////////
[6155]74bncComb::cmbParam::~cmbParam() {
[2933]75}
76
77// Partial
78////////////////////////////////////////////////////////////////////////////
[6155]79double bncComb::cmbParam::partial(const QString& AC_, const QString& prn_) {
[2933]80
[3485]81 if (type == offACgps) {
82 if (AC == AC_ && prn_[0] == 'G') {
[2934]83 return 1.0;
84 }
85 }
[3485]86 else if (type == offACglo) {
87 if (AC == AC_ && prn_[0] == 'R') {
88 return 1.0;
89 }
90 }
[3429]91 else if (type == offACSat) {
92 if (AC == AC_ && prn == prn_) {
[2933]93 return 1.0;
94 }
95 }
[3429]96 else if (type == clkSat) {
97 if (prn == prn_) {
[2933]98 return 1.0;
99 }
100 }
101
102 return 0.0;
103}
104
[2990]105//
106////////////////////////////////////////////////////////////////////////////
[6155]107QString bncComb::cmbParam::toString() const {
[2933]108
[2990]109 QString outStr;
110
[3485]111 if (type == offACgps) {
112 outStr = "AC offset GPS " + AC;
[2990]113 }
[3485]114 else if (type == offACglo) {
115 outStr = "AC offset GLO " + AC;
116 }
[3429]117 else if (type == offACSat) {
[2992]118 outStr = "Sat Offset " + AC + " " + prn;
[2990]119 }
[3429]120 else if (type == clkSat) {
[2992]121 outStr = "Clk Corr " + prn;
[2990]122 }
[2933]123
[2990]124 return outStr;
125}
126
[2933]127// Constructor
128////////////////////////////////////////////////////////////////////////////
[6155]129bncComb::bncComb() : bncEphUser(true) {
[2910]130
131 bncSettings settings;
132
133 QStringList combineStreams = settings.value("combineStreams").toStringList();
[2918]134
[4183]135 _cmbSampl = settings.value("cmbSampl").toInt();
136 if (_cmbSampl <= 0) {
137 _cmbSampl = 10;
138 }
139
[3455]140 _masterMissingEpochs = 0;
141
[3143]142 if (combineStreams.size() >= 1 && !combineStreams[0].isEmpty()) {
[2910]143 QListIterator<QString> it(combineStreams);
144 while (it.hasNext()) {
145 QStringList hlp = it.next().split(" ");
[2918]146 cmbAC* newAC = new cmbAC();
147 newAC->mountPoint = hlp[0];
148 newAC->name = hlp[1];
149 newAC->weight = hlp[2].toDouble();
[3453]150 if (_masterOrbitAC.isEmpty()) {
151 _masterOrbitAC = newAC->name;
152 }
[3429]153 _ACs.append(newAC);
[2910]154 }
155 }
[2927]156
[3211]157 _rtnetDecoder = 0;
[3201]158
[6155]159 connect(this, SIGNAL(newMessage(QByteArray,bool)),
[5068]160 BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
[2933]161
[5583]162 connect(BNC_CORE, SIGNAL(providerIDChanged(QString)),
[6155]163 this, SLOT(slotProviderIDChanged(QString)));
[5583]164
[6155]165 connect(BNC_CORE, SIGNAL(newOrbCorrections(QList<t_orbCorr>)),
166 this, SLOT(slotNewOrbCorrections(QList<t_orbCorr>)));
167
168 connect(BNC_CORE, SIGNAL(newClkCorrections(QList<t_clkCorr>)),
169 this, SLOT(slotNewClkCorrections(QList<t_clkCorr>)));
170
[3470]171 // Combination Method
172 // ------------------
[3481]173 if (settings.value("cmbMethod").toString() == "Single-Epoch") {
174 _method = singleEpoch;
[3470]175 }
176 else {
[3481]177 _method = filter;
[3470]178 }
[3032]179
[3484]180 // Use Glonass
181 // -----------
182 if ( Qt::CheckState(settings.value("pppGLONASS").toInt()) == Qt::Checked) {
183 _useGlonass = true;
184 }
185 else {
186 _useGlonass = false;
187 }
188
[3032]189 // Initialize Parameters (model: Clk_Corr = AC_Offset + Sat_Offset + Clk)
190 // ----------------------------------------------------------------------
[3470]191 if (_method == filter) {
192 int nextPar = 0;
193 QListIterator<cmbAC*> it(_ACs);
194 while (it.hasNext()) {
195 cmbAC* AC = it.next();
[3485]196 _params.push_back(new cmbParam(cmbParam::offACgps, ++nextPar, AC->name, ""));
[5808]197 for (unsigned iGps = 1; iGps <= t_prn::MAXPRN_GPS; iGps++) {
[3470]198 QString prn = QString("G%1").arg(iGps, 2, 10, QChar('0'));
199 _params.push_back(new cmbParam(cmbParam::offACSat, ++nextPar,
200 AC->name, prn));
201 }
[3483]202 if (_useGlonass) {
[3485]203 _params.push_back(new cmbParam(cmbParam::offACglo, ++nextPar, AC->name, ""));
[5808]204 for (unsigned iGlo = 1; iGlo <= t_prn::MAXPRN_GLONASS; iGlo++) {
[3483]205 QString prn = QString("R%1").arg(iGlo, 2, 10, QChar('0'));
206 _params.push_back(new cmbParam(cmbParam::offACSat, ++nextPar,
207 AC->name, prn));
208 }
209 }
[3470]210 }
[5808]211 for (unsigned iGps = 1; iGps <= t_prn::MAXPRN_GPS; iGps++) {
[3134]212 QString prn = QString("G%1").arg(iGps, 2, 10, QChar('0'));
[3470]213 _params.push_back(new cmbParam(cmbParam::clkSat, ++nextPar, "", prn));
[2991]214 }
[3483]215 if (_useGlonass) {
[5808]216 for (unsigned iGlo = 1; iGlo <= t_prn::MAXPRN_GLONASS; iGlo++) {
[3483]217 QString prn = QString("R%1").arg(iGlo, 2, 10, QChar('0'));
218 _params.push_back(new cmbParam(cmbParam::clkSat, ++nextPar, "", prn));
219 }
220 }
[3470]221
222 // Initialize Variance-Covariance Matrix
223 // -------------------------------------
224 _QQ.ReSize(_params.size());
225 _QQ = 0.0;
226 for (int iPar = 1; iPar <= _params.size(); iPar++) {
227 cmbParam* pp = _params[iPar-1];
228 _QQ(iPar,iPar) = pp->sig0 * pp->sig0;
229 }
[2991]230 }
[2933]231
[3052]232 // ANTEX File
233 // ----------
234 _antex = 0;
235 QString antexFileName = settings.value("pppAntex").toString();
236 if (!antexFileName.isEmpty()) {
237 _antex = new bncAntex();
238 if (_antex->readFile(antexFileName) != success) {
239 emit newMessage("wrong ANTEX file", true);
240 delete _antex;
241 _antex = 0;
242 }
243 }
[3138]244
[3329]245 // Maximal Residuum
246 // ----------------
247 _MAXRES = settings.value("cmbMaxres").toDouble();
248 if (_MAXRES <= 0.0) {
249 _MAXRES = 999.0;
250 }
[2898]251}
252
253// Destructor
254////////////////////////////////////////////////////////////////////////////
255bncComb::~bncComb() {
[3429]256 QListIterator<cmbAC*> icAC(_ACs);
257 while (icAC.hasNext()) {
258 delete icAC.next();
[2918]259 }
[3201]260 delete _rtnetDecoder;
[3052]261 delete _antex;
[3296]262 for (int iPar = 1; iPar <= _params.size(); iPar++) {
263 delete _params[iPar-1];
264 }
[3556]265 QListIterator<bncTime> itTime(_buffer.keys());
[3551]266 while (itTime.hasNext()) {
[3556]267 bncTime epoTime = itTime.next();
268 _buffer.remove(epoTime);
[3429]269 }
[2898]270}
271
[6155]272// Remember orbit corrections
[2898]273////////////////////////////////////////////////////////////////////////////
[6155]274void bncComb::slotNewOrbCorrections(QList<t_orbCorr> orbCorrections) {
[2906]275 QMutexLocker locker(&_mutex);
[2913]276
[6155]277 for (int ii = 0; ii < orbCorrections.size(); ii++) {
278 t_orbCorr& orbCorr = orbCorrections[ii];
279 QString staID(orbCorr._staID.c_str());
280 QString prn(orbCorr._prn.toString().c_str());
281
282 // Find/Check the AC Name
283 // ----------------------
284 QString acName;
285 QListIterator<cmbAC*> icAC(_ACs);
286 while (icAC.hasNext()) {
287 cmbAC* AC = icAC.next();
288 if (AC->mountPoint == staID) {
289 acName = AC->name;
290 break;
291 }
[3431]292 }
[6155]293 if (acName.isEmpty()) {
294 continue;
295 }
[3431]296
[6155]297 // Store the correction
298 // --------------------
299 QMap<t_prn, t_orbCorr>& storage = _orbCorrections[acName];
300 storage[orbCorr._prn] = orbCorr;
[2913]301 }
[6155]302}
[2913]303
[6155]304// Process clock corrections
305////////////////////////////////////////////////////////////////////////////
306void bncComb::slotNewClkCorrections(QList<t_clkCorr> clkCorrections) {
307 QMutexLocker locker(&_mutex);
308
309 bncTime lastTime;
310
311 for (int ii = 0; ii < clkCorrections.size(); ii++) {
312 t_clkCorr& clkCorr = clkCorrections[ii];
313 QString staID(clkCorr._staID.c_str());
314 QString prn(clkCorr._prn.toString().c_str());
315
316 // Set the last time
317 // -----------------
318 if (lastTime.undef() || clkCorr._time > lastTime) {
319 lastTime = clkCorr._time;
[3483]320 }
321
[6155]322 // Find/Check the AC Name
323 // ----------------------
324 QString acName;
325 QListIterator<cmbAC*> icAC(_ACs);
326 while (icAC.hasNext()) {
327 cmbAC* AC = icAC.next();
328 if (AC->mountPoint == staID) {
329 acName = AC->name;
330 break;
331 }
[3588]332 }
[6155]333 if (acName.isEmpty()) {
334 continue;
335 }
[3588]336
[6155]337 // Check GLONASS
338 // -------------
339 if (!_useGlonass && clkCorr._prn.system() == 'R') {
340 continue;
[3590]341 }
342
[6155]343 // Check Modulo Time
344 // -----------------
345 if (int(clkCorr._time.gpssec()) % _cmbSampl != 0.0) {
346 continue;
347 }
[3274]348
[6155]349 // Check Correction Age
350 // --------------------
351 if (_resTime.valid() && clkCorr._time <= _resTime) {
352 emit newMessage("bncComb: old correction: " + acName.toAscii() + " " + prn.toAscii(), true);
353 continue;
354 }
[6156]355
[6155]356 // Create new correction
357 // ---------------------
358 cmbCorr* newCorr = new cmbCorr();
[6157]359 newCorr->_prn = prn;
[6155]360 newCorr->_time = clkCorr._time;
361 newCorr->_iod = clkCorr._iod;
362 newCorr->_acName = acName;
363 newCorr->_clkCorr = new t_clkCorr(clkCorr);
364
[6156]365 // Check orbit correction
366 // ----------------------
367 if (!_orbCorrections.contains(acName)) {
368 delete newCorr;
369 continue;
370 }
371 else {
372 QMap<t_prn, t_orbCorr>& storage = _orbCorrections[acName];
373 if (!storage.contains(clkCorr._prn) || storage[clkCorr._prn]._iod != newCorr->_iod) {
374 delete newCorr;
375 continue;
376 }
377 else {
378 newCorr->_orbCorr = new t_orbCorr(storage[clkCorr._prn]);
379 }
380 }
381
[6155]382 // Check the Ephemeris
383 //--------------------
384 if (_eph.find(prn) == _eph.end()) {
385 emit newMessage("bncComb: eph not found " + prn.toAscii(), true);
386 delete newCorr;
387 continue;
[2986]388 }
[3029]389 else {
[6155]390 t_eph* lastEph = _eph[prn]->last;
391 t_eph* prevEph = _eph[prn]->prev;
392 if (lastEph && lastEph->IOD() == newCorr->_iod) {
393 newCorr->_eph = lastEph;
394 }
395 else if (lastEph && prevEph && prevEph->IOD() == newCorr->_iod) {
396 newCorr->_eph = prevEph;
397 switchToLastEph(lastEph, newCorr);
398 }
399 else {
400 emit newMessage("bncComb: eph not found " + prn.toAscii() +
401 QString(" %1").arg(newCorr->_iod).toAscii(), true);
402 delete newCorr;
403 continue;
404 }
[2986]405 }
[6155]406
407 // Store correction into the buffer
408 // --------------------------------
409 QVector<cmbCorr*>& corrs = _buffer[newCorr->_time].corrs;
410 corrs.push_back(newCorr);
[2986]411 }
412
[3435]413 // Process previous Epoch(s)
414 // -------------------------
[5134]415 const double waitTime = 1.0 * _cmbSampl;
[3556]416 QListIterator<bncTime> itTime(_buffer.keys());
[3435]417 while (itTime.hasNext()) {
[3556]418 bncTime epoTime = itTime.next();
[6155]419 if (epoTime < lastTime - waitTime) {
[3556]420 _resTime = epoTime;
[3435]421 processEpoch();
422 }
[2927]423 }
[2898]424}
425
[2986]426// Change the correction so that it refers to last received ephemeris
427////////////////////////////////////////////////////////////////////////////
[6155]428void bncComb::switchToLastEph(const t_eph* lastEph, cmbCorr* corr) {
[3028]429
[6155]430 if (corr->_eph == lastEph) {
[3429]431 return;
432 }
433
[2987]434 ColumnVector oldXC(4);
435 ColumnVector oldVV(3);
[6155]436 corr->_eph->getCrd(corr->_time, oldXC, oldVV, false);
[2988]437
[2987]438 ColumnVector newXC(4);
439 ColumnVector newVV(3);
[6155]440 lastEph->getCrd(corr->_time, newXC, newVV, false);
[2988]441
442 ColumnVector dX = newXC.Rows(1,3) - oldXC.Rows(1,3);
[2989]443 ColumnVector dV = newVV - oldVV;
444 double dC = newXC(4) - oldXC(4);
445
[2988]446 ColumnVector dRAO(3);
447 XYZ_to_RSW(newXC.Rows(1,3), newVV, dX, dRAO);
[2989]448
449 ColumnVector dDotRAO(3);
450 XYZ_to_RSW(newXC.Rows(1,3), newVV, dV, dDotRAO);
451
[6155]452 QString msg = "switch corr " + corr->_prn
453 + QString(" %1 -> %2 %3").arg(corr->_iod,3).arg(lastEph->IOD(),3).arg(dC*t_CST::c, 8, 'f', 4);
[3013]454
[3029]455 emit newMessage(msg.toAscii(), false);
[3028]456
[6155]457 corr->_iod = lastEph->IOD();
458 corr->_eph = lastEph;
459
460 if (corr->_clkCorr) {
461 corr->_clkCorr->_dClk -= dC;
462 }
463 if (corr->_orbCorr) {
464 for (int ii = 0; ii < 3; ii++) {
465 corr->_orbCorr->_xr[ii] += dRAO[ii];
466 corr->_orbCorr->_dotXr[ii] += dDotRAO[ii];
467 }
468 }
[2986]469}
470
[3429]471// Process Epoch
[2928]472////////////////////////////////////////////////////////////////////////////
[3429]473void bncComb::processEpoch() {
[2918]474
[2990]475 _log.clear();
476
477 QTextStream out(&_log, QIODevice::WriteOnly);
478
[3472]479 out << endl << "Combination:" << endl
480 << "------------------------------" << endl;
[2990]481
[3433]482 // Observation Statistics
483 // ----------------------
[3455]484 bool masterPresent = false;
[3433]485 QListIterator<cmbAC*> icAC(_ACs);
486 while (icAC.hasNext()) {
487 cmbAC* AC = icAC.next();
488 AC->numObs = 0;
[3434]489 QVectorIterator<cmbCorr*> itCorr(corrs());
[3433]490 while (itCorr.hasNext()) {
491 cmbCorr* corr = itCorr.next();
[6157]492 if (corr->_acName == AC->name) {
[3433]493 AC->numObs += 1;
[3453]494 if (AC->name == _masterOrbitAC) {
495 masterPresent = true;
496 }
[3433]497 }
498 }
499 out << AC->name.toAscii().data() << ": " << AC->numObs << endl;
500 }
501
[3453]502 // If Master not present, switch to another one
503 // --------------------------------------------
[4889]504 const unsigned switchMasterAfterGap = 1;
[3456]505 if (masterPresent) {
506 _masterMissingEpochs = 0;
507 }
508 else {
[3455]509 ++_masterMissingEpochs;
[4889]510 if (_masterMissingEpochs < switchMasterAfterGap) {
[3457]511 out << "Missing Master, Epoch skipped" << endl;
[3556]512 _buffer.remove(_resTime);
[3455]513 emit newMessage(_log, false);
514 return;
[3453]515 }
[3455]516 else {
517 _masterMissingEpochs = 0;
518 QListIterator<cmbAC*> icAC(_ACs);
519 while (icAC.hasNext()) {
520 cmbAC* AC = icAC.next();
521 if (AC->numObs > 0) {
522 out << "Switching Master AC "
523 << _masterOrbitAC.toAscii().data() << " --> "
524 << AC->name.toAscii().data() << " "
525 << _resTime.datestr().c_str() << " "
526 << _resTime.timestr().c_str() << endl;
527 _masterOrbitAC = AC->name;
528 break;
529 }
[3452]530 }
531 }
532 }
533
[6157]534 QMap<QString, cmbCorr*> resCorr;
[3472]535
536 // Perform the actual Combination using selected Method
537 // ----------------------------------------------------
538 t_irc irc;
[3475]539 ColumnVector dx;
[3472]540 if (_method == filter) {
[3475]541 irc = processEpoch_filter(out, resCorr, dx);
[3472]542 }
543 else {
[3475]544 irc = processEpoch_singleEpoch(out, resCorr, dx);
[3472]545 }
546
[3475]547 // Update Parameter Values, Print Results
548 // --------------------------------------
[3472]549 if (irc == success) {
[3475]550 for (int iPar = 1; iPar <= _params.size(); iPar++) {
551 cmbParam* pp = _params[iPar-1];
552 pp->xx += dx(iPar);
553 if (pp->type == cmbParam::clkSat) {
554 if (resCorr.find(pp->prn) != resCorr.end()) {
[6157]555 resCorr[pp->prn]->_dClk = pp->xx / t_CST::c;
[3475]556 }
557 }
558 out << _resTime.datestr().c_str() << " "
559 << _resTime.timestr().c_str() << " ";
560 out.setRealNumberNotation(QTextStream::FixedNotation);
561 out.setFieldWidth(8);
562 out.setRealNumberPrecision(4);
563 out << pp->toString() << " "
564 << pp->xx << " +- " << sqrt(_QQ(pp->index,pp->index)) << endl;
565 out.setFieldWidth(0);
566 }
[3472]567 printResults(out, resCorr);
568 dumpResults(resCorr);
569 }
570
571 // Delete Data, emit Message
572 // -------------------------
[3556]573 _buffer.remove(_resTime);
[3472]574 emit newMessage(_log, false);
575}
576
577// Process Epoch - Filter Method
578////////////////////////////////////////////////////////////////////////////
579t_irc bncComb::processEpoch_filter(QTextStream& out,
[6157]580 QMap<QString, cmbCorr*>& resCorr,
[3475]581 ColumnVector& dx) {
[3472]582
[3429]583 // Prediction Step
584 // ---------------
[3472]585 int nPar = _params.size();
[2933]586 ColumnVector x0(nPar);
587 for (int iPar = 1; iPar <= _params.size(); iPar++) {
[3455]588 cmbParam* pp = _params[iPar-1];
589 if (pp->epoSpec) {
[3451]590 pp->xx = 0.0;
[3455]591 _QQ.Row(iPar) = 0.0;
592 _QQ.Column(iPar) = 0.0;
593 _QQ(iPar,iPar) = pp->sig0 * pp->sig0;
[3451]594 }
[3455]595 else {
596 _QQ(iPar,iPar) += pp->sigP * pp->sigP;
597 }
[2933]598 x0(iPar) = pp->xx;
599 }
600
[3487]601 // Check Satellite Positions for Outliers
602 // --------------------------------------
[3497]603 if (checkOrbits(out) != success) {
[3487]604 return failure;
605 }
[3441]606
[3455]607 // Update and outlier detection loop
608 // ---------------------------------
[3487]609 SymmetricMatrix QQ_sav = _QQ;
[3455]610 while (true) {
[3135]611
[3455]612 Matrix AA;
613 ColumnVector ll;
614 DiagonalMatrix PP;
[3429]615
[3455]616 if (createAmat(AA, ll, PP, x0, resCorr) != success) {
[3472]617 return failure;
[3441]618 }
[2933]619
[5867]620 dx = 0.0;
[5808]621 kalman(AA, ll, PP, _QQ, dx);
[3429]622 ColumnVector vv = ll - AA * dx;
[3080]623
[3429]624 int maxResIndex;
625 double maxRes = vv.maximum_absolute_value1(maxResIndex);
626 out.setRealNumberNotation(QTextStream::FixedNotation);
627 out.setRealNumberPrecision(3);
628 out << _resTime.datestr().c_str() << " " << _resTime.timestr().c_str()
[3432]629 << " Maximum Residuum " << maxRes << ' '
[6157]630 << corrs()[maxResIndex-1]->_acName << ' ' << corrs()[maxResIndex-1]->_prn;
[3080]631
[3432]632 if (maxRes > _MAXRES) {
633 for (int iPar = 1; iPar <= _params.size(); iPar++) {
634 cmbParam* pp = _params[iPar-1];
635 if (pp->type == cmbParam::offACSat &&
[6157]636 pp->AC == corrs()[maxResIndex-1]->_acName &&
637 pp->prn == corrs()[maxResIndex-1]->_prn) {
[3432]638 QQ_sav.Row(iPar) = 0.0;
639 QQ_sav.Column(iPar) = 0.0;
[3455]640 QQ_sav(iPar,iPar) = pp->sig0 * pp->sig0;
[3432]641 }
642 }
643
644 out << " Outlier" << endl;
645 _QQ = QQ_sav;
[3455]646 corrs().remove(maxResIndex-1);
[3432]647 }
648 else {
649 out << " OK" << endl;
650 break;
651 }
652 }
653
[3472]654 return success;
[2918]655}
[3011]656
[3201]657// Print results
[3011]658////////////////////////////////////////////////////////////////////////////
[3429]659void bncComb::printResults(QTextStream& out,
[6157]660 const QMap<QString, cmbCorr*>& resCorr) {
[3011]661
[6157]662 QMapIterator<QString, cmbCorr*> it(resCorr);
[3011]663 while (it.hasNext()) {
664 it.next();
[6157]665 cmbCorr* corr = it.value();
666 const t_eph* eph = corr->_eph;
[3015]667 if (eph) {
[6109]668 ColumnVector xc(4);
669 ColumnVector vv(3);
670 eph->getCrd(_resTime, xc, vv, false);
[3015]671
[3429]672 out << _resTime.datestr().c_str() << " "
673 << _resTime.timestr().c_str() << " ";
[3015]674 out.setFieldWidth(3);
[6157]675 out << "Full Clock " << corr->_prn << " " << corr->_iod << " ";
[3015]676 out.setFieldWidth(14);
[6157]677 out << (xc(4) + corr->_dClk) * t_CST::c << endl;
[3370]678 out.setFieldWidth(0);
[3015]679 }
680 else {
681 out << "bncComb::printResuls bug" << endl;
682 }
[3011]683 }
684}
[3202]685
686// Send results to RTNet Decoder and directly to PPP Client
687////////////////////////////////////////////////////////////////////////////
[6157]688void bncComb::dumpResults(const QMap<QString, cmbCorr*>& resCorr) {
[3202]689
[5337]690 QString outLines;
691 QStringList corrLines;
[3214]692
693 unsigned year, month, day, hour, minute;
694 double sec;
[3429]695 _resTime.civil_date(year, month, day);
696 _resTime.civil_time(hour, minute, sec);
[3214]697
[5337]698 outLines.sprintf("* %4d %2d %2d %d %d %12.8f\n",
699 year, month, day, hour, minute, sec);
[3214]700
[6157]701 QMapIterator<QString, cmbCorr*> it(resCorr);
[3202]702 while (it.hasNext()) {
703 it.next();
[6157]704 cmbCorr* corr = it.value();
[3202]705
[4978]706 ColumnVector xc(4);
707 ColumnVector vv(3);
[6157]708 corr->_eph->getCrd(_resTime, xc, vv, false);
[4978]709
710 // Correction Phase Center --> CoM
711 // -------------------------------
712 ColumnVector dx(3); dx = 0.0;
713 if (_antex) {
714 double Mjd = _resTime.mjd() + _resTime.daysec()/86400.0;
[6157]715 if (_antex->satCoMcorrection(corr->_prn, Mjd, xc.Rows(1,3), dx) != success) {
[4992]716 dx = 0;
[6157]717 cout << "antenna not found " << corr->_prn.toAscii().data() << endl;
[3214]718 }
719 }
[4978]720
[6157]721 outLines += corr->_prn;
[5337]722 QString hlp;
723 hlp.sprintf(" APC 3 %15.4f %15.4f %15.4f"
724 " Clk 1 %15.4f"
725 " Vel 3 %15.4f %15.4f %15.4f"
726 " CoM 3 %15.4f %15.4f %15.4f\n",
727 xc(1), xc(2), xc(3),
728 xc(4)*t_CST::c,
729 vv(1), vv(2), vv(3),
730 xc(1)-dx(1), xc(2)-dx(2), xc(3)-dx(3));
731 outLines += hlp;
732
[4978]733 QString line;
[5564]734 int messageType = COTYPE_GPSCOMBINED;
735 int updateInt = 0;
[4978]736 line.sprintf("%d %d %d %.1f %s"
737 " %3d"
738 " %8.3f %8.3f %8.3f %8.3f"
739 " %10.5f %10.5f %10.5f %10.5f"
[5576]740 " %10.5f INTERNAL",
[4978]741 messageType, updateInt, _resTime.gpsw(), _resTime.gpssec(),
[6157]742 corr->_prn.toAscii().data(),
743 corr->_iod,
744 corr->_dClk * t_CST::c,
745 corr->_orbCorr->_xr[0],
746 corr->_orbCorr->_xr[1],
747 corr->_orbCorr->_xr[2],
748 0.0,
749 corr->_orbCorr->_dotXr[0],
750 corr->_orbCorr->_dotXr[1],
751 corr->_orbCorr->_dotXr[2],
752 0.0);
[4978]753 corrLines << line;
754
[3214]755 delete corr;
756 }
757
[5337]758 outLines += "EOE\n"; // End Of Epoch flag
759
[3215]760 if (!_rtnetDecoder) {
761 _rtnetDecoder = new bncRtnetDecoder();
762 }
[3221]763
[3215]764 vector<string> errmsg;
[5337]765 _rtnetDecoder->Decode(outLines.toAscii().data(), outLines.length(), errmsg);
[3215]766
[5861]767 // Send new Corrections to PPP etc.
768 // --------------------------------
[6157]769 //// emit newCorrections(corrLines);
[3202]770}
[3455]771
772// Create First Design Matrix and Vector of Measurements
773////////////////////////////////////////////////////////////////////////////
774t_irc bncComb::createAmat(Matrix& AA, ColumnVector& ll, DiagonalMatrix& PP,
775 const ColumnVector& x0,
[6157]776 QMap<QString, cmbCorr*>& resCorr) {
[3455]777
778 unsigned nPar = _params.size();
779 unsigned nObs = corrs().size();
780
781 if (nObs == 0) {
782 return failure;
783 }
784
[5742]785 int maxSat = t_prn::MAXPRN_GPS;
[3486]786// if (_useGlonass) {
[5742]787// maxSat = t_prn::MAXPRN_GPS + t_prn::MAXPRN_GLONASS;
[3486]788// }
[3455]789
[5742]790 const int nCon = (_method == filter) ? 1 + maxSat : 0;
[3483]791
[3455]792 AA.ReSize(nObs+nCon, nPar); AA = 0.0;
793 ll.ReSize(nObs+nCon); ll = 0.0;
794 PP.ReSize(nObs+nCon); PP = 1.0 / (sigObs * sigObs);
795
796 int iObs = 0;
797
798 QVectorIterator<cmbCorr*> itCorr(corrs());
799 while (itCorr.hasNext()) {
800 cmbCorr* corr = itCorr.next();
[6157]801 QString prn = corr->_prn;
[3487]802
[3455]803 ++iObs;
804
[6157]805 if (corr->_acName == _masterOrbitAC && resCorr.find(prn) == resCorr.end()) {
806 resCorr[prn] = new cmbCorr(*corr);
[3455]807 }
808
809 for (int iPar = 1; iPar <= _params.size(); iPar++) {
810 cmbParam* pp = _params[iPar-1];
[6157]811 AA(iObs, iPar) = pp->partial(corr->_acName, prn);
[3455]812 }
813
[6157]814 ll(iObs) = corr->_dClk * t_CST::c - DotProduct(AA.Row(iObs), x0);
[3455]815 }
816
817 // Regularization
818 // --------------
[3474]819 if (_method == filter) {
820 const double Ph = 1.e6;
821 PP(nObs+1) = Ph;
[3461]822 for (int iPar = 1; iPar <= _params.size(); iPar++) {
823 cmbParam* pp = _params[iPar-1];
[3465]824 if ( AA.Column(iPar).maximum_absolute_value() > 0.0 &&
[3474]825 pp->type == cmbParam::clkSat ) {
826 AA(nObs+1, iPar) = 1.0;
[3455]827 }
828 }
[3474]829 int iCond = 1;
[5808]830 for (unsigned iGps = 1; iGps <= t_prn::MAXPRN_GPS; iGps++) {
[3474]831 QString prn = QString("G%1").arg(iGps, 2, 10, QChar('0'));
832 ++iCond;
833 PP(nObs+iCond) = Ph;
834 for (int iPar = 1; iPar <= _params.size(); iPar++) {
835 cmbParam* pp = _params[iPar-1];
836 if ( AA.Column(iPar).maximum_absolute_value() > 0.0 &&
837 pp->type == cmbParam::offACSat &&
838 pp->prn == prn) {
839 AA(nObs+iCond, iPar) = 1.0;
840 }
841 }
842 }
[3486]843// if (_useGlonass) {
[5742]844// for (int iGlo = 1; iGlo <= t_prn::MAXPRN_GLONASS; iGlo++) {
[3486]845// QString prn = QString("R%1").arg(iGlo, 2, 10, QChar('0'));
846// ++iCond;
847// PP(nObs+iCond) = Ph;
848// for (int iPar = 1; iPar <= _params.size(); iPar++) {
849// cmbParam* pp = _params[iPar-1];
850// if ( AA.Column(iPar).maximum_absolute_value() > 0.0 &&
851// pp->type == cmbParam::offACSat &&
852// pp->prn == prn) {
853// AA(nObs+iCond, iPar) = 1.0;
854// }
855// }
856// }
857// }
[3455]858 }
859
860 return success;
861}
[3470]862
863// Process Epoch - Single-Epoch Method
864////////////////////////////////////////////////////////////////////////////
[3472]865t_irc bncComb::processEpoch_singleEpoch(QTextStream& out,
[6157]866 QMap<QString, cmbCorr*>& resCorr,
[3475]867 ColumnVector& dx) {
[3470]868
[3487]869 // Check Satellite Positions for Outliers
870 // --------------------------------------
[3497]871 if (checkOrbits(out) != success) {
[3487]872 return failure;
873 }
874
[3482]875 // Outlier Detection Loop
876 // ----------------------
877 while (true) {
878
879 // Remove Satellites that are not in Master
880 // ----------------------------------------
881 QMutableVectorIterator<cmbCorr*> it(corrs());
882 while (it.hasNext()) {
883 cmbCorr* corr = it.next();
[6157]884 QString prn = corr->_prn;
[3482]885 bool foundMaster = false;
886 QVectorIterator<cmbCorr*> itHlp(corrs());
887 while (itHlp.hasNext()) {
888 cmbCorr* corrHlp = itHlp.next();
[6157]889 QString prnHlp = corrHlp->_prn;
890 QString ACHlp = corrHlp->_acName;
[3482]891 if (ACHlp == _masterOrbitAC && prn == prnHlp) {
892 foundMaster = true;
893 break;
894 }
[3476]895 }
[3482]896 if (!foundMaster) {
[3556]897 delete corr;
[3482]898 it.remove();
899 }
[3473]900 }
[3482]901
902 // Count Number of Observations per Satellite and per AC
903 // -----------------------------------------------------
904 QMap<QString, int> numObsPrn;
905 QMap<QString, int> numObsAC;
906 QVectorIterator<cmbCorr*> itCorr(corrs());
907 while (itCorr.hasNext()) {
908 cmbCorr* corr = itCorr.next();
[6157]909 QString prn = corr->_prn;
910 QString AC = corr->_acName;
[3482]911 if (numObsPrn.find(prn) == numObsPrn.end()) {
912 numObsPrn[prn] = 1;
913 }
914 else {
915 numObsPrn[prn] += 1;
916 }
917 if (numObsAC.find(AC) == numObsAC.end()) {
918 numObsAC[AC] = 1;
919 }
920 else {
921 numObsAC[AC] += 1;
922 }
[3476]923 }
[3482]924
925 // Clean-Up the Paramters
926 // ----------------------
927 for (int iPar = 1; iPar <= _params.size(); iPar++) {
928 delete _params[iPar-1];
[3474]929 }
[3482]930 _params.clear();
931
932 // Set new Parameters
933 // ------------------
934 int nextPar = 0;
935
936 QMapIterator<QString, int> itAC(numObsAC);
937 while (itAC.hasNext()) {
938 itAC.next();
939 const QString& AC = itAC.key();
940 int numObs = itAC.value();
941 if (AC != _masterOrbitAC && numObs > 0) {
[3485]942 _params.push_back(new cmbParam(cmbParam::offACgps, ++nextPar, AC, ""));
943 if (_useGlonass) {
944 _params.push_back(new cmbParam(cmbParam::offACglo, ++nextPar, AC, ""));
945 }
[3482]946 }
947 }
948
949 QMapIterator<QString, int> itPrn(numObsPrn);
950 while (itPrn.hasNext()) {
951 itPrn.next();
952 const QString& prn = itPrn.key();
953 int numObs = itPrn.value();
954 if (numObs > 0) {
955 _params.push_back(new cmbParam(cmbParam::clkSat, ++nextPar, "", prn));
956 }
957 }
958
959 int nPar = _params.size();
960 ColumnVector x0(nPar);
961 x0 = 0.0;
962
963 // Create First-Design Matrix
964 // --------------------------
965 Matrix AA;
966 ColumnVector ll;
967 DiagonalMatrix PP;
968 if (createAmat(AA, ll, PP, x0, resCorr) != success) {
969 return failure;
[3476]970 }
[3482]971
972 ColumnVector vv;
973 try {
974 Matrix ATP = AA.t() * PP;
975 SymmetricMatrix NN; NN << ATP * AA;
976 ColumnVector bb = ATP * ll;
977 _QQ = NN.i();
978 dx = _QQ * bb;
979 vv = ll - AA * dx;
[3476]980 }
[3482]981 catch (Exception& exc) {
982 out << exc.what() << endl;
983 return failure;
[3476]984 }
[3474]985
[3482]986 int maxResIndex;
987 double maxRes = vv.maximum_absolute_value1(maxResIndex);
988 out.setRealNumberNotation(QTextStream::FixedNotation);
989 out.setRealNumberPrecision(3);
990 out << _resTime.datestr().c_str() << " " << _resTime.timestr().c_str()
991 << " Maximum Residuum " << maxRes << ' '
[6157]992 << corrs()[maxResIndex-1]->_acName << ' ' << corrs()[maxResIndex-1]->_prn;
[3474]993
[3482]994 if (maxRes > _MAXRES) {
995 out << " Outlier" << endl;
[3556]996 delete corrs()[maxResIndex-1];
[3482]997 corrs().remove(maxResIndex-1);
[3474]998 }
[3482]999 else {
1000 out << " OK" << endl;
1001 out.setRealNumberNotation(QTextStream::FixedNotation);
1002 out.setRealNumberPrecision(3);
1003 for (int ii = 0; ii < vv.Nrows(); ii++) {
1004 const cmbCorr* corr = corrs()[ii];
1005 out << _resTime.datestr().c_str() << ' '
1006 << _resTime.timestr().c_str() << " "
[6157]1007 << corr->_acName << ' ' << corr->_prn;
[3482]1008 out.setFieldWidth(6);
[6157]1009 out << " dClk = " << corr->_dClk * t_CST::c << " res = " << vv[ii] << endl;
[3482]1010 out.setFieldWidth(0);
1011 }
1012 return success;
[3474]1013 }
1014
[3473]1015 }
[3474]1016
[3482]1017 return failure;
[3470]1018}
[3487]1019
1020// Check Satellite Positions for Outliers
1021////////////////////////////////////////////////////////////////////////////
[3497]1022t_irc bncComb::checkOrbits(QTextStream& out) {
[3487]1023
[3489]1024 const double MAX_DISPLACEMENT = 0.20;
[3488]1025
[3502]1026 // Switch to last ephemeris (if possible)
1027 // --------------------------------------
[3501]1028 QMutableVectorIterator<cmbCorr*> im(corrs());
1029 while (im.hasNext()) {
1030 cmbCorr* corr = im.next();
[6157]1031 QString prn = corr->_prn;
[3503]1032 if (_eph.find(prn) == _eph.end()) {
[6157]1033 out << "checkOrbit: missing eph (not found) " << corr->_prn << endl;
[3556]1034 delete corr;
[3501]1035 im.remove();
1036 }
[6157]1037 else if (corr->_eph == 0) {
1038 out << "checkOrbit: missing eph (zero) " << corr->_prn << endl;
[3556]1039 delete corr;
[3503]1040 im.remove();
1041 }
[3502]1042 else {
[6157]1043 if ( corr->_eph == _eph[prn]->last || corr->_eph == _eph[prn]->prev ) {
[3502]1044 switchToLastEph(_eph[prn]->last, corr);
1045 }
1046 else {
[6157]1047 out << "checkOrbit: missing eph (deleted) " << corr->_prn << endl;
[3556]1048 delete corr;
[3502]1049 im.remove();
1050 }
1051 }
[3501]1052 }
1053
[3488]1054 while (true) {
1055
1056 // Compute Mean Corrections for all Satellites
1057 // -------------------------------------------
[3489]1058 QMap<QString, int> numCorr;
[3488]1059 QMap<QString, ColumnVector> meanRao;
1060 QVectorIterator<cmbCorr*> it(corrs());
1061 while (it.hasNext()) {
1062 cmbCorr* corr = it.next();
[6157]1063 QString prn = corr->_prn;
[3488]1064 if (meanRao.find(prn) == meanRao.end()) {
1065 meanRao[prn].ReSize(4);
[6157]1066 meanRao[prn].Rows(1,3) = corr->_orbCorr->_xr;
[3488]1067 meanRao[prn](4) = 1;
1068 }
1069 else {
[6157]1070 meanRao[prn].Rows(1,3) += corr->_orbCorr->_xr;
[3488]1071 meanRao[prn](4) += 1;
1072 }
[3489]1073 if (numCorr.find(prn) == numCorr.end()) {
1074 numCorr[prn] = 1;
1075 }
1076 else {
1077 numCorr[prn] += 1;
1078 }
[3487]1079 }
[3488]1080
1081 // Compute Differences wrt Mean, find Maximum
1082 // ------------------------------------------
1083 QMap<QString, cmbCorr*> maxDiff;
1084 it.toFront();
1085 while (it.hasNext()) {
1086 cmbCorr* corr = it.next();
[6157]1087 QString prn = corr->_prn;
[3488]1088 if (meanRao[prn](4) != 0) {
1089 meanRao[prn] /= meanRao[prn](4);
1090 meanRao[prn](4) = 0;
1091 }
[6157]1092 corr->_diffRao = corr->_orbCorr->_xr - meanRao[prn].Rows(1,3);
[3488]1093 if (maxDiff.find(prn) == maxDiff.end()) {
1094 maxDiff[prn] = corr;
1095 }
1096 else {
[6157]1097 double normMax = maxDiff[prn]->_diffRao.norm_Frobenius();
1098 double norm = corr->_diffRao.norm_Frobenius();
[3488]1099 if (norm > normMax) {
1100 maxDiff[prn] = corr;
1101 }
1102 }
[3487]1103 }
[3488]1104
[3655]1105 if (_ACs.size() == 1) {
1106 break;
1107 }
1108
[3488]1109 // Remove Outliers
1110 // ---------------
1111 bool removed = false;
1112 QMutableVectorIterator<cmbCorr*> im(corrs());
1113 while (im.hasNext()) {
1114 cmbCorr* corr = im.next();
[6157]1115 QString prn = corr->_prn;
[3489]1116 if (numCorr[prn] < 2) {
[3556]1117 delete corr;
[3489]1118 im.remove();
1119 }
1120 else if (corr == maxDiff[prn]) {
[6157]1121 double norm = corr->_diffRao.norm_Frobenius();
[3488]1122 if (norm > MAX_DISPLACEMENT) {
[3497]1123 out << _resTime.datestr().c_str() << " "
1124 << _resTime.timestr().c_str() << " "
1125 << "Orbit Outlier: "
[6157]1126 << corr->_acName.toAscii().data() << " "
1127 << prn.toAscii().data() << " "
1128 << corr->_iod << " "
1129 << norm << endl;
[3556]1130 delete corr;
[3488]1131 im.remove();
1132 removed = true;
1133 }
1134 }
[3487]1135 }
[3488]1136
1137 if (!removed) {
1138 break;
1139 }
[3487]1140 }
1141
1142 return success;
1143}
[3588]1144
1145//
1146////////////////////////////////////////////////////////////////////////////
[5583]1147void bncComb::slotProviderIDChanged(QString mountPoint) {
1148 QMutexLocker locker(&_mutex);
1149
1150 // Find the AC Name
1151 // ----------------
1152 QString acName;
1153 QListIterator<cmbAC*> icAC(_ACs);
1154 while (icAC.hasNext()) {
1155 cmbAC* AC = icAC.next();
1156 if (AC->mountPoint == mountPoint) {
1157 acName = AC->name;
1158 break;
1159 }
1160 }
1161 if (acName.isEmpty()) {
1162 return;
1163 }
1164
1165 // Remove all corrections of the corresponding AC
1166 // ----------------------------------------------
1167 QListIterator<bncTime> itTime(_buffer.keys());
1168 while (itTime.hasNext()) {
1169 bncTime epoTime = itTime.next();
1170 QVector<cmbCorr*>& corrVec = _buffer[epoTime].corrs;
[5584]1171 QMutableVectorIterator<cmbCorr*> it(corrVec);
[5583]1172 while (it.hasNext()) {
1173 cmbCorr* corr = it.next();
[6157]1174 if (acName == corr->_acName) {
[5584]1175 delete corr;
1176 it.remove();
[5583]1177 }
1178 }
1179 }
[5585]1180
1181 // Reset Satellite Offsets
1182 // -----------------------
1183 if (_method == filter) {
1184 for (int iPar = 1; iPar <= _params.size(); iPar++) {
1185 cmbParam* pp = _params[iPar-1];
1186 if (pp->AC == acName && pp->type == cmbParam::offACSat) {
1187 pp->xx = 0.0;
1188 _QQ.Row(iPar) = 0.0;
1189 _QQ.Column(iPar) = 0.0;
1190 _QQ(iPar,iPar) = pp->sig0 * pp->sig0;
1191 }
1192 }
1193 }
[5583]1194}
Note: See TracBrowser for help on using the repository browser.