1 /* interpolation/gsl_interp.h
3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 2004 Gerard Jungman
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 #ifndef __GSL_INTERP_H__
23 #define __GSL_INTERP_H__
25 #include <gsl/gsl_types.h>
30 # define __BEGIN_DECLS extern "C" {
31 # define __END_DECLS }
33 # define __BEGIN_DECLS /* empty */
34 # define __END_DECLS /* empty */
39 /* evaluation accelerator */
41 size_t cache; /* cache of index */
42 size_t miss_count; /* keep statistics */
48 /* interpolation object type */
51 unsigned int min_size;
52 void * (*alloc) (size_t size);
53 int (*init) (void *, const double xa[], const double ya[], size_t size);
54 int (*eval) (const void *, const double xa[], const double ya[], size_t size, double x, gsl_interp_accel *, double * y);
55 int (*eval_deriv) (const void *, const double xa[], const double ya[], size_t size, double x, gsl_interp_accel *, double * y_p);
56 int (*eval_deriv2) (const void *, const double xa[], const double ya[], size_t size, double x, gsl_interp_accel *, double * y_pp);
57 int (*eval_integ) (const void *, const double xa[], const double ya[], size_t size, gsl_interp_accel *, double a, double b, double * result);
58 void (*free) (void *);
63 /* general interpolation object */
65 const gsl_interp_type * type;
74 GSL_VAR const gsl_interp_type * gsl_interp_linear;
75 GSL_VAR const gsl_interp_type * gsl_interp_polynomial;
76 GSL_VAR const gsl_interp_type * gsl_interp_cspline;
77 GSL_VAR const gsl_interp_type * gsl_interp_cspline_periodic;
78 GSL_VAR const gsl_interp_type * gsl_interp_akima;
79 GSL_VAR const gsl_interp_type * gsl_interp_akima_periodic;
82 gsl_interp_accel_alloc(void);
85 gsl_interp_accel_find(gsl_interp_accel * a, const double x_array[], size_t size, double x);
88 gsl_interp_accel_reset (gsl_interp_accel * a);
91 gsl_interp_accel_free(gsl_interp_accel * a);
94 gsl_interp_alloc(const gsl_interp_type * T, size_t n);
97 gsl_interp_init(gsl_interp * obj, const double xa[], const double ya[], size_t size);
99 const char * gsl_interp_name(const gsl_interp * interp);
100 unsigned int gsl_interp_min_size(const gsl_interp * interp);
104 gsl_interp_eval_e(const gsl_interp * obj,
105 const double xa[], const double ya[], double x,
106 gsl_interp_accel * a, double * y);
109 gsl_interp_eval(const gsl_interp * obj,
110 const double xa[], const double ya[], double x,
111 gsl_interp_accel * a);
114 gsl_interp_eval_deriv_e(const gsl_interp * obj,
115 const double xa[], const double ya[], double x,
116 gsl_interp_accel * a,
120 gsl_interp_eval_deriv(const gsl_interp * obj,
121 const double xa[], const double ya[], double x,
122 gsl_interp_accel * a);
125 gsl_interp_eval_deriv2_e(const gsl_interp * obj,
126 const double xa[], const double ya[], double x,
127 gsl_interp_accel * a,
131 gsl_interp_eval_deriv2(const gsl_interp * obj,
132 const double xa[], const double ya[], double x,
133 gsl_interp_accel * a);
136 gsl_interp_eval_integ_e(const gsl_interp * obj,
137 const double xa[], const double ya[],
139 gsl_interp_accel * acc,
143 gsl_interp_eval_integ(const gsl_interp * obj,
144 const double xa[], const double ya[],
146 gsl_interp_accel * acc);
149 gsl_interp_free(gsl_interp * interp);
151 size_t gsl_interp_bsearch(const double x_array[], double x,
152 size_t index_lo, size_t index_hi);
156 gsl_interp_bsearch(const double x_array[], double x,
157 size_t index_lo, size_t index_hi);
160 gsl_interp_bsearch(const double x_array[], double x,
161 size_t index_lo, size_t index_hi)
163 size_t ilo = index_lo;
164 size_t ihi = index_hi;
165 while(ihi > ilo + 1) {
166 size_t i = (ihi + ilo)/2;
179 gsl_interp_accel_find(gsl_interp_accel * a, const double xa[], size_t len, double x)
181 size_t x_index = a->cache;
183 if(x < xa[x_index]) {
185 a->cache = gsl_interp_bsearch(xa, x, 0, x_index);
187 else if(x > xa[x_index + 1]) {
189 a->cache = gsl_interp_bsearch(xa, x, x_index, len-1);
197 #endif /* HAVE_INLINE */
202 #endif /* __GSL_INTERP_H__ */