Skip to main content

dierckx_sys/
lib.rs

1
2#![doc = include_str!("../README.md")]
3
4use libc::{c_double,c_int, };
5
6/*
7  Copyright 2021, Harbers Bik LLC
8
9  Licensed under the Apache License, Version 2.0 (the "License");
10  you may not use this file except in compliance with the License.
11  You may obtain a copy of the License at
12
13      http://www.apache.org/licenses/LICENSE-2.0
14
15  Unless required by applicable law or agreed to in writing, software
16  distributed under the License is distributed on an "AS IS" BASIS,
17  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  See the License for the specific language governing permissions and
19  limitations under the License.
20*/
21
22extern "C" {
23
24    #[doc = include_str!("curfit.md")]
25    pub fn curfit_(
26        iopt: *const c_int,     // iopt -1: Least-squares spline fixed knots, 0,1: smoothing spline. iopt=0 and s=0: interpolating spline
27        m: *const c_int,        // Number of data points supplied
28        x: *const c_double,     // Array of x coordinates (at least m values)
29        y: *const c_double,     // Array of y coordinates (at least m values)
30        w: *const c_double,     // Array weights (at least m values)
31        xb: *const c_double,    // Bounderies of the approximation interval. xb<=x(1), xe<=x(m)
32        xe: *const c_double, 
33        k: *const c_int,        // Degree of the spline, Linear = 1, Cubic = 3, Quintic = 5
34        s: *const c_double,     // Smoothing factor to be used if iopt >= 0
35        nest: *const c_int,     // nest = m + k + 1
36        n: *mut c_int,          // Number of knots returned. For iopt=-1 value needs to be specified on entry
37        t: *mut c_double,       // Array of dimension of at least nest. For iopt=-1 array of knots to be used for least-squares spline
38        c: *mut c_double,       // Double array of at least nest. Will contain the coefficients of the b-spline representation
39        fp: *mut c_double,      // Weighted sum of the squared residuals of the spline approximation.
40        wrk: *mut c_double,     // Double array of dimension at least (m(k+1)+nest(7+3k)).
41        lwrk: *const c_int,     // Size of 'wrk'
42        iwrk: *mut c_int,       // int Array of at least nest (m + k + 1)
43        ier: *mut c_int         // Error flag.
44    );
45
46
47    pub fn concur_(
48        iopt: *const c_int,     // iopt -1: Least-squares spline fixed knots, 0,1: smoothing spline. iopt=0 and s=0: interpolating spline
49        idim: *const c_int,     // dimension of the curve 0 < idim < 11; e.g. 3: trajectory of a fly flying in your office
50        m: *const c_int,        // Number of data points supplied
51        u: *const c_double,     // Array of parameter values (e.g. pathlength)
52        mx: *const c_int,       // Array size of data points, idim * m
53        x: *const c_double,     // Datapoints eg [x0, y0, z0, ... x1, y1.., z1, ..]
54        xx: *mut c_double,      // mx sized array, used as working space.
55        w: *const c_double,     // Array weights (at least m values)
56        ib: *const c_int,       // number of derivative constraints for the curve at the begin point: 0<=ib<=(k+1)/2 
57                                // choose 0 for only endpoint value (x) , 1 to add first derivative [x, dx/du], 2: to add second [x, dx/du, d2x/du2]
58        db: *const c_double,    // Array with the actural derivative begin point constraints
59        nb: *const c_int,       // Size of db: idim*ib
60        ie: *const c_int,       // number of derivative constraints for the curve at the end point: 0<=ib<=(k+1)/2 
61                                // choose 0 for only endpoint value (x) , 1 to add first derivative [x, dx/du], 2: to add second [x, dx/du, d2x/du2]
62        de: *const c_double,    // Array with the actural derivative begin point constraints
63        ne: *const c_int,       // Size of db: idim*ib
64        k: *const c_int,        // Degree of the spline, cubic = 3
65        s: *const c_double,           // Smoothing factor to be used if iopt >= 0
66        nest: *const c_int,     // nest=m+k+1+max(0,ib-1)+max(0,ie-1),
67        n: *mut c_int,          // Number of knots returned. For iopt=-1 value needs to pe specified on entry
68        t: *mut c_double,       // Array of dimension of at least nest. For iopt=-1 array of knots to be used for lsq spline
69        nc: *const c_int,       // actual size of array c: nest * idim
70        c: *mut c_double,       // coefficients of the b-spline representation, with size nc = nest * idim
71        np: *const c_int,       // size of cp: 2 * (k+1) * idim
72        cp:*mut c_double,       // array at least 2 * (k+1) * idim; spline representation of end points, mainly for internal use
73        fp: *mut c_double,      // Weighted sum of the squared residuals of the spline approximation.
74        wrk: *mut c_double,     // Float working array
75        lwrk: *const c_int,     // m*(k+1)+nest*(6+idim+3*k)
76        iwrk: *mut c_int,       // Integer working array
77        ier: *mut c_int         // Error flag.
78    );
79
80    pub fn clocur_(
81        iopt: *const c_int,     // iopt -1: Least-squares spline fixed knots, 0,1: smoothing spline. iopt=0 and s=0: interpolating spline
82        ipar: *const c_int,     // ipar 1: User supplied parameter values u(i), 0: values will be calculated by clocur
83        idim: *const c_int,     // dimension of the curve 0 < idim < 11; e.g. 3: trajectory of a fly flying in your office
84        m: *const c_int,        // Number of data points supplied
85        u: *const c_double,     // Array of parameter values (e.g. pathlength)
86        mx: *const c_int,       // Array size of data points, idim * m
87        x: *const c_double,     // Datapoints eg [x0, y0, z0, ... x1, y1.., z1, ..]
88        w: *const c_double,     // Array weights (at least m values)
89        k: *const c_int,        // Degree of the spline, cubic = 3
90        s: *const c_double,     // Smoothing factor to be used if iopt >= 0
91        nest: *const c_int,     // nest >= m+2*k
92        n: *mut c_int,          // Number of knots returned. For iopt=-1 value needs to be specified on entry
93        t: *mut c_double,       // Array of dimension of at least nest. For iopt=-1 array of knots to be used for lsq spline
94        nc: *const c_int,       // actual size of array c: nest * idim
95        c: *mut c_double,       // coefficients of the b-spline representation, with size nc = nest * idim
96        fp: *mut c_double,      // Weighted sum of the squared residuals of the spline approximation.
97        wrk: *mut c_double,     // Double array of dimension at least m*(k+1)+nest*(7+idim+5*k).
98        lwrk: *const c_int,     // Size of 'wrk'
99        iwrk: *mut c_int,       // int Array of at least nest
100        ier: *mut c_int,        // Error flag.
101    );
102
103    pub fn splev_(
104        t: *const c_double,     // array,length n, which contains the position of the knots
105        n: *const c_int,        // integer, giving the total number of knots of s(x). 
106        c: *const c_double,     // array,length n, which contains the b-spline coefficients
107        k: *const c_int,        // integer, giving the degree of s(x)
108        x: *const c_double,     // array,length m, which contains the points where s(x) must be evaluated
109        y: *mut c_double,       // array,length m, giving the value of s(x) at the different points
110        m: *const c_int,        // length of x and y
111        ier: *mut c_int,        // ier = 0 : normal return;  ier =10 : invalid input data : restrictions:  m >= 1, t(k+1) <= x(i) <= x(i+1) <= t(n-k) , i=1,2,...,m-1
112    ); 
113
114    pub fn curev_(
115        idim: *const c_int,     // integer, spline curve dimension
116        t: *const c_double,     // array, length n, knot positions
117        n: *const c_int,        // integer, total number of knots of s(x). 
118        c: *const c_double,     // array, length n, b-spline coefficients
119        nc: *const c_int,       // integer, number of b-spline coefficients
120        k: *const c_int,        // integer, spline degree
121        u: *const c_double,     // array,length m, which contains the points where spline s(u) must be evaluated
122        m: *const c_int,        // number of points where s(u) mut be evaluated
123        xy: *mut c_double,      // array,length mxy;  xy[idim*i+j] will contain the j-th coordinate of the i-th point on the curve
124        mxy: *const c_int,      // length of xy; mxy>=m*idim
125        ier: *mut c_int,        // ier = 0 : normal return;  ier =10 : invalid input data : restrictions:  m >= 1, t(k+1) <= x(i) <= x(i+1) <= t(n-k) , i=1,2,...,m-1
126    ); 
127
128    // all derivatives for a single point
129    pub fn spalde_(
130        t: *const c_double,     // array,length n, which contains the position of the knots
131        n: *const c_int,        // integer, giving the total number of knots of s(x). 
132        c: *const c_double,     // array,length n, which contains the b-spline coefficients
133        k1: *const c_int,       // integer, giving the order of s(x), k+1, with k polynomial degree
134        x: *const c_double,     // (single) f64 value which contains the point where the derivatives must be evaluated
135        d: *mut c_double,       // array,length k+1, containing the derivative values of s(x)
136        ier: *mut c_int,        // ier = 0 : normal return;  ier =10 : invalid input data
137    );
138
139    // all derivatives for a single point
140    pub fn cualde_(
141        idim: *const c_int,     // integer, giving the dimension of the spline curve
142        t: *const c_double,     // array,length n, which contains the position of the knots
143        n: *const c_int,        // integer, giving the total number of knots of s(x). 
144        c: *const c_double,     // array,length n, which contains the b-spline coefficients
145        k1: *const c_int,       // integer, giving the order of s(x), k+1, with k polynomial degree
146        u: *const c_double,     // (single) f64 value which contains the point where the derivatives must be evaluated
147        d: *mut c_double,       // array,length nd, giving the different curve derivatives.  d(idim*l+j) will contain the j-th coordinate of the l-th  derivative of the curve at the point u 
148        nd: *const c_int,       // integer, giving the dimension of array d: `nd >=(k+1)*idim`
149        ier: *mut c_int,        // ier = 0 : normal return;  ier =10 : invalid input data
150    );
151
152    // a single derivative for an array of points
153    pub fn spalder_(
154        t: *const c_double,     // array,length n, which contains the position of the knots
155        n: *const c_int,        // integer, giving the total number of knots of s(x). 
156        c: *const c_double,     // array,length n, which contains the b-spline coefficients
157        k: *const c_int,        // integer, degree of s(x)
158        nu: *const c_int,       // integer, specifying the order of the derivative. 0<=nu<=k
159        x: *const c_double,     // array,length m, which contains the points where  the derivative of s(x) must be evaluated
160        y: *mut c_double,       // array,length m, giving the value of the derivative of s(x) at the different points
161        m: *const c_int,        // length of x 
162        wrk: *mut c_double,     // Float working array of dimension n
163        ier: *mut c_int,        // ier = 0 : normal return;  ier =10 : invalid input data
164    );
165
166
167}