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

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

IRNSS support is added in RINEX QC

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