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