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

Last change on this file since 10096 was 10096, checked in by stuerze, 16 months ago

minor changes

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