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

Last change on this file since 10113 was 10109, checked in by stuerze, 20 months 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
[7013]1051
[8542]1052 ColumnVector xc(6);
[4978]1053 ColumnVector vv(3);
[7013]1054 corr->_eph->setClkCorr(dynamic_cast<const t_clkCorr*>(&clkCorr));
1055 corr->_eph->setOrbCorr(dynamic_cast<const t_orbCorr*>(&orbCorr));
[10038]1056 if (corr->_eph->getCrd(epoTime, xc, vv, true) != success) {
[9268]1057 delete corr;
1058 continue;
1059 }
[7012]1060
[4978]1061 // Correction Phase Center --> CoM
1062 // -------------------------------
1063 ColumnVector dx(3); dx = 0.0;
1064 if (_antex) {
[10038]1065 double Mjd = epoTime.mjd() + epoTime.daysec()/86400.0;
[6157]1066 if (_antex->satCoMcorrection(corr->_prn, Mjd, xc.Rows(1,3), dx) != success) {
[4992]1067 dx = 0;
[8204]1068 _log += "antenna not found " + corr->_prn.mid(0,3).toLatin1() + '\n';
[3214]1069 }
1070 }
[7012]1071
1072 outLines += corr->_prn.mid(0,3);
[10109]1073 QString hlp = QString().asprintf(
1074 " APC 3 %15.4f %15.4f %15.4f"
[9676]1075 " Clk 1 %15.4f"
1076 " Vel 3 %15.4f %15.4f %15.4f"
1077 " CoM 3 %15.4f %15.4f %15.4f",
1078 xc(1), xc(2), xc(3),
1079 xc(4) * t_CST::c,
1080 vv(1), vv(2), vv(3),
1081 xc(1)-dx(1), xc(2)-dx(2), xc(3)-dx(3));
[5337]1082 outLines += hlp;
[9676]1083 hlp.clear();
[5337]1084
[10101]1085 // CODE BIASES
1086 if (corr->_satCodeBias) {
1087 t_satCodeBias satCodeBias(static_cast<t_satCodeBias>(*corr->_satCodeBias));
1088 satCodeBias._staID = "INTERNAL";
1089 satCodeBiasList.push_back(satCodeBias);
[9676]1090 hlp = QString().asprintf(" CodeBias %2lu", satCodeBias._bias.size());
1091 outLines += hlp;
1092 hlp.clear();
1093 for (unsigned ii = 0; ii < satCodeBias._bias.size(); ii++) {
1094 const t_frqCodeBias& frqCodeBias = satCodeBias._bias[ii];
1095 if (!frqCodeBias._rnxType2ch.empty()) {
1096 hlp = QString().asprintf(" %s%10.6f", frqCodeBias._rnxType2ch.c_str(), frqCodeBias._value);
1097 outLines += hlp;
1098 hlp.clear();
1099 }
1100 }
1101 }
1102 outLines += "\n";
[3214]1103 delete corr;
1104 }
1105
[5337]1106 outLines += "EOE\n"; // End Of Epoch flag
[9710]1107 //cout << outLines.toStdString();
[5337]1108
[3215]1109 if (!_rtnetDecoder) {
1110 _rtnetDecoder = new bncRtnetDecoder();
1111 }
[3221]1112
[3215]1113 vector<string> errmsg;
[8204]1114 _rtnetDecoder->Decode(outLines.toLatin1().data(), outLines.length(), errmsg);
[3215]1115
[5861]1116 // Send new Corrections to PPP etc.
1117 // --------------------------------
[6161]1118 if (orbCorrections.size() > 0 && clkCorrections.size() > 0) {
1119 emit newOrbCorrections(orbCorrections);
1120 emit newClkCorrections(clkCorrections);
1121 }
[9676]1122 if (satCodeBiasList.size()) {
1123 emit newCodeBiases(satCodeBiasList);
1124 }
[3202]1125}
[3455]1126
1127// Create First Design Matrix and Vector of Measurements
1128////////////////////////////////////////////////////////////////////////////
[9258]1129t_irc bncComb::createAmat(char sys, Matrix& AA, ColumnVector& ll, DiagonalMatrix& PP,
1130 const ColumnVector& x0, QMap<QString, cmbCorr*>& resCorr) {
[3455]1131
[9258]1132 unsigned nPar = _params[sys].size();
1133 unsigned nObs = corrs(sys).size();
[3455]1134
1135 if (nObs == 0) {
1136 return failure;
1137 }
1138
[9258]1139 int maxSat = _cmbSysPrn[sys];
[3455]1140
[9259]1141 const int nCon = (_method == filter) ? 1 + maxSat : 0;
[3483]1142
[3455]1143 AA.ReSize(nObs+nCon, nPar); AA = 0.0;
1144 ll.ReSize(nObs+nCon); ll = 0.0;
1145 PP.ReSize(nObs+nCon); PP = 1.0 / (sigObs * sigObs);
1146
1147 int iObs = 0;
[9258]1148 QVectorIterator<cmbCorr*> itCorr(corrs(sys));
[3455]1149 while (itCorr.hasNext()) {
1150 cmbCorr* corr = itCorr.next();
[6157]1151 QString prn = corr->_prn;
[3487]1152
[3455]1153 ++iObs;
1154
[9258]1155 if (corr->_acName == _masterOrbitAC[sys] && resCorr.find(prn) == resCorr.end()) {
[6157]1156 resCorr[prn] = new cmbCorr(*corr);
[3455]1157 }
1158
[9258]1159 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1160 cmbParam* pp = _params[sys][iPar-1];
1161 AA(iObs, iPar) = pp->partial(sys, corr->_acName, prn);
[3455]1162 }
1163
[10038]1164 ll(iObs) = (corr->_clkCorr->_dClk * t_CST::c - corr->_satCodeBiasIF) - DotProduct(AA.Row(iObs), x0);
[9819]1165
[9821]1166 PP(iObs, iObs) *= 1.0 / (corr->_weightFactor * corr->_weightFactor);
[3455]1167 }
1168
1169 // Regularization
1170 // --------------
[3474]1171 if (_method == filter) {
1172 const double Ph = 1.e6;
1173 PP(nObs+1) = Ph;
[9258]1174 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1175 cmbParam* pp = _params[sys][iPar-1];
[3465]1176 if ( AA.Column(iPar).maximum_absolute_value() > 0.0 &&
[3474]1177 pp->type == cmbParam::clkSat ) {
1178 AA(nObs+1, iPar) = 1.0;
[3455]1179 }
1180 }
[9258]1181 unsigned flag = 0;
1182 if (sys == 'E') {
1183 flag = 1;
1184 }
[10026]1185// if (sys == 'R') {
1186// return success;
1187// }
[9259]1188 int iCond = 1;
1189 // GNSS
[9258]1190 for (unsigned iGnss = 1; iGnss <= _cmbSysPrn[sys]; iGnss++) {
1191 QString prn = QString("%1%2_%3").arg(sys).arg(iGnss, 2, 10, QChar('0')).arg(flag);
[3474]1192 ++iCond;
1193 PP(nObs+iCond) = Ph;
[9258]1194 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1195 cmbParam* pp = _params[sys][iPar-1];
[7299]1196 if ( pp &&
1197 AA.Column(iPar).maximum_absolute_value() > 0.0 &&
[7297]1198 pp->type == cmbParam::offACSat &&
[3474]1199 pp->prn == prn) {
1200 AA(nObs+iCond, iPar) = 1.0;
1201 }
1202 }
1203 }
[3455]1204 }
1205
1206 return success;
1207}
[3470]1208
1209// Process Epoch - Single-Epoch Method
1210////////////////////////////////////////////////////////////////////////////
[10038]1211t_irc bncComb::processEpoch_singleEpoch(bncTime epoTime, char sys, QTextStream& out,
[6157]1212 QMap<QString, cmbCorr*>& resCorr,
[3475]1213 ColumnVector& dx) {
[3470]1214
[3487]1215 // Check Satellite Positions for Outliers
1216 // --------------------------------------
[10038]1217 if (checkOrbits(epoTime, sys, out) != success) {
[3487]1218 return failure;
1219 }
1220
[3482]1221 // Outlier Detection Loop
1222 // ----------------------
1223 while (true) {
[7297]1224
[3482]1225 // Remove Satellites that are not in Master
1226 // ----------------------------------------
[9258]1227 QMutableVectorIterator<cmbCorr*> it(corrs(sys));
[3482]1228 while (it.hasNext()) {
1229 cmbCorr* corr = it.next();
[6157]1230 QString prn = corr->_prn;
[3482]1231 bool foundMaster = false;
[9258]1232 QVectorIterator<cmbCorr*> itHlp(corrs(sys));
[3482]1233 while (itHlp.hasNext()) {
1234 cmbCorr* corrHlp = itHlp.next();
[6157]1235 QString prnHlp = corrHlp->_prn;
1236 QString ACHlp = corrHlp->_acName;
[9258]1237 if (ACHlp == _masterOrbitAC[sys] && prn == prnHlp) {
[3482]1238 foundMaster = true;
1239 break;
1240 }
[3476]1241 }
[3482]1242 if (!foundMaster) {
[3556]1243 delete corr;
[3482]1244 it.remove();
1245 }
[3473]1246 }
[7297]1247
[3482]1248 // Count Number of Observations per Satellite and per AC
1249 // -----------------------------------------------------
1250 QMap<QString, int> numObsPrn;
1251 QMap<QString, int> numObsAC;
[9258]1252 QVectorIterator<cmbCorr*> itCorr(corrs(sys));
[3482]1253 while (itCorr.hasNext()) {
1254 cmbCorr* corr = itCorr.next();
[6157]1255 QString prn = corr->_prn;
1256 QString AC = corr->_acName;
[3482]1257 if (numObsPrn.find(prn) == numObsPrn.end()) {
1258 numObsPrn[prn] = 1;
1259 }
1260 else {
1261 numObsPrn[prn] += 1;
1262 }
1263 if (numObsAC.find(AC) == numObsAC.end()) {
1264 numObsAC[AC] = 1;
1265 }
1266 else {
1267 numObsAC[AC] += 1;
1268 }
[3476]1269 }
[7297]1270
[9258]1271 // Clean-Up the Parameters
1272 // -----------------------
1273 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1274 delete _params[sys][iPar-1];
[3474]1275 }
[9258]1276 _params[sys].clear();
[7297]1277
[3482]1278 // Set new Parameters
1279 // ------------------
1280 int nextPar = 0;
[7297]1281
[3482]1282 QMapIterator<QString, int> itAC(numObsAC);
1283 while (itAC.hasNext()) {
1284 itAC.next();
1285 const QString& AC = itAC.key();
1286 int numObs = itAC.value();
[9258]1287 if (AC != _masterOrbitAC[sys] && numObs > 0) {
1288 _params[sys].push_back(new cmbParam(cmbParam::offACgnss, ++nextPar, AC, ""));
[3482]1289 }
[7297]1290 }
1291
[3482]1292 QMapIterator<QString, int> itPrn(numObsPrn);
1293 while (itPrn.hasNext()) {
1294 itPrn.next();
1295 const QString& prn = itPrn.key();
1296 int numObs = itPrn.value();
1297 if (numObs > 0) {
[9258]1298 _params[sys].push_back(new cmbParam(cmbParam::clkSat, ++nextPar, "", prn));
[3482]1299 }
[7297]1300 }
1301
[9258]1302 int nPar = _params[sys].size();
[7297]1303 ColumnVector x0(nPar);
[3482]1304 x0 = 0.0;
[7297]1305
[3482]1306 // Create First-Design Matrix
1307 // --------------------------
1308 Matrix AA;
1309 ColumnVector ll;
1310 DiagonalMatrix PP;
[9258]1311 if (createAmat(sys, AA, ll, PP, x0, resCorr) != success) {
[3482]1312 return failure;
[3476]1313 }
[7297]1314
[3482]1315 ColumnVector vv;
1316 try {
1317 Matrix ATP = AA.t() * PP;
1318 SymmetricMatrix NN; NN << ATP * AA;
1319 ColumnVector bb = ATP * ll;
[9258]1320 _QQ[sys] = NN.i();
1321 dx = _QQ[sys] * bb;
[3482]1322 vv = ll - AA * dx;
[3476]1323 }
[3482]1324 catch (Exception& exc) {
[9635]1325 out << exc.what() << "\n";
[3482]1326 return failure;
[3476]1327 }
[3474]1328
[3482]1329 int maxResIndex;
[7297]1330 double maxRes = vv.maximum_absolute_value1(maxResIndex);
[3482]1331 out.setRealNumberNotation(QTextStream::FixedNotation);
[7297]1332 out.setRealNumberPrecision(3);
[10038]1333 out << epoTime.datestr().c_str() << " " << epoTime.timestr().c_str()
[3482]1334 << " Maximum Residuum " << maxRes << ' '
[9258]1335 << corrs(sys)[maxResIndex-1]->_acName << ' ' << corrs(sys)[maxResIndex-1]->_prn.mid(0,3);
[3474]1336
[3482]1337 if (maxRes > _MAXRES) {
[9635]1338 out << " Outlier" << "\n";
[9258]1339 delete corrs(sys)[maxResIndex-1];
1340 corrs(sys).remove(maxResIndex-1);
[3474]1341 }
[3482]1342 else {
[9635]1343 out << " OK" << "\n";
[3482]1344 out.setRealNumberNotation(QTextStream::FixedNotation);
[7297]1345 out.setRealNumberPrecision(3);
[3482]1346 for (int ii = 0; ii < vv.Nrows(); ii++) {
[9258]1347 const cmbCorr* corr = corrs(sys)[ii];
[10038]1348 out << epoTime.datestr().c_str() << ' '
1349 << epoTime.timestr().c_str() << " "
[6962]1350 << corr->_acName << ' ' << corr->_prn.mid(0,3);
[3482]1351 out.setFieldWidth(6);
[9635]1352 out << " res = " << vv[ii] << "\n";
[3482]1353 out.setFieldWidth(0);
1354 }
1355 return success;
[3474]1356 }
1357
[3473]1358 }
[3474]1359
[3482]1360 return failure;
[3470]1361}
[3487]1362
1363// Check Satellite Positions for Outliers
1364////////////////////////////////////////////////////////////////////////////
[10038]1365t_irc bncComb::checkOrbits(bncTime epoTime, char sys, QTextStream& out) {
[3487]1366
[3489]1367 const double MAX_DISPLACEMENT = 0.20;
[3488]1368
[3502]1369 // Switch to last ephemeris (if possible)
1370 // --------------------------------------
[9258]1371 QMutableVectorIterator<cmbCorr*> im(corrs(sys));
[3501]1372 while (im.hasNext()) {
1373 cmbCorr* corr = im.next();
[6157]1374 QString prn = corr->_prn;
[6443]1375
[7012]1376 t_eph* ephLast = _ephUser.ephLast(prn);
1377 t_eph* ephPrev = _ephUser.ephPrev(prn);
[6443]1378
1379 if (ephLast == 0) {
[9635]1380 out << "checkOrbit: missing eph (not found) " << corr->_prn.mid(0,3) << "\n";
[3556]1381 delete corr;
[3501]1382 im.remove();
1383 }
[6157]1384 else if (corr->_eph == 0) {
[9635]1385 out << "checkOrbit: missing eph (zero) " << corr->_prn.mid(0,3) << "\n";
[3556]1386 delete corr;
[3503]1387 im.remove();
1388 }
[3502]1389 else {
[6443]1390 if ( corr->_eph == ephLast || corr->_eph == ephPrev ) {
1391 switchToLastEph(ephLast, corr);
[3502]1392 }
1393 else {
[9635]1394 out << "checkOrbit: missing eph (deleted) " << corr->_prn.mid(0,3) << "\n";
[3556]1395 delete corr;
[3502]1396 im.remove();
1397 }
1398 }
[3501]1399 }
1400
[3488]1401 while (true) {
1402
1403 // Compute Mean Corrections for all Satellites
1404 // -------------------------------------------
[3489]1405 QMap<QString, int> numCorr;
[3488]1406 QMap<QString, ColumnVector> meanRao;
[9258]1407 QVectorIterator<cmbCorr*> it(corrs(sys));
[3488]1408 while (it.hasNext()) {
1409 cmbCorr* corr = it.next();
[6157]1410 QString prn = corr->_prn;
[3488]1411 if (meanRao.find(prn) == meanRao.end()) {
1412 meanRao[prn].ReSize(4);
[10038]1413 meanRao[prn].Rows(1,3) = corr->_orbCorr->_xr;
[7297]1414 meanRao[prn](4) = 1;
[3488]1415 }
1416 else {
[10038]1417 meanRao[prn].Rows(1,3) += corr->_orbCorr->_xr;
[7297]1418 meanRao[prn](4) += 1;
[3488]1419 }
[3489]1420 if (numCorr.find(prn) == numCorr.end()) {
1421 numCorr[prn] = 1;
1422 }
1423 else {
1424 numCorr[prn] += 1;
1425 }
[3487]1426 }
[7297]1427
[9258]1428 // Compute Differences wrt. Mean, find Maximum
1429 // -------------------------------------------
[3488]1430 QMap<QString, cmbCorr*> maxDiff;
1431 it.toFront();
1432 while (it.hasNext()) {
1433 cmbCorr* corr = it.next();
[6157]1434 QString prn = corr->_prn;
[3488]1435 if (meanRao[prn](4) != 0) {
1436 meanRao[prn] /= meanRao[prn](4);
1437 meanRao[prn](4) = 0;
1438 }
[10038]1439 corr->_diffRao = corr->_orbCorr->_xr - meanRao[prn].Rows(1,3);
[3488]1440 if (maxDiff.find(prn) == maxDiff.end()) {
1441 maxDiff[prn] = corr;
1442 }
1443 else {
[8901]1444 double normMax = maxDiff[prn]->_diffRao.NormFrobenius();
1445 double norm = corr->_diffRao.NormFrobenius();
[3488]1446 if (norm > normMax) {
1447 maxDiff[prn] = corr;
1448 }
[7297]1449 }
[3487]1450 }
[7297]1451
[3655]1452 if (_ACs.size() == 1) {
1453 break;
1454 }
1455
[3488]1456 // Remove Outliers
1457 // ---------------
1458 bool removed = false;
[9258]1459 QMutableVectorIterator<cmbCorr*> im(corrs(sys));
[3488]1460 while (im.hasNext()) {
1461 cmbCorr* corr = im.next();
[6157]1462 QString prn = corr->_prn;
[3489]1463 if (numCorr[prn] < 2) {
[3556]1464 delete corr;
[3489]1465 im.remove();
1466 }
1467 else if (corr == maxDiff[prn]) {
[8901]1468 double norm = corr->_diffRao.NormFrobenius();
[3488]1469 if (norm > MAX_DISPLACEMENT) {
[10038]1470 out << epoTime.datestr().c_str() << " "
1471 << epoTime.timestr().c_str() << " "
[7297]1472 << "Orbit Outlier: "
[8204]1473 << corr->_acName.toLatin1().data() << " "
1474 << prn.mid(0,3).toLatin1().data() << " "
[7297]1475 << corr->_iod << " "
[9635]1476 << norm << "\n";
[3556]1477 delete corr;
[3488]1478 im.remove();
1479 removed = true;
1480 }
1481 }
[3487]1482 }
[7297]1483
[3488]1484 if (!removed) {
1485 break;
1486 }
[3487]1487 }
1488
1489 return success;
1490}
[3588]1491
[7297]1492//
[3588]1493////////////////////////////////////////////////////////////////////////////
[5583]1494void bncComb::slotProviderIDChanged(QString mountPoint) {
1495 QMutexLocker locker(&_mutex);
1496
[8065]1497 QTextStream out(&_log, QIODevice::WriteOnly);
1498
[5583]1499 // Find the AC Name
1500 // ----------------
1501 QString acName;
1502 QListIterator<cmbAC*> icAC(_ACs);
1503 while (icAC.hasNext()) {
[10038]1504 cmbAC *AC = icAC.next();
[5583]1505 if (AC->mountPoint == mountPoint) {
1506 acName = AC->name;
[10038]1507 out << "Provider ID changed: AC " << AC->name.toLatin1().data() << " "
[10081]1508 << _resTime.datestr().c_str() << " " << _resTime.timestr().c_str()
[10038]1509 << "\n";
[5583]1510 break;
1511 }
1512 }
1513 if (acName.isEmpty()) {
1514 return;
1515 }
[9258]1516 QMapIterator<char, unsigned> itSys(_cmbSysPrn);
1517 while (itSys.hasNext()) {
1518 itSys.next();
1519 char sys = itSys.key();
1520 // Remove all corrections of the corresponding AC
1521 // ----------------------------------------------
[10038]1522 QVector<cmbCorr*> &corrVec = _buffer[sys].corrs;
1523 QMutableVectorIterator<cmbCorr*> it(corrVec);
1524 while (it.hasNext()) {
1525 cmbCorr *corr = it.next();
1526 if (acName == corr->_acName) {
1527 delete corr;
1528 it.remove();
[5583]1529 }
1530 }
[9258]1531 // Reset Satellite Offsets
1532 // -----------------------
1533 if (_method == filter) {
1534 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
[10038]1535 cmbParam *pp = _params[sys][iPar - 1];
[9258]1536 if (pp->AC == acName && pp->type == cmbParam::offACSat) {
1537 pp->xx = 0.0;
[10038]1538 _QQ[sys].Row(iPar) = 0.0;
[9258]1539 _QQ[sys].Column(iPar) = 0.0;
[10038]1540 _QQ[sys](iPar, iPar) = pp->sig0 * pp->sig0;
[9258]1541 }
[5585]1542 }
1543 }
1544 }
[5583]1545}
Note: See TracBrowser for help on using the repository browser.