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

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