52 #ifndef __PCL_JPLEphemeris_h
53 #define __PCL_JPLEphemeris_h
108 namespace JPLEphemerisItem
132 NumberOfRequiredItems = Sun + 1,
168 using item_index = JPLEphemerisItem::value_type;
212 #ifndef __PCL_NO_JPL_EPHEMERIS_TEST_ROUTINES
236 bool Test(
const String& filePath,
bool verbose =
true )
const;
336 if ( i == m_constants.
End() )
337 throw Error(
"Undefined integration constant '" + name +
'\'' );
348 if ( i == JPLEphemerisItem::Earth || i == JPLEphemerisItem::SSBMoon )
350 return i >= 0 && i < JPLEphemerisItem::NumberOfNativeItems && m_blockIndex[i].subblocks > 0;
368 return (i == JPLEphemerisItem::Nutations) ? 2 : (i == JPLEphemerisItem::TT_TDB ? 1 : 3);
391 if ( i == JPLEphemerisItem::Earth )
394 Interpolate( r.
Begin(),
nullptr, jd1, jd2, JPLEphemerisItem::EarthMoonBarycenter );
395 Interpolate( rm.
Begin(),
nullptr, jd1, jd2, JPLEphemerisItem::Moon );
399 else if ( i == JPLEphemerisItem::SSBMoon )
402 Interpolate( re.
Begin(),
nullptr, jd1, jd2, JPLEphemerisItem::EarthMoonBarycenter );
403 Interpolate( r.
Begin(),
nullptr, jd1, jd2, JPLEphemerisItem::Moon );
404 r += re - m_emb2Earth*r;
407 Interpolate( r.
Begin(),
nullptr, jd1, jd2, i );
409 if ( i != JPLEphemerisItem::Moon )
410 if ( i != JPLEphemerisItem::LunarLibration )
411 if ( i != JPLEphemerisItem::Nutations )
440 if ( i == JPLEphemerisItem::Earth )
443 Interpolate( r.
Begin(), v.
Begin(), jd1, jd2, JPLEphemerisItem::EarthMoonBarycenter );
444 Interpolate( rm.Begin(), vm.
Begin(), jd1, jd2, JPLEphemerisItem::Moon );
450 else if ( i == JPLEphemerisItem::SSBMoon )
453 Interpolate( re.Begin(), ve.
Begin(), jd1, jd2, JPLEphemerisItem::EarthMoonBarycenter );
454 Interpolate( r.
Begin(), v.
Begin(), jd1, jd2, JPLEphemerisItem::Moon );
455 r += re - m_emb2Earth*r;
456 v += ve - m_emb2Earth*v;
459 Interpolate( r.
Begin(), v.
Begin(), jd1, jd2, i );
461 if ( i != JPLEphemerisItem::Moon )
462 if ( i != JPLEphemerisItem::LunarLibration )
463 if ( i != JPLEphemerisItem::Nutations )
507 struct block_index_item
510 int coefficients = 0;
517 double m_ephStartJD = 0;
518 double m_ephEndJD = 0;
519 int m_blockDelta = 0;
521 block_index m_blockIndex;
523 double m_startJD = 0;
526 double m_emb2Earth = 0;
533 void Interpolate(
double* r,
double* v,
double jd1,
double jd2,
item_index n )
const
536 int ix =
TruncInt( ((jd1 - m_startJD) + jd2)/m_blockDelta );
537 if ( ix < 0 || ix >
int( m_blocks.Length() ) )
538 throw Error(
String().Format(
"Time point out of range: %.15g", jd1+jd2 ) );
539 if ( ix ==
int( m_blocks.Length() ) )
543 const double* block = m_blocks[ix].Begin();
546 const block_index_item& index = m_blockIndex[n];
555 int nk = index.coefficients;
558 int dx = m_blockDelta/index.subblocks;
561 ix = ((jd1 - jd0) + jd2)/dx;
562 if ( ix == index.subblocks )
566 const double* k = block + index.offset + ix*nv*nk;
571 pc[1] = (2*((jd1 - (jd0 + ix*dx)) + jd2) - dx)/dx;
573 for (
int i = 2; i < nk; ++i )
574 pc[i] = y2*pc[i-1] - pc[i-2];
575 for (
int i = 0; i < nv; ++i )
578 for (
int j = 0; j < nk; ++j )
579 r[i] += pc[j] * *k++;
585 double vf = 2.0*index.subblocks/m_blockDelta;
590 for (
int i = 3; i < nk; ++i )
591 vc[i] = y2*vc[i-1] + 2*pc[i-1] - vc[i-2];
592 for (
int i = nv; --i >= 0; )
595 for (
int j = nk; --j >= 0; )
596 v[i] += vc[j] * *--k;
A simple exception with an associated error message.
Generic array of vectors.
Generic vector of arbitrary length.
Eight-bit string (ISO/IEC-8859-1 or UTF-8 string)
EphemerisConstantList constant_list
bool Test(const String &filePath, bool verbose=true) const
void ComputeState(Vector &r, Vector &v, TimePoint t, item_index i) const
JPLEphemeris(const String &filePath)
void ComputeState(Vector &r, double jd1, double jd2, item_index i) const
void ComputeState(Vector &r, Vector &v, double jd1, double jd2, item_index i) const
void AddData(const String &filePath)
void ComputeState(Vector &r, TimePoint t, item_index i) const
double ConstantValue(const IsoString &name) const
double EphemerisEndJD() const
bool IsItemAvailable(int i) const
static int ComponentsForItem(int i)
JPLEphemerisItem::value_type item_index
IsoString Summary() const
const constant_list & Constants() const
double EphemerisStartJD() const
An instant in any timescale.
constexpr int JDI() const
constexpr double JDF() const
64-bit floating point real vector.
int TruncInt(T x) noexcept
FI BinarySearch(FI i, FI j, const T &v) noexcept
A numerical constant defined in an ephemeris file (XEPH format).
double value
The constant value.