1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
//
// A rust binding for the GSL library by Guillaume Gomez (guillaume1.gomez@gmail.com)
//

use crate::Value;
use ffi::FFI;

/// This function returns the index i of the array x_array such that `x_array[i] <= x < x_array[i+1]`.
/// The index is searched for in the range `[index_lo,index_hi]`.
#[doc(alias = "gsl_interp_bsearch")]
pub fn bsearch(x_array: &[f64], x: f64, index_lo: usize, index_hi: usize) -> usize {
    unsafe { sys::gsl_interp_bsearch(x_array.as_ptr(), x, index_lo, index_hi) }
}

/// This function returns the interpolated value of y for a given point x, using the interpolation
/// object interp, data arrays xa and ya and the accelerator acc. When x is outside the range of xa,
/// the error code ::Dom is returned with a value of rgsl::NAN for y.
#[doc(alias = "gsl_interp_eval")]
pub fn eval(interp: &::Interp, xa: &[f64], ya: &[f64], x: f64, acc: &mut ::InterpAccel) -> f64 {
    unsafe {
        sys::gsl_interp_eval(
            interp.unwrap_shared(),
            xa.as_ptr(),
            ya.as_ptr(),
            x,
            &mut acc.0,
        )
    }
}

/// This function returns the interpolated value of y for a given point x, using the interpolation
/// object interp, data arrays xa and ya and the accelerator acc. When x is outside the range of xa,
/// the error code ::Dom is returned with a value of rgsl::NAN for y.
///
/// Returns `y`.
#[doc(alias = "gsl_interp_eval_e")]
pub fn eval_e(
    interp: &::Interp,
    xa: &[f64],
    ya: &[f64],
    x: f64,
    acc: &mut ::InterpAccel,
) -> (Value, f64) {
    let mut y = 0.;
    let ret = unsafe {
        sys::gsl_interp_eval_e(
            interp.unwrap_shared(),
            xa.as_ptr(),
            ya.as_ptr(),
            x,
            &mut acc.0,
            &mut y,
        )
    };
    (::Value::from(ret), y)
}

/// This function returns the derivative d of an interpolated function for a given point x, using
/// the interpolation object interp, data arrays xa and ya and the accelerator acc.
#[doc(alias = "gsl_interp_eval_deriv")]
pub fn eval_deriv(
    interp: &::Interp,
    xa: &[f64],
    ya: &[f64],
    x: f64,
    acc: &mut ::InterpAccel,
) -> f64 {
    unsafe {
        sys::gsl_interp_eval_deriv(
            interp.unwrap_shared(),
            xa.as_ptr(),
            ya.as_ptr(),
            x,
            &mut acc.0,
        )
    }
}

/// This function returns the derivative d of an interpolated function for a given point x, using
/// the interpolation object interp, data arrays xa and ya and the accelerator acc.
///
/// Returns `(Value, d)`.
#[doc(alias = "gsl_interp_eval_deriv_e")]
pub fn eval_deriv_e(
    interp: &::Interp,
    xa: &[f64],
    ya: &[f64],
    x: f64,
    acc: &mut ::InterpAccel,
) -> (Value, f64) {
    let mut d = 0.;
    let ret = unsafe {
        sys::gsl_interp_eval_deriv_e(
            interp.unwrap_shared(),
            xa.as_ptr(),
            ya.as_ptr(),
            x,
            &mut acc.0,
            &mut d,
        )
    };
    (Value::from(ret), d)
}

/// This function returns the second derivative d2 of an interpolated function for a given point x,
/// using the interpolation object interp, data arrays xa and ya and the accelerator acc.
#[doc(alias = "gsl_interp_eval_deriv2")]
pub fn eval_deriv2(
    interp: &::Interp,
    xa: &[f64],
    ya: &[f64],
    x: f64,
    acc: &mut ::InterpAccel,
) -> f64 {
    unsafe {
        sys::gsl_interp_eval_deriv2(
            interp.unwrap_shared(),
            xa.as_ptr(),
            ya.as_ptr(),
            x,
            &mut acc.0,
        )
    }
}

/// This function returns the second derivative d2 of an interpolated function for a given point x,
/// using the interpolation object interp, data arrays xa and ya and the accelerator acc.
///
/// Returns `(Value, d2)`.
#[doc(alias = "gsl_interp_eval_deriv2_e")]
pub fn eval_deriv2_e(
    interp: &::Interp,
    xa: &[f64],
    ya: &[f64],
    x: f64,
    acc: &mut ::InterpAccel,
) -> (Value, f64) {
    let mut d2 = 0.;
    let ret = unsafe {
        sys::gsl_interp_eval_deriv2_e(
            interp.unwrap_shared(),
            xa.as_ptr(),
            ya.as_ptr(),
            x,
            &mut acc.0,
            &mut d2,
        )
    };
    (Value::from(ret), d2)
}

/// This function returns the numerical integral result of an interpolated function over the range
/// [a, b], using the interpolation object interp, data arrays xa and ya and the accelerator acc.
#[doc(alias = "gsl_interp_eval_integ")]
pub fn eval_integ(
    interp: &::Interp,
    xa: &[f64],
    ya: &[f64],
    a: f64,
    b: f64,
    acc: &mut ::InterpAccel,
) -> f64 {
    unsafe {
        sys::gsl_interp_eval_integ(
            interp.unwrap_shared(),
            xa.as_ptr(),
            ya.as_ptr(),
            a,
            b,
            &mut acc.0,
        )
    }
}

/// This function returns the numerical integral result of an interpolated function over the range
/// [a, b], using the interpolation object interp, data arrays xa and ya and the accelerator acc.
///
/// Returns `(Value, result)`.
#[doc(alias = "gsl_interp_eval_integ_e")]
pub fn eval_integ_e(
    interp: &::Interp,
    xa: &[f64],
    ya: &[f64],
    a: f64,
    b: f64,
    acc: &mut ::InterpAccel,
) -> (Value, f64) {
    let mut result = 0.;
    let ret = unsafe {
        sys::gsl_interp_eval_integ_e(
            interp.unwrap_shared(),
            xa.as_ptr(),
            ya.as_ptr(),
            a,
            b,
            &mut acc.0,
            &mut result,
        )
    };
    (Value::from(ret), result)
}