~ubuntu-branches/ubuntu/saucy/libctl/saucy

« back to all changes in this revision

Viewing changes to src/ctl.h.in

  • Committer: Bazaar Package Importer
  • Author(s): Josselin Mouette
  • Date: 2006-05-01 20:25:01 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20060501202501-lytbmb3oevyoqzxi
Tags: 3.0.1-1
* New upstream release (closes: #361676).
* Major rework of the debian/ directory. Switch to cdbs.
* Migrate Scheme files to a versioned location to allow several
  versions to be installed at once.
* Write a Makefile to put with the example.
* Update copyright, the library is now GPL.
* Use gfortran for the F77 wrappers.
* Standards-version is 3.7.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* libctl: flexible Guile-based control files for scientific software 
 
2
 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2006, Steven G. Johnson
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU Lesser General Public
 
6
 * License as published by the Free Software Foundation; either
 
7
 * version 2 of the License, or (at your option) any later version.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * Lesser General Public License for more details.
 
13
 * 
 
14
 * You should have received a copy of the GNU Lesser General Public
 
15
 * License along with this library; if not, write to the
 
16
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
 * Boston, MA  02111-1307, USA.
 
18
 *
 
19
 * Steven G. Johnson can be contacted at stevenj@alum.mit.edu.
 
20
 */
 
21
 
 
22
#ifndef CTL_H
 
23
#define CTL_H
 
24
 
 
25
#include <guile/gh.h>
 
26
 
 
27
#ifdef __cplusplus
 
28
extern "C" {
 
29
#endif                          /* __cplusplus */
 
30
 
 
31
/**************************************************************************/
 
32
/* Configuration options (guessed by configure).
 
33
   We have to put them here, rather than in a private config.h file,
 
34
   because they need to be known by user ctl-io.c and main.c files. */
 
35
 
 
36
/* set to version string */
 
37
#undef LIBCTL_VERSION
 
38
#undef LIBCTL_MAJOR_VERSION
 
39
#undef LIBCTL_MINOR_VERSION
 
40
#undef LIBCTL_BUGFIX_VERSION
 
41
 
 
42
/* Define if you have the following functions */
 
43
#undef HAVE_GH_LOAD
 
44
#undef HAVE_GH_BOOL2SCM
 
45
#undef HAVE_GH_VECTOR_REF
 
46
#undef HAVE_GH_LIST_REF
 
47
#undef HAVE_GH_LENGTH
 
48
#undef HAVE_SCM_FLUSH_ALL_PORTS
 
49
#undef HAVE_SCM_MAKE_COMPLEX
 
50
#undef HAVE_SCM_VARIABLE_SET_X
 
51
#undef HAVE_SCM_C_LOOKUP
 
52
#undef HAVE_SCM_C_MAKE_VECTOR
 
53
 
 
54
/* Define if you have the HAVE_SCM_COMPLEXP macro. */
 
55
#undef HAVE_SCM_COMPLEXP
 
56
 
 
57
/* Define if gh_lookup is not broken */
 
58
#undef GH_LOOKUP_OK
 
59
 
 
60
/* Define if we have C99 complex numbers and hence complex integration */
 
61
#undef CTL_HAS_COMPLEX_INTEGRATION
 
62
 
 
63
/**************************************************************************/
 
64
 
 
65
  /* Basic types: */
 
66
 
 
67
typedef int integer;
 
68
typedef double number;
 
69
typedef struct { number re, im; } cnumber; /* complex numbers! */
 
70
typedef short boolean;
 
71
typedef char *string;
 
72
typedef SCM list;
 
73
typedef SCM function;
 
74
typedef SCM object;
 
75
 
 
76
  /* define vector3 as a structure, not an array, so that it can
 
77
     be a function return value and so that simple assignment works. */
 
78
typedef struct { number x,y,z; } vector3;
 
79
 
 
80
  /* similarly for matrix3x3 */
 
81
typedef struct { vector3 c0, c1, c2; /* the columns */ } matrix3x3;
 
82
 
 
83
/* define complex equivalents: */
 
84
typedef struct { cnumber x,y,z; } cvector3;
 
85
typedef struct { cvector3 c0, c1, c2; /* the columns */ } cmatrix3x3;
 
86
 
 
87
/**************************************************************************/
 
88
 
 
89
#ifndef GH_LOOKUP_OK
 
90
#  define gh_lookup scm_symbol_value0
 
91
#endif
 
92
 
 
93
#ifndef HAVE_GH_LOAD
 
94
#  define gh_load gh_eval_file 
 
95
#endif
 
96
 
 
97
extern void ctl_include(char *filename);
 
98
extern char *ctl_fix_path(const char *path);
 
99
 
 
100
/**************************************************************************/
 
101
 
 
102
#ifndef HAVE_SCM_C_MAKE_VECTOR
 
103
#  define scm_c_make_vector(n,fill) scm_make_vector(SCM_MAKINUM(n), fill)
 
104
#endif
 
105
 
 
106
  /* vector3 and matrix3x3 utilities: */
 
107
 
 
108
extern number vector3_dot(vector3 v1,vector3 v2);
 
109
extern number vector3_norm(vector3 v);
 
110
extern vector3 vector3_scale(number s, vector3 v);
 
111
extern vector3 unit_vector3(vector3 v);
 
112
extern vector3 vector3_cross(vector3 v1,vector3 v2);
 
113
extern vector3 vector3_plus(vector3 v1,vector3 v2);
 
114
extern vector3 vector3_minus(vector3 v1,vector3 v2);
 
115
extern int vector3_equal(vector3 v1, vector3 v2);
 
116
 
 
117
extern vector3 matrix3x3_vector3_mult(matrix3x3 m, vector3 v);
 
118
extern vector3 matrix3x3_transpose_vector3_mult(matrix3x3 m, vector3 v);
 
119
extern matrix3x3 matrix3x3_mult(matrix3x3 m1, matrix3x3 m2);
 
120
extern matrix3x3 matrix3x3_transpose(matrix3x3 m);
 
121
extern number matrix3x3_determinant(matrix3x3 m);
 
122
extern matrix3x3 matrix3x3_inverse(matrix3x3 m);
 
123
extern int matrix3x3_equal(matrix3x3 m1, matrix3x3 m2);
 
124
 
 
125
extern vector3 matrix3x3_row1(matrix3x3 m);
 
126
extern vector3 matrix3x3_row2(matrix3x3 m);
 
127
extern vector3 matrix3x3_row3(matrix3x3 m);
 
128
 
 
129
/**************************************************************************/
 
130
 
 
131
  /* complex number utilities */
 
132
 
 
133
 
 
134
extern cnumber make_cnumber(number r, number i);
 
135
extern cnumber cnumber_conj(cnumber c);
 
136
extern int cnumber_equal(cnumber c1, cnumber c2);
 
137
#define cnumber_re(c) ((c).re)
 
138
#define cnumber_im(c) ((c).im)
 
139
 
 
140
extern vector3 cvector3_re(cvector3 cv);
 
141
extern vector3 cvector3_im(cvector3 cv);
 
142
extern cvector3 make_cvector3(vector3 vr, vector3 vi);
 
143
extern int cvector3_equal(cvector3 v1, cvector3 v2);
 
144
 
 
145
extern matrix3x3 cmatrix3x3_re(cmatrix3x3 cm);
 
146
extern matrix3x3 cmatrix3x3_im(cmatrix3x3 cm);
 
147
extern cmatrix3x3 make_cmatrix3x3(matrix3x3 mr, matrix3x3 mi);
 
148
cmatrix3x3 make_hermitian_cmatrix3x3(number m00, number m11, number m22,
 
149
                                     cnumber m01, cnumber m02, cnumber m12);
 
150
extern int cmatrix3x3_equal(cmatrix3x3 m1, cmatrix3x3 m2);
 
151
 
 
152
/**************************************************************************/
 
153
 
 
154
  /* type conversion */
 
155
 
 
156
#ifndef HAVE_GH_BOOL2SCM
 
157
  /* Guile 1.2 is missing gh_bool2scm for some reason; redefine: */
 
158
extern SCM bool2scm(boolean);
 
159
#define gh_bool2scm bool2scm
 
160
#endif
 
161
 
 
162
extern vector3 scm2vector3(SCM sv);
 
163
extern SCM vector32scm(vector3 v);
 
164
extern matrix3x3 scm2matrix3x3(SCM sm);
 
165
extern SCM matrix3x32scm(matrix3x3 m);
 
166
 
 
167
extern cnumber scm2cnumber(SCM sx);
 
168
extern SCM cnumber2scm(cnumber x);
 
169
extern cvector3 scm2cvector3(SCM sv);
 
170
extern SCM cvector32scm(cvector3 v);
 
171
extern cmatrix3x3 scm2cmatrix3x3(SCM sm);
 
172
extern SCM cmatrix3x32scm(cmatrix3x3 m);
 
173
 
 
174
#define ctl_convert_number_to_scm(x) gh_double2scm(x)
 
175
#define ctl_convert_cnumber_to_scm(x) cnumber2scm(x)
 
176
#define ctl_convert_integer_to_scm(x) gh_int2scm(x)
 
177
#define ctl_convert_string_to_scm(x) gh_str02scm(x)
 
178
#define ctl_convert_boolean_to_scm(x) gh_bool2scm(x)
 
179
#define ctl_convert_vector3_to_scm(x) vector32scm(x)
 
180
#define ctl_convert_matrix3x3_to_scm(x) matrix3x32scm(x)
 
181
#define ctl_convert_cvector3_to_scm(x) cvector32scm(x)
 
182
#define ctl_convert_cmatrix3x3_to_scm(x) cmatrix3x32scm(x)
 
183
#define ctl_convert_SCM_to_scm(x) (x)
 
184
#define ctl_convert_function_to_scm(x) (x)
 
185
#define ctl_convert_object_to_scm(x) (x)
 
186
#define ctl_convert_list_to_scm(x) (x)
 
187
 
 
188
#define ctl_convert_number_to_c(x) gh_scm2double(x)
 
189
#define ctl_convert_cnumber_to_c(x) scm2cnumber(x)
 
190
#define ctl_convert_integer_to_c(x) gh_scm2int(x)
 
191
#define ctl_convert_string_to_c(x) gh_scm2newstr(x, 0)
 
192
#define ctl_convert_boolean_to_c(x) gh_scm2bool(x)
 
193
#define ctl_convert_vector3_to_c(x) scm2vector3(x)
 
194
#define ctl_convert_matrix3x3_to_c(x) scm2matrix3x3(x)
 
195
#define ctl_convert_cvector3_to_c(x) scm2cvector3(x)
 
196
#define ctl_convert_cmatrix3x3_to_c(x) scm2cmatrix3x3(x)
 
197
#define ctl_convert_SCM_to_c(x) (x)
 
198
#define ctl_convert_function_to_c(x) (x)
 
199
#define ctl_convert_object_to_c(x) (x)
 
200
#define ctl_convert_list_to_c(x) (x)
 
201
 
 
202
/**************************************************************************/
 
203
 
 
204
  /* variable get/set functions */
 
205
 
 
206
extern integer ctl_get_integer(char *identifier);
 
207
extern number ctl_get_number(char *identifier);
 
208
extern cnumber ctl_get_cnumber(char *identifier);
 
209
extern boolean ctl_get_boolean(char *identifier);
 
210
extern char* ctl_get_string(char *identifier);
 
211
extern vector3 ctl_get_vector3(char *identifier);
 
212
extern matrix3x3 ctl_get_matrix3x3(char *identifier);
 
213
extern cvector3 ctl_get_cvector3(char *identifier);
 
214
extern cmatrix3x3 ctl_get_cmatrix3x3(char *identifier);
 
215
extern list ctl_get_list(char *identifier);
 
216
extern object ctl_get_object(char *identifier);
 
217
extern function ctl_get_function(char *identifier);
 
218
extern SCM ctl_get_SCM(char *identifier);
 
219
 
 
220
extern void ctl_set_integer(char *identifier, integer value);
 
221
extern void ctl_set_number(char *identifier, number value);
 
222
extern void ctl_set_cnumber(char *identifier, cnumber value);
 
223
extern void ctl_set_boolean(char *identifier, boolean value);
 
224
extern void ctl_set_string(char *identifier, char *value);
 
225
extern void ctl_set_vector3(char *identifier, vector3 value);
 
226
extern void ctl_set_matrix3x3(char *identifier, matrix3x3 value);
 
227
extern void ctl_set_cvector3(char *identifier, cvector3 value);
 
228
extern void ctl_set_cmatrix3x3(char *identifier, cmatrix3x3 value);
 
229
extern void ctl_set_list(char *identifier, list value);
 
230
extern void ctl_set_object(char *identifier, object value);
 
231
extern void ctl_set_function(char *identifier, function value);
 
232
extern void ctl_set_SCM(char *identifier, SCM value);
 
233
 
 
234
/**************************************************************************/
 
235
 
 
236
  /* list traversal */
 
237
 
 
238
extern int list_length(list l);
 
239
extern integer integer_list_ref(list l, int index);
 
240
extern number number_list_ref(list l, int index);
 
241
extern cnumber cnumber_list_ref(list l, int index);
 
242
extern boolean boolean_list_ref(list l, int index);
 
243
extern char* string_list_ref(list l, int index);
 
244
extern vector3 vector3_list_ref(list l, int index);
 
245
extern matrix3x3 matrix3x3_list_ref(list l, int index);
 
246
extern cvector3 cvector3_list_ref(list l, int index);
 
247
extern cmatrix3x3 cmatrix3x3_list_ref(list l, int index);
 
248
extern list list_list_ref(list l, int index);
 
249
extern object object_list_ref(list l, int index);
 
250
extern function function_list_ref(list l, int index);
 
251
extern SCM SCM_list_ref(list l, int index);
 
252
 
 
253
/**************************************************************************/
 
254
 
 
255
  /* list creation */
 
256
 
 
257
extern list make_integer_list(int num_items, const integer *items);
 
258
extern list make_number_list(int num_items, const number *items);
 
259
extern list make_cnumber_list(int num_items, const cnumber *items);
 
260
extern list make_boolean_list(int num_items, const boolean *items);
 
261
extern list make_string_list(int num_items, const char **items);
 
262
extern list make_vector3_list(int num_items, const vector3 *items);
 
263
extern list make_matrix3x3_list(int num_items, const matrix3x3 *items);
 
264
extern list make_cvector3_list(int num_items, const cvector3 *items);
 
265
extern list make_cmatrix3x3_list(int num_items, const cmatrix3x3 *items);
 
266
extern list make_list_list(int num_items, const list *items);
 
267
extern list make_object_list(int num_items, const object *items);
 
268
extern list make_function_list(int num_items, const function *items);
 
269
extern list make_SCM_list(int num_items, const function *items);
 
270
 
 
271
/**************************************************************************/
 
272
 
 
273
  /* object properties */
 
274
 
 
275
boolean object_is_member(char *type_name, object o);
 
276
 
 
277
extern integer integer_object_property(object o, char *property_name);
 
278
extern number number_object_property(object o, char *property_name);
 
279
extern cnumber cnumber_object_property(object o, char *property_name);
 
280
extern boolean boolean_object_property(object o, char *property_name);
 
281
extern char* string_object_property(object o, char *property_name);
 
282
extern vector3 vector3_object_property(object o, char *property_name);
 
283
extern matrix3x3 matrix3x3_object_property(object o, char *property_name);
 
284
extern cvector3 cvector3_object_property(object o, char *property_name);
 
285
extern cmatrix3x3 cmatrix3x3_object_property(object o, char *property_name);
 
286
extern list list_object_property(object o, char *property_name);
 
287
extern object object_object_property(object o, char *property_name);
 
288
extern function function_object_property(object o, char *property_name);
 
289
extern SCM SCM_object_property(object o, char *property_name);
 
290
 
 
291
/**************************************************************************/
 
292
 
 
293
/* main() hook functions.  These are prototypes of functions
 
294
   defined by the USER and called just before the program starts
 
295
   and just before it ends, respectively.  If you want to define
 
296
   them, you should also define HAVE_CTL_HOOKS when compiling main.c.
 
297
   
 
298
   Note that due to the behavior of the Guile interactive mode, 
 
299
   ctl_stop_hook will only get called in non-interactive mode.  Sigh. */
 
300
 
 
301
extern void ctl_start_hook(int *argc, char ***argv);
 
302
extern void ctl_stop_hook(void);
 
303
 
 
304
/**************************************************************************/
 
305
 
 
306
  /* subplex multi-dimensional minimization routines: */
 
307
 
 
308
typedef number (*multivar_func) (integer, number *, void *);
 
309
 
 
310
extern number subplex(multivar_func f, number *x, integer n, void *fdata,
 
311
                      number tol, integer maxnfe,       
 
312
                      number fmin, boolean use_fmin,
 
313
                      number *scale,    
 
314
                      integer *nfe, integer *errflag);
 
315
extern SCM subplex_scm(SCM f_scm, SCM x_scm,
 
316
                       SCM tol_scm, SCM maxnfe_scm,
 
317
                       SCM fmin_scm, SCM use_fmin_scm,
 
318
                       SCM scale_scm);
 
319
 
 
320
  /* multi-dimensional integration routines */
 
321
 
 
322
extern number adaptive_integration(multivar_func f, number *xmin, number *xmax,
 
323
                                   integer n, void *fdata, 
 
324
                                   number abstol, number reltol, 
 
325
                                   integer maxnfe, 
 
326
                                   number *esterr, integer *errflag);
 
327
 
 
328
extern SCM adaptive_integration_scm(SCM f_scm, SCM xmin_scm, SCM xmax_scm,
 
329
                                    SCM abstol_scm, SCM reltol_scm, SCM maxnfe_scm);
 
330
 
 
331
#ifdef CTL_HAS_COMPLEX_INTEGRATION
 
332
 
 
333
typedef cnumber (*cmultivar_func) (integer, number *, void *);
 
334
 
 
335
extern cnumber cadaptive_integration(cmultivar_func f, number *xmin, number *xmax,
 
336
                                     integer n, void *fdata, 
 
337
                                     number abstol, number reltol,
 
338
                                     integer maxnfe, 
 
339
                                     number *esterr, integer *errflag);
 
340
 
 
341
extern SCM cadaptive_integration_scm(SCM f_scm, SCM xmin_scm, SCM xmax_scm,
 
342
                                     SCM abstol_scm, SCM reltol_scm, SCM maxnfe_scm);
 
343
 
 
344
#endif /* CTL_HAS_COMPLEX_INTEGRATION */
 
345
 
 
346
/**************************************************************************/
 
347
 
 
348
#ifdef __cplusplus
 
349
           }                               /* extern "C" */
 
350
#endif                          /* __cplusplus */
 
351
 
 
352
#endif /* CTL_H */