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

Last change on this file since 9545 was 9545, checked in by stuerze, 9 months 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.4 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
235/*
236 vector<t_pppSatObs*>::iterator it = obsVector.begin();
237 while (it != obsVector.end()) {
238 t_pppSatObs* satObs = *it;
239 satObs->printObsMinusComputed();
240 it++;
241 }
242*/
243 return pseudoObsIono;
244}
245
246// Compute the Bancroft position, check for blunders
247//////////////////////////////////////////////////////////////////////////////
248t_irc t_pppClient::cmpBancroft(const bncTime& epoTime,
249 vector<t_pppSatObs*>& obsVector,
250 ColumnVector& xyzc, bool print) {
251
252 t_lc::type tLC = t_lc::dummy;
253
254 while (true) {
255 Matrix BB(obsVector.size(), 4);
256 int iObs = -1;
257 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
258 const t_pppSatObs* satObs = obsVector.at(ii);
259 if (tLC == t_lc::dummy) {
260 if (satObs->isValid(t_lc::cIF)) {
261 tLC = t_lc::cIF;
262 }
263 else if (satObs->isValid(t_lc::c1)) {
264 tLC = t_lc::c1;
265 }
266 else if (satObs->isValid(t_lc::c2)) {
267 tLC = t_lc::c2;
268 }
269 }
270 if ( satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle) ) {
271 ++iObs;
272 BB[iObs][0] = satObs->xc()[0];
273 BB[iObs][1] = satObs->xc()[1];
274 BB[iObs][2] = satObs->xc()[2];
275 BB[iObs][3] = satObs->obsValue(tLC) - satObs->cmpValueForBanc(tLC);
276 }
277 }
278 if (iObs + 1 < _opt->_minObs) {
279 LOG << "t_pppClient::cmpBancroft not enough observations: " << iObs + 1 << endl;
280 return failure;
281 }
282 BB = BB.Rows(1,iObs+1);
283 bancroft(BB, xyzc);
284
285 xyzc[3] /= t_CST::c;
286
287 // Check Blunders
288 // --------------
289 const double BLUNDER = 100.0;
290 double maxRes = 0.0;
291 unsigned maxResIndex = 0;
292 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
293 const t_pppSatObs* satObs = obsVector.at(ii);
294 if (satObs->isValid() &&
295 satObs->prn().system() == 'G' &&
296 (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle) ) {
297 ColumnVector rr = satObs->xc().Rows(1,3) - xyzc.Rows(1,3);
298 double res = rr.NormFrobenius() - satObs->obsValue(tLC)
299 - (satObs->xc()[3] - xyzc[3]) * t_CST::c;
300 if (std::isnan(res) || fabs(res) > maxRes) {
301 std::isnan(res) ?
302 maxRes = res :
303 maxRes = fabs(res);
304 maxResIndex = ii;
305 }
306 }
307 }
308 if (!std::isnan(maxRes) && maxRes < BLUNDER) {
309 if (print && _numEpoProcessing == 1) {
310 LOG.setf(ios::fixed);
311 LOG << string(epoTime) << " BANCROFT:" << ' '
312 << setw(14) << setprecision(3) << xyzc[0] << ' '
313 << setw(14) << setprecision(3) << xyzc[1] << ' '
314 << setw(14) << setprecision(3) << xyzc[2] << ' '
315 << setw(14) << setprecision(3) << xyzc[3] * t_CST::c << endl << endl;
316 }
317 break;
318 }
319 else {
320 t_pppSatObs* satObs = obsVector.at(maxResIndex);
321 LOG << "t_pppClient::cmpBancroft outlier " << satObs->prn().toString()
322 << " " << maxRes << endl;
323 delete satObs;
324 obsVector.erase(obsVector.begin() + maxResIndex);
325 }
326 }
327
328 return success;
329}
330
331// Compute A Priori GPS-Glonass Offset
332//////////////////////////////////////////////////////////////////////////////
333double t_pppClient::cmpOffGR(vector<t_pppSatObs*>& obsVector) {
334
335 t_lc::type tLC = t_lc::dummy;
336 double offGR = 0.0;
337
338 if (_opt->useSystem('R')) {
339 while (obsVector.size() > 0) {
340 offGR = 0.0;
341 double maxRes = 0.0;
342 int maxResIndex = -1;
343 t_prn maxResPrn;
344 unsigned nObs = 0;
345 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
346 const t_pppSatObs* satObs = obsVector.at(ii);
347 if (satObs->prn().system() == 'R') {
348 if (tLC == t_lc::dummy) {
349 tLC = satObs->isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
350 }
351 if (satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle)) {
352 double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC);
353 ++nObs;
354 offGR += ll;
355 if (fabs(ll) > fabs(maxRes)) {
356 maxRes = ll;
357 maxResIndex = ii;
358 maxResPrn = satObs->prn();
359 }
360 }
361 }
362 }
363
364 if (nObs > 0) {
365 offGR = offGR / nObs;
366 }
367 else {
368 offGR = 0.0;
369 }
370 if (fabs(maxRes) > OPT->_aprSigOGC) {
371 LOG << "t_pppClient::cmpOffGR outlier " << maxResPrn.toString() << " " << maxRes << endl;
372 delete obsVector.at(maxResIndex);
373 obsVector.erase(obsVector.begin() + maxResIndex);
374 }
375 else {
376 break;
377 }
378 }
379 }
380 return offGR;
381}
382
383// Compute A Priori GPS-Galileo Offset
384//////////////////////////////////////////////////////////////////////////////
385double t_pppClient::cmpOffGE(vector<t_pppSatObs*>& obsVector) {
386
387 t_lc::type tLC = t_lc::dummy;
388 double offGE = 0.0;
389
390 if (_opt->useSystem('E')) {
391 while (obsVector.size() > 0) {
392 offGE = 0.0;
393 double maxRes = 0.0;
394 int maxResIndex = -1;
395 t_prn maxResPrn;
396 unsigned nObs = 0;
397 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
398 const t_pppSatObs* satObs = obsVector.at(ii);
399 if (satObs->prn().system() == 'E') {
400 if (tLC == t_lc::dummy) {
401 tLC = satObs->isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
402 }
403 if (satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle)) {
404 double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC);
405 ++nObs;
406 offGE += ll;
407 if (fabs(ll) > fabs(maxRes)) {
408 maxRes = ll;
409 maxResIndex = ii;
410 maxResPrn = satObs->prn();
411 }
412 }
413 }
414 }
415
416 if (nObs > 0) {
417 offGE = offGE / nObs;
418 }
419 else {
420 offGE = 0.0;
421 }
422
423 if (fabs(maxRes) > OPT->_aprSigOGE) {
424 LOG << "t_pppClient::cmpOffGE outlier " << maxResPrn.toString() << " " << maxRes << endl;
425 delete obsVector.at(maxResIndex);
426 obsVector.erase(obsVector.begin() + maxResIndex);
427 }
428 else {
429 break;
430 }
431 }
432 }
433 return offGE;
434}
435
436// Compute A Priori GPS-BDS Offset
437//////////////////////////////////////////////////////////////////////////////
438double t_pppClient::cmpOffGC(vector<t_pppSatObs*>& obsVector) {
439
440 t_lc::type tLC = t_lc::dummy;
441 double offGC = 0.0;
442
443 if (_opt->useSystem('C')) {
444 while (obsVector.size() > 0) {
445 offGC = 0.0;
446 double maxRes = 0.0;
447 int maxResIndex = -1;
448 t_prn maxResPrn;
449 unsigned nObs = 0;
450 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
451 const t_pppSatObs* satObs = obsVector.at(ii);
452 if (satObs->prn().system() == 'C') {
453 if (tLC == t_lc::dummy) {
454 tLC = satObs->isValid(t_lc::cIF) ? t_lc::cIF : t_lc::c1;
455 }
456 if (satObs->isValid(tLC) && (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle)) {
457 double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC);
458 ++nObs;
459 offGC += ll;
460 if (fabs(ll) > fabs(maxRes)) {
461 maxRes = ll;
462 maxResIndex = ii;
463 maxResPrn = satObs->prn();
464 }
465 }
466 }
467 }
468
469 if (nObs > 0) {
470 offGC = offGC / nObs;
471 }
472 else {
473 offGC = 0.0;
474 }
475
476 if (fabs(maxRes) > OPT->_aprSigOGC) {
477 LOG << "t_pppClient::cmpOffGC outlier " << maxResPrn.toString() << " " << maxRes << endl;
478 delete obsVector.at(maxResIndex);
479 obsVector.erase(obsVector.begin() + maxResIndex);
480 }
481 else {
482 break;
483 }
484 }
485 }
486 return offGC;
487}
488
489//
490//////////////////////////////////////////////////////////////////////////////
491void t_pppClient::initOutput(t_output* output) {
492 _output = output;
493 _output->_numSat = 0;
494 _output->_hDop = 0.0;
495 _output->_error = false;
496}
497
498//
499//////////////////////////////////////////////////////////////////////////////
500void t_pppClient::clearObs() {
501 for (unsigned ii = 0; ii < _obsRover.size(); ii++) {
502 delete _obsRover.at(ii);
503 }
504 _obsRover.clear();
505}
506
507//
508//////////////////////////////////////////////////////////////////////////////
509void t_pppClient::finish(t_irc irc, int ind) {// LOG << "t_pppClient::finish(" << irc << ") " << ind << endl;
510
511 clearObs();
512
513 _output->_epoTime = _epoTimeRover;
514
515 if (irc == success) {
516 _output->_xyzRover[0] = _staRover->xyzApr()[0] + _filter->x()[0];
517 _output->_xyzRover[1] = _staRover->xyzApr()[1] + _filter->x()[1];
518 _output->_xyzRover[2] = _staRover->xyzApr()[2] + _filter->x()[2];
519
520 xyz2neu(_staRover->ellApr().data(), _filter->x().data(), _output->_neu);
521
522 copy(&_filter->Q().data()[0], &_filter->Q().data()[6], _output->_covMatrix);
523
524 _output->_trp0 = t_tropo::delay_saast(_staRover->xyzApr(), M_PI/2.0);
525 _output->_trp = _filter->trp();
526 _output->_trpStdev = _filter->trpStdev();
527
528 _output->_numSat = _filter->numSat();
529 _output->_hDop = _filter->HDOP();
530 _output->_error = false;
531 }
532 else {
533 _output->_error = true;
534 }
535 _output->_log = _log->str();
536 delete _log; _log = new ostringstream();
537
538 return;
539}
540
541//
542//////////////////////////////////////////////////////////////////////////////
543t_irc t_pppClient::cmpModel(t_pppStation* station, const ColumnVector& xyzc,
544 vector<t_pppSatObs*>& obsVector) {
545 bncTime time;
546 time = _epoTimeRover;
547 station->setName(_opt->_roverName);
548 station->setAntName(_opt->_antNameRover);
549 station->setEpochTime(time);
550 if (_opt->xyzAprRoverSet()) {
551 station->setXyzApr(_opt->_xyzAprRover);
552 }
553 else {
554 station->setXyzApr(xyzc.Rows(1,3));
555 }
556 station->setNeuEcc(_opt->_neuEccRover);
557
558 // Receiver Clock
559 // --------------
560 station->setDClk(xyzc[3]);
561
562 // Tides
563 // -----
564 station->setTideDsplEarth(_tides->earth(time, station->xyzApr()));
565 station->setTideDsplOcean(_tides->ocean(time, station->xyzApr(), station->name()));
566
567 // Observation model
568 // -----------------
569 vector<t_pppSatObs*>::iterator it = obsVector.begin();
570 while (it != obsVector.end()) {
571 t_pppSatObs* satObs = *it;
572 t_irc modelSetup;
573 if (satObs->isValid()) {
574 modelSetup = satObs->cmpModel(station);
575 }
576 if (satObs->isValid() &&
577 satObs->eleSat() >= _opt->_minEle &&
578 modelSetup == success) {
579 ++it;
580 }
581 else {
582 delete satObs;
583 it = obsVector.erase(it);
584 }
585 }
586
587 return success;
588}
589
590//
591//////////////////////////////////////////////////////////////////////////////
592void t_pppClient::processEpoch(const vector<t_satObs*>& satObs, t_output* output) {
593
594 try {
595 initOutput(output);
596 bool epochReProcessing = false;
597 _numEpoProcessing = 0;
598 _historicalRefSats.clear();
599
600 do {
601 _numEpoProcessing++;
602#ifdef BNC_DEBUG_PPP
603 LOG << "_numEpoProcessing " << _numEpoProcessing << endl;
604#endif
605 if (_obsPool->refSatChanged()) {
606 if(_filter->datumTransformation(_refSatMap) != success) {
607 LOG << "t_pppFilter::datumTransformation() != success" << endl;
608 return finish(failure,1);
609 }
610 else {
611 LOG << "t_pppFilter::datumTransformation() == success" << endl;
612 _filter->rememberState(1);
613 }
614 }
615 // Prepare Observations of the Rover
616 // ---------------------------------
617 if (prepareObs(satObs, _obsRover, _epoTimeRover) != success) {
618 return finish(failure,2);
619 }
620
621 if (_numEpoProcessing == 1) {
622 LOG << "\nPPP of Epoch ";
623 if (!_epoTimeRover.undef()) LOG << string(_epoTimeRover);
624 LOG << "\n---------------------------------------------------------------\n";
625 }
626
627 for (int iter = 1; iter <= 2; iter++) {
628 ColumnVector xyzc(4); xyzc = 0.0;
629 bool print = (iter == 2);
630 if (cmpBancroft(_epoTimeRover, _obsRover, xyzc, print) != success) {
631 return finish(failure,3);
632 }
633 if (cmpModel(_staRover, xyzc, _obsRover) != success) {
634 return finish(failure,4);
635 }
636 }
637
638 if (int(_obsRover.size()) < _opt->_minObs) {
639 LOG << "t_pppClient::processEpoch not enough observations" << endl;
640 return finish(failure,5);
641 }
642
643 if (_opt->_refSatRequired) {
644 if (handleRefSatellites(_obsRover) != success) {
645 return finish(failure,6);
646 }
647 if (_obsPool->refSatChanged()) {
648 LOG << "t_pppFilter: refSatChanged()" << endl;
649 epochReProcessing = true;
650 continue;
651 }
652 }
653
654 _offGR = cmpOffGR(_obsRover);
655 _offGE = cmpOffGE(_obsRover);
656 _offGC = cmpOffGC(_obsRover);
657
658 // Prepare Pseudo Observations of the Rover
659 // ----------------------------------------
660 _pseudoObsIono = preparePseudoObs(_obsRover);
661
662 // Store last epoch of data
663 // ------------------------
664 _obsPool->putEpoch(_epoTimeRover, _obsRover, _pseudoObsIono, _refSatMap);
665
666 // Process Epoch in Filter
667 // -----------------------
668 if (_filter->processEpoch() != success) {
669 LOG << "filter->processEpoch() != success" << endl;
670 return finish(failure,7);
671 }
672
673 // Epoch re-processing required?
674 // -----------------------------
675 if (_obsPool->refSatChangeRequired() && //SLIP
676 _opt->_obsModelType != t_pppOptions::UncombPPP) {
677 LOG << "pppClient: _obsPool->refSatChangeRequired() " << endl;
678 epochReProcessing = true;
679 _obsPool->deleteLastEpoch();
680 _filter->restoreState(0);
681 setHistoricalRefSats();
682 }
683 else {
684 epochReProcessing = false;
685 if (OPT->_obsModelType == OPT->DCMcodeBias ||
686 OPT->_obsModelType == OPT->DCMphaseBias) {
687 _filter->rememberState(0);
688 }
689 }
690 } while (epochReProcessing);
691
692 }
693 catch (Exception& exc) {
694 LOG << exc.what() << endl;
695 return finish(failure,8);
696 }
697 catch (t_except msg) {
698 LOG << msg.what() << endl;
699 return finish(failure,9);
700 }
701 catch (const char* msg) {
702 LOG << msg << endl;
703 return finish(failure,10);
704 }
705 catch (...) {
706 LOG << "unknown exception" << endl;
707 return finish(failure,11);
708 }
709 return finish(success,12);
710}
711
712//
713////////////////////////////////////////////////////////////////////////////
714double lorentz(const ColumnVector& aa, const ColumnVector& bb) {
715 return aa[0]*bb[0] + aa[1]*bb[1] + aa[2]*bb[2] - aa[3]*bb[3];
716}
717
718//
719////////////////////////////////////////////////////////////////////////////
720void t_pppClient::bancroft(const Matrix& BBpass, ColumnVector& pos) {
721
722 if (pos.Nrows() != 4) {
723 pos.ReSize(4);
724 }
725 pos = 0.0;
726
727 for (int iter = 1; iter <= 2; iter++) {
728 Matrix BB = BBpass;
729 int mm = BB.Nrows();
730 for (int ii = 1; ii <= mm; ii++) {
731 double xx = BB(ii,1);
732 double yy = BB(ii,2);
733 double traveltime = 0.072;
734 if (iter > 1) {
735 double zz = BB(ii,3);
736 double rho = sqrt( (xx-pos(1)) * (xx-pos(1)) +
737 (yy-pos(2)) * (yy-pos(2)) +
738 (zz-pos(3)) * (zz-pos(3)) );
739 traveltime = rho / t_CST::c;
740 }
741 double angle = traveltime * t_CST::omega;
742 double cosa = cos(angle);
743 double sina = sin(angle);
744 BB(ii,1) = cosa * xx + sina * yy;
745 BB(ii,2) = -sina * xx + cosa * yy;
746 }
747
748 Matrix BBB;
749 if (mm > 4) {
750 SymmetricMatrix hlp; hlp << BB.t() * BB;
751 BBB = hlp.i() * BB.t();
752 }
753 else {
754 BBB = BB.i();
755 }
756 ColumnVector ee(mm); ee = 1.0;
757 ColumnVector alpha(mm); alpha = 0.0;
758 for (int ii = 1; ii <= mm; ii++) {
759 alpha(ii) = lorentz(BB.Row(ii).t(),BB.Row(ii).t())/2.0;
760 }
761 ColumnVector BBBe = BBB * ee;
762 ColumnVector BBBalpha = BBB * alpha;
763 double aa = lorentz(BBBe, BBBe);
764 double bb = lorentz(BBBe, BBBalpha)-1;
765 double cc = lorentz(BBBalpha, BBBalpha);
766 double root = sqrt(bb*bb-aa*cc);
767
768 Matrix hlpPos(4,2);
769 hlpPos.Column(1) = (-bb-root)/aa * BBBe + BBBalpha;
770 hlpPos.Column(2) = (-bb+root)/aa * BBBe + BBBalpha;
771
772 ColumnVector omc(2);
773 for (int pp = 1; pp <= 2; pp++) {
774 hlpPos(4,pp) = -hlpPos(4,pp);
775 omc(pp) = BB(1,4) -
776 sqrt( (BB(1,1)-hlpPos(1,pp)) * (BB(1,1)-hlpPos(1,pp)) +
777 (BB(1,2)-hlpPos(2,pp)) * (BB(1,2)-hlpPos(2,pp)) +
778 (BB(1,3)-hlpPos(3,pp)) * (BB(1,3)-hlpPos(3,pp)) ) -
779 hlpPos(4,pp);
780 }
781 if ( fabs(omc(1)) > fabs(omc(2)) ) {
782 pos = hlpPos.Column(2);
783 }
784 else {
785 pos = hlpPos.Column(1);
786 }
787 }
788}
789
790//
791//////////////////////////////////////////////////////////////////////////////
792void t_pppClient::setRefSatellites(std::vector<t_pppSatObs*>& obsVector) {
793 // reference satellite definition per system
794 for (unsigned iSys = 0; iSys < _opt->systems().size(); iSys++) {
795 t_irc refSatReDefinition = success;
796 char sys = _opt->systems()[iSys];
797 bool refSatDefined = false;
798 t_pppRefSat* refSat = _refSatMap[sys];
799 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
800 t_pppSatObs* satObs = obsVector.at(ii);
801 if (satObs->eleSat() < _opt->_minEle) {
802 continue;
803 }
804 // reference satellite is unchanged
805 // ================================
806 if ( !_obsPool->refSatChangeRequired(sys) && refSat->prn() == satObs->prn()) {
807 refSatDefined = true;
808 obsVector[ii]->setAsReference();
809 }
810 // reference satellite has changed
811 // ===============================
812 else if ( _obsPool->refSatChangeRequired(sys) && refSat->prn() != satObs->prn()) {
813 if (satObs->prn().system() == sys) {
814 if (!_historicalRefSats[sys].contains(satObs->prn())) {
815 refSatDefined = true;
816 obsVector[ii]->setAsReference();
817 refSat->setPrn(satObs->prn());
818 }
819 else if ( _historicalRefSats[sys].contains(satObs->prn())) {
820 refSatReDefinition = failure;
821 }
822 }
823 }
824 if (refSatDefined) {
825 if (OPT->_pseudoObsIono) {
826 refSat->setStecValue(satObs->getIonoCodeDelay(t_frequency::G1));
827 }
828 break;
829 }
830 }
831
832 // all available satellites were already tried to use
833 if ((!refSatDefined) && (refSatReDefinition == failure)) {
834 refSat->setPrn(t_prn(sys, 99));
835 _obsPool->setRefSatChangeRequired(sys, false);
836 return;
837 }
838
839 // reference satellite has to be initialized
840 // =========================================
841 if (!refSatDefined) {
842 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
843 t_pppSatObs* satObs = obsVector.at(ii);
844 if (satObs->eleSat() < _opt->_minEle) {
845 continue;
846 }
847 if (satObs->prn().system() == sys) {
848 obsVector[ii]->setAsReference();
849 refSat->setPrn(satObs->prn());
850 if (OPT->_pseudoObsIono) {
851 refSat->setStecValue(satObs->getIonoCodeDelay(t_frequency::G1));
852 }
853 refSatDefined = true;
854 break;
855 }
856 }
857 }
858
859 // no observations for that system
860 // ===============================
861 if (!refSatDefined) {
862 refSat->setPrn(t_prn());
863 }
864 _obsPool->setRefSatChangeRequired(sys, false); // done or impossible
865 }
866
867 return;
868}
869
870//
871//////////////////////////////////////////////////////////////////////////////
872t_irc t_pppClient::handleRefSatellites(std::vector<t_pppSatObs*>& obsVector) {
873
874 // set refSats in current epoch
875 // ============================
876 setRefSatellites(obsVector); // current epoch
877 LOG.setf(ios::fixed);
878 t_pppObsPool::t_epoch* epoch = _obsPool->lastEpoch();
879 const QMap<char, t_pppRefSat*>& refSatMapLastEpoch = epoch->refSatMap();
880
881 QMapIterator<char, t_pppRefSat*> it(_refSatMap);
882 while (it.hasNext()) {
883 it.next();
884 char sys = it.key();
885 t_prn prn = it.value()->prn();
886 t_prn refSatLastEpochPrn = t_prn();
887 if (epoch) {
888 refSatLastEpochPrn = refSatMapLastEpoch[sys]->prn();
889 }
890 if (prn.number() == 0) { // no obs for that system available
891 continue;
892 }
893 else if (prn.number() == 99) { // refSat re-definition not possible
894 LOG << " => refSat re-definition impossible: " << sys << endl;
895 return failure;
896 }
897 QString str;
898 if (prn == refSatLastEpochPrn || refSatLastEpochPrn == t_prn() ) {
899 _obsPool->setRefSatChanged(sys, false);
900 str = " SET ";
901 }
902 else {
903 _obsPool->setRefSatChanged(sys, true);
904 str = " RESET ";
905 }
906 LOG << string(_epoTimeRover) << str.toStdString() << " REFSAT " << sys << ": " << prn.toString() << endl;
907 }
908 return success;
909}
910
911void t_pppClient::setHistoricalRefSats() {
912 QMapIterator<char, t_pppRefSat*> it(_refSatMap);
913 while (it.hasNext()) {
914 it.next();
915 t_prn prn = it.value()->prn();
916 char sys = prn.system();
917 if (_obsPool->refSatChangeRequired(sys)){
918 _historicalRefSats[sys].append(prn);
919 }
920 }
921}
922
923//
924//////////////////////////////////////////////////////////////////////////////
925void t_pppClient::reset() {
926
927 // to delete old orbit and clock corrections
928 delete _ephPool;
929 _ephPool = new t_pppEphPool();
930
931 // to delete old code biases
932 delete _obsPool;
933 _obsPool = new t_pppObsPool();
934
935 // to delete all parameters
936 delete _filter;
937 _filter = new t_pppFilter(_obsPool);
938
939}
Note: See TracBrowser for help on using the repository browser.