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

Last change on this file since 10224 was 10224, checked in by stuerze, 2 years ago

bug fixed

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