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

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