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

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

minor changes to read the bsx file every 6 hours

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