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

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

minor changes

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