Skip to content

Commit

Permalink
CSPICE integration (#88)
Browse files Browse the repository at this point in the history
* Adjust solsys-calcepth tests

* Initial CSPICE support

* Tweaks to CSPICE support and test

* Documentation for CSPICE support
  • Loading branch information
attipaci authored Nov 10, 2024
1 parent e46497e commit 9fabfcd
Show file tree
Hide file tree
Showing 10 changed files with 745 additions and 32 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ Changes expected for the next feature release, expected around 1 February 2025.
the CALCEPH development files (C headers and unversioned static or shared libraries depending on the needs of the
build).

- #86: NAIF CSPICE integration: `novas_use_cspice()`, `novas_use_cspice_planets()`, `novas_use_cspice_ephem()`
to use the NAIF CSPICE library for all Solar-system sources, major planets only, or for other bodies only.
`NOVAS_EPHEM_OBJECTS` should use NAIF IDs with CSPICE (or else -1 for name-based lookup). These functions are
provided by the `libsolsys-cspice.so[.1]` and/or `.a` plugin libraries, which are built contingent on the
`CSPICE_SUPPORT` variable being set to 1 prior to the build. The build of the plugin module requires an accessible
installation of the CSPICE development files (C headers and unversioned static or shared libraries depending on the
needs of the build).

- #87: Added `novas_planet_for_name()` function to return the NOVAS planet ID for a given (case insensitive) name.

- NOVAS-NAIF conversions for major planets (and Sun, Moon, SSB): `novas_to_naif_planet()` (planet centers),
Expand Down
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ ifeq ($(CALCEPH_SUPPORT),1)
SHARED_TARGETS += $(LIB)/libsolsys-calceph.so
endif

ifeq ($(CSPICE_SUPPORT),1)
CPPFLAGS += -DUSE_CSPICE=1
SOLSYS_TARGETS += $(OBJ)/solsys-cspice.o
SHARED_TARGETS += $(LIB)/libsolsys-cspice.so
endif

# Default target for packaging with Linux distributions
.PHONY: distro
distro: $(SHARED_TARGETS) $(DOC_TARGETS)
Expand Down Expand Up @@ -118,6 +124,8 @@ $(LIB)/libsolsys-ephem.so: $(LIB)/libsolsys-ephem.so.$(SO_VERSION)

$(LIB)/libsolsys-calceph.so: $(LIB)/libsolsys-calceph.so.$(SO_VERSION)

$(LIB)/libsolsys-cspice.so: $(LIB)/libsolsys-cspice.so.$(SO_VERSION)

$(LIB)/libnovas.so: $(LIB)/libsupernovas.so

$(LIB)/libsolsys%.so.$(SO_VERSION): LDFLAGS += -L$(LIB) -lsupernovas
Expand Down Expand Up @@ -145,6 +153,10 @@ $(LIB)/libsolsys-ephem.so.$(SO_VERSION): $(SRC)/solsys-ephem.c | $(LIB)/libsuper
$(LIB)/libsolsys-calceph.so.$(SO_VERSION): LDFLAGS += -lcalceph
$(LIB)/libsolsys-calceph.so.$(SO_VERSION): $(SRC)/solsys-calceph.c | $(LIB)/libsupernovas.so

# Shared library: libsolsys-cspice.so.1 (standalone solsys2.c functionality)
$(LIB)/libsolsys-cspice.so.$(SO_VERSION): LDFLAGS += -lcspice
$(LIB)/libsolsys-cspice.so.$(SO_VERSION): $(SRC)/solsys-cspice.c | $(LIB)/libsupernovas.so


# Static library: libnovas.a
$(LIB)/libnovas.a: $(OBJECTS) | $(LIB) Makefile
Expand Down
86 changes: 75 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ Outside contributions are very welcome. See
from JPL and/or in INPOP 2.0/3.0 format.
- [NAIF SPICE toolkit](https://naif.jpl.nasa.gov/naif/toolkit.html) for integrating Solar-system ephemeris
via from JPL.
- [Smithsonian/cspice-sharedlib](https://github.com/Smithsonian/cspice-sharedlib) for building CSPICE as a shared
library for dynamic linking.
- [IAU Minor Planet Center](https://www.minorplanetcenter.net/iau/mpc.html) provides another source
of ephemeris data.

Expand Down Expand Up @@ -201,8 +203,15 @@ the necessary variables in the shell prior to invoking `make`. For example:
setting `CALCEPH_SUPPORT = 1` in `config.mk` or in the shell prior to the build. When enabled it will build
`libsolsys-calceph.so[.1]` and/or `.a` supplemental libraries, depending on the build target. The build of the
modules requires an accessible installation of the CALCEPH development files (C headers and unversioned static or
shared libraries depending on the needs of the build). You might want to set `LD_LIBRARY_PATH`, and/or `CPPFLAGS`
to include an appropriate `-I<path>` option, to help locate these prior to calling `make`.
shared libraries depending on the needs of the build).

- You can enable integration with the [NAIF CSPICE Toolkit](https://naif.jpl.nasa.gov/naif/toolkit.html), by setting
`CSPICE_SUPPORT = 1` in `config.mk` or in the shell prior to the build. When enabled it will build
`libsolsys-cspice.so[.1]` and/or `.a` supplemental libraries, depending on the build target. The build of the
modules requires an accessible installation of the CSPICE development files (C headers, under a `cspice/`
sub-folder in the header search path, and unversioned static or shared libraries depending on the needs of the
build). You might want to check out the [Smithsonian/cspice-sharedlib](https://github.com/Smithsonian/cspice-sharedlib)
repository for building CSPICE as a shared library.

- If you want to use the CIO locator binary file for `cio_location()`, you can specify the path to the CIO locator
file (e.g. `/usr/local/share/supernovas/CIO_RA.TXT`) on your system e.g. by setting the `CIO_LOCATOR_FILE` shell
Expand Down Expand Up @@ -814,13 +823,19 @@ before that level of accuracy is reached.
to specify whether `object.number` in `NOVAS_EPHEM_OBJECT` type objects is a NAIF ID (default) or else a CALCEPH ID
number of the Solar-system body.
- NAIF CSPICE integration: `novas_use_cspice()`, `novas_use_cspice_planets()`, `novas_use_cspice_ephem()` to use the
NAIF CSPICE library for all Solar-system sources, major planets only, or for other bodies only.
`NOVAS_EPHEM_OBJECTS` should use NAIF IDs with CSPICE (or else -1 for name-based lookup).
- NAIF/NOVAS ID conversions for major planets (and Sun, Moon, SSB): `novas_to_naif_planet()`,
`novas_to_dexxx_planet()`, and `naif_to_novas_planet()`.
- Access to custom ephemeris provider functions: `get_planet_provider()` and `get_planet_provider_hp()`.
- Added `novas_planet_for_name()` function to return the NOVAS planet ID for a given (case insensitive) name.
<a name="api-changes"></a>
### Refinements to the NOVAS C API
Expand Down Expand Up @@ -913,8 +928,9 @@ NASA/JPL also provides [generic ephemerides](https://naif.jpl.nasa.gov/pub/naif/
planets, satellites thereof, the 300 largest asteroids, the Lagrange points, and some Earth orbiting stations.
- [Universal ephemeris data / service integration](#universal-ephemerides)
- [Built-in support for CALCEPH integration](#calceph-integration)
- [Built-in support for (old) JPL major planet ephemerides](#builtin-ephem-readers)
- [Optional support for CALCEPH integration](#calceph-integration)
- [Optional support for NAIF CSPICE toolkit integration](#cspice-integration)
- [Alternative support for (older) JPL major planet ephemerides](#builtin-ephem-readers)
- [Explicit linking of custom ephemeris functions](#explicit-ephem-linking)
Expand Down Expand Up @@ -964,18 +980,19 @@ provided you compiled SuperNOVAS with `BUILTIN_SOLSYS_EPHEM = 1` (in `config.mk`


<a name="calceph-integration"></a>
### Built-in support for CALCEPH integration
### Optional support for CALCEPH integration

The [CALCEPH](https://www.imcce.fr/recherche/equipes/asd/calceph/) library provides an easy-to-use access to JPL and
INPOP ephemeris files from C/C++. As of version 1.2, we provide built-in support for integrating the CALCEPH C library
INPOP ephemeris files from C/C++. As of version 1.2, we provide optional support for interfacing the CALCEPH C library
with SuperNOVAS for handling Solar-system objects.

Prior to building SuperNOVAS simply set `CALCEPH_SUPPORT` to 1 in `config.mk` or in your shell. Depending on the
Prior to building SuperNOVAS simply set `CALCEPH_SUPPORT` to 1 in `config.mk` or in your environment. Depending on the
build target, it will build `libsolsys-calceph.so[.1]` (target `shared`) or `libsolsys-calceph.a` (target `static`)
libraries, which provide the `novas_use_calceph()` and `novas_use_calceph_planets()` functions.

Of course, you will need access to the CALCEPH C development files (C headers and unversioned libraries) for the build
to succeed. Here is an example on how you'd use CALCEPH with SuperNOVAS in your application code:
Of course, you will need access to the CALCEPH C development files (C headers and unversioned `libcalceph.so` or `.a`
library) for the build to succeed. Here is an example on how you'd use CALCEPH with SuperNOVAS in your application
code:

```c
#include <calceph.h>
Expand Down Expand Up @@ -1003,16 +1020,63 @@ You can obtain readily available standard ephemeris files from
[NASA/JPL](https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/), such as
[DE440](https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/planets/de440.bsp), which covers the major planets, plus
Sun, Moon, and Solar-System Barycenter (SSB) for times between 1550 AD and 2650 AD. Or, you can use the
[JPL HORIZONS](https://ssd.jpl.nasa.gov/horizons/app.html#/) system to generate cutom ephemeris data for pretty much
[JPL HORIZONS](https://ssd.jpl.nasa.gov/horizons/app.html#/) system to generate custom ephemeris data for pretty much
all known solar systems bodies, down to the tiniest rocks. All of these should work with the `solsys-calceph` plugin.
And, when linking your application, don't forget to add `-lsolsys-calceph` to your link flags. That's all there is to
it.
<a name="cspice-integration"></a>
### Optional support for NAIF CSPICE toolkit integration
The [NAIF CSPICE Toolkit](https://naif.jpl.nasa.gov/naif/toolkit.html) is the canonical standard library for JPL
ephemeris files from C/C++. As of version 1.2, we provide optional support for interfacing CSPICE with SuperNOVAS for
handling Solar-system objects.
Prior to building SuperNOVAS simply set `CSPICE_SUPPORT` to 1 in `config.mk` or in your environment. Depending on the
build target, it will build `libsolsys-cspice.so[.1]` (target `shared`) or `libsolsys-cspice.a` (target `static`)
libraries, which provide the `novas_use_cspice()`, `novas_use_cspice_planets()`, and `novas_use_cspice_ephem()`
functions to enable CSPICE for providing data for all Solar-system sources, or for major planets only, or for other
bodies only, respectively.
Of course, you will need access to the CSPICE development files (C headers, installed under a `cspice/` directory
of an header search location, and the unversioned `libcspice.so` or `.a` library) for the build to succeed. You may
want to check out the [Smithsonian/cspice-sharedlib](https://github.com/Smithsonian/cspice-sharedlib) GitHub
repository to help you build CSPICE with shared libraries and dynamically linked tools.
Here is an example on how you might use CSPICE with SuperNOVAS in your application code:
```c
// You can load the desired kernels for CSPICE, using the CSPICE API.
// E.g. load DE440s and the Mars satellites from /data/ephem:
furnsh_c("/data/ephem/de440s.bsp");
furnsh_c("/data/ephem/mar097.bsp");
...
// check for CSPICE errors
if(return_c()) {
// oops, one of the kernels must not have loaded...
...
}
// Then use CSPICE as your SuperNOVAS ephemeris provider
novas_use_cspice();
```

You can obtain readily available standard ephemeris files from
[NASA/JPL](https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/), such as
[DE440](https://naif.jpl.nasa.gov/pub/naif/generic_kernels/spk/planets/de440.bsp), which covers the major planets, plus
Sun, Moon, and Solar-System Barycenter (SSB) for times between 1550 AD and 2650 AD. Or, you can use the
[JPL HORIZONS](https://ssd.jpl.nasa.gov/horizons/app.html#/) system to generate custom ephemeris data for pretty much
all known solar systems bodies, down to the tiniest rocks. All of these will work with the `solsys-cspice` plugin.

And, when linking your application, don't forget to add `-lsolsys-cspice` to your link flags. That's all there is to
it.


<a name="builtin-ephem-readers"></a>
### Built-in support for (old) JPL major planet ephemerides
### Alternative support for (older) JPL major planet ephemerides

If you only need support for major planets, you may be able to use one of the modules included in the SuperNOVAS
distribution. The modules `solsys1.c` and `solsys2.c` provide built-in support to older JPL ephemerides (DE200 to DE421),
Expand Down
8 changes: 8 additions & 0 deletions config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,14 @@ DEFAULT_SOLSYS ?= 3
CALCEPH_SUPPORT ?= 0


# Whether or not to build solsys-cspice libraries. You need the CSPICE
# development libraries (libcspice.so and/or libcspice.a) installed in
# LD_LIBRARY_PATH, and CSPICE header files in /usr/include/cspice or some
# other accessible location (you may also set an appropriate -I<path>
# option to CPPFLAGS prior to calling make).
CSPICE_SUPPORT ?= 0


# cppcheck options for 'check' target. You can add additional options by
# setting the CHECKEXTRA variable (e.g. in shell) prior to invoking 'make'.
CHECKOPTS ?= --enable=performance,warning,portability,style --language=c \
Expand Down
10 changes: 10 additions & 0 deletions include/solarsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,16 @@ int novas_calceph_use_ids(enum novas_id_type idtype);
#endif /* USE_CALCEPH */


// in solsys-cspice.c
#if USE_CSPICE

int novas_use_cspice();

int novas_use_cspice_ephem();

int novas_use_cspice_planets();

#endif /* USE_CALCEPH */


/// \cond PRIVATE
Expand Down
2 changes: 1 addition & 1 deletion src/solsys-calceph.c
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ static int novas_calceph(const char *name, long id, double jd_tdb_high, double j
id = i;
}

// Always return psoitions and velocities w.r.t. the SSB
// Always return positions and velocities w.r.t. the SSB
if(origin)
*origin = NOVAS_SSB;

Expand Down
Loading

0 comments on commit 9fabfcd

Please sign in to comment.