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

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