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

Last change on this file since 10078 was 10078, checked in by stuerze, 11 months ago

check regarding current time added in combination

File size: 44.9 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: definition class variable
117////////////////////////////////////////////////////////////////////////////
118bncComb* bncComb::instance = nullptr;
119
120
121// Constructor
122////////////////////////////////////////////////////////////////////////////
123bncComb::bncComb() : _ephUser(true) {
124
125 bncSettings settings;
126
127 QStringList cmbStreams = settings.value("cmbStreams").toStringList();
128
129 _cmbSampl = settings.value("cmbSampl").toInt();
130 if (_cmbSampl <= 0) {
131 _cmbSampl = 5;
132 }
133 _useGps = (Qt::CheckState(settings.value("cmbGps").toInt()) == Qt::Checked) ? true : false;
134 if (_useGps) {
135 _cmbSysPrn['G'] = t_prn::MAXPRN_GPS;
136 _masterMissingEpochs['G'] = 0;
137 }
138 _useGlo = (Qt::CheckState(settings.value("cmbGlo").toInt()) == Qt::Checked) ? true : false;
139 if (_useGlo) {
140 _cmbSysPrn['R'] = t_prn::MAXPRN_GLONASS;
141 _masterMissingEpochs['R'] = 0;
142 }
143 _useGal = (Qt::CheckState(settings.value("cmbGal").toInt()) == Qt::Checked) ? true : false;
144 if (_useGal) {
145 _cmbSysPrn['E'] = t_prn::MAXPRN_GALILEO;
146 _masterMissingEpochs['E'] = 0;
147 }
148 _useBds = (Qt::CheckState(settings.value("cmbBds").toInt()) == Qt::Checked) ? true : false;
149 if (_useBds) {
150 _cmbSysPrn['C'] = t_prn::MAXPRN_BDS;
151 _masterMissingEpochs['C'] = 0;
152 }
153 _useQzss = (Qt::CheckState(settings.value("cmbQzss").toInt()) == Qt::Checked) ? true : false;
154 if (_useQzss) {
155 _cmbSysPrn['J'] = t_prn::MAXPRN_QZSS;
156 _masterMissingEpochs['J'] = 0;
157 }
158 _useSbas = (Qt::CheckState(settings.value("cmbSbas").toInt()) == Qt::Checked) ? true : false;
159 if (_useSbas) {
160 _cmbSysPrn['S'] = t_prn::MAXPRN_SBAS;
161 _masterMissingEpochs['S'] = 0;
162 }
163 _useIrnss = (Qt::CheckState(settings.value("cmbIrnss").toInt()) == Qt::Checked) ? true : false;
164 if (_useIrnss) {
165 _cmbSysPrn['I'] = t_prn::MAXPRN_IRNSS;
166 _masterMissingEpochs['I'] = 0;
167 }
168
169 if (cmbStreams.size() >= 1 && !cmbStreams[0].isEmpty()) {
170 QListIterator<QString> it(cmbStreams);
171 while (it.hasNext()) {
172 QStringList hlp = it.next().split(" ");
173 cmbAC* newAC = new cmbAC();
174 newAC->mountPoint = hlp[0];
175 newAC->name = hlp[1];
176 newAC->weightFactor = hlp[2].toDouble();
177 QMapIterator<char, unsigned> itSys(_cmbSysPrn);
178 // init
179 while (itSys.hasNext()) {
180 itSys.next();
181 char sys = itSys.key();
182 if (_masterOrbitAC.isEmpty()) {
183 _masterOrbitAC[sys] = newAC->name;
184 }
185 }
186 _ACs.append(newAC);
187 }
188 }
189
190 QString ssrFormat;
191 _ssrCorr = 0;
192 QListIterator<QString> it(settings.value("uploadMountpointsOut").toStringList());
193 while (it.hasNext()) {
194 QStringList hlp = it.next().split(",");
195 if (hlp.size() > 7) {
196 ssrFormat = hlp[7];
197 }
198 }
199 if (ssrFormat == "IGS-SSR") {
200 _ssrCorr = new SsrCorrIgs();
201 }
202 else if (ssrFormat == "RTCM-SSR") {
203 _ssrCorr = new SsrCorrRtcm();
204 }
205 else { // default
206 _ssrCorr = new SsrCorrIgs();
207 }
208
209 _rtnetDecoder = 0;
210
211 connect(this, SIGNAL(newMessage(QByteArray,bool)), BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
212 connect(BNC_CORE, SIGNAL(providerIDChanged(QString)), this, SLOT(slotProviderIDChanged(QString)));
213 connect(BNC_CORE, SIGNAL(newOrbCorrections(QList<t_orbCorr>)), this, SLOT(slotNewOrbCorrections(QList<t_orbCorr>)));
214 connect(BNC_CORE, SIGNAL(newClkCorrections(QList<t_clkCorr>)), this, SLOT(slotNewClkCorrections(QList<t_clkCorr>)));
215 connect(BNC_CORE, SIGNAL(newCodeBiases(QList<t_satCodeBias>)), this, SLOT(slotNewCodeBiases(QList<t_satCodeBias>)));
216
217 // Combination Method
218 // ------------------
219 if (settings.value("cmbMethod").toString() == "Single-Epoch") {
220 _method = singleEpoch;
221 }
222 else {
223 _method = filter;
224 }
225
226 // Initialize Parameters (model: Clk_Corr = AC_Offset + Sat_Offset + Clk)
227 // ----------------------------------------------------------------------
228 if (_method == filter) {
229 // SYSTEM
230 QMapIterator<char, unsigned> itSys(_cmbSysPrn);
231 while (itSys.hasNext()) {
232 itSys.next();
233 int nextPar = 0;
234 char sys = itSys.key();
235 unsigned maxPrn = itSys.value();
236 unsigned flag = 0;
237 if (sys == 'E') {
238 flag = 1;
239 }
240 // AC
241 QListIterator<cmbAC*> itAc(_ACs);
242 while (itAc.hasNext()) {
243 cmbAC* AC = itAc.next();
244 _params[sys].push_back(new cmbParam(cmbParam::offACgnss, ++nextPar, AC->name, ""));
245 for (unsigned iGnss = 1; iGnss <= maxPrn; iGnss++) {
246 QString prn = QString("%1%2_%3").arg(sys).arg(iGnss, 2, 10, QChar('0')).arg(flag);
247 _params[sys].push_back(new cmbParam(cmbParam::offACSat, ++nextPar, AC->name, prn));
248 }
249 }
250 for (unsigned iGnss = 1; iGnss <= maxPrn; iGnss++) {
251 QString prn = QString("%1%2_%3").arg(sys).arg(iGnss, 2, 10, QChar('0')).arg(flag);
252 _params[sys].push_back(new cmbParam(cmbParam::clkSat, ++nextPar, "", prn));
253 }
254 // Initialize Variance-Covariance Matrix
255 // -------------------------------------
256 _QQ[sys].ReSize(_params[sys].size());
257 _QQ[sys] = 0.0;
258 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
259 cmbParam* pp = _params[sys][iPar-1];
260 _QQ[sys](iPar,iPar) = pp->sig0 * pp->sig0;
261 }
262 }
263 }
264
265 // ANTEX File
266 // ----------
267 _antex = 0;
268 QString antexFileName = settings.value("uploadAntexFile").toString();
269 if (!antexFileName.isEmpty()) {
270 _antex = new bncAntex();
271 if (_antex->readFile(antexFileName) != success) {
272 emit newMessage("bncCmb: wrong ANTEX file", true);
273 delete _antex;
274 _antex = 0;
275 }
276 }
277
278
279 // Bias SINEX File
280 // ---------------
281 _bsx = 0;
282 QString bsxFileName = settings.value("cmbBsxFile").toString();
283 if (!bsxFileName.isEmpty()) {
284 _bsx = new bncBiasSnx();
285 if (_bsx->readFile(bsxFileName) != success) {
286 emit newMessage("bncComb: wrong Bias SINEX file", true);
287 delete _bsx;
288 _bsx = 0;
289 }
290 }
291 if (_bsx) {
292 _ms = 6.0 * 3600 * 1000.0;
293 QTimer::singleShot(_ms, this, SLOT(slotReadBiasSnxFile()));
294 }
295
296
297 // Maximal Residuum
298 // ----------------
299 _MAXRES = settings.value("cmbMaxres").toDouble();
300 if (_MAXRES <= 0.0) {
301 _MAXRES = 999.0;
302 }
303}
304
305// Destructor
306////////////////////////////////////////////////////////////////////////////
307bncComb::~bncComb() {
308 QListIterator<cmbAC*> icAC(_ACs);
309 while (icAC.hasNext()) {
310 delete icAC.next();
311 }
312 delete _rtnetDecoder;
313 if (_ssrCorr) {
314 delete _ssrCorr;
315 }
316 delete _antex;
317 delete _bsx;
318
319 QMapIterator<char, unsigned> itSys(_cmbSysPrn);
320 while (itSys.hasNext()) {
321 itSys.next();
322 char sys = itSys.key();
323 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
324 delete _params[sys][iPar-1];
325 }
326 _buffer.remove(sys);
327 }
328 while (!_epoClkData.empty()) {
329 delete _epoClkData.front();
330 _epoClkData.pop_front();
331 }
332}
333
334void bncComb::slotReadBiasSnxFile() {
335 bncSettings settings;
336 QString bsxFileName = settings.value("cmbBsxFile").toString();
337
338 if (bsxFileName.isEmpty()) {
339 emit newMessage("bncComb: no Bias SINEX file specified", true);
340 return;
341 }
342 if (!_bsx) {
343 _bsx = new bncBiasSnx();
344 }
345 if (_bsx->readFile(bsxFileName) != success) {
346 emit newMessage("bncComb: wrong Bias SINEX file", true);
347 delete _bsx;
348 _bsx = 0;
349 }
350 else {
351 emit newMessage("bncComb: successfully read Bias SINEX file", true);
352 }
353
354 QTimer::singleShot(_ms, this, SLOT(slotReadBiasSnxFile()));
355}
356
357
358// Remember orbit corrections
359////////////////////////////////////////////////////////////////////////////
360void bncComb::slotNewOrbCorrections(QList<t_orbCorr> orbCorrections) {
361 QMutexLocker locker(&_mutex);
362
363 for (int ii = 0; ii < orbCorrections.size(); ii++) {
364 t_orbCorr& orbCorr = orbCorrections[ii];
365 QString staID(orbCorr._staID.c_str());
366 char sys = orbCorr._prn.system();
367
368 if (!_cmbSysPrn.contains(sys)){
369 continue;
370 }
371
372 // Find/Check the AC Name
373 // ----------------------
374 QString acName;
375 QListIterator<cmbAC*> icAC(_ACs);
376 while (icAC.hasNext()) {
377 cmbAC* AC = icAC.next();
378 if (AC->mountPoint == staID) {
379 acName = AC->name;
380 break;
381 }
382 }
383 if (acName.isEmpty()) {
384 continue;
385 }
386
387 // Store the correction
388 // --------------------
389 QMap<t_prn, t_orbCorr*>& storage = _orbCorrections[acName];
390 if (storage[orbCorr._prn]) {
391 delete storage[orbCorr._prn];
392 }
393 storage[orbCorr._prn] = new t_orbCorr(orbCorr);
394 }
395}
396
397// Remember Satellite Code Biases
398////////////////////////////////////////////////////////////////////////////
399void bncComb::slotNewCodeBiases(QList<t_satCodeBias> satCodeBiases) {
400 QMutexLocker locker(&_mutex);
401
402 for (int ii = 0; ii < satCodeBiases.size(); ii++) {
403 t_satCodeBias& satCodeBias = satCodeBiases[ii];
404 QString staID(satCodeBias._staID.c_str());
405 char sys = satCodeBias._prn.system();
406
407 if (!_cmbSysPrn.contains(sys)){
408 continue;
409 }
410
411 // Find/Check the AC Name
412 // ----------------------
413 QString acName;
414 QListIterator<cmbAC*> icAC(_ACs);
415 while (icAC.hasNext()) {
416 cmbAC* AC = icAC.next();
417 if (AC->mountPoint == staID) {
418 acName = AC->name;
419 break;
420 }
421 }
422 if (acName.isEmpty()) {
423 continue;
424 }
425
426 // Store the correction
427 // --------------------
428 QMap<t_prn, t_satCodeBias*>& storage = _satCodeBiases[acName];
429 if (storage[satCodeBias._prn]) {
430 delete storage[satCodeBias._prn];
431 }
432 storage[satCodeBias._prn] = new t_satCodeBias(satCodeBias);
433 }
434}
435
436// Process clock corrections
437////////////////////////////////////////////////////////////////////////////
438void bncComb::slotNewClkCorrections(QList<t_clkCorr> clkCorrections) {
439 QMutexLocker locker(&_mutex);
440 const double outWait = 1.0 * _cmbSampl;
441
442 // Loop over all observations (possible different epochs)
443 // -----------------------------------------------------
444 for (int ii = 0; ii < clkCorrections.size(); ii++) {
445 t_clkCorr* newClk = new t_clkCorr(clkCorrections[ii]);
446
447 char sys = newClk->_prn.system();
448 if (!_cmbSysPrn.contains(sys)){
449 delete newClk;
450 continue;
451 }
452
453 // Check regarding current time
454 // ----------------------------
455 int currentWeek = 0;
456 double currentSec = 0.0;
457 currentGPSWeeks(currentWeek, currentSec);
458 bncTime currentTime(currentWeek, currentSec);
459 if (newClk->_time >= currentTime) {
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 = 20;
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 (fabs(epoTime - _lastClkCorrTime) > 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.