cspline.cpp
1 /***************************************************************************
2  Copyright (C) 2002-2015 Kentaro Kitagawa
3  kitagawa@phys.s.u-tokyo.ac.jp
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  You should have received a copy of the GNU Library General
11  Public License and a list of authors along with this program;
12  see the files COPYING and AUTHORS.
13 ***************************************************************************/
14 #include "cspline.h"
15 #include <vector>
16 
17 CSplineApprox::CSplineApprox(const std::map<double, double> &pts) {
18  m_accel = gsl_interp_accel_alloc();
19  m_spline = gsl_spline_alloc(gsl_interp_cspline, pts.size());
20 
21  std::vector<double> x, y;
22  for(auto it = pts.begin(); it != pts.end(); it++) {
23  x.push_back(it->first);
24  y.push_back(it->second);
25  }
26  gsl_spline_init(m_spline, &x[0], &y[0], x.size());
27 }
28 
29 CSplineApprox::~CSplineApprox() {
30  gsl_spline_free(m_spline);
31  gsl_interp_accel_free(m_accel);
32 }
33 double
34 CSplineApprox::approx(double x) const {
35  return gsl_spline_eval(m_spline, x, m_accel);
36 }

Generated for KAME4 by  doxygen 1.8.3