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

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

Combination: some checks regarding the corrections epoch time are dded

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