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

Last change on this file since 10962 was 10962, checked in by stuerze, 3 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
[10958]1176 // Reject GLONASS corrections whose broadcast ephemeris has exceeded its
1177 // declared validity window. GLONASS nav ephemerides are issued every
1178 // 30 min and are valid for ±900 s around the reference time (TOC).
1179 // t_ephGlo::position() uses Runge-Kutta integration from TOC; beyond
1180 // ±900 s the integration error grows unchecked and propagates into both
1181 // the combined clock estimate and the SP3 position.
1182 if (corr->_eph->prn().system() == 'R') {
1183 double age = epoTime - corr->_eph->TOC();
1184 if (fabs(age) > 900.0) {
1185 emit newMessage(QString().asprintf(
1186 "bncComb: skip %s, GLONASS eph age %.0fs",
1187 corr->_prn.mid(0,3).toLatin1().data(), age).toLatin1(), false);
1188 delete corr;
1189 it.remove();
1190 continue;
1191 }
1192 }
1193
[9676]1194 // ORBIT
[10216]1195 t_orbCorr orbCorr(corr->_orbCorr);
[7013]1196 orbCorr._staID = "INTERNAL";
1197 orbCorrections.push_back(orbCorr);
[10038]1198
[9676]1199 // CLOCK
[10225]1200 t_clkCorr clkCorr(corr->_clkCorr);
[7013]1201 clkCorr._staID = "INTERNAL";
1202 clkCorr._dClk = corr->_dClkResult;
1203 clkCorr._dotDClk = 0.0;
1204 clkCorr._dotDotDClk = 0.0;
1205 clkCorrections.push_back(clkCorr);
[10038]1206
[8542]1207 ColumnVector xc(6);
[4978]1208 ColumnVector vv(3);
[7013]1209 corr->_eph->setClkCorr(dynamic_cast<const t_clkCorr*>(&clkCorr));
1210 corr->_eph->setOrbCorr(dynamic_cast<const t_orbCorr*>(&orbCorr));
[10954]1211
[10038]1212 if (corr->_eph->getCrd(epoTime, xc, vv, true) != success) {
[9268]1213 delete corr;
[10229]1214 it.remove();
[9268]1215 continue;
1216 }
[10956]1217
[4978]1218 // Correction Phase Center --> CoM
1219 // -------------------------------
[10153]1220 ColumnVector dx(3); dx = 0.0;
[10116]1221 ColumnVector apc(3); apc = 0.0;
1222 ColumnVector com(3); com = 0.0;
1223 bool masterIsAPC = true;
[4978]1224 if (_antex) {
[10038]1225 double Mjd = epoTime.mjd() + epoTime.daysec()/86400.0;
[10116]1226 char sys = corr->_eph->prn().system();
1227 masterIsAPC = _masterIsAPC[sys];
[10955]1228
1229 // Determine attitude mode from the master orbit AC for this system
1230 bncAntex::e_attMode attMode = bncAntex::ATT_COMPUTED;
1231 double extYaw = 0.0;
1232 const QString& masterName = _masterOrbitAC[sys];
1233 for (const cmbAC* ac : _ACs) {
1234 if (ac->name == masterName) {
1235 if (ac->attitudeSource == "SSR" && corr->_satYawAngleValid) {
1236 attMode = bncAntex::ATT_EXTERNAL;
1237 extYaw = corr->_satYawAngle;
1238 }
1239 else if (ac->attitudeSource == "Nominal") {
1240 attMode = bncAntex::ATT_NOMINAL;
1241 }
1242 break;
1243 }
1244 }
1245
1246 if (_antex->satCoMcorrection(corr->_prn, Mjd, xc.Rows(1,3), vv, dx,
1247 attMode, extYaw) != success) {
[4992]1248 dx = 0;
[10949]1249 emit newMessage("bncComb: antenna not found " + corr->_prn.mid(0,3).toLatin1(), false);
[3214]1250 }
[10949]1251 QString glonassYawLog = _antex->takeGlonassYawLog();
1252 if (!glonassYawLog.isEmpty()) {
1253 emit newMessage(("bncComb: " + glonassYawLog.trimmed()).toLatin1(), false);
1254 }
[10955]1255 QString gpsYawLog = _antex->takeGpsYawLog();
1256 if (!gpsYawLog.isEmpty()) {
1257 emit newMessage(("bncComb: " + gpsYawLog.trimmed()).toLatin1(), false);
1258 }
1259 QString onYawLog = _antex->takeOnYawLog();
1260 if (!onYawLog.isEmpty()) {
1261 emit newMessage(("bncComb: " + onYawLog.trimmed()).toLatin1(), false);
1262 }
[3214]1263 }
[10116]1264 if (masterIsAPC) {
1265 apc(1) = xc(1);
1266 apc(2) = xc(2);
1267 apc(3) = xc(3);
1268 com(1) = xc(1)-dx(1);
1269 com(2) = xc(2)-dx(2);
1270 com(3) = xc(3)-dx(3);
1271 }
1272 else {
1273 com(1) = xc(1);
1274 com(2) = xc(2);
1275 com(3) = xc(3);
1276 apc(1) = xc(1)+dx(1);
1277 apc(2) = xc(2)+dx(2);
1278 apc(3) = xc(3)+dx(3);
1279 }
[7012]1280
1281 outLines += corr->_prn.mid(0,3);
[10109]1282 QString hlp = QString().asprintf(
1283 " APC 3 %15.4f %15.4f %15.4f"
[9676]1284 " Clk 1 %15.4f"
1285 " Vel 3 %15.4f %15.4f %15.4f"
[10822]1286 " CoM 3 %15.4f %15.4f %15.4f",
[10116]1287 apc(1), apc(2), apc(3),
[9676]1288 xc(4) * t_CST::c,
1289 vv(1), vv(2), vv(3),
[10881]1290 com(1), com(2), com(3));
[5337]1291 outLines += hlp;
[9676]1292 hlp.clear();
[5337]1293
[10101]1294 // CODE BIASES
[10216]1295 if (corr->_satCodeBias._bias.size()) {
1296 t_satCodeBias satCodeBias(corr->_satCodeBias);
[10101]1297 satCodeBias._staID = "INTERNAL";
1298 satCodeBiasList.push_back(satCodeBias);
[9676]1299 hlp = QString().asprintf(" CodeBias %2lu", satCodeBias._bias.size());
1300 outLines += hlp;
1301 hlp.clear();
1302 for (unsigned ii = 0; ii < satCodeBias._bias.size(); ii++) {
1303 const t_frqCodeBias& frqCodeBias = satCodeBias._bias[ii];
1304 if (!frqCodeBias._rnxType2ch.empty()) {
[10881]1305 hlp = QString().asprintf(" %s%12.6f",
1306 frqCodeBias._rnxType2ch.c_str(),
1307 frqCodeBias._value);
[9676]1308 outLines += hlp;
1309 hlp.clear();
1310 }
1311 }
1312 }
[10881]1313 // PHASE BIASES
1314 /* can be added as soon as yaw agles from the ACs have useful values
1315 t_satPhaseBias satPhaseBias(corr->_satPhaseBias);
1316 satPhaseBias._staID = "INTERNAL";
1317 satPhaseBias._yaw = corr->_satYawAngle;
1318 satPhaseBiasList.push_back(satPhaseBias);
1319 hlp = QString().asprintf(" YawAngle %1.4f", satPhaseBias._yaw);
1320 outLines += hlp;
1321 hlp.clear();
1322 hlp = QString().asprintf(" PhaseBias %2lu", satPhaseBias._bias.size());
1323 outLines += hlp;
1324 hlp.clear();
1325 for (unsigned ii = 0; ii < satPhaseBias._bias.size(); ii++) {
1326 const t_frqPhaseBias& frqPhaseBias = satPhaseBias._bias[ii];
1327 if (!frqPhaseBias._rnxType2ch.empty()) {
1328 hlp = QString().asprintf(" %s%10.6f%3d%3d%3d",
1329 frqPhaseBias._rnxType2ch.c_str(),
1330 frqPhaseBias._value,
1331 frqPhaseBias._fixIndicator,
1332 frqPhaseBias._fixWideLaneIndicator,
1333 frqPhaseBias._jumpCounter);
1334 outLines += hlp;
1335 hlp.clear();
1336 }
1337 }*/
[9676]1338 outLines += "\n";
[3214]1339 delete corr;
[10229]1340 it.remove();
[3214]1341 }
[5337]1342 outLines += "EOE\n"; // End Of Epoch flag
[9710]1343 //cout << outLines.toStdString();
[5337]1344
[3215]1345 vector<string> errmsg;
[8204]1346 _rtnetDecoder->Decode(outLines.toLatin1().data(), outLines.length(), errmsg);
[3215]1347
[5861]1348 // Send new Corrections to PPP etc.
1349 // --------------------------------
[6161]1350 if (orbCorrections.size() > 0 && clkCorrections.size() > 0) {
1351 emit newOrbCorrections(orbCorrections);
1352 emit newClkCorrections(clkCorrections);
1353 }
[9676]1354 if (satCodeBiasList.size()) {
1355 emit newCodeBiases(satCodeBiasList);
1356 }
[3202]1357}
[3455]1358
1359// Create First Design Matrix and Vector of Measurements
1360////////////////////////////////////////////////////////////////////////////
[10820]1361t_irc bncComb::createAmat(char sys, Matrix& AA, ColumnVector& ll, DiagonalMatrix& PP, const ColumnVector& x0, const QMap<QString, cmbCorr*>& masterCorr) {
[3455]1362
[9258]1363 unsigned nPar = _params[sys].size();
1364 unsigned nObs = corrs(sys).size();
[3455]1365
1366 if (nObs == 0) {
1367 return failure;
1368 }
1369
[9258]1370 int maxSat = _cmbSysPrn[sys];
[3455]1371
[9259]1372 const int nCon = (_method == filter) ? 1 + maxSat : 0;
[3483]1373
[3455]1374 AA.ReSize(nObs+nCon, nPar); AA = 0.0;
1375 ll.ReSize(nObs+nCon); ll = 0.0;
1376 PP.ReSize(nObs+nCon); PP = 1.0 / (sigObs * sigObs);
1377
1378 int iObs = 0;
[9258]1379 QVectorIterator<cmbCorr*> itCorr(corrs(sys));
[3455]1380 while (itCorr.hasNext()) {
1381 cmbCorr* corr = itCorr.next();
[6157]1382 QString prn = corr->_prn;
[3487]1383
[3455]1384 ++iObs;
1385
[9258]1386 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1387 cmbParam* pp = _params[sys][iPar-1];
1388 AA(iObs, iPar) = pp->partial(sys, corr->_acName, prn);
[3455]1389 }
[10694]1390 // Consistency corrections to keep the combined clock consistent to masterOrbit
1391 // ----------------------------------------------------------------------------
[10820]1392 double dC_orb = DotProduct((corr->_satPos - masterCorr[prn]->_satPos), corr->_satPos);
1393 dC_orb /= masterCorr[prn]->_satPos.NormFrobenius();
1394 double dC_att = (corr->_satYawAngle - masterCorr[prn]->_satYawAngle) / (2 * M_PI);
1395 dC_att *= corr->_lambdaIF;
[10881]1396 double dC_apriori_corr = dC_orb;// + dC_att; can be added if useful values are provided by the ACs
[3455]1397
[10813]1398 ll(iObs) = ((corr->_clkCorr._dClk * t_CST::c) - dC_apriori_corr - corr->_satCodeBiasIF) - DotProduct(AA.Row(iObs), x0);
[9819]1399
[9821]1400 PP(iObs, iObs) *= 1.0 / (corr->_weightFactor * corr->_weightFactor);
[3455]1401 }
1402
1403 // Regularization
1404 // --------------
[3474]1405 if (_method == filter) {
1406 const double Ph = 1.e6;
1407 PP(nObs+1) = Ph;
[9258]1408 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1409 cmbParam* pp = _params[sys][iPar-1];
[3465]1410 if ( AA.Column(iPar).maximum_absolute_value() > 0.0 &&
[3474]1411 pp->type == cmbParam::clkSat ) {
1412 AA(nObs+1, iPar) = 1.0;
[3455]1413 }
1414 }
[10962]1415 //if (sys == 'R') {
1416 // return success;
1417 // }
[9259]1418 int iCond = 1;
1419 // GNSS
[9258]1420 for (unsigned iGnss = 1; iGnss <= _cmbSysPrn[sys]; iGnss++) {
[10599]1421 int flag = t_corrSSR::getSsrNavTypeFlag(sys, iGnss);
[9258]1422 QString prn = QString("%1%2_%3").arg(sys).arg(iGnss, 2, 10, QChar('0')).arg(flag);
[3474]1423 ++iCond;
1424 PP(nObs+iCond) = Ph;
[9258]1425 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1426 cmbParam* pp = _params[sys][iPar-1];
[7299]1427 if ( pp &&
1428 AA.Column(iPar).maximum_absolute_value() > 0.0 &&
[7297]1429 pp->type == cmbParam::offACSat &&
[3474]1430 pp->prn == prn) {
1431 AA(nObs+iCond, iPar) = 1.0;
1432 }
1433 }
1434 }
[3455]1435 }
1436
1437 return success;
1438}
[3470]1439
1440// Process Epoch - Single-Epoch Method
1441////////////////////////////////////////////////////////////////////////////
[10038]1442t_irc bncComb::processEpoch_singleEpoch(bncTime epoTime, char sys, QTextStream& out,
[10694]1443 QMap<QString, cmbCorr*>& masterCorr,
[3475]1444 ColumnVector& dx) {
[3470]1445
[3487]1446 // Check Satellite Positions for Outliers
1447 // --------------------------------------
[10694]1448 if (checkOrbits(epoTime, sys, out, masterCorr) != success) {
[3487]1449 return failure;
1450 }
1451
[3482]1452 // Outlier Detection Loop
1453 // ----------------------
[10227]1454 while (_running) {
[3482]1455 // Count Number of Observations per Satellite and per AC
1456 // -----------------------------------------------------
1457 QMap<QString, int> numObsPrn;
1458 QMap<QString, int> numObsAC;
[9258]1459 QVectorIterator<cmbCorr*> itCorr(corrs(sys));
[3482]1460 while (itCorr.hasNext()) {
1461 cmbCorr* corr = itCorr.next();
[6157]1462 QString prn = corr->_prn;
1463 QString AC = corr->_acName;
[3482]1464 if (numObsPrn.find(prn) == numObsPrn.end()) {
1465 numObsPrn[prn] = 1;
1466 }
1467 else {
1468 numObsPrn[prn] += 1;
1469 }
1470 if (numObsAC.find(AC) == numObsAC.end()) {
1471 numObsAC[AC] = 1;
1472 }
1473 else {
1474 numObsAC[AC] += 1;
1475 }
[3476]1476 }
[7297]1477
[9258]1478 // Clean-Up the Parameters
1479 // -----------------------
1480 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
1481 delete _params[sys][iPar-1];
[3474]1482 }
[9258]1483 _params[sys].clear();
[7297]1484
[3482]1485 // Set new Parameters
1486 // ------------------
1487 int nextPar = 0;
[7297]1488
[3482]1489 QMapIterator<QString, int> itAC(numObsAC);
1490 while (itAC.hasNext()) {
1491 itAC.next();
1492 const QString& AC = itAC.key();
1493 int numObs = itAC.value();
[9258]1494 if (AC != _masterOrbitAC[sys] && numObs > 0) {
1495 _params[sys].push_back(new cmbParam(cmbParam::offACgnss, ++nextPar, AC, ""));
[3482]1496 }
[7297]1497 }
1498
[3482]1499 QMapIterator<QString, int> itPrn(numObsPrn);
1500 while (itPrn.hasNext()) {
1501 itPrn.next();
1502 const QString& prn = itPrn.key();
1503 int numObs = itPrn.value();
1504 if (numObs > 0) {
[9258]1505 _params[sys].push_back(new cmbParam(cmbParam::clkSat, ++nextPar, "", prn));
[3482]1506 }
[7297]1507 }
1508
[9258]1509 int nPar = _params[sys].size();
[7297]1510 ColumnVector x0(nPar);
[3482]1511 x0 = 0.0;
[7297]1512
[3482]1513 // Create First-Design Matrix
1514 // --------------------------
1515 Matrix AA;
1516 ColumnVector ll;
1517 DiagonalMatrix PP;
[10820]1518 if (createAmat(sys, AA, ll, PP, x0, masterCorr) != success) {
[3482]1519 return failure;
[3476]1520 }
[7297]1521
[3482]1522 ColumnVector vv;
1523 try {
1524 Matrix ATP = AA.t() * PP;
1525 SymmetricMatrix NN; NN << ATP * AA;
1526 ColumnVector bb = ATP * ll;
[9258]1527 _QQ[sys] = NN.i();
1528 dx = _QQ[sys] * bb;
[3482]1529 vv = ll - AA * dx;
[3476]1530 }
[3482]1531 catch (Exception& exc) {
[9635]1532 out << exc.what() << "\n";
[3482]1533 return failure;
[3476]1534 }
[3474]1535
[3482]1536 int maxResIndex;
[7297]1537 double maxRes = vv.maximum_absolute_value1(maxResIndex);
[3482]1538 out.setRealNumberNotation(QTextStream::FixedNotation);
[7297]1539 out.setRealNumberPrecision(3);
[10038]1540 out << epoTime.datestr().c_str() << " " << epoTime.timestr().c_str()
[3482]1541 << " Maximum Residuum " << maxRes << ' '
[9258]1542 << corrs(sys)[maxResIndex-1]->_acName << ' ' << corrs(sys)[maxResIndex-1]->_prn.mid(0,3);
[3474]1543
[10451]1544 if (maxRes > _MAX_RES) {
[9635]1545 out << " Outlier" << "\n";
[9258]1546 delete corrs(sys)[maxResIndex-1];
1547 corrs(sys).remove(maxResIndex-1);
[3474]1548 }
[3482]1549 else {
[9635]1550 out << " OK" << "\n";
[3482]1551 out.setRealNumberNotation(QTextStream::FixedNotation);
[7297]1552 out.setRealNumberPrecision(3);
[3482]1553 for (int ii = 0; ii < vv.Nrows(); ii++) {
[9258]1554 const cmbCorr* corr = corrs(sys)[ii];
[10038]1555 out << epoTime.datestr().c_str() << ' '
1556 << epoTime.timestr().c_str() << " "
[6962]1557 << corr->_acName << ' ' << corr->_prn.mid(0,3);
[3482]1558 out.setFieldWidth(6);
[9635]1559 out << " res = " << vv[ii] << "\n";
[3482]1560 out.setFieldWidth(0);
1561 }
1562 return success;
[3474]1563 }
1564
[3473]1565 }
[3474]1566
[3482]1567 return failure;
[3470]1568}
[3487]1569
1570// Check Satellite Positions for Outliers
1571////////////////////////////////////////////////////////////////////////////
[10694]1572t_irc bncComb::checkOrbits(bncTime epoTime, char sys, QTextStream& out, QMap<QString, cmbCorr*>& masterCorr) {
[3487]1573
[3502]1574 // Switch to last ephemeris (if possible)
1575 // --------------------------------------
[9258]1576 QMutableVectorIterator<cmbCorr*> im(corrs(sys));
[3501]1577 while (im.hasNext()) {
1578 cmbCorr* corr = im.next();
[6157]1579 QString prn = corr->_prn;
[6443]1580
[7012]1581 t_eph* ephLast = _ephUser.ephLast(prn);
1582 t_eph* ephPrev = _ephUser.ephPrev(prn);
[6443]1583
1584 if (ephLast == 0) {
[9635]1585 out << "checkOrbit: missing eph (not found) " << corr->_prn.mid(0,3) << "\n";
[3556]1586 delete corr;
[3501]1587 im.remove();
1588 }
[6157]1589 else if (corr->_eph == 0) {
[9635]1590 out << "checkOrbit: missing eph (zero) " << corr->_prn.mid(0,3) << "\n";
[3556]1591 delete corr;
[3503]1592 im.remove();
1593 }
[3502]1594 else {
[10612]1595 if ( corr->_eph == ephLast ||
1596 corr->_eph == ephPrev ) {
[6443]1597 switchToLastEph(ephLast, corr);
[10820]1598
1599 ColumnVector xc(6);
1600 ColumnVector vv(3);
1601 if (corr->_eph->getCrd(corr->_time, xc, vv, false) != success) {
1602 delete corr;
1603 im.remove();
1604 }
1605 else {
1606 corr->_satPos = xc.Rows(1,3);
1607 }
[3502]1608 }
1609 else {
[9635]1610 out << "checkOrbit: missing eph (deleted) " << corr->_prn.mid(0,3) << "\n";
[3556]1611 delete corr;
[3502]1612 im.remove();
1613 }
1614 }
[3501]1615 }
1616
[10227]1617 while (_running) {
[3488]1618
1619 // Compute Mean Corrections for all Satellites
1620 // -------------------------------------------
[3489]1621 QMap<QString, int> numCorr;
[3488]1622 QMap<QString, ColumnVector> meanRao;
[9258]1623 QVectorIterator<cmbCorr*> it(corrs(sys));
[3488]1624 while (it.hasNext()) {
1625 cmbCorr* corr = it.next();
[6157]1626 QString prn = corr->_prn;
[10820]1627
[3488]1628 if (meanRao.find(prn) == meanRao.end()) {
1629 meanRao[prn].ReSize(4);
[10216]1630 meanRao[prn].Rows(1,3) = corr->_orbCorr._xr;
[7297]1631 meanRao[prn](4) = 1;
[3488]1632 }
1633 else {
[10216]1634 meanRao[prn].Rows(1,3) += corr->_orbCorr._xr;
[7297]1635 meanRao[prn](4) += 1;
[3488]1636 }
[3489]1637 if (numCorr.find(prn) == numCorr.end()) {
1638 numCorr[prn] = 1;
1639 }
1640 else {
1641 numCorr[prn] += 1;
1642 }
[3487]1643 }
[7297]1644
[9258]1645 // Compute Differences wrt. Mean, find Maximum
1646 // -------------------------------------------
[3488]1647 QMap<QString, cmbCorr*> maxDiff;
1648 it.toFront();
1649 while (it.hasNext()) {
1650 cmbCorr* corr = it.next();
[6157]1651 QString prn = corr->_prn;
[3488]1652 if (meanRao[prn](4) != 0) {
1653 meanRao[prn] /= meanRao[prn](4);
1654 meanRao[prn](4) = 0;
1655 }
[10820]1656 corr->_diffRao2Mean = corr->_orbCorr._xr - meanRao[prn].Rows(1,3);
[10665]1657
[3488]1658 if (maxDiff.find(prn) == maxDiff.end()) {
1659 maxDiff[prn] = corr;
1660 }
1661 else {
[10820]1662 double normMax = maxDiff[prn]->_diffRao2Mean.NormFrobenius();
1663 double norm = corr->_diffRao2Mean.NormFrobenius();
[3488]1664 if (norm > normMax) {
1665 maxDiff[prn] = corr;
1666 }
[7297]1667 }
[3487]1668 }
[7297]1669
[3655]1670 if (_ACs.size() == 1) {
[10665]1671 QVectorIterator<cmbCorr*> it(corrs(sys));
1672 while (it.hasNext()) {
1673 cmbCorr* corr = it.next();
1674 QString prn = corr->_prn;
[10820]1675 if (corr->_acName == _masterOrbitAC[sys] && masterCorr.find(prn) == masterCorr.end()) {
[10694]1676 masterCorr[prn] = new cmbCorr(*corr);
[10665]1677 }
1678 }
[3655]1679 break;
1680 }
1681
[3488]1682 // Remove Outliers
1683 // ---------------
1684 bool removed = false;
[9258]1685 QMutableVectorIterator<cmbCorr*> im(corrs(sys));
[3488]1686 while (im.hasNext()) {
1687 cmbCorr* corr = im.next();
[6157]1688 QString prn = corr->_prn;
[3489]1689 if (numCorr[prn] < 2) {
[3556]1690 delete corr;
[3489]1691 im.remove();
1692 }
1693 else if (corr == maxDiff[prn]) {
[10820]1694 double norm = corr->_diffRao2Mean.NormFrobenius();
[10816]1695 if (norm > _MAX_DISPLACEMENT) {
[10038]1696 out << epoTime.datestr().c_str() << " "
1697 << epoTime.timestr().c_str() << " "
[7297]1698 << "Orbit Outlier: "
[8204]1699 << corr->_acName.toLatin1().data() << " "
1700 << prn.mid(0,3).toLatin1().data() << " "
[7297]1701 << corr->_iod << " "
[9635]1702 << norm << "\n";
[3556]1703 delete corr;
[3488]1704 im.remove();
1705 removed = true;
1706 }
1707 }
[3487]1708 }
[10665]1709 // Set master orbit
1710 // -----------------------------------------
[3488]1711 if (!removed) {
[10665]1712 QVectorIterator<cmbCorr*> it(corrs(sys));
1713 while (it.hasNext()) {
1714 cmbCorr* corr = it.next();
1715 QString prn = corr->_prn;
[10820]1716 if (corr->_acName == _masterOrbitAC[sys] && masterCorr.find(prn) == masterCorr.end()) {
[10694]1717 masterCorr[prn] = new cmbCorr(*corr);
[10665]1718 }
1719 }
1720 // Remove satellites that are not in masterOrbit
1721 // and compute differences wrt. masterOrbit
1722 // ----------------------------------------------
1723 QMutableVectorIterator<cmbCorr*> im(corrs(sys));
1724 while (im.hasNext()) {
1725 cmbCorr* corr = im.next();
1726 QString prn = corr->_prn;
[10694]1727 if (masterCorr.find(prn) == masterCorr.end()) {
[10665]1728 delete corr;
1729 im.remove();
1730 }
1731 }
[3488]1732 break;
1733 }
[3487]1734 }
1735
1736 return success;
1737}
[3588]1738
[7297]1739//
[3588]1740////////////////////////////////////////////////////////////////////////////
[5583]1741void bncComb::slotProviderIDChanged(QString mountPoint) {
1742 QMutexLocker locker(&_mutex);
1743
[8065]1744 QTextStream out(&_log, QIODevice::WriteOnly);
1745
[5583]1746 // Find the AC Name
1747 // ----------------
1748 QString acName;
1749 QListIterator<cmbAC*> icAC(_ACs);
1750 while (icAC.hasNext()) {
[10038]1751 cmbAC *AC = icAC.next();
[5583]1752 if (AC->mountPoint == mountPoint) {
1753 acName = AC->name;
[10764]1754 out << "SSR Provider or Service changed: AC " << AC->name.toLatin1().data() << " "
[10081]1755 << _resTime.datestr().c_str() << " " << _resTime.timestr().c_str()
[10038]1756 << "\n";
[5583]1757 break;
1758 }
1759 }
1760 if (acName.isEmpty()) {
1761 return;
1762 }
[9258]1763 QMapIterator<char, unsigned> itSys(_cmbSysPrn);
1764 while (itSys.hasNext()) {
1765 itSys.next();
1766 char sys = itSys.key();
1767 // Remove all corrections of the corresponding AC
1768 // ----------------------------------------------
[10038]1769 QVector<cmbCorr*> &corrVec = _buffer[sys].corrs;
1770 QMutableVectorIterator<cmbCorr*> it(corrVec);
1771 while (it.hasNext()) {
1772 cmbCorr *corr = it.next();
1773 if (acName == corr->_acName) {
1774 delete corr;
1775 it.remove();
[5583]1776 }
1777 }
[9258]1778 // Reset Satellite Offsets
1779 // -----------------------
1780 if (_method == filter) {
1781 for (int iPar = 1; iPar <= _params[sys].size(); iPar++) {
[10038]1782 cmbParam *pp = _params[sys][iPar - 1];
[9258]1783 if (pp->AC == acName && pp->type == cmbParam::offACSat) {
1784 pp->xx = 0.0;
[10038]1785 _QQ[sys].Row(iPar) = 0.0;
[9258]1786 _QQ[sys].Column(iPar) = 0.0;
[10038]1787 _QQ[sys](iPar, iPar) = pp->sig0 * pp->sig0;
[9258]1788 }
[5585]1789 }
1790 }
1791 }
[5583]1792}
[10451]1793
1794//
1795////////////////////////////////////////////////////////////////////////////
1796bool bncComb::excludeSat(const t_prn& prn, const QStringList excludeSats) const {
1797 QStringListIterator it(excludeSats);
1798 while (it.hasNext()) {
1799 string prnStr = it.next().toLatin1().data();
[10599]1800 if (prnStr == prn.toString() || // prn
1801 prnStr == prn.toString().substr(0,1)) { // sys
[10451]1802 return true;
1803 }
1804 }
1805 return false;
1806}
Note: See TracBrowser for help on using the repository browser.