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

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

GPS fit intervall: different specifications in differet RINEX versions are now considerred

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