| 1 |
|
|---|
| 2 | // Part of BNC, a utility for retrieving decoding and
|
|---|
| 3 | // converting GNSS data streams from NTRIP broadcasters.
|
|---|
| 4 | //
|
|---|
| 5 | // Copyright (C) 2007
|
|---|
| 6 | // German Federal Agency for Cartography and Geodesy (BKG)
|
|---|
| 7 | // http://www.bkg.bund.de
|
|---|
| 8 | // Czech Technical University Prague, Department of Geodesy
|
|---|
| 9 | // http://www.fsv.cvut.cz
|
|---|
| 10 | //
|
|---|
| 11 | // Email: euref-ip@bkg.bund.de
|
|---|
| 12 | //
|
|---|
| 13 | // This program is free software; you can redistribute it and/or
|
|---|
| 14 | // modify it under the terms of the GNU General Public License
|
|---|
| 15 | // as published by the Free Software Foundation, version 2.
|
|---|
| 16 | //
|
|---|
| 17 | // This program is distributed in the hope that it will be useful,
|
|---|
| 18 | // but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 19 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 20 | // GNU General Public License for more details.
|
|---|
| 21 | //
|
|---|
| 22 | // You should have received a copy of the GNU General Public License
|
|---|
| 23 | // along with this program; if not, write to the Free Software
|
|---|
| 24 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|---|
| 25 |
|
|---|
| 26 | /* -------------------------------------------------------------------------
|
|---|
| 27 | * BKG NTRIP Client
|
|---|
| 28 | * -------------------------------------------------------------------------
|
|---|
| 29 | *
|
|---|
| 30 | * Class: t_pppClient
|
|---|
| 31 | *
|
|---|
| 32 | * Purpose: PPP Client processing starts here
|
|---|
| 33 | *
|
|---|
| 34 | * Author: L. Mervart
|
|---|
| 35 | *
|
|---|
| 36 | * Created: 29-Jul-2014
|
|---|
| 37 | *
|
|---|
| 38 | * Changes:
|
|---|
| 39 | *
|
|---|
| 40 | * -----------------------------------------------------------------------*/
|
|---|
| 41 |
|
|---|
| 42 | #include <QThreadStorage>
|
|---|
| 43 |
|
|---|
| 44 | #include <iostream>
|
|---|
| 45 | #include <iomanip>
|
|---|
| 46 | #include <stdlib.h>
|
|---|
| 47 | #include <string.h>
|
|---|
| 48 | #include <stdexcept>
|
|---|
| 49 |
|
|---|
| 50 | #include "pppClient.h"
|
|---|
| 51 | #include "ephpool.h"
|
|---|
| 52 | #include "obspool.h"
|
|---|
| 53 | #include "satbias.h"
|
|---|
| 54 | #include "bncconst.h"
|
|---|
| 55 | #include "bncutils.h"
|
|---|
| 56 | #include "station.h"
|
|---|
| 57 | #include "bnctides.h"
|
|---|
| 58 | #include "bncantex.h"
|
|---|
| 59 | #include "filter.h"
|
|---|
| 60 |
|
|---|
| 61 | using namespace BNC;
|
|---|
| 62 | using namespace std;
|
|---|
| 63 |
|
|---|
| 64 | // Global variable holding thread-specific pointers
|
|---|
| 65 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 66 | QThreadStorage<t_pppClient*> CLIENTS;
|
|---|
| 67 |
|
|---|
| 68 | // Static function returning thread-specific pointer
|
|---|
| 69 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 70 | t_pppClient* t_pppClient::instance() {
|
|---|
| 71 | return CLIENTS.localData();
|
|---|
| 72 | }
|
|---|
| 73 |
|
|---|
| 74 | // Constructor
|
|---|
| 75 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 76 | t_pppClient::t_pppClient(const t_options* opt) {
|
|---|
| 77 | _output = 0;
|
|---|
| 78 | _opt = new t_options(*opt);
|
|---|
| 79 | _log = new ostringstream();
|
|---|
| 80 | _ephPool = new t_ephPool();
|
|---|
| 81 | _obsPool = new t_obsPool();
|
|---|
| 82 | _staRover = new t_station();
|
|---|
| 83 | _filter = new t_filter();
|
|---|
| 84 |
|
|---|
| 85 | if (!_opt->_antexFile.empty()) {
|
|---|
| 86 | _antex = new bncAntex(_opt->_antexFile.c_str());
|
|---|
| 87 | }
|
|---|
| 88 | else {
|
|---|
| 89 | _antex = 0;
|
|---|
| 90 | }
|
|---|
| 91 |
|
|---|
| 92 | CLIENTS.setLocalData(this); // CLIENTS takes ownership over "this"
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | // Destructor
|
|---|
| 96 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 97 | t_pppClient::~t_pppClient() {
|
|---|
| 98 | cout << "~t_pppClient" << endl;
|
|---|
| 99 | delete _log;
|
|---|
| 100 | delete _opt;
|
|---|
| 101 | delete _ephPool;
|
|---|
| 102 | delete _obsPool;
|
|---|
| 103 | delete _staRover;
|
|---|
| 104 | delete _antex;
|
|---|
| 105 | delete _filter;
|
|---|
| 106 | clearObs();
|
|---|
| 107 | }
|
|---|
| 108 |
|
|---|
| 109 | //
|
|---|
| 110 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 111 | void t_pppClient::putGPSEphemeris(const t_ephGPS* eph) {
|
|---|
| 112 | cout << "t_pppClient::putGPSEphemeris " << PPP_CLIENT << endl;
|
|---|
| 113 | _ephPool->putEphemeris(new t_ephGPS(*eph));
|
|---|
| 114 | }
|
|---|
| 115 |
|
|---|
| 116 | //
|
|---|
| 117 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 118 | void t_pppClient::putGloEphemeris(const t_ephGlo* eph) {
|
|---|
| 119 | _ephPool->putEphemeris(new t_ephGlo(*eph));
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | //
|
|---|
| 123 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 124 | void t_pppClient::putOrbCorrections(int numCorr, const t_orbCorr* corr) {
|
|---|
| 125 | for (int ii = 0; ii < numCorr; ii++) {
|
|---|
| 126 | _ephPool->putOrbCorrection(new t_orbCorr(corr[ii]));
|
|---|
| 127 | }
|
|---|
| 128 | }
|
|---|
| 129 |
|
|---|
| 130 | //
|
|---|
| 131 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 132 | void t_pppClient::putClkCorrections(int numCorr, const t_clkCorr* corr) {
|
|---|
| 133 | for (int ii = 0; ii < numCorr; ii++) {
|
|---|
| 134 | _ephPool->putClkCorrection(new t_clkCorr(corr[ii]));
|
|---|
| 135 | }
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | //
|
|---|
| 139 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 140 | void t_pppClient::putBiases(int numBiases, const t_satBiases* biases) {
|
|---|
| 141 | for (int ii = 0; ii < numBiases; ii++) {
|
|---|
| 142 | _obsPool->putBiases(new t_satBias(biases[ii]));
|
|---|
| 143 | }
|
|---|
| 144 | }
|
|---|
| 145 |
|
|---|
| 146 | //
|
|---|
| 147 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 148 | t_irc t_pppClient::prepareObs(int numSat, const t_pppSatObs* satObs,
|
|---|
| 149 | vector<t_satObs*>& obsVector, bncTime& epoTime) {
|
|---|
| 150 | // Default
|
|---|
| 151 | // -------
|
|---|
| 152 | epoTime.reset();
|
|---|
| 153 |
|
|---|
| 154 | // Create vector of valid observations
|
|---|
| 155 | // -----------------------------------
|
|---|
| 156 | int numValidGPS = 0;
|
|---|
| 157 | for (int ii = 0; ii < numSat; ii++) {
|
|---|
| 158 | char system = satObs[ii]._prn.system();
|
|---|
| 159 | if (system == 'G' || (system == 'R' && OPT->useGlonass())) {
|
|---|
| 160 | t_satObs* satObs = new t_satObs(satObs[ii]);
|
|---|
| 161 | if (satObs->isValid()) {
|
|---|
| 162 | obsVector.push_back(satObs);
|
|---|
| 163 | if (satObs->prn().system() == 'G') {
|
|---|
| 164 | ++numValidGPS;
|
|---|
| 165 | }
|
|---|
| 166 | }
|
|---|
| 167 | else {
|
|---|
| 168 | delete satObs;
|
|---|
| 169 | }
|
|---|
| 170 | }
|
|---|
| 171 | }
|
|---|
| 172 |
|
|---|
| 173 | // Check whether data are synchronized, compute epoTime
|
|---|
| 174 | // ----------------------------------------------------
|
|---|
| 175 | const double MAXSYNC = 0.05; // synchronization limit
|
|---|
| 176 | double meanDt = 0.0;
|
|---|
| 177 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
|---|
| 178 | const t_satObs* satObs = obsVector.at(ii);
|
|---|
| 179 | if (epoTime.undef()) {
|
|---|
| 180 | epoTime = satObs->time();
|
|---|
| 181 | }
|
|---|
| 182 | else {
|
|---|
| 183 | double dt = satObs->time() - epoTime;
|
|---|
| 184 | if (fabs(dt) > MAXSYNC) {
|
|---|
| 185 | LOG << "t_pppClient::prepareObs asynchronous observations" << endl;
|
|---|
| 186 | return failure;
|
|---|
| 187 | }
|
|---|
| 188 | meanDt += dt;
|
|---|
| 189 | }
|
|---|
| 190 | }
|
|---|
| 191 | epoTime += meanDt / obsVector.size();
|
|---|
| 192 |
|
|---|
| 193 | return success;
|
|---|
| 194 | }
|
|---|
| 195 |
|
|---|
| 196 | // Compute the Bancroft position, check for blunders
|
|---|
| 197 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 198 | t_irc t_pppClient::cmpBancroft(const bncTime& epoTime,
|
|---|
| 199 | vector<t_satObs*>& obsVector,
|
|---|
| 200 | ColumnVector& xyzc, bool print) {
|
|---|
| 201 |
|
|---|
| 202 | t_lc::type tLC = (OPT->dualFreqRequired() ? t_lc::cIF : t_lc::c1);
|
|---|
| 203 |
|
|---|
| 204 | while (true) {
|
|---|
| 205 | Matrix BB(obsVector.size(), 4);
|
|---|
| 206 | int iObs = -1;
|
|---|
| 207 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
|---|
| 208 | const t_satObs* satObs = obsVector.at(ii);
|
|---|
| 209 | if ( satObs->isValid() && satObs->prn().system() == 'G' &&
|
|---|
| 210 | (!satObs->modelSet() || satObs->eleSat() >= OPT->_minEle) ) {
|
|---|
| 211 | ++iObs;
|
|---|
| 212 | BB[iObs][0] = satObs->xc()[0];
|
|---|
| 213 | BB[iObs][1] = satObs->xc()[1];
|
|---|
| 214 | BB[iObs][2] = satObs->xc()[2];
|
|---|
| 215 | BB[iObs][3] = satObs->obsValue(tLC) - satObs->cmpValueForBanc(tLC);
|
|---|
| 216 | }
|
|---|
| 217 | }
|
|---|
| 218 | if (iObs + 1 < OPT->_minObs) {
|
|---|
| 219 | LOG << "t_pppClient::cmpBancroft not enough observations" << endl;
|
|---|
| 220 | return failure;
|
|---|
| 221 | }
|
|---|
| 222 | BB = BB.Rows(1,iObs+1);
|
|---|
| 223 | bancroft(BB, xyzc);
|
|---|
| 224 |
|
|---|
| 225 | xyzc[3] /= t_CST::c;
|
|---|
| 226 |
|
|---|
| 227 | // Check Blunders
|
|---|
| 228 | // --------------
|
|---|
| 229 | const double BLUNDER = 100.0;
|
|---|
| 230 | double maxRes = 0.0;
|
|---|
| 231 | unsigned maxResIndex = 0;
|
|---|
| 232 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
|---|
| 233 | const t_satObs* satObs = obsVector.at(ii);
|
|---|
| 234 | if ( satObs->isValid() && satObs->prn().system() == 'G' &&
|
|---|
| 235 | (!satObs->modelSet() || satObs->eleSat() >= OPT->_minEle) ) {
|
|---|
| 236 | ColumnVector rr = satObs->xc().Rows(1,3) - xyzc.Rows(1,3);
|
|---|
| 237 | double res = rr.norm_Frobenius() - satObs->obsValue(tLC)
|
|---|
| 238 | - (satObs->xc()[3] - xyzc[3]) * t_CST::c;
|
|---|
| 239 | if (fabs(res) > maxRes) {
|
|---|
| 240 | maxRes = fabs(res);
|
|---|
| 241 | maxResIndex = ii;
|
|---|
| 242 | }
|
|---|
| 243 | }
|
|---|
| 244 | }
|
|---|
| 245 | if (maxRes < BLUNDER) {
|
|---|
| 246 | if (print) {
|
|---|
| 247 | LOG.setf(ios::fixed);
|
|---|
| 248 | LOG << string(epoTime) << " BANCROFT:" << ' '
|
|---|
| 249 | << setw(14) << setprecision(3) << xyzc[0] << ' '
|
|---|
| 250 | << setw(14) << setprecision(3) << xyzc[1] << ' '
|
|---|
| 251 | << setw(14) << setprecision(3) << xyzc[2] << ' '
|
|---|
| 252 | << setw(14) << setprecision(3) << xyzc[3] * t_CST::c << endl << endl;
|
|---|
| 253 | }
|
|---|
| 254 | break;
|
|---|
| 255 | }
|
|---|
| 256 | else {
|
|---|
| 257 | t_satObs* satObs = obsVector.at(maxResIndex);
|
|---|
| 258 | LOG << "t_pppClient::cmpBancroft outlier " << satObs->prn().toString()
|
|---|
| 259 | << " " << maxRes << endl;
|
|---|
| 260 | delete satObs;
|
|---|
| 261 | obsVector.erase(obsVector.begin() + maxResIndex);
|
|---|
| 262 | }
|
|---|
| 263 | }
|
|---|
| 264 |
|
|---|
| 265 | return success;
|
|---|
| 266 | }
|
|---|
| 267 |
|
|---|
| 268 | // Compute A Priori GPS-Glonass Offset
|
|---|
| 269 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 270 | double t_pppClient::cmpOffGG(vector<t_satObs*>& obsVector) {
|
|---|
| 271 |
|
|---|
| 272 | t_lc::type tLC = (OPT->dualFreqRequired() ? t_lc::cIF : t_lc::c1);
|
|---|
| 273 | double offGG = 0.0;
|
|---|
| 274 |
|
|---|
| 275 | if (OPT->useGlonass()) {
|
|---|
| 276 | while (true) {
|
|---|
| 277 | offGG = 0.0;
|
|---|
| 278 | bool outlierFound = false;
|
|---|
| 279 | unsigned nObs = 0;
|
|---|
| 280 | for (unsigned ii = 0; ii < obsVector.size(); ii++) {
|
|---|
| 281 | t_satObs* satObs = obsVector.at(ii);
|
|---|
| 282 | if ( !satObs->outlier() && satObs->isValid() && satObs->prn().system() == 'R' &&
|
|---|
| 283 | (!satObs->modelSet() || satObs->eleSat() >= OPT->_minEle) ) {
|
|---|
| 284 | ++nObs;
|
|---|
| 285 | double ll = satObs->obsValue(tLC) - satObs->cmpValue(tLC);
|
|---|
| 286 | if (fabs(ll) > 1000.0) {
|
|---|
| 287 | satObs->setOutlier();
|
|---|
| 288 | outlierFound = true;
|
|---|
| 289 | LOG << "t_pppClient::cmpOffGG outlier " << satObs->prn().toString()
|
|---|
| 290 | << " " << ll << endl;
|
|---|
| 291 | }
|
|---|
| 292 | offGG += ll;
|
|---|
| 293 | }
|
|---|
| 294 | }
|
|---|
| 295 | if (nObs > 0) {
|
|---|
| 296 | offGG = offGG / nObs;
|
|---|
| 297 | }
|
|---|
| 298 | else {
|
|---|
| 299 | offGG = 0.0;
|
|---|
| 300 | }
|
|---|
| 301 | if (!outlierFound) {
|
|---|
| 302 | break;
|
|---|
| 303 | }
|
|---|
| 304 | }
|
|---|
| 305 | }
|
|---|
| 306 |
|
|---|
| 307 | return offGG;
|
|---|
| 308 | }
|
|---|
| 309 |
|
|---|
| 310 | //
|
|---|
| 311 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 312 | void t_pppClient::initOutput(t_output* output) {
|
|---|
| 313 | _output = output;
|
|---|
| 314 | _output->_numSat = 0;
|
|---|
| 315 | _output->_pDop = 0.0;
|
|---|
| 316 | _output->_error = false;
|
|---|
| 317 | }
|
|---|
| 318 |
|
|---|
| 319 | //
|
|---|
| 320 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 321 | void t_pppClient::clearObs() {
|
|---|
| 322 | for (unsigned ii = 0; ii < _obsRover.size(); ii++) {
|
|---|
| 323 | delete _obsRover.at(ii);
|
|---|
| 324 | }
|
|---|
| 325 | _obsRover.clear();
|
|---|
| 326 | }
|
|---|
| 327 |
|
|---|
| 328 | //
|
|---|
| 329 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 330 | void t_pppClient::finish(t_irc irc) {
|
|---|
| 331 |
|
|---|
| 332 | clearObs();
|
|---|
| 333 |
|
|---|
| 334 | _output->_epoTime = _epoTimeRover;
|
|---|
| 335 |
|
|---|
| 336 | if (irc == success) {
|
|---|
| 337 | _output->_xyzRover[0] = _staRover->xyzApr()[0] + _filter->x()[0];
|
|---|
| 338 | _output->_xyzRover[1] = _staRover->xyzApr()[1] + _filter->x()[1];
|
|---|
| 339 | _output->_xyzRover[2] = _staRover->xyzApr()[2] + _filter->x()[2];
|
|---|
| 340 | copy(&_filter->Q().data()[0], &_filter->Q().data()[6], _output->_covMatrix);
|
|---|
| 341 | _output->_numSat = _filter->numSat();
|
|---|
| 342 | _output->_pDop = _filter->PDOP();
|
|---|
| 343 | _output->_error = false;
|
|---|
| 344 | }
|
|---|
| 345 | else {
|
|---|
| 346 | _output->_error = true;
|
|---|
| 347 | }
|
|---|
| 348 | _output->_log = _log->str();
|
|---|
| 349 | delete _log; _log = new ostringstream();
|
|---|
| 350 | }
|
|---|
| 351 |
|
|---|
| 352 | //
|
|---|
| 353 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 354 | t_irc t_pppClient::cmpModel(t_station* station, const ColumnVector& xyzc,
|
|---|
| 355 | vector<t_satObs*>& obsVector) {
|
|---|
| 356 |
|
|---|
| 357 | bncTime time;
|
|---|
| 358 | time = _epoTimeRover;
|
|---|
| 359 | station->setName(OPT->_roverName);
|
|---|
| 360 | station->setAntName(OPT->_antNameRover);
|
|---|
| 361 | if (OPT->xyzAprRoverSet()) {
|
|---|
| 362 | station->setXyzApr(OPT->_xyzAprRover);
|
|---|
| 363 | }
|
|---|
| 364 | else {
|
|---|
| 365 | station->setXyzApr(xyzc.Rows(1,3));
|
|---|
| 366 | }
|
|---|
| 367 | station->setNeuEcc(OPT->_neuEccRover);
|
|---|
| 368 |
|
|---|
| 369 | // Receiver Clock
|
|---|
| 370 | // --------------
|
|---|
| 371 | station->setDClk(xyzc[3]);
|
|---|
| 372 |
|
|---|
| 373 | // Tides
|
|---|
| 374 | // -----
|
|---|
| 375 | ColumnVector hlp = station->xyzApr();
|
|---|
| 376 | tides(time, hlp);
|
|---|
| 377 | station->setTideDspl(hlp - station->xyzApr());
|
|---|
| 378 |
|
|---|
| 379 | // Observation model
|
|---|
| 380 | // -----------------
|
|---|
| 381 | vector<t_satObs*>::iterator it = obsVector.begin();
|
|---|
| 382 | while (it != obsVector.end()) {
|
|---|
| 383 | t_satObs* satObs = *it;
|
|---|
| 384 | satObs->cmpModel(station);
|
|---|
| 385 | if (satObs->isValid() && satObs->eleSat() >= OPT->_minEle) {
|
|---|
| 386 | ++it;
|
|---|
| 387 | }
|
|---|
| 388 | else {
|
|---|
| 389 | delete satObs;
|
|---|
| 390 | it = obsVector.erase(it);
|
|---|
| 391 | }
|
|---|
| 392 | }
|
|---|
| 393 |
|
|---|
| 394 | return success;
|
|---|
| 395 | }
|
|---|
| 396 |
|
|---|
| 397 | //
|
|---|
| 398 | //////////////////////////////////////////////////////////////////////////////
|
|---|
| 399 | void t_pppClient::processEpoch(int numSatRover, const t_pppSatObs* satObsRover,
|
|---|
| 400 | t_output* output) {
|
|---|
| 401 |
|
|---|
| 402 | try {
|
|---|
| 403 | initOutput(output);
|
|---|
| 404 |
|
|---|
| 405 | // Prepare Observations of the Rover
|
|---|
| 406 | // ---------------------------------
|
|---|
| 407 | if (prepareObs(numSatRover, satObsRover, _obsRover,
|
|---|
| 408 | _epoTimeRover) != success) {
|
|---|
| 409 | return finish(failure);
|
|---|
| 410 | }
|
|---|
| 411 |
|
|---|
| 412 | LOG << "\nResults of Epoch ";
|
|---|
| 413 | if (!_epoTimeRover.undef()) LOG << string(_epoTimeRover);
|
|---|
| 414 | LOG << "\n--------------------------------------\n";
|
|---|
| 415 |
|
|---|
| 416 | for (int iter = 1; iter <= 2; iter++) {
|
|---|
| 417 | ColumnVector xyzc(4); xyzc = 0.0;
|
|---|
| 418 | bool print = (iter == 2);
|
|---|
| 419 | if (cmpBancroft(_epoTimeRover, _obsRover, xyzc, print) != success) {
|
|---|
| 420 | return finish(failure);
|
|---|
| 421 | }
|
|---|
| 422 | if (cmpModel(_staRover, xyzc, _obsRover) != success) {
|
|---|
| 423 | return finish(failure);
|
|---|
| 424 | }
|
|---|
| 425 | }
|
|---|
| 426 |
|
|---|
| 427 | _offGG = cmpOffGG(_obsRover);
|
|---|
| 428 |
|
|---|
| 429 | // Store last epoch of data
|
|---|
| 430 | // ------------------------
|
|---|
| 431 | _obsPool->putEpoch(_epoTimeRover, _obsRover);
|
|---|
| 432 |
|
|---|
| 433 | // Process Epoch in Filter
|
|---|
| 434 | // -----------------------
|
|---|
| 435 | if (_filter->processEpoch(_obsPool) != success) {
|
|---|
| 436 | return finish(failure);
|
|---|
| 437 | }
|
|---|
| 438 | }
|
|---|
| 439 | catch (Exception& exc) {
|
|---|
| 440 | LOG << exc.what() << endl;
|
|---|
| 441 | return finish(failure);
|
|---|
| 442 | }
|
|---|
| 443 | catch (pppExcept msg) {
|
|---|
| 444 | LOG << msg.what() << endl;
|
|---|
| 445 | return finish(failure);
|
|---|
| 446 | }
|
|---|
| 447 | catch (...) {
|
|---|
| 448 | LOG << "unknown exception" << endl;
|
|---|
| 449 | return finish(failure);
|
|---|
| 450 | }
|
|---|
| 451 |
|
|---|
| 452 | return finish(success);
|
|---|
| 453 | }
|
|---|
| 454 |
|
|---|
| 455 | //
|
|---|
| 456 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 457 | double lorentz(const ColumnVector& aa, const ColumnVector& bb) {
|
|---|
| 458 | return aa[0]*bb[0] + aa[1]*bb[1] + aa[2]*bb[2] - aa[3]*bb[3];
|
|---|
| 459 | }
|
|---|
| 460 |
|
|---|
| 461 | //
|
|---|
| 462 | ////////////////////////////////////////////////////////////////////////////
|
|---|
| 463 | void t_pppClient::bancroft(const Matrix& BBpass, ColumnVector& pos) {
|
|---|
| 464 |
|
|---|
| 465 | if (pos.Nrows() != 4) {
|
|---|
| 466 | pos.ReSize(4);
|
|---|
| 467 | }
|
|---|
| 468 | pos = 0.0;
|
|---|
| 469 |
|
|---|
| 470 | for (int iter = 1; iter <= 2; iter++) {
|
|---|
| 471 | Matrix BB = BBpass;
|
|---|
| 472 | int mm = BB.Nrows();
|
|---|
| 473 | for (int ii = 1; ii <= mm; ii++) {
|
|---|
| 474 | double xx = BB(ii,1);
|
|---|
| 475 | double yy = BB(ii,2);
|
|---|
| 476 | double traveltime = 0.072;
|
|---|
| 477 | if (iter > 1) {
|
|---|
| 478 | double zz = BB(ii,3);
|
|---|
| 479 | double rho = sqrt( (xx-pos(1)) * (xx-pos(1)) +
|
|---|
| 480 | (yy-pos(2)) * (yy-pos(2)) +
|
|---|
| 481 | (zz-pos(3)) * (zz-pos(3)) );
|
|---|
| 482 | traveltime = rho / t_CST::c;
|
|---|
| 483 | }
|
|---|
| 484 | double angle = traveltime * t_CST::omega;
|
|---|
| 485 | double cosa = cos(angle);
|
|---|
| 486 | double sina = sin(angle);
|
|---|
| 487 | BB(ii,1) = cosa * xx + sina * yy;
|
|---|
| 488 | BB(ii,2) = -sina * xx + cosa * yy;
|
|---|
| 489 | }
|
|---|
| 490 |
|
|---|
| 491 | Matrix BBB;
|
|---|
| 492 | if (mm > 4) {
|
|---|
| 493 | SymmetricMatrix hlp; hlp << BB.t() * BB;
|
|---|
| 494 | BBB = hlp.i() * BB.t();
|
|---|
| 495 | }
|
|---|
| 496 | else {
|
|---|
| 497 | BBB = BB.i();
|
|---|
| 498 | }
|
|---|
| 499 | ColumnVector ee(mm); ee = 1.0;
|
|---|
| 500 | ColumnVector alpha(mm); alpha = 0.0;
|
|---|
| 501 | for (int ii = 1; ii <= mm; ii++) {
|
|---|
| 502 | alpha(ii) = lorentz(BB.Row(ii).t(),BB.Row(ii).t())/2.0;
|
|---|
| 503 | }
|
|---|
| 504 | ColumnVector BBBe = BBB * ee;
|
|---|
| 505 | ColumnVector BBBalpha = BBB * alpha;
|
|---|
| 506 | double aa = lorentz(BBBe, BBBe);
|
|---|
| 507 | double bb = lorentz(BBBe, BBBalpha)-1;
|
|---|
| 508 | double cc = lorentz(BBBalpha, BBBalpha);
|
|---|
| 509 | double root = sqrt(bb*bb-aa*cc);
|
|---|
| 510 |
|
|---|
| 511 | Matrix hlpPos(4,2);
|
|---|
| 512 | hlpPos.Column(1) = (-bb-root)/aa * BBBe + BBBalpha;
|
|---|
| 513 | hlpPos.Column(2) = (-bb+root)/aa * BBBe + BBBalpha;
|
|---|
| 514 |
|
|---|
| 515 | ColumnVector omc(2);
|
|---|
| 516 | for (int pp = 1; pp <= 2; pp++) {
|
|---|
| 517 | hlpPos(4,pp) = -hlpPos(4,pp);
|
|---|
| 518 | omc(pp) = BB(1,4) -
|
|---|
| 519 | sqrt( (BB(1,1)-hlpPos(1,pp)) * (BB(1,1)-hlpPos(1,pp)) +
|
|---|
| 520 | (BB(1,2)-hlpPos(2,pp)) * (BB(1,2)-hlpPos(2,pp)) +
|
|---|
| 521 | (BB(1,3)-hlpPos(3,pp)) * (BB(1,3)-hlpPos(3,pp)) ) -
|
|---|
| 522 | hlpPos(4,pp);
|
|---|
| 523 | }
|
|---|
| 524 | if ( fabs(omc(1)) > fabs(omc(2)) ) {
|
|---|
| 525 | pos = hlpPos.Column(2);
|
|---|
| 526 | }
|
|---|
| 527 | else {
|
|---|
| 528 | pos = hlpPos.Column(1);
|
|---|
| 529 | }
|
|---|
| 530 | }
|
|---|
| 531 | }
|
|---|
| 532 |
|
|---|