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

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