source: ntrip/trunk/BNC/combination/bnccomb.cpp@ 3463

Last change on this file since 3463 was 3463, checked in by mervart, 13 years ago
File size: 21.1 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"
22#include "bncapp.h"
[3201]23#include "upload/bncrtnetdecoder.h"
[2910]24#include "bncsettings.h"
[2933]25#include "bncmodel.h"
[2988]26#include "bncutils.h"
[3027]27#include "bncpppclient.h"
[3181]28#include "bncsp3.h"
[3052]29#include "bncantex.h"
[3055]30#include "bnctides.h"
[2898]31
[3455]32const int moduloTime = 10;
[2898]33
[3455]34const double sig0_offAC = 1000.0;
35const double sig0_offACSat = 100.0;
[3463]36const double sigP_offACSat = 0.1;
[3455]37const double sig0_clkSat = 100.0;
38
39const double sigObs = 0.05;
40
[3134]41const int MAXPRN_GPS = 32;
42
[3455]43using namespace std;
44
[2898]45// Constructor
46////////////////////////////////////////////////////////////////////////////
[3429]47cmbParam::cmbParam(parType type_, int index_,
48 const QString& ac_, const QString& prn_) {
[3032]49
[3433]50 type = type_;
51 index = index_;
52 AC = ac_;
53 prn = prn_;
54 xx = 0.0;
[3455]55 eph = 0;
[3429]56
57 if (type == offAC) {
[3455]58 epoSpec = true;
59 sig0 = sig0_offAC;
60 sigP = sig0;
[3429]61 }
62 else if (type == offACSat) {
[3455]63 epoSpec = false;
64 sig0 = sig0_offACSat;
65 sigP = sigP_offACSat;
[3429]66 }
67 else if (type == clkSat) {
[3455]68 epoSpec = true;
69 sig0 = sig0_clkSat;
70 sigP = sig0;
[3429]71 }
[2933]72}
73
74// Destructor
75////////////////////////////////////////////////////////////////////////////
76cmbParam::~cmbParam() {
77}
78
79// Partial
80////////////////////////////////////////////////////////////////////////////
[3429]81double cmbParam::partial(const QString& AC_, const QString& prn_) {
[2933]82
[3429]83 if (type == offAC) {
[3032]84 if (AC == AC_) {
[2934]85 return 1.0;
86 }
87 }
[3429]88 else if (type == offACSat) {
89 if (AC == AC_ && prn == prn_) {
[2933]90 return 1.0;
91 }
92 }
[3429]93 else if (type == clkSat) {
94 if (prn == prn_) {
[2933]95 return 1.0;
96 }
97 }
98
99 return 0.0;
100}
101
[2990]102//
103////////////////////////////////////////////////////////////////////////////
104QString cmbParam::toString() const {
[2933]105
[2990]106 QString outStr;
107
[3429]108 if (type == offAC) {
[2992]109 outStr = "AC offset " + AC;
[2990]110 }
[3429]111 else if (type == offACSat) {
[2992]112 outStr = "Sat Offset " + AC + " " + prn;
[2990]113 }
[3429]114 else if (type == clkSat) {
[2992]115 outStr = "Clk Corr " + prn;
[2990]116 }
[2933]117
[2990]118 return outStr;
119}
120
[2933]121// Constructor
122////////////////////////////////////////////////////////////////////////////
[2898]123bncComb::bncComb() {
[2910]124
125 bncSettings settings;
126
127 QStringList combineStreams = settings.value("combineStreams").toStringList();
[2918]128
[3455]129 _masterMissingEpochs = 0;
130
[3143]131 if (combineStreams.size() >= 1 && !combineStreams[0].isEmpty()) {
[2910]132 QListIterator<QString> it(combineStreams);
133 while (it.hasNext()) {
134 QStringList hlp = it.next().split(" ");
[2918]135 cmbAC* newAC = new cmbAC();
136 newAC->mountPoint = hlp[0];
137 newAC->name = hlp[1];
138 newAC->weight = hlp[2].toDouble();
[3453]139 if (_masterOrbitAC.isEmpty()) {
140 _masterOrbitAC = newAC->name;
141 }
[3429]142 _ACs.append(newAC);
[2910]143 }
144 }
[2927]145
[3211]146 _rtnetDecoder = 0;
[3201]147
[2990]148 connect(this, SIGNAL(newMessage(QByteArray,bool)),
149 ((bncApp*)qApp), SLOT(slotMessage(const QByteArray,bool)));
[2933]150
[3032]151
152 // Initialize Parameters (model: Clk_Corr = AC_Offset + Sat_Offset + Clk)
153 // ----------------------------------------------------------------------
[2933]154 int nextPar = 0;
[3429]155 QListIterator<cmbAC*> it(_ACs);
[2991]156 while (it.hasNext()) {
[3429]157 cmbAC* AC = it.next();
158 _params.push_back(new cmbParam(cmbParam::offAC, ++nextPar, AC->name, ""));
[3134]159 for (int iGps = 1; iGps <= MAXPRN_GPS; iGps++) {
160 QString prn = QString("G%1").arg(iGps, 2, 10, QChar('0'));
[3429]161 _params.push_back(new cmbParam(cmbParam::offACSat, ++nextPar,
162 AC->name, prn));
[2991]163 }
164 }
[3134]165 for (int iGps = 1; iGps <= MAXPRN_GPS; iGps++) {
[2933]166 QString prn = QString("G%1").arg(iGps, 2, 10, QChar('0'));
[3429]167 _params.push_back(new cmbParam(cmbParam::clkSat, ++nextPar, "", prn));
[2933]168 }
169
[3032]170 // Initialize Variance-Covariance Matrix
171 // -------------------------------------
172 _QQ.ReSize(_params.size());
[2933]173 _QQ = 0.0;
174 for (int iPar = 1; iPar <= _params.size(); iPar++) {
175 cmbParam* pp = _params[iPar-1];
[3455]176 _QQ(iPar,iPar) = pp->sig0 * pp->sig0;
[2933]177 }
[3035]178
[3052]179 // ANTEX File
180 // ----------
181 _antex = 0;
182 QString antexFileName = settings.value("pppAntex").toString();
183 if (!antexFileName.isEmpty()) {
184 _antex = new bncAntex();
185 if (_antex->readFile(antexFileName) != success) {
186 emit newMessage("wrong ANTEX file", true);
187 delete _antex;
188 _antex = 0;
189 }
190 }
[3138]191
[3329]192 // Maximal Residuum
193 // ----------------
194 _MAXRES = settings.value("cmbMaxres").toDouble();
195 if (_MAXRES <= 0.0) {
196 _MAXRES = 999.0;
197 }
[2898]198}
199
200// Destructor
201////////////////////////////////////////////////////////////////////////////
202bncComb::~bncComb() {
[3429]203 QListIterator<cmbAC*> icAC(_ACs);
204 while (icAC.hasNext()) {
205 delete icAC.next();
[2918]206 }
[3201]207 delete _rtnetDecoder;
[3052]208 delete _antex;
[3296]209 for (int iPar = 1; iPar <= _params.size(); iPar++) {
210 delete _params[iPar-1];
211 }
[3434]212 QVectorIterator<cmbCorr*> itCorr(corrs());
[3429]213 while (itCorr.hasNext()) {
214 delete itCorr.next();
215 }
[2898]216}
217
[2928]218// Read and store one correction line
[2898]219////////////////////////////////////////////////////////////////////////////
220void bncComb::processCorrLine(const QString& staID, const QString& line) {
[2906]221 QMutexLocker locker(&_mutex);
[2913]222
[3431]223 // Find the AC Name
224 // ----------------
225 QString acName;
226 QListIterator<cmbAC*> icAC(_ACs);
227 while (icAC.hasNext()) {
228 cmbAC* AC = icAC.next();
229 if (AC->mountPoint == staID) {
230 acName = AC->name;
231 break;
232 }
233 }
234 if (acName.isEmpty()) {
235 return;
236 }
237
[2918]238 // Read the Correction
239 // -------------------
[3429]240 cmbCorr* newCorr = new cmbCorr();
[3431]241 newCorr->acName = acName;
[2913]242 if (!newCorr->readLine(line) == success) {
243 delete newCorr;
244 return;
245 }
246
[3274]247 // Check Modulo Time
248 // -----------------
249 if (int(newCorr->tt.gpssec()) % moduloTime != 0.0) {
250 delete newCorr;
251 return;
252 }
253
[3299]254 // Delete old corrections
255 // ----------------------
[3437]256 if (_resTime.valid() && newCorr->tt <= _resTime) {
[2924]257 delete newCorr;
258 return;
259 }
260
[3029]261 // Check the Ephemeris
262 //--------------------
[2986]263 if (_eph.find(newCorr->prn) == _eph.end()) {
264 delete newCorr;
265 return;
266 }
267 else {
268 t_eph* lastEph = _eph[newCorr->prn]->last;
269 t_eph* prevEph = _eph[newCorr->prn]->prev;
[3029]270 if (lastEph && lastEph->IOD() == newCorr->iod) {
271 newCorr->eph = lastEph;
[2986]272 }
[3029]273 else if (prevEph && prevEph->IOD() == newCorr->iod) {
274 newCorr->eph = prevEph;
[3429]275 switchToLastEph(lastEph, newCorr);
[3029]276 }
277 else {
[2986]278 delete newCorr;
279 return;
280 }
281 }
282
[3435]283 // Process previous Epoch(s)
284 // -------------------------
285 QListIterator<bncTime> itTime(_buffer.keys());
286 while (itTime.hasNext()) {
287 bncTime epoTime = itTime.next();
[3438]288 if (epoTime < newCorr->tt - moduloTime) {
[3435]289 _resTime = epoTime;
290 processEpoch();
291 }
[2927]292 }
293
[3429]294 // Merge or add the correction
295 // ---------------------------
[3435]296 QVector<cmbCorr*>& corrs = _buffer[newCorr->tt].corrs;
[3429]297 cmbCorr* existingCorr = 0;
[3435]298 QVectorIterator<cmbCorr*> itCorr(corrs);
[3429]299 while (itCorr.hasNext()) {
300 cmbCorr* hlp = itCorr.next();
301 if (hlp->prn == newCorr->prn && hlp->acName == newCorr->prn) {
302 existingCorr = hlp;
[2918]303 break;
304 }
305 }
[3429]306 if (existingCorr) {
[3298]307 delete newCorr;
[3429]308 existingCorr->readLine(line); // merge (multiple messages)
[2918]309 }
[2919]310 else {
[3435]311 corrs.append(newCorr);
[2919]312 }
[2898]313}
314
[2986]315// Change the correction so that it refers to last received ephemeris
316////////////////////////////////////////////////////////////////////////////
[3029]317void bncComb::switchToLastEph(const t_eph* lastEph, t_corr* corr) {
[3028]318
[3429]319 if (corr->eph == lastEph) {
320 return;
321 }
322
[2987]323 ColumnVector oldXC(4);
324 ColumnVector oldVV(3);
[3029]325 corr->eph->position(corr->tt.gpsw(), corr->tt.gpssec(),
326 oldXC.data(), oldVV.data());
[2988]327
[2987]328 ColumnVector newXC(4);
329 ColumnVector newVV(3);
[3029]330 lastEph->position(corr->tt.gpsw(), corr->tt.gpssec(),
[2987]331 newXC.data(), newVV.data());
[2988]332
333 ColumnVector dX = newXC.Rows(1,3) - oldXC.Rows(1,3);
[2989]334 ColumnVector dV = newVV - oldVV;
335 double dC = newXC(4) - oldXC(4);
336
[2988]337 ColumnVector dRAO(3);
338 XYZ_to_RSW(newXC.Rows(1,3), newVV, dX, dRAO);
[2989]339
340 ColumnVector dDotRAO(3);
341 XYZ_to_RSW(newXC.Rows(1,3), newVV, dV, dDotRAO);
342
[3455]343 QString msg = "switch corr " + corr->prn
[3029]344 + QString(" %1 -> %2 %3").arg(corr->iod,3)
[3013]345 .arg(lastEph->IOD(),3).arg(dC*t_CST::c, 8, 'f', 4);
346
[3029]347 emit newMessage(msg.toAscii(), false);
[3028]348
[3029]349 corr->iod = lastEph->IOD();
350 corr->eph = lastEph;
[3031]351 corr->rao += dRAO;
352 corr->dotRao += dDotRAO;
[3029]353 corr->dClk -= dC;
[2986]354}
355
[3429]356// Process Epoch
[2928]357////////////////////////////////////////////////////////////////////////////
[3429]358void bncComb::processEpoch() {
[2918]359
[3429]360 int nPar = _params.size();
361
[2990]362 _log.clear();
363
364 QTextStream out(&_log, QIODevice::WriteOnly);
365
[3371]366 out << endl << "Combination:" << endl
[3275]367 << "------------------------------" << endl;
[2990]368
[3433]369 // Observation Statistics
370 // ----------------------
[3455]371 bool masterPresent = false;
[3433]372 QListIterator<cmbAC*> icAC(_ACs);
373 while (icAC.hasNext()) {
374 cmbAC* AC = icAC.next();
375 AC->numObs = 0;
[3434]376 QVectorIterator<cmbCorr*> itCorr(corrs());
[3433]377 while (itCorr.hasNext()) {
378 cmbCorr* corr = itCorr.next();
379 if (corr->acName == AC->name) {
380 AC->numObs += 1;
[3453]381 if (AC->name == _masterOrbitAC) {
382 masterPresent = true;
383 }
[3433]384 }
385 }
386 out << AC->name.toAscii().data() << ": " << AC->numObs << endl;
387 }
388
[3453]389 // If Master not present, switch to another one
390 // --------------------------------------------
[3456]391 if (masterPresent) {
392 _masterMissingEpochs = 0;
393 }
394 else {
[3455]395 ++_masterMissingEpochs;
[3459]396 if (_masterMissingEpochs < 10) {
[3457]397 out << "Missing Master, Epoch skipped" << endl;
[3455]398 _buffer.remove(_resTime);
399 emit newMessage(_log, false);
400 return;
[3453]401 }
[3455]402 else {
403 _masterMissingEpochs = 0;
404 QListIterator<cmbAC*> icAC(_ACs);
405 while (icAC.hasNext()) {
406 cmbAC* AC = icAC.next();
407 if (AC->numObs > 0) {
408 out << "Switching Master AC "
409 << _masterOrbitAC.toAscii().data() << " --> "
410 << AC->name.toAscii().data() << " "
411 << _resTime.datestr().c_str() << " "
412 << _resTime.timestr().c_str() << endl;
413 _masterOrbitAC = AC->name;
414 break;
415 }
[3452]416 }
417 }
418 }
419
[3429]420 // Prediction Step
421 // ---------------
[2933]422 ColumnVector x0(nPar);
423 for (int iPar = 1; iPar <= _params.size(); iPar++) {
[3455]424 cmbParam* pp = _params[iPar-1];
[3460]425//// QString prn = pp->prn;
426//// if (!prn.isEmpty() && _eph.find(prn) != _eph.end()) {
427//// switchToLastEph(_eph[prn]->last, pp);
428//// }
[3455]429 if (pp->epoSpec) {
[3451]430 pp->xx = 0.0;
[3455]431 _QQ.Row(iPar) = 0.0;
432 _QQ.Column(iPar) = 0.0;
433 _QQ(iPar,iPar) = pp->sig0 * pp->sig0;
[3451]434 }
[3455]435 else {
436 _QQ(iPar,iPar) += pp->sigP * pp->sigP;
437 }
[2933]438 x0(iPar) = pp->xx;
439 }
440
[3455]441 SymmetricMatrix QQ_sav = _QQ;
[3441]442
[3455]443 ColumnVector dx;
[3429]444 QMap<QString, t_corr*> resCorr;
[3455]445
446 // Update and outlier detection loop
447 // ---------------------------------
448 while (true) {
[3135]449
[3455]450 Matrix AA;
451 ColumnVector ll;
452 DiagonalMatrix PP;
[3429]453
[3455]454 if (createAmat(AA, ll, PP, x0, resCorr) != success) {
455 _buffer.remove(_resTime);
456 emit newMessage(_log, false);
457 return;
[3441]458 }
[2933]459
[3429]460 bncModel::kalman(AA, ll, PP, _QQ, dx);
461 ColumnVector vv = ll - AA * dx;
[3080]462
[3429]463 int maxResIndex;
464 double maxRes = vv.maximum_absolute_value1(maxResIndex);
465 out.setRealNumberNotation(QTextStream::FixedNotation);
466 out.setRealNumberPrecision(3);
467 out << _resTime.datestr().c_str() << " " << _resTime.timestr().c_str()
[3432]468 << " Maximum Residuum " << maxRes << ' '
[3434]469 << corrs()[maxResIndex-1]->acName << ' ' << corrs()[maxResIndex-1]->prn;
[3080]470
[3432]471 if (maxRes > _MAXRES) {
472 for (int iPar = 1; iPar <= _params.size(); iPar++) {
473 cmbParam* pp = _params[iPar-1];
474 if (pp->type == cmbParam::offACSat &&
[3434]475 pp->AC == corrs()[maxResIndex-1]->acName &&
476 pp->prn == corrs()[maxResIndex-1]->prn) {
[3432]477 QQ_sav.Row(iPar) = 0.0;
478 QQ_sav.Column(iPar) = 0.0;
[3455]479 QQ_sav(iPar,iPar) = pp->sig0 * pp->sig0;
[3432]480 }
481 }
482
483 out << " Outlier" << endl;
484 _QQ = QQ_sav;
[3455]485 corrs().remove(maxResIndex-1);
[3432]486 }
487 else {
488 out << " OK" << endl;
489 break;
490 }
491 }
492
493 // Update Parameter Values
494 // -----------------------
[3429]495 for (int iPar = 1; iPar <= _params.size(); iPar++) {
496 cmbParam* pp = _params[iPar-1];
497 pp->xx += dx(iPar);
498 if (pp->type == cmbParam::clkSat) {
499 if (resCorr.find(pp->prn) != resCorr.end()) {
500 resCorr[pp->prn]->dClk = pp->xx / t_CST::c;
[3080]501 }
502 }
[3429]503 out << _resTime.datestr().c_str() << " "
504 << _resTime.timestr().c_str() << " ";
505 out.setRealNumberNotation(QTextStream::FixedNotation);
506 out.setFieldWidth(8);
507 out.setRealNumberPrecision(4);
508 out << pp->toString() << " "
509 << pp->xx << " +- " << sqrt(_QQ(pp->index,pp->index)) << endl;
510 out.setFieldWidth(0);
[2918]511 }
[2919]512
[3432]513 // Print Results
514 // -------------
[3429]515 printResults(out, resCorr);
516 dumpResults(resCorr);
[2928]517
[2990]518 emit newMessage(_log, false);
[3296]519
[3432]520 // Delete Data
521 // -----------
[3434]522 _buffer.remove(_resTime);
[2918]523}
[3011]524
[3201]525// Print results
[3011]526////////////////////////////////////////////////////////////////////////////
[3429]527void bncComb::printResults(QTextStream& out,
[3011]528 const QMap<QString, t_corr*>& resCorr) {
529
530 QMapIterator<QString, t_corr*> it(resCorr);
531 while (it.hasNext()) {
532 it.next();
533 t_corr* corr = it.value();
[3029]534 const t_eph* eph = corr->eph;
[3015]535 if (eph) {
536 double xx, yy, zz, cc;
[3429]537 eph->position(_resTime.gpsw(), _resTime.gpssec(), xx, yy, zz, cc);
[3015]538
[3429]539 out << _resTime.datestr().c_str() << " "
540 << _resTime.timestr().c_str() << " ";
[3015]541 out.setFieldWidth(3);
542 out << "Full Clock " << corr->prn << " " << corr->iod << " ";
543 out.setFieldWidth(14);
544 out << (cc + corr->dClk) * t_CST::c << endl;
[3370]545 out.setFieldWidth(0);
[3015]546 }
547 else {
548 out << "bncComb::printResuls bug" << endl;
549 }
[3011]550 }
551}
[3202]552
553// Send results to RTNet Decoder and directly to PPP Client
554////////////////////////////////////////////////////////////////////////////
[3429]555void bncComb::dumpResults(const QMap<QString, t_corr*>& resCorr) {
[3202]556
[3214]557 ostringstream out; out.setf(std::ios::fixed);
[3216]558 QStringList corrLines;
[3214]559
560 unsigned year, month, day, hour, minute;
561 double sec;
[3429]562 _resTime.civil_date(year, month, day);
563 _resTime.civil_time(hour, minute, sec);
[3214]564
565 out << "* "
566 << setw(4) << year << " "
567 << setw(2) << month << " "
568 << setw(2) << day << " "
569 << setw(2) << hour << " "
570 << setw(2) << minute << " "
571 << setw(12) << setprecision(8) << sec << " "
572 << endl;
573
[3202]574 QMapIterator<QString, t_corr*> it(resCorr);
575 while (it.hasNext()) {
576 it.next();
577 t_corr* corr = it.value();
578
[3214]579 double dT = 60.0;
[3202]580
[3214]581 for (int iTime = 1; iTime <= 2; iTime++) {
582
[3429]583 bncTime time12 = (iTime == 1) ? _resTime : _resTime + dT;
[3214]584
585 ColumnVector xc(4);
586 ColumnVector vv(3);
587 corr->eph->position(time12.gpsw(), time12.gpssec(),
588 xc.data(), vv.data());
589 bncPPPclient::applyCorr(time12, corr, xc, vv);
590
591 // Relativistic Correction
592 // -----------------------
593 double relCorr = - 2.0 * DotProduct(xc.Rows(1,3),vv) / t_CST::c / t_CST::c;
594 xc(4) -= relCorr;
595
596 // Code Biases
597 // -----------
598 double dcbP1C1 = 0.0;
599 double dcbP1P2 = 0.0;
600
601 // Correction Phase Center --> CoM
602 // -------------------------------
603 ColumnVector dx(3); dx = 0.0;
604 if (_antex) {
605 double Mjd = time12.mjd() + time12.daysec()/86400.0;
606 if (_antex->satCoMcorrection(corr->prn, Mjd, xc.Rows(1,3), dx) == success) {
607 xc(1) -= dx(1);
608 xc(2) -= dx(2);
609 xc(3) -= dx(3);
610 }
611 else {
612 cout << "antenna not found" << endl;
613 }
614 }
615
616 if (iTime == 1) {
617 out << 'P' << corr->prn.toAscii().data()
618 << setw(14) << setprecision(6) << xc(1) / 1000.0
619 << setw(14) << setprecision(6) << xc(2) / 1000.0
620 << setw(14) << setprecision(6) << xc(3) / 1000.0
621 << setw(14) << setprecision(6) << xc(4) * 1e6
622 << setw(14) << setprecision(6) << relCorr * 1e6
623 << setw(8) << setprecision(3) << dx(1)
624 << setw(8) << setprecision(3) << dx(2)
625 << setw(8) << setprecision(3) << dx(3)
626 << setw(8) << setprecision(3) << dcbP1C1
627 << setw(8) << setprecision(3) << dcbP1P2
628 << setw(6) << setprecision(1) << dT;
[3216]629
[3218]630 QString line;
[3217]631 int messageType = COTYPE_GPSCOMBINED;
[3218]632 int updateInt = 0;
633 line.sprintf("%d %d %d %.1f %s"
634 " %3d"
635 " %8.3f %8.3f %8.3f %8.3f"
636 " %10.5f %10.5f %10.5f %10.5f"
[3262]637 " %10.5f %10.5f %10.5f %10.5f INTERNAL",
[3218]638 messageType, updateInt, time12.gpsw(), time12.gpssec(),
639 corr->prn.toAscii().data(),
640 corr->iod,
[3219]641 corr->dClk * t_CST::c,
[3218]642 corr->rao[0],
643 corr->rao[1],
644 corr->rao[2],
[3219]645 corr->dotDClk * t_CST::c,
[3218]646 corr->dotRao[0],
647 corr->dotRao[1],
648 corr->dotRao[2],
[3262]649 corr->dotDotDClk * t_CST::c,
650 corr->dotDotRao[0],
651 corr->dotDotRao[1],
652 corr->dotDotRao[2]);
[3220]653 corrLines << line;
[3214]654 }
655 else {
656 out << setw(14) << setprecision(6) << xc(1) / 1000.0
657 << setw(14) << setprecision(6) << xc(2) / 1000.0
658 << setw(14) << setprecision(6) << xc(3) / 1000.0 << endl;
659 }
660 }
661
662 delete corr;
663 }
[3228]664 out << "EOE" << endl; // End Of Epoch flag
[3214]665
[3215]666 if (!_rtnetDecoder) {
667 _rtnetDecoder = new bncRtnetDecoder();
668 }
[3221]669
[3215]670 vector<string> errmsg;
[3221]671 _rtnetDecoder->Decode((char*) out.str().data(), out.str().size(), errmsg);
[3215]672
[3216]673 // Optionally send new Corrections to PPP
674 // --------------------------------------
675 bncApp* app = (bncApp*) qApp;
676 if (app->_bncPPPclient) {
677 app->_bncPPPclient->slotNewCorrections(corrLines);
678 }
[3202]679}
[3455]680
681// Create First Design Matrix and Vector of Measurements
682////////////////////////////////////////////////////////////////////////////
683t_irc bncComb::createAmat(Matrix& AA, ColumnVector& ll, DiagonalMatrix& PP,
684 const ColumnVector& x0,
685 QMap<QString, t_corr*>& resCorr) {
686
687 unsigned nPar = _params.size();
688 unsigned nObs = corrs().size();
689
690 if (nObs == 0) {
691 return failure;
692 }
693
[3461]694 const int nCon = 1 + MAXPRN_GPS;
[3455]695
696 AA.ReSize(nObs+nCon, nPar); AA = 0.0;
697 ll.ReSize(nObs+nCon); ll = 0.0;
698 PP.ReSize(nObs+nCon); PP = 1.0 / (sigObs * sigObs);
699
700 int iObs = 0;
701
702 QVectorIterator<cmbCorr*> itCorr(corrs());
703 while (itCorr.hasNext()) {
704 cmbCorr* corr = itCorr.next();
705 QString prn = corr->prn;
706 switchToLastEph(_eph[prn]->last, corr);
707 ++iObs;
708
709 if (corr->acName == _masterOrbitAC && resCorr.find(prn) == resCorr.end()) {
710 resCorr[prn] = new t_corr(*corr);
711 }
712
713 for (int iPar = 1; iPar <= _params.size(); iPar++) {
714 cmbParam* pp = _params[iPar-1];
715 AA(iObs, iPar) = pp->partial(corr->acName, prn);
716 }
717
718 ll(iObs) = corr->dClk * t_CST::c - DotProduct(AA.Row(iObs), x0);
719 }
720
721 // Regularization
722 // --------------
723 const double Ph = 1.e6;
[3461]724 PP(nObs+1) = Ph;
[3455]725 for (int iPar = 1; iPar <= _params.size(); iPar++) {
726 cmbParam* pp = _params[iPar-1];
[3461]727 if (AA.Column(iPar).maximum_absolute_value() > 0.0) {
728 if (pp->type == cmbParam::clkSat) {
729 AA(nObs+1, iPar) = 1.0;
730 }
[3455]731 }
732 }
[3461]733 int iCond = 1;
734 for (int iGps = 1; iGps <= MAXPRN_GPS; iGps++) {
735 QString prn = QString("G%1").arg(iGps, 2, 10, QChar('0'));
736 ++iCond;
737 PP(nObs+iCond) = Ph;
738 for (int iPar = 1; iPar <= _params.size(); iPar++) {
739 cmbParam* pp = _params[iPar-1];
740 if (pp->type == cmbParam::offACSat && pp->prn == prn) {
741 AA(nObs+iCond, iPar) = 1.0;
[3455]742 }
743 }
744 }
745
746 return success;
747}
748
749// Change the parameter so that it refers to last received ephemeris
750////////////////////////////////////////////////////////////////////////////
751void bncComb::switchToLastEph(const t_eph* lastEph, cmbParam* pp) {
752
[3458]753 if (pp->type != cmbParam::clkSat) {
[3455]754 return;
755 }
756
757 if (pp->eph == 0) {
758 pp->eph = lastEph;
759 return;
760 }
761
762 if (pp->eph == lastEph) {
763 return;
764 }
765
766 ColumnVector oldXC(4);
767 ColumnVector oldVV(3);
768 pp->eph->position(_resTime.gpsw(), _resTime.gpssec(),
769 oldXC.data(), oldVV.data());
770
771 ColumnVector newXC(4);
772 ColumnVector newVV(3);
773 lastEph->position(_resTime.gpsw(), _resTime.gpssec(),
774 newXC.data(), newVV.data());
775
776 double dC = newXC(4) - oldXC(4);
777
778 QString msg = "switch param " + pp->prn
779 + QString(" %1 -> %2 %3").arg(pp->eph->IOD(),3)
780 .arg(lastEph->IOD(),3).arg(dC*t_CST::c, 8, 'f', 4);
781
782 emit newMessage(msg.toAscii(), false);
783
784 pp->eph = lastEph;
785 pp->xx -= dC * t_CST::c;
786}
787
Note: See TracBrowser for help on using the repository browser.