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

Last change on this file since 8581 was 8581, checked in by stuerze, 5 years ago

minor changes

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