source: ntrip/branches/BNC_2.12/src/combination/bnccomb.cpp@ 9180

Last change on this file since 9180 was 9180, checked in by stuerze, 3 years ago

check if orbit and clock corrections are in defined ranges is added

File size: 35.3 KB
Line 
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 *
13 * Changes:
14 *
15 * -----------------------------------------------------------------------*/
16
17#include <newmatio.h>
18#include <iomanip>
19#include <sstream>
20
21#include "bnccomb.h"
22#include "bnccore.h"
23#include "upload/bncrtnetdecoder.h"
24#include "bncsettings.h"
25#include "bncutils.h"
26#include "bncsp3.h"
27#include "bncantex.h"
28#include "t_prn.h"
29
30const double sig0_offAC = 1000.0;
31const double sig0_offACSat = 100.0;
32const double sigP_offACSat = 0.01;
33const double sig0_clkSat = 100.0;
34
35const double sigObs = 0.05;
36
37using namespace std;
38
39// Constructor
40////////////////////////////////////////////////////////////////////////////
41bncComb::cmbParam::cmbParam(parType type_, int index_, const QString& ac_, const QString& prn_) {
42
43 type = type_;
44 index = index_;
45 AC = ac_;
46 prn = prn_;
47 xx = 0.0;
48 eph = 0;
49
50 if (type == offACgps) {
51 epoSpec = true;
52 sig0 = sig0_offAC;
53 sigP = sig0;
54 }
55 else if (type == offACglo) {
56 epoSpec = true;
57 sig0 = sig0_offAC;
58 sigP = sig0;
59 }
60 else if (type == offACSat) {
61 epoSpec = false;
62 sig0 = sig0_offACSat;
63 sigP = sigP_offACSat;
64 }
65 else if (type == clkSat) {
66 epoSpec = true;
67 sig0 = sig0_clkSat;
68 sigP = sig0;
69 }
70}
71
72// Destructor
73////////////////////////////////////////////////////////////////////////////
74bncComb::cmbParam::~cmbParam() {
75}
76
77// Partial
78////////////////////////////////////////////////////////////////////////////
79double bncComb::cmbParam::partial(const QString& AC_, const QString& prn_) {
80
81 if (type == offACgps) {
82 if (AC == AC_ && prn_[0] == 'G') {
83 return 1.0;
84 }
85 }
86 else if (type == offACglo) {
87 if (AC == AC_ && prn_[0] == 'R') {
88 return 1.0;
89 }
90 }
91 else if (type == offACSat) {
92 if (AC == AC_ && prn == prn_) {
93 return 1.0;
94 }
95 }
96 else if (type == clkSat) {
97 if (prn == prn_) {
98 return 1.0;
99 }
100 }
101
102 return 0.0;
103}
104
105//
106////////////////////////////////////////////////////////////////////////////
107QString bncComb::cmbParam::toString() const {
108
109 QString outStr;
110
111 if (type == offACgps) {
112 outStr = "AC offset GPS " + AC;
113 }
114 else if (type == offACglo) {
115 outStr = "AC offset GLO " + AC;
116 }
117 else if (type == offACSat) {
118 outStr = "Sat Offset " + AC + " " + prn.mid(0,3);
119 }
120 else if (type == clkSat) {
121 outStr = "Clk Corr " + prn.mid(0,3);
122 }
123
124 return outStr;
125}
126
127// Singleton
128////////////////////////////////////////////////////////////////////////////
129bncComb* bncComb::instance() {
130 static bncComb _bncComb;
131 return &_bncComb;
132}
133
134// Constructor
135////////////////////////////////////////////////////////////////////////////
136bncComb::bncComb() : _ephUser(true) {
137
138 bncSettings settings;
139
140 QStringList cmbStreams = settings.value("cmbStreams").toStringList();
141
142 _cmbSampl = settings.value("cmbSampl").toInt();
143 if (_cmbSampl <= 0) {
144 _cmbSampl = 10;
145 }
146
147 _masterMissingEpochs = 0;
148
149 if (cmbStreams.size() >= 1 && !cmbStreams[0].isEmpty()) {
150 QListIterator<QString> it(cmbStreams);
151 while (it.hasNext()) {
152 QStringList hlp = it.next().split(" ");
153 cmbAC* newAC = new cmbAC();
154 newAC->mountPoint = hlp[0];
155 newAC->name = hlp[1];
156 newAC->weight = hlp[2].toDouble();
157 if (_masterOrbitAC.isEmpty()) {
158 _masterOrbitAC = newAC->name;
159 }
160 _ACs.append(newAC);
161 }
162 }
163
164 QString ssrFormat;
165 QListIterator<QString> it(settings.value("uploadMountpointsOut").toStringList());
166 while (it.hasNext()) {
167 QStringList hlp = it.next().split(",");
168 if (hlp.size() > 5) {
169 ssrFormat = hlp[5];
170 }
171 }
172 _ssrCorr = 0;
173 if (ssrFormat == "IGS-SSR") {
174 _ssrCorr = new SsrCorrIgs();
175 }
176 else if (ssrFormat == "RTCM-SSR") {
177 _ssrCorr = new SsrCorrRtcm();
178 }
179
180 _rtnetDecoder = 0;
181
182 connect(this, SIGNAL(newMessage(QByteArray,bool)),
183 BNC_CORE, SLOT(slotMessage(const QByteArray,bool)));
184
185 connect(BNC_CORE, SIGNAL(providerIDChanged(QString)),
186 this, SLOT(slotProviderIDChanged(QString)));
187
188 connect(BNC_CORE, SIGNAL(newOrbCorrections(QList<t_orbCorr>)),
189 this, SLOT(slotNewOrbCorrections(QList<t_orbCorr>)));
190
191 connect(BNC_CORE, SIGNAL(newClkCorrections(QList<t_clkCorr>)),
192 this, SLOT(slotNewClkCorrections(QList<t_clkCorr>)));
193
194 // Combination Method
195 // ------------------
196 if (settings.value("cmbMethod").toString() == "Single-Epoch") {
197 _method = singleEpoch;
198 }
199 else {
200 _method = filter;
201 }
202
203 // Use Glonass
204 // -----------
205 if ( Qt::CheckState(settings.value("cmbUseGlonass").toInt()) == Qt::Checked) {
206 _useGlonass = true;
207 }
208 else {
209 _useGlonass = false;
210 }
211
212 // Initialize Parameters (model: Clk_Corr = AC_Offset + Sat_Offset + Clk)
213 // ----------------------------------------------------------------------
214 if (_method == filter) {
215 int nextPar = 0;
216 QListIterator<cmbAC*> it(_ACs);
217 while (it.hasNext()) {
218 cmbAC* AC = it.next();
219 _params.push_back(new cmbParam(cmbParam::offACgps, ++nextPar, AC->name, ""));
220 for (unsigned iGps = 1; iGps <= t_prn::MAXPRN_GPS; iGps++) {
221 QString prn = QString("G%1_0").arg(iGps, 2, 10, QChar('0'));
222 _params.push_back(new cmbParam(cmbParam::offACSat, ++nextPar,
223 AC->name, prn));
224 }
225 if (_useGlonass) {
226 _params.push_back(new cmbParam(cmbParam::offACglo, ++nextPar, AC->name, ""));
227 for (unsigned iGlo = 1; iGlo <= t_prn::MAXPRN_GLONASS; iGlo++) {
228 QString prn = QString("R%1_0").arg(iGlo, 2, 10, QChar('0'));
229 _params.push_back(new cmbParam(cmbParam::offACSat, ++nextPar,
230 AC->name, prn));
231 }
232 }
233 }
234 for (unsigned iGps = 1; iGps <= t_prn::MAXPRN_GPS; iGps++) {
235 QString prn = QString("G%1_0").arg(iGps, 2, 10, QChar('0'));
236 _params.push_back(new cmbParam(cmbParam::clkSat, ++nextPar, "", prn));
237 }
238 if (_useGlonass) {
239 for (unsigned iGlo = 1; iGlo <= t_prn::MAXPRN_GLONASS; iGlo++) {
240 QString prn = QString("R%1_0").arg(iGlo, 2, 10, QChar('0'));
241 _params.push_back(new cmbParam(cmbParam::clkSat, ++nextPar, "", prn));
242 }
243 }
244
245 // Initialize Variance-Covariance Matrix
246 // -------------------------------------
247 _QQ.ReSize(_params.size());
248 _QQ = 0.0;
249 for (int iPar = 1; iPar <= _params.size(); iPar++) {
250 cmbParam* pp = _params[iPar-1];
251 _QQ(iPar,iPar) = pp->sig0 * pp->sig0;
252 }
253 }
254
255 // ANTEX File
256 // ----------
257 _antex = 0;
258 QString antexFileName = settings.value("uploadAntexFile").toString();
259 if (!antexFileName.isEmpty()) {
260 _antex = new bncAntex();
261 if (_antex->readFile(antexFileName) != success) {
262 emit newMessage("wrong ANTEX file", true);
263 delete _antex;
264 _antex = 0;
265 }
266 }
267
268 // Maximal Residuum
269 // ----------------
270 _MAXRES = settings.value("cmbMaxres").toDouble();
271 if (_MAXRES <= 0.0) {
272 _MAXRES = 999.0;
273 }
274}
275
276// Destructor
277////////////////////////////////////////////////////////////////////////////
278bncComb::~bncComb() {
279 QListIterator<cmbAC*> icAC(_ACs);
280 while (icAC.hasNext()) {
281 delete icAC.next();
282 }
283 delete _rtnetDecoder;
284 if (_ssrCorr) {
285 delete _ssrCorr;
286 }
287 delete _antex;
288 for (int iPar = 1; iPar <= _params.size(); iPar++) {
289 delete _params[iPar-1];
290 }
291 QListIterator<bncTime> itTime(_buffer.keys());
292 while (itTime.hasNext()) {
293 bncTime epoTime = itTime.next();
294 _buffer.remove(epoTime);
295 }
296}
297
298// Remember orbit corrections
299////////////////////////////////////////////////////////////////////////////
300void bncComb::slotNewOrbCorrections(QList<t_orbCorr> orbCorrections) {
301 QMutexLocker locker(&_mutex);
302
303 for (int ii = 0; ii < orbCorrections.size(); ii++) {
304 t_orbCorr& orbCorr = orbCorrections[ii];
305 QString staID(orbCorr._staID.c_str());
306 QString prn(orbCorr._prn.toInternalString().c_str());
307
308 // Find/Check the AC Name
309 // ----------------------
310 QString acName;
311 QListIterator<cmbAC*> icAC(_ACs);
312 while (icAC.hasNext()) {
313 cmbAC* AC = icAC.next();
314 if (AC->mountPoint == staID) {
315 acName = AC->name;
316 break;
317 }
318 }
319 if (acName.isEmpty()) {
320 continue;
321 }
322
323 // Store the correction
324 // --------------------
325 QMap<t_prn, t_orbCorr>& storage = _orbCorrections[acName];
326 storage[orbCorr._prn] = orbCorr;
327 }
328}
329
330// Process clock corrections
331////////////////////////////////////////////////////////////////////////////
332void bncComb::slotNewClkCorrections(QList<t_clkCorr> clkCorrections) {
333 QMutexLocker locker(&_mutex);
334
335 bncTime lastTime;
336
337 for (int ii = 0; ii < clkCorrections.size(); ii++) {
338 t_clkCorr& clkCorr = clkCorrections[ii];
339 QString staID(clkCorr._staID.c_str());
340 QString prn(clkCorr._prn.toInternalString().c_str());
341
342 // Set the last time
343 // -----------------
344 if (lastTime.undef() || clkCorr._time > lastTime) {
345 lastTime = clkCorr._time;
346 }
347
348 // Find/Check the AC Name
349 // ----------------------
350 QString acName;
351 QListIterator<cmbAC*> icAC(_ACs);
352 while (icAC.hasNext()) {
353 cmbAC* AC = icAC.next();
354 if (AC->mountPoint == staID) {
355 acName = AC->name;
356 break;
357 }
358 }
359 if (acName.isEmpty()) {
360 continue;
361 }
362
363 // Check GLONASS
364 // -------------
365 if (!_useGlonass && clkCorr._prn.system() == 'R') {
366 continue;
367 }
368
369 if (
370 clkCorr._prn.system() == 'E' ||
371 clkCorr._prn.system() == 'C' ||
372 clkCorr._prn.system() == 'J' ||
373 clkCorr._prn.system() == 'I' ||
374 clkCorr._prn.system() == 'S' ) {
375 continue;
376 }
377
378 // Check Modulo Time
379 // -----------------
380 int sec = int(nint(clkCorr._time.gpssec()*10));
381 if (sec % (_cmbSampl*10) != 0.0) {
382 continue;
383 }
384
385 // Check Correction Age
386 // --------------------
387 if (_resTime.valid() && clkCorr._time <= _resTime) {
388 emit newMessage("bncComb: old correction: " + acName.toAscii() + " " + prn.mid(0,3).toAscii(), true);
389 continue;
390 }
391
392 // Create new correction
393 // ---------------------
394 cmbCorr* newCorr = new cmbCorr();
395 newCorr->_prn = prn;
396 newCorr->_time = clkCorr._time;
397 newCorr->_iod = clkCorr._iod;
398 newCorr->_acName = acName;
399 newCorr->_clkCorr = clkCorr;
400
401 // Check orbit correction
402 // ----------------------
403 if (!_orbCorrections.contains(acName)) {
404 delete newCorr;
405 continue;
406 }
407 else {
408 QMap<t_prn, t_orbCorr>& storage = _orbCorrections[acName];
409 if (!storage.contains(clkCorr._prn) || storage[clkCorr._prn]._iod != newCorr->_iod) {
410 delete newCorr;
411 continue;
412 }
413 else {
414 newCorr->_orbCorr = storage[clkCorr._prn];
415 }
416 }
417
418 // Check the Ephemeris
419 //--------------------
420 t_eph* ephLast = _ephUser.ephLast(prn);
421 t_eph* ephPrev = _ephUser.ephPrev(prn);
422 if (ephLast == 0) {
423 emit newMessage("bncComb: eph not found for " + prn.mid(0,3).toAscii(), true);
424 delete newCorr;
425 continue;
426 }
427 else {
428 if (ephLast->IOD() == newCorr->_iod) {
429 newCorr->_eph = ephLast;
430 }
431 else if (ephPrev && ephPrev->IOD() == newCorr->_iod) {
432 newCorr->_eph = ephPrev;
433 switchToLastEph(ephLast, newCorr);
434 }
435 else {
436 emit newMessage("bncComb: eph not found for " + prn.mid(0,3).toAscii() +
437 QString(" with IOD %1").arg(newCorr->_iod).toAscii(), true);
438 delete newCorr;
439 continue;
440 }
441 }
442
443 // Store correction into the buffer
444 // --------------------------------
445 QVector<cmbCorr*>& corrs = _buffer[newCorr->_time].corrs;
446 corrs.push_back(newCorr);
447 }
448
449 // Process previous Epoch(s)
450 // -------------------------
451 const double outWait = 1.0 * _cmbSampl;
452 QListIterator<bncTime> itTime(_buffer.keys());
453 while (itTime.hasNext()) {
454 bncTime epoTime = itTime.next();
455 if (epoTime < lastTime - outWait) {
456 _resTime = epoTime;
457 processEpoch();
458 }
459 }
460}
461
462// Change the correction so that it refers to last received ephemeris
463////////////////////////////////////////////////////////////////////////////
464void bncComb::switchToLastEph(t_eph* lastEph, cmbCorr* corr) {
465
466 if (corr->_eph == lastEph) {
467 return;
468 }
469
470 ColumnVector oldXC(6);
471 ColumnVector oldVV(3);
472 corr->_eph->getCrd(corr->_time, oldXC, oldVV, false);
473
474 ColumnVector newXC(6);
475 ColumnVector newVV(3);
476 lastEph->getCrd(corr->_time, newXC, newVV, false);
477
478 ColumnVector dX = newXC.Rows(1,3) - oldXC.Rows(1,3);
479 ColumnVector dV = newVV - oldVV;
480 double dC = newXC(4) - oldXC(4);
481
482 ColumnVector dRAO(3);
483 XYZ_to_RSW(newXC.Rows(1,3), newVV, dX, dRAO);
484
485 ColumnVector dDotRAO(3);
486 XYZ_to_RSW(newXC.Rows(1,3), newVV, dV, dDotRAO);
487
488 QString msg = "switch corr " + corr->_prn.mid(0,3)
489 + QString(" %1 -> %2 %3").arg(corr->_iod,3).arg(lastEph->IOD(),3).arg(dC*t_CST::c, 8, 'f', 4);
490
491 emit newMessage(msg.toAscii(), false);
492
493 corr->_iod = lastEph->IOD();
494 corr->_eph = lastEph;
495
496 corr->_orbCorr._xr += dRAO;
497 corr->_orbCorr._dotXr += dDotRAO;
498 corr->_clkCorr._dClk -= dC;
499}
500
501// Process Epoch
502////////////////////////////////////////////////////////////////////////////
503void bncComb::processEpoch() {
504
505 _log.clear();
506
507 QTextStream out(&_log, QIODevice::WriteOnly);
508
509 out << endl << "Combination:" << endl
510 << "------------------------------" << endl;
511
512 // Observation Statistics
513 // ----------------------
514 bool masterPresent = false;
515 QListIterator<cmbAC*> icAC(_ACs);
516 while (icAC.hasNext()) {
517 cmbAC* AC = icAC.next();
518 AC->numObs = 0;
519 QVectorIterator<cmbCorr*> itCorr(corrs());
520 while (itCorr.hasNext()) {
521 cmbCorr* corr = itCorr.next();
522 if (corr->_acName == AC->name) {
523 AC->numObs += 1;
524 if (AC->name == _masterOrbitAC) {
525 masterPresent = true;
526 }
527 }
528 }
529 out << AC->name.toAscii().data() << ": " << AC->numObs << endl;
530 }
531
532 // If Master not present, switch to another one
533 // --------------------------------------------
534 const unsigned switchMasterAfterGap = 1;
535 if (masterPresent) {
536 _masterMissingEpochs = 0;
537 }
538 else {
539 ++_masterMissingEpochs;
540 if (_masterMissingEpochs < switchMasterAfterGap) {
541 out << "Missing Master, Epoch skipped" << endl;
542 _buffer.remove(_resTime);
543 emit newMessage(_log, false);
544 return;
545 }
546 else {
547 _masterMissingEpochs = 0;
548 QListIterator<cmbAC*> icAC(_ACs);
549 while (icAC.hasNext()) {
550 cmbAC* AC = icAC.next();
551 if (AC->numObs > 0) {
552 out << "Switching Master AC "
553 << _masterOrbitAC.toAscii().data() << " --> "
554 << AC->name.toAscii().data() << " "
555 << _resTime.datestr().c_str() << " "
556 << _resTime.timestr().c_str() << endl;
557 _masterOrbitAC = AC->name;
558 break;
559 }
560 }
561 }
562 }
563
564 QMap<QString, cmbCorr*> resCorr;
565
566 // Perform the actual Combination using selected Method
567 // ----------------------------------------------------
568 t_irc irc;
569 ColumnVector dx;
570 if (_method == filter) {
571 irc = processEpoch_filter(out, resCorr, dx);
572 }
573 else {
574 irc = processEpoch_singleEpoch(out, resCorr, dx);
575 }
576
577 // Update Parameter Values, Print Results
578 // --------------------------------------
579 if (irc == success) {
580 for (int iPar = 1; iPar <= _params.size(); iPar++) {
581 cmbParam* pp = _params[iPar-1];
582 pp->xx += dx(iPar);
583 if (pp->type == cmbParam::clkSat) {
584 if (resCorr.find(pp->prn) != resCorr.end()) {
585 resCorr[pp->prn]->_dClkResult = pp->xx / t_CST::c;
586 }
587 }
588 out << _resTime.datestr().c_str() << " "
589 << _resTime.timestr().c_str() << " ";
590 out.setRealNumberNotation(QTextStream::FixedNotation);
591 out.setFieldWidth(8);
592 out.setRealNumberPrecision(4);
593 out << pp->toString() << " "
594 << pp->xx << " +- " << sqrt(_QQ(pp->index,pp->index)) << endl;
595 out.setFieldWidth(0);
596 }
597 printResults(out, resCorr);
598 dumpResults(resCorr);
599 }
600
601 // Delete Data, emit Message
602 // -------------------------
603 _buffer.remove(_resTime);
604 emit newMessage(_log, false);
605}
606
607// Process Epoch - Filter Method
608////////////////////////////////////////////////////////////////////////////
609t_irc bncComb::processEpoch_filter(QTextStream& out,
610 QMap<QString, cmbCorr*>& resCorr,
611 ColumnVector& dx) {
612
613 // Prediction Step
614 // ---------------
615 int nPar = _params.size();
616 ColumnVector x0(nPar);
617 for (int iPar = 1; iPar <= _params.size(); iPar++) {
618 cmbParam* pp = _params[iPar-1];
619 if (pp->epoSpec) {
620 pp->xx = 0.0;
621 _QQ.Row(iPar) = 0.0;
622 _QQ.Column(iPar) = 0.0;
623 _QQ(iPar,iPar) = pp->sig0 * pp->sig0;
624 }
625 else {
626 _QQ(iPar,iPar) += pp->sigP * pp->sigP;
627 }
628 x0(iPar) = pp->xx;
629 }
630
631 // Check Satellite Positions for Outliers
632 // --------------------------------------
633 if (checkOrbits(out) != success) {
634 return failure;
635 }
636
637 // Update and outlier detection loop
638 // ---------------------------------
639 SymmetricMatrix QQ_sav = _QQ;
640 while (true) {
641
642 Matrix AA;
643 ColumnVector ll;
644 DiagonalMatrix PP;
645
646 if (createAmat(AA, ll, PP, x0, resCorr) != success) {
647 return failure;
648 }
649
650 dx.ReSize(nPar); dx = 0.0;
651 kalman(AA, ll, PP, _QQ, dx);
652
653 ColumnVector vv = ll - AA * dx;
654
655 int maxResIndex;
656 double maxRes = vv.maximum_absolute_value1(maxResIndex);
657 out.setRealNumberNotation(QTextStream::FixedNotation);
658 out.setRealNumberPrecision(3);
659 out << _resTime.datestr().c_str() << " " << _resTime.timestr().c_str()
660 << " Maximum Residuum " << maxRes << ' '
661 << corrs()[maxResIndex-1]->_acName << ' ' << corrs()[maxResIndex-1]->_prn.mid(0,3);
662 if (maxRes > _MAXRES) {
663 for (int iPar = 1; iPar <= _params.size(); iPar++) {
664 cmbParam* pp = _params[iPar-1];
665 if (pp->type == cmbParam::offACSat &&
666 pp->AC == corrs()[maxResIndex-1]->_acName &&
667 pp->prn == corrs()[maxResIndex-1]->_prn.mid(0,3)) {
668 QQ_sav.Row(iPar) = 0.0;
669 QQ_sav.Column(iPar) = 0.0;
670 QQ_sav(iPar,iPar) = pp->sig0 * pp->sig0;
671 }
672 }
673
674 out << " Outlier" << endl;
675 _QQ = QQ_sav;
676 corrs().remove(maxResIndex-1);
677 }
678 else {
679 out << " OK" << endl;
680 out.setRealNumberNotation(QTextStream::FixedNotation);
681 out.setRealNumberPrecision(4);
682 for (int ii = 0; ii < corrs().size(); ii++) {
683 const cmbCorr* corr = corrs()[ii];
684 out << _resTime.datestr().c_str() << ' '
685 << _resTime.timestr().c_str() << " "
686 << corr->_acName << ' ' << corr->_prn.mid(0,3);
687 out.setFieldWidth(10);
688 out << " res = " << vv[ii] << endl;
689 out.setFieldWidth(0);
690 }
691 break;
692 }
693 }
694
695 return success;
696}
697
698// Print results
699////////////////////////////////////////////////////////////////////////////
700void bncComb::printResults(QTextStream& out,
701 const QMap<QString, cmbCorr*>& resCorr) {
702
703 QMapIterator<QString, cmbCorr*> it(resCorr);
704 while (it.hasNext()) {
705 it.next();
706 cmbCorr* corr = it.value();
707 const t_eph* eph = corr->_eph;
708 if (eph) {
709 ColumnVector xc(6);
710 ColumnVector vv(3);
711 eph->getCrd(_resTime, xc, vv, false);
712
713 out << _resTime.datestr().c_str() << " "
714 << _resTime.timestr().c_str() << " ";
715 out.setFieldWidth(3);
716 out << "Full Clock " << corr->_prn.mid(0,3) << " " << corr->_iod << " ";
717 out.setFieldWidth(14);
718 out << (xc(4) + corr->_dClkResult) * t_CST::c << endl;
719 out.setFieldWidth(0);
720 }
721 else {
722 out << "bncComb::printResuls bug" << endl;
723 }
724 }
725}
726
727// Send results to RTNet Decoder and directly to PPP Client
728////////////////////////////////////////////////////////////////////////////
729void bncComb::dumpResults(const QMap<QString, cmbCorr*>& resCorr) {
730
731 QList<t_orbCorr> orbCorrections;
732 QList<t_clkCorr> clkCorrections;
733
734 QString outLines;
735 unsigned year, month, day, hour, minute;
736 double sec;
737 _resTime.civil_date(year, month, day);
738 _resTime.civil_time(hour, minute, sec);
739
740 outLines.sprintf("* %4d %2d %2d %d %d %12.8f\n",
741 year, month, day, hour, minute, sec);
742
743 QMapIterator<QString, cmbCorr*> it(resCorr);
744 while (it.hasNext()) {
745 it.next();
746 cmbCorr* corr = it.value();
747
748 t_orbCorr orbCorr(corr->_orbCorr);
749 orbCorr._staID = "INTERNAL";
750 orbCorrections.push_back(orbCorr);
751
752 t_clkCorr clkCorr(corr->_clkCorr);
753 clkCorr._staID = "INTERNAL";
754 clkCorr._dClk = corr->_dClkResult;
755 clkCorr._dotDClk = 0.0;
756 clkCorr._dotDotDClk = 0.0;
757 clkCorrections.push_back(clkCorr);
758
759 ColumnVector xc(6);
760 ColumnVector vv(3);
761 corr->_eph->setClkCorr(dynamic_cast<const t_clkCorr*>(&clkCorr));
762 corr->_eph->setOrbCorr(dynamic_cast<const t_orbCorr*>(&orbCorr));
763 corr->_eph->getCrd(_resTime, xc, vv, true);
764
765 // Correction Phase Center --> CoM
766 // -------------------------------
767 ColumnVector dx(3); dx = 0.0;
768 if (_antex) {
769 double Mjd = _resTime.mjd() + _resTime.daysec()/86400.0;
770 if (_antex->satCoMcorrection(corr->_prn, Mjd, xc.Rows(1,3), dx) != success) {
771 dx = 0;
772 _log += "antenna not found " + corr->_prn.mid(0,3).toAscii() + '\n';
773 }
774 }
775
776 outLines += corr->_prn.mid(0,3);
777 QString hlp;
778 hlp.sprintf(" APC 3 %15.4f %15.4f %15.4f"
779 " Clk 1 %15.4f"
780 " Vel 3 %15.4f %15.4f %15.4f"
781 " CoM 3 %15.4f %15.4f %15.4f\n",
782 xc(1), xc(2), xc(3),
783 xc(4) * t_CST::c,
784 vv(1), vv(2), vv(3),
785 xc(1)-dx(1), xc(2)-dx(2), xc(3)-dx(3));
786 outLines += hlp;
787
788 QString line;
789 int messageType = _ssrCorr->COTYPE_GPSCOMBINED;
790 int updateInt = 0;
791 line.sprintf("%d %d %d %.1f %s"
792 " %lu"
793 " %8.3f %8.3f %8.3f %8.3f"
794 " %10.5f %10.5f %10.5f %10.5f"
795 " %10.5f INTERNAL",
796 messageType, updateInt, _resTime.gpsw(), _resTime.gpssec(),
797 corr->_prn.mid(0,3).toAscii().data(),
798 corr->_iod,
799 corr->_dClkResult * t_CST::c,
800 corr->_orbCorr._xr[0],
801 corr->_orbCorr._xr[1],
802 corr->_orbCorr._xr[2],
803 0.0,
804 corr->_orbCorr._dotXr[0],
805 corr->_orbCorr._dotXr[1],
806 corr->_orbCorr._dotXr[2],
807 0.0);
808 delete corr;
809 }
810
811 outLines += "EOE\n"; // End Of Epoch flag
812
813 if (!_rtnetDecoder) {
814 _rtnetDecoder = new bncRtnetDecoder();
815 }
816
817 vector<string> errmsg;
818 _rtnetDecoder->Decode(outLines.toAscii().data(), outLines.length(), errmsg);
819
820 // Send new Corrections to PPP etc.
821 // --------------------------------
822 if (orbCorrections.size() > 0 && clkCorrections.size() > 0) {
823 emit newOrbCorrections(orbCorrections);
824 emit newClkCorrections(clkCorrections);
825 }
826}
827
828// Create First Design Matrix and Vector of Measurements
829////////////////////////////////////////////////////////////////////////////
830t_irc bncComb::createAmat(Matrix& AA, ColumnVector& ll, DiagonalMatrix& PP,
831 const ColumnVector& x0,
832 QMap<QString, cmbCorr*>& resCorr) {
833
834 unsigned nPar = _params.size();
835 unsigned nObs = corrs().size();
836
837 if (nObs == 0) {
838 return failure;
839 }
840
841 int maxSat = t_prn::MAXPRN_GPS;
842// if (_useGlonass) {
843// maxSat = t_prn::MAXPRN_GPS + t_prn::MAXPRN_GLONASS;
844// }
845
846 const int nCon = (_method == filter) ? 1 + maxSat : 0;
847
848 AA.ReSize(nObs+nCon, nPar); AA = 0.0;
849 ll.ReSize(nObs+nCon); ll = 0.0;
850 PP.ReSize(nObs+nCon); PP = 1.0 / (sigObs * sigObs);
851
852 int iObs = 0;
853 QVectorIterator<cmbCorr*> itCorr(corrs());
854 while (itCorr.hasNext()) {
855 cmbCorr* corr = itCorr.next();
856 QString prn = corr->_prn;
857
858 ++iObs;
859
860 if (corr->_acName == _masterOrbitAC && resCorr.find(prn) == resCorr.end()) {
861 resCorr[prn] = new cmbCorr(*corr);
862 }
863
864 for (int iPar = 1; iPar <= _params.size(); iPar++) {
865 cmbParam* pp = _params[iPar-1];
866 AA(iObs, iPar) = pp->partial(corr->_acName, prn);
867 }
868
869 ll(iObs) = corr->_clkCorr._dClk * t_CST::c - DotProduct(AA.Row(iObs), x0);
870 }
871
872 // Regularization
873 // --------------
874 if (_method == filter) {
875 const double Ph = 1.e6;
876 PP(nObs+1) = Ph;
877 for (int iPar = 1; iPar <= _params.size(); iPar++) {
878 cmbParam* pp = _params[iPar-1];
879 if ( AA.Column(iPar).maximum_absolute_value() > 0.0 &&
880 pp->type == cmbParam::clkSat ) {
881 AA(nObs+1, iPar) = 1.0;
882 }
883 }
884 int iCond = 1;
885 for (unsigned iGps = 1; iGps <= t_prn::MAXPRN_GPS; iGps++) {
886 QString prn = QString("G%1_0").arg(iGps, 2, 10, QChar('0'));
887 ++iCond;
888 PP(nObs+iCond) = Ph;
889 for (int iPar = 1; iPar <= _params.size(); iPar++) {
890 cmbParam* pp = _params[iPar-1];
891 if ( pp &&
892 AA.Column(iPar).maximum_absolute_value() > 0.0 &&
893 pp->type == cmbParam::offACSat &&
894 pp->prn == prn) {
895 AA(nObs+iCond, iPar) = 1.0;
896 }
897 }
898 }
899// if (_useGlonass) {
900// for (unsigned iGlo = 1; iGlo <= t_prn::MAXPRN_GLONASS; iGlo++) {
901// QString prn = QString("R%1_0").arg(iGlo, 2, 10, QChar('0'));
902// ++iCond;
903// PP(nObs+iCond) = Ph;
904// for (int iPar = 1; iPar <= _params.size(); iPar++) {
905// cmbParam* pp = _params[iPar-1];
906// if ( pp &&
907// AA.Column(iPar).maximum_absolute_value() > 0.0 &&
908// pp->type == cmbParam::offACSat &&
909// pp->prn == prn) {
910// AA(nObs+iCond, iPar) = 1.0;
911// }
912// }
913// }
914// }
915 }
916
917 return success;
918}
919
920// Process Epoch - Single-Epoch Method
921////////////////////////////////////////////////////////////////////////////
922t_irc bncComb::processEpoch_singleEpoch(QTextStream& out,
923 QMap<QString, cmbCorr*>& resCorr,
924 ColumnVector& dx) {
925
926 // Check Satellite Positions for Outliers
927 // --------------------------------------
928 if (checkOrbits(out) != success) {
929 return failure;
930 }
931
932 // Outlier Detection Loop
933 // ----------------------
934 while (true) {
935
936 // Remove Satellites that are not in Master
937 // ----------------------------------------
938 QMutableVectorIterator<cmbCorr*> it(corrs());
939 while (it.hasNext()) {
940 cmbCorr* corr = it.next();
941 QString prn = corr->_prn;
942 bool foundMaster = false;
943 QVectorIterator<cmbCorr*> itHlp(corrs());
944 while (itHlp.hasNext()) {
945 cmbCorr* corrHlp = itHlp.next();
946 QString prnHlp = corrHlp->_prn;
947 QString ACHlp = corrHlp->_acName;
948 if (ACHlp == _masterOrbitAC && prn == prnHlp) {
949 foundMaster = true;
950 break;
951 }
952 }
953 if (!foundMaster) {
954 delete corr;
955 it.remove();
956 }
957 }
958
959 // Count Number of Observations per Satellite and per AC
960 // -----------------------------------------------------
961 QMap<QString, int> numObsPrn;
962 QMap<QString, int> numObsAC;
963 QVectorIterator<cmbCorr*> itCorr(corrs());
964 while (itCorr.hasNext()) {
965 cmbCorr* corr = itCorr.next();
966 QString prn = corr->_prn;
967 QString AC = corr->_acName;
968 if (numObsPrn.find(prn) == numObsPrn.end()) {
969 numObsPrn[prn] = 1;
970 }
971 else {
972 numObsPrn[prn] += 1;
973 }
974 if (numObsAC.find(AC) == numObsAC.end()) {
975 numObsAC[AC] = 1;
976 }
977 else {
978 numObsAC[AC] += 1;
979 }
980 }
981
982 // Clean-Up the Paramters
983 // ----------------------
984 for (int iPar = 1; iPar <= _params.size(); iPar++) {
985 delete _params[iPar-1];
986 }
987 _params.clear();
988
989 // Set new Parameters
990 // ------------------
991 int nextPar = 0;
992
993 QMapIterator<QString, int> itAC(numObsAC);
994 while (itAC.hasNext()) {
995 itAC.next();
996 const QString& AC = itAC.key();
997 int numObs = itAC.value();
998 if (AC != _masterOrbitAC && numObs > 0) {
999 _params.push_back(new cmbParam(cmbParam::offACgps, ++nextPar, AC, ""));
1000 if (_useGlonass) {
1001 _params.push_back(new cmbParam(cmbParam::offACglo, ++nextPar, AC, ""));
1002 }
1003 }
1004 }
1005
1006 QMapIterator<QString, int> itPrn(numObsPrn);
1007 while (itPrn.hasNext()) {
1008 itPrn.next();
1009 const QString& prn = itPrn.key();
1010 int numObs = itPrn.value();
1011 if (numObs > 0) {
1012 _params.push_back(new cmbParam(cmbParam::clkSat, ++nextPar, "", prn));
1013 }
1014 }
1015
1016 int nPar = _params.size();
1017 ColumnVector x0(nPar);
1018 x0 = 0.0;
1019
1020 // Create First-Design Matrix
1021 // --------------------------
1022 Matrix AA;
1023 ColumnVector ll;
1024 DiagonalMatrix PP;
1025 if (createAmat(AA, ll, PP, x0, resCorr) != success) {
1026 return failure;
1027 }
1028
1029 ColumnVector vv;
1030 try {
1031 Matrix ATP = AA.t() * PP;
1032 SymmetricMatrix NN; NN << ATP * AA;
1033 ColumnVector bb = ATP * ll;
1034 _QQ = NN.i();
1035 dx = _QQ * bb;
1036 vv = ll - AA * dx;
1037 }
1038 catch (Exception& exc) {
1039 out << exc.what() << endl;
1040 return failure;
1041 }
1042
1043 int maxResIndex;
1044 double maxRes = vv.maximum_absolute_value1(maxResIndex);
1045 out.setRealNumberNotation(QTextStream::FixedNotation);
1046 out.setRealNumberPrecision(3);
1047 out << _resTime.datestr().c_str() << " " << _resTime.timestr().c_str()
1048 << " Maximum Residuum " << maxRes << ' '
1049 << corrs()[maxResIndex-1]->_acName << ' ' << corrs()[maxResIndex-1]->_prn.mid(0,3);
1050
1051 if (maxRes > _MAXRES) {
1052 out << " Outlier" << endl;
1053 delete corrs()[maxResIndex-1];
1054 corrs().remove(maxResIndex-1);
1055 }
1056 else {
1057 out << " OK" << endl;
1058 out.setRealNumberNotation(QTextStream::FixedNotation);
1059 out.setRealNumberPrecision(3);
1060 for (int ii = 0; ii < vv.Nrows(); ii++) {
1061 const cmbCorr* corr = corrs()[ii];
1062 out << _resTime.datestr().c_str() << ' '
1063 << _resTime.timestr().c_str() << " "
1064 << corr->_acName << ' ' << corr->_prn.mid(0,3);
1065 out.setFieldWidth(6);
1066 out << " res = " << vv[ii] << endl;
1067 out.setFieldWidth(0);
1068 }
1069 return success;
1070 }
1071
1072 }
1073
1074 return failure;
1075}
1076
1077// Check Satellite Positions for Outliers
1078////////////////////////////////////////////////////////////////////////////
1079t_irc bncComb::checkOrbits(QTextStream& out) {
1080
1081 const double MAX_DISPLACEMENT = 0.20;
1082
1083 // Switch to last ephemeris (if possible)
1084 // --------------------------------------
1085 QMutableVectorIterator<cmbCorr*> im(corrs());
1086 while (im.hasNext()) {
1087 cmbCorr* corr = im.next();
1088 QString prn = corr->_prn;
1089
1090 t_eph* ephLast = _ephUser.ephLast(prn);
1091 t_eph* ephPrev = _ephUser.ephPrev(prn);
1092
1093 if (ephLast == 0) {
1094 out << "checkOrbit: missing eph (not found) " << corr->_prn.mid(0,3) << endl;
1095 delete corr;
1096 im.remove();
1097 }
1098 else if (corr->_eph == 0) {
1099 out << "checkOrbit: missing eph (zero) " << corr->_prn.mid(0,3) << endl;
1100 delete corr;
1101 im.remove();
1102 }
1103 else {
1104 if ( corr->_eph == ephLast || corr->_eph == ephPrev ) {
1105 switchToLastEph(ephLast, corr);
1106 }
1107 else {
1108 out << "checkOrbit: missing eph (deleted) " << corr->_prn.mid(0,3) << endl;
1109 delete corr;
1110 im.remove();
1111 }
1112 }
1113 }
1114
1115 while (true) {
1116
1117 // Compute Mean Corrections for all Satellites
1118 // -------------------------------------------
1119 QMap<QString, int> numCorr;
1120 QMap<QString, ColumnVector> meanRao;
1121 QVectorIterator<cmbCorr*> it(corrs());
1122 while (it.hasNext()) {
1123 cmbCorr* corr = it.next();
1124 QString prn = corr->_prn;
1125 if (meanRao.find(prn) == meanRao.end()) {
1126 meanRao[prn].ReSize(4);
1127 meanRao[prn].Rows(1,3) = corr->_orbCorr._xr;
1128 meanRao[prn](4) = 1;
1129 }
1130 else {
1131 meanRao[prn].Rows(1,3) += corr->_orbCorr._xr;
1132 meanRao[prn](4) += 1;
1133 }
1134 if (numCorr.find(prn) == numCorr.end()) {
1135 numCorr[prn] = 1;
1136 }
1137 else {
1138 numCorr[prn] += 1;
1139 }
1140 }
1141
1142 // Compute Differences wrt Mean, find Maximum
1143 // ------------------------------------------
1144 QMap<QString, cmbCorr*> maxDiff;
1145 it.toFront();
1146 while (it.hasNext()) {
1147 cmbCorr* corr = it.next();
1148 QString prn = corr->_prn;
1149 if (meanRao[prn](4) != 0) {
1150 meanRao[prn] /= meanRao[prn](4);
1151 meanRao[prn](4) = 0;
1152 }
1153 corr->_diffRao = corr->_orbCorr._xr - meanRao[prn].Rows(1,3);
1154 if (maxDiff.find(prn) == maxDiff.end()) {
1155 maxDiff[prn] = corr;
1156 }
1157 else {
1158 double normMax = maxDiff[prn]->_diffRao.norm_Frobenius();
1159 double norm = corr->_diffRao.norm_Frobenius();
1160 if (norm > normMax) {
1161 maxDiff[prn] = corr;
1162 }
1163 }
1164 }
1165
1166 if (_ACs.size() == 1) {
1167 break;
1168 }
1169
1170 // Remove Outliers
1171 // ---------------
1172 bool removed = false;
1173 QMutableVectorIterator<cmbCorr*> im(corrs());
1174 while (im.hasNext()) {
1175 cmbCorr* corr = im.next();
1176 QString prn = corr->_prn;
1177 if (numCorr[prn] < 2) {
1178 delete corr;
1179 im.remove();
1180 }
1181 else if (corr == maxDiff[prn]) {
1182 double norm = corr->_diffRao.norm_Frobenius();
1183 if (norm > MAX_DISPLACEMENT) {
1184 out << _resTime.datestr().c_str() << " "
1185 << _resTime.timestr().c_str() << " "
1186 << "Orbit Outlier: "
1187 << corr->_acName.toAscii().data() << " "
1188 << prn.mid(0,3).toAscii().data() << " "
1189 << corr->_iod << " "
1190 << norm << endl;
1191 delete corr;
1192 im.remove();
1193 removed = true;
1194 }
1195 }
1196 }
1197
1198 if (!removed) {
1199 break;
1200 }
1201 }
1202
1203 return success;
1204}
1205
1206//
1207////////////////////////////////////////////////////////////////////////////
1208void bncComb::slotProviderIDChanged(QString mountPoint) {
1209 QMutexLocker locker(&_mutex);
1210
1211 QTextStream out(&_log, QIODevice::WriteOnly);
1212
1213 // Find the AC Name
1214 // ----------------
1215 QString acName;
1216 QListIterator<cmbAC*> icAC(_ACs);
1217 while (icAC.hasNext()) {
1218 cmbAC* AC = icAC.next();
1219 if (AC->mountPoint == mountPoint) {
1220 acName = AC->name;
1221 out << "Provider ID changed: AC " << AC->name.toAscii().data() << " "
1222 << _resTime.datestr().c_str() << " "
1223 << _resTime.timestr().c_str() << endl;
1224 break;
1225 }
1226 }
1227 if (acName.isEmpty()) {
1228 return;
1229 }
1230
1231 // Remove all corrections of the corresponding AC
1232 // ----------------------------------------------
1233 QListIterator<bncTime> itTime(_buffer.keys());
1234 while (itTime.hasNext()) {
1235 bncTime epoTime = itTime.next();
1236 QVector<cmbCorr*>& corrVec = _buffer[epoTime].corrs;
1237 QMutableVectorIterator<cmbCorr*> it(corrVec);
1238 while (it.hasNext()) {
1239 cmbCorr* corr = it.next();
1240 if (acName == corr->_acName) {
1241 delete corr;
1242 it.remove();
1243 }
1244 }
1245 }
1246
1247 // Reset Satellite Offsets
1248 // -----------------------
1249 if (_method == filter) {
1250 for (int iPar = 1; iPar <= _params.size(); iPar++) {
1251 cmbParam* pp = _params[iPar-1];
1252 if (pp->AC == acName && pp->type == cmbParam::offACSat) {
1253 pp->xx = 0.0;
1254 _QQ.Row(iPar) = 0.0;
1255 _QQ.Column(iPar) = 0.0;
1256 _QQ(iPar,iPar) = pp->sig0 * pp->sig0;
1257 }
1258 }
1259 }
1260}
Note: See TracBrowser for help on using the repository browser.