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

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