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

Last change on this file since 10038 was 10038, checked in by stuerze, 12 months ago

minor changes

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