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

Last change on this file since 8405 was 8368, checked in by stuerze, 6 years ago

small bug fixes in 'reqc' ephemeris check

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