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

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