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

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

minor changes

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