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

Last change on this file was 10451, checked in by stuerze, 40 hours ago

two more options added to the combination procedure

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