source: ntrip/branches/BNC_LM/bncmodel.cpp@ 10583

Last change on this file since 10583 was 3571, checked in by mervart, 13 years ago
File size: 41.2 KB
Line 
1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters.
3//
4// Copyright (C) 2007
5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
7// Czech Technical University Prague, Department of Geodesy
8// http://www.fsv.cvut.cz
9//
10// Email: euref-ip@bkg.bund.de
11//
12// This program is free software; you can redistribute it and/or
13// modify it under the terms of the GNU General Public License
14// as published by the Free Software Foundation, version 2.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the Free Software
23// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
27 * -------------------------------------------------------------------------
28 *
29 * Class: bncParam, bncModel
30 *
31 * Purpose: Model for PPP
32 *
33 * Author: L. Mervart
34 *
35 * Created: 01-Dec-2009
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iomanip>
42#include <cmath>
43#include <newmatio.h>
44#include <sstream>
45
46#include "bncmodel.h"
47#include "bncapp.h"
48#include "bncpppclient.h"
49#include "bancroft.h"
50#include "bncutils.h"
51#include "bncsettings.h"
52#include "bnctides.h"
53#include "bncantex.h"
54
55using namespace std;
56
57const unsigned MINOBS = 5;
58const double MINELE = 10.0 * M_PI / 180.0;
59const double MAXRES_CODE = 10.0;
60const double MAXRES_PHASE_GPS = 0.04;
61const double MAXRES_PHASE_GLONASS = 0.08;
62const double GLONASS_WEIGHT_FACTOR = 5.0;
63
64// Constructor
65////////////////////////////////////////////////////////////////////////////
66bncParam::bncParam(bncParam::parType typeIn, int indexIn,
67 const QString& prnIn) {
68 type = typeIn;
69 index = indexIn;
70 prn = prnIn;
71 index_old = 0;
72 xx = 0.0;
73 numEpo = 0;
74}
75
76// Destructor
77////////////////////////////////////////////////////////////////////////////
78bncParam::~bncParam() {
79}
80
81// Partial
82////////////////////////////////////////////////////////////////////////////
83double bncParam::partial(t_satData* satData, bool phase) {
84
85 Tracer tracer("bncParam::partial");
86
87 // Coordinates
88 // -----------
89 if (type == CRD_X) {
90 return (xx - satData->xx(1)) / satData->rho;
91 }
92 else if (type == CRD_Y) {
93 return (xx - satData->xx(2)) / satData->rho;
94 }
95 else if (type == CRD_Z) {
96 return (xx - satData->xx(3)) / satData->rho;
97 }
98
99 // Receiver Clocks
100 // ---------------
101 else if (type == RECCLK) {
102 return 1.0;
103 }
104
105 // Troposphere
106 // -----------
107 else if (type == TROPO) {
108 return 1.0 / sin(satData->eleSat);
109 }
110
111 // Galileo Offset
112 // --------------
113 else if (type == GALILEO_OFFSET) {
114 if (satData->prn[0] == 'E') {
115 return 1.0;
116 }
117 else {
118 return 0.0;
119 }
120 }
121
122 // Ambiguities
123 // -----------
124 else if (type == AMB_L3) {
125 if (phase && satData->prn == prn) {
126 return 1.0;
127 }
128 else {
129 return 0.0;
130 }
131 }
132
133 // Default return
134 // --------------
135 return 0.0;
136}
137
138// Constructor
139////////////////////////////////////////////////////////////////////////////
140bncModel::bncModel(QByteArray staID) {
141
142 _staID = staID;
143
144 connect(this, SIGNAL(newMessage(QByteArray,bool)),
145 ((bncApp*)qApp), SLOT(slotMessage(const QByteArray,bool)));
146
147 bncSettings settings;
148
149 // Observation Sigmas
150 // ------------------
151 _sigP3 = 5.0;
152 if (!settings.value("pppSigmaCode").toString().isEmpty()) {
153 _sigP3 = settings.value("pppSigmaCode").toDouble();
154 }
155 _sigL3 = 0.02;
156 if (!settings.value("pppSigmaPhase").toString().isEmpty()) {
157 _sigL3 = settings.value("pppSigmaPhase").toDouble();
158 }
159
160 // Parameter Sigmas
161 // ----------------
162 _sigCrd0 = 100.0;
163 if (!settings.value("pppSigCrd0").toString().isEmpty()) {
164 _sigCrd0 = settings.value("pppSigCrd0").toDouble();
165 }
166 _sigCrdP = 100.0;
167 if (!settings.value("pppSigCrdP").toString().isEmpty()) {
168 _sigCrdP = settings.value("pppSigCrdP").toDouble();
169 }
170 _sigTrp0 = 0.1;
171 if (!settings.value("pppSigTrp0").toString().isEmpty()) {
172 _sigTrp0 = settings.value("pppSigTrp0").toDouble();
173 }
174 _sigTrpP = 1e-6;
175 if (!settings.value("pppSigTrpP").toString().isEmpty()) {
176 _sigTrpP = settings.value("pppSigTrpP").toDouble();
177 }
178 _sigClk0 = 1000.0;
179 _sigAmb0 = 1000.0;
180 _sigGalileoOffset0 = 1000.0;
181 _sigGalileoOffsetP = 0.0;
182
183 // Quick-Start Mode
184 // ----------------
185 _quickStart = 0;
186 if (settings.value("pppRefCrdX").toString() != "" &&
187 settings.value("pppRefCrdY").toString() != "" &&
188 settings.value("pppRefCrdZ").toString() != "" &&
189 !settings.value("pppQuickStart").toString().isEmpty()) {
190 _quickStart = settings.value("pppQuickStart").toDouble();
191 }
192
193 // Several options
194 // ---------------
195 _usePhase = false;
196 if ( Qt::CheckState(settings.value("pppUsePhase").toInt()) == Qt::Checked) {
197 _usePhase = true;
198 }
199
200 _estTropo = false;
201 if ( Qt::CheckState(settings.value("pppEstTropo").toInt()) == Qt::Checked) {
202 _estTropo = true;
203 }
204
205 _useGalileo = false;
206 if ( Qt::CheckState(settings.value("pppGalileo").toInt()) == Qt::Checked) {
207 _useGalileo = true;
208 }
209
210 // NMEA Output
211 // -----------
212 QString nmeaFileName = settings.value("nmeaFile").toString();
213 if (nmeaFileName.isEmpty()) {
214 _nmeaFile = 0;
215 _nmeaStream = 0;
216 }
217 else {
218 expandEnvVar(nmeaFileName);
219 _nmeaFile = new QFile(nmeaFileName);
220 if ( Qt::CheckState(settings.value("rnxAppend").toInt()) == Qt::Checked) {
221 _nmeaFile->open(QIODevice::WriteOnly | QIODevice::Append);
222 }
223 else {
224 _nmeaFile->open(QIODevice::WriteOnly);
225 }
226 _nmeaStream = new QTextStream();
227 _nmeaStream->setDevice(_nmeaFile);
228 }
229
230 // Antenna Name, ANTEX File
231 // ------------------------
232 _antex = 0;
233 QString antexFileName = settings.value("pppAntex").toString();
234 if (!antexFileName.isEmpty()) {
235 _antex = new bncAntex();
236 if (_antex->readFile(antexFileName) != success) {
237 emit newMessage("wrong ANTEX file", true);
238 delete _antex;
239 _antex = 0;
240 }
241 else {
242 _antennaName = settings.value("pppAntenna").toString();
243 }
244 }
245
246 // Antenna Eccentricities
247 // ----------------------
248 _dN = settings.value("pppRefdN").toDouble();
249 _dE = settings.value("pppRefdE").toDouble();
250 _dU = settings.value("pppRefdU").toDouble();
251
252 // Bancroft Coordinates
253 // --------------------
254 _xcBanc.ReSize(4); _xcBanc = 0.0;
255 _ellBanc.ReSize(3); _ellBanc = 0.0;
256
257 // Save copy of data (used in outlier detection)
258 // ---------------------------------------------
259 _epoData_sav = new t_epoData();
260}
261
262// Destructor
263////////////////////////////////////////////////////////////////////////////
264bncModel::~bncModel() {
265 delete _nmeaStream;
266 delete _nmeaFile;
267 for (int ii = 0; ii < _posAverage.size(); ++ii) {
268 delete _posAverage[ii];
269 }
270 delete _antex;
271 for (int iPar = 1; iPar <= _params.size(); iPar++) {
272 delete _params[iPar-1];
273 }
274 for (int iPar = 1; iPar <= _params_sav.size(); iPar++) {
275 delete _params_sav[iPar-1];
276 }
277 delete _epoData_sav;
278}
279
280// Reset Parameters and Variance-Covariance Matrix
281////////////////////////////////////////////////////////////////////////////
282void bncModel::reset() {
283
284 Tracer tracer("bncModel::reset");
285
286 for (int iPar = 1; iPar <= _params.size(); iPar++) {
287 delete _params[iPar-1];
288 }
289 _params.clear();
290
291 int nextPar = 0;
292 _params.push_back(new bncParam(bncParam::CRD_X, ++nextPar, ""));
293 _params.push_back(new bncParam(bncParam::CRD_Y, ++nextPar, ""));
294 _params.push_back(new bncParam(bncParam::CRD_Z, ++nextPar, ""));
295 _params.push_back(new bncParam(bncParam::RECCLK, ++nextPar, ""));
296 if (_estTropo) {
297 _params.push_back(new bncParam(bncParam::TROPO, ++nextPar, ""));
298 }
299 if (_useGalileo) {
300 _params.push_back(new bncParam(bncParam::GALILEO_OFFSET, ++nextPar, ""));
301 }
302
303 _QQ.ReSize(_params.size());
304 _QQ = 0.0;
305 for (int iPar = 1; iPar <= _params.size(); iPar++) {
306 bncParam* pp = _params[iPar-1];
307 pp->xx = 0.0;
308 if (pp->isCrd()) {
309 _QQ(iPar,iPar) = _sigCrd0 * _sigCrd0;
310 }
311 else if (pp->type == bncParam::RECCLK) {
312 _QQ(iPar,iPar) = _sigClk0 * _sigClk0;
313 }
314 else if (pp->type == bncParam::TROPO) {
315 _QQ(iPar,iPar) = _sigTrp0 * _sigTrp0;
316 }
317 else if (pp->type == bncParam::GALILEO_OFFSET) {
318 _QQ(iPar,iPar) = _sigGalileoOffset0 * _sigGalileoOffset0;
319 }
320 }
321}
322
323// Bancroft Solution
324////////////////////////////////////////////////////////////////////////////
325t_irc bncModel::cmpBancroft(t_epoData* epoData) {
326
327 Tracer tracer("bncModel::cmpBancroft");
328
329 if (epoData->sizeSys('G') < MINOBS) {
330 _log += "bncModel::cmpBancroft: not enough data\n";
331 return failure;
332 }
333
334 Matrix BB(epoData->sizeSys('G'), 4);
335
336 QMapIterator<QString, t_satData*> it(epoData->satData);
337 int iObsBanc = 0;
338 while (it.hasNext()) {
339 it.next();
340 t_satData* satData = it.value();
341 if (satData->system() == 'G') {
342 ++iObsBanc;
343 QString prn = it.key();
344 BB(iObsBanc, 1) = satData->xx(1);
345 BB(iObsBanc, 2) = satData->xx(2);
346 BB(iObsBanc, 3) = satData->xx(3);
347 BB(iObsBanc, 4) = satData->P3 + satData->clk;
348 }
349 }
350
351 bancroft(BB, _xcBanc);
352
353 // Ellipsoidal Coordinates
354 // ------------------------
355 xyz2ell(_xcBanc.data(), _ellBanc.data());
356
357 // Compute Satellite Elevations
358 // ----------------------------
359 QMutableMapIterator<QString, t_satData*> im(epoData->satData);
360 while (im.hasNext()) {
361 im.next();
362 t_satData* satData = im.value();
363 cmpEle(satData);
364 if (satData->eleSat < MINELE) {
365 delete satData;
366 im.remove();
367 }
368 }
369
370 return success;
371}
372
373// Computed Value
374////////////////////////////////////////////////////////////////////////////
375double bncModel::cmpValue(t_satData* satData, bool phase) {
376
377 Tracer tracer("bncModel::cmpValue");
378
379 ColumnVector xRec(3);
380 xRec(1) = x();
381 xRec(2) = y();
382 xRec(3) = z();
383
384 double rho0 = (satData->xx - xRec).norm_Frobenius();
385 double dPhi = t_CST::omega * rho0 / t_CST::c;
386
387 xRec(1) = x() * cos(dPhi) - y() * sin(dPhi);
388 xRec(2) = y() * cos(dPhi) + x() * sin(dPhi);
389 xRec(3) = z();
390
391 tides(_time, xRec);
392
393 satData->rho = (satData->xx - xRec).norm_Frobenius();
394
395 double tropDelay = delay_saast(satData->eleSat) +
396 trp() / sin(satData->eleSat);
397
398 double wind = 0.0;
399 if (phase) {
400 wind = windUp(satData->prn, satData->xx, xRec) * satData->lambda3;
401 }
402
403 double offset = 0.0;
404 if (satData->prn[0] == 'E') {
405 offset = Galileo_offset();
406 }
407
408 double phaseCenter = 0.0;
409 if (_antex) {
410 bool found;
411 phaseCenter = _antex->pco(_antennaName, satData->eleSat, found);
412 if (!found) {
413 emit newMessage("ANTEX: antenna >"
414 + _antennaName.toAscii() + "< not found", true);
415 }
416 }
417
418 double antennaOffset = 0.0;
419 if (_dN != 0.0 || _dE != 0.0 || _dU != 0.0) {
420 double cosa = cos(satData->azSat);
421 double sina = sin(satData->azSat);
422 double cose = cos(satData->eleSat);
423 double sine = sin(satData->eleSat);
424 antennaOffset = -_dN * cosa*cose - _dE * sina*cose - _dU * sine;
425 }
426
427 return satData->rho + phaseCenter + antennaOffset + clk()
428 + offset - satData->clk + tropDelay + wind;
429}
430
431// Tropospheric Model (Saastamoinen)
432////////////////////////////////////////////////////////////////////////////
433double bncModel::delay_saast(double Ele) {
434
435 Tracer tracer("bncModel::delay_saast");
436
437 double xyz[3];
438 xyz[0] = x();
439 xyz[1] = y();
440 xyz[2] = z();
441 double ell[3];
442 xyz2ell(xyz, ell);
443 double height = ell[2];
444
445 double pp = 1013.25 * pow(1.0 - 2.26e-5 * height, 5.225);
446 double TT = 18.0 - height * 0.0065 + 273.15;
447 double hh = 50.0 * exp(-6.396e-4 * height);
448 double ee = hh / 100.0 * exp(-37.2465 + 0.213166*TT - 0.000256908*TT*TT);
449
450 double h_km = height / 1000.0;
451
452 if (h_km < 0.0) h_km = 0.0;
453 if (h_km > 5.0) h_km = 5.0;
454 int ii = int(h_km + 1);
455 double href = ii - 1;
456
457 double bCor[6];
458 bCor[0] = 1.156;
459 bCor[1] = 1.006;
460 bCor[2] = 0.874;
461 bCor[3] = 0.757;
462 bCor[4] = 0.654;
463 bCor[5] = 0.563;
464
465 double BB = bCor[ii-1] + (bCor[ii]-bCor[ii-1]) * (h_km - href);
466
467 double zen = M_PI/2.0 - Ele;
468
469 return (0.002277/cos(zen)) * (pp + ((1255.0/TT)+0.05)*ee - BB*(tan(zen)*tan(zen)));
470}
471
472// Prediction Step of the Filter
473////////////////////////////////////////////////////////////////////////////
474void bncModel::predict(int iPhase, t_epoData* epoData) {
475
476 Tracer tracer("bncModel::predict");
477
478 if (iPhase == 0) {
479
480 bncSettings settings;
481
482 _maxSolGap = settings.value("pppMaxSolGap").toDouble();
483
484 bool firstCrd = false;
485 if (!_lastTimeOK.valid() || (_maxSolGap > 0 && _time - _lastTimeOK > _maxSolGap)) {
486 firstCrd = true;
487 _startTime = epoData->tt;
488 reset();
489 }
490
491 // Use different white noise for Quick-Start mode
492 // ----------------------------------------------
493 double sigCrdP_used = _sigCrdP;
494 if ( _quickStart > 0.0 && _quickStart > (epoData->tt - _startTime) ) {
495 sigCrdP_used = 0.0;
496 }
497
498 // Predict Parameter values, add white noise
499 // -----------------------------------------
500 for (int iPar = 1; iPar <= _params.size(); iPar++) {
501 bncParam* pp = _params[iPar-1];
502
503 // Coordinates
504 // -----------
505 if (pp->type == bncParam::CRD_X) {
506 if (firstCrd) {
507 if (settings.value("pppRefCrdX").toString() != "" &&
508 settings.value("pppRefCrdY").toString() != "" &&
509 settings.value("pppRefCrdZ").toString() != "") {
510 pp->xx = settings.value("pppRefCrdX").toDouble();
511 }
512 else {
513 pp->xx = _xcBanc(1);
514 }
515 }
516 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
517 }
518 else if (pp->type == bncParam::CRD_Y) {
519 if (firstCrd) {
520 if (settings.value("pppRefCrdX").toString() != "" &&
521 settings.value("pppRefCrdY").toString() != "" &&
522 settings.value("pppRefCrdZ").toString() != "") {
523 pp->xx = settings.value("pppRefCrdY").toDouble();
524 }
525 else {
526 pp->xx = _xcBanc(2);
527 }
528 }
529 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
530 }
531 else if (pp->type == bncParam::CRD_Z) {
532 if (firstCrd) {
533 if (settings.value("pppRefCrdX").toString() != "" &&
534 settings.value("pppRefCrdY").toString() != "" &&
535 settings.value("pppRefCrdZ").toString() != "") {
536 pp->xx = settings.value("pppRefCrdZ").toDouble();
537 }
538 else {
539 pp->xx = _xcBanc(3);
540 }
541 }
542 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
543 }
544
545 // Receiver Clocks
546 // ---------------
547 else if (pp->type == bncParam::RECCLK) {
548 pp->xx = _xcBanc(4);
549 for (int jj = 1; jj <= _params.size(); jj++) {
550 _QQ(iPar, jj) = 0.0;
551 }
552 _QQ(iPar,iPar) = _sigClk0 * _sigClk0;
553 }
554
555 // Tropospheric Delay
556 // ------------------
557 else if (pp->type == bncParam::TROPO) {
558 _QQ(iPar,iPar) += _sigTrpP * _sigTrpP;
559 }
560
561 // Galileo Offset
562 // --------------
563 else if (pp->type == bncParam::GALILEO_OFFSET) {
564 _QQ(iPar,iPar) += _sigGalileoOffsetP * _sigGalileoOffsetP;
565 }
566 }
567 }
568
569 // Add New Ambiguities if necessary
570 // --------------------------------
571 if (_usePhase) {
572
573 // Make a copy of QQ and xx, set parameter indices
574 // -----------------------------------------------
575 SymmetricMatrix QQ_old = _QQ;
576
577 for (int iPar = 1; iPar <= _params.size(); iPar++) {
578 _params[iPar-1]->index_old = _params[iPar-1]->index;
579 _params[iPar-1]->index = 0;
580 }
581
582 // Remove Ambiguity Parameters without observations
583 // ------------------------------------------------
584 int iPar = 0;
585 QMutableVectorIterator<bncParam*> im(_params);
586 while (im.hasNext()) {
587 bncParam* par = im.next();
588 bool removed = false;
589 if (par->type == bncParam::AMB_L3) {
590 if (epoData->satData.find(par->prn) == epoData->satData.end()) {
591 removed = true;
592 delete par;
593 im.remove();
594 }
595 }
596 if (! removed) {
597 ++iPar;
598 par->index = iPar;
599 }
600 }
601
602 // Add new ambiguity parameters
603 // ----------------------------
604 QMapIterator<QString, t_satData*> it(epoData->satData);
605 while (it.hasNext()) {
606 it.next();
607 t_satData* satData = it.value();
608 addAmb(satData);
609 }
610
611 int nPar = _params.size();
612 _QQ.ReSize(nPar); _QQ = 0.0;
613 for (int i1 = 1; i1 <= nPar; i1++) {
614 bncParam* p1 = _params[i1-1];
615 if (p1->index_old != 0) {
616 _QQ(p1->index, p1->index) = QQ_old(p1->index_old, p1->index_old);
617 for (int i2 = 1; i2 <= nPar; i2++) {
618 bncParam* p2 = _params[i2-1];
619 if (p2->index_old != 0) {
620 _QQ(p1->index, p2->index) = QQ_old(p1->index_old, p2->index_old);
621 }
622 }
623 }
624 }
625
626 for (int ii = 1; ii <= nPar; ii++) {
627 bncParam* par = _params[ii-1];
628 if (par->index_old == 0) {
629 _QQ(par->index, par->index) = _sigAmb0 * _sigAmb0;
630 }
631 par->index_old = par->index;
632 }
633 }
634}
635
636// Update Step of the Filter (currently just a single-epoch solution)
637////////////////////////////////////////////////////////////////////////////
638t_irc bncModel::update(t_epoData* epoData) {
639
640 Tracer tracer("bncModel::update");
641
642 bncSettings settings;
643
644 _log.clear();
645
646 _time = epoData->tt; // current epoch time
647
648 if (settings.value("pppSPP").toString() == "PPP") {
649 _log += "Precise Point Positioning of Epoch "
650 + QByteArray(_time.timestr(1).c_str()) +
651 "\n---------------------------------------------------------------\n";
652 }
653 else {
654 _log += "Single Point Positioning of Epoch "
655 + QByteArray(_time.timestr(1).c_str()) +
656 "\n--------------------------------------------------------------\n";
657 }
658
659 // Outlier Detection Loop
660 // ----------------------
661 if (update_p(epoData) != success) {
662 emit newMessage(_log, false);
663 return failure;
664 }
665
666 // Remember the Epoch-specific Results for the computation of means
667 // ----------------------------------------------------------------
668 pppPos* newPos = new pppPos;
669 newPos->time = epoData->tt;
670
671 // Set Solution Vector
672 // -------------------
673 ostringstream strB;
674 strB.setf(ios::fixed);
675 QVectorIterator<bncParam*> itPar(_params);
676 while (itPar.hasNext()) {
677 bncParam* par = itPar.next();
678
679 if (par->type == bncParam::RECCLK) {
680 strB << "\n clk = " << setw(10) << setprecision(3) << par->xx
681 << " +- " << setw(6) << setprecision(3)
682 << sqrt(_QQ(par->index,par->index));
683 }
684 else if (par->type == bncParam::AMB_L3) {
685 ++par->numEpo;
686 strB << "\n amb " << par->prn.toAscii().data() << " = "
687 << setw(10) << setprecision(3) << par->xx
688 << " +- " << setw(6) << setprecision(3)
689 << sqrt(_QQ(par->index,par->index))
690 << " nEpo = " << par->numEpo;
691 }
692 else if (par->type == bncParam::TROPO) {
693 double aprTrp = delay_saast(M_PI/2.0);
694 strB << "\n trp = " << par->prn.toAscii().data()
695 << setw(7) << setprecision(3) << aprTrp << " "
696 << setw(6) << setprecision(3) << showpos << par->xx << noshowpos
697 << " +- " << setw(6) << setprecision(3)
698 << sqrt(_QQ(par->index,par->index));
699 newPos->xnt[6] = aprTrp + par->xx;
700 }
701 else if (par->type == bncParam::GALILEO_OFFSET) {
702 strB << "\n offset = " << setw(10) << setprecision(3) << par->xx
703 << " +- " << setw(6) << setprecision(3)
704 << sqrt(_QQ(par->index,par->index));
705 }
706 }
707 strB << '\n';
708 _log += strB.str().c_str();
709 emit newMessage(_log, false);
710
711 // Final Message (both log file and screen)
712 // ----------------------------------------
713 ostringstream strC;
714 strC.setf(ios::fixed);
715 strC << _staID.data() << " PPP "
716 << epoData->tt.timestr(1) << " " << epoData->sizeAll() << " "
717 << setw(14) << setprecision(3) << x() << " +- "
718 << setw(6) << setprecision(3) << sqrt(_QQ(1,1)) << " "
719 << setw(14) << setprecision(3) << y() << " +- "
720 << setw(6) << setprecision(3) << sqrt(_QQ(2,2)) << " "
721 << setw(14) << setprecision(3) << z() << " +- "
722 << setw(6) << setprecision(3) << sqrt(_QQ(3,3));
723
724 // NEU Output
725 // ----------
726 double xyzRef[3];
727
728 if (settings.value("pppRefCrdX").toString() != "" &&
729 settings.value("pppRefCrdY").toString() != "" &&
730 settings.value("pppRefCrdZ").toString() != "") {
731
732 xyzRef[0] = settings.value("pppRefCrdX").toDouble();
733 xyzRef[1] = settings.value("pppRefCrdY").toDouble();
734 xyzRef[2] = settings.value("pppRefCrdZ").toDouble();
735
736 newPos->xnt[0] = x() - xyzRef[0];
737 newPos->xnt[1] = y() - xyzRef[1];
738 newPos->xnt[2] = z() - xyzRef[2];
739
740 double ellRef[3];
741 xyz2ell(xyzRef, ellRef);
742 xyz2neu(ellRef, newPos->xnt, &newPos->xnt[3]);
743
744 strC << " NEU "
745 << setw(8) << setprecision(3) << newPos->xnt[3] << " "
746 << setw(8) << setprecision(3) << newPos->xnt[4] << " "
747 << setw(8) << setprecision(3) << newPos->xnt[5] << endl;
748
749 }
750
751 emit newMessage(QByteArray(strC.str().c_str()), true);
752
753 if (settings.value("pppAverage").toString() == "") {
754 delete newPos;
755 }
756 else {
757
758 _posAverage.push_back(newPos);
759
760 // Time Span for Average Computation
761 // ---------------------------------
762 double tRangeAverage = settings.value("pppAverage").toDouble() * 60.;
763 if (tRangeAverage < 0) {
764 tRangeAverage = 0;
765 }
766 if (tRangeAverage > 86400) {
767 tRangeAverage = 86400;
768 }
769
770 // Compute the Mean
771 // ----------------
772 ColumnVector mean(7); mean = 0.0;
773
774 QMutableVectorIterator<pppPos*> it(_posAverage);
775 while (it.hasNext()) {
776 pppPos* pp = it.next();
777 if ( (epoData->tt - pp->time) >= tRangeAverage ) {
778 delete pp;
779 it.remove();
780 }
781 else {
782 for (int ii = 0; ii < 7; ++ii) {
783 mean[ii] += pp->xnt[ii];
784 }
785 }
786 }
787
788 int nn = _posAverage.size();
789
790 if (nn > 0) {
791
792 mean /= nn;
793
794 // Compute the Deviation
795 // ---------------------
796 ColumnVector std(7); std = 0.0;
797 QVectorIterator<pppPos*> it2(_posAverage);
798 while (it2.hasNext()) {
799 pppPos* pp = it2.next();
800 for (int ii = 0; ii < 7; ++ii) {
801 std[ii] += (pp->xnt[ii] - mean[ii]) * (pp->xnt[ii] - mean[ii]);
802 }
803 }
804 for (int ii = 0; ii < 7; ++ii) {
805 std[ii] = sqrt(std[ii] / nn);
806 }
807
808 if (settings.value("pppRefCrdX").toString() != "" &&
809 settings.value("pppRefCrdY").toString() != "" &&
810 settings.value("pppRefCrdZ").toString() != "") {
811
812 ostringstream strD; strD.setf(ios::fixed);
813 strD << _staID.data() << " AVE-XYZ "
814 << epoData->tt.timestr(1) << " "
815 << setw(13) << setprecision(3) << mean[0] + xyzRef[0] << " +- "
816 << setw(6) << setprecision(3) << std[0] << " "
817 << setw(14) << setprecision(3) << mean[1] + xyzRef[1] << " +- "
818 << setw(6) << setprecision(3) << std[1] << " "
819 << setw(14) << setprecision(3) << mean[2] + xyzRef[2] << " +- "
820 << setw(6) << setprecision(3) << std[2];
821 emit newMessage(QByteArray(strD.str().c_str()), true);
822
823 ostringstream strE; strE.setf(ios::fixed);
824 strE << _staID.data() << " AVE-NEU "
825 << epoData->tt.timestr(1) << " "
826 << setw(13) << setprecision(3) << mean[3] << " +- "
827 << setw(6) << setprecision(3) << std[3] << " "
828 << setw(14) << setprecision(3) << mean[4] << " +- "
829 << setw(6) << setprecision(3) << std[4] << " "
830 << setw(14) << setprecision(3) << mean[5] << " +- "
831 << setw(6) << setprecision(3) << std[5];
832 emit newMessage(QByteArray(strE.str().c_str()), true);
833
834 if ( Qt::CheckState(settings.value("pppEstTropo").toInt()) == Qt::Checked) {
835 ostringstream strF; strF.setf(ios::fixed);
836 strF << _staID.data() << " AVE-TRP "
837 << epoData->tt.timestr(1) << " "
838 << setw(13) << setprecision(3) << mean[6] << " +- "
839 << setw(6) << setprecision(3) << std[6] << endl;
840 emit newMessage(QByteArray(strF.str().c_str()), true);
841 }
842 }
843 }
844 }
845
846 // NMEA Output
847 // -----------
848 double xyz[3];
849 xyz[0] = x();
850 xyz[1] = y();
851 xyz[2] = z();
852 double ell[3];
853 xyz2ell(xyz, ell);
854 double phiDeg = ell[0] * 180 / M_PI;
855 double lamDeg = ell[1] * 180 / M_PI;
856
857 char phiCh = 'N';
858 if (phiDeg < 0) {
859 phiDeg = -phiDeg;
860 phiCh = 'S';
861 }
862 char lamCh = 'E';
863 if (lamDeg < 0) {
864 lamDeg = -lamDeg;
865 lamCh = 'W';
866 }
867
868 string datestr = epoData->tt.datestr(0); // yyyymmdd
869 ostringstream strRMC;
870 strRMC.setf(ios::fixed);
871 strRMC << "GPRMC,"
872 << epoData->tt.timestr(0,0) << ",A,"
873 << setw(2) << setfill('0') << int(phiDeg)
874 << setw(6) << setprecision(3) << setfill('0')
875 << fmod(60*phiDeg,60) << ',' << phiCh << ','
876 << setw(3) << setfill('0') << int(lamDeg)
877 << setw(6) << setprecision(3) << setfill('0')
878 << fmod(60*lamDeg,60) << ',' << lamCh << ",,,"
879 << datestr[6] << datestr[7] << datestr[4] << datestr[5]
880 << datestr[2] << datestr[3] << ",,";
881
882 writeNMEAstr(QString(strRMC.str().c_str()));
883
884 double dop = 2.0; // TODO
885
886 ostringstream strGGA;
887 strGGA.setf(ios::fixed);
888 strGGA << "GPGGA,"
889 << epoData->tt.timestr(0,0) << ','
890 << setw(2) << setfill('0') << int(phiDeg)
891 << setw(10) << setprecision(7) << setfill('0')
892 << fmod(60*phiDeg,60) << ',' << phiCh << ','
893 << setw(3) << setfill('0') << int(lamDeg)
894 << setw(10) << setprecision(7) << setfill('0')
895 << fmod(60*lamDeg,60) << ',' << lamCh
896 << ",1," << setw(2) << setfill('0') << epoData->sizeAll() << ','
897 << setw(3) << setprecision(1) << dop << ','
898 << setprecision(3) << ell[2] << ",M,0.0,M,,";
899
900 writeNMEAstr(QString(strGGA.str().c_str()));
901
902 _lastTimeOK = _time; // remember time of last successful update
903 return success;
904}
905
906// Outlier Detection
907////////////////////////////////////////////////////////////////////////////
908QString bncModel::outlierDetection(int iPhase, const ColumnVector& vv,
909 QMap<QString, t_satData*>& satData) {
910
911 Tracer tracer("bncModel::outlierDetection");
912
913 QString prnGPS;
914 QString prnGlo;
915 double maxResGPS = 0.0;
916 double maxResGlo = 0.0;
917 findMaxRes(vv, satData, prnGPS, prnGlo, maxResGPS, maxResGlo);
918
919 if (iPhase == 1) {
920 if (maxResGlo > MAXRES_PHASE_GLONASS) {
921 _log += "Outlier Phase " + prnGlo + " "
922 + QByteArray::number(maxResGlo, 'f', 3) + "\n";
923 return prnGlo;
924 }
925 else if (maxResGPS > MAXRES_PHASE_GPS) {
926 _log += "Outlier Phase " + prnGPS + " "
927 + QByteArray::number(maxResGPS, 'f', 3) + "\n";
928 return prnGPS;
929 }
930 }
931 else if (iPhase == 0 && maxResGPS > MAXRES_CODE) {
932 _log += "Outlier Code " + prnGPS + " "
933 + QByteArray::number(maxResGPS, 'f', 3) + "\n";
934 return prnGPS;
935 }
936
937 return QString();
938}
939
940//
941////////////////////////////////////////////////////////////////////////////
942void bncModel::writeNMEAstr(const QString& nmStr) {
943
944 Tracer tracer("bncModel::writeNMEAstr");
945
946 unsigned char XOR = 0;
947 for (int ii = 0; ii < nmStr.length(); ii++) {
948 XOR ^= (unsigned char) nmStr[ii].toAscii();
949 }
950
951 QString outStr = '$' + nmStr
952 + QString("*%1\n").arg(int(XOR), 0, 16).toUpper();
953
954 if (_nmeaStream) {
955 *_nmeaStream << outStr;
956 _nmeaStream->flush();
957 }
958
959 emit newNMEAstr(outStr.toAscii());
960}
961
962//
963//////////////////////////////////////////////////////////////////////////////
964void bncModel::kalman(const Matrix& AA, const ColumnVector& ll,
965 const DiagonalMatrix& PP,
966 SymmetricMatrix& QQ, ColumnVector& dx) {
967
968 Tracer tracer("bncModel::kalman");
969
970 int nObs = AA.Nrows();
971 int nPar = AA.Ncols();
972
973 UpperTriangularMatrix SS = Cholesky(QQ).t();
974
975 Matrix SA = SS*AA.t();
976 Matrix SRF(nObs+nPar, nObs+nPar); SRF = 0;
977 for (int ii = 1; ii <= nObs; ++ii) {
978 SRF(ii,ii) = 1.0 / sqrt(PP(ii,ii));
979 }
980
981 SRF.SubMatrix (nObs+1, nObs+nPar, 1, nObs) = SA;
982 SRF.SymSubMatrix(nObs+1, nObs+nPar) = SS;
983
984 UpperTriangularMatrix UU;
985 QRZ(SRF, UU);
986
987 SS = UU.SymSubMatrix(nObs+1, nObs+nPar);
988 UpperTriangularMatrix SH_rt = UU.SymSubMatrix(1, nObs);
989 Matrix YY = UU.SubMatrix(1, nObs, nObs+1, nObs+nPar);
990
991 UpperTriangularMatrix SHi = SH_rt.i();
992
993 Matrix KT = SHi * YY;
994 SymmetricMatrix Hi; Hi << SHi * SHi.t();
995
996 dx = KT.t() * ll;
997 QQ << (SS.t() * SS);
998}
999
1000// Phase Wind-Up Correction
1001///////////////////////////////////////////////////////////////////////////
1002double bncModel::windUp(const QString& prn, const ColumnVector& rSat,
1003 const ColumnVector& rRec) {
1004
1005 Tracer tracer("bncModel::windUp");
1006
1007 double Mjd = _time.mjd() + _time.daysec() / 86400.0;
1008
1009 // First time - initialize to zero
1010 // -------------------------------
1011 if (!_windUpTime.contains(prn)) {
1012 _windUpSum[prn] = 0.0;
1013 }
1014
1015 // Compute the correction for new time
1016 // -----------------------------------
1017 if (!_windUpTime.contains(prn) || _windUpTime[prn] != Mjd) {
1018 _windUpTime[prn] = Mjd;
1019
1020 // Unit Vector GPS Satellite --> Receiver
1021 // --------------------------------------
1022 ColumnVector rho = rRec - rSat;
1023 rho /= rho.norm_Frobenius();
1024
1025 // GPS Satellite unit Vectors sz, sy, sx
1026 // -------------------------------------
1027 ColumnVector sz = -rSat / rSat.norm_Frobenius();
1028
1029 ColumnVector xSun = Sun(Mjd);
1030 xSun /= xSun.norm_Frobenius();
1031
1032 ColumnVector sy = crossproduct(sz, xSun);
1033 ColumnVector sx = crossproduct(sy, sz);
1034
1035 // Effective Dipole of the GPS Satellite Antenna
1036 // ---------------------------------------------
1037 ColumnVector dipSat = sx - rho * DotProduct(rho,sx)
1038 - crossproduct(rho, sy);
1039
1040 // Receiver unit Vectors rx, ry
1041 // ----------------------------
1042 ColumnVector rx(3);
1043 ColumnVector ry(3);
1044
1045 double recEll[3]; xyz2ell(rRec.data(), recEll) ;
1046 double neu[3];
1047
1048 neu[0] = 1.0;
1049 neu[1] = 0.0;
1050 neu[2] = 0.0;
1051 neu2xyz(recEll, neu, rx.data());
1052
1053 neu[0] = 0.0;
1054 neu[1] = -1.0;
1055 neu[2] = 0.0;
1056 neu2xyz(recEll, neu, ry.data());
1057
1058 // Effective Dipole of the Receiver Antenna
1059 // ----------------------------------------
1060 ColumnVector dipRec = rx - rho * DotProduct(rho,rx)
1061 + crossproduct(rho, ry);
1062
1063 // Resulting Effect
1064 // ----------------
1065 double alpha = DotProduct(dipSat,dipRec) /
1066 (dipSat.norm_Frobenius() * dipRec.norm_Frobenius());
1067
1068 if (alpha > 1.0) alpha = 1.0;
1069 if (alpha < -1.0) alpha = -1.0;
1070
1071 double dphi = acos(alpha) / 2.0 / M_PI; // in cycles
1072
1073 if ( DotProduct(rho, crossproduct(dipSat, dipRec)) < 0.0 ) {
1074 dphi = -dphi;
1075 }
1076
1077 _windUpSum[prn] = floor(_windUpSum[prn] - dphi + 0.5) + dphi;
1078 }
1079
1080 return _windUpSum[prn];
1081}
1082
1083//
1084///////////////////////////////////////////////////////////////////////////
1085void bncModel::cmpEle(t_satData* satData) {
1086 Tracer tracer("bncModel::cmpEle");
1087 ColumnVector rr = satData->xx - _xcBanc.Rows(1,3);
1088 double rho = rr.norm_Frobenius();
1089
1090 double neu[3];
1091 xyz2neu(_ellBanc.data(), rr.data(), neu);
1092
1093 satData->eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
1094 if (neu[2] < 0) {
1095 satData->eleSat *= -1.0;
1096 }
1097 satData->azSat = atan2(neu[1], neu[0]);
1098}
1099
1100//
1101///////////////////////////////////////////////////////////////////////////
1102void bncModel::addAmb(t_satData* satData) {
1103 Tracer tracer("bncModel::addAmb");
1104 bool found = false;
1105 for (int iPar = 1; iPar <= _params.size(); iPar++) {
1106 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
1107 _params[iPar-1]->prn == satData->prn) {
1108 found = true;
1109 break;
1110 }
1111 }
1112 if (!found) {
1113 bncParam* par = new bncParam(bncParam::AMB_L3,
1114 _params.size()+1, satData->prn);
1115 _params.push_back(par);
1116 par->xx = satData->L3 - cmpValue(satData, true);
1117 }
1118}
1119
1120//
1121///////////////////////////////////////////////////////////////////////////
1122void bncModel::addObs(int iPhase, unsigned& iObs, t_satData* satData,
1123 Matrix& AA, ColumnVector& ll, DiagonalMatrix& PP) {
1124
1125 Tracer tracer("bncModel::addObs");
1126
1127 const double ELEWGHT = 20.0;
1128 double ellWgtCoef = 1.0;
1129 double eleD = satData->eleSat * 180.0 / M_PI;
1130 if (eleD < ELEWGHT) {
1131 ellWgtCoef = 1.5 - 0.5 / (ELEWGHT - 10.0) * (eleD - 10.0);
1132 }
1133
1134 // Remember Observation Index
1135 // --------------------------
1136 ++iObs;
1137 satData->obsIndex = iObs;
1138
1139 // Phase Observations
1140 // ------------------
1141 if (iPhase == 1) {
1142 ll(iObs) = satData->L3 - cmpValue(satData, true);
1143 double sigL3 = _sigL3;
1144 if (satData->system() == 'R') {
1145 sigL3 *= GLONASS_WEIGHT_FACTOR;
1146 }
1147 PP(iObs,iObs) = 1.0 / (sigL3 * sigL3) / (ellWgtCoef * ellWgtCoef);
1148 for (int iPar = 1; iPar <= _params.size(); iPar++) {
1149 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
1150 _params[iPar-1]->prn == satData->prn) {
1151 ll(iObs) -= _params[iPar-1]->xx;
1152 }
1153 AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
1154 }
1155 }
1156
1157 // Code Observations
1158 // -----------------
1159 else {
1160 ll(iObs) = satData->P3 - cmpValue(satData, false);
1161 PP(iObs,iObs) = 1.0 / (_sigP3 * _sigP3) / (ellWgtCoef * ellWgtCoef);
1162 for (int iPar = 1; iPar <= _params.size(); iPar++) {
1163 AA(iObs, iPar) = _params[iPar-1]->partial(satData, false);
1164 }
1165 }
1166}
1167
1168//
1169///////////////////////////////////////////////////////////////////////////
1170QByteArray bncModel::printRes(int iPhase, const ColumnVector& vv,
1171 const QMap<QString, t_satData*>& satDataMap) {
1172
1173 Tracer tracer("bncModel::printRes");
1174
1175 ostringstream str;
1176 str.setf(ios::fixed);
1177
1178 QMapIterator<QString, t_satData*> it(satDataMap);
1179 while (it.hasNext()) {
1180 it.next();
1181 t_satData* satData = it.value();
1182 if (satData->obsIndex != 0) {
1183 str << _time.timestr(1)
1184 << " RES " << satData->prn.toAscii().data()
1185 << (iPhase ? " L3 " : " P3 ")
1186 << setw(9) << setprecision(4) << vv(satData->obsIndex) << endl;
1187 }
1188 }
1189
1190 return QByteArray(str.str().c_str());
1191}
1192
1193//
1194///////////////////////////////////////////////////////////////////////////
1195void bncModel::findMaxRes(const ColumnVector& vv,
1196 const QMap<QString, t_satData*>& satData,
1197 QString& prnGPS, QString& prnGlo,
1198 double& maxResGPS, double& maxResGlo) {
1199
1200 Tracer tracer("bncModel::findMaxRes");
1201
1202 maxResGPS = 0.0;
1203 maxResGlo = 0.0;
1204
1205 QMapIterator<QString, t_satData*> it(satData);
1206 while (it.hasNext()) {
1207 it.next();
1208 t_satData* satData = it.value();
1209 if (satData->obsIndex != 0) {
1210 QString prn = satData->prn;
1211 if (prn[0] == 'R') {
1212 if (fabs(vv(satData->obsIndex)) > maxResGlo) {
1213 maxResGlo = fabs(vv(satData->obsIndex));
1214 prnGlo = prn;
1215 }
1216 }
1217 else {
1218 if (fabs(vv(satData->obsIndex)) > maxResGPS) {
1219 maxResGPS = fabs(vv(satData->obsIndex));
1220 prnGPS = prn;
1221 }
1222 }
1223 }
1224 }
1225}
1226
1227// Update Step (private - loop over outliers)
1228////////////////////////////////////////////////////////////////////////////
1229t_irc bncModel::update_p(t_epoData* epoData) {
1230
1231 Tracer tracer("bncModel::update_p");
1232
1233 // Save Variance-Covariance Matrix, and Status Vector
1234 // --------------------------------------------------
1235 rememberState(epoData);
1236
1237 QString lastOutlierPrn;
1238
1239 // Try with all satellites, then with all minus one, etc.
1240 // ------------------------------------------------------
1241 while (selectSatellites(lastOutlierPrn, epoData->satData) == success) {
1242
1243 QByteArray strResCode;
1244 QByteArray strResPhase;
1245
1246 // Bancroft Solution
1247 // -----------------
1248 if (cmpBancroft(epoData) != success) {
1249 break;
1250 }
1251
1252 // First update using code observations, then phase observations
1253 // -------------------------------------------------------------
1254 for (int iPhase = 0; iPhase <= (_usePhase ? 1 : 0); iPhase++) {
1255
1256 // Status Prediction
1257 // -----------------
1258 predict(iPhase, epoData);
1259
1260 // Create First-Design Matrix
1261 // --------------------------
1262 unsigned nPar = _params.size();
1263 unsigned nObs = 0;
1264 if (iPhase == 0) {
1265 nObs = epoData->sizeAll() - epoData->sizeSys('R'); // Glonass code not used
1266 }
1267 else {
1268 nObs = epoData->sizeAll();
1269 }
1270
1271 // Prepare first-design Matrix, vector observed-computed
1272 // -----------------------------------------------------
1273 Matrix AA(nObs, nPar); // first design matrix
1274 ColumnVector ll(nObs); // tems observed-computed
1275 DiagonalMatrix PP(nObs); PP = 0.0;
1276
1277 unsigned iObs = 0;
1278 QMapIterator<QString, t_satData*> it(epoData->satData);
1279 while (it.hasNext()) {
1280 it.next();
1281 t_satData* satData = it.value();
1282 if (iPhase == 1 || satData->system() != 'R') {
1283 QString prn = satData->prn;
1284 addObs(iPhase, iObs, satData, AA, ll, PP);
1285 }
1286 }
1287
1288 // Compute Filter Update
1289 // ---------------------
1290 ColumnVector dx;
1291 kalman(AA, ll, PP, _QQ, dx);
1292 ColumnVector vv = ll - AA * dx;
1293
1294 // Print Residuals
1295 // ---------------
1296 if (iPhase == 0) {
1297 strResCode = printRes(iPhase, vv, epoData->satData);
1298 }
1299 else {
1300 strResPhase = printRes(iPhase, vv, epoData->satData);
1301 }
1302
1303 // Check the residuals
1304 // -------------------
1305 lastOutlierPrn = outlierDetection(iPhase, vv, epoData->satData);
1306
1307 // No Outlier Detected
1308 // -------------------
1309 if (lastOutlierPrn.isEmpty()) {
1310
1311 QVectorIterator<bncParam*> itPar(_params);
1312 while (itPar.hasNext()) {
1313 bncParam* par = itPar.next();
1314 par->xx += dx(par->index);
1315 }
1316
1317 if (!_usePhase || iPhase == 1) {
1318 if (_outlierGPS.size() > 0 || _outlierGlo.size() > 0) {
1319 _log += "Neglected PRNs: ";
1320 if (!_outlierGPS.isEmpty()) {
1321 _log += _outlierGPS.last() + ' ';
1322 }
1323 QStringListIterator itGlo(_outlierGlo);
1324 while (itGlo.hasNext()) {
1325 QString prn = itGlo.next();
1326 _log += prn + ' ';
1327 }
1328 }
1329 _log += '\n';
1330
1331 _log += strResCode + strResPhase;
1332
1333 return success;
1334 }
1335 }
1336
1337 // Outlier Found
1338 // -------------
1339 else {
1340 restoreState(epoData);
1341 break;
1342 }
1343
1344 } // for iPhase
1345
1346 } // while selectSatellites
1347
1348 restoreState(epoData);
1349 return failure;
1350}
1351
1352// Remeber Original State Vector and Variance-Covariance Matrix
1353////////////////////////////////////////////////////////////////////////////
1354void bncModel::rememberState(t_epoData* epoData) {
1355
1356 _QQ_sav = _QQ;
1357
1358 QVectorIterator<bncParam*> itSav(_params_sav);
1359 while (itSav.hasNext()) {
1360 bncParam* par = itSav.next();
1361 delete par;
1362 }
1363 _params_sav.clear();
1364
1365 QVectorIterator<bncParam*> it(_params);
1366 while (it.hasNext()) {
1367 bncParam* par = it.next();
1368 _params_sav.push_back(new bncParam(*par));
1369 }
1370
1371 _epoData_sav->deepCopy(epoData);
1372}
1373
1374// Restore Original State Vector and Variance-Covariance Matrix
1375////////////////////////////////////////////////////////////////////////////
1376void bncModel::restoreState(t_epoData* epoData) {
1377
1378 _QQ = _QQ_sav;
1379
1380 QVectorIterator<bncParam*> it(_params);
1381 while (it.hasNext()) {
1382 bncParam* par = it.next();
1383 delete par;
1384 }
1385 _params.clear();
1386
1387 QVectorIterator<bncParam*> itSav(_params_sav);
1388 while (itSav.hasNext()) {
1389 bncParam* par = itSav.next();
1390 _params.push_back(new bncParam(*par));
1391 }
1392
1393 epoData->deepCopy(_epoData_sav);
1394}
1395
1396//
1397////////////////////////////////////////////////////////////////////////////
1398t_irc bncModel::selectSatellites(const QString& lastOutlierPrn,
1399 QMap<QString, t_satData*>& satData) {
1400
1401 // First Call
1402 // ----------
1403 if (lastOutlierPrn.isEmpty()) {
1404 _outlierGPS.clear();
1405 _outlierGlo.clear();
1406 return success;
1407 }
1408
1409 // Second and next trials
1410 // ----------------------
1411 else {
1412
1413 if (lastOutlierPrn[0] == 'R') {
1414 _outlierGlo << lastOutlierPrn;
1415 }
1416
1417 // Remove all Glonass Outliers
1418 // ---------------------------
1419 QStringListIterator it(_outlierGlo);
1420 while (it.hasNext()) {
1421 QString prn = it.next();
1422 if (satData.contains(prn)) {
1423 delete satData.take(prn);
1424 }
1425 }
1426
1427 if (lastOutlierPrn[0] == 'R') {
1428 _outlierGPS.clear();
1429 return success;
1430 }
1431
1432 // GPS Outlier appeared for the first time - try to delete it
1433 // ----------------------------------------------------------
1434 if (_outlierGPS.indexOf(lastOutlierPrn) == -1) {
1435 _outlierGPS << lastOutlierPrn;
1436 if (satData.contains(lastOutlierPrn)) {
1437 delete satData.take(lastOutlierPrn);
1438 }
1439 return success;
1440 }
1441
1442 }
1443
1444 return failure;
1445}
Note: See TracBrowser for help on using the repository browser.