Outsourced house cusp position calculations to SWE-GLib.
This commit is contained in:
parent
7dc0a25d9d
commit
6aada9a3c6
@ -3,6 +3,7 @@
|
||||
#include "calculate.h"
|
||||
|
||||
#include "../swe/src/swephexp.h"
|
||||
#include "../swe-glib/src/swe-glib.h"
|
||||
|
||||
#define EPHEDIR "/home/polesz/Projektek/c/astrognome/swe/data"
|
||||
|
||||
@ -309,6 +310,17 @@ free_planet_data(gpointer data)
|
||||
g_free(planetData);
|
||||
}
|
||||
|
||||
void
|
||||
print_house_cusp(gpointer data, gpointer user_data)
|
||||
{
|
||||
gdouble *cusp = data;
|
||||
gint *house = user_data;
|
||||
|
||||
printf("House %2d..: %s (%f)\n", *house, signName[get_sign(*cusp)], *cusp);
|
||||
|
||||
*house += 1;
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
@ -338,6 +350,8 @@ main(int argc, char *argv[])
|
||||
signData_t *signData;
|
||||
GList *planetIdList;
|
||||
struct aspect_check_data aspectCheckData;
|
||||
GsweTimestamp *timestamp;
|
||||
GsweMoment *moment;
|
||||
|
||||
#if 1
|
||||
year = 1983;
|
||||
@ -395,6 +409,10 @@ main(int argc, char *argv[])
|
||||
ADD_SIGN(signDataTable, signData, SIGN_PISCES, ELEMENT_WATER, TYPE_MUTABLE);
|
||||
|
||||
swe_set_ephe_path(EPHEDIR);
|
||||
gswe_init(EPHEDIR);
|
||||
|
||||
timestamp = gswe_timestamp_new_from_gregorian_full(year, month, day, hour, min, sec, 0, 1.0);
|
||||
moment = gswe_moment_new_full(timestamp, lon, lat, alt, GSWE_HOUSE_SYSTEM_PLACIDUS);
|
||||
|
||||
if (set_location_and_time(lon, lat, alt, year, month, day, hour, min, sec, timezone, &te) == 0) {
|
||||
return 1;
|
||||
@ -406,9 +424,8 @@ main(int argc, char *argv[])
|
||||
|
||||
swe_houses(te, lat, lon, 'P', cusps, ascmc);
|
||||
|
||||
for (p = 1; p < 13; p++) {
|
||||
printf("House %2d..: %s (%f)\n", p, signName[get_sign(cusps[p])], cusps[p]);
|
||||
}
|
||||
p = 1;
|
||||
g_list_foreach(gswe_moment_get_house_cusps(moment), print_house_cusp, &p);
|
||||
|
||||
printf("\nPLANETS AND POINTS\n==================\n\n");
|
||||
|
||||
|
@ -1,11 +1,28 @@
|
||||
#include <math.h>
|
||||
#include "swe-glib.h"
|
||||
#include "gswe-types.h"
|
||||
#include "gswe-moment.h"
|
||||
|
||||
#include "../../swe/src/swephexp.h"
|
||||
|
||||
#define GSWE_MOMENT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), GSWE_TYPE_MOMENT, GsweMomentPrivate))
|
||||
|
||||
/**
|
||||
* GsweMomentPrivate:
|
||||
* @timestamp: a #GsweTimestmp object representing the current local time at
|
||||
* the given position specified by @coordinates. Be warned though,
|
||||
* that the time zone is NOT checked against the coordinates!
|
||||
* @coordinates: the coordinates of the observers position
|
||||
* @revision: an internal counter which is incremented whenever the timestamp
|
||||
* or the coordinates change. Planetary positions are recalculated
|
||||
* if this number changes
|
||||
*/
|
||||
struct _GsweMomentPrivate {
|
||||
GsweTimestamp *timestamp;
|
||||
GsweCoordinates coordinates;
|
||||
GsweHouseSystem house_system;
|
||||
guint revision;
|
||||
GList *house_list;
|
||||
guint house_revision;
|
||||
};
|
||||
|
||||
enum {
|
||||
@ -67,6 +84,9 @@ gswe_moment_init(GsweMoment *moment)
|
||||
moment->priv = GSWE_MOMENT_GET_PRIVATE(moment);
|
||||
|
||||
moment->priv->timestamp = NULL;
|
||||
moment->priv->house_list = NULL;
|
||||
moment->priv->planet_list = NULL;
|
||||
moment->priv->revision = 1;
|
||||
|
||||
//moment->priv->a_string = g_strdup("Maman");
|
||||
}
|
||||
@ -74,6 +94,8 @@ gswe_moment_init(GsweMoment *moment)
|
||||
static void
|
||||
gswe_moment_timestamp_changed(GsweMoment *moment, gpointer data)
|
||||
{
|
||||
moment->priv->revision++;
|
||||
gswe_moment_emit_changed(moment);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -91,9 +113,9 @@ gswe_moment_dispose(GObject *gobject)
|
||||
static void
|
||||
gswe_moment_finalize(GObject *gobject)
|
||||
{
|
||||
//GsweMoment *moment = GSWE_MOMENT(gobject);
|
||||
GsweMoment *moment = GSWE_MOMENT(gobject);
|
||||
|
||||
//g_free(moment->priv->a_string);
|
||||
g_list_free_full(moment->priv->house_list, g_free);
|
||||
|
||||
G_OBJECT_CLASS(gswe_moment_parent_class)->finalize(gobject);
|
||||
}
|
||||
@ -175,3 +197,56 @@ gswe_moment_new(void)
|
||||
return (GsweMoment *)g_object_new(GSWE_TYPE_MOMENT, NULL);
|
||||
}
|
||||
|
||||
GsweMoment *
|
||||
gswe_moment_new_full(GsweTimestamp *timestamp, gdouble longitude, gdouble latitude, gdouble altitude, GsweHouseSystem house_system)
|
||||
{
|
||||
GsweMoment *moment = gswe_moment_new();
|
||||
|
||||
moment->priv->timestamp = timestamp;
|
||||
g_object_ref(timestamp);
|
||||
g_signal_connect(G_OBJECT(timestamp), "changed", G_CALLBACK(gswe_moment_timestamp_changed), NULL);
|
||||
moment->priv->coordinates.longitude = longitude;
|
||||
moment->priv->coordinates.latitude = latitude;
|
||||
moment->priv->coordinates.altitude = altitude;
|
||||
moment->priv->house_system = house_system;
|
||||
|
||||
return moment;
|
||||
}
|
||||
|
||||
static void
|
||||
gswe_moment_calculate_house_positions(GsweMoment *moment)
|
||||
{
|
||||
gdouble cusps[13],
|
||||
ascmc[10];
|
||||
gint i;
|
||||
GsweHouseSystemInfo *house_system_data;
|
||||
|
||||
if ((house_system_data = g_hash_table_lookup(gswe_house_system_info_table, GINT_TO_POINTER(moment->priv->house_system))) == NULL) {
|
||||
g_error("Unknown house system!");
|
||||
}
|
||||
|
||||
swe_houses(gswe_timestamp_get_julian_day(moment->priv->timestamp), moment->priv->coordinates.latitude, moment->priv->coordinates.longitude, house_system_data->sweph_id, cusps, ascmc);
|
||||
|
||||
g_list_free_full(moment->priv->house_list, g_free);
|
||||
moment->priv->house_list = NULL;
|
||||
|
||||
for (i = 12; i >= 1; i--) {
|
||||
gdouble *cusp = g_new0(gdouble, 1);
|
||||
|
||||
*cusp = cusps[i];
|
||||
moment->priv->house_list = g_list_prepend(moment->priv->house_list, cusp);
|
||||
}
|
||||
|
||||
moment->priv->house_revision = moment->priv->revision;
|
||||
}
|
||||
|
||||
GList *
|
||||
gswe_moment_get_house_cusps(GsweMoment *moment)
|
||||
{
|
||||
if (moment->priv->house_revision != moment->priv->revision) {
|
||||
gswe_moment_calculate_house_positions(moment);
|
||||
}
|
||||
|
||||
return moment->priv->house_list;
|
||||
}
|
||||
|
||||
|
@ -31,12 +31,14 @@ GQuark gswe_moment_error_quark(void);
|
||||
* GsweCoordinates:
|
||||
* @longitude: longitude part of the coordinates
|
||||
* @latitude: latitude part of the coordinates
|
||||
* @altitude: altitude relative to sea level
|
||||
*
|
||||
* GsweCoordinates specifies an exact point on Earth's surface
|
||||
*/
|
||||
typedef struct _GsweCoordinates {
|
||||
gdouble longitude;
|
||||
gdouble latitude;
|
||||
gdouble altitude;
|
||||
} GsweCoordinates;
|
||||
|
||||
struct _GsweMoment {
|
||||
@ -64,7 +66,9 @@ GType gswe_moment_get_type(void);
|
||||
|
||||
/* Method definitions */
|
||||
GsweMoment *gswe_moment_new(void);
|
||||
GsweMoment *gswe_moment_new_full(GsweTimestamp *timestamp, gdouble longitude, gdouble latitude, gdouble altitude, GsweHouseSystem house_system);
|
||||
void gswe_moment_set_timestamp(GsweMoment *moment, GsweTimestamp *timestamp);
|
||||
GList *gswe_moment_get_house_cusps(GsweMoment *moment);
|
||||
|
||||
#endif /* __GSWE_MOMENT_H__ */
|
||||
|
||||
|
@ -1,6 +1,8 @@
|
||||
#ifndef __SWE_GLIB_GSWE_PLANETS_H__
|
||||
#define __SWE_GLIB_GSWE_PLANETS_H__
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
typedef enum {
|
||||
GSWE_PLANET_NONE,
|
||||
GSWE_PLANET_SUN,
|
||||
|
@ -4,8 +4,10 @@
|
||||
#include <glib.h>
|
||||
#include "gswe-types.h"
|
||||
#include "gswe-timestamp.h"
|
||||
#include "gswe-moment.h"
|
||||
|
||||
extern GHashTable *gswe_planet_info_table;
|
||||
extern GHashTable *gswe_house_system_info_table;
|
||||
|
||||
void gswe_init(gchar *sweph_path);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user