chiark / gitweb /
untabify source files, make indenting more uniform with GNU indent -kr --no-tabs...
[nlopt.git] / src / api / f77funcs_.h
1 /* Copyright (c) 2007-2014 Massachusetts Institute of Technology
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining
4  * a copy of this software and associated documentation files (the
5  * "Software"), to deal in the Software without restriction, including
6  * without limitation the rights to use, copy, modify, merge, publish,
7  * distribute, sublicense, and/or sell copies of the Software, and to
8  * permit persons to whom the Software is furnished to do so, subject to
9  * the following conditions:
10  * 
11  * The above copyright notice and this permission notice shall be
12  * included in all copies or substantial portions of the Software.
13  * 
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
21  */
22
23 /* Fortran API wrappers, using the F77 macro defined in f77api.c.
24    This header file is #included one or more times from f77api.c
25    in order to define verions of the Fortran API for various compilers. 
26
27    All of the functions in this file have underscores in their names,
28    which means that they are treated differently for name-mangling
29    (thank you, g77 and f2c) than names without underscores.
30    
31    The return value of a function is converted to the first argument
32    of a subroutine. */
33
34 void F77_(nlo_create, NLO_CREATE) (nlopt_opt * opt, int *alg, int *n) {
35     if (*n < 0)
36         *opt = NULL;
37     else {
38         *opt = nlopt_create((nlopt_algorithm) * alg, (unsigned) *n);
39         nlopt_set_munge(*opt, free_f77_func_data, dup_f77_func_data);
40     }
41 }
42
43 void F77_(nlo_copy, NLO_COPY) (nlopt_opt * nopt, nlopt_opt * opt) {
44     *nopt = nlopt_copy(*opt);
45 }
46
47 void F77_(nlo_destroy, NLO_DESTROY) (nlopt_opt * opt) {
48     nlopt_destroy(*opt);
49 }
50
51 void F77_(nlo_optimize, NLO_OPTIMIZE) (int *ret, nlopt_opt * opt, double *x, double *optf) {
52     *ret = (int) nlopt_optimize(*opt, x, optf);
53 }
54
55 void F77_(nlo_set_min_objective, NLO_SET_MIN_OBJECTIVE) (int *ret, nlopt_opt * opt, nlopt_f77_func f, void *f_data) {
56     f77_func_data *d = (f77_func_data *) malloc(sizeof(f77_func_data));
57     if (!d) {
58         *ret = (int) NLOPT_OUT_OF_MEMORY;
59         return;
60     }
61     d->f = f;
62     d->f_data = f_data;
63     *ret = (int) nlopt_set_min_objective(*opt, f77_func_wrap, d);
64 }
65
66 void F77_(nlo_set_max_objective, NLO_SET_MAX_OBJECTIVE) (int *ret, nlopt_opt * opt, nlopt_f77_func f, void *f_data) {
67     f77_func_data *d = (f77_func_data *) malloc(sizeof(f77_func_data));
68     if (!d) {
69         *ret = (int) NLOPT_OUT_OF_MEMORY;
70         return;
71     }
72     d->f = f;
73     d->f_data = f_data;
74     *ret = (int) nlopt_set_max_objective(*opt, f77_func_wrap, d);
75 }
76
77 F77_GET(algorithm, ALGORITHM, int) F77_GET(dimension, DIMENSION, int)
78  F77_GETSETA(lower_bounds, LOWER_BOUNDS, double) F77_GETSETA(upper_bounds, UPPER_BOUNDS, double)
79
80 void F77_(nlo_remove_inequality_constraints, NLO_REMOVE_INEQUALITY_CONSTRAINTS) (int *ret, nlopt_opt * opt)
81 {
82     *ret = (int) nlopt_remove_inequality_constraints(*opt);
83 }
84
85 void F77_(nlo_add_inequality_constraint, NLO_ADD_INEQUALITY_CONSTRAINT) (int *ret, nlopt_opt * opt, nlopt_f77_func fc, void *fc_data, double *tol) {
86     f77_func_data *d = (f77_func_data *) malloc(sizeof(f77_func_data));
87     if (!d) {
88         *ret = (int) NLOPT_OUT_OF_MEMORY;
89         return;
90     }
91     d->f = fc;
92     d->f_data = fc_data;
93     *ret = (int) nlopt_add_inequality_constraint(*opt, f77_func_wrap, d, *tol);
94 }
95
96 void F77_(nlo_add_inequality_mconstraint, NLO_ADD_INEQUALITY_MCONSTRAINT) (int *ret, nlopt_opt * opt, int *m, nlopt_f77_mfunc mfc, void *mfc_data, double *tol) {
97     f77_func_data *d;
98     if (*m < 0) {
99         *ret = (int) NLOPT_INVALID_ARGS;
100         return;
101     }
102     if (*m == 0) {
103         *ret = (int) NLOPT_SUCCESS;
104         return;
105     }
106     d = (f77_func_data *) malloc(sizeof(f77_func_data));
107     if (!d) {
108         *ret = (int) NLOPT_OUT_OF_MEMORY;
109         return;
110     }
111     d->mf = mfc;
112     d->f_data = mfc_data;
113     *ret = (int) nlopt_add_inequality_mconstraint(*opt, (unsigned) *m, f77_mfunc_wrap, d, tol);
114 }
115
116 void F77_(nlo_remove_equality_constraints, NLO_REMOVE_EQUALITY_CONSTRAINTS) (int *ret, nlopt_opt * opt) {
117     *ret = (int) nlopt_remove_equality_constraints(*opt);
118 }
119
120 void F77_(nlo_add_equality_constraint, NLO_ADD_EQUALITY_CONSTRAINT) (int *ret, nlopt_opt * opt, nlopt_f77_func fc, void *fc_data, double *tol) {
121     f77_func_data *d = (f77_func_data *) malloc(sizeof(f77_func_data));
122     if (!d) {
123         *ret = (int) NLOPT_OUT_OF_MEMORY;
124         return;
125     }
126     d->f = fc;
127     d->f_data = fc_data;
128     *ret = (int) nlopt_add_equality_constraint(*opt, f77_func_wrap, d, *tol);
129 }
130
131 void F77_(nlo_add_equality_mconstraint, NLO_ADD_EQUALITY_MCONSTRAINT) (int *ret, nlopt_opt * opt, int *m, nlopt_f77_mfunc mfc, void *mfc_data, double *tol) {
132     f77_func_data *d;
133     if (*m < 0) {
134         *ret = (int) NLOPT_INVALID_ARGS;
135         return;
136     }
137     if (*m == 0) {
138         *ret = (int) NLOPT_SUCCESS;
139         return;
140     }
141     d = (f77_func_data *) malloc(sizeof(f77_func_data));
142     if (!d) {
143         *ret = (int) NLOPT_OUT_OF_MEMORY;
144         return;
145     }
146     d->mf = mfc;
147     d->f_data = mfc_data;
148     *ret = (int) nlopt_add_equality_mconstraint(*opt, (unsigned) *m, f77_mfunc_wrap, d, tol);
149 }
150
151 F77_GETSET(stopval, STOPVAL, double)
152 F77_GETSET(ftol_rel, FTOL_REL, double)
153 F77_GETSET(ftol_abs, FTOL_ABS, double)
154 F77_GETSET(xtol_rel, XTOL_REL, double) F77_GETSETA(xtol_abs, XTOL_ABS, double) F77_GETSET(maxeval, MAXEVAL, int) F77_GET(numevals, NUMEVALS, int) F77_GETSET(maxtime, MAXTIME, double)
155  F77_GETSET(force_stop, FORCE_STOP, int)
156 void F77_(nlo_force_stop, NLO_FORCE_STOP) (int *ret, nlopt_opt * opt)
157 {
158     *ret = (int) nlopt_force_stop(*opt);
159 }
160
161 F77_SET(local_optimizer, LOCAL_OPTIMIZER, nlopt_opt)
162 F77_GETSET(population, POPULATION, unsigned) F77_GETSET(vector_storage, vector_storage, unsigned)
163  F77_SETA(default_initial_step, DEFAULT_INITIAL_STEP, double) F77_SETA(initial_step, INITIAL_STEP, double) F77_SET(initial_step1, INITIAL_STEP1, double)
164 void F77_(nlo_get_initial_step, NLO_GET_INITIAL_STEP) (int *ret, nlopt_opt * opt, const double *x, double *dx)
165 {
166     *ret = (int) nlopt_get_initial_step(*opt, x, dx);
167 }