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

Last change on this file since 10019 was 10019, checked in by stuerze, 13 months ago

minor changes

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