/** * se1.ts — Swiss Ephemeris .se1 binary file reader (pure TypeScript, no GPL) * * Reads DE431-based Chebyshev polynomial files from Astrodienst (.se1 format). * These data files are freely downloadable and carry no GPL restriction — * only the SE C library is AGPL/GPL. This reader is an independent * implementation of the documented binary format. * * Format reference: * https://www.astro.com/swisseph/swephprg.htm * Swiss Ephemeris source: sweph.c (read_const, get_new_segment) * * File layout: * [TEXT] 3 × CR+LF lines (version, filename, copyright) * [BIN] endian_test (int32) = 0x616263 * [BIN] file_length (int32) * [BIN] JPL DE number (int32) * [BIN] tfstart (double) — file Julian Day start * [BIN] tfend (double) — file Julian Day end * [BIN] npl (int16) — number of bodies * [BIN] ipl[npl] (int16 each) — body IDs * [BIN] CRC32 (int32) — checksum of header bytes so far * [BIN] gen_const: 5 doubles (clight, aunit, helgravconst, ratme, sunradius) * Per body (×npl): * [BIN] lndx0 (int32) — byte offset of segment index table * [BIN] iflg (uint8) — SEI_FLG_* flags * [BIN] ncoe (uint8) — Chebyshev coefficient count * [BIN] rmax_int (int32) — normalization factor × 1000 * [BIN] 10 doubles: tfstart,tfend,dseg,telem,prot,dprot,qrot,dqrot,peri,dperi * [BIN] refep: 2*ncoe doubles — ONLY if (iflg & SEI_FLG_ELLIPSE) * Data region: * Segment index at lndx0: 3 bytes per interval → byte offset of coeff block * Coefficient blocks: variable-width packed Chebyshev coefficients */ export declare const SE_BODY: { readonly Sun: 0; readonly Moon: 1; readonly Mercury: 2; readonly Venus: 3; readonly Mars: 4; readonly Jupiter: 5; readonly Saturn: 6; readonly Uranus: 7; readonly Neptune: 8; readonly Pluto: 9; readonly MeanNode: 10; }; interface PlanetDesc { bodyId: number; lndx0: number; iflg: number; ncoe: number; rmax: number; tfstart: number; tfend: number; dseg: number; nndx: number; telem: number; prot: number; dprot: number; qrot: number; dqrot: number; peri: number; dperi: number; refep?: Float64Array; } export declare class Se1File { private readonly buf; private readonly le; /** Map from SE body ID → descriptor */ readonly planets: Map; /** Mass ratio Earth/Moon (from gen_const, ~81.30) */ ratme: number; constructor(filePath: string); /** * Return geocentric ecliptic rectangular coordinates [x, y, z] in AU * for the given SE body ID at Julian Day `tjd` (barycentric/TDB approx). * * For Sun (body 0): returns heliocentric Earth position (caller must negate * to get Sun geocentric, or subtract from planet_helio for planet geocentric). * * For Moon (body 1): returns geocentric ecliptic position (EMB-adjusted). * * For other bodies: returns heliocentric ecliptic position. */ getRawPosition(bodyId: number, tjd: number): [number, number, number]; private textHeaderEnd; private parseHeader; private evalChebyshev; /** * Evaluate one Chebyshev component using the SE Clenshaw recursion. * Computes: coef[0]/2 + sum_{k=1}^{ncoe-1} coef[k] * T_k(t) * * coef[offset .. offset+ncoe-1] * * Clenshaw backward recurrence (k from ncoe-1 downto 1): * b[k] = coef[k] + 2t*b[k+1] - b[k+2] * After loop: br = b[1], brp2 = b[2] * Result: t * b[1] - b[2] + coef[0] / 2 */ private echeb; /** * Unpack a coefficient block at `fpos` into a Float64Array of length 3*ncoe. * * SE uses a 4-group (or 6-group) variable-width integer encoding. * Sign is encoded in the LSB of each stored integer (bit 0 = 1 → negative). * Magnitude = stored_uint >>> 1, then scaled: magnitude / 1e9 * rmax / 2. * * Critical: 4-byte values must be read as UNSIGNED (using buf.readUInt32LE) * because JavaScript's bitwise `|` operators produce Int32, not UInt32. * Use unsigned right shift `>>> 1` (not `>> 1`) for the magnitude. */ private unpackCoefficients; /** * Rotate position around the Z-axis by angle `a` (radians). * Used to apply the argument-of-perihelion rotation (peri field). */ private rotateZ; /** * Rotate position from orbital plane frame to J2000 ecliptic frame. * Transform: x_ecl = Rz(prot) × Rx(qrot) × x_orb * * @param P prot in radians (longitude of ascending node) * @param Q qrot in radians (orbital inclination) */ private rotatePlaneToEcliptic; private readF64; private readI32; private readI16; private read3Bytes; } export declare function loadSe1(filePath: string): Se1File; export declare function resetSe1Cache(): void; export {};