| 179 | |
| 180 | |
| 181 | double getTimeSystemCorrection(const TimeSystem inTS, |
| 182 | const TimeSystem outTS, |
| 183 | const int year, |
| 184 | const int month, |
| 185 | const double day) |
| 186 | { |
| 187 | double dt(0.0); |
| 188 | |
| 189 | // identity |
| 190 | if (inTS == outTS) |
| 191 | return dt; |
| 192 | |
| 193 | // cannot convert unknowns |
| 194 | if (inTS == TimeSystem::Unknown || outTS == TimeSystem::Unknown) |
| 195 | { |
| 196 | Exception e("Cannot compute correction for TimeSystem::Unknown"); |
| 197 | GNSSTK_THROW(e); |
| 198 | } |
| 199 | |
| 200 | // compute TT-TDB here; ref Astronomical Almanac B7 |
| 201 | double TDBmTT(0.0); |
| 202 | if (inTS == TimeSystem::TDB || outTS == TimeSystem::TDB) |
| 203 | { |
| 204 | int iday = int(day); |
| 205 | long jday = convertCalendarToJD(year, month, iday) ; |
| 206 | double frac(day-iday); |
| 207 | double TJ2000(jday-2451545.5+frac); // t-J2000 |
| 208 | // 0.0001657 sec * sin(357.53 + 0.98560028 * TJ2000 deg) |
| 209 | frac = ::fmod(0.017201969994578 * TJ2000, 6.2831853071796); |
| 210 | TDBmTT = 0.0001657 * ::sin(6.240075674 + frac); |
| 211 | // 0.000022 sec * sin(246.11 + 0.90251792 * TJ2000 deg) |
| 212 | frac = ::fmod(0.015751909262251 * TJ2000, 6.2831853071796); |
| 213 | TDBmTT += 0.000022 * ::sin(4.295429822 + frac); |
| 214 | } |
| 215 | |
| 216 | // Time system conversions constants |
| 217 | static const double TAI_minus_GPSGAL_EPOCH = 19.; |
| 218 | static const double TAI_minus_BDT_EPOCH = 33.; |
| 219 | static const double TAI_minus_TT_EPOCH = -32.184; |
| 220 | |
| 221 | // ----------------------------------------------------------- |
| 222 | // conversions: first convert inTS->TAI ... |
| 223 | // TAI = GPS + 19s |
| 224 | // TAI = UTC + getLeapSeconds() |
| 225 | // TAI = TT - 32.184s |
| 226 | if (inTS == TimeSystem::GPS || // GPS -> TAI |
| 227 | inTS == TimeSystem::GAL || // GAL -> TAI |
| 228 | inTS == TimeSystem::QZS || // QZS -> TAI |
| 229 | inTS == TimeSystem::IRN ) // IRN -> TAI |
| 230 | { |
| 231 | dt = TAI_minus_GPSGAL_EPOCH; |
| 232 | } |
| 233 | else if (inTS == TimeSystem::UTC) // UTC -> TAI |
| 234 | { |
| 235 | dt = getLeapSeconds(year, month, day); |
| 236 | } |
| 237 | else if (inTS == TimeSystem::GLO) // GLO -> TAI |
| 238 | { |