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

Last change on this file since 10475 was 10475, checked in by stuerze, 5 months ago

minor changes

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