Dear Ladies and Gentlemen,finally I succeeded in writing a (hopefully modern) wrapper around the interpolated data set and pass it to the GSL integration method.
Maybe it helps others.
Kind regards and have a nice weekend,
Klaus Huthmacher.
#include <gsl/gsl_integration.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_spline.h>
#include <iostream>
#include <memory>
#include <vector>
class parameters
{
public:
parameters();
double get(double);
private:
std::vector<double> x, y;
std::unique_ptr<gsl_interp_accel,void(*)(gsl_interp_accel*)> acc;
std::unique_ptr<gsl_spline,void(*)(gsl_spline*)> spline;
};
/*
---{}--- constructor ---{}---
*/
parameters::parameters():
x({{0.0,1.0,2.0}}),y({{0.0,1.0,2.0}}),
acc(gsl_interp_accel_alloc(),gsl_interp_accel_free),
spline(gsl_spline_alloc(gsl_interp_cspline,x.size()),gsl_spline_free)
{
gsl_spline_init(spline.get(),x.data(),y.data(),x.size());
}
/*
---{}--- parameters::get ---{}---
*/
auto parameters::get(double x) -> double
{
return gsl_spline_eval(spline.get(),x,acc.get());
}
/*
---{}--- gsl function ---{}---
*/
double function(double x, void* ptr)
{
parameters* params = static_cast<parameters*>(ptr);
return params->get(x);
}
int main()
{
parameters params;
gsl_function F;
F.function = &function;
F.params = ¶ms;
double result, error;
std::unique_ptr<gsl_integration_workspace,void(*)(gsl_integration_workspace*)>
w(gsl_integration_workspace_alloc(1000),gsl_integration_workspace_free);
gsl_integration_qags(&F,0,2,0,1.0e-7,1000,w.get(),&result,&error);
std::cout << result << std::endl;
return 0;
}
<<attachment: huthmacher.vcf>>
