source: ntrip/branches/BNC_2.13.beta/src/combination/bnccomb.cpp@ 10132

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

minor changes

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(
1074 " APC 3 %15.4f %15.4f %15.4f"
1075 " Clk 1 %15.4f"
1076 " Vel 3 %15.4f %15.4f %15.4f"
1077 " CoM 3 %15.4f %15.4f %15.4f",
1078 xc(1), xc(2), xc(3),
1079 xc(4) * t_CST::c,
1080 vv(1), vv(2), vv(3),
1081 xc(1)-dx(1), xc(2)-dx(2), xc(3)-dx(3));
1082 outLines += hlp;
1083 hlp.clear();
1084
1085 // CODE BIASES
1086 if (corr->_satCodeBias) {
1087 t_satCodeBias satCodeBias(static_cast<t_satCodeBias>(*corr->_satCodeBias));
1088 satCodeBias._staID = "INTERNAL";
1089 satCodeBiasList.push_back(satCodeBias);
1090 hlp = QString().asprintf(" CodeBias %2lu", satCodeBias._bias.size());
1091 outLines += hlp;
1092 hlp.clear();
1093 for (unsigned ii = 0; ii < satCodeBias._bias.size(); ii++) {
1094 const t_frqCodeBias& frqCodeBias = satCodeBias._bias[ii];
1095 if (!frqCodeBias._rnxType2ch.empty()) {
1096 hlp = QString().asprintf(" %s%10.6f", frqCodeBias._rnxType2ch.c_str(), frqCodeBias._value);
1097 outLines += hlp;
1098 hlp.clear();
1099 }
1100 }
1101 }
1102 outLines += "\n";
1103 delete corr;
1104 }
1105
1106 outLines += "EOE\n"; // End Of Epoch flag
1107 //cout << outLines.toStdString();
1108
1109 if (!_rtnetDecoder) {
1110 _rtnetDecoder = new bncRtnetDecoder();
1111 }
1112
1113 vector<string> errmsg;
1114 _rtnetDecoder->Decode(outLines.toLatin1().data(), outLines.length(), errmsg);
1115
1116 // Send new Corrections to PPP etc.
1117 // --------------------------------
1118 if (orbCorrections.size() > 0 && clkCorrections.size() > 0) {
1119 emit newOrbCorrections(orbCorrections);
1120 emit newClkCorrections(clkCorrections);
1121 }
1122 if (satCodeBiasList.size()) {
1123 emit newCodeBiases(satCodeBiasList);
1124 }
1125}
1126
1127// Create First Design Matrix and Vector of Measurements
1128////////////////////////////////////////////////////////////////////////////
1129t_irc bncComb::createAmat(char sys, Matrix& AA, ColumnVector& ll, DiagonalMatrix& PP,
1130 const ColumnVector& x0, QMap<QString, cmbCorr*>& resCorr) {
1131
1132 unsigned nPar = _params[sys].size();
1133 unsigned nObs = corrs(sys).size();
1134
1135 if (nObs == 0) {
1136 return failure;
1137 }
1138
1139 int maxSat = _cmbSysPrn[sys];
1140
1141 const int nCon = (_method == filter) ? 1 + maxSat : 0;
1142
1143 AA.ReSize(nObs+nCon, nPar); AA = 0.0;
1144 ll.ReSize(nObs+nCon); ll = 0.0;
1145 PP.ReSize(nObs+nCon); PP = 1.0 / (sigObs * sigObs);
1146
1147 int iObs = 0;
1148 QVectorIterator<cmbCorr*> itCorr(corrs(sys));
1149 while (itCorr.hasNext()) {
1150 cmbCorr* corr = itCorr.next();
1151 QString prn = corr->_prn;
1152
1153 ++iObs;
1154
1155 if (corr->_acName == _masterOrbitAC[sys] && resCorr.find(prn) == resCorr.end()) {
1156 resCorr[prn] = new cmbCorr(*corr);
1157 }
1158
1159 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1160 cmbParam* pp = _params[sys][iPar-1];
1161 AA(iObs, iPar) = pp->partial(sys, corr->_acName, prn);
1162 }
1163
1164 ll(iObs) = (corr->_clkCorr->_dClk * t_CST::c - corr->_satCodeBiasIF) - DotProduct(AA.Row(iObs), x0);
1165
1166 PP(iObs, iObs) *= 1.0 / (corr->_weightFactor * corr->_weightFactor);
1167 }
1168
1169 // Regularization
1170 // --------------
1171 if (_method == filter) {
1172 const double Ph = 1.e6;
1173 PP(nObs+1) = Ph;
1174 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1175 cmbParam* pp = _params[sys][iPar-1];
1176 if ( AA.Column(iPar).maximum_absolute_value() > 0.0 &&
1177 pp->type == cmbParam::clkSat ) {
1178 AA(nObs+1, iPar) = 1.0;
1179 }
1180 }
1181 unsigned flag = 0;
1182 if (sys == 'E') {
1183 flag = 1;
1184 }
1185// if (sys == 'R') {
1186// return success;
1187// }
1188 int iCond = 1;
1189 // GNSS
1190 for (unsigned iGnss = 1; iGnss <= _cmbSysPrn[sys]; iGnss++) {
1191 QString prn = QString("%1%2_%3").arg(sys).arg(iGnss, 2, 10, QChar('0')).arg(flag);
1192 ++iCond;
1193 PP(nObs+iCond) = Ph;
1194 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1195 cmbParam* pp = _params[sys][iPar-1];
1196 if ( pp &&
1197 AA.Column(iPar).maximum_absolute_value() > 0.0 &&
1198 pp->type == cmbParam::offACSat &&
1199 pp->prn == prn) {
1200 AA(nObs+iCond, iPar) = 1.0;
1201 }
1202 }
1203 }
1204 }
1205
1206 return success;
1207}
1208
1209// Process Epoch - Single-Epoch Method
1210////////////////////////////////////////////////////////////////////////////
1211t_irc bncComb::processEpoch_singleEpoch(bncTime epoTime, char sys, QTextStream& out,
1212 QMap<QString, cmbCorr*>& resCorr,
1213 ColumnVector& dx) {
1214
1215 // Check Satellite Positions for Outliers
1216 // --------------------------------------
1217 if (checkOrbits(epoTime, sys, out) != success) {
1218 return failure;
1219 }
1220
1221 // Outlier Detection Loop
1222 // ----------------------
1223 while (true) {
1224
1225 // Remove Satellites that are not in Master
1226 // ----------------------------------------
1227 QMutableVectorIterator<cmbCorr*> it(corrs(sys));
1228 while (it.hasNext()) {
1229 cmbCorr* corr = it.next();
1230 QString prn = corr->_prn;
1231 bool foundMaster = false;
1232 QVectorIterator<cmbCorr*> itHlp(corrs(sys));
1233 while (itHlp.hasNext()) {
1234 cmbCorr* corrHlp = itHlp.next();
1235 QString prnHlp = corrHlp->_prn;
1236 QString ACHlp = corrHlp->_acName;
1237 if (ACHlp == _masterOrbitAC[sys] && prn == prnHlp) {
1238 foundMaster = true;
1239 break;
1240 }
1241 }
1242 if (!foundMaster) {
1243 delete corr;
1244 it.remove();
1245 }
1246 }
1247
1248 // Count Number of Observations per Satellite and per AC
1249 // -----------------------------------------------------
1250 QMap<QString, int> numObsPrn;
1251 QMap<QString, int> numObsAC;
1252 QVectorIterator<cmbCorr*> itCorr(corrs(sys));
1253 while (itCorr.hasNext()) {
1254 cmbCorr* corr = itCorr.next();
1255 QString prn = corr->_prn;
1256 QString AC = corr->_acName;
1257 if (numObsPrn.find(prn) == numObsPrn.end()) {
1258 numObsPrn[prn] = 1;
1259 }
1260 else {
1261 numObsPrn[prn] += 1;
1262 }
1263 if (numObsAC.find(AC) == numObsAC.end()) {
1264 numObsAC[AC] = 1;
1265 }
1266 else {
1267 numObsAC[AC] += 1;
1268 }
1269 }
1270
1271 // Clean-Up the Parameters
1272 // -----------------------
1273 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1274 delete _params[sys][iPar-1];
1275 }
1276 _params[sys].clear();
1277
1278 // Set new Parameters
1279 // ------------------
1280 int nextPar = 0;
1281
1282 QMapIterator<QString, int> itAC(numObsAC);
1283 while (itAC.hasNext()) {
1284 itAC.next();
1285 const QString& AC = itAC.key();
1286 int numObs = itAC.value();
1287 if (AC != _masterOrbitAC[sys] && numObs > 0) {
1288 _params[sys].push_back(new cmbParam(cmbParam::offACgnss, ++nextPar, AC, ""));
1289 }
1290 }
1291
1292 QMapIterator<QString, int> itPrn(numObsPrn);
1293 while (itPrn.hasNext()) {
1294 itPrn.next();
1295 const QString& prn = itPrn.key();
1296 int numObs = itPrn.value();
1297 if (numObs > 0) {
1298 _params[sys].push_back(new cmbParam(cmbParam::clkSat, ++nextPar, "", prn));
1299 }
1300 }
1301
1302 int nPar = _params[sys].size();
1303 ColumnVector x0(nPar);
1304 x0 = 0.0;
1305
1306 // Create First-Design Matrix
1307 // --------------------------
1308 Matrix AA;
1309 ColumnVector ll;
1310 DiagonalMatrix PP;
1311 if (createAmat(sys, AA, ll, PP, x0, resCorr) != success) {
1312 return failure;
1313 }
1314
1315 ColumnVector vv;
1316 try {
1317 Matrix ATP = AA.t() * PP;
1318 SymmetricMatrix NN; NN << ATP * AA;
1319 ColumnVector bb = ATP * ll;
1320 _QQ[sys] = NN.i();
1321 dx = _QQ[sys] * bb;
1322 vv = ll - AA * dx;
1323 }
1324 catch (Exception& exc) {
1325 out << exc.what() << "\n";
1326 return failure;
1327 }
1328
1329 int maxResIndex;
1330 double maxRes = vv.maximum_absolute_value1(maxResIndex);
1331 out.setRealNumberNotation(QTextStream::FixedNotation);
1332 out.setRealNumberPrecision(3);
1333 out << epoTime.datestr().c_str() << " " << epoTime.timestr().c_str()
1334 << " Maximum Residuum " << maxRes << ' '
1335 << corrs(sys)[maxResIndex-1]->_acName << ' ' << corrs(sys)[maxResIndex-1]->_prn.mid(0,3);
1336
1337 if (maxRes > _MAXRES) {
1338 out << " Outlier" << "\n";
1339 delete corrs(sys)[maxResIndex-1];
1340 corrs(sys).remove(maxResIndex-1);
1341 }
1342 else {
1343 out << " OK" << "\n";
1344 out.setRealNumberNotation(QTextStream::FixedNotation);
1345 out.setRealNumberPrecision(3);
1346 for (int ii = 0; ii < vv.Nrows(); ii++) {
1347 const cmbCorr* corr = corrs(sys)[ii];
1348 out << epoTime.datestr().c_str() << ' '
1349 << epoTime.timestr().c_str() << " "
1350 << corr->_acName << ' ' << corr->_prn.mid(0,3);
1351 out.setFieldWidth(6);
1352 out << " res = " << vv[ii] << "\n";
1353 out.setFieldWidth(0);
1354 }
1355 return success;
1356 }
1357
1358 }
1359
1360 return failure;
1361}
1362
1363// Check Satellite Positions for Outliers
1364////////////////////////////////////////////////////////////////////////////
1365t_irc bncComb::checkOrbits(bncTime epoTime, char sys, QTextStream& out) {
1366
1367 const double MAX_DISPLACEMENT = 0.20;
1368
1369 // Switch to last ephemeris (if possible)
1370 // --------------------------------------
1371 QMutableVectorIterator<cmbCorr*> im(corrs(sys));
1372 while (im.hasNext()) {
1373 cmbCorr* corr = im.next();
1374 QString prn = corr->_prn;
1375
1376 t_eph* ephLast = _ephUser.ephLast(prn);
1377 t_eph* ephPrev = _ephUser.ephPrev(prn);
1378
1379 if (ephLast == 0) {
1380 out << "checkOrbit: missing eph (not found) " << corr->_prn.mid(0,3) << "\n";
1381 delete corr;
1382 im.remove();
1383 }
1384 else if (corr->_eph == 0) {
1385 out << "checkOrbit: missing eph (zero) " << corr->_prn.mid(0,3) << "\n";
1386 delete corr;
1387 im.remove();
1388 }
1389 else {
1390 if ( corr->_eph == ephLast || corr->_eph == ephPrev ) {
1391 switchToLastEph(ephLast, corr);
1392 }
1393 else {
1394 out << "checkOrbit: missing eph (deleted) " << corr->_prn.mid(0,3) << "\n";
1395 delete corr;
1396 im.remove();
1397 }
1398 }
1399 }
1400
1401 while (true) {
1402
1403 // Compute Mean Corrections for all Satellites
1404 // -------------------------------------------
1405 QMap<QString, int> numCorr;
1406 QMap<QString, ColumnVector> meanRao;
1407 QVectorIterator<cmbCorr*> it(corrs(sys));
1408 while (it.hasNext()) {
1409 cmbCorr* corr = it.next();
1410 QString prn = corr->_prn;
1411 if (meanRao.find(prn) == meanRao.end()) {
1412 meanRao[prn].ReSize(4);
1413 meanRao[prn].Rows(1,3) = corr->_orbCorr->_xr;
1414 meanRao[prn](4) = 1;
1415 }
1416 else {
1417 meanRao[prn].Rows(1,3) += corr->_orbCorr->_xr;
1418 meanRao[prn](4) += 1;
1419 }
1420 if (numCorr.find(prn) == numCorr.end()) {
1421 numCorr[prn] = 1;
1422 }
1423 else {
1424 numCorr[prn] += 1;
1425 }
1426 }
1427
1428 // Compute Differences wrt. Mean, find Maximum
1429 // -------------------------------------------
1430 QMap<QString, cmbCorr*> maxDiff;
1431 it.toFront();
1432 while (it.hasNext()) {
1433 cmbCorr* corr = it.next();
1434 QString prn = corr->_prn;
1435 if (meanRao[prn](4) != 0) {
1436 meanRao[prn] /= meanRao[prn](4);
1437 meanRao[prn](4) = 0;
1438 }
1439 corr->_diffRao = corr->_orbCorr->_xr - meanRao[prn].Rows(1,3);
1440 if (maxDiff.find(prn) == maxDiff.end()) {
1441 maxDiff[prn] = corr;
1442 }
1443 else {
1444 double normMax = maxDiff[prn]->_diffRao.NormFrobenius();
1445 double norm = corr->_diffRao.NormFrobenius();
1446 if (norm > normMax) {
1447 maxDiff[prn] = corr;
1448 }
1449 }
1450 }
1451
1452 if (_ACs.size() == 1) {
1453 break;
1454 }
1455
1456 // Remove Outliers
1457 // ---------------
1458 bool removed = false;
1459 QMutableVectorIterator<cmbCorr*> im(corrs(sys));
1460 while (im.hasNext()) {
1461 cmbCorr* corr = im.next();
1462 QString prn = corr->_prn;
1463 if (numCorr[prn] < 2) {
1464 delete corr;
1465 im.remove();
1466 }
1467 else if (corr == maxDiff[prn]) {
1468 double norm = corr->_diffRao.NormFrobenius();
1469 if (norm > MAX_DISPLACEMENT) {
1470 out << epoTime.datestr().c_str() << " "
1471 << epoTime.timestr().c_str() << " "
1472 << "Orbit Outlier: "
1473 << corr->_acName.toLatin1().data() << " "
1474 << prn.mid(0,3).toLatin1().data() << " "
1475 << corr->_iod << " "
1476 << norm << "\n";
1477 delete corr;
1478 im.remove();
1479 removed = true;
1480 }
1481 }
1482 }
1483
1484 if (!removed) {
1485 break;
1486 }
1487 }
1488
1489 return success;
1490}
1491
1492//
1493////////////////////////////////////////////////////////////////////////////
1494void bncComb::slotProviderIDChanged(QString mountPoint) {
1495 QMutexLocker locker(&_mutex);
1496
1497 QTextStream out(&_log, QIODevice::WriteOnly);
1498
1499 // Find the AC Name
1500 // ----------------
1501 QString acName;
1502 QListIterator<cmbAC*> icAC(_ACs);
1503 while (icAC.hasNext()) {
1504 cmbAC *AC = icAC.next();
1505 if (AC->mountPoint == mountPoint) {
1506 acName = AC->name;
1507 out << "Provider ID changed: AC " << AC->name.toLatin1().data() << " "
1508 << _resTime.datestr().c_str() << " " << _resTime.timestr().c_str()
1509 << "\n";
1510 break;
1511 }
1512 }
1513 if (acName.isEmpty()) {
1514 return;
1515 }
1516 QMapIterator<char, unsigned> itSys(_cmbSysPrn);
1517 while (itSys.hasNext()) {
1518 itSys.next();
1519 char sys = itSys.key();
1520 // Remove all corrections of the corresponding AC
1521 // ----------------------------------------------
1522 QVector<cmbCorr*> &corrVec = _buffer[sys].corrs;
1523 QMutableVectorIterator<cmbCorr*> it(corrVec);
1524 while (it.hasNext()) {
1525 cmbCorr *corr = it.next();
1526 if (acName == corr->_acName) {
1527 delete corr;
1528 it.remove();
1529 }
1530 }
1531 // Reset Satellite Offsets
1532 // -----------------------
1533 if (_method == filter) {
1534 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1535 cmbParam *pp = _params[sys][iPar - 1];
1536 if (pp->AC == acName && pp->type == cmbParam::offACSat) {
1537 pp->xx = 0.0;
1538 _QQ[sys].Row(iPar) = 0.0;
1539 _QQ[sys].Column(iPar) = 0.0;
1540 _QQ[sys](iPar, iPar) = pp->sig0 * pp->sig0;
1541 }
1542 }
1543 }
1544 }
1545}
Note: See TracBrowser for help on using the repository browser.