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

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

revert some changes temporary

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