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

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

minor changes

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