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

Last change on this file since 11215 was 11215, checked in by stuerze, 43 minutes ago

Upload Ephemeris: majority vote included

  • Property svn:keywords set to Author Date Id Rev URL;svn:eol-style=native
  • Property svn:mime-type set to text/plain
File size: 23.5 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 _ssrFormat = ssrUnknown;
62 if (!_opt->_antexFileName.empty()) {
63 _antex = new bncAntex(_opt->_antexFileName.c_str());
64 *_log << _antex->info().toStdString() << endl;
65 }
66 if (!_opt->_blqFileName.empty()) {
67 if (_tides->readBlqFile(_opt->_blqFileName.c_str()) == success) {
68 //_tides->printAllBlqSets();
69 }
70 }
71 CLIENTS.setLocalData(this); // CLIENTS takes ownership over "this"
72}
73
74// Destructor
75//////////////////////////////////////////////////////////////////////////////
76t_pppClient::~t_pppClient() {
77 _running = false;
78 delete _log;
79 delete _opt;
80 delete _ephPool;
81 delete _obsPool;
82 delete _staRover;
83 if (_antex) {
84 delete _antex;
85 }
86 delete _filter;
87 delete _tides;
88 clearObs();
89}
90
91//
92//////////////////////////////////////////////////////////////////////////////
93void t_pppClient::putEphemeris(const t_eph* eph) {
94 if (eph->prn().toInt() == 0) { // satellite outside the range supported by BNC (e.g. G39)
95 return;
96 }
97 const t_ephGPS* ephGPS = dynamic_cast<const t_ephGPS*>(eph);
98 const t_ephGlo* ephGlo = dynamic_cast<const t_ephGlo*>(eph);
99 const t_ephGal* ephGal = dynamic_cast<const t_ephGal*>(eph);
100 const t_ephBDS* ephBDS = dynamic_cast<const t_ephBDS*>(eph);
101 if (ephGPS) {
102 _ephPool->putEphemeris(new t_ephGPS(*ephGPS));
103 }
104 else if (ephGlo) {
105 _ephPool->putEphemeris(new t_ephGlo(*ephGlo));
106 }
107 else if (ephGal) {
108 // SSR corrections of all formats refer to Galileo I/NAV. The pool matches
109 // corrections by IOD only and keeps one ephemeris per TOC, so an F/NAV set
110 // with the same IODnav (different clock parameters) must not get in.
111 if (ephGal->type() == t_eph::INAV) {
112 _ephPool->putEphemeris(new t_ephGal(*ephGal));
113 }
114 }
115 else if (ephBDS) {
116 _ephPool->putEphemeris(new t_ephBDS(*ephBDS));
117 }
118}
119
120//
121//////////////////////////////////////////////////////////////////////////////
122void t_pppClient::putTec(const t_vTec* vTec) {
123 _obsPool->putTec(new t_vTec(*vTec));
124}
125
126//
127//////////////////////////////////////////////////////////////////////////////
128void t_pppClient::putMetaData(const t_metaData* metaData) {
129 _obsPool->putMetaData(new t_metaData(*metaData));
130}
131
132//
133//////////////////////////////////////////////////////////////////////////////
134void t_pppClient::putOrbCorrections(const vector<t_orbCorr*>& corr) {
135 if (OPT->_logMode == t_pppOptions::normal && corr.size() > 0) {
136 LOG << "orbCorrections " << string(corr[0]->_time) << ' ' << corr.size() << endl;
137 }
138 for (unsigned ii = 0; ii < corr.size(); ii++) {
139 _ssrFormat = corr[ii]->_ssrFormat;
140 _ephPool->putOrbCorrection(new t_orbCorr(*corr[ii]));
141 }
142}
143
144//
145//////////////////////////////////////////////////////////////////////////////
146void t_pppClient::putClkCorrections(const vector<t_clkCorr*>& corr) {
147 if (OPT->_logMode == t_pppOptions::normal && corr.size() > 0) {
148 LOG << "clkCorrections " << string(corr[0]->_time) << ' ' << corr.size() << endl;
149 }
150 for (unsigned ii = 0; ii < corr.size(); ii++) {
151 _ephPool->putClkCorrection(new t_clkCorr(*corr[ii]));
152 }
153}
154
155//
156//////////////////////////////////////////////////////////////////////////////
157void t_pppClient::putCodeBiases(const vector<t_satCodeBias*>& biases) {
158 if (OPT->_logMode == t_pppOptions::normal && biases.size() > 0) {
159 LOG << "codeBiases " << string(biases[0]->_time) << ' ' << biases.size() << endl;
160 }
161 set<char> systems;
162 for (unsigned ii = 0; ii < biases.size(); ii++) {
163 t_satCodeBias* newBias = new t_satCodeBias(*biases[ii]);
164 char sys = newBias->_prn.system();
165 if (systems.find(sys) == systems.end()) {
166 _obsPool->clearCodeBiases(sys);
167 systems.insert(sys);
168 }
169 _obsPool->putCodeBias(newBias);
170 }
171}
172
173//
174//////////////////////////////////////////////////////////////////////////////
175void t_pppClient::putSatAntennas(const vector<t_satAntenna*>& satAntennas) {
176 if (OPT->_logMode == t_pppOptions::normal && satAntennas.size() > 0) {
177 LOG << "satAntennas " << string(satAntennas[0]->_time) << ' ' << satAntennas.size() << endl;
178 }
179 for (unsigned ii = 0; ii < satAntennas.size(); ii++) {
180 _obsPool->putSatAntenna(new t_satAntenna(*satAntennas[ii]));
181 }
182}
183
184//
185//////////////////////////////////////////////////////////////////////////////
186void t_pppClient::putPhaseBiases(const vector<t_satPhaseBias*>& biases) {
187 if (OPT->_logMode == t_pppOptions::normal && biases.size() > 0) {
188 LOG << "phaseBiases " << string(biases[0]->_time) << ' ' << biases.size() << endl;
189 }
190 set<char> systems;
191 for (unsigned ii = 0; ii < biases.size(); ii++) {
192 t_satPhaseBias* newBias = new t_satPhaseBias(*biases[ii]);
193 char sys = newBias->_prn.system();
194 if (systems.find(sys) == systems.end()) {
195 _obsPool->clearPhaseBiases(sys);
196 systems.insert(sys);
197 }
198 _obsPool->putPhaseBias(newBias);
199 }
200}
201
202//
203//////////////////////////////////////////////////////////////////////////////
204t_irc t_pppClient::prepareObs(const vector<t_satObs*>& satObs,
205 vector<t_pppSatObs*>& obsVector, bncTime& epoTime) {
206
207 // Default
208 // -------
209 epoTime.reset();
210 clearObs();
211
212 // Create vector of valid observations
213 // -----------------------------------
214 for (unsigned ii = 0; ii < satObs.size(); ii++) {
215 char sys = satObs[ii]->_prn.system();
216 if (_opt->useSystem(sys)) {
217 t_pppSatObs* pppSatObs = new t_pppSatObs(*satObs[ii]);
218 if (pppSatObs->isValid()) {
219 obsVector.push_back(pppSatObs);
220 }
221 else {
222 delete pppSatObs;
223 }
224 }
225 }
226
227 // Check whether data are synchronized, compute epoTime
228 // ----------------------------------------------------
229 const double MAXSYNC = 0.05; // synchronization limit
230 double meanDt = 0.0;
231 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
232 const t_pppSatObs* satObs = obsVector.at(ii);
233 if (epoTime.undef()) {
234 epoTime = satObs->time();
235 }
236 else {
237 double dt = satObs->time() - epoTime;
238 if (fabs(dt) > MAXSYNC) {
239 LOG << "t_pppClient::prepareObs asynchronous observations" << endl;
240 return failure;
241 }
242 meanDt += dt;
243 }
244 }
245
246 if (obsVector.size() > 0) {
247 epoTime += meanDt / obsVector.size();
248 }
249
250 return success;
251}
252
253//
254//////////////////////////////////////////////////////////////////////////////
255bool t_pppClient::preparePseudoObs(std::vector<t_pppSatObs*>& obsVector) {
256
257 bool pseudoObsIono = false;
258
259 if (_opt->_pseudoObsIono) {
260
261 // Select reference satellite per system: keep the current one if still
262 // visible; only switch to highest elevation when the current one disappears
263 // -------------------------------------------------------------------------
264 map<char, t_pppSatObs*> refSatMap;
265 map<char, t_pppSatObs*> bestEleMap;
266 for (t_pppSatObs* satObs : obsVector) {
267 satObs->resetReference();
268 double stec = satObs->getIonoCodeDelay(t_frequency::G1);
269 if (stec == 0.0) continue;
270 char sys = satObs->prn().system();
271 if (!bestEleMap.count(sys) || satObs->eleSat() > bestEleMap[sys]->eleSat()) {
272 bestEleMap[sys] = satObs;
273 }
274 if (_refPrnMap.count(sys) && satObs->prn() == _refPrnMap[sys]) {
275 refSatMap[sys] = satObs;
276 }
277 }
278 for (auto& kv : bestEleMap) {
279 if (!refSatMap.count(kv.first)) {
280 refSatMap[kv.first] = kv.second;
281 }
282 }
283 for (auto& kv : refSatMap) {
284 _refPrnMap[kv.first] = kv.second->prn();
285 kv.second->setAsReference();
286 }
287
288 if (bestEleMap.empty()) {
289 LOG << "GIM pseudo-obs unavailable: no valid STEC (vTec data missing?)" << endl;
290 }
291
292 // Set STEC pseudo-observations (single-differenced vs reference satellite)
293 // -------------------------------------------------------------------------
294 int nGIM = 0;
295 for (t_pppSatObs* satObs : obsVector) {
296 char sys = satObs->prn().system();
297 double stecRefSat = refSatMap.count(sys)
298 ? refSatMap[sys]->getIonoCodeDelay(t_frequency::G1)
299 : 0.0;
300 if (satObs->setPseudoObsIono(t_frequency::G1, stecRefSat)) {
301 pseudoObsIono = true;
302 nGIM++;
303 }
304 }
305 if (nGIM > 0) {
306 LOG << "GIM pseudo-obs: " << nGIM << " satellites, ref:";
307 for (auto& kv : refSatMap) {
308 LOG << ' ' << kv.second->prn().toString();
309 }
310 LOG << endl;
311 }
312 }
313
314 if (OPT->_logMode == t_pppOptions::all) {
315 vector<t_pppSatObs*>::iterator it = obsVector.begin();
316 while (it != obsVector.end()) {
317 t_pppSatObs* satObs = *it;
318 satObs->printObsMinusComputed();
319 it++;
320 }
321 }
322 return pseudoObsIono;
323}
324
325// Compute the Bancroft position, check for blunders
326//////////////////////////////////////////////////////////////////////////////
327t_irc t_pppClient::cmpBancroft(const bncTime& epoTime,
328 vector<t_pppSatObs*>& obsVector,
329 ColumnVector& xyzc, bool print) {
330
331 int numBancroft = obsVector.size();
332
333 while (_running) {
334 Matrix BB(numBancroft, 4);
335 int iObs = -1;
336 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
337 const t_pppSatObs* satObs = obsVector.at(ii);
338 t_lc LC = satObs->rangeLC();
339 if ( satObs->isValid(LC) &&
340 (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle) ) {
341 ++iObs;
342 BB[iObs][0] = satObs->xc()[0];
343 BB[iObs][1] = satObs->xc()[1];
344 BB[iObs][2] = satObs->xc()[2];
345 BB[iObs][3] = satObs->obsValue(LC) - satObs->cmpValueForBanc(LC);
346 }
347 }
348 if (iObs + 1 < _opt->_minObs) {
349 LOG << "t_pppClient::cmpBancroft not enough observations: " << iObs + 1 << endl;
350 return failure;
351 }
352 BB = BB.Rows(1,iObs+1);
353 if (bancroft(BB, xyzc) != success) {
354 return failure;
355 }
356
357 xyzc[3] /= t_CST::c;
358
359 // Check Blunders
360 // --------------
361 const double BLUNDER = 1500.0;
362 double maxRes = 0.0;
363 unsigned maxResIndex = 0;
364 for (unsigned ii = 0; ii < obsVector.size(); ii++) {
365 const t_pppSatObs* satObs = obsVector.at(ii);
366 t_lc LC = satObs->rangeLC();
367 if (satObs->isValid(LC) &&
368 (!satObs->modelSet() || satObs->eleSat() >= _opt->_minEle) ) {
369 ColumnVector rr = satObs->xc().Rows(1,3) - xyzc.Rows(1,3);
370 double res = rr.NormFrobenius() - satObs->obsValue(LC)
371 - (satObs->xc()[3] - xyzc[3]) * t_CST::c;
372 if (fabs(res) > maxRes) {
373 maxRes = fabs(res);
374 maxResIndex = ii;
375 }
376 }
377 }
378 if (maxRes < BLUNDER) {
379 if (print) {
380 LOG.setf(ios::fixed);
381 LOG << "\nPPP of Epoch ";
382 if (!_epoTimeRover.undef()) LOG << string(_epoTimeRover);
383 LOG << " using " << _opt->_corrMount;
384 LOG << "\n---------------------------------------------------------------\n";
385 LOG << string(epoTime) << " BANCROFT: "
386 << setw(14) << setprecision(3) << xyzc[0] << ' '
387 << setw(14) << setprecision(3) << xyzc[1] << ' '
388 << setw(14) << setprecision(3) << xyzc[2] << ' '
389 << setw(14) << setprecision(3) << xyzc[3] * t_CST::c << endl << endl;
390 }
391 break;
392 }
393 else {
394 t_pppSatObs* satObs = obsVector.at(maxResIndex);
395 LOG << "t_pppClient::cmpBancroft Outlier " << satObs->prn().toString()
396 << " " << maxRes << endl;
397 delete satObs;
398 obsVector.erase(obsVector.begin() + maxResIndex);
399 }
400 }
401
402 return success;
403}
404
405//
406//////////////////////////////////////////////////////////////////////////////
407void t_pppClient::initOutput(t_output* output) {
408 _output = output;
409 _output->_numSat = 0;
410 _output->_hDop = 0.0;
411 _output->_resRmsCode = 0.0;
412 _output->_resRmsPhase = 0.0;
413 _output->_error = false;
414}
415
416//
417//////////////////////////////////////////////////////////////////////////////
418void t_pppClient::clearObs() {
419 for (unsigned ii = 0; ii < _obsRover.size(); ii++) {
420 delete _obsRover.at(ii);
421 }
422 _obsRover.clear();
423}
424
425//
426//////////////////////////////////////////////////////////////////////////////
427void t_pppClient::finish(t_irc irc, int ind) {
428#ifdef BNC_DEBUG_PPP
429 LOG << "t_pppClient::finish(" << ind << "): " << irc << endl;
430#endif
431
432 clearObs();
433
434 _output->_epoTime = _epoTimeRover;
435
436 if (irc == success) {
437 _output->_xyzRover[0] = _staRover->xyzApr()[0] + _filter->x()[0];
438 _output->_xyzRover[1] = _staRover->xyzApr()[1] + _filter->x()[1];
439 _output->_xyzRover[2] = _staRover->xyzApr()[2] + _filter->x()[2];
440
441 xyz2neu(_staRover->ellApr().data(), _filter->x().data(), _output->_neu);
442
443 copy(&_filter->Q().data()[0], &_filter->Q().data()[6], _output->_covMatrix);
444
445 _output->_trp0 = t_tropo::delay_saast(_staRover->xyzApr(), M_PI/2.0);
446 _output->_trp = _filter->trp();
447 _output->_trpStdev = _filter->trpStdev();
448
449 _output->_fixRatio = _filter->fixRatio();
450
451 _output->_numSat = _filter->numSat();
452 _output->_hDop = _filter->HDOP();
453 _output->_resRmsCode = _filter->resRmsCode();
454 _output->_resRmsPhase = _filter->resRmsPhase();
455 _output->_error = false;
456 }
457 else {
458 _output->_error = true;
459 }
460
461 _output->_log = _log->str();
462 delete _log; _log = new ostringstream();
463
464 return;
465}
466
467//
468//////////////////////////////////////////////////////////////////////////////
469t_irc t_pppClient::cmpModel(t_pppStation* station, const ColumnVector& xyzc,
470 vector<t_pppSatObs*>& obsVector) {
471 bncTime time;
472 time = _epoTimeRover;
473 station->setName(_opt->_roverName);
474 station->setAntName(_opt->_antNameRover);
475 station->setEpochTime(time);
476
477 if (_opt->xyzAprRoverSet()) {
478 if (_opt->_refEpochRover != 0.0) {
479 double dt = decimalYear(time) - _opt->_refEpochRover;
480 station->setXyzApr(_opt->_xyzAprRover + dt * _opt->_velRover);
481 }
482 else {
483 station->setXyzApr(_opt->_xyzAprRover);
484 }
485 }
486 else {
487 station->setXyzApr(xyzc.Rows(1,3));
488 }
489 station->setNeuEcc(_opt->_neuEccRover);
490
491 // Receiver Clock
492 // --------------
493 station->setDClk(xyzc[3]);
494
495 // Tides
496 // -----
497 // RTCM-SSR Metadata (model correction type 3 = solid earth tides) tells us
498 // whether - and with which model - the correction stream's generation
499 // system already accounted for solid earth tides. To stay consistent with
500 // the orbit/clock corrections, mirror that choice here: skip our own
501 // correction if the provider applied none, apply our default model if the
502 // provider used its own default, and fall back to our default (with a
503 // warning) if the provider used some other, unsupported model - we have no
504 // way to reproduce an unknown model exactly. Absent any Metadata message
505 // (e.g. RTNET or older streams), keep today's unconditional behavior.
506 bool applyEarthTide = true;
507 const t_metaData* metaData = _obsPool->metaData();
508 if (metaData) {
509 for (unsigned ii = 0; ii < metaData->_entries.size(); ii++) {
510 const t_metaDataEntry& entry = metaData->_entries[ii];
511 if (entry._typeIndicator == 3) { // solid earth tides
512 if (!entry._applicationIndicator) {
513 applyEarthTide = false;
514 }
515 else if (entry._nonDefaultIndicator) {
516 LOG << "WARNING: SSR Metadata signals a non-default solid earth "
517 << "tide model (identifier " << entry._nonDefaultIdentifier
518 << "); applying BNC's default model anyway, results may be "
519 << "inconsistent" << endl;
520 }
521 break;
522 }
523 }
524 }
525 if (applyEarthTide) {
526 station->setTideDsplEarth(_tides->earth(time, station->xyzApr()));
527 }
528 else {
529 ColumnVector tideDsplEarth(3); tideDsplEarth = 0.0;
530 station->setTideDsplEarth(tideDsplEarth);
531 }
532 station->setTideDsplOcean(_tides->ocean(time, station->xyzApr(), station->name()));
533
534 // Observation model
535 // -----------------
536 vector<t_pppSatObs*>::iterator it = obsVector.begin();
537 while (it != obsVector.end()) {
538 t_pppSatObs* satObs = *it;
539 t_irc modelSetup;
540 if (satObs->isValid()) {
541 modelSetup = satObs->cmpModel(station);
542 }
543 if (satObs->isValid() &&
544 satObs->eleSat() >= _opt->_minEle &&
545 modelSetup == success) {
546 ++it;
547 }
548 else {
549 delete satObs;
550 it = obsVector.erase(it);
551 }
552 }
553
554 return success;
555}
556
557//
558//////////////////////////////////////////////////////////////////////////////
559void t_pppClient::processEpoch(const vector<t_satObs*>& satObs, t_output* output) {
560
561 try {
562 initOutput(output);
563
564 // Prepare Observations of the Rover
565 // ---------------------------------
566 if (prepareObs(satObs, _obsRover, _epoTimeRover) != success) {
567 return finish(failure, 1);
568 }
569
570 // a changed ANTEX file is read and used from its GPS week on
571 if (_antex) {
572 QString msg = _antexReloader.update(_antex, _epoTimeRover);
573 if (!msg.isEmpty()) {
574 LOG << string(_epoTimeRover) << " " << msg.toStdString() << endl;
575 }
576 }
577
578 for (int iter = 1; iter <= 2; iter++) {
579 ColumnVector xyzc(4); xyzc = 0.0;
580 bool print = (iter == 2);
581 if (cmpBancroft(_epoTimeRover, _obsRover, xyzc, print) != success) {
582 return finish(failure, 2);
583 }
584 if (cmpModel(_staRover, xyzc, _obsRover) != success) {
585 return finish(failure, 3);
586 }
587 }
588
589 // Use observations only if satellite code biases are available
590 // ------------------------------------------------------------
591 if (_opt->ambRes()) {
592 useObsWithBiasesOnly(_obsRover);
593 }
594
595 if (int(_obsRover.size()) < _opt->_minObs) {
596 LOG << "t_pppClient::processEpoch not enough observations" << endl;
597 return finish(failure, 4);
598 }
599
600 // Prepare Pseudo Observations of the Rover
601 // ----------------------------------------
602 _pseudoObsIono = preparePseudoObs(_obsRover);
603
604 // Store last epoch of data
605 // ------------------------
606 _obsPool->putEpoch(_epoTimeRover, _obsRover, _pseudoObsIono);
607
608 // Process Epoch in Filter
609 // -----------------------
610 if (_filter->processEpoch(_obsPool) != success) {
611 LOG << "t_pppFilter::processEpoch() != success" << endl;
612 return finish(failure, 5);
613 }
614 }
615 catch (Exception& exc) {
616 LOG << exc.what() << endl;
617 // A failed Kalman update (e.g. non-positive-definite covariance) leaves
618 // the filter state unusable and would be carried into every subsequent
619 // epoch => restart the filter, keeping ephemerides and corrections
620 // ----------------------------------------------------------------------
621 LOG << string(_epoTimeRover) << " pppClient: filter reset after exception" << endl;
622 delete _filter;
623 _filter = new t_pppFilter();
624 return finish(failure, 6);
625 }
626 catch (t_except msg) {
627 LOG << msg.what() << endl;
628 return finish(failure, 7);
629 }
630 catch (const char* msg) {
631 LOG << msg << endl;
632 return finish(failure, 8);
633 }
634 catch (...) {
635 LOG << "unknown exception" << endl;
636 return finish(failure, 9);
637 }
638 return finish(success, 0);
639}
640
641//
642////////////////////////////////////////////////////////////////////////////
643double lorentz(const ColumnVector& aa, const ColumnVector& bb) {
644 return aa[0]*bb[0] + aa[1]*bb[1] + aa[2]*bb[2] - aa[3]*bb[3];
645}
646
647//
648////////////////////////////////////////////////////////////////////////////
649t_irc t_pppClient::bancroft(const Matrix& BBpass, ColumnVector& pos) {
650
651 if (pos.Nrows() != 4) {
652 pos.ReSize(4);
653 }
654 pos = 0.0;
655
656 for (int iter = 1; iter <= 2; iter++) {
657 Matrix BB = BBpass;
658 int mm = BB.Nrows();
659 for (int ii = 1; ii <= mm; ii++) {
660 double xx = BB(ii,1);
661 double yy = BB(ii,2);
662 double traveltime = 0.072;
663 if (iter > 1) {
664 double zz = BB(ii,3);
665 double rho = sqrt( (xx-pos(1)) * (xx-pos(1)) +
666 (yy-pos(2)) * (yy-pos(2)) +
667 (zz-pos(3)) * (zz-pos(3)) );
668 traveltime = rho / t_CST::c;
669 }
670 double angle = traveltime * t_CST::omega;
671 double cosa = cos(angle);
672 double sina = sin(angle);
673 BB(ii,1) = cosa * xx + sina * yy;
674 BB(ii,2) = -sina * xx + cosa * yy;
675 }
676
677 Matrix BBB;
678 if (mm > 4) {
679 SymmetricMatrix hlp; hlp << BB.t() * BB;
680 BBB = hlp.i() * BB.t();
681 }
682 else {
683 BBB = BB.i();
684 }
685 ColumnVector ee(mm); ee = 1.0;
686 ColumnVector alpha(mm); alpha = 0.0;
687 for (int ii = 1; ii <= mm; ii++) {
688 alpha(ii) = lorentz(BB.Row(ii).t(),BB.Row(ii).t())/2.0;
689 }
690 ColumnVector BBBe = BBB * ee;
691 ColumnVector BBBalpha = BBB * alpha;
692 double aa = lorentz(BBBe, BBBe);
693 double bb = lorentz(BBBe, BBBalpha)-1;
694 double cc = lorentz(BBBalpha, BBBalpha);
695 double root = sqrt(bb*bb-aa*cc);
696
697 Matrix hlpPos(4,2);
698 hlpPos.Column(1) = (-bb-root)/aa * BBBe + BBBalpha;
699 hlpPos.Column(2) = (-bb+root)/aa * BBBe + BBBalpha;
700
701 ColumnVector omc(2);
702 for (int pp = 1; pp <= 2; pp++) {
703 hlpPos(4,pp) = -hlpPos(4,pp);
704 omc(pp) = BB(1,4) -
705 sqrt( (BB(1,1)-hlpPos(1,pp)) * (BB(1,1)-hlpPos(1,pp)) +
706 (BB(1,2)-hlpPos(2,pp)) * (BB(1,2)-hlpPos(2,pp)) +
707 (BB(1,3)-hlpPos(3,pp)) * (BB(1,3)-hlpPos(3,pp)) ) -
708 hlpPos(4,pp);
709 }
710 if ( fabs(omc(1)) > fabs(omc(2)) ) {
711 pos = hlpPos.Column(2);
712 }
713 else {
714 pos = hlpPos.Column(1);
715 }
716 }
717 if (pos.size() != 4 ||
718 std::isnan(pos(1)) ||
719 std::isnan(pos(2)) ||
720 std::isnan(pos(3)) ||
721 std::isnan(pos(4))) {
722 return failure;
723 }
724
725 return success;
726}
727
728//
729//////////////////////////////////////////////////////////////////////////////
730void t_pppClient::reset() {
731
732 LOG << "pppClient: reset" << endl;
733 _refPrnMap.clear();
734 // to delete old orbit and clock corrections
735 delete _ephPool;
736 _ephPool = new t_pppEphPool();
737
738 // to delete old biases
739 delete _obsPool;
740 _obsPool = new t_pppObsPool();
741
742 // to delete all parameters
743 delete _filter;
744 _filter = new t_pppFilter();
745
746}
747
748//
749//////////////////////////////////////////////////////////////////////////////
750void t_pppClient::useObsWithBiasesOnly(vector<t_pppSatObs*>& obsVector) const {
751 vector<t_pppSatObs*>::iterator it = obsVector.begin();
752 while (it != obsVector.end()) {
753 t_pppSatObs* pppSatObs = *it;
754 if (pppSatObs->hasBiases()) {
755 ++it;
756 }
757 else {
758 LOG << "t_pppClient::useObsWithBiasesOnly: no biases: " << pppSatObs->prn().toString().c_str() << endl;
759 it = obsVector.erase(it);
760 delete pppSatObs;
761 }
762 }
763}
Note: See TracBrowser for help on using the repository browser.