Dear All,
I'm trying to wrap a C library (LSODA https://github.com/sdwfrost/liblsoda) in Nim. In C, one has a typedef for a function to be passed
typedef int (*_lsoda_f) (double, double *, double *, void *);
An example of this is below:
int fex(double t, double *y, double *ydot, void *data)
{
ydot[0] = 1.0E4 * y[1] * y[2] - .04E0 * y[0];
ydot[2] = 3.0E7 * y[1] * y[1];
ydot[1] = -1.0 * (ydot[0] + ydot[2]);
return(0);
}
This modifies the ydot array in-place.
This function is then used in a struct
struct lsoda_context_t {
_lsoda_f function;
void * data;
int neq;
int state;
char * error;
/* private for lsoda */
struct lsoda_common_t * common;
struct lsoda_opt_t * opt;
};
C2Nim generates some stubs, but I'm having problems with passing arrays to C.
var atol: array[3,cdouble]
atol = [0.001,0.001,0.001]
If I want to pass atol as a double*, is the following ok
addr(atol[0])
or am I thinking too C-like?
Also, any hints on how to rewrite the function to be passed in Nim would be great.
The C test program is here: https://github.com/sdwfrost/liblsoda/blob/master/test/test.c
Best,
Simon