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

Last change on this file since 10220 was 10216, checked in by stuerze, 3 years ago

memory leak fixed in combination

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