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

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