erfars 0.2.0

Safe Rust bindings to the Essential Routines for Fundamental Astronomy (ERFA) C library.
Documentation
//! ERFA Calendar Functions

use crate::{ERFAResult, raw::calendar::*, unexpected_val_err};

/// Gregorian Calendar to Julian Date.
///
/// Please see the full ERFA docs for this function [here](https://github.com/liberfa/erfa/blob/master/src/cal2jd.c)
pub fn Cal2jd(year: i32, month: i32, day: i32) -> ERFAResult<(f64, f64)> {
    let mut djm0: f64 = 0.0;
    let mut djm: f64 = 0.0;
    let err: i32;
    unsafe { err = eraCal2jd(year, month, day, &mut djm0, &mut djm) };

    match err {
        0 => Ok(((djm0, djm), err)),
        -1 => Err(err),
        -2 => Err(err),
        -3 => Err(err),
        _ => unexpected_val_err!(eraCal2dj),
    }
}

/// Julian Date to Besselian Epoch.
///
/// Please see the full ERFA docs for this function [here](https://github.com/liberfa/erfa/blob/master/src/epb.c)
pub fn Epb(jd0: f64, jd1: f64) -> f64 {
    return unsafe { eraEpb(jd0, jd1) };
}

/// Besselian Epoch to Julian Date.
///
/// Please see the full ERFA docs for this function [here](https://github.com/liberfa/erfa/blob/master/src/epb2jd.c)
pub fn Epb2jd(epoch: f64) -> (f64, f64) {
    let mut djm0: f64 = 0.0;
    let mut djm: f64 = 0.0;
    unsafe {
        eraEpb2jd(epoch, &mut djm0, &mut djm);
    }

    return (djm0, djm);
}

/// Julian Date to Julian Epoch.
///
/// Please see the full ERFA docs for this function [here](https://github.com/liberfa/erfa/blob/master/src/epj.c)
pub fn Epj(jd0: f64, jd1: f64) -> f64 {
    return unsafe { eraEpj(jd0, jd1) };
}

/// Julian Epoch to Julian Date.
///
/// Please see the full ERFA docs for this function [here](https://github.com/liberfa/erfa/blob/master/src/epj2jd.c)
pub fn Epj2jd(epoch: f64) -> (f64, f64) {
    let mut djm0: f64 = 0.0;
    let mut djm: f64 = 0.0;
    unsafe {
        eraEpj2jd(epoch, &mut djm0, &mut djm);
    }

    return (djm0, djm);
}

/// Julian Date to Gregorian year, month, day, and fraction of a day.
///
/// Please see the full ERFA docs for this function [here](https://github.com/liberfa/erfa/blob/master/src/jd2cal.c)
pub fn Jd2cal(jd0: f64, jd1: f64) -> ERFAResult<(i32, i32, i32, f64)> {
    let mut iy: i32 = 0;
    let mut im: i32 = 0;
    let mut id: i32 = 0;
    let mut fd: f64 = 0.0;
    let err: i32;
    unsafe { err = eraJd2cal(jd0, jd1, &mut iy, &mut im, &mut id, &mut fd) };

    match err {
        0 => Ok(((iy, im, id, fd), 0)),
        -1 => Err(-1),
        _ => unexpected_val_err!(eraJd2cal),
    }
}

/// Julian Date to Gregorian Calendar, expressed in a form convenient for
/// formatting messages: rounded to a specified precision.
///
/// Please see the full ERFA docs for this function [here](https://github.com/liberfa/erfa/blob/master/src/jdcalf.c)
pub fn Jdcalf(jd0: f64, jd1: f64, ndp: i32) -> ERFAResult<(i32, i32, i32, i32)> {
    let mut iymdf: [i32; 4] = [0, 0, 0, 0];
    let err: i32;
    unsafe { err = eraJdcalf(ndp, jd0, jd1, &mut iymdf) };

    match err {
        0 => Ok(((iymdf[0], iymdf[1], iymdf[2], iymdf[3]), 0)),
        1 => Ok(((iymdf[0], iymdf[1], iymdf[2], iymdf[3]), 1)),
        -1 => Err(-1),
        _ => unexpected_val_err!(eraJdcalf),
    }
}