libswe_sys/swerust/swe07/
handler.rs

1use crate::raw;
2use crate::sweconst::Bodies;
3use std::ffi::{CStr, CString};
4
5/*
6 * 7. Eclipses, risings, settings, meridian transits, planetary phenomena
7 */
8#[derive(Debug)]
9pub struct PhenoUtResult {
10    pub phase_angle: f64,
11    pub phase_illuminated: f64,
12    pub elongation_of_planet: f64,
13    pub apparent_dimaeter_of_disc: f64,
14    pub apparent_magnitude: f64,
15    pub status: i32,
16    pub serr: String,
17}
18
19pub fn pheno_ut(tjd_ut: f64, ipl: Bodies, iflag: i32) -> PhenoUtResult {
20    let mut attr: [f64; 20] = [0.0; 20];
21    let mut serr = [0; 255];
22    let result = unsafe {
23        let p_attr = attr.as_mut_ptr();
24        let p_serr = serr.as_mut_ptr();
25        let status =
26            raw::swe_pheno_ut(tjd_ut, ipl as i32, iflag, p_attr, p_serr);
27        let s_serr = CString::from(CStr::from_ptr(p_serr))
28            .to_str()
29            .unwrap()
30            .to_string();
31        PhenoUtResult {
32            phase_angle: attr[0],
33            phase_illuminated: attr[1],
34            elongation_of_planet: attr[2],
35            apparent_dimaeter_of_disc: attr[3],
36            apparent_magnitude: attr[4],
37            serr: s_serr,
38            status,
39        }
40    };
41    result
42}