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

Last change on this file since 10101 was 10101, checked in by stuerze, 15 months ago

bug fixed

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