chiark / gitweb /
Use trusty
[nlopt.git] / api / f77api.c
index 193d50e1835cb939a2c364fb90775b598ad54eb7..e753c86ae84dc7e0549a89eb75ddff9e59df13a2 100644 (file)
@@ -1,4 +1,4 @@
-/* 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
@@ -32,8 +32,14 @@ typedef void (*nlopt_f77_func)(double *val, const int *n, const double *x,
                               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;
 
@@ -63,6 +69,15 @@ static double f77_func_wrap(unsigned n, const double *x, double *grad, void *dat
      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); }
@@ -81,6 +96,8 @@ static double f77_func_wrap(unsigned n, const double *x, double *grad, void *dat
    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"
@@ -106,5 +123,7 @@ static double f77_func_wrap(unsigned n, const double *x, double *grad, void *dat
        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"