/* * eph_provider.h -- Ephemeris provider dispatch for pg_orrery * * Manages the optional JPL DE ephemeris alongside the compiled-in * VSOP87 and ELP2000-82B theories. * * Key design constraints: * - Per-backend lazy initialization (never in _PG_init/postmaster) * - ICRS equatorial -> ecliptic J2000 frame rotation at the boundary * - Automatic VSOP87 fallback on any DE error * - No shared state between PostgreSQL backends */ #ifndef PG_ORRERY_EPH_PROVIDER_H #define PG_ORRERY_EPH_PROVIDER_H #include "postgres.h" #include "types.h" /* * Ephemeris provider identifiers. */ typedef enum { EPH_VSOP87, /* compiled-in VSOP87 / ELP2000-82B (always available) */ EPH_JPL_DE /* JPL DE binary file (optional, STABLE) */ } EphProvider; /* * Initialize the GUC variable (pg_orrery.ephemeris_path). * Called from _PG_init(). Does NOT open the DE file. */ void eph_register_gucs(void); /* * Cleanup callback for on_proc_exit. * Closes the DE file descriptor if open. */ void eph_cleanup(int code, Datum arg); /* * Attempt to initialize the DE reader for this backend. * Returns true if DE is available and ready, false otherwise. * On first call, opens the file and validates. On subsequent calls, * returns cached status. * * Thread-safe per backend (each backend has its own static state). */ bool eph_de_available(void); /* * Which provider is currently active? */ EphProvider eph_current_provider(void); /* * Get the configured ephemeris file path (or NULL if not set). */ const char *eph_get_path(void); /* * Get planet heliocentric ecliptic J2000 position via DE. * * body_id: pg_orrery body ID (1=Mercury..8=Neptune) * jd: Julian date (TDB) * xyz[6]: output position (AU) in ecliptic J2000 frame * (xyz[3..5] are zero — velocity not yet implemented) * * Returns true on success. On failure, xyz is unchanged and * caller should fall back to VSOP87. */ bool eph_de_planet(int body_id, double jd, double xyz[6]); /* * Get Earth heliocentric ecliptic J2000 position via DE. * * jd: Julian date (TDB) * xyz[6]: output position (AU) in ecliptic J2000 frame * * Returns true on success. */ bool eph_de_earth(double jd, double xyz[6]); /* * Get Moon geocentric ecliptic J2000 position via DE. * * jd: Julian date (TDB) * xyz[3]: output position (AU) in ecliptic J2000 frame * * Returns true on success. On failure, caller falls back to ELP2000-82B. */ bool eph_de_moon(double jd, double xyz[3]); /* * Get Sun "heliocentric" position (always 0,0,0 but consistent API). */ bool eph_de_sun(double jd, double xyz[6]); /* * DE metadata accessors (for pg_orrery_ephemeris_info). * Return 0/0.0 if DE is not loaded. */ double eph_de_start_jd(void); double eph_de_end_jd(void); int eph_de_version(void); double eph_de_au_km(void); #endif /* PG_ORRERY_EPH_PROVIDER_H */