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

Last change on this file since 10116 was 10116, checked in by stuerze, 18 months ago

minor changes

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
298 // Maximal Residuum
299 // ----------------
300 _MAXRES = settings.value("cmbMaxres").toDouble();
301 if (_MAXRES <= 0.0) {
302 _MAXRES = 999.0;
303 }
304}
305
306// Destructor
307////////////////////////////////////////////////////////////////////////////
308bncComb::~bncComb() {
309 QListIterator<cmbAC*> icAC(_ACs);
310 while (icAC.hasNext()) {
311 delete icAC.next();
312 }
313 delete _rtnetDecoder;
314 if (_ssrCorr) {
315 delete _ssrCorr;
316 }
317 delete _antex;
318 delete _bsx;
319
320 QMapIterator<char, unsigned> itSys(_cmbSysPrn);
321 while (itSys.hasNext()) {
322 itSys.next();
323 char sys = itSys.key();
324 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
325 delete _params[sys][iPar-1];
326 }
327 _buffer.remove(sys);
328 }
329 while (!_epoClkData.empty()) {
330 delete _epoClkData.front();
331 _epoClkData.pop_front();
332 }
333}
334
335void bncComb::slotReadBiasSnxFile() {
336 bncSettings settings;
337 QString bsxFileName = settings.value("cmbBsxFile").toString();
338
339 if (bsxFileName.isEmpty()) {
340 emit newMessage("bncComb: no Bias SINEX file specified", true);
341 return;
342 }
343 if (!_bsx) {
344 _bsx = new bncBiasSnx();
345 }
346 if (_bsx->readFile(bsxFileName) != success) {
347 emit newMessage("bncComb: wrong Bias SINEX file", true);
348 delete _bsx;
349 _bsx = 0;
350 }
351 else {
352 emit newMessage("bncComb: successfully read Bias SINEX file", true);
353 }
354
355 QTimer::singleShot(_ms, this, SLOT(slotReadBiasSnxFile()));
356}
357
358
359// Remember orbit corrections
360////////////////////////////////////////////////////////////////////////////
361void bncComb::slotNewOrbCorrections(QList<t_orbCorr> orbCorrections) {
362 QMutexLocker locker(&_mutex);
363
364 for (int ii = 0; ii < orbCorrections.size(); ii++) {
365 t_orbCorr& orbCorr = orbCorrections[ii];
366 QString staID(orbCorr._staID.c_str());
367 char sys = orbCorr._prn.system();
368
369 if (!_cmbSysPrn.contains(sys)){
370 continue;
371 }
372
373 // Find/Check the AC Name
374 // ----------------------
375 QString acName;
376 QListIterator<cmbAC*> icAC(_ACs);
377 while (icAC.hasNext()) {
378 cmbAC* AC = icAC.next();
379 if (AC->mountPoint == staID) {
380 acName = AC->name;
381 break;
382 }
383 }
384 if (acName.isEmpty()) {
385 continue;
386 }
387
388 // Store the correction
389 // --------------------
390 QMap<t_prn, t_orbCorr*>& storage = _orbCorrections[acName];
391 if (storage[orbCorr._prn]) {
392 delete storage[orbCorr._prn];
393 }
394 storage[orbCorr._prn] = new t_orbCorr(orbCorr);
395 }
396}
397
398// Remember Satellite Code Biases
399////////////////////////////////////////////////////////////////////////////
400void bncComb::slotNewCodeBiases(QList<t_satCodeBias> satCodeBiases) {
401 QMutexLocker locker(&_mutex);
402
403 for (int ii = 0; ii < satCodeBiases.size(); ii++) {
404 t_satCodeBias& satCodeBias = satCodeBiases[ii];
405 QString staID(satCodeBias._staID.c_str());
406 char sys = satCodeBias._prn.system();
407
408 if (!_cmbSysPrn.contains(sys)){
409 continue;
410 }
411
412 // Find/Check the AC Name
413 // ----------------------
414 QString acName;
415 QListIterator<cmbAC*> icAC(_ACs);
416 while (icAC.hasNext()) {
417 cmbAC* AC = icAC.next();
418 if (AC->mountPoint == staID) {
419 acName = AC->name;
420 break;
421 }
422 }
423 if (acName.isEmpty()) {
424 continue;
425 }
426
427 // Store the correction
428 // --------------------
429 QMap<t_prn, t_satCodeBias*>& storage = _satCodeBiases[acName];
430 if (storage[satCodeBias._prn]) {
431 delete storage[satCodeBias._prn];
432 }
433 storage[satCodeBias._prn] = new t_satCodeBias(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 ((newClk->_time >= currentTime) || // future time stamp
488 (currentTime - newClk->_time) > 120.0) { // very old data sets
489#ifdef BNC_DEBUG_CMB
490 emit newMessage("bncComb: very old data sets: " + acName.toLatin1() + " " + newClk->_prn.toString().c_str() +
491 QString(" %1 ").arg(newClk->_time.timestr().c_str()).toLatin1() + "vs. current time" +
492 QString(" %1 ").arg(currentTime.timestr().c_str()).toLatin1(), true);
493#endif
494 delete newClk;
495 continue;
496 }
497
498
499 // Set the last time
500 // -----------------
501 if (_lastClkCorrTime.undef() || newClk->_time > _lastClkCorrTime) {
502 _lastClkCorrTime = newClk->_time;
503 }
504
505 // Check Correction Age
506 // --------------------
507 if (_resTime.valid() && newClk->_time <= _resTime) {
508#ifdef BNC_DEBUG_CMB
509 emit newMessage("bncComb: old correction: " + acName.toLatin1() + " " + newClk->_prn.toString().c_str() +
510 QString(" %1 ").arg(newClk->_time.timestr().c_str()).toLatin1() + "vs. last processing Epoch" +
511 QString(" %1 ").arg(_resTime.timestr().c_str()).toLatin1(), true);
512#endif
513 delete newClk;
514 continue;
515 }
516
517 // Find the corresponding data epoch or create a new one
518 // -----------------------------------------------------
519 epoClkData* epoch = 0;
520 deque<epoClkData*>::const_iterator it;
521 for (it = _epoClkData.begin(); it != _epoClkData.end(); it++) {
522 if (newClk->_time == (*it)->_time) {
523 epoch = *it;
524 break;
525 }
526 }
527 if (epoch == 0) {
528 if (_epoClkData.empty() || newClk->_time > _epoClkData.back()->_time) {
529 epoch = new epoClkData;
530 epoch->_time = newClk->_time;
531 _epoClkData.push_back(epoch);
532 }
533 }
534
535 // Put data into the epoch
536 // -----------------------
537 if (epoch != 0) {
538 epoch->_clkCorr.push_back(newClk);
539 }
540 else {
541 delete newClk;
542 }
543 }
544
545 // Make sure the buffer does not grow beyond any limit
546 // ---------------------------------------------------
547 const unsigned MAX_EPODATA_SIZE = 25;
548 if (_epoClkData.size() > MAX_EPODATA_SIZE) {
549 delete _epoClkData.front();
550 _epoClkData.pop_front();
551 }
552
553 // Process the oldest epochs
554 // ------------------------
555 while (_epoClkData.size()) {
556
557 if (!_lastClkCorrTime.valid()) {
558 return;
559 }
560
561 const vector<t_clkCorr*>& clkCorrVec = _epoClkData.front()->_clkCorr;
562
563 bncTime epoTime = _epoClkData.front()->_time;
564
565 if ((currentTime - epoTime) > 120.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 = new t_clkCorr(*clkCorrVec[ii]);
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 if (resCorr[pp->prn]->_satCodeBias == 0) {
877 resCorr[pp->prn]->_satCodeBias = new t_satCodeBias();
878 }
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 // Delete Data
896 // -----------
897 _buffer.remove(sys);
898}
899
900// Process Epoch - Filter Method
901////////////////////////////////////////////////////////////////////////////
902t_irc bncComb::processEpoch_filter(bncTime epoTime, char sys, QTextStream& out,
903 QMap<QString, cmbCorr*>& resCorr,
904 ColumnVector& dx) {
905
906 // Prediction Step
907 // ---------------
908 int nPar = _params[sys].size();
909 ColumnVector x0(nPar);
910 for (int iPar = 1; iPar <= nPar; iPar++) {
911 cmbParam* pp = _params[sys][iPar-1];
912 if (pp->epoSpec) {
913 pp->xx = 0.0;
914 _QQ[sys].Row(iPar) = 0.0;
915 _QQ[sys].Column(iPar) = 0.0;
916 _QQ[sys](iPar,iPar) = pp->sig0 * pp->sig0;
917 }
918 else {
919 _QQ[sys](iPar,iPar) += pp->sigP * pp->sigP;
920 }
921 x0(iPar) = pp->xx;
922 }
923
924 // Check Satellite Positions for Outliers
925 // --------------------------------------
926 if (checkOrbits(epoTime, sys, out) != success) {
927 return failure;
928 }
929
930 // Update and outlier detection loop
931 // ---------------------------------
932 SymmetricMatrix QQ_sav = _QQ[sys];
933 while (true) {
934
935 Matrix AA;
936 ColumnVector ll;
937 DiagonalMatrix PP;
938
939 if (createAmat(sys, AA, ll, PP, x0, resCorr) != success) {
940 return failure;
941 }
942
943 dx.ReSize(nPar); dx = 0.0;
944 kalman(AA, ll, PP, _QQ[sys], dx);
945
946 ColumnVector vv = ll - AA * dx;
947
948 int maxResIndex;
949 double maxRes = vv.maximum_absolute_value1(maxResIndex);
950 out.setRealNumberNotation(QTextStream::FixedNotation);
951 out.setRealNumberPrecision(3);
952 out << epoTime.datestr().c_str() << " " << epoTime.timestr().c_str()
953 << " Maximum Residuum " << maxRes << ' '
954 << corrs(sys)[maxResIndex-1]->_acName << ' ' << corrs(sys)[maxResIndex-1]->_prn.mid(0,3);
955 if (maxRes > _MAXRES) {
956 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
957 cmbParam* pp = _params[sys][iPar-1];
958 if (pp->type == cmbParam::offACSat &&
959 pp->AC == corrs(sys)[maxResIndex-1]->_acName &&
960 pp->prn == corrs(sys)[maxResIndex-1]->_prn.mid(0,3)) {
961 QQ_sav.Row(iPar) = 0.0;
962 QQ_sav.Column(iPar) = 0.0;
963 QQ_sav(iPar,iPar) = pp->sig0 * pp->sig0;
964 }
965 }
966
967 out << " Outlier" << "\n";
968 _QQ[sys] = QQ_sav;
969 corrs(sys).remove(maxResIndex-1);
970 }
971 else {
972 out << " OK" << "\n";
973 out.setRealNumberNotation(QTextStream::FixedNotation);
974 out.setRealNumberPrecision(4);
975 for (int ii = 0; ii < corrs(sys).size(); ii++) {
976 const cmbCorr* corr = corrs(sys)[ii];
977 out << epoTime.datestr().c_str() << ' '
978 << epoTime.timestr().c_str() << " "
979 << corr->_acName << ' ' << corr->_prn.mid(0,3);
980 out.setFieldWidth(10);
981 out << " res = " << vv[ii] << "\n";
982 out.setFieldWidth(0);
983 }
984 break;
985 }
986 }
987
988 return success;
989}
990
991// Print results
992////////////////////////////////////////////////////////////////////////////
993void bncComb::printResults(bncTime epoTime, QTextStream& out,
994 const QMap<QString, cmbCorr*>& resCorr) {
995
996 QMapIterator<QString, cmbCorr*> it(resCorr);
997 while (it.hasNext()) {
998 it.next();
999 cmbCorr* corr = it.value();
1000 const t_eph* eph = corr->_eph;
1001 if (eph) {
1002 ColumnVector xc(6);
1003 ColumnVector vv(3);
1004 if (eph->getCrd(epoTime, xc, vv, false) != success) {
1005 continue;
1006 }
1007 out << epoTime.datestr().c_str() << " "
1008 << epoTime.timestr().c_str() << " ";
1009 out.setFieldWidth(3);
1010 out << "Full Clock " << corr->_prn.mid(0,3) << " " << corr->_iod << " ";
1011 out.setFieldWidth(14);
1012 out << (xc(4) + corr->_dClkResult) * t_CST::c << "\n";
1013 out.setFieldWidth(0);
1014 }
1015 else {
1016 out << "bncComb::printResults bug" << "\n";
1017 }
1018 out.flush();
1019 }
1020}
1021
1022// Send results to RTNet Decoder and directly to PPP Client
1023////////////////////////////////////////////////////////////////////////////
1024void bncComb::dumpResults(bncTime epoTime, const QMap<QString, cmbCorr*>& resCorr) {
1025
1026 QList<t_orbCorr> orbCorrections;
1027 QList<t_clkCorr> clkCorrections;
1028 QList<t_satCodeBias> satCodeBiasList;
1029
1030 unsigned year, month, day, hour, minute;
1031 double sec;
1032 epoTime.civil_date(year, month, day);
1033 epoTime.civil_time(hour, minute, sec);
1034
1035 QString outLines = QString().asprintf("* %4d %2d %2d %d %d %12.8f\n",
1036 year, month, day, hour, minute, sec);
1037
1038 QMapIterator<QString, cmbCorr*> it(resCorr);
1039 while (it.hasNext()) {
1040 it.next();
1041 cmbCorr* corr = it.value();
1042
1043 // ORBIT
1044 t_orbCorr orbCorr(static_cast<t_orbCorr>(*corr->_orbCorr));
1045 orbCorr._staID = "INTERNAL";
1046 orbCorrections.push_back(orbCorr);
1047
1048 // CLOCK
1049 t_clkCorr clkCorr(static_cast<t_clkCorr>(*corr->_clkCorr));
1050 clkCorr._staID = "INTERNAL";
1051 clkCorr._dClk = corr->_dClkResult;
1052 clkCorr._dotDClk = 0.0;
1053 clkCorr._dotDotDClk = 0.0;
1054 clkCorrections.push_back(clkCorr);
1055
1056
1057 ColumnVector xc(6);
1058 ColumnVector vv(3);
1059 corr->_eph->setClkCorr(dynamic_cast<const t_clkCorr*>(&clkCorr));
1060 corr->_eph->setOrbCorr(dynamic_cast<const t_orbCorr*>(&orbCorr));
1061 if (corr->_eph->getCrd(epoTime, xc, vv, true) != success) {
1062 delete corr;
1063 continue;
1064 }
1065
1066 // Correction Phase Center --> CoM
1067 // -------------------------------
1068
1069 ColumnVector dx(3); dx = 0.0;
1070 ColumnVector apc(3); apc = 0.0;
1071 ColumnVector com(3); com = 0.0;
1072 bool masterIsAPC = true;
1073 if (_antex) {
1074 double Mjd = epoTime.mjd() + epoTime.daysec()/86400.0;
1075 char sys = corr->_eph->prn().system();
1076 masterIsAPC = _masterIsAPC[sys];
1077 if (_antex->satCoMcorrection(corr->_prn, Mjd, xc.Rows(1,3), dx) != success) {
1078 dx = 0;
1079 _log += "antenna not found " + corr->_prn.mid(0,3).toLatin1() + '\n';
1080 }
1081 }
1082 if (masterIsAPC) {
1083 apc(1) = xc(1);
1084 apc(2) = xc(2);
1085 apc(3) = xc(3);
1086 com(1) = xc(1)-dx(1);
1087 com(2) = xc(2)-dx(2);
1088 com(3) = xc(3)-dx(3);
1089 }
1090 else {
1091 com(1) = xc(1);
1092 com(2) = xc(2);
1093 com(3) = xc(3);
1094 apc(1) = xc(1)+dx(1);
1095 apc(2) = xc(2)+dx(2);
1096 apc(3) = xc(3)+dx(3);
1097 }
1098
1099 outLines += corr->_prn.mid(0,3);
1100 QString hlp = QString().asprintf(
1101 " APC 3 %15.4f %15.4f %15.4f"
1102 " Clk 1 %15.4f"
1103 " Vel 3 %15.4f %15.4f %15.4f"
1104 " CoM 3 %15.4f %15.4f %15.4f",
1105 apc(1), apc(2), apc(3),
1106 xc(4) * t_CST::c,
1107 vv(1), vv(2), vv(3),
1108 com(1), com(2), com(3));
1109 outLines += hlp;
1110 hlp.clear();
1111
1112 // CODE BIASES
1113 if (corr->_satCodeBias) {
1114 t_satCodeBias satCodeBias(static_cast<t_satCodeBias>(*corr->_satCodeBias));
1115 satCodeBias._staID = "INTERNAL";
1116 satCodeBiasList.push_back(satCodeBias);
1117 hlp = QString().asprintf(" CodeBias %2lu", satCodeBias._bias.size());
1118 outLines += hlp;
1119 hlp.clear();
1120 for (unsigned ii = 0; ii < satCodeBias._bias.size(); ii++) {
1121 const t_frqCodeBias& frqCodeBias = satCodeBias._bias[ii];
1122 if (!frqCodeBias._rnxType2ch.empty()) {
1123 hlp = QString().asprintf(" %s%10.6f", frqCodeBias._rnxType2ch.c_str(), frqCodeBias._value);
1124 outLines += hlp;
1125 hlp.clear();
1126 }
1127 }
1128 }
1129 outLines += "\n";
1130 delete corr;
1131 }
1132
1133 outLines += "EOE\n"; // End Of Epoch flag
1134 //cout << outLines.toStdString();
1135
1136 if (!_rtnetDecoder) {
1137 _rtnetDecoder = new bncRtnetDecoder();
1138 }
1139
1140 vector<string> errmsg;
1141 _rtnetDecoder->Decode(outLines.toLatin1().data(), outLines.length(), errmsg);
1142
1143 // Send new Corrections to PPP etc.
1144 // --------------------------------
1145 if (orbCorrections.size() > 0 && clkCorrections.size() > 0) {
1146 emit newOrbCorrections(orbCorrections);
1147 emit newClkCorrections(clkCorrections);
1148 }
1149 if (satCodeBiasList.size()) {
1150 emit newCodeBiases(satCodeBiasList);
1151 }
1152}
1153
1154// Create First Design Matrix and Vector of Measurements
1155////////////////////////////////////////////////////////////////////////////
1156t_irc bncComb::createAmat(char sys, Matrix& AA, ColumnVector& ll, DiagonalMatrix& PP,
1157 const ColumnVector& x0, QMap<QString, cmbCorr*>& resCorr) {
1158
1159 unsigned nPar = _params[sys].size();
1160 unsigned nObs = corrs(sys).size();
1161
1162 if (nObs == 0) {
1163 return failure;
1164 }
1165
1166 int maxSat = _cmbSysPrn[sys];
1167
1168 const int nCon = (_method == filter) ? 1 + maxSat : 0;
1169
1170 AA.ReSize(nObs+nCon, nPar); AA = 0.0;
1171 ll.ReSize(nObs+nCon); ll = 0.0;
1172 PP.ReSize(nObs+nCon); PP = 1.0 / (sigObs * sigObs);
1173
1174 int iObs = 0;
1175 QVectorIterator<cmbCorr*> itCorr(corrs(sys));
1176 while (itCorr.hasNext()) {
1177 cmbCorr* corr = itCorr.next();
1178 QString prn = corr->_prn;
1179
1180 ++iObs;
1181
1182 if (corr->_acName == _masterOrbitAC[sys] && resCorr.find(prn) == resCorr.end()) {
1183 resCorr[prn] = new cmbCorr(*corr);
1184 }
1185
1186 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1187 cmbParam* pp = _params[sys][iPar-1];
1188 AA(iObs, iPar) = pp->partial(sys, corr->_acName, prn);
1189 }
1190
1191 ll(iObs) = (corr->_clkCorr->_dClk * t_CST::c - corr->_satCodeBiasIF) - DotProduct(AA.Row(iObs), x0);
1192
1193 PP(iObs, iObs) *= 1.0 / (corr->_weightFactor * corr->_weightFactor);
1194 }
1195
1196 // Regularization
1197 // --------------
1198 if (_method == filter) {
1199 const double Ph = 1.e6;
1200 PP(nObs+1) = Ph;
1201 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1202 cmbParam* pp = _params[sys][iPar-1];
1203 if ( AA.Column(iPar).maximum_absolute_value() > 0.0 &&
1204 pp->type == cmbParam::clkSat ) {
1205 AA(nObs+1, iPar) = 1.0;
1206 }
1207 }
1208 unsigned flag = 0;
1209 if (sys == 'E') {
1210 flag = 1;
1211 }
1212// if (sys == 'R') {
1213// return success;
1214// }
1215 int iCond = 1;
1216 // GNSS
1217 for (unsigned iGnss = 1; iGnss <= _cmbSysPrn[sys]; iGnss++) {
1218 QString prn = QString("%1%2_%3").arg(sys).arg(iGnss, 2, 10, QChar('0')).arg(flag);
1219 ++iCond;
1220 PP(nObs+iCond) = Ph;
1221 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1222 cmbParam* pp = _params[sys][iPar-1];
1223 if ( pp &&
1224 AA.Column(iPar).maximum_absolute_value() > 0.0 &&
1225 pp->type == cmbParam::offACSat &&
1226 pp->prn == prn) {
1227 AA(nObs+iCond, iPar) = 1.0;
1228 }
1229 }
1230 }
1231 }
1232
1233 return success;
1234}
1235
1236// Process Epoch - Single-Epoch Method
1237////////////////////////////////////////////////////////////////////////////
1238t_irc bncComb::processEpoch_singleEpoch(bncTime epoTime, char sys, QTextStream& out,
1239 QMap<QString, cmbCorr*>& resCorr,
1240 ColumnVector& dx) {
1241
1242 // Check Satellite Positions for Outliers
1243 // --------------------------------------
1244 if (checkOrbits(epoTime, sys, out) != success) {
1245 return failure;
1246 }
1247
1248 // Outlier Detection Loop
1249 // ----------------------
1250 while (true) {
1251
1252 // Remove Satellites that are not in Master
1253 // ----------------------------------------
1254 QMutableVectorIterator<cmbCorr*> it(corrs(sys));
1255 while (it.hasNext()) {
1256 cmbCorr* corr = it.next();
1257 QString prn = corr->_prn;
1258 bool foundMaster = false;
1259 QVectorIterator<cmbCorr*> itHlp(corrs(sys));
1260 while (itHlp.hasNext()) {
1261 cmbCorr* corrHlp = itHlp.next();
1262 QString prnHlp = corrHlp->_prn;
1263 QString ACHlp = corrHlp->_acName;
1264 if (ACHlp == _masterOrbitAC[sys] && prn == prnHlp) {
1265 foundMaster = true;
1266 break;
1267 }
1268 }
1269 if (!foundMaster) {
1270 delete corr;
1271 it.remove();
1272 }
1273 }
1274
1275 // Count Number of Observations per Satellite and per AC
1276 // -----------------------------------------------------
1277 QMap<QString, int> numObsPrn;
1278 QMap<QString, int> numObsAC;
1279 QVectorIterator<cmbCorr*> itCorr(corrs(sys));
1280 while (itCorr.hasNext()) {
1281 cmbCorr* corr = itCorr.next();
1282 QString prn = corr->_prn;
1283 QString AC = corr->_acName;
1284 if (numObsPrn.find(prn) == numObsPrn.end()) {
1285 numObsPrn[prn] = 1;
1286 }
1287 else {
1288 numObsPrn[prn] += 1;
1289 }
1290 if (numObsAC.find(AC) == numObsAC.end()) {
1291 numObsAC[AC] = 1;
1292 }
1293 else {
1294 numObsAC[AC] += 1;
1295 }
1296 }
1297
1298 // Clean-Up the Parameters
1299 // -----------------------
1300 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1301 delete _params[sys][iPar-1];
1302 }
1303 _params[sys].clear();
1304
1305 // Set new Parameters
1306 // ------------------
1307 int nextPar = 0;
1308
1309 QMapIterator<QString, int> itAC(numObsAC);
1310 while (itAC.hasNext()) {
1311 itAC.next();
1312 const QString& AC = itAC.key();
1313 int numObs = itAC.value();
1314 if (AC != _masterOrbitAC[sys] && numObs > 0) {
1315 _params[sys].push_back(new cmbParam(cmbParam::offACgnss, ++nextPar, AC, ""));
1316 }
1317 }
1318
1319 QMapIterator<QString, int> itPrn(numObsPrn);
1320 while (itPrn.hasNext()) {
1321 itPrn.next();
1322 const QString& prn = itPrn.key();
1323 int numObs = itPrn.value();
1324 if (numObs > 0) {
1325 _params[sys].push_back(new cmbParam(cmbParam::clkSat, ++nextPar, "", prn));
1326 }
1327 }
1328
1329 int nPar = _params[sys].size();
1330 ColumnVector x0(nPar);
1331 x0 = 0.0;
1332
1333 // Create First-Design Matrix
1334 // --------------------------
1335 Matrix AA;
1336 ColumnVector ll;
1337 DiagonalMatrix PP;
1338 if (createAmat(sys, AA, ll, PP, x0, resCorr) != success) {
1339 return failure;
1340 }
1341
1342 ColumnVector vv;
1343 try {
1344 Matrix ATP = AA.t() * PP;
1345 SymmetricMatrix NN; NN << ATP * AA;
1346 ColumnVector bb = ATP * ll;
1347 _QQ[sys] = NN.i();
1348 dx = _QQ[sys] * bb;
1349 vv = ll - AA * dx;
1350 }
1351 catch (Exception& exc) {
1352 out << exc.what() << "\n";
1353 return failure;
1354 }
1355
1356 int maxResIndex;
1357 double maxRes = vv.maximum_absolute_value1(maxResIndex);
1358 out.setRealNumberNotation(QTextStream::FixedNotation);
1359 out.setRealNumberPrecision(3);
1360 out << epoTime.datestr().c_str() << " " << epoTime.timestr().c_str()
1361 << " Maximum Residuum " << maxRes << ' '
1362 << corrs(sys)[maxResIndex-1]->_acName << ' ' << corrs(sys)[maxResIndex-1]->_prn.mid(0,3);
1363
1364 if (maxRes > _MAXRES) {
1365 out << " Outlier" << "\n";
1366 delete corrs(sys)[maxResIndex-1];
1367 corrs(sys).remove(maxResIndex-1);
1368 }
1369 else {
1370 out << " OK" << "\n";
1371 out.setRealNumberNotation(QTextStream::FixedNotation);
1372 out.setRealNumberPrecision(3);
1373 for (int ii = 0; ii < vv.Nrows(); ii++) {
1374 const cmbCorr* corr = corrs(sys)[ii];
1375 out << epoTime.datestr().c_str() << ' '
1376 << epoTime.timestr().c_str() << " "
1377 << corr->_acName << ' ' << corr->_prn.mid(0,3);
1378 out.setFieldWidth(6);
1379 out << " res = " << vv[ii] << "\n";
1380 out.setFieldWidth(0);
1381 }
1382 return success;
1383 }
1384
1385 }
1386
1387 return failure;
1388}
1389
1390// Check Satellite Positions for Outliers
1391////////////////////////////////////////////////////////////////////////////
1392t_irc bncComb::checkOrbits(bncTime epoTime, char sys, QTextStream& out) {
1393
1394 const double MAX_DISPLACEMENT = 0.20;
1395
1396 // Switch to last ephemeris (if possible)
1397 // --------------------------------------
1398 QMutableVectorIterator<cmbCorr*> im(corrs(sys));
1399 while (im.hasNext()) {
1400 cmbCorr* corr = im.next();
1401 QString prn = corr->_prn;
1402
1403 t_eph* ephLast = _ephUser.ephLast(prn);
1404 t_eph* ephPrev = _ephUser.ephPrev(prn);
1405
1406 if (ephLast == 0) {
1407 out << "checkOrbit: missing eph (not found) " << corr->_prn.mid(0,3) << "\n";
1408 delete corr;
1409 im.remove();
1410 }
1411 else if (corr->_eph == 0) {
1412 out << "checkOrbit: missing eph (zero) " << corr->_prn.mid(0,3) << "\n";
1413 delete corr;
1414 im.remove();
1415 }
1416 else {
1417 if ( corr->_eph == ephLast || corr->_eph == ephPrev ) {
1418 switchToLastEph(ephLast, corr);
1419 }
1420 else {
1421 out << "checkOrbit: missing eph (deleted) " << corr->_prn.mid(0,3) << "\n";
1422 delete corr;
1423 im.remove();
1424 }
1425 }
1426 }
1427
1428 while (true) {
1429
1430 // Compute Mean Corrections for all Satellites
1431 // -------------------------------------------
1432 QMap<QString, int> numCorr;
1433 QMap<QString, ColumnVector> meanRao;
1434 QVectorIterator<cmbCorr*> it(corrs(sys));
1435 while (it.hasNext()) {
1436 cmbCorr* corr = it.next();
1437 QString prn = corr->_prn;
1438 if (meanRao.find(prn) == meanRao.end()) {
1439 meanRao[prn].ReSize(4);
1440 meanRao[prn].Rows(1,3) = corr->_orbCorr->_xr;
1441 meanRao[prn](4) = 1;
1442 }
1443 else {
1444 meanRao[prn].Rows(1,3) += corr->_orbCorr->_xr;
1445 meanRao[prn](4) += 1;
1446 }
1447 if (numCorr.find(prn) == numCorr.end()) {
1448 numCorr[prn] = 1;
1449 }
1450 else {
1451 numCorr[prn] += 1;
1452 }
1453 }
1454
1455 // Compute Differences wrt. Mean, find Maximum
1456 // -------------------------------------------
1457 QMap<QString, cmbCorr*> maxDiff;
1458 it.toFront();
1459 while (it.hasNext()) {
1460 cmbCorr* corr = it.next();
1461 QString prn = corr->_prn;
1462 if (meanRao[prn](4) != 0) {
1463 meanRao[prn] /= meanRao[prn](4);
1464 meanRao[prn](4) = 0;
1465 }
1466 corr->_diffRao = corr->_orbCorr->_xr - meanRao[prn].Rows(1,3);
1467 if (maxDiff.find(prn) == maxDiff.end()) {
1468 maxDiff[prn] = corr;
1469 }
1470 else {
1471 double normMax = maxDiff[prn]->_diffRao.NormFrobenius();
1472 double norm = corr->_diffRao.NormFrobenius();
1473 if (norm > normMax) {
1474 maxDiff[prn] = corr;
1475 }
1476 }
1477 }
1478
1479 if (_ACs.size() == 1) {
1480 break;
1481 }
1482
1483 // Remove Outliers
1484 // ---------------
1485 bool removed = false;
1486 QMutableVectorIterator<cmbCorr*> im(corrs(sys));
1487 while (im.hasNext()) {
1488 cmbCorr* corr = im.next();
1489 QString prn = corr->_prn;
1490 if (numCorr[prn] < 2) {
1491 delete corr;
1492 im.remove();
1493 }
1494 else if (corr == maxDiff[prn]) {
1495 double norm = corr->_diffRao.NormFrobenius();
1496 if (norm > MAX_DISPLACEMENT) {
1497 out << epoTime.datestr().c_str() << " "
1498 << epoTime.timestr().c_str() << " "
1499 << "Orbit Outlier: "
1500 << corr->_acName.toLatin1().data() << " "
1501 << prn.mid(0,3).toLatin1().data() << " "
1502 << corr->_iod << " "
1503 << norm << "\n";
1504 delete corr;
1505 im.remove();
1506 removed = true;
1507 }
1508 }
1509 }
1510
1511 if (!removed) {
1512 break;
1513 }
1514 }
1515
1516 return success;
1517}
1518
1519//
1520////////////////////////////////////////////////////////////////////////////
1521void bncComb::slotProviderIDChanged(QString mountPoint) {
1522 QMutexLocker locker(&_mutex);
1523
1524 QTextStream out(&_log, QIODevice::WriteOnly);
1525
1526 // Find the AC Name
1527 // ----------------
1528 QString acName;
1529 QListIterator<cmbAC*> icAC(_ACs);
1530 while (icAC.hasNext()) {
1531 cmbAC *AC = icAC.next();
1532 if (AC->mountPoint == mountPoint) {
1533 acName = AC->name;
1534 out << "Provider ID changed: AC " << AC->name.toLatin1().data() << " "
1535 << _resTime.datestr().c_str() << " " << _resTime.timestr().c_str()
1536 << "\n";
1537 break;
1538 }
1539 }
1540 if (acName.isEmpty()) {
1541 return;
1542 }
1543 QMapIterator<char, unsigned> itSys(_cmbSysPrn);
1544 while (itSys.hasNext()) {
1545 itSys.next();
1546 char sys = itSys.key();
1547 // Remove all corrections of the corresponding AC
1548 // ----------------------------------------------
1549 QVector<cmbCorr*> &corrVec = _buffer[sys].corrs;
1550 QMutableVectorIterator<cmbCorr*> it(corrVec);
1551 while (it.hasNext()) {
1552 cmbCorr *corr = it.next();
1553 if (acName == corr->_acName) {
1554 delete corr;
1555 it.remove();
1556 }
1557 }
1558 // Reset Satellite Offsets
1559 // -----------------------
1560 if (_method == filter) {
1561 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1562 cmbParam *pp = _params[sys][iPar - 1];
1563 if (pp->AC == acName && pp->type == cmbParam::offACSat) {
1564 pp->xx = 0.0;
1565 _QQ[sys].Row(iPar) = 0.0;
1566 _QQ[sys].Column(iPar) = 0.0;
1567 _QQ[sys](iPar, iPar) = pp->sig0 * pp->sig0;
1568 }
1569 }
1570 }
1571 }
1572}
Note: See TracBrowser for help on using the repository browser.