sweph4ruby 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2005 Pedro Moreira Santos
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,8 @@
1
+ Author:: Pedro Moreira Santos (mailto:pedro.santos@bizarrologia.com)
2
+ Copyright:: Copyright (c) 2005 Pedro Moreira Santos
3
+ License:: MIT
4
+
5
+
6
+ sweph4ruby provides a ruby interface for the SWISS EPHEMERIS [http://www.astro.com/swisseph/] a library for the computation of planetary positions implemented in C.
7
+
8
+ Swiss Ephemeris is a compression of the JPL-Ephemeris DE406 that can be found here [http://www.jpl.nasa.gov], more information about SWISS EPHEMERIS can be found in the user manual [http://www.astro.com/swisseph/swisseph.htm?lang=f].
Binary file
@@ -0,0 +1,12 @@
1
+ require 'mkmf'
2
+ require 'rbconfig'
3
+ include Config
4
+
5
+ if (CONFIG["host_os"] == "mswin32" )
6
+ $LOCAL_LIBS += "swelib32.lib"
7
+ else
8
+ $LOCAL_LIBS += "libswe.a"
9
+ end
10
+
11
+ dir_config("sweph4ruby")
12
+ create_makefile("sweph4ruby")
Binary file
Binary file
@@ -0,0 +1,318 @@
1
+ /************************************************************
2
+ $Header: sweodef.h,v 1.65 2003/06/14 13:02:34 alois Exp $
3
+ definitions and constants for all Swiss Ephemeris source files,
4
+ only required for compiling the libraries, not for the external
5
+ interface of the libraries.
6
+
7
+ The definitions are a subset of Astrodienst's ourdef.h content
8
+ and must be kept compatible. Everything not used in SwissEph
9
+ has been deleted.
10
+
11
+ Does auto-dectection of MSDOS (TURBO_C or MS_C) or HPUNIX.
12
+ Must be extended for more portability; there should be a way
13
+ to detect byte order and file system type.
14
+
15
+ ************************************************************/
16
+
17
+ /* Copyright (C) 1997, 1998 Astrodienst AG, Switzerland. All rights reserved.
18
+
19
+ This file is part of Swiss Ephemeris Free Edition.
20
+
21
+ Swiss Ephemeris is distributed with NO WARRANTY OF ANY KIND. No author
22
+ or distributor accepts any responsibility for the consequences of using it,
23
+ or for whether it serves any particular purpose or works at all, unless he
24
+ or she says so in writing. Refer to the Swiss Ephemeris Public License
25
+ ("SEPL" or the "License") for full details.
26
+
27
+ Every copy of Swiss Ephemeris must include a copy of the License,
28
+ normally in a plain ASCII text file named LICENSE. The License grants you
29
+ the right to copy, modify and redistribute Swiss Ephemeris, but only
30
+ under certain conditions described in the License. Among other things, the
31
+ License requires that the copyright notices and this notice be preserved on
32
+ all copies.
33
+
34
+ For uses of the Swiss Ephemeris which do not fall under the definitions
35
+ laid down in the Public License, the Swiss Ephemeris Professional Edition
36
+ must be purchased by the developer before he/she distributes any of his
37
+ software or makes available any product or service built upon the use of
38
+ the Swiss Ephemeris.
39
+
40
+ Authors of the Swiss Ephemeris: Dieter Koch and Alois Treindl
41
+
42
+ The authors of Swiss Ephemeris have no control or influence over any of
43
+ the derived works, i.e. over software or services created by other
44
+ programmers which use Swiss Ephemeris functions.
45
+
46
+ The names of the authors or of the copyright holder (Astrodienst) must not
47
+ be used for promoting any software, product or service which uses or contains
48
+ the Swiss Ephemeris. This copyright notice is the ONLY place where the
49
+ names of the authors can legally appear, except in cases where they have
50
+ given special permission in writing.
51
+
52
+ The trademarks 'Swiss Ephemeris' and 'Swiss Ephemeris inside' may be used
53
+ for promoting such software, products or services.
54
+ */
55
+ #ifndef _OURDEF_INCLUDED /* ourdef.h is a superset of sweodef.h */
56
+ #ifndef _SWEODEF_INCLUDED /* allow multiple #includes */
57
+ #define _SWEODEF_INCLUDED
58
+
59
+ # define MY_TRUE 1 /* for use in other defines, before TRUE is defined */
60
+ # define MY_FALSE 0 /* for use in other defines, before TRUE is defined */
61
+
62
+
63
+ #ifdef _WIN32 /* Microsoft VC 5.0 does not define MSDOS anymore */
64
+ # undef MSDOS
65
+ # define MSDOS MY_TRUE
66
+ #include <wtypes.h>
67
+ #include <objbase.h>
68
+ #include <wincon.h>
69
+ #include <winbase.h>
70
+ #include <io.h>
71
+ #include <windows.h>
72
+ # define sleep(x) Sleep((x) * 1000)
73
+ #endif
74
+
75
+ #ifdef _MSC_VER
76
+ # define MS_VC
77
+ #endif
78
+
79
+ #ifdef WIN32 /* Microsoft VC 5.0 does not define MSDOS anymore */
80
+ # define MSDOS MY_TRUE
81
+ #endif
82
+
83
+ #ifdef MSDOS /* already defined by some DOS compilers */
84
+ # undef MSDOS
85
+ # define MSDOS MY_TRUE
86
+ #endif
87
+
88
+ #ifdef __TURBOC__ /* defined by turboc */
89
+ # ifndef MSDOS
90
+ # define MSDOS MY_TRUE
91
+ # endif
92
+ # define TURBO_C
93
+ #endif
94
+
95
+ #ifdef __SC__ /* defined by Symantec C */
96
+ # ifndef MSDOS
97
+ # define MSDOS MY_TRUE
98
+ # endif
99
+ # define SYMANTEC_C
100
+ #endif
101
+
102
+ #ifdef __WATCOMC__ /* defined by WatcomC */
103
+ # ifndef MSDOS
104
+ # define MSDOS MY_TRUE
105
+ # endif
106
+ # define WATCOMC
107
+ #endif
108
+
109
+ #ifdef __MWERKS__ /* defined on Macintosh CodeWarrior */
110
+ # if macintosh && powerc
111
+ # define MACOS MY_TRUE /* let it undefined otherwise */
112
+ # define MSDOS MY_FALSE /* in case one above fired falsely */
113
+ # endif
114
+ #endif
115
+
116
+ #if MSDOS
117
+ # define HPUNIX MY_FALSE
118
+ # define INTEL_BYTE_ORDER 1
119
+ # ifndef TURBO_C
120
+ # define MS_C /* assume Microsoft C compiler */
121
+ # endif
122
+ # define MYFAR far
123
+ # define UNIX_FS MY_FALSE
124
+ #else
125
+ # ifdef MACOS
126
+ # define HPUNIX MY_FALSE
127
+ # define MYFAR
128
+ # define UNIX_FS MY_FALSE
129
+ # else
130
+ # define MSDOS MY_FALSE
131
+ # define HPUNIX MY_TRUE
132
+ # ifndef _HPUX_SOURCE
133
+ # define _HPUX_SOURCE
134
+ # endif
135
+ # define MYFAR
136
+ # define UNIX_FS MY_TRUE
137
+ # endif
138
+ #endif
139
+
140
+ #include <math.h>
141
+ #include <stdlib.h>
142
+ #ifndef FILE
143
+ # include <stdio.h>
144
+ #endif
145
+
146
+ #if HPUNIX
147
+ # include <unistd.h>
148
+ #endif
149
+
150
+ /*
151
+ * if we have 16-bit ints, we define INT_16; we will need %ld to printf an int32
152
+ * if we have 64-bit long, we define LONG_64
153
+ * If none is defined, we have int = long = 32 bit, and use %d to printf an int32
154
+ */
155
+ #include <limits.h>
156
+ #if INT_MAX < 40000
157
+ # define INT_16
158
+ #else
159
+ # if LONG_MAX > INT_MAX
160
+ # define LONG_64
161
+ # endif
162
+ #endif
163
+
164
+ #ifdef BYTE_ORDER
165
+ #ifdef LITTLE_ENDIAN
166
+ # if BYTE_ORDER == LITTLE_ENDIAN
167
+ # define INTEL_BYTE_ORDER
168
+ # endif
169
+ #endif
170
+ #endif
171
+
172
+ #ifdef INT_16
173
+ typedef long int32;
174
+ typedef unsigned long uint32;
175
+ typedef int int16;
176
+ typedef double REAL8; /* real with at least 64 bit precision */
177
+ typedef long INT4; /* signed integer with at least 32 bit precision */
178
+ typedef unsigned long UINT4;
179
+ /* unsigned integer with at least 32 bit precision */
180
+ typedef int AS_BOOL;
181
+ typedef unsigned int UINT2; /* unsigned 16 bits */
182
+ # define ABS4 labs /* abs function for long */
183
+ #else
184
+ typedef int int32;
185
+ typedef unsigned int uint32;
186
+ typedef short int16;
187
+ typedef double REAL8; /* real with at least 64 bit precision */
188
+ typedef int INT4; /* signed integer with at least 32 bit precision */
189
+ typedef unsigned int UINT4;
190
+ /* unsigned integer with at least 32 bit precision */
191
+ typedef int AS_BOOL;
192
+ typedef unsigned short UINT2; /* unsigned 16 bits */
193
+ # define ABS4 abs /* abs function for long */
194
+ #endif
195
+
196
+ #if MSDOS
197
+ # ifdef TURBO_C
198
+ # include <alloc.h> /* MSC needs malloc ! */
199
+ # else
200
+ # include <malloc.h>
201
+ # endif
202
+ # define SIGALRM SIGINT
203
+ #endif
204
+
205
+ #ifndef TRUE
206
+ # define TRUE 1
207
+ # define FALSE 0
208
+ #endif
209
+
210
+ #ifndef OK
211
+ # define OK (0)
212
+ # define ERR (-1)
213
+ #endif
214
+
215
+ /* hack because UCHAR is already used by mingw gcc */
216
+ #ifdef __GNUC__
217
+ #ifdef _WIN32
218
+ #define UCHAR SWE_UCHAR
219
+ #endif
220
+ #endif
221
+
222
+ typedef unsigned char UCHAR;
223
+ #define UCP (UCHAR*)
224
+ #define SCP (char*)
225
+
226
+ # define CHARSET_ISO_LATIN_1 TRUE /* used by ctype256 */
227
+
228
+ #ifdef DOS_DEGREE /* use compiler switch to get DOS character! */
229
+ # define ODEGREE_CHAR 248 /* DOS degree character */
230
+ #else
231
+ # ifdef MACOS
232
+ # define ODEGREE_CHAR 161 /* Macintosh degree character */
233
+ # else
234
+ # define ODEGREE_CHAR 176 /* Latin1 degree character */
235
+ # endif
236
+ #endif
237
+
238
+
239
+
240
+ #ifndef HUGE
241
+ # define HUGE 1.7E+308 /* biggest value for REAL8 */
242
+ #endif
243
+ #ifndef M_PI
244
+ # define M_PI 3.14159265358979323846
245
+ #endif
246
+
247
+ #define forward static
248
+
249
+ #define AS_MAXCH 256 /* used for string declarations, allowing 255 char+\0 */
250
+
251
+ #define DEGTORAD 0.0174532925199433
252
+ #define RADTODEG 57.2957795130823
253
+
254
+ typedef int32 centisec; /* centiseconds used for angles and times */
255
+ #define CS (centisec) /* use for casting */
256
+ #define CSEC centisec /* use for typing */
257
+
258
+ #define DEG 360000 /* degree expressed in centiseconds */
259
+ #define DEG7_30 (2700000) /* 7.5 degrees */
260
+ #define DEG15 (15 * DEG)
261
+ #define DEG24 (24 * DEG)
262
+ #define DEG30 (30 * DEG)
263
+ #define DEG60 (60 * DEG)
264
+ #define DEG90 (90 * DEG)
265
+ #define DEG120 (120 * DEG)
266
+ #define DEG150 (150 * DEG)
267
+ #define DEG180 (180 * DEG)
268
+ #define DEG270 (270 * DEG)
269
+ #define DEG360 (360 * DEG)
270
+
271
+ #define CSTORAD 4.84813681109536E-08 /* centisec to rad: pi / 180 /3600/100 */
272
+ #define RADTOCS 2.06264806247096E+07 /* rad to centisec 180*3600*100/pi */
273
+
274
+ #define CS2DEG (1.0/360000.0) /* centisec to degree */
275
+
276
+ /* control strings for fopen() */
277
+ #if UNIX_FS
278
+ # define BFILE_R_ACCESS "r" /* open binary file for reading */
279
+ # define BFILE_RW_ACCESS "r+" /* open binary file for writing and reading */
280
+ # define BFILE_W_CREATE "w" /* create/open binary file for write*/
281
+ # define BFILE_A_ACCESS "a+" /* create/open binary file for append*/
282
+ # define FILE_R_ACCESS "r" /* open text file for reading */
283
+ # define FILE_RW_ACCESS "r+" /* open text file for writing and reading */
284
+ # define FILE_W_CREATE "w" /* create/open text file for write*/
285
+ # define FILE_A_ACCESS "a+" /* create/open text file for append*/
286
+ # define O_BINARY 0 /* for open(), not defined in Unix */
287
+ # define OPEN_MODE 0666 /* default file creation mode */
288
+ # define DIR_GLUE "/" /* glue string for directory/file */
289
+ # define PATH_SEPARATOR ";:" /* semicolon or colon may be used */
290
+ #else
291
+ # define BFILE_R_ACCESS "rb" /* open binary file for reading */
292
+ # define BFILE_RW_ACCESS "r+b" /* open binary file for writing and reading */
293
+ # define BFILE_W_CREATE "wb" /* create/open binary file for write*/
294
+ # define BFILE_A_ACCESS "a+b" /* create/open binary file for append*/
295
+ # define PATH_SEPARATOR ";" /* semicolon as PATH separator */
296
+ # define OPEN_MODE 0666 /* default file creation mode */
297
+ # ifdef MACOS
298
+ # define FILE_R_ACCESS "r" /* open text file for reading */
299
+ # define FILE_RW_ACCESS "r+" /* open text file for writing and reading */
300
+ # define FILE_W_CREATE "w" /* create/open text file for write*/
301
+ # define FILE_A_ACCESS "a+" /* create/open text file for append*/
302
+ # define DIR_GLUE ":" /* glue string for directory/file */
303
+ # else
304
+ # define FILE_R_ACCESS "rt" /* open text file for reading */
305
+ # define FILE_RW_ACCESS "r+t" /* open text file for writing and reading */
306
+ # define FILE_W_CREATE "wt" /* create/open text file for write*/
307
+ # define FILE_A_ACCESS "a+t" /* create/open text file for append*/
308
+ /* attention, all backslashes for msdos directry names must be written as \\,
309
+ because it is the C escape character */
310
+ # define DIR_GLUE "\\" /* glue string for directory/file */
311
+ # endif
312
+ #endif
313
+
314
+ #include <string.h>
315
+ #include <ctype.h>
316
+
317
+ #endif /* _SWEODEF_INCLUDED */
318
+ #endif /* _OURDEF_INCLUDED */
@@ -0,0 +1,101 @@
1
+ #include "ruby.h"
2
+ #include "swephexp.h"
3
+
4
+ static VALUE t_init(VALUE self)
5
+ {
6
+ return self;
7
+ }
8
+
9
+ static VALUE t_swe_set_ephe_path(VALUE self, VALUE path)
10
+ {
11
+ swe_set_ephe_path(StringValuePtr(path));
12
+ return self;
13
+ }
14
+
15
+ static VALUE t_swe_julday(VALUE self, VALUE year, VALUE month, VALUE day, VALUE hour)
16
+ {
17
+ VALUE julday = swe_julday( NUM2INT(year), NUM2INT(month), NUM2INT(day), NUM2DBL(hour), SE_GREG_CAL );
18
+ return rb_float_new(julday);
19
+ }
20
+
21
+ static VALUE t_swe_calc(VALUE self, VALUE julian_day, VALUE body)
22
+ {
23
+ double results[6];
24
+ char serr[AS_MAXCH];
25
+ VALUE arr = rb_ary_new();
26
+ int id_push = rb_intern("push");
27
+ int i =0;
28
+
29
+ if ( swe_calc(NUM2DBL(julian_day), NUM2INT(body), SEFLG_SPEED, results, serr) < 0 )
30
+ rb_raise (rb_eRuntimeError, serr);
31
+
32
+ for ( i = 0; i < 6; i++)
33
+ rb_funcall(arr, id_push, 1, rb_float_new(results[i]));
34
+
35
+ return arr;
36
+ }
37
+
38
+ static VALUE t_swe_houses(VALUE self, VALUE julian_day, VALUE latitude, VALUE longitude, VALUE house_system)
39
+ {
40
+ double cusps[13];
41
+ double ascmc[10];
42
+ char serr[AS_MAXCH];
43
+ VALUE arr = rb_ary_new();
44
+ int id_push = rb_intern("push");
45
+ int i =0;
46
+
47
+ if ( swe_houses(NUM2DBL(julian_day), NUM2DBL(latitude), NUM2DBL(longitude), NUM2CHR(house_system), cusps, ascmc) < 0 )
48
+ rb_raise (rb_eRuntimeError, serr);
49
+
50
+ for ( i = 0; i < 13; i++)
51
+ rb_funcall(arr, id_push, 1, rb_float_new(cusps[i]));
52
+
53
+ for ( i = 0; i < 10; i++)
54
+ rb_funcall(arr, id_push, 1, rb_float_new(ascmc[i]));
55
+
56
+ return arr;
57
+ }
58
+
59
+ static VALUE t_swe_get_planet_name(VALUE self, VALUE body_number)
60
+ {
61
+ char snam[40];
62
+
63
+ swe_get_planet_name(NUM2INT(body_number), snam);
64
+ return rb_str_new2(snam);
65
+ }
66
+
67
+ static VALUE t_swe_house_pos(VALUE self, VALUE armc, VALUE geolat, VALUE eps, VALUE house_system, VALUE lon, VALUE lat)
68
+ {
69
+ double xpin[2];
70
+ char serr[AS_MAXCH];
71
+ VALUE house;
72
+
73
+ xpin[0] = NUM2DBL(lon);
74
+ xpin[1] = NUM2DBL(lat);
75
+
76
+ house = swe_house_pos(NUM2DBL(armc), NUM2DBL(geolat), NUM2DBL(eps), NUM2CHR(house_system), xpin, serr);
77
+ return rb_float_new(house);
78
+ }
79
+
80
+ static VALUE t_swe_deltat(VALUE self, VALUE tjd)
81
+ {
82
+ VALUE ret;
83
+
84
+ ret = swe_deltat(NUM2DBL(tjd));
85
+ return rb_float_new(ret);
86
+ }
87
+
88
+ VALUE cSweph;
89
+
90
+ void Init_sweph4ruby()
91
+ {
92
+ cSweph = rb_define_class("Sweph", rb_cObject);
93
+ rb_define_method(cSweph, "initialize", t_init, 0);
94
+ rb_define_method(cSweph, "swe_set_ephe_path", t_swe_set_ephe_path, 1);
95
+ rb_define_method(cSweph, "swe_julday", t_swe_julday, 4);
96
+ rb_define_method(cSweph, "swe_calc", t_swe_calc, 2);
97
+ rb_define_method(cSweph, "swe_houses", t_swe_houses, 4);
98
+ rb_define_method(cSweph, "swe_get_planet_name", t_swe_get_planet_name, 1);
99
+ rb_define_method(cSweph, "swe_house_pos", t_swe_house_pos, 6);
100
+ rb_define_method(cSweph, "swe_deltat", t_swe_deltat, 1);
101
+ }