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

Last change on this file since 9819 was 9819, checked in by stuerze, 20 months ago

minor chenges to allow streams without code biases within the combination

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