swe-glib/README.md

153 lines
5.2 KiB
Markdown
Raw Normal View History

2013-09-06 10:12:43 +00:00
# SWE-GLib
2015-09-02 14:26:17 +00:00
SWE-GLib is a GLib style wrapper library around Astrodienst's
[Swiss Ephemeris library](http://www.astro.com/swisseph/).
2013-09-06 10:12:43 +00:00
2015-09-02 14:26:17 +00:00
The source tree contains Astrodienst's ephemeride files, as requested
by Alois Treindl of Astrodienst in a mail written to me on 24 July,
2013.
2013-09-06 10:12:43 +00:00
2013-09-06 10:39:36 +00:00
## GTK-Doc
2015-09-02 14:26:17 +00:00
The project utilizes [GTK-Doc](http://www.gtk.org/gtk-doc/), requiring
version 1.19 or later. Although the generated documentation is a bit
messy (not everything is documented, and there are some unresolved
variables, like [SERVER] on the generated index page.
2013-09-06 10:39:36 +00:00
2015-09-02 14:26:17 +00:00
Still, the documentation generates well, and at least gives a clue
about object usage.
2013-09-06 10:39:36 +00:00
2013-09-27 02:05:50 +00:00
## Bindings
2015-09-02 14:26:17 +00:00
SWE-GLib utilizes
[GObject Introspection](https://wiki.gnome.org/GObjectIntrospection),
which means it is available for many languages. Check out the
[examples](examples) directory for some sample code!
2013-09-27 02:05:50 +00:00
2013-09-06 10:12:43 +00:00
## Usage
2015-09-02 14:26:17 +00:00
Many functions return non-opaque C structs; their documentation can be
found inline, and in the generated GTK-Doc. Unless otherwise stated,
the returned values should never be freed.
2013-09-06 10:39:36 +00:00
### Creating the required objects
Then you need to create a `GsweTimestamp` object:
2013-09-06 10:12:43 +00:00
```c
GsweTimestamp *timestamp = gswe_timestamp_new_from_gregorian_full(1983, 3, 7, 11, 54, 45, 0, 1.0);
```
The `GsweTimetamp` object is used to convert dates between the Gregorian calendar dates and Julian Day values (not to be confused with Julian calendar dates).
2013-09-06 10:12:43 +00:00
2013-09-06 10:39:36 +00:00
Next, you have to create a `GsweMoment` object:
2013-09-06 10:12:43 +00:00
```c
GsweMoment *moment = gswe_moment_new_full(timestamp, 19.081599, 47.462485, 300.0, GSWE_HOUSE_PLACIDUS);
```
2013-09-06 10:39:36 +00:00
The `GsweMoment` object holds information of a given moment at a given place on earth. `gswe_moment_new_full()` requires a `GsweTimestamp` object, some geographical coordinates (in degrees) together with altitude above sea level (in meters), and a house system to use.
### Adding planets
After that you have to add some planets you want to do calculations on.
```c
gswe_moment_add_planet(moment, GSWE_PLANET_SUN);
```
Alternatively, you can add every planets known by SWE-GLib with
```c
gswe_moment_add_all_planets(moment);
```
### Getting planet positions and such
Then, you can get the planet data with
```c
GswePlanetData *sun_data = gswe_moment_get_planet(moment, GSWE_PLANET_SUN);
```
### Getting aspects and antiscia
2013-09-06 10:39:36 +00:00
SWE-GLib is also able to calculate aspects and antiscia. This functionality does not exist in the Swiss Ephemeris library, though. For this, of course, you have to add multiple planets (at least two) to your `GsweMoment`. After that, you can call `gswe_moment_get_planet_aspects()` and `gswe_moment_get_planet_antiscia()`.
2013-09-06 10:39:36 +00:00
```c
GList *sun_aspects = gswe_moment_get_planet_aspects(moment, GSWE_PLANET_SUN);
GList *sun_antiscia = gswe_moment_get_planet_antiscia(moment, GSWE_PLANET_SUN);
2013-09-06 10:39:36 +00:00
```
2015-09-02 14:26:17 +00:00
The returned GList objects hold zero or more `GsweAspectData` or
`GsweAntiscionData` objects, respectively.
2013-09-06 10:39:36 +00:00
### Getting the Moon phase
2015-09-02 14:26:17 +00:00
Last, but not least, SWE-GLib can calculate Moon's phase at the given
moment. For that, you have to call `gswe_moment_get_moon_phase()`:
2013-09-06 10:39:36 +00:00
```c
GsweMoonPhaseData *moon_phase = gswe_moment_get_moon_phase(moment);
```
2013-09-06 10:12:43 +00:00
### About altitude
2015-09-02 14:26:17 +00:00
The Swiss Ephemeris library requires the altitude value to be
specified for several calculations. It also notifies how important it
is:
2013-09-06 10:12:43 +00:00
2015-09-02 14:26:17 +00:00
> the altitude above sea must be in meters. Neglecting the altitude
> can result in an error of about 2 arc seconds with the moon and at
> an altitude 3000m.
2013-09-06 10:12:43 +00:00
2015-09-02 14:26:17 +00:00
2 arc seconds is about 0.000555 degrees of error, which is, well, kind
of small. Of course, if you need very precise horoscopes or need
planetary positions for a totally different thing, you should really
provide a (close to) exact value; otherwise, it is safe to pass any
value (well, which seems logical: the average level of all dry lands
is about 840 meters; the average level of the whole planet Earth
(including oceans and seas) is around 280 meters. Providing a value of
~400 should be OK most of the time).
2013-09-06 10:12:43 +00:00
## API stability
2015-09-02 14:26:17 +00:00
The project is currently transitioning to 2.0. master is a bit fragile
at the moment, 1.x versions are considered to be stable (although see
commit 8f52aba about a huge typo-bug).
2013-09-06 10:39:36 +00:00
## Limitations
### Topocentric calculations only
2015-09-02 14:26:17 +00:00
Although the original Swiss Ephemeris library supports it, SWE-GLib
can't do Heliocentric, nor Geocentric (as seen from the center of
Earth) calculations, only Topocentric (as seen from a given point on
Earths surface) calculations yet.
### Database size
2015-09-02 14:26:17 +00:00
The size of all data files provided by Astrodienst is around
40MB. Although it should not be a problem with today's home hardware,
it can be a hard requirement on embedded systems. For basic
calculations, keeping the following files under $(datadir)/swe-glib is
usually enough:
2015-09-02 14:26:17 +00:00
* `seas_18.se1`
* `semo_18.se1`
* `sepl_18.se1`
### Fixed stars are not known yet
2015-09-02 14:26:17 +00:00
Although Swiss Ephemeris has the functionality to calculate the
position of fixed stars, SWE-GLib doesn't provide such
functionality. This, however, is a planned feature for the close
future.
2013-09-22 16:22:13 +00:00
## Licencing
2015-09-02 14:26:17 +00:00
As the underlying Swiss Ephemeris is published under GPL (or a
commercial license I can not afford), SWE-GLib is also uses that. This
means that you can currently use SWE-GLib in software published under
the GNU GPL v3 (or, at your option, any later version).