Skip to content

Commit bb95e7e

Browse files
committed
Export minpack API via bind(c)
1 parent 8479bd3 commit bb95e7e

File tree

5 files changed

+981
-8
lines changed

5 files changed

+981
-8
lines changed

fpm.toml

+5
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,8 @@ main = "test_lmdif.f90"
4646
name = "test_lmstr"
4747
source-dir = "test"
4848
main = "test_lmstr.f90"
49+
50+
[[test]]
51+
name = "c-test"
52+
source-dir = "test/api"
53+
main = "tester.c"

include/minpack.h

+363
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,363 @@
1+
#pragma once
2+
3+
#ifdef __cplusplus
4+
#define MINPACK_EXTERN extern "C"
5+
#else
6+
#define MINPACK_EXTERN extern
7+
#endif
8+
9+
// In case we have to add some attributes to all functions (e.g. for DLL exports)
10+
#define MINPACK_CALL
11+
12+
MINPACK_EXTERN double MINPACK_CALL
13+
minpack_dpmpar(int /* i */);
14+
15+
typedef void (*minpack_func)(
16+
int /* n */,
17+
const double* /* x */,
18+
double* /* fvec */,
19+
int* /* iflag */,
20+
void* /* udata */);
21+
22+
/*
23+
* the purpose of hybrd is to find a zero of a system of
24+
* n nonlinear functions in n variables by a modification
25+
* of the powell hybrid method. the user must provide a
26+
* subroutine which calculates the functions. the jacobian is
27+
* then calculated by a forward-difference approximation.
28+
*/
29+
MINPACK_EXTERN void MINPACK_CALL
30+
minpack_hybrd(
31+
minpack_func /* fcn */,
32+
int /* n */,
33+
double* /* x */,
34+
double* /* fvec */,
35+
double /* xtol */,
36+
int /* maxfev */,
37+
int /* ml */,
38+
int /* mu */,
39+
double /* epsfcn */,
40+
double* /* diag */,
41+
int /* mode */,
42+
double /* factor */,
43+
int /* nprint */,
44+
int* /* info */,
45+
int* /* nfev */,
46+
double* /* fjac */,
47+
int /* ldfjac */,
48+
double* /* r */,
49+
int /* lr */,
50+
double* /* qtf */,
51+
double* /* wa1 */,
52+
double* /* wa2 */,
53+
double* /* wa3 */,
54+
double* /* wa4 */,
55+
void* /* udata */);
56+
57+
/*
58+
* the purpose of hybrd1 is to find a zero of a system of
59+
* n nonlinear functions in n variables by a modification
60+
* of the powell hybrid method. this is done by using the
61+
* more general nonlinear equation solver hybrd. the user
62+
* must provide a subroutine which calculates the functions.
63+
* the jacobian is then calculated by a forward-difference
64+
* approximation.
65+
*/
66+
MINPACK_EXTERN void MINPACK_CALL
67+
minpack_hybrd1(
68+
minpack_func /* fcn */,
69+
int /* n */,
70+
double* /* x */,
71+
double* /* fvec */,
72+
double /* tol */,
73+
int* /* info */,
74+
double* /* wa */,
75+
int /* lwa */,
76+
void* /* udata */);
77+
78+
typedef void (*minpack_fcn_hybrj)(
79+
int /* n */,
80+
const double* /* x */,
81+
double* /* fvec */,
82+
double* /* fjac */,
83+
int /* ldfjac */,
84+
int* /* iflag */,
85+
void* /* udata */);
86+
87+
/*
88+
* the purpose of hybrj is to find a zero of a system of
89+
* n nonlinear functions in n variables by a modification
90+
* of the powell hybrid method. the user must provide a
91+
* subroutine which calculates the functions and the jacobian.
92+
*/
93+
MINPACK_EXTERN void MINPACK_CALL
94+
minpack_hybrj(
95+
minpack_fcn_hybrj /* fcn */,
96+
int /* n */,
97+
double* /* x */,
98+
double* /* fvec */,
99+
double* /* fjac */,
100+
int /* ldfjac */,
101+
double /* xtol */,
102+
int /* maxfev */,
103+
double* /* diag */,
104+
int /* mode */,
105+
double /* factor */,
106+
int /* nprint */,
107+
int* /* info */,
108+
int* /* nfev */,
109+
int* /* njev */,
110+
double* /* r */,
111+
int /* lr */,
112+
double* /* qtf */,
113+
double* /* wa1 */,
114+
double* /* wa2 */,
115+
double* /* wa3 */,
116+
double* /* wa4 */,
117+
void* /* udata */);
118+
119+
/*
120+
* The purpose of hybrj1 is to find a zero of a system of
121+
* n nonlinear functions in n variables by a modification
122+
* of the powell hybrid method. this is done by using the
123+
* more general nonlinear equation solver hybrj. the user
124+
* must provide a subroutine which calculates the functions
125+
* and the jacobian.
126+
*/
127+
MINPACK_EXTERN void MINPACK_CALL
128+
minpack_hybrj1(
129+
minpack_fcn_hybrj /* fcn */,
130+
int /* n */,
131+
double* /* x */,
132+
double* /* fvec */,
133+
double* /* fjac */,
134+
int /* ldfjac */,
135+
double /* tol */,
136+
int* /* info */,
137+
double* /* wa */,
138+
int /* lwa */,
139+
void* /* udata */);
140+
141+
typedef void (*minpack_fcn_lmder)(
142+
int /* m */,
143+
int /* n */,
144+
const double* /* x */,
145+
double* /* fvec */,
146+
double* /* fjac */,
147+
int /* ldfjac */,
148+
int* /* iflag */,
149+
void* /* udata */);
150+
151+
/*
152+
* the purpose of lmder is to minimize the sum of the squares of
153+
* m nonlinear functions in n variables by a modification of
154+
* the levenberg-marquardt algorithm. the user must provide a
155+
* subroutine which calculates the functions and the jacobian.
156+
*/
157+
MINPACK_EXTERN void MINPACK_CALL
158+
minpack_lmder(
159+
minpack_fcn_lmder /* fcn */,
160+
int /* m */,
161+
int /* n */,
162+
double* /* x */,
163+
double* /* fvec */,
164+
double* /* fjac */,
165+
int /* ldfjac */,
166+
double /* ftol */,
167+
double /* xtol */,
168+
double /* gtol */,
169+
int /* maxfev */,
170+
double* /* diag */,
171+
int /* mode */,
172+
double /* factor */,
173+
int /* nprint */,
174+
int* /* info */,
175+
int* /* nfev */,
176+
int* /* njev */,
177+
int* /* ipvt */,
178+
double* /* qtf */,
179+
double* /* wa1 */,
180+
double* /* wa2 */,
181+
double* /* wa3 */,
182+
double* /* wa4 */,
183+
void* /* udata */);
184+
185+
/*
186+
* the purpose of lmder1 is to minimize the sum of the squares of
187+
* m nonlinear functions in n variables by a modification of the
188+
* levenberg-marquardt algorithm. this is done by using the more
189+
* general least-squares solver lmder. the user must provide a
190+
* subroutine which calculates the functions and the jacobian.
191+
*/
192+
MINPACK_EXTERN void MINPACK_CALL
193+
minpack_lmder1(
194+
minpack_fcn_lmder /* fcn */,
195+
int /* m */,
196+
int /* n */,
197+
double /* *x */,
198+
double /* *fvec */,
199+
double /* *fjac */,
200+
int /* ldfjac */,
201+
double /* tol */,
202+
int /* *info */,
203+
int /* *ipvt */,
204+
double /* *wa */,
205+
int /* lwa */,
206+
void* /* udata */);
207+
208+
typedef void (*minpack_func2)(
209+
int /* m */,
210+
int /* n */,
211+
const double* /* x */,
212+
double* /* fvec */,
213+
int* /* iflag */,
214+
void* /* udata */);
215+
216+
/*
217+
* the purpose of lmdif is to minimize the sum of the squares of
218+
* m nonlinear functions in n variables by a modification of
219+
* the levenberg-marquardt algorithm. the user must provide a
220+
* subroutine which calculates the functions. the jacobian is
221+
* then calculated by a forward-difference approximation.
222+
*/
223+
MINPACK_EXTERN void MINPACK_CALL
224+
minpack_lmdif(
225+
minpack_func2 /* fcn */,
226+
int /* m */,
227+
int /* n */,
228+
double* /* x */,
229+
double* /* fvec */,
230+
double /* ftol */,
231+
double /* xtol */,
232+
double /* gtol */,
233+
int /* maxfev */,
234+
double /* epsfcn */,
235+
double* /* diag */,
236+
int /* mode */,
237+
double /* factor */,
238+
int /* nprint */,
239+
int* /* info */,
240+
int* /* nfev */,
241+
double* /* fjac */,
242+
int /* ldfjac */,
243+
int* /* ipvt */,
244+
double* /* qtf */,
245+
double* /* wa1 */,
246+
double* /* wa2 */,
247+
double* /* wa3 */,
248+
double* /* wa4 */,
249+
void* /* udata */);
250+
251+
/*
252+
* the purpose of lmdif1 is to minimize the sum of the squares of
253+
* m nonlinear functions in n variables by a modification of the
254+
* levenberg-marquardt algorithm. this is done by using the more
255+
* general least-squares solver lmdif. the user must provide a
256+
* subroutine which calculates the functions. the jacobian is
257+
* then calculated by a forward-difference approximation.
258+
*/
259+
MINPACK_EXTERN void MINPACK_CALL
260+
minpack_lmdif1(
261+
minpack_func2 /* fcn */,
262+
int /* m */,
263+
int /* n */,
264+
double* /* x */,
265+
double* /* fvec */,
266+
double /* tol */,
267+
int* /* info */,
268+
int* /* iwa */,
269+
double* /* wa */,
270+
int /* lwa */,
271+
void* /* udata */);
272+
273+
typedef void (*minpack_fcn_lmstr)(
274+
int /* m */,
275+
int /* n */,
276+
const double* /* x */,
277+
double* /* fvec */,
278+
double* /* fjrow */,
279+
int* /* iflag */,
280+
void* /* udata */);
281+
282+
/*
283+
* the purpose of lmstr is to minimize the sum of the squares of
284+
* m nonlinear functions in n variables by a modification of
285+
* the levenberg-marquardt algorithm which uses minimal storage.
286+
* the user must provide a subroutine which calculates the
287+
* functions and the rows of the jacobian.
288+
*/
289+
MINPACK_EXTERN void MINPACK_CALL
290+
minpack_lmstr(
291+
minpack_fcn_lmstr /* fcn */,
292+
int /* m */,
293+
int /* n */,
294+
double* /* x */,
295+
double* /* fvec */,
296+
double* /* fjac */,
297+
int /* ldfjac */,
298+
double /* ftol */,
299+
double /* xtol */,
300+
double /* gtol */,
301+
int /* maxfev */,
302+
double* /* diag */,
303+
int /* mode */,
304+
double /* factor */,
305+
int /* nprint */,
306+
int* /* info */,
307+
int* /* nfev */,
308+
int* /* njev */,
309+
int* /* ipvt */,
310+
double* /* qtf */,
311+
double* /* wa1 */,
312+
double* /* wa2 */,
313+
double* /* wa3 */,
314+
double* /* wa4 */,
315+
void* /* udata */);
316+
317+
/*
318+
* the purpose of lmstr1 is to minimize the sum of the squares of
319+
* m nonlinear functions in n variables by a modification of
320+
* the levenberg-marquardt algorithm which uses minimal storage.
321+
* this is done by using the more general least-squares solver
322+
* lmstr. the user must provide a subroutine which calculates
323+
* the functions and the rows of the jacobian.
324+
*/
325+
MINPACK_EXTERN void MINPACK_CALL
326+
minpack_lmstr1(
327+
minpack_fcn_lmstr /* fcn */,
328+
int /* m */,
329+
int /* n */,
330+
double* /* x */,
331+
double* /* fvec */,
332+
double* /* fjac */,
333+
int /* ldfjac */,
334+
double /* tol */,
335+
int* /* info */,
336+
int* /* ipvt */,
337+
double* /* wa */,
338+
int /* lwa */,
339+
void* /* udata */);
340+
341+
/*
342+
* this subroutine checks the gradients of m nonlinear functions
343+
* in n variables, evaluated at a point x, for consistency with
344+
* the functions themselves.
345+
*
346+
* the subroutine does not perform reliably if cancellation or
347+
* rounding errors cause a severe loss of significance in the
348+
* evaluation of a function. therefore, none of the components
349+
* of x should be unusually small (in particular, zero) or any
350+
* other value which may cause loss of significance.
351+
*/
352+
MINPACK_EXTERN void MINPACK_CALL
353+
minpack_chkder(
354+
int /* m */,
355+
int /* n */,
356+
const double* /* x */,
357+
const double* /* fvec */,
358+
const double* /* fjac */,
359+
int /* ldfjac */,
360+
double* /* xp */,
361+
const double* /* fvecp */,
362+
int /* mode */,
363+
double* /* err */);

0 commit comments

Comments
 (0)