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

Last change on this file since 9819 was 9819, checked in by stuerze, 3 months ago

minor chenges to allow streams without code biases within the combination

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