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

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

minor changes

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