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

Last change on this file since 10956 was 10956, checked in by stuerze, 7 weeks ago

minor changes

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