source: ntrip/trunk/BNC/bncmodel.cpp@ 3330

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