29 #ifndef gslInterpolation_hpp
30 #define gslInterpolation_hpp
33 #include <gsl/gsl_interp.h>
34 #include <gsl/gsl_errno.h>
36 #include "../mxException.hpp"
60 template<
typename realT>
69 static_assert( std::is_same<
double,
typename std::remove_cv<realT>::type>::value,
"GSL Interpolation only works with double");
71 gsl_set_error_handler_off();
73 gsl_interp * interp = gsl_interp_alloc(interpT, Nin);
76 std::cerr <<
"gsl_interpolate: gsl_interp_alloc failed\n";
80 gsl_interp_accel * acc = gsl_interp_accel_alloc ();
83 std::cerr <<
"gsl_interpolate: gsl_interp_accel_alloc failed\n";
87 int gsl_errno = gsl_interp_init(interp, xin, yin, Nin);
91 std::cerr <<
"gsl_interpolate: error from gsl_interp_init [" << gsl_strerror(gsl_errno) <<
"]\n";
92 gsl_interp_free(interp);
93 gsl_interp_accel_free (acc);
98 for(
size_t i=0;i<Nout; ++i)
101 gsl_errno += gsl_interp_eval_e (interp, xin, yin, xout[i], acc, &yout[i]);
104 gsl_interp_free(interp);
105 gsl_interp_accel_free (acc);
109 std::cerr <<
"gsl_interpolate: error(s) reported by gsl_interp_eval_e\n";
128 template<
typename realT>
130 std::vector<realT> & xin,
131 std::vector<realT> & yin,
132 std::vector<realT> & xout,
133 std::vector<realT> & yout )
135 yout.resize(xout.size());
136 return gsl_interpolate(interpT, xin.data(), yin.data(), xin.size(), xout.data(), yout.data(), xout.size());
int gsl_interpolate(const gsl_interp_type *interpT, std::vector< realT > &xin, std::vector< realT > &yin, std::vector< realT > &xout, std::vector< realT > &yout)
Interpolate a 1-D data X vs Y discrete function onto a new X axis (vector version)