swisseph 1.3.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: aa1f02504d32c51d08e76d5198f94810f43bfe5dbbebd159936cf3e7daad6132
4
+ data.tar.gz: 7d185d5cf22a9a81955ee713945bbb12e03fdd13614aca4ca19faaa4dc194837
5
+ SHA512:
6
+ metadata.gz: cb03742afc4ea4ddc959921e8bfa9e5b8b0879a99027e25e4b0442a33c3a2a113d2a9b6107dc378f0510814dc468fdffd0a0966b0d2a590bc8ab6e66c55d32d8
7
+ data.tar.gz: 8fc99879df66a86c08c3199fb81e8b99021bfb6d166f013f6c2a08b1a2fac04a72f61179804acb7dc64452f0cf4335e9087811422de655eebf3c5587631607b3
data/README.md ADDED
@@ -0,0 +1,144 @@
1
+ # Swisseph
2
+
3
+ **Swiss Ephemeris for Ruby**
4
+
5
+ [![Gem Version](https://badge.fury.io/rb/swisseph.svg)](https://badge.fury.io/rb/swisseph)
6
+
7
+ Native Ruby bindings for the [Swiss Ephemeris](http://www.astro.com/swisseph/) library (v2.10.3a), providing high-precision astronomical calculations for astrological applications.
8
+
9
+ ## History & Motivation
10
+
11
+ This gem is a modernized fork of the original [aakara/swe4r](https://github.com/aakara/swe4r). Since the original project has been abandoned, this version was created to:
12
+
13
+ - Ensure compatibility with modern Ruby versions.
14
+ - Automate the build process using CMake.
15
+ - Provide more idiomatic Ruby aliases and convenience methods.
16
+ - Maintain active support for the latest Swiss Ephemeris releases.
17
+
18
+ ## Convenience Features
19
+
20
+ ### Shorthand Methods
21
+ All `swe_*` methods are also available without the `swe_` prefix:
22
+
23
+ ```ruby
24
+ # Traditional way:
25
+ Swisseph.swe_julday(2024, 1, 1, 12.0)
26
+
27
+ # Modern shorthand:
28
+ Swisseph.julday(2024, 1, 1, 12.0)
29
+ ```
30
+
31
+ ### Module Aliases
32
+ For even shorter code, you can use the `Sweph` alias:
33
+
34
+ ```ruby
35
+ Sweph.julday(2024, 1, 1, 12.0)
36
+ ```
37
+
38
+ ---
39
+
40
+ ## Installation
41
+
42
+ ```bash
43
+ gem install swisseph
44
+ ```
45
+
46
+ Or add to your Gemfile:
47
+
48
+ ```ruby
49
+ gem 'swisseph'
50
+ ```
51
+
52
+ ### Build Requirements
53
+
54
+ This gem requires **CMake 3.14 or later** to build from source. CMake is used to automatically download the Swiss Ephemeris library from GitHub during installation.
55
+
56
+ **Installing CMake:**
57
+ - **macOS:** `brew install cmake`
58
+ - **Ubuntu/Debian:** `sudo apt-get install cmake`
59
+ - **Windows:** Download from [cmake.org](https://cmake.org/download/)
60
+
61
+ ---
62
+
63
+ ## Quick Examples
64
+
65
+ ### Calculate Planetary Position
66
+ ```ruby
67
+ require 'swisseph'
68
+
69
+ # Get Julian day for May 14, 2012 at 10:15
70
+ jd = Sweph.julday(2012, 5, 14, 10.25)
71
+
72
+ # Calculate Sun position using Moshier ephemeris
73
+ sun = Sweph.calc_ut(jd, Sweph::SE_SUN, Sweph::SEFLG_MOSEPH | Sweph::SEFLG_SPEED)
74
+
75
+ puts "Sun longitude: #{sun[0]}°"
76
+ puts "Sun latitude: #{sun[1]}°"
77
+ ```
78
+
79
+ ### Calculate House Cusps
80
+ ```ruby
81
+ require 'swisseph'
82
+
83
+ jd = Sweph.julday(2012, 5, 14, 10.25)
84
+ lat, lon = 45.45, -112.18
85
+
86
+ # Calculate Placidus houses
87
+ cusps, angles = Sweph.houses(jd, lat, lon, 'P')
88
+
89
+ puts "Ascendant: #{angles[0]}°"
90
+ puts "House 1: #{cusps[1]}°"
91
+ ```
92
+
93
+ ---
94
+
95
+ ## Supported Functions
96
+
97
+ The gem provides full coverage of the Swiss Ephemeris API. All functions are available in both `swe_prefix` and `shorthand` forms.
98
+
99
+ | Category | Key Functions |
100
+ | :--- | :--- |
101
+ | **Planets** | `calc_ut`, `calc`, `get_orbital_elements`, `pheno_ut` |
102
+ | **Fixed Stars** | `fixstar_ut`, `fixstar2_ut`, `fixstar_mag` |
103
+ | **Houses** | `houses`, `houses_ex`, `house_pos`, `house_name` |
104
+ | **Eclipses** | `sol_eclipse_when_glob`, `lun_eclipse_when`, `sol_eclipse_where` |
105
+ | **Transits** | `solcross_ut`, `mooncross_ut`, `rise_trans` |
106
+ | **Time** | `julday`, `revjul`, `utc_to_jd`, `deltat`, `sidtime` |
107
+ | **Utilities** | `set_ephe_path`, `set_topo`, `get_planet_name`, `split_deg` |
108
+
109
+ ---
110
+
111
+ ## Constants
112
+
113
+ The gem provides constants for planets, calculation flags, and more:
114
+
115
+ ```ruby
116
+ # Bodies
117
+ Swisseph::SE_SUN, SE_MOON, SE_MERCURY, SE_VENUS, SE_MARS...
118
+ # Flags
119
+ Swisseph::SEFLG_MOSEPH, SEFLG_SWIEPH, SEFLG_SPEED, SEFLG_SIDEREAL...
120
+ # Houses
121
+ 'P' (Placidus), 'K' (Koch), 'E' (Equal), 'C' (Campanus)...
122
+ ```
123
+
124
+ ---
125
+
126
+ ## Ephemeris Files
127
+
128
+ The **Moshier ephemeris** (`SEFLG_MOSEPH`) is built-in and requires no files.
129
+
130
+ For high-precision calculations, a minimal set of Swiss Ephemeris data files is **automatically included** during installation. For extended time ranges or asteroid files, download them from [astro.com](https://www.astro.com/ftp/swisseph/ephe/) and configure:
131
+
132
+ ```ruby
133
+ Sweph.set_ephe_path('/path/to/ephemeris/files')
134
+ ```
135
+
136
+ ## Documentation
137
+
138
+ - [Swiss Ephemeris Programmer's Documentation](https://www.astro.com/swisseph/swephprg.htm)
139
+ - [Official Library Homepage](http://www.astro.com/swisseph/)
140
+
141
+ ## License
142
+
143
+ GPL-2.0-or-later. See [LICENSE](LICENSE) for details.
144
+ Swiss Ephemeris library is (C) Astrodienst AG.
@@ -0,0 +1,117 @@
1
+ cmake_minimum_required(VERSION 3.14)
2
+ project(SwissEphemerisDownloader)
3
+
4
+ # Include FetchContent module for downloading dependencies
5
+ include(FetchContent)
6
+
7
+ # Swiss Ephemeris version pinning
8
+ # Use v2.10.3a as the latest stable release
9
+ # Can be overridden via: cmake -DSWISSEPH_VERSION=<tag>
10
+ set(SWISSEPH_VERSION "v2.10.3a" CACHE STRING "Swiss Ephemeris version tag")
11
+
12
+ # Fetch Swiss Ephemeris from GitHub
13
+ FetchContent_Declare(
14
+ swisseph
15
+ GIT_REPOSITORY https://github.com/aloistr/swisseph.git
16
+ GIT_TAG ${SWISSEPH_VERSION}
17
+ GIT_SHALLOW TRUE # Only fetch the specific tag, not full history
18
+ SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/swisseph_src
19
+ )
20
+
21
+ message(STATUS "Fetching Swiss Ephemeris ${SWISSEPH_VERSION} from GitHub...")
22
+ FetchContent_MakeAvailable(swisseph)
23
+
24
+ # List of C source files to copy (exclude utility programs)
25
+ set(SWEPH_SOURCES
26
+ swecl.c
27
+ swedate.c
28
+ sweephe4.c
29
+ swehel.c
30
+ swehouse.c
31
+ swejpl.c
32
+ swemmoon.c
33
+ swemplan.c
34
+ sweph.c
35
+ swephlib.c
36
+ )
37
+
38
+ # List of header files to copy
39
+ set(SWEPH_HEADERS
40
+ swedate.h
41
+ swedll.h
42
+ sweephe4.h
43
+ swehouse.h
44
+ swejpl.h
45
+ swemptab.h
46
+ swenut2000a.h
47
+ sweodef.h
48
+ sweph.h
49
+ swephexp.h
50
+ swephlib.h
51
+ swevents.h
52
+ )
53
+
54
+ # Copy source files from fetched directory to ext/swisseph
55
+ foreach(src_file ${SWEPH_SOURCES})
56
+ configure_file(
57
+ ${swisseph_SOURCE_DIR}/${src_file}
58
+ ${CMAKE_CURRENT_SOURCE_DIR}/${src_file}
59
+ COPYONLY
60
+ )
61
+ endforeach()
62
+
63
+ # Copy header files
64
+ foreach(hdr_file ${SWEPH_HEADERS})
65
+ configure_file(
66
+ ${swisseph_SOURCE_DIR}/${hdr_file}
67
+ ${CMAKE_CURRENT_SOURCE_DIR}/${hdr_file}
68
+ COPYONLY
69
+ )
70
+ endforeach()
71
+
72
+ # Copy data files from root directory
73
+ configure_file(
74
+ ${swisseph_SOURCE_DIR}/agpl-3.0.txt
75
+ ${CMAKE_CURRENT_SOURCE_DIR}/agpl-3.0.txt
76
+ COPYONLY
77
+ )
78
+
79
+ configure_file(
80
+ ${swisseph_SOURCE_DIR}/seleapsec.txt
81
+ ${CMAKE_CURRENT_SOURCE_DIR}/seleapsec.txt
82
+ COPYONLY
83
+ )
84
+
85
+ # Copy sefstars.txt from ephe/ subdirectory
86
+ configure_file(
87
+ ${swisseph_SOURCE_DIR}/ephe/sefstars.txt
88
+ ${CMAKE_CURRENT_SOURCE_DIR}/sefstars.txt
89
+ COPYONLY
90
+ )
91
+
92
+ # Copy ephemeris data files from ephe/ directory
93
+ set(SWEPH_EPHE_FILES
94
+ seas_18.se1
95
+ seasm18.se1
96
+ semo_18.se1
97
+ semom18.se1
98
+ sepl_18.se1
99
+ seplm18.se1
100
+ )
101
+
102
+ foreach(ephe_file ${SWEPH_EPHE_FILES})
103
+ if(EXISTS ${swisseph_SOURCE_DIR}/ephe/${ephe_file})
104
+ configure_file(
105
+ ${swisseph_SOURCE_DIR}/ephe/${ephe_file}
106
+ ${CMAKE_CURRENT_SOURCE_DIR}/${ephe_file}
107
+ COPYONLY
108
+ )
109
+ else()
110
+ message(WARNING "Ephemeris file not found: ${ephe_file}")
111
+ endif()
112
+ endforeach()
113
+
114
+ message(STATUS "Swiss Ephemeris sources and data files copied successfully")
115
+
116
+ # Create a stamp file to indicate successful fetch
117
+ file(WRITE ${CMAKE_CURRENT_SOURCE_DIR}/.swisseph_fetched "${SWISSEPH_VERSION}")
@@ -0,0 +1,67 @@
1
+ require 'mkmf'
2
+ require 'fileutils'
3
+
4
+ # Check if CMake is available
5
+ def cmake_available?
6
+ system('cmake --version > /dev/null 2>&1')
7
+ end
8
+
9
+ # Run CMake to fetch Swiss Ephemeris sources
10
+ def fetch_swisseph_with_cmake
11
+ puts "Fetching Swiss Ephemeris sources with CMake..."
12
+
13
+ build_dir = File.join(__dir__, 'cmake_build')
14
+ FileUtils.mkdir_p(build_dir)
15
+
16
+ # Configure CMake
17
+ unless system("cmake -S #{__dir__} -B #{build_dir}")
18
+ raise "CMake configuration failed. Please ensure CMake 3.14+ is installed."
19
+ end
20
+
21
+ # Build (which triggers FetchContent)
22
+ unless system("cmake --build #{build_dir}")
23
+ raise "CMake build failed."
24
+ end
25
+
26
+ # Verify sources were fetched
27
+ stamp_file = File.join(__dir__, '.swisseph_fetched')
28
+ unless File.exist?(stamp_file)
29
+ raise "Swiss Ephemeris sources not fetched successfully."
30
+ end
31
+
32
+ # Clean up build directory (keep fetched sources)
33
+ FileUtils.rm_rf(build_dir)
34
+
35
+ puts "Swiss Ephemeris sources fetched successfully."
36
+ end
37
+
38
+ # Check if Swiss Ephemeris sources need to be fetched
39
+ stamp_file = File.join(__dir__, '.swisseph_fetched')
40
+ swisseph_sources_exist = File.exist?(File.join(__dir__, 'sweph.c'))
41
+
42
+ if !swisseph_sources_exist || !File.exist?(stamp_file)
43
+ unless cmake_available?
44
+ raise <<~ERROR
45
+ CMake is required to build this gem but was not found.
46
+
47
+ Please install CMake 3.14 or later:
48
+ - macOS: brew install cmake
49
+ - Ubuntu/Debian: sudo apt-get install cmake
50
+ - Or download from: https://cmake.org/download/
51
+ ERROR
52
+ end
53
+
54
+ fetch_swisseph_with_cmake
55
+ end
56
+
57
+ # Get all C source files, excluding utility programs
58
+ $srcs = Dir.glob('*.c').select { |f|
59
+ !['swephgen4.c', 'swemini.c', 'sweasp.c', 'swevents.c', 'swetest.c'].include?(f)
60
+ }
61
+
62
+ # Verify we have the necessary sources
63
+ if $srcs.empty? || !$srcs.include?('swisseph.c')
64
+ raise "Required Swiss Ephemeris source files (swisseph.c) not found. Build cannot proceed."
65
+ end
66
+
67
+ create_makefile("swisseph/swisseph")