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

Last change on this file since 9683 was 9676, checked in by stuerze, 2 years ago

combination is extended to use/provide Code Biases

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