-/* Copyright (c) 2007-2010 Massachusetts Institute of Technology
+/* Copyright (c) 2007-2014 Massachusetts Institute of Technology
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
*/
#include <stdlib.h>
+#include <string.h>
#include "nlopt.h"
double *gradient, const int *need_gradient,
void *func_data);
+typedef void (*nlopt_f77_mfunc)(const int *m,
+ double *val, const int *n, const double *x,
+ double *gradient, const int *need_gradient,
+ void *func_data);
+
typedef struct {
nlopt_f77_func f;
+ nlopt_f77_mfunc mf;
void *f_data;
} f77_func_data;
return val;
}
+static void f77_mfunc_wrap(unsigned m, double *result, unsigned n, const double *x, double *grad, void *data)
+{
+ f77_func_data *d = (f77_func_data *) data;
+ int mi = (int) m;
+ int ni = (int) n;
+ int need_gradient = grad != 0;
+ d->mf(&mi, result, &ni, x, grad, &need_gradient, d->f_data);
+}
+
/*-----------------------------------------------------------------------*/
#define F77_GET(name,NAME,T) void F77_(nlo_get_##name,NLO_GET_##NAME)(T *val, nlopt_opt *opt) { *val = (T) nlopt_get_##name(*opt); }
#define F77_SET(name,NAME,T) void F77_(nlo_set_##name,NLO_SET_##NAME)(int *ret, nlopt_opt *opt, T *val) { *ret = (int) nlopt_set_##name(*opt, *val); }
#define F77_GETSET(name,NAME,T) F77_GET(name,NAME,T) F77_SET(name,NAME,T)
-#define F77_GETA(name,NAME,T) void F77_(nlo_get_##name,NLO_GET_##NAME)(int *ret, T *val, nlopt_opt *opt) { *ret = (int) nlopt_get_##name(*opt, val); }
+#define F77_GETA(name,NAME,T) void F77_(nlo_get_##name,NLO_GET_##NAME)(int *ret, nlopt_opt *opt, T *val) { *ret = (int) nlopt_get_##name(*opt, val); }
#define F77_SETA(name,NAME,T) void F77_(nlo_set_##name,NLO_SET_##NAME)(int *ret, nlopt_opt *opt, T *val) { *ret = (int) nlopt_set_##name(*opt, val); }
#define F77_GETSETA(name,NAME,T) F77_GETA(name,NAME,T) F77_SETA(name,NAME,T) F77_SET(name##1,NAME##1,T)
wrapper functions are so small, the library bloat of including them
multiple times is negligible and seems well worth the benefit. */
+# define F77CALL(a, A) F77(a, A)
+
/* name + underscore is by far the most common (gfortran, g77, Intel, ...) */
# define F77(a, A) a ## _
# include "f77funcs.h"
http://msdn.microsoft.com/library/en-us/vccore98/html/_core_mixed.2d.language_programming.3a_.overview.asp
*/
# undef F77
+# undef F77CALL
# define F77(a, A) NLOPT_STDCALL A
+# define F77CALL(a, A) A
# include "f77funcs.h"