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

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