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

Last change on this file since 8430 was 8420, checked in by stuerze, 6 years ago

minor changes to exclude unhealthy satellites from satellite coordinates determination

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