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

Last change on this file since 10035 was 10035, checked in by stuerze, 12 months ago

minor changes

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