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

Last change on this file since 9631 was 9546, checked in by stuerze, 4 years ago

minor changes

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