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

Last change on this file since 9765 was 9765, checked in by stuerze, 22 months ago

some more changes to consider RINEX Version 4 nav file (EPH key only)

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