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

Last change on this file since 9527 was 9527, checked in by stuerze, 2 years ago

update regarding PPP

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