source: ntrip/trunk/BNC/src/bncmodel.cpp@ 4801

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