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

Last change on this file since 10227 was 10227, checked in by stuerze, 4 months ago

minor changes

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