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

Last change on this file since 10076 was 10076, checked in by stuerze, 11 months ago

minor changes

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