27 static constexpr std::size_t jpl_de_offset_time = 0xA5C;
30 static constexpr std::size_t jpl_de_offset_table1 = 0xA88;
33 static constexpr std::size_t jpl_de_offset_denum = 0xB18;
36 static constexpr std::size_t jpl_de_offset_table2 = 0xB1C;
39 static constexpr std::size_t jpl_de_offset_table3 = 0xB28;
42 static constexpr std::int32_t jpl_de_denum_endian_mask = 0xFFFF0000;
45 static constexpr std::size_t jpl_de_table1_count = 12;
48 static constexpr std::size_t jpl_de_table2_count = 1;
51 static constexpr std::size_t jpl_de_table3_count = 2;
54 static constexpr std::size_t jpl_de_max_item_count = jpl_de_table1_count + jpl_de_table2_count + jpl_de_table3_count;
57 static constexpr std::size_t jpl_de_constant_limit = 400;
60 static constexpr std::size_t jpl_de_constant_length = 6;
112 static constexpr std::uint8_t jpl_de_component_count[jpl_de_max_item_count] =
145 std::size_t (
deserialize_context::*read32)(std::byte*, std::size_t) = &deserialize_context::read32<std::endian::native>;
146 std::size_t (
deserialize_context::*read64)(std::byte*, std::size_t) = &deserialize_context::read64<std::endian::native>;
150 ctx.
seek(jpl_de_offset_denum);
151 ctx.
read8(
reinterpret_cast<std::byte*
>(&denum),
sizeof(std::int32_t));
154 if (denum & jpl_de_denum_endian_mask)
157 if constexpr (std::endian::native == std::endian::little)
159 read32 = &deserialize_context::read32<std::endian::big>;
160 read64 = &deserialize_context::read64<std::endian::big>;
164 read32 = &deserialize_context::read32<std::endian::little>;
165 read64 = &deserialize_context::read64<std::endian::little>;
170 double ephemeris_time[3];
171 ctx.
seek(jpl_de_offset_time);
172 std::invoke(read64, ctx,
reinterpret_cast<std::byte*
>(ephemeris_time), 3);
175 const double epoch = 2451545.0;
176 ephemeris_time[0] -= epoch;
177 ephemeris_time[1] -= epoch;
180 std::int32_t constant_count;
181 std::invoke(read32, ctx,
reinterpret_cast<std::byte*
>(&constant_count), 1);
184 std::int32_t coeff_table[jpl_de_max_item_count][3];
185 ctx.
seek(jpl_de_offset_table1);
186 std::invoke(read32, ctx,
reinterpret_cast<std::byte*
>(coeff_table), jpl_de_table1_count * 3);
189 ctx.
seek(jpl_de_offset_table2);
190 std::invoke(read32, ctx,
reinterpret_cast<std::byte*
>(&coeff_table[jpl_de_table1_count][0]), jpl_de_table2_count * 3);
193 if (constant_count > jpl_de_constant_limit)
195 ctx.
seek(jpl_de_offset_table3 + (constant_count - jpl_de_constant_limit) * jpl_de_constant_length);
199 std::invoke(read32, ctx,
reinterpret_cast<std::byte*
>(&coeff_table[jpl_de_table1_count + jpl_de_table2_count][0]), jpl_de_table3_count * 3);
202 std::int32_t record_coeff_count = 0;
203 for (
int i = 0; i < jpl_de_max_item_count; ++i)
205 std::int32_t coeff_count = coeff_table[i][0] + coeff_table[i][1] * coeff_table[i][2] *
static_cast<std::int32_t
>(jpl_de_component_count[i]) - 1;
206 record_coeff_count =
std::max(record_coeff_count, coeff_count);
210 std::size_t record_size = record_coeff_count *
sizeof(double);
211 std::size_t record_count =
static_cast<std::size_t
>((ephemeris_time[1] - ephemeris_time[0]) / ephemeris_time[2]);
214 std::size_t strides[11];
215 for (
int i = 0; i < 11; ++i)
217 strides[i] = coeff_table[i][2] * coeff_table[i][1] * 3;
224 for (
int i = 0; i < 11; ++i)
227 trajectory.t0 = ephemeris_time[0];
228 trajectory.t1 = ephemeris_time[1];
229 trajectory.dt = ephemeris_time[2] /
static_cast<double>(coeff_table[i][2]);
230 trajectory.n = coeff_table[i][1];
231 trajectory.a.resize(record_count * strides[i]);
235 for (std::size_t i = 0; i < record_count; ++i)
238 ctx.
seek((i + 2) * record_size + 2 *
sizeof(double));
240 for (
int j = 0; j < 11; ++j)
242 std::invoke(read64, ctx,
reinterpret_cast<std::byte*
>(&ephemeris.
trajectories[j].a[i * strides[j]]), strides[j]);
250 auto resource = std::make_unique<physics::orbit::ephemeris<double>>();
Templated resource loader.
Manages the loading, caching, and saving of resources.
@ jpl_de_id_saturn
Saturn.
@ jpl_de_id_earth_nutation
Earth nutation.
@ jpl_de_id_luma_angular_velocity
Lunar mantle angular velocity.
@ jpl_de_id_mercury
Mercury.
@ jpl_de_id_luma_libration
Lunar mantle libration.
@ jpl_de_id_tt_tdb
TT-TDB.
@ jpl_de_id_neptune
Neptune.
@ jpl_de_id_embary
Earth-Moon barycenter.
@ jpl_de_id_uranus
Uranus.
@ jpl_de_id_jupiter
Jupiter.
constexpr vector< T, N > max(const vector< T, N > &x, const vector< T, N > &y)
Returns a vector containing the maximum elements of two vectors.
Provides access to a deserialization state.
virtual void seek(std::size_t offset)=0
Seeks to a position in the file.
virtual std::size_t read8(std::byte *data, std::size_t count) noexcept(false)=0
Reads 8-bit (byte) data.
Specializations of deserializer define the deserialization process for a given type.
Table of orbital trajectories.
std::vector< trajectory< T > > trajectories
Table of orbital trajectories.