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

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