source: ntrip/branches/BNC_2.12/src/ephemeris.cpp@ 7923

Last change on this file since 7923 was 7923, checked in by stuerze, 8 years ago

minor changes in RINEX 2.11 epemeris output in case of an unknown transmission time

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