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

Last change on this file since 3285 was 3281, checked in by mervart, 13 years ago
File size: 38.5 KB
RevLine 
[2057]1// Part of BNC, a utility for retrieving decoding and
2// converting GNSS data streams from NTRIP broadcasters.
3//
4// Copyright (C) 2007
5// German Federal Agency for Cartography and Geodesy (BKG)
6// http://www.bkg.bund.de
7// Czech Technical University Prague, Department of Geodesy
8// http://www.fsv.cvut.cz
9//
10// Email: euref-ip@bkg.bund.de
11//
12// This program is free software; you can redistribute it and/or
13// modify it under the terms of the GNU General Public License
14// as published by the Free Software Foundation, version 2.
15//
16// This program is distributed in the hope that it will be useful,
17// but WITHOUT ANY WARRANTY; without even the implied warranty of
18// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19// GNU General Public License for more details.
20//
21// You should have received a copy of the GNU General Public License
22// along with this program; if not, write to the Free Software
23// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24
25/* -------------------------------------------------------------------------
26 * BKG NTRIP Client
27 * -------------------------------------------------------------------------
28 *
29 * Class: bncParam, bncModel
30 *
31 * Purpose: Model for PPP
32 *
33 * Author: L. Mervart
34 *
35 * Created: 01-Dec-2009
36 *
37 * Changes:
38 *
39 * -----------------------------------------------------------------------*/
40
41#include <iomanip>
[2063]42#include <cmath>
[2060]43#include <newmatio.h>
[2113]44#include <sstream>
[2057]45
46#include "bncmodel.h"
[2113]47#include "bncapp.h"
[2058]48#include "bncpppclient.h"
49#include "bancroft.h"
[2063]50#include "bncutils.h"
[2077]51#include "bncsettings.h"
[2580]52#include "bnctides.h"
[2881]53#include "bncantex.h"
[2057]54
55using namespace std;
56
[2243]57const unsigned MINOBS = 4;
[2287]58const double MINELE_GPS = 10.0 * M_PI / 180.0;
59const double MINELE_GLO = 10.0 * M_PI / 180.0;
[2780]60const double MINELE_GAL = 10.0 * M_PI / 180.0;
[2243]61const double MAXRES_CODE_GPS = 10.0;
62const double MAXRES_PHASE_GPS = 0.10;
[2539]63const double MAXRES_PHASE_GLO = 0.05;
[2784]64const double MAXRES_CODE_GAL = 10.0;
65const double MAXRES_PHASE_GAL = 0.10;
[2070]66
[2057]67// Constructor
68////////////////////////////////////////////////////////////////////////////
[2080]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;
[2473]76
[2057]77}
78
79// Destructor
80////////////////////////////////////////////////////////////////////////////
81bncParam::~bncParam() {
82}
83
[2060]84// Partial
85////////////////////////////////////////////////////////////////////////////
[2239]86double bncParam::partial(t_satData* satData, bool phase) {
87
88 // Coordinates
89 // -----------
[2060]90 if (type == CRD_X) {
[2109]91 return (xx - satData->xx(1)) / satData->rho;
[2060]92 }
93 else if (type == CRD_Y) {
[2109]94 return (xx - satData->xx(2)) / satData->rho;
[2060]95 }
96 else if (type == CRD_Z) {
[2109]97 return (xx - satData->xx(3)) / satData->rho;
[2060]98 }
[2239]99
100 // Receiver Clocks
101 // ---------------
[2265]102 else if (type == RECCLK) {
103 return 1.0;
[2060]104 }
[2239]105
106 // Troposphere
107 // -----------
[2084]108 else if (type == TROPO) {
109 return 1.0 / sin(satData->eleSat);
110 }
[2239]111
[2782]112 // Galileo Offset
113 // --------------
114 else if (type == GALILEO_OFFSET) {
115 if (satData->prn[0] == 'E') {
116 return 1.0;
117 }
118 else {
119 return 0.0;
120 }
121 }
122
[2239]123 // Ambiguities
124 // -----------
[2080]125 else if (type == AMB_L3) {
[2239]126 if (phase && satData->prn == prn) {
[2080]127 return 1.0;
128 }
129 else {
130 return 0.0;
131 }
132 }
[2239]133
134 // Default return
135 // --------------
[2060]136 return 0.0;
137}
138
[2058]139// Constructor
140////////////////////////////////////////////////////////////////////////////
[2113]141bncModel::bncModel(QByteArray staID) {
[2084]142
[2113]143 _staID = staID;
144
[3107]145 connect(this, SIGNAL(newMessage(QByteArray,bool)),
146 ((bncApp*)qApp), SLOT(slotMessage(const QByteArray,bool)));
147
[2648]148 bncSettings settings;
149
[2720]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()) {
[2741]158 _sigL3 = settings.value("pppSigmaPhase").toDouble();
[2720]159 }
[2648]160
[2720]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 }
[2782]179 _sigClk0 = 1000.0;
180 _sigAmb0 = 1000.0;
181 _sigGalileoOffset0 = 1000.0;
[2784]182 _sigGalileoOffsetP = 0.0;
[2648]183
[2720]184 // Quick-Start Mode
185 // ----------------
186 _quickStart = 0;
[2726]187 if (settings.value("pppRefCrdX").toString() != "" &&
188 settings.value("pppRefCrdY").toString() != "" &&
189 settings.value("pppRefCrdZ").toString() != "" &&
[2720]190 !settings.value("pppQuickStart").toString().isEmpty()) {
[2745]191 _quickStart = settings.value("pppQuickStart").toDouble();
[2720]192 }
193
[3107]194 // Several options
195 // ---------------
[2084]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
[3107]206 _useGalileo = false;
[2799]207 if ( Qt::CheckState(settings.value("pppGalileo").toInt()) == Qt::Checked) {
[3107]208 _useGalileo = true;
[2782]209 }
[2073]210
[2125]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 }
[2881]230
[3107]231 // Antenna Name, ANTEX File
232 // ------------------------
[2896]233 _antex = 0;
[2881]234 QString antexFileName = settings.value("pppAntex").toString();
235 if (!antexFileName.isEmpty()) {
236 _antex = new bncAntex();
[2883]237 if (_antex->readFile(antexFileName) != success) {
[2938]238 emit newMessage("wrong ANTEX file", true);
[2887]239 delete _antex;
240 _antex = 0;
[2883]241 }
[2938]242 else {
243 _antennaName = settings.value("pppAntenna").toString();
244 }
[2881]245 }
[3107]246
247 // Bancroft Coordinates
248 // --------------------
249 _xcBanc.ReSize(4); _xcBanc = 0.0;
250 _ellBanc.ReSize(3); _ellBanc = 0.0;
[2058]251}
252
[3108]253// Destructor
[3107]254////////////////////////////////////////////////////////////////////////////
[3108]255bncModel::~bncModel() {
256 delete _nmeaStream;
257 delete _nmeaFile;
258 for (int ii = 0; ii < _posAverage.size(); ++ii) {
259 delete _posAverage[ii];
260 }
261 delete _antex;
262 for (int iPar = 1; iPar <= _params.size(); iPar++) {
263 delete _params[iPar-1];
264 }
265}
266
267// Reset Parameters and Variance-Covariance Matrix
268////////////////////////////////////////////////////////////////////////////
[3107]269void bncModel::reset() {
270
271 for (int iPar = 1; iPar <= _params.size(); iPar++) {
272 delete _params[iPar-1];
273 }
274 _params.clear();
275
276 int nextPar = 0;
277 _params.push_back(new bncParam(bncParam::CRD_X, ++nextPar, ""));
278 _params.push_back(new bncParam(bncParam::CRD_Y, ++nextPar, ""));
279 _params.push_back(new bncParam(bncParam::CRD_Z, ++nextPar, ""));
280 _params.push_back(new bncParam(bncParam::RECCLK, ++nextPar, ""));
281 if (_estTropo) {
282 _params.push_back(new bncParam(bncParam::TROPO, ++nextPar, ""));
283 }
284 if (_useGalileo) {
285 _params.push_back(new bncParam(bncParam::GALILEO_OFFSET, ++nextPar, ""));
286 }
287
288 _QQ.ReSize(_params.size());
289 _QQ = 0.0;
290 for (int iPar = 1; iPar <= _params.size(); iPar++) {
291 bncParam* pp = _params[iPar-1];
292 pp->xx = 0.0;
293 if (pp->isCrd()) {
294 _QQ(iPar,iPar) = _sigCrd0 * _sigCrd0;
295 }
296 else if (pp->type == bncParam::RECCLK) {
297 _QQ(iPar,iPar) = _sigClk0 * _sigClk0;
298 }
299 else if (pp->type == bncParam::TROPO) {
300 _QQ(iPar,iPar) = _sigTrp0 * _sigTrp0;
301 }
302 else if (pp->type == bncParam::GALILEO_OFFSET) {
303 _QQ(iPar,iPar) = _sigGalileoOffset0 * _sigGalileoOffset0;
304 }
305 }
306}
307
[2058]308// Bancroft Solution
309////////////////////////////////////////////////////////////////////////////
310t_irc bncModel::cmpBancroft(t_epoData* epoData) {
311
[2231]312 if (epoData->sizeGPS() < MINOBS) {
[2547]313 _log += "bncModel::cmpBancroft: not enough data\n";
[2058]314 return failure;
315 }
316
[2231]317 Matrix BB(epoData->sizeGPS(), 4);
[2058]318
[2231]319 QMapIterator<QString, t_satData*> it(epoData->satDataGPS);
[2791]320 int iObsBanc = 0;
[2058]321 while (it.hasNext()) {
[2791]322 ++iObsBanc;
[2058]323 it.next();
324 QString prn = it.key();
325 t_satData* satData = it.value();
[2791]326 BB(iObsBanc, 1) = satData->xx(1);
327 BB(iObsBanc, 2) = satData->xx(2);
328 BB(iObsBanc, 3) = satData->xx(3);
329 BB(iObsBanc, 4) = satData->P3 + satData->clk;
[2058]330 }
331
332 bancroft(BB, _xcBanc);
333
[2064]334 // Ellipsoidal Coordinates
335 // ------------------------
336 xyz2ell(_xcBanc.data(), _ellBanc.data());
[2063]337
[2064]338 // Compute Satellite Elevations
339 // ----------------------------
[2231]340 QMutableMapIterator<QString, t_satData*> iGPS(epoData->satDataGPS);
341 while (iGPS.hasNext()) {
342 iGPS.next();
343 t_satData* satData = iGPS.value();
[2789]344 cmpEle(satData);
[2287]345 if (satData->eleSat < MINELE_GPS) {
[2070]346 delete satData;
[2231]347 iGPS.remove();
[2070]348 }
[2064]349 }
350
[2231]351 QMutableMapIterator<QString, t_satData*> iGlo(epoData->satDataGlo);
352 while (iGlo.hasNext()) {
353 iGlo.next();
354 t_satData* satData = iGlo.value();
[2789]355 cmpEle(satData);
[2287]356 if (satData->eleSat < MINELE_GLO) {
[2231]357 delete satData;
358 iGlo.remove();
359 }
360 }
361
[2780]362 QMutableMapIterator<QString, t_satData*> iGal(epoData->satDataGal);
363 while (iGal.hasNext()) {
364 iGal.next();
365 t_satData* satData = iGal.value();
[2789]366 cmpEle(satData);
[2780]367 if (satData->eleSat < MINELE_GAL) {
368 delete satData;
369 iGal.remove();
370 }
371 }
372
[2058]373 return success;
374}
[2060]375
376// Computed Value
377////////////////////////////////////////////////////////////////////////////
[2583]378double bncModel::cmpValue(t_satData* satData, bool phase) {
[2060]379
[2073]380 ColumnVector xRec(3);
381 xRec(1) = x();
382 xRec(2) = y();
383 xRec(3) = z();
[2060]384
[2073]385 double rho0 = (satData->xx - xRec).norm_Frobenius();
[2060]386 double dPhi = t_CST::omega * rho0 / t_CST::c;
387
[2073]388 xRec(1) = x() * cos(dPhi) - y() * sin(dPhi);
389 xRec(2) = y() * cos(dPhi) + x() * sin(dPhi);
390 xRec(3) = z();
391
[2580]392 tides(_time, xRec);
393
[2060]394 satData->rho = (satData->xx - xRec).norm_Frobenius();
395
[2084]396 double tropDelay = delay_saast(satData->eleSat) +
397 trp() / sin(satData->eleSat);
[2060]398
[2583]399 double wind = 0.0;
400 if (phase) {
401 wind = windUp(satData->prn, satData->xx, xRec) * satData->lambda3;
402 }
403
[2783]404 double offset = 0.0;
405 if (satData->prn[0] == 'E') {
406 offset = Galileo_offset();
407 }
408
[2894]409 double phaseCenter = 0.0;
[2938]410 if (_antex) {
411 bool found;
412 phaseCenter = _antex->pco(_antennaName, satData->eleSat, found);
413 if (!found) {
414 emit newMessage("ANTEX: antenna >"
415 + _antennaName.toAscii() + "< not found", true);
416 }
[2894]417 }
418
419 return satData->rho + phaseCenter + clk()
420 + offset - satData->clk + tropDelay + wind;
[2060]421}
422
[2063]423// Tropospheric Model (Saastamoinen)
424////////////////////////////////////////////////////////////////////////////
[2065]425double bncModel::delay_saast(double Ele) {
[2063]426
[2769]427 double xyz[3];
428 xyz[0] = x();
429 xyz[1] = y();
430 xyz[2] = z();
431 double ell[3];
432 xyz2ell(xyz, ell);
433 double height = ell[2];
[2063]434
[2064]435 double pp = 1013.25 * pow(1.0 - 2.26e-5 * height, 5.225);
436 double TT = 18.0 - height * 0.0065 + 273.15;
437 double hh = 50.0 * exp(-6.396e-4 * height);
[2063]438 double ee = hh / 100.0 * exp(-37.2465 + 0.213166*TT - 0.000256908*TT*TT);
439
[2064]440 double h_km = height / 1000.0;
[2063]441
442 if (h_km < 0.0) h_km = 0.0;
443 if (h_km > 5.0) h_km = 5.0;
444 int ii = int(h_km + 1);
445 double href = ii - 1;
446
447 double bCor[6];
448 bCor[0] = 1.156;
449 bCor[1] = 1.006;
450 bCor[2] = 0.874;
451 bCor[3] = 0.757;
452 bCor[4] = 0.654;
453 bCor[5] = 0.563;
454
455 double BB = bCor[ii-1] + (bCor[ii]-bCor[ii-1]) * (h_km - href);
456
457 double zen = M_PI/2.0 - Ele;
458
459 return (0.002277/cos(zen)) * (pp + ((1255.0/TT)+0.05)*ee - BB*(tan(zen)*tan(zen)));
460}
461
[2073]462// Prediction Step of the Filter
463////////////////////////////////////////////////////////////////////////////
[2080]464void bncModel::predict(t_epoData* epoData) {
[2073]465
[2648]466 bncSettings settings;
[2244]467
[3106]468 _time = epoData->tt; // current epoch time
469
[3118]470 _maxSolGap = settings.value("pppMaxSolGap").toDouble();
471
[2648]472 bool firstCrd = false;
[3118]473 if (!_lastTimeOK.valid() || (_maxSolGap > 0 && _time - _lastTimeOK > _maxSolGap)) {
[2648]474 firstCrd = true;
[2874]475 _startTime = epoData->tt;
[3107]476 reset();
[2648]477 }
478
[2726]479 // Use different white noise for Quick-Start mode
[2720]480 // ----------------------------------------------
481 double sigCrdP_used = _sigCrdP;
[2874]482 if ( _quickStart > 0.0 && _quickStart > (epoData->tt - _startTime) ) {
[2720]483 sigCrdP_used = 0.0;
[2648]484 }
485
[2244]486 // Predict Parameter values, add white noise
487 // -----------------------------------------
488 for (int iPar = 1; iPar <= _params.size(); iPar++) {
489 bncParam* pp = _params[iPar-1];
490
491 // Coordinates
492 // -----------
493 if (pp->type == bncParam::CRD_X) {
[2720]494 if (firstCrd) {
[2726]495 if (settings.value("pppRefCrdX").toString() != "" &&
496 settings.value("pppRefCrdY").toString() != "" &&
497 settings.value("pppRefCrdZ").toString() != "") {
[2648]498 pp->xx = settings.value("pppRefCrdX").toDouble();
499 }
500 else {
501 pp->xx = _xcBanc(1);
502 }
[2244]503 }
[2720]504 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
[2244]505 }
506 else if (pp->type == bncParam::CRD_Y) {
[2720]507 if (firstCrd) {
[2726]508 if (settings.value("pppRefCrdX").toString() != "" &&
509 settings.value("pppRefCrdY").toString() != "" &&
510 settings.value("pppRefCrdZ").toString() != "") {
[2648]511 pp->xx = settings.value("pppRefCrdY").toDouble();
512 }
513 else {
514 pp->xx = _xcBanc(2);
515 }
[2244]516 }
[2720]517 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
[2244]518 }
519 else if (pp->type == bncParam::CRD_Z) {
[2720]520 if (firstCrd) {
[2726]521 if (settings.value("pppRefCrdX").toString() != "" &&
522 settings.value("pppRefCrdY").toString() != "" &&
523 settings.value("pppRefCrdZ").toString() != "") {
[2648]524 pp->xx = settings.value("pppRefCrdZ").toDouble();
525 }
526 else {
527 pp->xx = _xcBanc(3);
528 }
[2244]529 }
[2720]530 _QQ(iPar,iPar) += sigCrdP_used * sigCrdP_used;
[2244]531 }
532
533 // Receiver Clocks
534 // ---------------
[2265]535 else if (pp->type == bncParam::RECCLK) {
[2244]536 pp->xx = _xcBanc(4);
537 for (int jj = 1; jj <= _params.size(); jj++) {
538 _QQ(iPar, jj) = 0.0;
539 }
[2720]540 _QQ(iPar,iPar) = _sigClk0 * _sigClk0;
[2244]541 }
542
543 // Tropospheric Delay
544 // ------------------
545 else if (pp->type == bncParam::TROPO) {
[2720]546 _QQ(iPar,iPar) += _sigTrpP * _sigTrpP;
[2244]547 }
[2782]548
549 // Galileo Offset
550 // --------------
551 else if (pp->type == bncParam::GALILEO_OFFSET) {
552 _QQ(iPar,iPar) += _sigGalileoOffsetP * _sigGalileoOffsetP;
553 }
[2244]554 }
555
556 // Add New Ambiguities if necessary
557 // --------------------------------
[2083]558 if (_usePhase) {
[2080]559
[2083]560 // Make a copy of QQ and xx, set parameter indices
561 // -----------------------------------------------
562 SymmetricMatrix QQ_old = _QQ;
563
564 for (int iPar = 1; iPar <= _params.size(); iPar++) {
565 _params[iPar-1]->index_old = _params[iPar-1]->index;
566 _params[iPar-1]->index = 0;
567 }
568
569 // Remove Ambiguity Parameters without observations
570 // ------------------------------------------------
571 int iPar = 0;
572 QMutableVectorIterator<bncParam*> it(_params);
573 while (it.hasNext()) {
574 bncParam* par = it.next();
575 bool removed = false;
576 if (par->type == bncParam::AMB_L3) {
[2231]577 if (epoData->satDataGPS.find(par->prn) == epoData->satDataGPS.end() &&
[2780]578 epoData->satDataGlo.find(par->prn) == epoData->satDataGlo.end() &&
579 epoData->satDataGal.find(par->prn) == epoData->satDataGal.end() ) {
[2083]580 removed = true;
581 delete par;
582 it.remove();
583 }
[2080]584 }
[2083]585 if (! removed) {
586 ++iPar;
587 par->index = iPar;
588 }
[2080]589 }
[2083]590
591 // Add new ambiguity parameters
592 // ----------------------------
[2231]593 QMapIterator<QString, t_satData*> iGPS(epoData->satDataGPS);
594 while (iGPS.hasNext()) {
595 iGPS.next();
[2244]596 t_satData* satData = iGPS.value();
[2789]597 addAmb(satData);
[2080]598 }
[2231]599
600 QMapIterator<QString, t_satData*> iGlo(epoData->satDataGlo);
601 while (iGlo.hasNext()) {
602 iGlo.next();
[2233]603 t_satData* satData = iGlo.value();
[2789]604 addAmb(satData);
[2231]605 }
[2780]606
607 QMapIterator<QString, t_satData*> iGal(epoData->satDataGal);
608 while (iGal.hasNext()) {
609 iGal.next();
610 t_satData* satData = iGal.value();
[2789]611 addAmb(satData);
[2780]612 }
[2083]613
614 int nPar = _params.size();
615 _QQ.ReSize(nPar); _QQ = 0.0;
616 for (int i1 = 1; i1 <= nPar; i1++) {
617 bncParam* p1 = _params[i1-1];
618 if (p1->index_old != 0) {
619 _QQ(p1->index, p1->index) = QQ_old(p1->index_old, p1->index_old);
620 for (int i2 = 1; i2 <= nPar; i2++) {
621 bncParam* p2 = _params[i2-1];
622 if (p2->index_old != 0) {
623 _QQ(p1->index, p2->index) = QQ_old(p1->index_old, p2->index_old);
624 }
[2080]625 }
626 }
627 }
[2083]628
629 for (int ii = 1; ii <= nPar; ii++) {
630 bncParam* par = _params[ii-1];
631 if (par->index_old == 0) {
[2720]632 _QQ(par->index, par->index) = _sigAmb0 * _sigAmb0;
[2083]633 }
634 par->index_old = par->index;
[2080]635 }
636 }
[2073]637}
638
[2060]639// Update Step of the Filter (currently just a single-epoch solution)
640////////////////////////////////////////////////////////////////////////////
641t_irc bncModel::update(t_epoData* epoData) {
642
[2473]643 bncSettings settings;
644
[2248]645 _log.clear();
[2124]646
[2827]647 if (settings.value("pppSPP").toString() == "PPP") {
648 _log += "Precise Point Positioning of Epoch "
649 + QByteArray(_time.timestr(1).c_str()) +
650 "\n---------------------------------------------------------------\n";
651 }
652 else {
653 _log += "Single Point Positioning of Epoch "
654 + QByteArray(_time.timestr(1).c_str()) +
[2547]655 "\n--------------------------------------------------------------\n";
[2827]656 }
[2547]657
[2112]658 SymmetricMatrix QQsav;
[2109]659 ColumnVector dx;
[2112]660 ColumnVector vv;
[2073]661
[2113]662 // Loop over all outliers
663 // ----------------------
[2108]664 do {
665
666 // Bancroft Solution
667 // -----------------
668 if (cmpBancroft(epoData) != success) {
[2124]669 emit newMessage(_log, false);
[2108]670 return failure;
671 }
[2080]672
[2108]673 // Status Prediction
674 // -----------------
675 predict(epoData);
676
[2109]677 // Create First-Design Matrix
678 // --------------------------
[2108]679 unsigned nPar = _params.size();
[2231]680 unsigned nObs = 0;
681 if (_usePhase) {
[2780]682 nObs = 2 * (epoData->sizeGPS() + epoData->sizeGal()) + epoData->sizeGlo();
[2231]683 }
684 else {
[2780]685 nObs = epoData->sizeGPS() + epoData->sizeGal(); // Glonass code not used
[2231]686 }
[2108]687
[2540]688 if (nObs < nPar) {
[2547]689 _log += "bncModel::update: nObs < nPar\n";
[2540]690 emit newMessage(_log, false);
691 return failure;
692 }
693
[2108]694 Matrix AA(nObs, nPar); // first design matrix
695 ColumnVector ll(nObs); // tems observed-computed
[2283]696 DiagonalMatrix PP(nObs); PP = 0.0;
[2108]697
698 unsigned iObs = 0;
[2231]699
700 // GPS code and (optionally) phase observations
701 // --------------------------------------------
702 QMapIterator<QString, t_satData*> itGPS(epoData->satDataGPS);
703 while (itGPS.hasNext()) {
704 itGPS.next();
705 t_satData* satData = itGPS.value();
[2790]706 addObs(iObs, satData, AA, ll, PP);
[2080]707 }
[2231]708
709 // Glonass phase observations
710 // --------------------------
[2790]711 QMapIterator<QString, t_satData*> itGlo(epoData->satDataGlo);
712 while (itGlo.hasNext()) {
713 itGlo.next();
714 t_satData* satData = itGlo.value();
715 addObs(iObs, satData, AA, ll, PP);
[2231]716 }
717
[2780]718 // Galileo code and (optionally) phase observations
719 // ------------------------------------------------
720 QMapIterator<QString, t_satData*> itGal(epoData->satDataGal);
721 while (itGal.hasNext()) {
722 itGal.next();
723 t_satData* satData = itGal.value();
[2790]724 addObs(iObs, satData, AA, ll, PP);
[2780]725 }
726
[2112]727 // Compute Filter Update
[2108]728 // ---------------------
[2112]729 QQsav = _QQ;
730
[2283]731 kalman(AA, ll, PP, _QQ, dx);
732
733 vv = ll - AA * dx;
734
[2791]735 // Print Residuals
736 // ---------------
737 if (true) {
738 ostringstream str;
739 str.setf(ios::fixed);
[2245]740
[2791]741 QMapIterator<QString, t_satData*> itGPS(epoData->satDataGPS);
742 while (itGPS.hasNext()) {
743 itGPS.next();
744 t_satData* satData = itGPS.value();
745 printRes(vv, str, satData);
[2246]746 }
[2791]747 QMapIterator<QString, t_satData*> itGlo(epoData->satDataGlo);
748 while (itGlo.hasNext()) {
749 itGlo.next();
750 t_satData* satData = itGlo.value();
751 printRes(vv, str, satData);
[2265]752 }
[2791]753 QMapIterator<QString, t_satData*> itGal(epoData->satDataGal);
754 while (itGal.hasNext()) {
755 itGal.next();
756 t_satData* satData = itGal.value();
757 printRes(vv, str, satData);
[2246]758 }
[2791]759 _log += str.str().c_str();
[2265]760 }
[2246]761
[2231]762 } while (outlierDetection(QQsav, vv, epoData->satDataGPS,
[2780]763 epoData->satDataGlo, epoData->satDataGal) != 0);
[2111]764
[2670]765 // Remember the Epoch-specific Results for the computation of means
766 // ----------------------------------------------------------------
767 pppPos* newPos = new pppPos;
768 newPos->time = epoData->tt;
769
[2109]770 // Set Solution Vector
771 // -------------------
[2265]772 ostringstream strB;
773 strB.setf(ios::fixed);
[2073]774 QVectorIterator<bncParam*> itPar(_params);
[2060]775 while (itPar.hasNext()) {
776 bncParam* par = itPar.next();
[2109]777 par->xx += dx(par->index);
[2265]778
779 if (par->type == bncParam::RECCLK) {
[2798]780 strB << "\n clk = " << setw(10) << setprecision(3) << par->xx
[2124]781 << " +- " << setw(6) << setprecision(3)
782 << sqrt(_QQ(par->index,par->index));
783 }
784 else if (par->type == bncParam::AMB_L3) {
[2265]785 strB << "\n amb " << par->prn.toAscii().data() << " = "
[2798]786 << setw(10) << setprecision(3) << par->xx
[2124]787 << " +- " << setw(6) << setprecision(3)
788 << sqrt(_QQ(par->index,par->index));
789 }
[2212]790 else if (par->type == bncParam::TROPO) {
[2670]791 double aprTrp = delay_saast(M_PI/2.0);
[2547]792 strB << "\n trp = " << par->prn.toAscii().data()
[2670]793 << setw(7) << setprecision(3) << aprTrp << " "
[2213]794 << setw(6) << setprecision(3) << showpos << par->xx << noshowpos
[2212]795 << " +- " << setw(6) << setprecision(3)
796 << sqrt(_QQ(par->index,par->index));
[2670]797 newPos->xnt[6] = aprTrp + par->xx;
[2212]798 }
[2782]799 else if (par->type == bncParam::GALILEO_OFFSET) {
[2798]800 strB << "\n offset = " << setw(10) << setprecision(3) << par->xx
[2782]801 << " +- " << setw(6) << setprecision(3)
802 << sqrt(_QQ(par->index,par->index));
803 }
[2060]804 }
[2265]805 strB << '\n';
[2547]806 _log += strB.str().c_str();
807 emit newMessage(_log, false);
[2060]808
[2547]809 // Final Message (both log file and screen)
810 // ----------------------------------------
811 ostringstream strC;
812 strC.setf(ios::fixed);
813 strC << _staID.data() << " PPP "
[2599]814 << epoData->tt.timestr(1) << " " << epoData->sizeAll() << " "
[2231]815 << setw(14) << setprecision(3) << x() << " +- "
816 << setw(6) << setprecision(3) << sqrt(_QQ(1,1)) << " "
817 << setw(14) << setprecision(3) << y() << " +- "
818 << setw(6) << setprecision(3) << sqrt(_QQ(2,2)) << " "
819 << setw(14) << setprecision(3) << z() << " +- "
[2124]820 << setw(6) << setprecision(3) << sqrt(_QQ(3,3));
[2113]821
[2370]822 // NEU Output
823 // ----------
[2862]824 double xyzRef[3];
825
[2726]826 if (settings.value("pppRefCrdX").toString() != "" &&
827 settings.value("pppRefCrdY").toString() != "" &&
828 settings.value("pppRefCrdZ").toString() != "") {
[2649]829
[2370]830 xyzRef[0] = settings.value("pppRefCrdX").toDouble();
831 xyzRef[1] = settings.value("pppRefCrdY").toDouble();
832 xyzRef[2] = settings.value("pppRefCrdZ").toDouble();
[2649]833
[2670]834 newPos->xnt[0] = x() - xyzRef[0];
835 newPos->xnt[1] = y() - xyzRef[1];
836 newPos->xnt[2] = z() - xyzRef[2];
[2649]837
838 double ellRef[3];
[2370]839 xyz2ell(xyzRef, ellRef);
[2670]840 xyz2neu(ellRef, newPos->xnt, &newPos->xnt[3]);
[2649]841
[2547]842 strC << " NEU "
[2670]843 << setw(8) << setprecision(3) << newPos->xnt[3] << " "
844 << setw(8) << setprecision(3) << newPos->xnt[4] << " "
[2797]845 << setw(8) << setprecision(3) << newPos->xnt[5] << endl;
[2649]846
[2370]847 }
848
[2547]849 emit newMessage(QByteArray(strC.str().c_str()), true);
850
[2671]851 if (settings.value("pppAverage").toString() == "") {
852 delete newPos;
853 }
854 else {
855
856 _posAverage.push_back(newPos);
[2599]857
[2648]858 // Time Span for Average Computation
859 // ---------------------------------
860 double tRangeAverage = settings.value("pppAverage").toDouble() * 60.;
861 if (tRangeAverage < 0) {
862 tRangeAverage = 0;
863 }
864 if (tRangeAverage > 86400) {
865 tRangeAverage = 86400;
866 }
[2599]867
[2648]868 // Compute the Mean
869 // ----------------
[2670]870 ColumnVector mean(7); mean = 0.0;
[2648]871
[2599]872 QMutableVectorIterator<pppPos*> it(_posAverage);
873 while (it.hasNext()) {
874 pppPos* pp = it.next();
[2648]875 if ( (epoData->tt - pp->time) >= tRangeAverage ) {
[2599]876 delete pp;
877 it.remove();
878 }
[2648]879 else {
[2670]880 for (int ii = 0; ii < 7; ++ii) {
881 mean[ii] += pp->xnt[ii];
[2649]882 }
[2648]883 }
[2599]884 }
[2648]885
886 int nn = _posAverage.size();
887
[2649]888 if (nn > 0) {
[2648]889
[2649]890 mean /= nn;
891
892 // Compute the Deviation
893 // ---------------------
[2670]894 ColumnVector std(7); std = 0.0;
[2649]895 QVectorIterator<pppPos*> it2(_posAverage);
896 while (it2.hasNext()) {
897 pppPos* pp = it2.next();
[2670]898 for (int ii = 0; ii < 7; ++ii) {
899 std[ii] += (pp->xnt[ii] - mean[ii]) * (pp->xnt[ii] - mean[ii]);
[2649]900 }
901 }
[2670]902 for (int ii = 0; ii < 7; ++ii) {
[2649]903 std[ii] = sqrt(std[ii] / nn);
904 }
[3169]905
906 if (settings.value("pppRefCrdX").toString() != "" &&
907 settings.value("pppRefCrdY").toString() != "" &&
908 settings.value("pppRefCrdZ").toString() != "") {
[2649]909
[3169]910 ostringstream strD; strD.setf(ios::fixed);
911 strD << _staID.data() << " AVE-XYZ "
912 << epoData->tt.timestr(1) << " "
913 << setw(13) << setprecision(3) << mean[0] + xyzRef[0] << " +- "
914 << setw(6) << setprecision(3) << std[0] << " "
915 << setw(14) << setprecision(3) << mean[1] + xyzRef[1] << " +- "
916 << setw(6) << setprecision(3) << std[1] << " "
917 << setw(14) << setprecision(3) << mean[2] + xyzRef[2] << " +- "
918 << setw(6) << setprecision(3) << std[2];
919 emit newMessage(QByteArray(strD.str().c_str()), true);
[2649]920
[3169]921 ostringstream strE; strE.setf(ios::fixed);
922 strE << _staID.data() << " AVE-NEU "
923 << epoData->tt.timestr(1) << " "
924 << setw(13) << setprecision(3) << mean[3] << " +- "
925 << setw(6) << setprecision(3) << std[3] << " "
926 << setw(14) << setprecision(3) << mean[4] << " +- "
927 << setw(6) << setprecision(3) << std[4] << " "
928 << setw(14) << setprecision(3) << mean[5] << " +- "
929 << setw(6) << setprecision(3) << std[5];
930 emit newMessage(QByteArray(strE.str().c_str()), true);
[2649]931
[3169]932 if ( Qt::CheckState(settings.value("pppEstTropo").toInt()) == Qt::Checked) {
933 ostringstream strF; strF.setf(ios::fixed);
934 strF << _staID.data() << " AVE-TRP "
935 << epoData->tt.timestr(1) << " "
936 << setw(13) << setprecision(3) << mean[6] << " +- "
937 << setw(6) << setprecision(3) << std[6] << endl;
938 emit newMessage(QByteArray(strF.str().c_str()), true);
939 }
[2726]940 }
[2599]941 }
942 }
943
[2131]944 // NMEA Output
945 // -----------
[2181]946 double xyz[3];
947 xyz[0] = x();
948 xyz[1] = y();
949 xyz[2] = z();
950 double ell[3];
951 xyz2ell(xyz, ell);
952 double phiDeg = ell[0] * 180 / M_PI;
953 double lamDeg = ell[1] * 180 / M_PI;
[2132]954
[2181]955 char phiCh = 'N';
956 if (phiDeg < 0) {
957 phiDeg = -phiDeg;
958 phiCh = 'S';
959 }
960 char lamCh = 'E';
961 if (lamDeg < 0) {
[2563]962 lamDeg = -lamDeg;
963 lamCh = 'W';
[2181]964 }
[2132]965
[2566]966 string datestr = epoData->tt.datestr(0); // yyyymmdd
967 ostringstream strRMC;
968 strRMC.setf(ios::fixed);
969 strRMC << "GPRMC,"
970 << epoData->tt.timestr(0,0) << ",A,"
971 << setw(2) << setfill('0') << int(phiDeg)
972 << setw(6) << setprecision(3) << setfill('0')
973 << fmod(60*phiDeg,60) << ',' << phiCh << ','
974 << setw(3) << setfill('0') << int(lamDeg)
975 << setw(6) << setprecision(3) << setfill('0')
976 << fmod(60*lamDeg,60) << ',' << lamCh << ",,,"
[2569]977 << datestr[6] << datestr[7] << datestr[4] << datestr[5]
978 << datestr[2] << datestr[3] << ",,";
[2566]979
980 writeNMEAstr(QString(strRMC.str().c_str()));
981
[2181]982 double dop = 2.0; // TODO
[2133]983
[2566]984 ostringstream strGGA;
985 strGGA.setf(ios::fixed);
986 strGGA << "GPGGA,"
987 << epoData->tt.timestr(0,0) << ','
988 << setw(2) << setfill('0') << int(phiDeg)
989 << setw(10) << setprecision(7) << setfill('0')
990 << fmod(60*phiDeg,60) << ',' << phiCh << ','
991 << setw(3) << setfill('0') << int(lamDeg)
992 << setw(10) << setprecision(7) << setfill('0')
993 << fmod(60*lamDeg,60) << ',' << lamCh
994 << ",1," << setw(2) << setfill('0') << epoData->sizeAll() << ','
995 << setw(3) << setprecision(1) << dop << ','
[2569]996 << setprecision(3) << ell[2] << ",M,0.0,M,,";
[2181]997
[2566]998 writeNMEAstr(QString(strGGA.str().c_str()));
[2131]999
[3106]1000 _lastTimeOK = _time; // remember time of last successful update
[2060]1001 return success;
1002}
[2112]1003
1004// Outlier Detection
1005////////////////////////////////////////////////////////////////////////////
1006int bncModel::outlierDetection(const SymmetricMatrix& QQsav,
1007 const ColumnVector& vv,
[2231]1008 QMap<QString, t_satData*>& satDataGPS,
[2780]1009 QMap<QString, t_satData*>& satDataGlo,
1010 QMap<QString, t_satData*>& satDataGal) {
[2112]1011
[2792]1012 QString prnCode;
1013 QString prnPhase;
1014 double maxResCode = 0.0;
1015 double maxResPhase = 0.0;
[2231]1016
[2792]1017 QString prnRemoved;
1018 double maxRes;
[2112]1019
[2793]1020 int irc = 0;
1021
[3281]1022 // Check GPS Code
1023 // --------------
[2793]1024 if (irc == 0) {
[3281]1025 findMaxRes(vv,satDataGPS, prnCode, maxResCode, prnPhase, maxResPhase);
1026 if (maxResCode > MAXRES_CODE_GPS) {
1027 satDataGPS.remove(prnCode);
1028 prnRemoved = prnCode;
1029 maxRes = maxResCode;
1030 irc = 1;
1031 }
1032 }
1033
1034 // Check Galileo Code
1035 // ------------------
1036 if (irc == 0) {
1037 findMaxRes(vv,satDataGal, prnCode, maxResCode, prnPhase, maxResPhase);
1038 if (maxResCode > MAXRES_CODE_GAL) {
1039 satDataGal.remove(prnCode);
1040 prnRemoved = prnCode;
1041 maxRes = maxResCode;
1042 irc = 1;
1043 }
1044 }
1045
1046 // Check Glonass Phase
1047 // -------------------
1048 if (irc == 0) {
[2793]1049 findMaxRes(vv,satDataGlo, prnCode, maxResCode, prnPhase, maxResPhase);
1050 if (maxResPhase > MAXRES_PHASE_GLO) {
1051 satDataGlo.remove(prnPhase);
1052 prnRemoved = prnPhase;
1053 maxRes = maxResPhase;
1054 irc = 1;
1055 }
[2792]1056 }
[2112]1057
[3281]1058 // Check Galileo Phase
1059 // -------------------
[2793]1060 if (irc == 0) {
[2792]1061 findMaxRes(vv,satDataGal, prnCode, maxResCode, prnPhase, maxResPhase);
1062 if (maxResPhase > MAXRES_PHASE_GAL) {
1063 satDataGal.remove(prnPhase);
1064 prnRemoved = prnPhase;
1065 maxRes = maxResPhase;
[2793]1066 irc = 1;
[2112]1067 }
[2793]1068 }
[2112]1069
[3281]1070 // Check GPS Phase
1071 // ---------------
[2793]1072 if (irc == 0) {
1073 findMaxRes(vv,satDataGPS, prnCode, maxResCode, prnPhase, maxResPhase);
1074 if (maxResPhase > MAXRES_PHASE_GPS) {
1075 satDataGPS.remove(prnPhase);
1076 prnRemoved = prnPhase;
1077 maxRes = maxResPhase;
1078 irc = 1;
[2780]1079 }
1080 }
1081
[2793]1082 if (irc != 0) {
[2792]1083 _log += "Outlier " + prnRemoved.toAscii() + " "
1084 + QByteArray::number(maxRes, 'f', 3) + "\n";
[2248]1085 _QQ = QQsav;
1086 }
[2793]1087
1088 return irc;
[2112]1089}
[2130]1090
1091//
1092////////////////////////////////////////////////////////////////////////////
1093void bncModel::writeNMEAstr(const QString& nmStr) {
1094
1095 unsigned char XOR = 0;
1096 for (int ii = 0; ii < nmStr.length(); ii++) {
1097 XOR ^= (unsigned char) nmStr[ii].toAscii();
1098 }
[2181]1099
1100 QString outStr = '$' + nmStr
1101 + QString("*%1\n").arg(int(XOR), 0, 16).toUpper();
[2130]1102
[2178]1103 if (_nmeaStream) {
[2181]1104 *_nmeaStream << outStr;
[2178]1105 _nmeaStream->flush();
1106 }
[2130]1107
[2181]1108 emit newNMEAstr(outStr.toAscii());
[2130]1109}
[2283]1110
1111////
1112//////////////////////////////////////////////////////////////////////////////
1113void bncModel::kalman(const Matrix& AA, const ColumnVector& ll,
1114 const DiagonalMatrix& PP,
1115 SymmetricMatrix& QQ, ColumnVector& dx) {
1116
1117 int nObs = AA.Nrows();
1118 int nPar = AA.Ncols();
1119
1120 UpperTriangularMatrix SS = Cholesky(QQ).t();
1121
1122 Matrix SA = SS*AA.t();
1123 Matrix SRF(nObs+nPar, nObs+nPar); SRF = 0;
1124 for (int ii = 1; ii <= nObs; ++ii) {
1125 SRF(ii,ii) = 1.0 / sqrt(PP(ii,ii));
1126 }
1127
1128 SRF.SubMatrix (nObs+1, nObs+nPar, 1, nObs) = SA;
1129 SRF.SymSubMatrix(nObs+1, nObs+nPar) = SS;
1130
1131 UpperTriangularMatrix UU;
1132 QRZ(SRF, UU);
1133
1134 SS = UU.SymSubMatrix(nObs+1, nObs+nPar);
1135 UpperTriangularMatrix SH_rt = UU.SymSubMatrix(1, nObs);
1136 Matrix YY = UU.SubMatrix(1, nObs, nObs+1, nObs+nPar);
1137
1138 UpperTriangularMatrix SHi = SH_rt.i();
1139
1140 Matrix KT = SHi * YY;
1141 SymmetricMatrix Hi; Hi << SHi * SHi.t();
1142
1143 dx = KT.t() * ll;
1144 QQ << (SS.t() * SS);
1145}
[2582]1146
1147// Phase Wind-Up Correction
1148///////////////////////////////////////////////////////////////////////////
1149double bncModel::windUp(const QString& prn, const ColumnVector& rSat,
1150 const ColumnVector& rRec) {
1151
1152 double Mjd = _time.mjd() + _time.daysec() / 86400.0;
1153
1154 // First time - initialize to zero
1155 // -------------------------------
1156 if (!_windUpTime.contains(prn)) {
1157 _windUpSum[prn] = 0.0;
1158 }
1159
1160 // Compute the correction for new time
1161 // -----------------------------------
[2942]1162 if (!_windUpTime.contains(prn) || _windUpTime[prn] != Mjd) {
[2582]1163 _windUpTime[prn] = Mjd;
1164
1165 // Unit Vector GPS Satellite --> Receiver
1166 // --------------------------------------
1167 ColumnVector rho = rRec - rSat;
1168 rho /= rho.norm_Frobenius();
1169
1170 // GPS Satellite unit Vectors sz, sy, sx
1171 // -------------------------------------
1172 ColumnVector sz = -rSat / rSat.norm_Frobenius();
1173
1174 ColumnVector xSun = Sun(Mjd);
1175 xSun /= xSun.norm_Frobenius();
1176
1177 ColumnVector sy = crossproduct(sz, xSun);
1178 ColumnVector sx = crossproduct(sy, sz);
1179
1180 // Effective Dipole of the GPS Satellite Antenna
1181 // ---------------------------------------------
1182 ColumnVector dipSat = sx - rho * DotProduct(rho,sx)
1183 - crossproduct(rho, sy);
1184
1185 // Receiver unit Vectors rx, ry
1186 // ----------------------------
1187 ColumnVector rx(3);
1188 ColumnVector ry(3);
1189
1190 double recEll[3]; xyz2ell(rRec.data(), recEll) ;
1191 double neu[3];
1192
1193 neu[0] = 1.0;
1194 neu[1] = 0.0;
1195 neu[2] = 0.0;
1196 neu2xyz(recEll, neu, rx.data());
1197
1198 neu[0] = 0.0;
1199 neu[1] = -1.0;
1200 neu[2] = 0.0;
1201 neu2xyz(recEll, neu, ry.data());
1202
1203 // Effective Dipole of the Receiver Antenna
1204 // ----------------------------------------
1205 ColumnVector dipRec = rx - rho * DotProduct(rho,rx)
1206 + crossproduct(rho, ry);
1207
1208 // Resulting Effect
1209 // ----------------
1210 double alpha = DotProduct(dipSat,dipRec) /
1211 (dipSat.norm_Frobenius() * dipRec.norm_Frobenius());
1212
1213 if (alpha > 1.0) alpha = 1.0;
1214 if (alpha < -1.0) alpha = -1.0;
1215
1216 double dphi = acos(alpha) / 2.0 / M_PI; // in cycles
1217
1218 if ( DotProduct(rho, crossproduct(dipSat, dipRec)) < 0.0 ) {
1219 dphi = -dphi;
1220 }
1221
1222 _windUpSum[prn] = floor(_windUpSum[prn] - dphi + 0.5) + dphi;
1223 }
1224
1225 return _windUpSum[prn];
1226}
[2789]1227
1228//
1229///////////////////////////////////////////////////////////////////////////
1230void bncModel::cmpEle(t_satData* satData) {
1231 ColumnVector rr = satData->xx - _xcBanc.Rows(1,3);
1232 double rho = rr.norm_Frobenius();
1233
1234 double neu[3];
1235 xyz2neu(_ellBanc.data(), rr.data(), neu);
1236
1237 satData->eleSat = acos( sqrt(neu[0]*neu[0] + neu[1]*neu[1]) / rho );
1238 if (neu[2] < 0) {
1239 satData->eleSat *= -1.0;
1240 }
1241 satData->azSat = atan2(neu[1], neu[0]);
1242}
1243
1244//
1245///////////////////////////////////////////////////////////////////////////
1246void bncModel::addAmb(t_satData* satData) {
1247 bool found = false;
1248 for (int iPar = 1; iPar <= _params.size(); iPar++) {
1249 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
1250 _params[iPar-1]->prn == satData->prn) {
1251 found = true;
1252 break;
1253 }
1254 }
1255 if (!found) {
1256 bncParam* par = new bncParam(bncParam::AMB_L3,
1257 _params.size()+1, satData->prn);
1258 _params.push_back(par);
1259 par->xx = satData->L3 - cmpValue(satData, true);
1260 }
1261}
[2790]1262
1263//
1264///////////////////////////////////////////////////////////////////////////
1265void bncModel::addObs(unsigned& iObs, t_satData* satData,
1266 Matrix& AA, ColumnVector& ll, DiagonalMatrix& PP) {
1267
[2791]1268 // Code Observations
1269 // -----------------
[2790]1270 if (satData->system() != 'R') {
1271 ++iObs;
1272 ll(iObs) = satData->P3 - cmpValue(satData, false);
1273 PP(iObs,iObs) = 1.0 / (_sigP3 * _sigP3);
1274 for (int iPar = 1; iPar <= _params.size(); iPar++) {
1275 AA(iObs, iPar) = _params[iPar-1]->partial(satData, false);
1276 }
[2791]1277 satData->indexCode = iObs;
[2790]1278 }
1279
[2791]1280 // Phase Observations
1281 // ------------------
[2790]1282 if (_usePhase) {
1283 ++iObs;
1284 ll(iObs) = satData->L3 - cmpValue(satData, true);
1285 PP(iObs,iObs) = 1.0 / (_sigL3 * _sigL3);
1286 for (int iPar = 1; iPar <= _params.size(); iPar++) {
1287 if (_params[iPar-1]->type == bncParam::AMB_L3 &&
1288 _params[iPar-1]->prn == satData->prn) {
1289 ll(iObs) -= _params[iPar-1]->xx;
1290 }
1291 AA(iObs, iPar) = _params[iPar-1]->partial(satData, true);
1292 }
[2791]1293 satData->indexPhase = iObs;
[2790]1294 }
1295}
[2791]1296
1297//
1298///////////////////////////////////////////////////////////////////////////
1299void bncModel::printRes(const ColumnVector& vv,
1300 ostringstream& str, t_satData* satData) {
[2800]1301 if (satData->indexPhase) {
[2797]1302 str << _time.timestr(1)
[2800]1303 << " RES " << satData->prn.toAscii().data() << " L3 "
1304 << setw(9) << setprecision(4) << vv(satData->indexPhase);
1305 if (satData->indexCode) {
1306 str << " P3 " << setw(9) << setprecision(4) << vv(satData->indexCode);
[2797]1307 }
1308 str << endl;
[2791]1309 }
1310}
[2792]1311
1312//
1313///////////////////////////////////////////////////////////////////////////
1314void bncModel::findMaxRes(const ColumnVector& vv,
1315 const QMap<QString, t_satData*>& satData,
1316 QString& prnCode, double& maxResCode,
1317 QString& prnPhase, double& maxResPhase) {
1318 maxResCode = 0.0;
1319 maxResPhase = 0.0;
1320
1321 QMapIterator<QString, t_satData*> it(satData);
1322 while (it.hasNext()) {
1323 it.next();
1324 t_satData* satData = it.value();
1325 if (satData->indexCode) {
1326 if (fabs(vv(satData->indexCode)) > maxResCode) {
1327 maxResCode = fabs(vv(satData->indexCode));
1328 prnCode = satData->prn;
1329 }
1330 }
1331 if (satData->indexPhase) {
1332 if (fabs(vv(satData->indexPhase)) > maxResPhase) {
1333 maxResPhase = fabs(vv(satData->indexPhase));
1334 prnPhase = satData->prn;
1335 }
1336 }
1337 }
1338}
1339
Note: See TracBrowser for help on using the repository browser.