source: ntrip/trunk/BNC/src/ephemeris.cpp@ 9089

Last change on this file since 9089 was 8964, checked in by stuerze, 4 years ago

minor changes

File size: 47.7 KB
RevLine 
[1025]1#include <sstream>
[2234]2#include <iostream>
[1025]3#include <iomanip>
[1239]4#include <cstring>
[1025]5
[2234]6#include <newmatio.h>
7
[1025]8#include "ephemeris.h"
[2221]9#include "bncutils.h"
[2285]10#include "bnctime.h"
[5070]11#include "bnccore.h"
[5839]12#include "bncutils.h"
[6141]13#include "satObs.h"
[6044]14#include "pppInclude.h"
[6400]15#include "pppModel.h"
[1025]16
17using namespace std;
18
[5749]19// Constructor
20////////////////////////////////////////////////////////////////////////////
21t_eph::t_eph() {
[6518]22 _checkState = unchecked;
23 _orbCorr = 0;
24 _clkCorr = 0;
[5749]25}
[7278]26// Destructor
27////////////////////////////////////////////////////////////////////////////
28t_eph::~t_eph() {
29 if (_orbCorr)
30 delete _orbCorr;
31 if (_clkCorr)
32 delete _clkCorr;
33}
[5749]34
[7481]35//
[5749]36////////////////////////////////////////////////////////////////////////////
[6141]37void t_eph::setOrbCorr(const t_orbCorr* orbCorr) {
[7888]38 if (_orbCorr) {
39 delete _orbCorr;
40 _orbCorr = 0;
41 }
[6141]42 _orbCorr = new t_orbCorr(*orbCorr);
[5749]43}
44
[7481]45//
[5749]46////////////////////////////////////////////////////////////////////////////
[6141]47void t_eph::setClkCorr(const t_clkCorr* clkCorr) {
[7888]48 if (_clkCorr) {
49 delete _clkCorr;
50 _clkCorr = 0;
51 }
[6141]52 _clkCorr = new t_clkCorr(*clkCorr);
[5749]53}
54
[7481]55//
[5749]56////////////////////////////////////////////////////////////////////////////
[6109]57t_irc t_eph::getCrd(const bncTime& tt, ColumnVector& xc, ColumnVector& vv, bool useCorr) const {
[6518]58
[8419]59 if (_checkState == bad ||
[8618]60 _checkState == unhealthy ||
61 _checkState == outdated) {
[6518]62 return failure;
63 }
[8903]64
[8542]65 xc.ReSize(6);
[5749]66 vv.ReSize(3);
[6213]67 if (position(tt.gpsw(), tt.gpssec(), xc.data(), vv.data()) != success) {
68 return failure;
69 }
[5789]70 if (useCorr) {
[5839]71 if (_orbCorr && _clkCorr) {
[5849]72 double dtO = tt - _orbCorr->_time;
[6556]73 if (_orbCorr->_updateInt) {
[8903]74 dtO -= (0.5 * ssrUpdateInt[_orbCorr->_updateInt]);
[6556]75 }
[5839]76 ColumnVector dx(3);
[5849]77 dx[0] = _orbCorr->_xr[0] + _orbCorr->_dotXr[0] * dtO;
78 dx[1] = _orbCorr->_xr[1] + _orbCorr->_dotXr[1] * dtO;
79 dx[2] = _orbCorr->_xr[2] + _orbCorr->_dotXr[2] * dtO;
80
[7133]81 RSW_to_XYZ(xc.Rows(1,3), vv.Rows(1,3), dx, dx);
[5849]82
[5839]83 xc[0] -= dx[0];
84 xc[1] -= dx[1];
85 xc[2] -= dx[2];
[5849]86
[7133]87 ColumnVector dv(3);
88 RSW_to_XYZ(xc.Rows(1,3), vv.Rows(1,3), _orbCorr->_dotXr, dv);
89
90 vv[0] -= dv[0];
91 vv[1] -= dv[1];
92 vv[2] -= dv[2];
93
[5849]94 double dtC = tt - _clkCorr->_time;
[6556]95 if (_clkCorr->_updateInt) {
[8903]96 dtC -= (0.5 * ssrUpdateInt[_clkCorr->_updateInt]);
[6556]97 }
[7014]98 xc[3] += _clkCorr->_dClk + _clkCorr->_dotDClk * dtC + _clkCorr->_dotDotDClk * dtC * dtC;
[5839]99 }
100 else {
101 return failure;
102 }
[5749]103 }
104 return success;
105}
106
[6801]107//
108//////////////////////////////////////////////////////////////////////////////
109QString t_eph::rinexDateStr(const bncTime& tt, const t_prn& prn, double version) {
110 QString prnStr(prn.toString().c_str());
111 return rinexDateStr(tt, prnStr, version);
112}
113
114//
115//////////////////////////////////////////////////////////////////////////////
116QString t_eph::rinexDateStr(const bncTime& tt, const QString& prnStr, double version) {
117
118 QString datStr;
119
120 unsigned year, month, day, hour, min;
121 double sec;
122 tt.civil_date(year, month, day);
123 tt.civil_time(hour, min, sec);
124
125 QTextStream out(&datStr);
126
127 if (version < 3.0) {
128 QString prnHlp = prnStr.mid(1,2); if (prnHlp[0] == '0') prnHlp[0] = ' ';
129 out << prnHlp << QString(" %1 %2 %3 %4 %5%6")
130 .arg(year % 100, 2, 10, QChar('0'))
131 .arg(month, 2)
132 .arg(day, 2)
133 .arg(hour, 2)
134 .arg(min, 2)
135 .arg(sec, 5, 'f',1);
136 }
137 else {
138 out << prnStr << QString(" %1 %2 %3 %4 %5 %6")
139 .arg(year, 4)
140 .arg(month, 2, 10, QChar('0'))
141 .arg(day, 2, 10, QChar('0'))
142 .arg(hour, 2, 10, QChar('0'))
143 .arg(min, 2, 10, QChar('0'))
144 .arg(int(sec), 2, 10, QChar('0'));
145 }
146
147 return datStr;
148}
149
150// Constructor
151//////////////////////////////////////////////////////////////////////////////
152t_ephGPS::t_ephGPS(float rnxVersion, const QStringList& lines) {
153
154 const int nLines = 8;
155
156 if (lines.size() != nLines) {
157 _checkState = bad;
158 return;
159 }
160
161 // RINEX Format
162 // ------------
163 int fieldLen = 19;
164
165 int pos[4];
166 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
167 pos[1] = pos[0] + fieldLen;
168 pos[2] = pos[1] + fieldLen;
169 pos[3] = pos[2] + fieldLen;
170
171 // Read eight lines
172 // ----------------
173 for (int iLine = 0; iLine < nLines; iLine++) {
174 QString line = lines[iLine];
175
176 if ( iLine == 0 ) {
[8204]177 QTextStream in(line.left(pos[1]).toLatin1());
[6801]178 int year, month, day, hour, min;
179 double sec;
180
[7139]181 QString prnStr, n;
[6880]182 in >> prnStr;
[7639]183
184 if (prnStr.size() == 1 &&
[8168]185 (prnStr[0] == 'G' ||
186 prnStr[0] == 'J' ||
187 prnStr[0] == 'I')) {
[7139]188 in >> n;
189 prnStr.append(n);
[6880]190 }
[7639]191
[6880]192 in >> year >> month >> day >> hour >> min >> sec;
[6801]193 if (prnStr.at(0) == 'G') {
194 _prn.set('G', prnStr.mid(1).toInt());
195 }
196 else if (prnStr.at(0) == 'J') {
197 _prn.set('J', prnStr.mid(1).toInt());
198 }
[8168]199 else if (prnStr.at(0) == 'I') {
200 _prn.set('I', prnStr.mid(1).toInt());
201 }
[6801]202 else {
203 _prn.set('G', prnStr.toInt());
204 }
205
206 if (year < 80) {
207 year += 2000;
208 }
209 else if (year < 100) {
210 year += 1900;
211 }
212
213 _TOC.set(year, month, day, hour, min, sec);
214
215 if ( readDbl(line, pos[1], fieldLen, _clock_bias ) ||
216 readDbl(line, pos[2], fieldLen, _clock_drift ) ||
217 readDbl(line, pos[3], fieldLen, _clock_driftrate) ) {
218 _checkState = bad;
219 return;
220 }
221 }
222
223 else if ( iLine == 1 ) {
224 if ( readDbl(line, pos[0], fieldLen, _IODE ) ||
225 readDbl(line, pos[1], fieldLen, _Crs ) ||
226 readDbl(line, pos[2], fieldLen, _Delta_n) ||
227 readDbl(line, pos[3], fieldLen, _M0 ) ) {
228 _checkState = bad;
229 return;
230 }
231 }
232
233 else if ( iLine == 2 ) {
234 if ( readDbl(line, pos[0], fieldLen, _Cuc ) ||
235 readDbl(line, pos[1], fieldLen, _e ) ||
236 readDbl(line, pos[2], fieldLen, _Cus ) ||
237 readDbl(line, pos[3], fieldLen, _sqrt_A) ) {
238 _checkState = bad;
239 return;
240 }
241 }
242
243 else if ( iLine == 3 ) {
244 if ( readDbl(line, pos[0], fieldLen, _TOEsec) ||
245 readDbl(line, pos[1], fieldLen, _Cic ) ||
246 readDbl(line, pos[2], fieldLen, _OMEGA0) ||
247 readDbl(line, pos[3], fieldLen, _Cis ) ) {
248 _checkState = bad;
249 return;
250 }
251 }
252
253 else if ( iLine == 4 ) {
254 if ( readDbl(line, pos[0], fieldLen, _i0 ) ||
255 readDbl(line, pos[1], fieldLen, _Crc ) ||
256 readDbl(line, pos[2], fieldLen, _omega ) ||
257 readDbl(line, pos[3], fieldLen, _OMEGADOT) ) {
258 _checkState = bad;
259 return;
260 }
261 }
262
[8168]263 else if ( iLine == 5 && type() != t_eph::IRNSS) {
[6801]264 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
265 readDbl(line, pos[1], fieldLen, _L2Codes) ||
266 readDbl(line, pos[2], fieldLen, _TOEweek ) ||
267 readDbl(line, pos[3], fieldLen, _L2PFlag) ) {
268 _checkState = bad;
269 return;
270 }
271 }
[8168]272 else if ( iLine == 5 && type() == t_eph::IRNSS) {
273 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
274 readDbl(line, pos[2], fieldLen, _TOEweek) ) {
275 _checkState = bad;
276 return;
277 }
278 }
[6801]279
[8168]280 else if ( iLine == 6 && type() != t_eph::IRNSS) {
[6801]281 if ( readDbl(line, pos[0], fieldLen, _ura ) ||
282 readDbl(line, pos[1], fieldLen, _health) ||
283 readDbl(line, pos[2], fieldLen, _TGD ) ||
284 readDbl(line, pos[3], fieldLen, _IODC ) ) {
285 _checkState = bad;
286 return;
287 }
288 }
[8168]289 else if ( iLine == 6 && type() == t_eph::IRNSS) {
290 if ( readDbl(line, pos[0], fieldLen, _ura ) ||
291 readDbl(line, pos[1], fieldLen, _health) ||
292 readDbl(line, pos[2], fieldLen, _TGD ) ) {
293 _checkState = bad;
294 return;
295 }
296 }
[6801]297 else if ( iLine == 7 ) {
298 if ( readDbl(line, pos[0], fieldLen, _TOT) ) {
299 _checkState = bad;
300 return;
301 }
[8927]302 // fitInterval is not valid for IRNSS
303 if (type() != t_eph::IRNSS) {
304 double fitIntervalRnx;
305 readDbl(line, pos[1], fieldLen, fitIntervalRnx);
[8934]306 if (type() == t_eph::GPS) { // in RINEX specified allways as time period for GPS
[8931]307 _fitInterval = fitIntervalRnx;
[8934]308 } else if (type() == t_eph::QZSS) { // specified as flag for QZSS
309 if (rnxVersion == 3.02) {
310 _fitInterval = fitIntervalRnx; // specified as time period
[8931]311 }
[8934]312 else {
313 _fitInterval = fitIntervalFromFlag(fitIntervalRnx, _IODC, t_eph::QZSS);
314 }
[8927]315 }
[8925]316 }
[6801]317 }
318 }
319}
320
[2222]321// Compute GPS Satellite Position (virtual)
[1025]322////////////////////////////////////////////////////////////////////////////
[6213]323t_irc t_ephGPS::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
[1025]324
[1098]325 static const double omegaEarth = 7292115.1467e-11;
[5277]326 static const double gmGRS = 398.6005e12;
[1025]327
[8542]328 memset(xc, 0, 6*sizeof(double));
[1025]329 memset(vv, 0, 3*sizeof(double));
330
331 double a0 = _sqrt_A * _sqrt_A;
332 if (a0 == 0) {
[6213]333 return failure;
[1025]334 }
335
[5277]336 double n0 = sqrt(gmGRS/(a0*a0*a0));
[4018]337
338 bncTime tt(GPSweek, GPSweeks);
[4543]339 double tk = tt - bncTime(int(_TOEweek), _TOEsec);
[4018]340
[1025]341 double n = n0 + _Delta_n;
342 double M = _M0 + n*tk;
343 double E = M;
344 double E_last;
[8368]345 int nLoop = 0;
[1025]346 do {
347 E_last = E;
348 E = M + _e*sin(E);
[8368]349
350 if (++nLoop == 100) {
351 return failure;
352 }
353 } while ( fabs(E-E_last)*a0 > 0.001);
[1025]354 double v = 2.0*atan( sqrt( (1.0 + _e)/(1.0 - _e) )*tan( E/2 ) );
355 double u0 = v + _omega;
356 double sin2u0 = sin(2*u0);
357 double cos2u0 = cos(2*u0);
358 double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
359 double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
360 double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
361 double xp = r*cos(u);
362 double yp = r*sin(u);
[7481]363 double OM = _OMEGA0 + (_OMEGADOT - omegaEarth)*tk -
[4018]364 omegaEarth*_TOEsec;
[7278]365
[1025]366 double sinom = sin(OM);
367 double cosom = cos(OM);
368 double sini = sin(i);
369 double cosi = cos(i);
370 xc[0] = xp*cosom - yp*cosi*sinom;
371 xc[1] = xp*sinom + yp*cosi*cosom;
[7481]372 xc[2] = yp*sini;
373
[4018]374 double tc = tt - _TOC;
[2429]375 xc[3] = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc;
[1025]376
377 // Velocity
378 // --------
379 double tanv2 = tan(v/2);
380 double dEdM = 1 / (1 - _e*cos(E));
[7278]381 double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2) / (1 + tanv2*tanv2)
[1025]382 * dEdM * n;
383 double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
384 double dotom = _OMEGADOT - omegaEarth;
385 double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
[7278]386 double dotr = a0 * _e*sin(E) * dEdM * n
[1025]387 + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
388 double dotx = dotr*cos(u) - r*sin(u)*dotu;
389 double doty = dotr*sin(u) + r*cos(u)*dotu;
390
391 vv[0] = cosom *dotx - cosi*sinom *doty // dX / dr
392 - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
393 + yp*sini*sinom*doti; // dX / di
394
395 vv[1] = sinom *dotx + cosi*cosom *doty
396 + xp*cosom*dotom - yp*cosi*sinom*dotom
397 - yp*sini*cosom*doti;
398
399 vv[2] = sini *doty + yp*cosi *doti;
[2429]400
401 // Relativistic Correction
402 // -----------------------
[7481]403 // correspondent to IGS convention and GPS ICD (and SSR standard)
[2429]404 xc[3] -= 2.0 * (xc[0]*vv[0] + xc[1]*vv[1] + xc[2]*vv[2]) / t_CST::c / t_CST::c;
[6213]405
[8542]406 xc[4] = _clock_drift + _clock_driftrate*tc;
407 xc[5] = _clock_driftrate;
[8581]408
[6213]409 return success;
[1025]410}
411
[6801]412// RINEX Format String
413//////////////////////////////////////////////////////////////////////////////
414QString t_ephGPS::toString(double version) const {
[2221]415
[6801]416 QString rnxStr = rinexDateStr(_TOC, _prn, version);
[2221]417
[6801]418 QTextStream out(&rnxStr);
[2221]419
[6801]420 out << QString("%1%2%3\n")
421 .arg(_clock_bias, 19, 'e', 12)
422 .arg(_clock_drift, 19, 'e', 12)
423 .arg(_clock_driftrate, 19, 'e', 12);
[2221]424
[6801]425 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
[2221]426
[6801]427 out << QString(fmt)
428 .arg(_IODE, 19, 'e', 12)
429 .arg(_Crs, 19, 'e', 12)
430 .arg(_Delta_n, 19, 'e', 12)
431 .arg(_M0, 19, 'e', 12);
432
433 out << QString(fmt)
434 .arg(_Cuc, 19, 'e', 12)
435 .arg(_e, 19, 'e', 12)
436 .arg(_Cus, 19, 'e', 12)
437 .arg(_sqrt_A, 19, 'e', 12);
438
439 out << QString(fmt)
440 .arg(_TOEsec, 19, 'e', 12)
441 .arg(_Cic, 19, 'e', 12)
442 .arg(_OMEGA0, 19, 'e', 12)
443 .arg(_Cis, 19, 'e', 12);
444
445 out << QString(fmt)
446 .arg(_i0, 19, 'e', 12)
447 .arg(_Crc, 19, 'e', 12)
448 .arg(_omega, 19, 'e', 12)
449 .arg(_OMEGADOT, 19, 'e', 12);
450
[8800]451 if (type() == t_eph::IRNSS) {
[8168]452 out << QString(fmt)
453 .arg(_IDOT, 19, 'e', 12)
[8800]454 .arg(0.0, 19, 'e', 12)
455 .arg(_TOEweek, 19, 'e', 12)
456 .arg(0.0, 19, 'e', 12);
457 }
458 else {
459 out << QString(fmt)
460 .arg(_IDOT, 19, 'e', 12)
[8168]461 .arg(_L2Codes, 19, 'e', 12)
462 .arg(_TOEweek, 19, 'e', 12)
463 .arg(_L2PFlag, 19, 'e', 12);
[8800]464 }
[6801]465
[8168]466 if (type() == t_eph::IRNSS) {
467 out << QString(fmt)
468 .arg(_ura, 19, 'e', 12)
469 .arg(_health, 19, 'e', 12)
470 .arg(_TGD, 19, 'e', 12)
[8790]471 .arg(0.0, 19, 'e', 12);
[8168]472 }
473 else {
474 out << QString(fmt)
475 .arg(_ura, 19, 'e', 12)
476 .arg(_health, 19, 'e', 12)
477 .arg(_TGD, 19, 'e', 12)
478 .arg(_IODC, 19, 'e', 12);
479 }
[6801]480
[7922]481 double tot = _TOT;
482 if (tot == 0.9999e9 && version < 3.0) {
483 tot = 0.0;
484 }
[8927]485 // fitInterval
[8964]486 if (type() == t_eph::IRNSS) {// not valid for IRNSS
[8800]487 out << QString(fmt)
[8168]488 .arg(tot, 19, 'e', 12)
[8800]489 .arg(0.0, 19, 'e', 12)
490 .arg("", 19, QChar(' '))
491 .arg("", 19, QChar(' '));
492 }
493 else {
[8934]494 // for GPS and QZSS in version 3.02 specified in hours
495 double fitIntervalRnx = _fitInterval;
496 // otherwise specified as flag
497 if (type() == t_eph::QZSS && version != 3.02) {
[8925]498 (_fitInterval == 2.0) ? fitIntervalRnx = 0.0 : fitIntervalRnx = 1.0;
499 }
[8800]500 out << QString(fmt)
[8925]501 .arg(tot, 19, 'e', 12)
502 .arg(fitIntervalRnx, 19, 'e', 12)
503 .arg("", 19, QChar(' '))
504 .arg("", 19, QChar(' '));
[8800]505 }
[6801]506 return rnxStr;
[2221]507}
508
[6801]509// Constructor
510//////////////////////////////////////////////////////////////////////////////
511t_ephGlo::t_ephGlo(float rnxVersion, const QStringList& lines) {
[2221]512
[6801]513 const int nLines = 4;
514
515 if (lines.size() != nLines) {
516 _checkState = bad;
517 return;
[6518]518 }
519
[6801]520 // RINEX Format
521 // ------------
522 int fieldLen = 19;
[2221]523
[6801]524 int pos[4];
525 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
526 pos[1] = pos[0] + fieldLen;
527 pos[2] = pos[1] + fieldLen;
528 pos[3] = pos[2] + fieldLen;
[2221]529
[6801]530 // Read four lines
531 // ---------------
532 for (int iLine = 0; iLine < nLines; iLine++) {
533 QString line = lines[iLine];
[2221]534
[6801]535 if ( iLine == 0 ) {
[8204]536 QTextStream in(line.left(pos[1]).toLatin1());
[6213]537
[6801]538 int year, month, day, hour, min;
539 double sec;
[2221]540
[7139]541 QString prnStr, n;
[6880]542 in >> prnStr;
[7639]543 if (prnStr.size() == 1 && prnStr[0] == 'R') {
[7139]544 in >> n;
545 prnStr.append(n);
[6880]546 }
547 in >> year >> month >> day >> hour >> min >> sec;
[6801]548 if (prnStr.at(0) == 'R') {
549 _prn.set('R', prnStr.mid(1).toInt());
550 }
551 else {
552 _prn.set('R', prnStr.toInt());
553 }
[2221]554
[6801]555 if (year < 80) {
556 year += 2000;
557 }
558 else if (year < 100) {
559 year += 1900;
560 }
[2221]561
[6801]562 _gps_utc = gnumleap(year, month, day);
[2221]563
[6801]564 _TOC.set(year, month, day, hour, min, sec);
565 _TOC = _TOC + _gps_utc;
[8800]566 int nd = int((_TOC.gpssec())) / (24.0*60.0*60.0);
[6801]567 if ( readDbl(line, pos[1], fieldLen, _tau ) ||
568 readDbl(line, pos[2], fieldLen, _gamma) ||
569 readDbl(line, pos[3], fieldLen, _tki ) ) {
570 _checkState = bad;
571 return;
572 }
[8800]573 _tki -= nd * 86400.0;
574 _tau = -_tau;
[6801]575 }
576
577 else if ( iLine == 1 ) {
578 if ( readDbl(line, pos[0], fieldLen, _x_pos ) ||
579 readDbl(line, pos[1], fieldLen, _x_velocity ) ||
580 readDbl(line, pos[2], fieldLen, _x_acceleration) ||
581 readDbl(line, pos[3], fieldLen, _health ) ) {
582 _checkState = bad;
583 return;
584 }
585 }
586
587 else if ( iLine == 2 ) {
588 if ( readDbl(line, pos[0], fieldLen, _y_pos ) ||
589 readDbl(line, pos[1], fieldLen, _y_velocity ) ||
590 readDbl(line, pos[2], fieldLen, _y_acceleration ) ||
591 readDbl(line, pos[3], fieldLen, _frequency_number) ) {
592 _checkState = bad;
593 return;
594 }
595 }
596
597 else if ( iLine == 3 ) {
598 if ( readDbl(line, pos[0], fieldLen, _z_pos ) ||
599 readDbl(line, pos[1], fieldLen, _z_velocity ) ||
600 readDbl(line, pos[2], fieldLen, _z_acceleration) ||
601 readDbl(line, pos[3], fieldLen, _E ) ) {
602 _checkState = bad;
603 return;
604 }
605 }
606 }
607
608 // Initialize status vector
609 // ------------------------
610 _tt = _TOC;
[8698]611 _xv.ReSize(6); _xv = 0.0;
[6801]612 _xv(1) = _x_pos * 1.e3;
613 _xv(2) = _y_pos * 1.e3;
614 _xv(3) = _z_pos * 1.e3;
615 _xv(4) = _x_velocity * 1.e3;
616 _xv(5) = _y_velocity * 1.e3;
617 _xv(6) = _z_velocity * 1.e3;
[2221]618}
619
[6801]620// Compute Glonass Satellite Position (virtual)
[2771]621////////////////////////////////////////////////////////////////////////////
[6801]622t_irc t_ephGlo::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
[2771]623
[6801]624 static const double nominalStep = 10.0;
[2771]625
[8542]626 memset(xc, 0, 6*sizeof(double));
[2771]627 memset(vv, 0, 3*sizeof(double));
628
[6801]629 double dtPos = bncTime(GPSweek, GPSweeks) - _tt;
630
[8698]631 if (fabs(dtPos) > 24 * 3600.0) {
[6213]632 return failure;
[2771]633 }
634
[6801]635 int nSteps = int(fabs(dtPos) / nominalStep) + 1;
636 double step = dtPos / nSteps;
[4018]637
[6801]638 double acc[3];
639 acc[0] = _x_acceleration * 1.e3;
640 acc[1] = _y_acceleration * 1.e3;
641 acc[2] = _z_acceleration * 1.e3;
[8456]642
[6801]643 for (int ii = 1; ii <= nSteps; ii++) {
644 _xv = rungeKutta4(_tt.gpssec(), _xv, step, acc, glo_deriv);
645 _tt = _tt + step;
646 }
[4018]647
[6801]648 // Position and Velocity
649 // ---------------------
650 xc[0] = _xv(1);
651 xc[1] = _xv(2);
652 xc[2] = _xv(3);
[2771]653
[6801]654 vv[0] = _xv(4);
655 vv[1] = _xv(5);
656 vv[2] = _xv(6);
[2771]657
[6801]658 // Clock Correction
659 // ----------------
660 double dtClk = bncTime(GPSweek, GPSweeks) - _TOC;
661 xc[3] = -_tau + _gamma * dtClk;
[2771]662
[8542]663 xc[4] = _gamma;
664 xc[5] = 0.0;
[8483]665
[6213]666 return success;
[2771]667}
668
[6801]669// RINEX Format String
[3659]670//////////////////////////////////////////////////////////////////////////////
[6801]671QString t_ephGlo::toString(double version) const {
[3664]672
[8800]673 QString rnxStr = rinexDateStr(_TOC -_gps_utc, _prn, version);
674 int nd = int((_TOC - _gps_utc).gpssec()) / (24.0*60.0*60.0);
[6801]675 QTextStream out(&rnxStr);
[3664]676
[6801]677 out << QString("%1%2%3\n")
[8800]678 .arg(-_tau, 19, 'e', 12)
679 .arg(_gamma, 19, 'e', 12)
680 .arg(_tki+nd*86400.0, 19, 'e', 12);
[3668]681
[6801]682 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
[3664]683
[6801]684 out << QString(fmt)
685 .arg(_x_pos, 19, 'e', 12)
686 .arg(_x_velocity, 19, 'e', 12)
687 .arg(_x_acceleration, 19, 'e', 12)
688 .arg(_health, 19, 'e', 12);
[3664]689
[6801]690 out << QString(fmt)
691 .arg(_y_pos, 19, 'e', 12)
692 .arg(_y_velocity, 19, 'e', 12)
693 .arg(_y_acceleration, 19, 'e', 12)
694 .arg(_frequency_number, 19, 'e', 12);
[3666]695
[6801]696 out << QString(fmt)
697 .arg(_z_pos, 19, 'e', 12)
698 .arg(_z_velocity, 19, 'e', 12)
699 .arg(_z_acceleration, 19, 'e', 12)
700 .arg(_E, 19, 'e', 12);
[3666]701
[6801]702 return rnxStr;
[3659]703}
704
[6801]705// Derivative of the state vector using a simple force model (static)
706////////////////////////////////////////////////////////////////////////////
707ColumnVector t_ephGlo::glo_deriv(double /* tt */, const ColumnVector& xv,
708 double* acc) {
[3659]709
[6801]710 // State vector components
711 // -----------------------
712 ColumnVector rr = xv.rows(1,3);
713 ColumnVector vv = xv.rows(4,6);
[3699]714
[6801]715 // Acceleration
[3699]716 // ------------
[6801]717 static const double gmWGS = 398.60044e12;
718 static const double AE = 6378136.0;
719 static const double OMEGA = 7292115.e-11;
720 static const double C20 = -1082.6257e-6;
[3699]721
[8903]722 double rho = rr.NormFrobenius();
[6801]723 double t1 = -gmWGS/(rho*rho*rho);
724 double t2 = 3.0/2.0 * C20 * (gmWGS*AE*AE) / (rho*rho*rho*rho*rho);
725 double t3 = OMEGA * OMEGA;
726 double t4 = 2.0 * OMEGA;
727 double z2 = rr(3) * rr(3);
[3699]728
[6801]729 // Vector of derivatives
730 // ---------------------
731 ColumnVector va(6);
732 va(1) = vv(1);
733 va(2) = vv(2);
734 va(3) = vv(3);
735 va(4) = (t1 + t2*(1.0-5.0*z2/(rho*rho)) + t3) * rr(1) + t4*vv(2) + acc[0];
736 va(5) = (t1 + t2*(1.0-5.0*z2/(rho*rho)) + t3) * rr(2) - t4*vv(1) + acc[1];
737 va(6) = (t1 + t2*(3.0-5.0*z2/(rho*rho)) ) * rr(3) + acc[2];
[3699]738
[6801]739 return va;
740}
[3699]741
[6801]742// IOD of Glonass Ephemeris (virtual)
743////////////////////////////////////////////////////////////////////////////
[7169]744unsigned int t_ephGlo::IOD() const {
[6801]745 bncTime tMoscow = _TOC - _gps_utc + 3 * 3600.0;
[7054]746 return (unsigned long)tMoscow.daysec() / 900;
[3659]747}
748
[8187]749// Health status of Glonass Ephemeris (virtual)
750////////////////////////////////////////////////////////////////////////////
751unsigned int t_ephGlo::isUnhealthy() const {
[8215]752
[8217]753 if (_almanac_health_availablility_indicator) {
[8215]754 if ((_health == 0 && _almanac_health == 0) ||
755 (_health == 1 && _almanac_health == 0) ||
756 (_health == 1 && _almanac_health == 1)) {
757 return 1;
758 }
[8187]759 }
[8217]760 else if (!_almanac_health_availablility_indicator) {
761 if (_health) {
762 return 1;
763 }
764 }
[8215]765 return 0; /* (_health == 0 && _almanac_health == 1) or (_health == 0) */
[8187]766}
767
[3659]768// Constructor
769//////////////////////////////////////////////////////////////////////////////
[4891]770t_ephGal::t_ephGal(float rnxVersion, const QStringList& lines) {
[6809]771 int year, month, day, hour, min;
772 double sec;
773 QString prnStr;
[4891]774 const int nLines = 8;
775 if (lines.size() != nLines) {
[6518]776 _checkState = bad;
[4891]777 return;
778 }
779
780 // RINEX Format
781 // ------------
782 int fieldLen = 19;
[6792]783 double SVhealth = 0.0;
784 double datasource = 0.0;
[6798]785
[4891]786 int pos[4];
787 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
788 pos[1] = pos[0] + fieldLen;
789 pos[2] = pos[1] + fieldLen;
790 pos[3] = pos[2] + fieldLen;
791
792 // Read eight lines
793 // ----------------
794 for (int iLine = 0; iLine < nLines; iLine++) {
795 QString line = lines[iLine];
796
797 if ( iLine == 0 ) {
[8204]798 QTextStream in(line.left(pos[1]).toLatin1());
[7140]799 QString n;
[6880]800 in >> prnStr;
[7639]801 if (prnStr.size() == 1 && prnStr[0] == 'E') {
[7139]802 in >> n;
803 prnStr.append(n);
[6880]804 }
805 in >> year >> month >> day >> hour >> min >> sec;
[4891]806 if (year < 80) {
807 year += 2000;
808 }
809 else if (year < 100) {
810 year += 1900;
811 }
812
813 _TOC.set(year, month, day, hour, min, sec);
814
815 if ( readDbl(line, pos[1], fieldLen, _clock_bias ) ||
816 readDbl(line, pos[2], fieldLen, _clock_drift ) ||
817 readDbl(line, pos[3], fieldLen, _clock_driftrate) ) {
[6518]818 _checkState = bad;
[4891]819 return;
820 }
821 }
822
823 else if ( iLine == 1 ) {
824 if ( readDbl(line, pos[0], fieldLen, _IODnav ) ||
825 readDbl(line, pos[1], fieldLen, _Crs ) ||
826 readDbl(line, pos[2], fieldLen, _Delta_n) ||
827 readDbl(line, pos[3], fieldLen, _M0 ) ) {
[6518]828 _checkState = bad;
[4891]829 return;
830 }
831 }
832
833 else if ( iLine == 2 ) {
834 if ( readDbl(line, pos[0], fieldLen, _Cuc ) ||
835 readDbl(line, pos[1], fieldLen, _e ) ||
836 readDbl(line, pos[2], fieldLen, _Cus ) ||
837 readDbl(line, pos[3], fieldLen, _sqrt_A) ) {
[6518]838 _checkState = bad;
[4891]839 return;
840 }
841 }
842
843 else if ( iLine == 3 ) {
844 if ( readDbl(line, pos[0], fieldLen, _TOEsec) ||
845 readDbl(line, pos[1], fieldLen, _Cic ) ||
846 readDbl(line, pos[2], fieldLen, _OMEGA0) ||
847 readDbl(line, pos[3], fieldLen, _Cis ) ) {
[6518]848 _checkState = bad;
[4891]849 return;
850 }
851 }
852
853 else if ( iLine == 4 ) {
854 if ( readDbl(line, pos[0], fieldLen, _i0 ) ||
855 readDbl(line, pos[1], fieldLen, _Crc ) ||
856 readDbl(line, pos[2], fieldLen, _omega ) ||
857 readDbl(line, pos[3], fieldLen, _OMEGADOT) ) {
[6518]858 _checkState = bad;
[4891]859 return;
860 }
861 }
862
863 else if ( iLine == 5 ) {
[6792]864 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
865 readDbl(line, pos[1], fieldLen, datasource) ||
866 readDbl(line, pos[2], fieldLen, _TOEweek ) ) {
[6518]867 _checkState = bad;
[4891]868 return;
[6792]869 } else {
870 if (int(datasource) & (1<<8)) {
[6812]871 _fnav = true;
872 _inav = false;
[6792]873 } else if (int(datasource) & (1<<9)) {
[6812]874 _fnav = false;
875 _inav = true;
[6792]876 }
[6892]877 _TOEweek -= 1024.0;
[4891]878 }
879 }
880
881 else if ( iLine == 6 ) {
882 if ( readDbl(line, pos[0], fieldLen, _SISA ) ||
[6792]883 readDbl(line, pos[1], fieldLen, SVhealth) ||
[4891]884 readDbl(line, pos[2], fieldLen, _BGD_1_5A) ||
885 readDbl(line, pos[3], fieldLen, _BGD_1_5B) ) {
[6518]886 _checkState = bad;
[4891]887 return;
[6792]888 } else {
889 // Bit 0
[6812]890 _e1DataInValid = (int(SVhealth) & (1<<0));
[6792]891 // Bit 1-2
[6802]892 _E1_bHS = double((int(SVhealth) >> 1) & 0x3);
[6792]893 // Bit 3
[6812]894 _e5aDataInValid = (int(SVhealth) & (1<<3));
[6792]895 // Bit 4-5
[6802]896 _E5aHS = double((int(SVhealth) >> 4) & 0x3);
[6792]897 // Bit 6
[6812]898 _e5bDataInValid = (int(SVhealth) & (1<<6));
[6792]899 // Bit 7-8
[6802]900 _E5bHS = double((int(SVhealth) >> 7) & 0x3);
[6809]901
902 if (prnStr.at(0) == 'E') {
[7140]903 _prn.set('E', prnStr.mid(1).toInt(), _inav ? 1 : 0);
[6809]904 }
[4891]905 }
906 }
907
908 else if ( iLine == 7 ) {
909 if ( readDbl(line, pos[0], fieldLen, _TOT) ) {
[6518]910 _checkState = bad;
[4891]911 return;
912 }
913 }
914 }
[3659]915}
[4013]916
[6801]917// Compute Galileo Satellite Position (virtual)
918////////////////////////////////////////////////////////////////////////////
919t_irc t_ephGal::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
[4013]920
[6801]921 static const double omegaEarth = 7292115.1467e-11;
[8212]922 static const double gmWGS = 398.6004418e12;
[4023]923
[8542]924 memset(xc, 0, 6*sizeof(double));
[6801]925 memset(vv, 0, 3*sizeof(double));
[4023]926
[6801]927 double a0 = _sqrt_A * _sqrt_A;
928 if (a0 == 0) {
929 return failure;
930 }
[4023]931
[6801]932 double n0 = sqrt(gmWGS/(a0*a0*a0));
[4023]933
[6801]934 bncTime tt(GPSweek, GPSweeks);
935 double tk = tt - bncTime(_TOC.gpsw(), _TOEsec);
[4023]936
[6801]937 double n = n0 + _Delta_n;
938 double M = _M0 + n*tk;
939 double E = M;
940 double E_last;
[8368]941 int nLoop = 0;
[6801]942 do {
943 E_last = E;
944 E = M + _e*sin(E);
[8368]945
946 if (++nLoop == 100) {
947 return failure;
948 }
[6801]949 } while ( fabs(E-E_last)*a0 > 0.001 );
950 double v = 2.0*atan( sqrt( (1.0 + _e)/(1.0 - _e) )*tan( E/2 ) );
951 double u0 = v + _omega;
952 double sin2u0 = sin(2*u0);
953 double cos2u0 = cos(2*u0);
954 double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
955 double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
956 double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
957 double xp = r*cos(u);
958 double yp = r*sin(u);
959 double OM = _OMEGA0 + (_OMEGADOT - omegaEarth)*tk -
960 omegaEarth*_TOEsec;
[4023]961
[6801]962 double sinom = sin(OM);
963 double cosom = cos(OM);
964 double sini = sin(i);
965 double cosi = cos(i);
966 xc[0] = xp*cosom - yp*cosi*sinom;
967 xc[1] = xp*sinom + yp*cosi*cosom;
968 xc[2] = yp*sini;
[4023]969
[6801]970 double tc = tt - _TOC;
971 xc[3] = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc;
[4023]972
[6801]973 // Velocity
974 // --------
975 double tanv2 = tan(v/2);
976 double dEdM = 1 / (1 - _e*cos(E));
977 double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2) / (1 + tanv2*tanv2)
978 * dEdM * n;
979 double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
980 double dotom = _OMEGADOT - omegaEarth;
981 double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
982 double dotr = a0 * _e*sin(E) * dEdM * n
983 + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
984 double dotx = dotr*cos(u) - r*sin(u)*dotu;
985 double doty = dotr*sin(u) + r*cos(u)*dotu;
[4023]986
[6801]987 vv[0] = cosom *dotx - cosi*sinom *doty // dX / dr
988 - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
989 + yp*sini*sinom*doti; // dX / di
990
991 vv[1] = sinom *dotx + cosi*cosom *doty
992 + xp*cosom*dotom - yp*cosi*sinom*dotom
993 - yp*sini*cosom*doti;
994
995 vv[2] = sini *doty + yp*cosi *doti;
996
997 // Relativistic Correction
998 // -----------------------
[7481]999 // correspondent to Galileo ICD and to SSR standard
1000 xc[3] -= 4.442807633e-10 * _e * sqrt(a0) *sin(E);
1001 // correspondent to IGS convention
1002 //xc[3] -= 2.0 * (xc[0]*vv[0] + xc[1]*vv[1] + xc[2]*vv[2]) / t_CST::c / t_CST::c;
[6801]1003
[8542]1004 xc[4] = _clock_drift + _clock_driftrate*tc;
1005 xc[5] = _clock_driftrate;
[8581]1006
[6801]1007 return success;
[4023]1008}
1009
[8187]1010// Health status of Galileo Ephemeris (virtual)
1011////////////////////////////////////////////////////////////////////////////
1012unsigned int t_ephGal::isUnhealthy() const {
1013 if (_E5aHS && _E5bHS && _E1_bHS) {
1014 return 1;
1015 }
1016 return 0;
1017}
1018
[4023]1019// RINEX Format String
1020//////////////////////////////////////////////////////////////////////////////
1021QString t_ephGal::toString(double version) const {
1022
[4029]1023 QString rnxStr = rinexDateStr(_TOC, _prn, version);
[4023]1024
1025 QTextStream out(&rnxStr);
1026
1027 out << QString("%1%2%3\n")
1028 .arg(_clock_bias, 19, 'e', 12)
1029 .arg(_clock_drift, 19, 'e', 12)
1030 .arg(_clock_driftrate, 19, 'e', 12);
1031
1032 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
1033
1034 out << QString(fmt)
1035 .arg(_IODnav, 19, 'e', 12)
1036 .arg(_Crs, 19, 'e', 12)
1037 .arg(_Delta_n, 19, 'e', 12)
1038 .arg(_M0, 19, 'e', 12);
1039
1040 out << QString(fmt)
1041 .arg(_Cuc, 19, 'e', 12)
1042 .arg(_e, 19, 'e', 12)
1043 .arg(_Cus, 19, 'e', 12)
1044 .arg(_sqrt_A, 19, 'e', 12);
1045
1046 out << QString(fmt)
1047 .arg(_TOEsec, 19, 'e', 12)
1048 .arg(_Cic, 19, 'e', 12)
1049 .arg(_OMEGA0, 19, 'e', 12)
1050 .arg(_Cis, 19, 'e', 12);
1051
1052 out << QString(fmt)
1053 .arg(_i0, 19, 'e', 12)
1054 .arg(_Crc, 19, 'e', 12)
1055 .arg(_omega, 19, 'e', 12)
1056 .arg(_OMEGADOT, 19, 'e', 12);
1057
[6792]1058 int dataSource = 0;
1059 int SVhealth = 0;
1060 double BGD_1_5A = _BGD_1_5A;
1061 double BGD_1_5B = _BGD_1_5B;
[6812]1062 if (_fnav) {
[6792]1063 dataSource |= (1<<1);
1064 dataSource |= (1<<8);
1065 BGD_1_5B = 0.0;
1066 // SVhealth
1067 // Bit 3 : E5a DVS
[6812]1068 if (_e5aDataInValid) {
[6792]1069 SVhealth |= (1<<3);
1070 }
1071 // Bit 4-5: E5a HS
1072 if (_E5aHS == 1.0) {
1073 SVhealth |= (1<<4);
1074 }
1075 else if (_E5aHS == 2.0) {
1076 SVhealth |= (1<<5);
1077 }
1078 else if (_E5aHS == 3.0) {
1079 SVhealth |= (1<<4);
1080 SVhealth |= (1<<5);
1081 }
1082 }
[6812]1083 else if(_inav) {
[6803]1084 // Bit 2 and 0 are set because from MT1046 the data source cannot be determined
1085 // and RNXv3.03 says both can be set if the navigation messages were merged
[5539]1086 dataSource |= (1<<0);
[6792]1087 dataSource |= (1<<2);
[5540]1088 dataSource |= (1<<9);
[6792]1089 // SVhealth
1090 // Bit 0 : E1-B DVS
[6812]1091 if (_e1DataInValid) {
[6792]1092 SVhealth |= (1<<0);
1093 }
1094 // Bit 1-2: E1-B HS
1095 if (_E1_bHS == 1.0) {
1096 SVhealth |= (1<<1);
1097 }
1098 else if (_E1_bHS == 2.0) {
1099 SVhealth |= (1<<2);
1100 }
[6803]1101 else if (_E1_bHS == 3.0) {
[6792]1102 SVhealth |= (1<<1);
1103 SVhealth |= (1<<2);
1104 }
[6802]1105 // Bit 3 : E5a DVS
[6812]1106 if (_e5aDataInValid) {
[6802]1107 SVhealth |= (1<<3);
1108 }
1109 // Bit 4-5: E5a HS
1110 if (_E5aHS == 1.0) {
1111 SVhealth |= (1<<4);
1112 }
1113 else if (_E5aHS == 2.0) {
1114 SVhealth |= (1<<5);
1115 }
[6803]1116 else if (_E5aHS == 3.0) {
[6802]1117 SVhealth |= (1<<4);
1118 SVhealth |= (1<<5);
1119 }
[6792]1120 // Bit 6 : E5b DVS
[6812]1121 if (_e5bDataInValid) {
[6792]1122 SVhealth |= (1<<6);
1123 }
1124 // Bit 7-8: E5b HS
1125 if (_E5bHS == 1.0) {
1126 SVhealth |= (1<<7);
1127 }
1128 else if (_E5bHS == 2.0) {
1129 SVhealth |= (1<<8);
1130 }
[6803]1131 else if (_E5bHS == 3.0) {
[6792]1132 SVhealth |= (1<<7);
1133 SVhealth |= (1<<8);
1134 }
[5539]1135 }
[6792]1136
[4023]1137 out << QString(fmt)
[5532]1138 .arg(_IDOT, 19, 'e', 12)
1139 .arg(double(dataSource), 19, 'e', 12)
[6892]1140 .arg(_TOEweek + 1024.0, 19, 'e', 12)
[5532]1141 .arg(0.0, 19, 'e', 12);
[4023]1142
1143 out << QString(fmt)
[6798]1144 .arg(_SISA, 19, 'e', 12)
[6792]1145 .arg(double(SVhealth), 19, 'e', 12)
1146 .arg(BGD_1_5A, 19, 'e', 12)
1147 .arg(BGD_1_5B, 19, 'e', 12);
[4023]1148
[7922]1149 double tot = _TOT;
1150 if (tot == 0.9999e9 && version < 3.0) {
1151 tot = 0.0;
1152 }
[4023]1153 out << QString(fmt)
[7922]1154 .arg(tot, 19, 'e', 12)
[4024]1155 .arg("", 19, QChar(' '))
1156 .arg("", 19, QChar(' '))
1157 .arg("", 19, QChar(' '));
[4023]1158
1159 return rnxStr;
1160}
1161
[6385]1162// Constructor
1163//////////////////////////////////////////////////////////////////////////////
[6390]1164t_ephSBAS::t_ephSBAS(float rnxVersion, const QStringList& lines) {
1165
1166 const int nLines = 4;
1167
1168 if (lines.size() != nLines) {
[6518]1169 _checkState = bad;
[6390]1170 return;
1171 }
1172
1173 // RINEX Format
1174 // ------------
1175 int fieldLen = 19;
1176
1177 int pos[4];
1178 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
1179 pos[1] = pos[0] + fieldLen;
1180 pos[2] = pos[1] + fieldLen;
1181 pos[3] = pos[2] + fieldLen;
1182
1183 // Read four lines
1184 // ---------------
1185 for (int iLine = 0; iLine < nLines; iLine++) {
1186 QString line = lines[iLine];
1187
1188 if ( iLine == 0 ) {
[8204]1189 QTextStream in(line.left(pos[1]).toLatin1());
[6390]1190
1191 int year, month, day, hour, min;
1192 double sec;
[6880]1193
[7139]1194 QString prnStr, n;
[6880]1195 in >> prnStr;
[7639]1196 if (prnStr.size() == 1 && prnStr[0] == 'S') {
[7139]1197 in >> n;
1198 prnStr.append(n);
[6880]1199 }
1200 in >> year >> month >> day >> hour >> min >> sec;
[6390]1201 if (prnStr.at(0) == 'S') {
1202 _prn.set('S', prnStr.mid(1).toInt());
1203 }
1204 else {
1205 _prn.set('S', prnStr.toInt());
1206 }
1207
1208 if (year < 80) {
1209 year += 2000;
1210 }
1211 else if (year < 100) {
1212 year += 1900;
1213 }
1214
1215 _TOC.set(year, month, day, hour, min, sec);
1216
1217 if ( readDbl(line, pos[1], fieldLen, _agf0 ) ||
1218 readDbl(line, pos[2], fieldLen, _agf1 ) ||
[8456]1219 readDbl(line, pos[3], fieldLen, _TOT ) ) {
[6518]1220 _checkState = bad;
[6390]1221 return;
1222 }
1223 }
1224
1225 else if ( iLine == 1 ) {
1226 if ( readDbl(line, pos[0], fieldLen, _x_pos ) ||
1227 readDbl(line, pos[1], fieldLen, _x_velocity ) ||
1228 readDbl(line, pos[2], fieldLen, _x_acceleration) ||
1229 readDbl(line, pos[3], fieldLen, _health ) ) {
[6518]1230 _checkState = bad;
[6390]1231 return;
1232 }
1233 }
1234
1235 else if ( iLine == 2 ) {
1236 if ( readDbl(line, pos[0], fieldLen, _y_pos ) ||
1237 readDbl(line, pos[1], fieldLen, _y_velocity ) ||
1238 readDbl(line, pos[2], fieldLen, _y_acceleration ) ||
1239 readDbl(line, pos[3], fieldLen, _ura ) ) {
[6518]1240 _checkState = bad;
[6390]1241 return;
1242 }
1243 }
1244
1245 else if ( iLine == 3 ) {
[6536]1246 double iodn;
[6390]1247 if ( readDbl(line, pos[0], fieldLen, _z_pos ) ||
1248 readDbl(line, pos[1], fieldLen, _z_velocity ) ||
1249 readDbl(line, pos[2], fieldLen, _z_acceleration) ||
[6536]1250 readDbl(line, pos[3], fieldLen, iodn ) ) {
[6518]1251 _checkState = bad;
[6390]1252 return;
[6891]1253 } else {
[6536]1254 _IODN = int(iodn);
[6390]1255 }
1256 }
1257 }
1258
[7278]1259 _x_pos *= 1.e3;
1260 _y_pos *= 1.e3;
1261 _z_pos *= 1.e3;
1262 _x_velocity *= 1.e3;
1263 _y_velocity *= 1.e3;
1264 _z_velocity *= 1.e3;
1265 _x_acceleration *= 1.e3;
1266 _y_acceleration *= 1.e3;
1267 _z_acceleration *= 1.e3;
[6385]1268}
1269
[7054]1270// IOD of SBAS Ephemeris (virtual)
1271////////////////////////////////////////////////////////////////////////////
1272
[7169]1273unsigned int t_ephSBAS::IOD() const {
[7054]1274 unsigned char buffer[80];
1275 int size = 0;
1276 int numbits = 0;
1277 long long bitbuffer = 0;
1278 unsigned char *startbuffer = buffer;
1279
1280 SBASADDBITSFLOAT(30, this->_x_pos, 0.08)
1281 SBASADDBITSFLOAT(30, this->_y_pos, 0.08)
1282 SBASADDBITSFLOAT(25, this->_z_pos, 0.4)
1283 SBASADDBITSFLOAT(17, this->_x_velocity, 0.000625)
1284 SBASADDBITSFLOAT(17, this->_y_velocity, 0.000625)
1285 SBASADDBITSFLOAT(18, this->_z_velocity, 0.004)
1286 SBASADDBITSFLOAT(10, this->_x_acceleration, 0.0000125)
1287 SBASADDBITSFLOAT(10, this->_y_acceleration, 0.0000125)
1288 SBASADDBITSFLOAT(10, this->_z_acceleration, 0.0000625)
1289 SBASADDBITSFLOAT(12, this->_agf0, 1.0/static_cast<double>(1<<30)/static_cast<double>(1<<1))
1290 SBASADDBITSFLOAT(8, this->_agf1, 1.0/static_cast<double>(1<<30)/static_cast<double>(1<<10))
1291 SBASADDBITS(5,0); // the last byte is filled by 0-bits to obtain a length of an integer multiple of 8
1292
1293 return CRC24(size, startbuffer);
1294}
1295
[6385]1296// Compute SBAS Satellite Position (virtual)
1297////////////////////////////////////////////////////////////////////////////
1298t_irc t_ephSBAS::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
[6386]1299
1300 bncTime tt(GPSweek, GPSweeks);
1301 double dt = tt - _TOC;
1302
[7278]1303 xc[0] = _x_pos + _x_velocity * dt + _x_acceleration * dt * dt / 2.0;
1304 xc[1] = _y_pos + _y_velocity * dt + _y_acceleration * dt * dt / 2.0;
1305 xc[2] = _z_pos + _z_velocity * dt + _z_acceleration * dt * dt / 2.0;
[6386]1306
1307 vv[0] = _x_velocity + _x_acceleration * dt;
1308 vv[1] = _y_velocity + _y_acceleration * dt;
1309 vv[2] = _z_velocity + _z_acceleration * dt;
1310
1311 xc[3] = _agf0 + _agf1 * dt;
1312
[8542]1313 xc[4] = _agf1;
1314 xc[5] = 0.0;
[8483]1315
[6386]1316 return success;
[6385]1317}
1318
1319// RINEX Format String
1320//////////////////////////////////////////////////////////////////////////////
[6388]1321QString t_ephSBAS::toString(double version) const {
1322
1323 QString rnxStr = rinexDateStr(_TOC, _prn, version);
1324
1325 QTextStream out(&rnxStr);
1326
1327 out << QString("%1%2%3\n")
[6390]1328 .arg(_agf0, 19, 'e', 12)
1329 .arg(_agf1, 19, 'e', 12)
[8456]1330 .arg(_TOT, 19, 'e', 12);
[6388]1331
1332 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
1333
1334 out << QString(fmt)
1335 .arg(1.e-3*_x_pos, 19, 'e', 12)
1336 .arg(1.e-3*_x_velocity, 19, 'e', 12)
1337 .arg(1.e-3*_x_acceleration, 19, 'e', 12)
[6390]1338 .arg(_health, 19, 'e', 12);
[6388]1339
1340 out << QString(fmt)
1341 .arg(1.e-3*_y_pos, 19, 'e', 12)
1342 .arg(1.e-3*_y_velocity, 19, 'e', 12)
1343 .arg(1.e-3*_y_acceleration, 19, 'e', 12)
[6390]1344 .arg(_ura, 19, 'e', 12);
[6388]1345
1346 out << QString(fmt)
1347 .arg(1.e-3*_z_pos, 19, 'e', 12)
1348 .arg(1.e-3*_z_velocity, 19, 'e', 12)
1349 .arg(1.e-3*_z_acceleration, 19, 'e', 12)
[6536]1350 .arg(double(_IODN), 19, 'e', 12);
[6388]1351
1352 return rnxStr;
[6385]1353}
[6400]1354
1355// Constructor
1356//////////////////////////////////////////////////////////////////////////////
[6600]1357t_ephBDS::t_ephBDS(float rnxVersion, const QStringList& lines) {
[6400]1358
1359 const int nLines = 8;
1360
1361 if (lines.size() != nLines) {
[6518]1362 _checkState = bad;
[6400]1363 return;
1364 }
1365
1366 // RINEX Format
1367 // ------------
1368 int fieldLen = 19;
1369
1370 int pos[4];
1371 pos[0] = (rnxVersion <= 2.12) ? 3 : 4;
1372 pos[1] = pos[0] + fieldLen;
1373 pos[2] = pos[1] + fieldLen;
1374 pos[3] = pos[2] + fieldLen;
1375
1376 // Read eight lines
1377 // ----------------
1378 for (int iLine = 0; iLine < nLines; iLine++) {
1379 QString line = lines[iLine];
1380
1381 if ( iLine == 0 ) {
[8204]1382 QTextStream in(line.left(pos[1]).toLatin1());
[6400]1383
1384 int year, month, day, hour, min;
1385 double sec;
[6880]1386
[7139]1387 QString prnStr, n;
[6880]1388 in >> prnStr;
[7639]1389 if (prnStr.size() == 1 && prnStr[0] == 'C') {
[7139]1390 in >> n;
1391 prnStr.append(n);
[6880]1392 }
1393 in >> year >> month >> day >> hour >> min >> sec;
[6400]1394 if (prnStr.at(0) == 'C') {
1395 _prn.set('C', prnStr.mid(1).toInt());
1396 }
1397 else {
1398 _prn.set('C', prnStr.toInt());
1399 }
1400
1401 if (year < 80) {
1402 year += 2000;
1403 }
1404 else if (year < 100) {
1405 year += 1900;
1406 }
1407
[6812]1408 _TOC.setBDS(year, month, day, hour, min, sec);
[6400]1409
1410 if ( readDbl(line, pos[1], fieldLen, _clock_bias ) ||
1411 readDbl(line, pos[2], fieldLen, _clock_drift ) ||
1412 readDbl(line, pos[3], fieldLen, _clock_driftrate) ) {
[6518]1413 _checkState = bad;
[6400]1414 return;
1415 }
1416 }
1417
1418 else if ( iLine == 1 ) {
1419 double aode;
1420 if ( readDbl(line, pos[0], fieldLen, aode ) ||
1421 readDbl(line, pos[1], fieldLen, _Crs ) ||
1422 readDbl(line, pos[2], fieldLen, _Delta_n) ||
1423 readDbl(line, pos[3], fieldLen, _M0 ) ) {
[6518]1424 _checkState = bad;
[6400]1425 return;
1426 }
1427 _AODE = int(aode);
1428 }
1429
1430 else if ( iLine == 2 ) {
1431 if ( readDbl(line, pos[0], fieldLen, _Cuc ) ||
1432 readDbl(line, pos[1], fieldLen, _e ) ||
1433 readDbl(line, pos[2], fieldLen, _Cus ) ||
1434 readDbl(line, pos[3], fieldLen, _sqrt_A) ) {
[6518]1435 _checkState = bad;
[6400]1436 return;
1437 }
1438 }
1439
1440 else if ( iLine == 3 ) {
[6812]1441 if ( readDbl(line, pos[0], fieldLen, _TOEsec ) ||
[6400]1442 readDbl(line, pos[1], fieldLen, _Cic ) ||
1443 readDbl(line, pos[2], fieldLen, _OMEGA0) ||
1444 readDbl(line, pos[3], fieldLen, _Cis ) ) {
[6518]1445 _checkState = bad;
[6400]1446 return;
1447 }
1448 }
1449
1450 else if ( iLine == 4 ) {
1451 if ( readDbl(line, pos[0], fieldLen, _i0 ) ||
1452 readDbl(line, pos[1], fieldLen, _Crc ) ||
1453 readDbl(line, pos[2], fieldLen, _omega ) ||
1454 readDbl(line, pos[3], fieldLen, _OMEGADOT) ) {
[6518]1455 _checkState = bad;
[6400]1456 return;
1457 }
1458 }
1459
1460 else if ( iLine == 5 ) {
1461 if ( readDbl(line, pos[0], fieldLen, _IDOT ) ||
[6812]1462 readDbl(line, pos[2], fieldLen, _TOEweek)) {
[6518]1463 _checkState = bad;
[6400]1464 return;
1465 }
1466 }
1467
1468 else if ( iLine == 6 ) {
1469 double SatH1;
[6755]1470 if ( readDbl(line, pos[0], fieldLen, _URA ) ||
1471 readDbl(line, pos[1], fieldLen, SatH1) ||
[6400]1472 readDbl(line, pos[2], fieldLen, _TGD1) ||
1473 readDbl(line, pos[3], fieldLen, _TGD2) ) {
[6518]1474 _checkState = bad;
[6400]1475 return;
1476 }
1477 _SatH1 = int(SatH1);
1478 }
1479
1480 else if ( iLine == 7 ) {
1481 double aodc;
[6812]1482 if ( readDbl(line, pos[0], fieldLen, _TOT) ||
[6400]1483 readDbl(line, pos[1], fieldLen, aodc) ) {
[6518]1484 _checkState = bad;
[6400]1485 return;
1486 }
[6812]1487 if (_TOT == 0.9999e9) { // 0.9999e9 means not known (RINEX standard)
1488 _TOT = _TOEsec;
[6400]1489 }
1490 _AODC = int(aodc);
1491 }
1492 }
1493
[7138]1494 _TOE.setBDS(int(_TOEweek), _TOEsec);
1495
[6400]1496 // remark: actually should be computed from second_tot
1497 // but it seems to be unreliable in RINEX files
[6843]1498 //_TOT = _TOC.bdssec();
[6400]1499}
1500
[7054]1501// IOD of BDS Ephemeris (virtual)
1502////////////////////////////////////////////////////////////////////////////
[7169]1503unsigned int t_ephBDS::IOD() const {
[8410]1504 return (int(_TOEsec)/720) % 240;
[7054]1505}
1506
[6601]1507// Compute BDS Satellite Position (virtual)
[6400]1508//////////////////////////////////////////////////////////////////////////////
[6600]1509t_irc t_ephBDS::position(int GPSweek, double GPSweeks, double* xc, double* vv) const {
[6400]1510
[6602]1511 static const double gmBDS = 398.6004418e12;
1512 static const double omegaBDS = 7292115.0000e-11;
[6400]1513
1514 xc[0] = xc[1] = xc[2] = xc[3] = 0.0;
1515 vv[0] = vv[1] = vv[2] = 0.0;
1516
1517 bncTime tt(GPSweek, GPSweeks);
1518
1519 if (_sqrt_A == 0) {
1520 return failure;
1521 }
1522 double a0 = _sqrt_A * _sqrt_A;
1523
[6602]1524 double n0 = sqrt(gmBDS/(a0*a0*a0));
[6400]1525 double tk = tt - _TOE;
1526 double n = n0 + _Delta_n;
1527 double M = _M0 + n*tk;
1528 double E = M;
1529 double E_last;
1530 int nLoop = 0;
1531 do {
1532 E_last = E;
1533 E = M + _e*sin(E);
1534
1535 if (++nLoop == 100) {
1536 return failure;
1537 }
1538 } while ( fabs(E-E_last)*a0 > 0.001 );
1539
1540 double v = atan2(sqrt(1-_e*_e) * sin(E), cos(E) - _e);
1541 double u0 = v + _omega;
1542 double sin2u0 = sin(2*u0);
1543 double cos2u0 = cos(2*u0);
1544 double r = a0*(1 - _e*cos(E)) + _Crc*cos2u0 + _Crs*sin2u0;
1545 double i = _i0 + _IDOT*tk + _Cic*cos2u0 + _Cis*sin2u0;
1546 double u = u0 + _Cuc*cos2u0 + _Cus*sin2u0;
1547 double xp = r*cos(u);
1548 double yp = r*sin(u);
1549 double toesec = (_TOE.gpssec() - 14.0);
1550 double sinom = 0;
1551 double cosom = 0;
1552 double sini = 0;
1553 double cosi = 0;
[7278]1554
[7481]1555 // Velocity
1556 // --------
1557 double tanv2 = tan(v/2);
1558 double dEdM = 1 / (1 - _e*cos(E));
1559 double dotv = sqrt((1.0 + _e)/(1.0 - _e)) / cos(E/2)/cos(E/2)
1560 / (1 + tanv2*tanv2) * dEdM * n;
1561 double dotu = dotv + (-_Cuc*sin2u0 + _Cus*cos2u0)*2*dotv;
1562 double doti = _IDOT + (-_Cic*sin2u0 + _Cis*cos2u0)*2*dotv;
1563 double dotr = a0 * _e*sin(E) * dEdM * n
1564 + (-_Crc*sin2u0 + _Crs*cos2u0)*2*dotv;
1565
1566 double dotx = dotr*cos(u) - r*sin(u)*dotu;
1567 double doty = dotr*sin(u) + r*cos(u)*dotu;
1568
[6400]1569 const double iMaxGEO = 10.0 / 180.0 * M_PI;
1570
1571 // MEO/IGSO satellite
1572 // ------------------
1573 if (_i0 > iMaxGEO) {
[6602]1574 double OM = _OMEGA0 + (_OMEGADOT - omegaBDS)*tk - omegaBDS*toesec;
[6400]1575
1576 sinom = sin(OM);
1577 cosom = cos(OM);
1578 sini = sin(i);
1579 cosi = cos(i);
1580
1581 xc[0] = xp*cosom - yp*cosi*sinom;
1582 xc[1] = xp*sinom + yp*cosi*cosom;
[7278]1583 xc[2] = yp*sini;
[7481]1584
1585 // Velocity
1586 // --------
1587
1588 double dotom = _OMEGADOT - t_CST::omega;
1589
1590 vv[0] = cosom *dotx - cosi*sinom *doty // dX / dr
1591 - xp*sinom*dotom - yp*cosi*cosom*dotom // dX / dOMEGA
1592 + yp*sini*sinom*doti; // dX / di
1593
1594 vv[1] = sinom *dotx + cosi*cosom *doty
1595 + xp*cosom*dotom - yp*cosi*sinom*dotom
1596 - yp*sini*cosom*doti;
1597
1598 vv[2] = sini *doty + yp*cosi *doti;
1599
[6400]1600 }
1601
1602 // GEO satellite
1603 // -------------
1604 else {
[6602]1605 double OM = _OMEGA0 + _OMEGADOT*tk - omegaBDS*toesec;
1606 double ll = omegaBDS*tk;
[6400]1607
1608 sinom = sin(OM);
1609 cosom = cos(OM);
1610 sini = sin(i);
1611 cosi = cos(i);
1612
1613 double xx = xp*cosom - yp*cosi*sinom;
1614 double yy = xp*sinom + yp*cosi*cosom;
[7278]1615 double zz = yp*sini;
[6400]1616
[7487]1617 Matrix RX = BNC_PPP::t_astro::rotX(-5.0 / 180.0 * M_PI);
1618 Matrix RZ = BNC_PPP::t_astro::rotZ(ll);
[6400]1619
1620 ColumnVector X1(3); X1 << xx << yy << zz;
[7487]1621 ColumnVector X2 = RZ*RX*X1;
[6400]1622
1623 xc[0] = X2(1);
1624 xc[1] = X2(2);
1625 xc[2] = X2(3);
[7278]1626
[7481]1627 double dotom = _OMEGADOT;
[6400]1628
[7481]1629 double vx = cosom *dotx - cosi*sinom *doty
1630 - xp*sinom*dotom - yp*cosi*cosom*dotom
1631 + yp*sini*sinom*doti;
[6400]1632
[7481]1633 double vy = sinom *dotx + cosi*cosom *doty
1634 + xp*cosom*dotom - yp*cosi*sinom*dotom
1635 - yp*sini*cosom*doti;
[7278]1636
[7501]1637 double vz = sini *doty + yp*cosi *doti;
[6400]1638
[7501]1639 ColumnVector V(3); V << vx << vy << vz;
[7481]1640
[7487]1641 Matrix RdotZ(3,3);
[7481]1642 double C = cos(ll);
1643 double S = sin(ll);
1644 Matrix UU(3,3);
1645 UU[0][0] = -S; UU[0][1] = +C; UU[0][2] = 0.0;
1646 UU[1][0] = -C; UU[1][1] = -S; UU[1][2] = 0.0;
1647 UU[2][0] = 0.0; UU[2][1] = 0.0; UU[2][2] = 0.0;
[7487]1648 RdotZ = omegaBDS * UU;
[7481]1649
1650 ColumnVector VV(3);
[7487]1651 VV = RZ*RX*V + RdotZ*RX*X1;
[7481]1652
1653 vv[0] = VV(1);
1654 vv[1] = VV(2);
1655 vv[2] = VV(3);
1656 }
1657
1658 double tc = tt - _TOC;
1659 xc[3] = _clock_bias + _clock_drift*tc + _clock_driftrate*tc*tc;
1660
[7278]1661 // dotC = _clock_drift + _clock_driftrate*tc
[6400]1662 // - 4.442807633e-10*_e*sqrt(a0)*cos(E) * dEdM * n;
1663
[7481]1664 // Relativistic Correction
1665 // -----------------------
1666 // correspondent to BDS ICD and to SSR standard
[8964]1667 xc[3] -= 4.442807633e-10 * _e * sqrt(a0) *sin(E);
[7481]1668 // correspondent to IGS convention
1669 // xc[3] -= 2.0 * (xc[0]*vv[0] + xc[1]*vv[1] + xc[2]*vv[2]) / t_CST::c / t_CST::c;
1670
[8542]1671 xc[4] = _clock_drift + _clock_driftrate*tc;
1672 xc[5] = _clock_driftrate;
[6400]1673 return success;
1674}
1675
1676// RINEX Format String
1677//////////////////////////////////////////////////////////////////////////////
[6600]1678QString t_ephBDS::toString(double version) const {
[8419]1679
[6812]1680 QString rnxStr = rinexDateStr(_TOC-14.0, _prn, version);
[6400]1681
1682 QTextStream out(&rnxStr);
1683
1684 out << QString("%1%2%3\n")
1685 .arg(_clock_bias, 19, 'e', 12)
1686 .arg(_clock_drift, 19, 'e', 12)
1687 .arg(_clock_driftrate, 19, 'e', 12);
1688
1689 QString fmt = version < 3.0 ? " %1%2%3%4\n" : " %1%2%3%4\n";
1690
1691 out << QString(fmt)
1692 .arg(double(_AODE), 19, 'e', 12)
1693 .arg(_Crs, 19, 'e', 12)
1694 .arg(_Delta_n, 19, 'e', 12)
1695 .arg(_M0, 19, 'e', 12);
1696
1697 out << QString(fmt)
1698 .arg(_Cuc, 19, 'e', 12)
1699 .arg(_e, 19, 'e', 12)
1700 .arg(_Cus, 19, 'e', 12)
1701 .arg(_sqrt_A, 19, 'e', 12);
1702
[6843]1703 double toes = 0.0;
1704 if (_TOEweek > -1.0) {// RINEX input
1705 toes = _TOEsec;
1706 }
1707 else {// RTCM stream input
[6812]1708 toes = _TOE.bdssec();
[6755]1709 }
[6400]1710 out << QString(fmt)
[6843]1711 .arg(toes, 19, 'e', 12)
[6755]1712 .arg(_Cic, 19, 'e', 12)
1713 .arg(_OMEGA0, 19, 'e', 12)
1714 .arg(_Cis, 19, 'e', 12);
[6400]1715
1716 out << QString(fmt)
1717 .arg(_i0, 19, 'e', 12)
1718 .arg(_Crc, 19, 'e', 12)
1719 .arg(_omega, 19, 'e', 12)
1720 .arg(_OMEGADOT, 19, 'e', 12);
1721
[6843]1722 double toew = 0.0;
1723 if (_TOEweek > -1.0) {// RINEX input
1724 toew = _TOEweek;
1725 }
1726 else {// RTCM stream input
1727 toew = double(_TOE.bdsw());
1728 }
[6400]1729 out << QString(fmt)
[6843]1730 .arg(_IDOT, 19, 'e', 12)
1731 .arg(0.0, 19, 'e', 12)
1732 .arg(toew, 19, 'e', 12)
1733 .arg(0.0, 19, 'e', 12);
[6400]1734
1735 out << QString(fmt)
[6798]1736 .arg(_URA, 19, 'e', 12)
[6400]1737 .arg(double(_SatH1), 19, 'e', 12)
1738 .arg(_TGD1, 19, 'e', 12)
1739 .arg(_TGD2, 19, 'e', 12);
1740
[6843]1741 double tots = 0.0;
1742 if (_TOEweek > -1.0) {// RINEX input
1743 tots = _TOT;
1744 }
1745 else {// RTCM stream input
[6812]1746 tots = _TOE.bdssec();
[6755]1747 }
[6400]1748 out << QString(fmt)
[6792]1749 .arg(tots, 19, 'e', 12)
[6755]1750 .arg(double(_AODC), 19, 'e', 12)
1751 .arg("", 19, QChar(' '))
1752 .arg("", 19, QChar(' '));
[6400]1753 return rnxStr;
1754}
Note: See TracBrowser for help on using the repository browser.