-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Stanislas Marquis
committed
Mar 14, 2014
0 parents
commit be5fda3
Showing
20 changed files
with
3,429 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Swephelp CMakeLists.txt | ||
|
||
cmake_minimum_required( VERSION 2.8 ) | ||
project( swephelp ) | ||
|
||
message( STATUS "-- Configuring swephelp..." ) | ||
|
||
set( SOURCES | ||
swhdatetime.c | ||
swhformat.c | ||
swhgeo.c | ||
swhmisc.c | ||
swhraman.c | ||
swhsearch.c | ||
swhutil.c | ||
) | ||
|
||
include_directories( BEFORE . ../libswe ) | ||
|
||
if ( MSVC ) | ||
add_definitions( -D_CRT_SECURE_NO_WARNINGS ) | ||
else() | ||
add_definitions( -g -O9 -Wall ) | ||
if ( NOT MINGW ) | ||
add_definitions( -fPIC ) | ||
endif() | ||
endif() | ||
|
||
add_library( swephelp STATIC ${SOURCES} ) | ||
|
||
# vi: set fenc=utf-8 ff=unix et sw=4 ts=3 sts=4 : |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Swephelp makefile | ||
|
||
CC = gcc | ||
CFLAGS = -g -O9 -Wall -std=gnu99 | ||
# path to swisseph | ||
INCS = -I. -I./libswe | ||
|
||
SWHOBJ = swhdatetime.o swhformat.o swhgeo.o swhmisc.o swhraman.o swhsearch.o swhutil.o | ||
|
||
.c.o: | ||
$(CC) -c $(CFLAGS) $(INCS) $< | ||
|
||
all: libswephelp.a | ||
|
||
libswephelp.a: $(SWHOBJ) | ||
ar rcs libswephelp.a $(SWHOBJ) | ||
|
||
clean: | ||
rm -f *.o libswephelp.a | ||
|
||
# vi: set fenc=utf-8 ff=unix sw=4 et=4 ts=4 sts=4 : |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
=============== | ||
Swephelp README | ||
=============== | ||
|
||
Swephelp is a helper library based on (and for) the Swiss Ephemeris library. | ||
It is not part of the Swiss Ephemeris library itself. | ||
|
||
It features a collection of functions frequently used in astrology applications. | ||
|
||
Functions for dates and time, geographical information, indian astrology, | ||
transits search, constant values for aspects, signs, planets... | ||
|
||
Stanislas Marquis <smarquis@astrorigin.ch> | ||
|
||
.. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
Swephelp | ||
Copyright 2007-2014 Stanislas Marquis <smarquis@astrorigin.ch> | ||
Swephelp is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License as | ||
published by the Free Software Foundation; either version 2 of | ||
the License, or (at your option) any later version. | ||
Swephelp is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with Swephelp. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** @file swephelp.h | ||
** @brief swephelp export header file | ||
** | ||
** Main swephelp header, imports all swephelp functions and defines. | ||
*/ | ||
|
||
#ifndef SWEPHELP_H | ||
#define SWEPHELP_H | ||
|
||
/* pollute namespace with fancy aliases */ | ||
#ifndef SWH_USE_ALIASES | ||
#define SWH_USE_ALIASES 1 | ||
#endif | ||
|
||
/* use a global mutex to protect swisseph data */ | ||
#ifndef SWH_USE_THREADS | ||
#define SWH_USE_THREADS 1 | ||
#endif | ||
|
||
/* include swisseph functions */ | ||
#include <swephexp.h> | ||
|
||
/* swephelp headers */ | ||
#include "swhdatetime.h" | ||
#include "swhdef.h" | ||
#include "swhformat.h" | ||
#include "swhgeo.h" | ||
#include "swhmisc.h" | ||
#include "swhraman.h" | ||
#include "swhsearch.h" | ||
#include "swhutil.h" | ||
|
||
#endif /* SWEPHELP_H */ | ||
/* vi: set fenc=utf-8 ff=unix et sw=4 ts=4 sts=4 : */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
/* | ||
Swephelp | ||
Copyright 2007-2014 Stanislas Marquis <smarquis@astrorigin.ch> | ||
Swephelp is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License as | ||
published by the Free Software Foundation; either version 2 of | ||
the License, or (at your option) any later version. | ||
Swephelp is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with Swephelp. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** @file swhdatetime.c | ||
** @brief swephelp date and time functions | ||
*/ | ||
|
||
#include <assert.h> | ||
#include <math.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <time.h> | ||
|
||
#include <swephexp.h> | ||
|
||
#include "swhdatetime.h" | ||
#include "swhwin.h" | ||
|
||
/** @brief Get current Julian day number, Gregorian calendar | ||
** @return Julian day number | ||
*/ | ||
double swh_jdnow(void) | ||
{ | ||
time_t t = time(NULL); | ||
#ifdef WIN32 /* has not gmtime_r ? */ | ||
struct tm *tmp = gmtime(&t); | ||
return swe_julday(tmp->tm_year+1900, tmp->tm_mon+1, tmp->tm_mday, | ||
(tmp->tm_hour+(tmp->tm_min/60.0)+(tmp->tm_sec/3600.0)), SE_GREG_CAL); | ||
#else | ||
struct tm tmp; | ||
gmtime_r(&t, &tmp); | ||
return swe_julday(tmp.tm_year+1900, tmp.tm_mon+1, tmp.tm_mday, | ||
(tmp.tm_hour+(tmp.tm_min/60.0)+(tmp.tm_sec/3600.0)), SE_GREG_CAL); | ||
#endif | ||
} | ||
|
||
/** @brief Reverse Julian day to date and time | ||
** | ||
** Similar to swe_revjul, but returns time with three integers instead | ||
** of one double. (Also tries to avoid some floating points rounding errors.) | ||
** | ||
** @see swh_julday() | ||
** | ||
** @param jd Julian day | ||
** @param flag Calendar type (SE_GREG_CAL|SE_JUL_CAL) | ||
** @param dt Results, declared as int[6] (year, month, day, hour, min, sec) | ||
** @return 0 | ||
*/ | ||
int swh_revjul(double jd, int flag, int *dt) | ||
{ | ||
double t; | ||
assert(flag == SE_GREG_CAL || flag == SE_JUL_CAL); | ||
swe_revjul(jd, flag, &dt[0], &dt[1], &dt[2], &t); | ||
dt[3] = (int) floor(t); | ||
t -= dt[3]; | ||
dt[4] = (int) floor(t * 60); | ||
t -= dt[4]/60.0; | ||
dt[5] = (int) lround(t * 3600); | ||
if (dt[5] == 60) /* rounding error */ | ||
{ | ||
dt[5] = 0; | ||
dt[4] += 1; | ||
if (dt[4] == 60) | ||
{ | ||
dt[4] = 0; | ||
dt[3] += 1; | ||
/* wont go further? */ | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
/** @brief Get integers from datetime representation | ||
** | ||
** As a habit we keep dates and times in a personal, yet | ||
** unambiguous format: "{yyyy}/{mm}/{dd} {hh}:{mm}:{ss}". | ||
** | ||
** @param coord datetime string | ||
** @param ret Returned integers declared as int[6] | ||
** @return 0 on success, or -1 if string is invalid | ||
*/ | ||
int swh_dt2i(const char *dt, int *ret) | ||
{ | ||
char *ptr, buf[22]; | ||
#ifndef WIN32 | ||
char *saveptr; | ||
#endif | ||
strcpy(buf, dt); | ||
#ifndef WIN32 | ||
ptr = strtok_r(buf, "/", &saveptr); | ||
#else | ||
ptr = strtok(buf, "/"); | ||
#endif | ||
if (ptr == NULL || strspn(ptr, "-0123456789") != strlen(ptr)) | ||
return -1; | ||
else | ||
ret[0] = atoi(ptr); /* year */ | ||
#ifndef WIN32 | ||
ptr = strtok_r(NULL, "/", &saveptr); | ||
#else | ||
ptr = strtok(NULL, "/"); | ||
#endif | ||
if (ptr == NULL || strspn(ptr, "0123456789") != strlen(ptr)) | ||
return -1; | ||
else | ||
ret[1] = atoi(ptr); /* month */ | ||
assert(ret[1] > 0 && ret[1] < 13); | ||
#ifndef WIN32 | ||
ptr = strtok_r(NULL, " ", &saveptr); | ||
#else | ||
ptr = strtok(NULL, " "); | ||
#endif | ||
if (ptr == NULL || strspn(ptr, "0123456789") != strlen(ptr)) | ||
return -1; | ||
else | ||
ret[2] = atoi(ptr); /* mday */ | ||
assert(ret[2] > 0 && ret[2] < 32); | ||
#ifndef WIN32 | ||
ptr = strtok_r(NULL, ":", &saveptr); | ||
#else | ||
ptr = strtok(NULL, ":"); | ||
#endif | ||
if (ptr == NULL || strspn(ptr, "0123456789") != strlen(ptr)) | ||
return -1; | ||
else | ||
ret[3] = atoi(ptr); /* hour */ | ||
assert(ret[3] > -1 && ret[3] < 24); | ||
#ifndef WIN32 | ||
ptr = strtok_r(NULL, ":", &saveptr); | ||
#else | ||
ptr = strtok(NULL, ":"); | ||
#endif | ||
if (ptr == NULL || strspn(ptr, "0123456789") != strlen(ptr)) | ||
return -1; | ||
else | ||
ret[4] = atoi(ptr); /* minutes */ | ||
assert(ret[4] > -1 && ret[4] < 60); | ||
#ifndef WIN32 | ||
ptr = strtok_r(NULL, ":", &saveptr); | ||
#else | ||
ptr = strtok(NULL, ":"); | ||
#endif | ||
if (ptr == NULL || strspn(ptr, "0123456789") != strlen(ptr)) | ||
return -1; | ||
else | ||
ret[5] = atoi(ptr); /* seconds */ | ||
assert(ret[5] > -1 && ret[5] < 60); | ||
return 0; | ||
} | ||
|
||
/* vi: set fenc=utf-8 ff=unix et sw=4 ts=4 sts=4 : */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
Swephelp | ||
Copyright 2007-2014 Stanislas Marquis <smarquis@astrorigin.ch> | ||
Swephelp is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License as | ||
published by the Free Software Foundation; either version 2 of | ||
the License, or (at your option) any later version. | ||
Swephelp is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with Swephelp. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
/** @file swhdatetime.h | ||
** @brief swephelp date and time functions | ||
*/ | ||
|
||
#ifndef SWHDATETIME_H | ||
#define SWHDATETIME_H | ||
|
||
#ifndef SWH_USE_ALIASES | ||
#define SWH_USE_ALIASES 1 | ||
#endif | ||
|
||
#ifdef __cplusplus | ||
extern "C" | ||
{ | ||
#endif | ||
|
||
#include <swephexp.h> | ||
|
||
/** @brief Get current Julian day number, Gregorian calendar | ||
** @return Julian day number | ||
*/ | ||
double swh_jdnow(void); | ||
|
||
/** @brief Get Julian day number from a date and time | ||
** | ||
** A conveniance function that, compared to swe_julday, does not require | ||
** hour in decimal format, but accepts integers only. | ||
** | ||
** @attention Does not check date validity. See swe_date_conversion. | ||
** | ||
** @see swh_revjul() | ||
** | ||
** @param year Year (4 digits) | ||
** @param mon Month [1;12] | ||
** @param day Day [1;31] | ||
** @param hour Hour [0;23] | ||
** @param min Minutes [0;59] | ||
** @param sec Seconds [0;59] | ||
** @param flag Calendar type (SE_GREG_CAL|SE_JUL_CAL) | ||
** @return Julian day number | ||
*/ | ||
#define swh_julday(year, mon, day, hour, min, sec, flag)\ | ||
swe_julday(year, mon, day, ((hour)+((min)/60.0)+((sec)/3600.0)), flag) | ||
|
||
/** @brief Reverse Julian day to date and time | ||
** | ||
** Similar to swe_revjul, but returns time with three integers instead | ||
** of one double. (Also tries to avoid some floating points rounding errors.) | ||
** | ||
** @see swh_julday() | ||
** | ||
** @param jd Julian day | ||
** @param flag Calendar type (SE_GREG_CAL|SE_JUL_CAL) | ||
** @param dt Results, declared as int[6] (year, month, day, hour, min, sec) | ||
** @return 0 | ||
*/ | ||
int swh_revjul(double jd, int flag, int *dt); | ||
|
||
/** @brief Get integers from datetime representation | ||
** | ||
** As a habit we keep dates and times in a personal, yet | ||
** unambiguous format: "{yyyy}/{mm}/{dd} {hh}:{mm}:{ss}". | ||
** | ||
** @param coord datetime string | ||
** @param ret Returned integers declared as int[6] | ||
** @return 0 on success, or -1 if string is invalid | ||
*/ | ||
int swh_dt2i(const char *dt, int *ret); | ||
|
||
#if SWH_USE_ALIASES | ||
|
||
/** @def DateTime_Split | ||
*/ | ||
#define DateTime_Split(dt, ret) swh_dt2i(dt, ret) | ||
|
||
#endif /* SWH_USE_ALIASES */ | ||
|
||
#ifdef __cplusplus | ||
} /* extern "C" */ | ||
#endif | ||
|
||
#endif /* SWHDATETIME_H */ | ||
/* vi: set fenc=utf-8 ff=unix et sw=4 ts=4 sts=4 : */ |
Oops, something went wrong.