1 /* interpolation/spline.c
3 * Copyright (C) 2001, 2007 Brian Gough
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include <gsl/gsl_errno.h>
23 #include <gsl/gsl_interp.h>
24 #include <gsl/gsl_spline.h>
27 gsl_spline_alloc (const gsl_interp_type * T, size_t size)
29 gsl_spline * spline = (gsl_spline *) malloc (sizeof(gsl_spline));
33 GSL_ERROR_NULL ("failed to allocate space for spline struct",
37 spline->interp = gsl_interp_alloc (T, size);
39 if (spline->interp == NULL)
42 GSL_ERROR_NULL ("failed to allocate space for interp", GSL_ENOMEM);
45 spline->x = (double *) malloc (size * sizeof(double));
47 if (spline->x == NULL)
49 gsl_interp_free(spline->interp);
51 GSL_ERROR_NULL ("failed to allocate space for x", GSL_ENOMEM);
54 spline->y = (double *) malloc (size * sizeof(double));
56 if (spline->y == NULL)
59 gsl_interp_free(spline->interp);
61 GSL_ERROR_NULL ("failed to allocate space for y", GSL_ENOMEM);
70 gsl_spline_init (gsl_spline * spline, const double x_array[], const double y_array[], size_t size)
72 if (size != spline->size)
74 GSL_ERROR ("data must match size of spline object", GSL_EINVAL);
77 memcpy (spline->x, x_array, size * sizeof(double));
78 memcpy (spline->y, y_array, size * sizeof(double));
81 int status = gsl_interp_init (spline->interp, x_array, y_array, size);
87 gsl_spline_name(const gsl_spline * spline)
89 return gsl_interp_name(spline->interp);
93 gsl_spline_min_size(const gsl_spline * spline)
95 return gsl_interp_min_size(spline->interp);
99 gsl_spline_free (gsl_spline * spline)
101 gsl_interp_free (spline->interp);
108 gsl_spline_eval_e (const gsl_spline * spline,
110 gsl_interp_accel * a, double *y)
112 return gsl_interp_eval_e (spline->interp,
113 spline->x, spline->y,
118 gsl_spline_eval (const gsl_spline * spline,
120 gsl_interp_accel * a)
122 return gsl_interp_eval (spline->interp,
123 spline->x, spline->y,
129 gsl_spline_eval_deriv_e (const gsl_spline * spline,
131 gsl_interp_accel * a,
134 return gsl_interp_eval_deriv_e (spline->interp,
135 spline->x, spline->y,
140 gsl_spline_eval_deriv (const gsl_spline * spline,
142 gsl_interp_accel * a)
144 return gsl_interp_eval_deriv (spline->interp,
145 spline->x, spline->y,
151 gsl_spline_eval_deriv2_e (const gsl_spline * spline,
153 gsl_interp_accel * a,
156 return gsl_interp_eval_deriv2_e (spline->interp,
157 spline->x, spline->y,
162 gsl_spline_eval_deriv2 (const gsl_spline * spline,
164 gsl_interp_accel * a)
166 return gsl_interp_eval_deriv2 (spline->interp,
167 spline->x, spline->y,
173 gsl_spline_eval_integ_e (const gsl_spline * spline,
175 gsl_interp_accel * acc,
178 return gsl_interp_eval_integ_e (spline->interp,
179 spline->x, spline->y,
185 gsl_spline_eval_integ (const gsl_spline * spline,
187 gsl_interp_accel * acc)
189 return gsl_interp_eval_integ (spline->interp,
190 spline->x, spline->y,