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

Last change on this file since 10098 was 10098, checked in by stuerze, 3 years ago

minor changes

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