1extern crate serde;
2extern crate serde_derive;
3extern crate serde_json;
4extern crate strum;
5
6use strum::{AsStaticRef, IntoEnumIterator};
7
8use libswe_sys::sweconst::{
10 Angle, Bodies, Calandar, House, Object, ObjectType, OptionalFlag,
11};
12use libswe_sys::swerust::{
13 handler_swe02, handler_swe03, handler_swe07, handler_swe08, handler_swe14,
14};
15use serde::Deserialize;
16use std::env;
17use std::fs::File;
18use std::io::Read;
19use std::path::PathBuf;
20
21#[derive(Deserialize, Debug)]
22pub struct Data {
23 year: i32,
24 month: i32,
25 day: i32,
26 hourf64: f64,
27 hour: i32,
28 min: i32,
29 sec: f64,
30 lat: f64,
31 lng: f64,
32}
33
34fn main() {
35 println!("Swissephem C -> Rust");
36 let swe02_path: &str =
40 "/Users/stephanebressani/Code/Rust/libswe-sys/src/swisseph/sweph";
41 handler_swe02::set_ephe_path(&swe02_path);
42 println!("Set the path of ephemeris to: {}", &swe02_path);
43 println!("Version swephem: {}", handler_swe02::version());
44 println!("Get path of library: {}", handler_swe02::get_library_path());
45
46 const PATH: &str = "examples/data.json";
47 let mut s = String::new();
48 let mut file_path = PathBuf::new();
49 file_path.push(env::current_dir().unwrap().as_path());
50 file_path.push(PATH);
51 File::open(file_path.as_path())
52 .unwrap()
53 .read_to_string(&mut s)
54 .unwrap();
55 let data: Data = serde_json::from_str(&s).unwrap();
56 println!("Data: {:?}", data);
57 let julday: f64 = handler_swe08::julday(
58 data.year,
59 data.month,
60 data.day,
61 data.hourf64,
62 Calandar::Gregorian,
63 );
64 println!("Get julday: {:?}", julday);
65
66 let mut object: Vec<Object> = Vec::new();
67 let mut calc: handler_swe03::CalcUtResult;
68 for bodies in Bodies::iter() {
69 if bodies.clone().object_type() == ObjectType::PlanetOrStar
70 || bodies.clone().object_type() == ObjectType::Fiction
71 {
72 calc = handler_swe03::calc_ut(
73 julday,
74 bodies.clone(),
75 OptionalFlag::Speed as i32,
76 );
77 object.push(Object::new(
78 bodies.clone(),
79 bodies.clone().as_static(),
80 bodies.clone().object_type(),
81 calc.longitude,
82 calc.latitude,
83 calc.speed_longitude,
84 ));
85 }
86 }
87
88 for o in object {
89 println!("{:?}", o);
90 }
91
92 let pheno_ut: handler_swe07::PhenoUtResult = handler_swe07::pheno_ut(
93 julday,
94 Bodies::Sun,
95 OptionalFlag::Speed as i32,
96 );
97 println!("PhenoUt: {:?}", pheno_ut);
98
99 let name = handler_swe14::house_name('P');
101 println!("Hsys: {}", name);
102
103 let utc_time_zone: handler_swe08::UtcTimeZoneResult =
104 handler_swe08::utc_time_zone(
105 data.year, data.month, data.day, data.hour, data.min, data.sec, 2.0,
106 );
107 println!("utc_time_zone: {:?}", utc_time_zone);
108
109 let utc_to_jd: handler_swe08::UtcToJdResult = handler_swe08::utc_to_jd(
110 utc_time_zone.year[0],
111 utc_time_zone.month[0],
112 utc_time_zone.day[0],
113 utc_time_zone.hour[0],
114 utc_time_zone.min[0],
115 utc_time_zone.sec[0],
116 Calandar::Gregorian,
123 );
124 println!("utc_to_jd: {:?}", utc_to_jd);
125
126 let result_w =
128 handler_swe14::houses(utc_to_jd.julian_day_ut, data.lat, data.lng, 'W');
129 let mut house2: Vec<House> = Vec::new();
131 for (i, res) in result_w.clone().cusps.iter().enumerate() {
132 if i > 0 {
133 let angle = Angle::Nothing;
135 house2.push(House::new(i as i32, res.clone(), angle));
136 if i + 1 > 12 {
137 break;
138 }
139 }
140 }
141
142 for h in house2 {
143 println!("{:?}", h);
144 }
145 println!("House (wohle signs): {:?}", result_w.clone());
146
147 let result =
149 handler_swe14::houses(utc_to_jd.julian_day_ut, data.lat, data.lng, 'P');
150 let mut house: Vec<House> = Vec::new();
152 for (i, res) in result.clone().cusps.iter().enumerate() {
153 if i > 0 {
154 let angle;
155 angle = match i {
171 1 => Angle::Asc,
172 4 => Angle::Fc,
173 7 => Angle::Desc,
174 10 => Angle::Mc,
175 _ => Angle::Nothing,
176 };
177 house.push(House::new(i as i32, res.clone(), angle));
178 if i + 1 > 12 {
179 break;
180 }
181 }
182 }
183
184 for h in house {
185 println!("{:?}", h);
186 }
187 println!("House (Placidus): {:?}", result.clone());
188
189 let calcfp = handler_swe03::calc_ut_fp(
191 julday,
192 data.lat,
193 data.lng,
194 'P',
195 OptionalFlag::Speed as i32,
196 );
197 println!("Fortuna Part: {}", calcfp.longitude);
198
199 println!("Exit and free memory swephem");
200 handler_swe02::close();
201}