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

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

minor changes

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