How aloistr/swisseph works
1. What this repository is
- Swiss Ephemeris is primarily a C calculation library for astronomical/astrological ephemerides, not an application server or web app.
- The repo bundles the core source code, ephemeris data files, CLI tools, tests, documentation, and platform bindings.
2. Core computation engine
- The main library lives in the root C files: sweph.c, swephlib.c, swedate.c, swehouse.c, swemmoon.c, swemplan.c, swecl.c, swehel.c, swejpl.c, and related headers.
- These modules implement the low-level astronomy logic: date/time conversion, planetary and lunar calculations, house systems, eclipses, coordinate transforms, and JPL ephemeris access.
3. Public API boundary
- swephexp.h, sweph.h, swedll.h, and the other headers define the callable API and exported symbols.
- The architecture is a classic library boundary: external programs call Swiss Ephemeris functions, which then resolve data files and compute results internally.
4. Ephemeris data as a separate runtime dependency
- The ephe/ directory is not code; it is the runtime data store the library reads from.
- It contains compressed planetary and lunar files (*.se1), asteroid files, star lists, leap-second data, and lookup lists.
- The README makes clear that the library searches these files through an ephemeris path configured at runtime, via defaults, environment variables, or swe_set_ephe_path().
5. Data flow: from API call to file-backed calculation
- A consumer calls a library function with a date/time and target object.
- The library normalizes the input using the date/time subsystem, then looks up the required ephemeris record in ephe/ or, when configured, in external JPL files.
- The result is computed and returned directly to the caller; there is no persistent application state or database layer.
6. JPL integration
- swejpl.c and related files provide support for JPL binary ephemerides such as DE200, DE406, DE431, and DE441.
- These files are external downloads from NASA JPL and are treated as optional high-precision runtime inputs.
- This creates a boundary between Swiss Ephemeris logic and third-party scientific data.
7. Command-line tools
- swetest.c is the main interactive/automation CLI for querying calculations from the library.
- swevents.c is a higher-level tool for event searches, built on top of the same calculation engine.
- bin/ contains helper launchers/scripts for these executables.
8. Regression and validation subsystem
- setest/ is a substantial test harness with suites for calculations, fixstars, dates, houses, eclipses, rise/set, and other domains.
- It includes custom readers, checkpointing, generated fixtures, and shell/perl helpers, indicating the project relies on data-driven regression testing against known outputs.
- This test layer is important for preserving numerical correctness across releases.
9. Platform-specific integrations
- contrib/android/jni/ contains JNI bindings and Android build files, showing how the C core is exposed to Android applications.
- windows/ contains native Windows programs, resources, and VB declaration files for integration with Windows tooling and Excel/VB environments.
- These are wrappers around the same underlying C engine rather than separate implementations.
10. Documentation and release packaging
- doc/ contains the user and programmer documentation, including PDFs and HTML.
- contrib/ also holds third-party examples, language bindings, and packaged binaries.
- The repo structure reflects a distribution model where the source library, binary data files, and consumer integrations are shipped together.
11. Build and distribution model
- The top-level Makefile and per-subdirectory makefiles indicate a portable C build targeting multiple platforms.
- There is no single runtime service; instead, the build produces libraries and tools that depend on the ephemeris data files being placed correctly on disk.
12. Architectural diagram takeaway
- A good diagram should show:
- Consumers: CLI tools, tests, Windows apps, Android JNI, and external language bindings.
- Core library: the C calculation engine.
- Data inputs: local ephe/ files and optional JPL binaries.
- Support layers: tests, docs, and platform-specific wrappers.
- The key architectural theme is a file-backed scientific computation library with multiple front ends.
Main entry points: sweph.c Calc engine · swephexp.h Public API · Makefile Build files · README.md Documentation
Components 18
Core library
C ephemeris engine and public API boundary
- Public API · Callable surface and exported symbols
swephexp.h - Date/time · Input normalization and calendar conversions
swedate.c - Planets · Planetary and lunar position calculations
swemplan.c - Houses · House system calculations
swehouse.c - Events · Eclipses, rises, and other derived phenomena
swecl.c - Calc engine · Main orchestration and ephemeris computations
sweph.c - Support lib · Shared helpers, tables, and constants
swephlib.c - JPL access · Binary ephemeris integration for external DE files
swejpl.c
Runtime data
Ephemeris files and lookup tables consumed at runtime
- Ephemeris files · Local planetary, lunar, asteroid, and star data files
ephe - JPL binaries · Optional high-precision external ephemeris files
Command-line tools
Executable front ends built on the library
Validation
Regression suites and test harnesses
- Regression suite · Data-driven validation and checkpointing system
setest/setest.c - Test suites · Calculation, houses, eclipses, rise/set, and related suites
setest/suite_01_calc.c
Platform bindings
Native integrations for Android and Windows
- Android JNI · JNI bridge and Android build wrappers around the C core
contrib/android/jni/swejni.c - Windows apps · Native Windows programs and VB declarations using the library
windows/swewin/swewin.c
Docs & packaging
Documentation and distribution artifacts
- Documentation · User and programmer manuals plus HTML/PDF output
doc/README.md - Build files · Portable make-based build and release packaging
Makefile
Connections 22
- swetest → Public API: calls · CLI invokes the public C API
- swevents → Public API: calls · Event search tool uses library functions
- Regression suite → Public API: validates · Regression harness exercises the API
- Test suites → Regression suite: drives · Suite modules feed the test runner
- Android JNI → Public API: binds · JNI exposes the engine to Android apps
- Windows apps → Public API: wraps · Windows programs and VB declarations target the same core
- Public API → Calc engine: fronts · Public entry points dispatch into the calculation engine
- Calc engine → Date/time: normalizes · Input dates and times are converted before computation
- Calc engine → Planets: computes · Coordinates and positions are derived here
- Calc engine → Houses: computes · House-system results are produced here
- Calc engine → Events: derives · Higher-level phenomena are calculated here
- Calc engine → Support lib: uses · Shared helpers and tables support the main engine
- Calc engine → JPL access: optionally uses · High-precision mode delegates to JPL reader support
- Calc engine → Ephemeris files: reads · Standard calculations load file-backed ephemeris records
- JPL access → JPL binaries: reads · Optional backend consumes external binary ephemerides
- Build files → swetest: builds · Portable build produces CLI tools
- Build files → swevents: builds · Portable build produces CLI tools
- Build files → Android JNI: packages · Android makefiles and JNI sources are part of distribution
- Build files → Windows apps: packages · Windows artifacts and wrappers are distributed with the repo
- Documentation → Public API: describes · Documentation explains the library boundary and usage
- Documentation → swetest: documents · Manuals cover CLI usage and examples
- Documentation → Regression suite: documents · Test harness behavior and workflows are documented