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

Last change on this file since 10480 was 10479, checked in by stuerze, 21 months ago

BNC writes combination results now in a separate output file

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