Reputation: 2594
I need to use the GNU-GSL interpolation function, that looks like this:
double gsl_interp_eval (const gsl_interp * interp, const double xa[], const double ya[], double x, gsl_interp_accel * acc)
But the xa[] and ya[] arrays that I need are the elements A.x and A.y.value described by these objects:
class c_ys {
double value;
};
struct s_points {
double x;
c_ys y;
};
class c_curves {
vector<s_points> A;
};
How can I use these elements as second and third arguments in the function gsl_interp_eval?
Upvotes: 1
Views: 71
Reputation: 726479
You wouldn't be able to do it without making copies, because the offsets in memory between the double
members is not correct.
Here is how you can do it:
double *x = new double[A.size()];
double *y = new double[A.size()];
for (int i = 0 ; i != A.size() ; i++) {
x[i] = A[i].x;
y[i] = A[i].y.value;
}
gsl_interp_eval(...); // call your function
delete[] x;
delete[] y;
Upvotes: 2