source: ntrip/trunk/BNC/src/PPP/pppClient.cpp@ 10002

Last change on this file since 10002 was 10002, checked in by stuerze, 13 months ago

minor changes

  • Property svn:keywords set to Author Date Id Rev URL;svn:eol-style=native
  • Property svn:mime-type set to text/plain
File size: 25.5 KB
RevLine 
[7237]1/* -------------------------------------------------------------------------
2 * BKG NTRIP Client
3 * -------------------------------------------------------------------------
4 *
5 * Class: t_pppClient
6 *
7 * Purpose: PPP Client processing starts here
8 *
9 * Author: L. Mervart
10 *
11 * Created: 29-Jul-2014
12 *
[7271]13 * Changes:
[7237]14 *
15 * -----------------------------------------------------------------------*/
16
17#include <QThreadStorage>
18
19#include <iostream>
20#include <iomanip>
[8451]21#include <cmath>
[7237]22#include <string.h>
23#include <stdexcept>
24
25#include "pppClient.h"
26#include "pppEphPool.h"
27#include "pppObsPool.h"
28#include "bncconst.h"
29#include "bncutils.h"
30#include "pppStation.h"
31#include "bncantex.h"
32#include "pppFilter.h"
33
34using namespace BNC_PPP;
35using namespace std;
36
37// Global variable holding thread-specific pointers
38//////////////////////////////////////////////////////////////////////////////
39QThreadStorage<t_pppClient*> CLIENTS;
40
41// Static function returning thread-specific pointer
42//////////////////////////////////////////////////////////////////////////////
43t_pppClient* t_pppClient::instance() {
44 return CLIENTS.localData();
45}
46
47// Constructor
48//////////////////////////////////////////////////////////////////////////////
49t_pppClient::t_pppClient(const t_pppOptions* opt) {
50 _output = 0;
51 _opt = new t_pppOptions(*opt);
52 _log = new ostringstream();
53 _ephPool = new t_pppEphPool();
54 _obsPool = new t_pppObsPool();
55 _staRover = new t_pppStation();
[8905]56 _filter = new t_pppFilter(_obsPool);
[7237]57 _tides = new t_tides();
[8905]58 _antex = 0;
[7237]59 if (!_opt->_antexFileName.empty()) {
60 _antex = new bncAntex(_opt->_antexFileName.c_str());
61 }
[8905]62 if (!_opt->_blqFileName.empty()) {
63 if (_tides->readBlqFile(_opt->_blqFileName.c_str()) == success) {
64 //_tides->printAllBlqSets();
65 }
[7237]66 }
[7996]67
[8910]68 if (_opt->_refSatRequired) {
[8912]69 for (unsigned iSys = 0; iSys < _opt->systems().size(); iSys++) {
[9508]70 char sys = _opt->systems()[iSys];
71 _refSatMap[sys] = new t_pppRefSat();
[8905]72 }
[7972]73 }
[9419]74
[10002]75 _offGG = 0.0;
[7237]76 CLIENTS.setLocalData(this); // CLIENTS takes ownership over "this"
77}
78
79// Destructor
80//////////////////////////////////////////////////////////////////////////////
81t_pppClient::~t_pppClient() {
82 delete _log;
83 delete _opt;
[8905]84 delete _filter;
[7237]85 delete _ephPool;
86 delete _obsPool;
87 delete _staRover;
[7866]88 if (_antex) {
89 delete _antex;
90 }
[7237]91 delete _tides;
92 clearObs();
[9508]93 QMapIterator<char, t_pppRefSat*> it(_refSatMap);
94 while (it.hasNext()) {
95 it.next();
96 delete it.value();
97 }
98 _refSatMap.clear();
[7237]99}
100
[7271]101//
[7237]102//////////////////////////////////////////////////////////////////////////////
103void t_pppClient::putEphemeris(const t_eph* eph) {
104 const t_ephGPS* ephGPS = dynamic_cast<const t_ephGPS*>(eph);
105 const t_ephGlo* ephGlo = dynamic_cast<const t_ephGlo*>(eph);
106 const t_ephGal* ephGal = dynamic_cast<const t_ephGal*>(eph);
[7271]107 const t_ephBDS* ephBDS = dynamic_cast<const t_ephBDS*>(eph);
[7237]108 if (ephGPS) {
109 _ephPool->putEphemeris(new t_ephGPS(*ephGPS));
110 }
111 else if (ephGlo) {
112 _ephPool->putEphemeris(new t_ephGlo(*ephGlo));
113 }
114 else if (ephGal) {
115 _ephPool->putEphemeris(new t_ephGal(*ephGal));
116 }
[7271]117 else if (ephBDS) {
118 _ephPool->putEphemeris(new t_ephBDS(*ephBDS));
119 }
[7237]120}
121
122//
123//////////////////////////////////////////////////////////////////////////////
124void t_pppClient::putTec(const t_vTec* vTec) {
[7248]125 _obsPool->putTec(new t_vTec(*vTec));
[7237]126}
127
[7271]128//
[7237]129//////////////////////////////////////////////////////////////////////////////
130void t_pppClient::putOrbCorrections(const vector<t_orbCorr*>& corr) {
131 for (unsigned ii = 0; ii < corr.size(); ii++) {
132 _ephPool->putOrbCorrection(new t_orbCorr(*corr[ii]));
133 }
134}
135
[7271]136//
[7237]137//////////////////////////////////////////////////////////////////////////////
138void t_pppClient::putClkCorrections(const vector<t_clkCorr*>& corr) {
139 for (unsigned ii = 0; ii < corr.size(); ii++) {
140 _ephPool->putClkCorrection(new t_clkCorr(*corr[ii]));
141 }
142}
143
[7271]144//
[7237]145//////////////////////////////////////////////////////////////////////////////
146void t_pppClient::putCodeBiases(const vector<t_satCodeBias*>& biases) {
147 for (unsigned ii = 0; ii < biases.size(); ii++) {
148 _obsPool->putCodeBias(new t_satCodeBias(*biases[ii]));
149 }
150}
151
152//
153//////////////////////////////////////////////////////////////////////////////
[7288]154void t_pppClient::putPhaseBiases(const vector<t_satPhaseBias*>& biases) {
155 for (unsigned ii = 0; ii < biases.size(); ii++) {
156 _obsPool->putPhaseBias(new t_satPhaseBias(*biases[ii]));
157 }
158}
159
160//
161//////////////////////////////////////////////////////////////////////////////
[7237]162t_irc t_pppClient::prepareObs(const vector<t_satObs*>& satObs,
163 vector<t_pppSatObs*>& obsVector, bncTime& epoTime) {
[8905]164
[7271]165 // Default
[7237]166 // -------
167 epoTime.reset();
[8956]168 clearObs();
[7237]169
170 // Create vector of valid observations
171 // -----------------------------------
172 for (unsigned ii = 0; ii < satObs.size(); ii++) {
[9567]173 char sys = satObs[ii]->_prn.system();
174 if (_opt->useSystem(sys)) {
[7237]175 t_pppSatObs* pppSatObs = new t_pppSatObs(*satObs[ii]);
176 if (pppSatObs->isValid()) {
177 obsVector.push_back(pppSatObs);
178 }
179 else {
180 delete pppSatObs;
181 }
182 }
183 }
184
185 // Check whether data are synchronized, compute epoTime
186 // ----------------------------------------------------
187 const double MAXSYNC = 0.05; // synchronization limit
188 double meanDt = 0.0;
189 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
190 const t_pppSatObs* satObs = obsVector.at(ii);
191 if (epoTime.undef()) {
192 epoTime = satObs->time();
193 }
194 else {
195 double dt = satObs->time() - epoTime;
196 if (fabs(dt) > MAXSYNC) {
197 LOG << "t_pppClient::prepareObs asynchronous observations" << endl;
198 return failure;
199 }
200 meanDt += dt;
201 }
202 }
203
204 if (obsVector.size() > 0) {
205 epoTime += meanDt / obsVector.size();
206 }
207
208 return success;
209}
210
[8905]211//
212//////////////////////////////////////////////////////////////////////////////
213bool t_pppClient::preparePseudoObs(std::vector<t_pppSatObs*>& obsVector) {
214
215 bool pseudoObsIono = false;
216
[8912]217 if (_opt->_pseudoObsIono) {
[8905]218 vector<t_pppSatObs*>::iterator it = obsVector.begin();
219 while (it != obsVector.end()) {
220 t_pppSatObs* satObs = *it;
[9508]221 char sys = satObs->prn().system();
222 t_pppRefSat* refSat = _refSatMap[sys];
[8905]223 double stecRef = refSat->stecValue();
224 if (stecRef && !satObs->isReference()) {
225 pseudoObsIono = true;
226 satObs->setPseudoObsIono(t_frequency::G1, stecRef);
227 }
228 it++;
229 }
230 }
[9538]231
[8961]232/*
233 vector<t_pppSatObs*>::iterator it = obsVector.begin();
234 while (it != obsVector.end()) {
235 t_pppSatObs* satObs = *it;
236 satObs->printObsMinusComputed();
237 it++;
238 }
239*/
[8905]240 return pseudoObsIono;
241}
242
[9560]243//
244//////////////////////////////////////////////////////////////////////////////
245void t_pppClient::useObsWithCodeBiasesOnly(std::vector<t_pppSatObs*>& obsVector) {
246
247 vector<t_pppSatObs*>::iterator it = obsVector.begin();
248 while (it != obsVector.end()) {
249 t_pppSatObs* pppSatObs = *it;
250 char sys = pppSatObs->prn().system();
251 bool codeBiasesAvailable = false;
252 t_frequency::type fType1 = t_lc::toFreq(sys,t_lc::c1);
253 t_frequency::type fType2 = t_lc::toFreq(sys,t_lc::c2);
254 if (pppSatObs->getCodeBias(fType1) &&
255 pppSatObs->getCodeBias(fType2)) {
256 codeBiasesAvailable = true;
257 }
258 if (codeBiasesAvailable) {
259 ++it;
260 }
261 else {
262 it = obsVector.erase(it);
263 delete pppSatObs;
264 }
265 }
266
267}
268
269
[7237]270// Compute the Bancroft position, check for blunders
271//////////////////////////////////////////////////////////////////////////////
[7271]272t_irc t_pppClient::cmpBancroft(const bncTime& epoTime,
[7237]273 vector<t_pppSatObs*>& obsVector,
274 ColumnVector& xyzc, bool print) {
275
276 t_lc::type tLC = t_lc::dummy;
277
278 while (true) {
279 Matrix BB(obsVector.size(), 4);
280 int iObs = -1;
281 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
282 const t_pppSatObs* satObs = obsVector.at(ii);
[8034]283 if (tLC == t_lc::dummy) {
284 if (satObs->isValid(t_lc::cIF)) {
285 tLC = t_lc::cIF;
[7237]286 }
[8034]287 else if (satObs->isValid(t_lc::c1)) {
288 tLC = t_lc::c1;
[7237]289 }
[8445]290 else if (satObs->isValid(t_lc::c2)) {
[8034]291 tLC = t_lc::c2;
292 }
[7237]293 }
[9600]294 if ( satObs->isValid(tLC) &&
295 (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle) ) {
[8034]296 ++iObs;
297 BB[iObs][0] = satObs->xc()[0];
298 BB[iObs][1] = satObs->xc()[1];
299 BB[iObs][2] = satObs->xc()[2];
300 BB[iObs][3] = satObs->obsValue(tLC) - satObs->cmpValueForBanc(tLC);
301 }
[7237]302 }
[8912]303 if (iObs + 1 < _opt->_minObs) {
[9943]304 LOG << "t_pppClient::cmpBancroft not enough observations: " << iObs + 1 << endl;
[7237]305 return failure;
306 }
307 BB = BB.Rows(1,iObs+1);
[9600]308 if (bancroft(BB, xyzc) != success) {
309 return failure;
310 }
[7237]311
312 xyzc[3] /= t_CST::c;
313
314 // Check Blunders
315 // --------------
316 const double BLUNDER = 100.0;
317 double maxRes = 0.0;
318 unsigned maxResIndex = 0;
319 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
320 const t_pppSatObs* satObs = obsVector.at(ii);
[8905]321 if (satObs->isValid() &&
[8912]322 (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle) ) {
[7237]323 ColumnVector rr = satObs->xc().Rows(1,3) - xyzc.Rows(1,3);
[8905]324 double res = rr.NormFrobenius() - satObs->obsValue(tLC)
[8453]325 - (satObs->xc()[3] - xyzc[3]) * t_CST::c;
[9600]326 if (fabs(res) > maxRes) {
327 maxRes = fabs(res);
[7237]328 maxResIndex = ii;
329 }
330 }
331 }
[9600]332 if (maxRes < BLUNDER) {
[9386]333 if (print && _numEpoProcessing == 1) {
[7237]334 LOG.setf(ios::fixed);
[9783]335 LOG << "\nPPP of Epoch ";
336 if (!_epoTimeRover.undef()) LOG << string(_epoTimeRover);
337 LOG << "\n---------------------------------------------------------------\n";
[7237]338 LOG << string(epoTime) << " BANCROFT:" << ' '
339 << setw(14) << setprecision(3) << xyzc[0] << ' '
340 << setw(14) << setprecision(3) << xyzc[1] << ' '
341 << setw(14) << setprecision(3) << xyzc[2] << ' '
342 << setw(14) << setprecision(3) << xyzc[3] * t_CST::c << endl << endl;
343 }
344 break;
345 }
346 else {
347 t_pppSatObs* satObs = obsVector.at(maxResIndex);
348 LOG << "t_pppClient::cmpBancroft outlier " << satObs->prn().toString()
349 << " " << maxRes << endl;
350 delete satObs;
351 obsVector.erase(obsVector.begin() + maxResIndex);
352 }
353 }
354
355 return success;
356}
[10002]357// Compute A Priori GPS-Glonass Offset
358//////////////////////////////////////////////////////////////////////////////
359double t_pppClient::cmpOffGG(vector<t_pppSatObs*>& obsVector) {
[7237]360
[10002]361 t_lc::type tLC = t_lc::dummy;
362 double offGG = 0.0;
363
364 if (OPT->useSystem('R')) {
365
366 while (obsVector.size() > 0) {
367 offGG = 0.0;
368 double maxRes = 0.0;
369 int maxResIndex = -1;
370 t_prn maxResPrn;
371 unsigned nObs = 0;
372 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
373 t_pppSatObs* satObs = obsVector.at(ii);
374 if (satObs->prn().system() == 'R') {
375 if (tLC == t_lc::dummy) {
376 tLC = satObs->isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
377 }
378 if (satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= OPT->_minEle)) {
379 double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC);
380 ++nObs;
381 offGG += ll;
382 if (fabs(ll) > fabs(maxRes)) {
383 maxRes = ll;
384 maxResIndex = ii;
385 maxResPrn = satObs->prn();
386 }
387 }
388 }
389 }
390
391 if (nObs > 0) {
392 offGG = offGG / nObs;
393 }
394 else {
395 offGG = 0.0;
396 }
397
398 if (fabs(maxRes) > 1000.0) {
399 LOG << "t_pppClient::cmpOffGG outlier " << maxResPrn.toString() << " " << maxRes << endl;
400 obsVector.erase(obsVector.begin() + maxResIndex);
401 }
402 else {
403 break;
404 }
405 }
406 }
407
408 return offGG;
409}
410
[7271]411//
[7237]412//////////////////////////////////////////////////////////////////////////////
413void t_pppClient::initOutput(t_output* output) {
414 _output = output;
415 _output->_numSat = 0;
[7927]416 _output->_hDop = 0.0;
[7237]417 _output->_error = false;
418}
419
[7271]420//
[7237]421//////////////////////////////////////////////////////////////////////////////
422void t_pppClient::clearObs() {
423 for (unsigned ii = 0; ii < _obsRover.size(); ii++) {
424 delete _obsRover.at(ii);
425 }
426 _obsRover.clear();
427}
428
[7271]429//
[7237]430//////////////////////////////////////////////////////////////////////////////
[9585]431void t_pppClient::finish(t_irc irc, int ind) {
[9783]432#ifdef BNC_DEBUG_PPP
[9585]433 LOG << "t_pppClient::finish(" << ind << "): " << irc << endl;
[9783]434#endif
[9585]435
[7237]436 clearObs();
437
438 _output->_epoTime = _epoTimeRover;
439
440 if (irc == success) {
441 _output->_xyzRover[0] = _staRover->xyzApr()[0] + _filter->x()[0];
442 _output->_xyzRover[1] = _staRover->xyzApr()[1] + _filter->x()[1];
443 _output->_xyzRover[2] = _staRover->xyzApr()[2] + _filter->x()[2];
444
445 xyz2neu(_staRover->ellApr().data(), _filter->x().data(), _output->_neu);
446
447 copy(&_filter->Q().data()[0], &_filter->Q().data()[6], _output->_covMatrix);
448
449 _output->_trp0 = t_tropo::delay_saast(_staRover->xyzApr(), M_PI/2.0);
450 _output->_trp = _filter->trp();
451 _output->_trpStdev = _filter->trpStdev();
452
[9386]453 _output->_numSat = _filter->numSat();
454 _output->_hDop = _filter->HDOP();
[7237]455 _output->_error = false;
456 }
457 else {
458 _output->_error = true;
[9581]459 if (OPT->_obsModelType == OPT->DCMcodeBias ||
460 OPT->_obsModelType == OPT->DCMphaseBias) {
[9607]461 if (ind == 1 || ind > 7) {
462 reset();
463 }
[9581]464 }
[7237]465 }
466 _output->_log = _log->str();
467 delete _log; _log = new ostringstream();
[9545]468
469 return;
[7237]470}
471
[7271]472//
[7237]473//////////////////////////////////////////////////////////////////////////////
474t_irc t_pppClient::cmpModel(t_pppStation* station, const ColumnVector& xyzc,
475 vector<t_pppSatObs*>& obsVector) {
476 bncTime time;
477 time = _epoTimeRover;
[8912]478 station->setName(_opt->_roverName);
479 station->setAntName(_opt->_antNameRover);
[8905]480 station->setEpochTime(time);
[8912]481 if (_opt->xyzAprRoverSet()) {
482 station->setXyzApr(_opt->_xyzAprRover);
[7237]483 }
484 else {
485 station->setXyzApr(xyzc.Rows(1,3));
486 }
[8912]487 station->setNeuEcc(_opt->_neuEccRover);
[7237]488
489 // Receiver Clock
490 // --------------
491 station->setDClk(xyzc[3]);
492
493 // Tides
494 // -----
[8905]495 station->setTideDsplEarth(_tides->earth(time, station->xyzApr()));
496 station->setTideDsplOcean(_tides->ocean(time, station->xyzApr(), station->name()));
[7271]497
[7237]498 // Observation model
499 // -----------------
500 vector<t_pppSatObs*>::iterator it = obsVector.begin();
501 while (it != obsVector.end()) {
502 t_pppSatObs* satObs = *it;
[7254]503 t_irc modelSetup;
[7237]504 if (satObs->isValid()) {
[7254]505 modelSetup = satObs->cmpModel(station);
[7237]506 }
[7254]507 if (satObs->isValid() &&
[8912]508 satObs->eleSat() >= _opt->_minEle &&
[7254]509 modelSetup == success) {
[7237]510 ++it;
511 }
512 else {
513 delete satObs;
514 it = obsVector.erase(it);
515 }
516 }
517
518 return success;
519}
520
[7271]521//
[7237]522//////////////////////////////////////////////////////////////////////////////
523void t_pppClient::processEpoch(const vector<t_satObs*>& satObs, t_output* output) {
524
525 try {
526 initOutput(output);
[8912]527 bool epochReProcessing = false;
[9386]528 _numEpoProcessing = 0;
[9419]529 _historicalRefSats.clear();
530
[8905]531 do {
[9386]532 _numEpoProcessing++;
[9419]533#ifdef BNC_DEBUG_PPP
534 LOG << "_numEpoProcessing " << _numEpoProcessing << endl;
535#endif
[9386]536 if (_obsPool->refSatChanged()) {
[9508]537 if(_filter->datumTransformation(_refSatMap) != success) {
538 LOG << "t_pppFilter::datumTransformation() != success" << endl;
[9545]539 return finish(failure,1);
[9386]540 }
541 else {
[9508]542 LOG << "t_pppFilter::datumTransformation() == success" << endl;
[9527]543 _filter->rememberState(1);
[9386]544 }
[8956]545 }
[8905]546 // Prepare Observations of the Rover
547 // ---------------------------------
548 if (prepareObs(satObs, _obsRover, _epoTimeRover) != success) {
[9545]549 return finish(failure,2);
[7237]550 }
[8905]551
552 for (int iter = 1; iter <= 2; iter++) {
553 ColumnVector xyzc(4); xyzc = 0.0;
554 bool print = (iter == 2);
555 if (cmpBancroft(_epoTimeRover, _obsRover, xyzc, print) != success) {
[9545]556 return finish(failure,3);
[8905]557 }
[9783]558
[8905]559 if (cmpModel(_staRover, xyzc, _obsRover) != success) {
[9545]560 return finish(failure,4);
[8905]561 }
562 }
563
[8912]564 if (_opt->_refSatRequired) {
[9386]565 if (handleRefSatellites(_obsRover) != success) {
[9545]566 return finish(failure,6);
[8905]567 }
[9508]568 if (_obsPool->refSatChanged()) {
569 LOG << "t_pppFilter: refSatChanged()" << endl;
[9527]570 epochReProcessing = true;
571 continue;
[9386]572 }
[8905]573 }
[7237]574
[9565]575 // use observations only if satellite code biases are available
576 // ------------------------------------------------------------
[9783]577 if (!_opt->_corrMount.empty() &&
[9601]578 (OPT->_obsModelType == OPT->DCMcodeBias ||
579 OPT->_obsModelType == OPT->DCMphaseBias)) {
[9584]580 useObsWithCodeBiasesOnly(_obsRover);
581 }
[9560]582
583 if (int(_obsRover.size()) < _opt->_minObs) {
584 LOG << "t_pppClient::processEpoch not enough observations" << endl;
585 return finish(failure,5);
586 }
587
[10002]588 _offGG = cmpOffGG(_obsRover);
589
[8956]590 // Prepare Pseudo Observations of the Rover
591 // ----------------------------------------
592 _pseudoObsIono = preparePseudoObs(_obsRover);
593
[8905]594 // Store last epoch of data
595 // ------------------------
[9508]596 _obsPool->putEpoch(_epoTimeRover, _obsRover, _pseudoObsIono, _refSatMap);
[7904]597
[8905]598 // Process Epoch in Filter
599 // -----------------------
[9386]600 if (_filter->processEpoch() != success) {
[9545]601 LOG << "filter->processEpoch() != success" << endl;
602 return finish(failure,7);
[8905]603 }
[8912]604
605 // Epoch re-processing required?
606 // -----------------------------
[9395]607 if (_obsPool->refSatChangeRequired() && //SLIP
608 _opt->_obsModelType != t_pppOptions::UncombPPP) {
[9545]609 LOG << "pppClient: _obsPool->refSatChangeRequired() " << endl;
[8912]610 epochReProcessing = true;
[8956]611 _obsPool->deleteLastEpoch();
[9527]612 _filter->restoreState(0);
[9386]613 setHistoricalRefSats();
[8912]614 }
615 else {
616 epochReProcessing = false;
[9537]617 if (OPT->_obsModelType == OPT->DCMcodeBias ||
618 OPT->_obsModelType == OPT->DCMphaseBias) {
619 _filter->rememberState(0);
620 }
[8912]621 }
622 } while (epochReProcessing);
[9431]623
[7237]624 }
625 catch (Exception& exc) {
626 LOG << exc.what() << endl;
[9545]627 return finish(failure,8);
[7237]628 }
629 catch (t_except msg) {
630 LOG << msg.what() << endl;
[9545]631 return finish(failure,9);
[7237]632 }
633 catch (const char* msg) {
634 LOG << msg << endl;
[9545]635 return finish(failure,10);
[7237]636 }
637 catch (...) {
638 LOG << "unknown exception" << endl;
[9545]639 return finish(failure,11);
[7237]640 }
[9545]641 return finish(success,12);
[7237]642}
643
[7271]644//
[7237]645////////////////////////////////////////////////////////////////////////////
646double lorentz(const ColumnVector& aa, const ColumnVector& bb) {
647 return aa[0]*bb[0] + aa[1]*bb[1] + aa[2]*bb[2] - aa[3]*bb[3];
648}
649
[7271]650//
[7237]651////////////////////////////////////////////////////////////////////////////
[9600]652t_irc t_pppClient::bancroft(const Matrix& BBpass, ColumnVector& pos) {
[7237]653
654 if (pos.Nrows() != 4) {
655 pos.ReSize(4);
656 }
657 pos = 0.0;
658
659 for (int iter = 1; iter <= 2; iter++) {
660 Matrix BB = BBpass;
661 int mm = BB.Nrows();
662 for (int ii = 1; ii <= mm; ii++) {
663 double xx = BB(ii,1);
664 double yy = BB(ii,2);
665 double traveltime = 0.072;
666 if (iter > 1) {
667 double zz = BB(ii,3);
[7271]668 double rho = sqrt( (xx-pos(1)) * (xx-pos(1)) +
669 (yy-pos(2)) * (yy-pos(2)) +
[7237]670 (zz-pos(3)) * (zz-pos(3)) );
671 traveltime = rho / t_CST::c;
672 }
673 double angle = traveltime * t_CST::omega;
674 double cosa = cos(angle);
675 double sina = sin(angle);
676 BB(ii,1) = cosa * xx + sina * yy;
677 BB(ii,2) = -sina * xx + cosa * yy;
678 }
[7271]679
[7237]680 Matrix BBB;
681 if (mm > 4) {
682 SymmetricMatrix hlp; hlp << BB.t() * BB;
683 BBB = hlp.i() * BB.t();
684 }
685 else {
686 BBB = BB.i();
687 }
688 ColumnVector ee(mm); ee = 1.0;
689 ColumnVector alpha(mm); alpha = 0.0;
690 for (int ii = 1; ii <= mm; ii++) {
[7271]691 alpha(ii) = lorentz(BB.Row(ii).t(),BB.Row(ii).t())/2.0;
[7237]692 }
693 ColumnVector BBBe = BBB * ee;
694 ColumnVector BBBalpha = BBB * alpha;
695 double aa = lorentz(BBBe, BBBe);
696 double bb = lorentz(BBBe, BBBalpha)-1;
697 double cc = lorentz(BBBalpha, BBBalpha);
698 double root = sqrt(bb*bb-aa*cc);
699
[7271]700 Matrix hlpPos(4,2);
[7237]701 hlpPos.Column(1) = (-bb-root)/aa * BBBe + BBBalpha;
702 hlpPos.Column(2) = (-bb+root)/aa * BBBe + BBBalpha;
703
704 ColumnVector omc(2);
705 for (int pp = 1; pp <= 2; pp++) {
706 hlpPos(4,pp) = -hlpPos(4,pp);
[7271]707 omc(pp) = BB(1,4) -
[7237]708 sqrt( (BB(1,1)-hlpPos(1,pp)) * (BB(1,1)-hlpPos(1,pp)) +
709 (BB(1,2)-hlpPos(2,pp)) * (BB(1,2)-hlpPos(2,pp)) +
[7271]710 (BB(1,3)-hlpPos(3,pp)) * (BB(1,3)-hlpPos(3,pp)) ) -
[7237]711 hlpPos(4,pp);
712 }
713 if ( fabs(omc(1)) > fabs(omc(2)) ) {
714 pos = hlpPos.Column(2);
715 }
716 else {
717 pos = hlpPos.Column(1);
718 }
719 }
[9600]720 if (pos.size() != 4 ||
721 std::isnan(pos(1)) ||
722 std::isnan(pos(2)) ||
723 std::isnan(pos(3)) ||
724 std::isnan(pos(4))) {
725 return failure;
726 }
727
728 return success;
[7237]729}
730
[7972]731//
732//////////////////////////////////////////////////////////////////////////////
[8956]733void t_pppClient::setRefSatellites(std::vector<t_pppSatObs*>& obsVector) {
734 // reference satellite definition per system
735 for (unsigned iSys = 0; iSys < _opt->systems().size(); iSys++) {
[9490]736 t_irc refSatReDefinition = success;
[9386]737 char sys = _opt->systems()[iSys];
[8956]738 bool refSatDefined = false;
[9508]739 t_pppRefSat* refSat = _refSatMap[sys];
[8956]740 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
741 t_pppSatObs* satObs = obsVector.at(ii);
[9386]742 if (satObs->eleSat() < _opt->_minEle) {
743 continue;
744 }
[8956]745 // reference satellite is unchanged
[9395]746 // ================================
[9508]747 if ( !_obsPool->refSatChangeRequired(sys) && refSat->prn() == satObs->prn()) {
[8956]748 refSatDefined = true;
749 obsVector[ii]->setAsReference();
750 }
751 // reference satellite has changed
[9395]752 // ===============================
753 else if ( _obsPool->refSatChangeRequired(sys) && refSat->prn() != satObs->prn()) {
[9386]754 if (satObs->prn().system() == sys) {
[9395]755 if (!_historicalRefSats[sys].contains(satObs->prn())) {
756 refSatDefined = true;
757 obsVector[ii]->setAsReference();
758 refSat->setPrn(satObs->prn());
759 }
760 else if ( _historicalRefSats[sys].contains(satObs->prn())) {
761 refSatReDefinition = failure;
762 }
[8956]763 }
764 }
765 if (refSatDefined) {
766 if (OPT->_pseudoObsIono) {
767 refSat->setStecValue(satObs->getIonoCodeDelay(t_frequency::G1));
768 }
769 break;
770 }
771 }
[9490]772
[9398]773 // all available satellites were already tried to use
[9395]774 if ((!refSatDefined) && (refSatReDefinition == failure)) {
775 refSat->setPrn(t_prn(sys, 99));
[9398]776 _obsPool->setRefSatChangeRequired(sys, false);
777 return;
[9395]778 }
779
[8956]780 // reference satellite has to be initialized
[9395]781 // =========================================
[8956]782 if (!refSatDefined) {
783 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
784 t_pppSatObs* satObs = obsVector.at(ii);
785 if (satObs->eleSat() < _opt->_minEle) {
786 continue;
787 }
[9583]788 if (satObs->prn().system() == sys &&
789 !_historicalRefSats[sys].contains(satObs->prn())) {
[8956]790 obsVector[ii]->setAsReference();
791 refSat->setPrn(satObs->prn());
792 if (OPT->_pseudoObsIono) {
793 refSat->setStecValue(satObs->getIonoCodeDelay(t_frequency::G1));
794 }
795 refSatDefined = true;
796 break;
797 }
798 }
799 }
[9395]800
[9398]801 // no observations for that system
802 // ===============================
803 if (!refSatDefined) {
[9386]804 refSat->setPrn(t_prn());
805 }
[9398]806 _obsPool->setRefSatChangeRequired(sys, false); // done or impossible
[8956]807 }
[9398]808
809 return;
[9386]810}
[8956]811
[9386]812//
813//////////////////////////////////////////////////////////////////////////////
814t_irc t_pppClient::handleRefSatellites(std::vector<t_pppSatObs*>& obsVector) {
815
816 // set refSats in current epoch
817 // ============================
818 setRefSatellites(obsVector); // current epoch
819 LOG.setf(ios::fixed);
[9508]820 t_pppObsPool::t_epoch* epoch = _obsPool->lastEpoch();
821 const QMap<char, t_pppRefSat*>& refSatMapLastEpoch = epoch->refSatMap();
[9527]822
[9508]823 QMapIterator<char, t_pppRefSat*> it(_refSatMap);
[9386]824 while (it.hasNext()) {
825 it.next();
826 char sys = it.key();
827 t_prn prn = it.value()->prn();
[9508]828 t_prn refSatLastEpochPrn = t_prn();
829 if (epoch) {
830 refSatLastEpochPrn = refSatMapLastEpoch[sys]->prn();
831 }
[9395]832 if (prn.number() == 0) { // no obs for that system available
833 continue;
834 }
835 else if (prn.number() == 99) { // refSat re-definition not possible
[9490]836 LOG << " => refSat re-definition impossible: " << sys << endl;
[9386]837 return failure;
838 }
[9432]839 QString str;
[9508]840 if (prn == refSatLastEpochPrn || refSatLastEpochPrn == t_prn() ) {
[9386]841 _obsPool->setRefSatChanged(sys, false);
842 str = " SET ";
843 }
844 else {
845 _obsPool->setRefSatChanged(sys, true);
846 str = " RESET ";
847 }
848 LOG << string(_epoTimeRover) << str.toStdString() << " REFSAT " << sys << ": " << prn.toString() << endl;
849 }
850 return success;
[8956]851}
852
[9386]853void t_pppClient::setHistoricalRefSats() {
[9508]854 QMapIterator<char, t_pppRefSat*> it(_refSatMap);
[9386]855 while (it.hasNext()) {
856 it.next();
857 t_prn prn = it.value()->prn();
858 char sys = prn.system();
[9548]859 if (_obsPool->refSatChangeRequired(sys)) {
[9386]860 _historicalRefSats[sys].append(prn);
861 }
[9508]862 }
863}
[9386]864
[8956]865//
866//////////////////////////////////////////////////////////////////////////////
[9548]867void t_pppClient::reset() {LOG << "t_pppClient::reset()" << endl;
[7972]868
869 // to delete old orbit and clock corrections
870 delete _ephPool;
871 _ephPool = new t_pppEphPool();
872
873 // to delete old code biases
874 delete _obsPool;
875 _obsPool = new t_pppObsPool();
[8905]876
877 // to delete all parameters
878 delete _filter;
879 _filter = new t_pppFilter(_obsPool);
880
[7996]881}
Note: See TracBrowser for help on using the repository browser.