diff options
author | Alberto Ruiz <aruiz@um.es> | 2015-04-27 10:52:59 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2015-04-27 10:52:59 +0200 |
commit | 5e845013180e8f86dd8153030d5f5ea13826497d (patch) | |
tree | 52df8c1e8dda157896d4884bbd0dbfb439132d21 /packages/gsl/src/Numeric/GSL/gsl-aux.c | |
parent | e282d2b4c5f389941225d02df94e7baf38c4f38e (diff) | |
parent | a25d6f45d7131bd86508f82870d2e24606a811e8 (diff) |
Merge pull request #122 from peddie/master
Add a new module containing the GSL interpolation interface
Diffstat (limited to 'packages/gsl/src/Numeric/GSL/gsl-aux.c')
-rw-r--r-- | packages/gsl/src/Numeric/GSL/gsl-aux.c | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/packages/gsl/src/Numeric/GSL/gsl-aux.c b/packages/gsl/src/Numeric/GSL/gsl-aux.c index ffc5c20..e1b189c 100644 --- a/packages/gsl/src/Numeric/GSL/gsl-aux.c +++ b/packages/gsl/src/Numeric/GSL/gsl-aux.c | |||
@@ -34,6 +34,7 @@ | |||
34 | #include <gsl/gsl_rng.h> | 34 | #include <gsl/gsl_rng.h> |
35 | #include <gsl/gsl_randist.h> | 35 | #include <gsl/gsl_randist.h> |
36 | #include <gsl/gsl_roots.h> | 36 | #include <gsl/gsl_roots.h> |
37 | #include <gsl/gsl_spline.h> | ||
37 | #include <gsl/gsl_multifit_nlin.h> | 38 | #include <gsl/gsl_multifit_nlin.h> |
38 | #include <string.h> | 39 | #include <string.h> |
39 | #include <stdio.h> | 40 | #include <stdio.h> |
@@ -140,6 +141,117 @@ int deriv(int code, double f(double, void*), double x, double h, double * result | |||
140 | return 0; | 141 | return 0; |
141 | } | 142 | } |
142 | 143 | ||
144 | int spline_eval(const double xa[], const double ya[], unsigned int size, | ||
145 | double x, int method, double *y) { | ||
146 | DEBUGMSG("spline_eval"); | ||
147 | const gsl_interp_type *T; | ||
148 | switch (method) { | ||
149 | case 0: { T = gsl_interp_linear; break; } | ||
150 | case 1: { T = gsl_interp_polynomial; break; } | ||
151 | case 2: { T = gsl_interp_cspline; break; } | ||
152 | case 3: { T = gsl_interp_cspline_periodic; break; } | ||
153 | case 4: { T = gsl_interp_akima; break; } | ||
154 | case 5: { T = gsl_interp_akima_periodic; break; } | ||
155 | default: ERROR(BAD_CODE); | ||
156 | } | ||
157 | |||
158 | gsl_spline *spline = gsl_spline_alloc(T, size); | ||
159 | if (NULL == spline) ERROR(MEM); | ||
160 | const int initres = gsl_spline_init(spline, xa, ya, size); | ||
161 | CHECK(initres,initres); | ||
162 | gsl_interp_accel *acc = gsl_interp_accel_alloc(); | ||
163 | if (NULL == acc) { gsl_spline_free(spline); ERROR(MEM); }; | ||
164 | |||
165 | const int res = gsl_spline_eval_e(spline, x, acc, y); | ||
166 | CHECK(res,res); | ||
167 | gsl_interp_accel_free(acc); | ||
168 | gsl_spline_free(spline); | ||
169 | OK | ||
170 | } | ||
171 | |||
172 | int spline_eval_deriv(const double xa[], const double ya[], unsigned int size, | ||
173 | double x, int method, double *y) { | ||
174 | DEBUGMSG("spline_eval_deriv"); | ||
175 | const gsl_interp_type *T; | ||
176 | switch (method) { | ||
177 | case 0: { T = gsl_interp_linear; break; } | ||
178 | case 1: { T = gsl_interp_polynomial; break; } | ||
179 | case 2: { T = gsl_interp_cspline; break; } | ||
180 | case 3: { T = gsl_interp_cspline_periodic; break; } | ||
181 | case 4: { T = gsl_interp_akima; break; } | ||
182 | case 5: { T = gsl_interp_akima_periodic; break; } | ||
183 | default: ERROR(BAD_CODE); | ||
184 | } | ||
185 | |||
186 | gsl_spline *spline = gsl_spline_alloc(T, size); | ||
187 | if (NULL == spline) ERROR(MEM); | ||
188 | const int initres = gsl_spline_init(spline, xa, ya, size); | ||
189 | CHECK(initres,initres); | ||
190 | gsl_interp_accel *acc = gsl_interp_accel_alloc(); | ||
191 | if (NULL == acc) { gsl_spline_free(spline); ERROR(MEM); }; | ||
192 | |||
193 | const int res = gsl_spline_eval_deriv_e(spline, x, acc, y); | ||
194 | CHECK(res,res); | ||
195 | gsl_interp_accel_free(acc); | ||
196 | gsl_spline_free(spline); | ||
197 | OK | ||
198 | } | ||
199 | |||
200 | int spline_eval_deriv2(const double xa[], const double ya[], unsigned int size, | ||
201 | double x, int method, double *y) { | ||
202 | DEBUGMSG("spline_eval_deriv2"); | ||
203 | const gsl_interp_type *T; | ||
204 | switch (method) { | ||
205 | case 0: { T = gsl_interp_linear; break; } | ||
206 | case 1: { T = gsl_interp_polynomial; break; } | ||
207 | case 2: { T = gsl_interp_cspline; break; } | ||
208 | case 3: { T = gsl_interp_cspline_periodic; break; } | ||
209 | case 4: { T = gsl_interp_akima; break; } | ||
210 | case 5: { T = gsl_interp_akima_periodic; break; } | ||
211 | default: ERROR(BAD_CODE); | ||
212 | } | ||
213 | |||
214 | gsl_spline *spline = gsl_spline_alloc(T, size); | ||
215 | if (NULL == spline) ERROR(MEM); | ||
216 | const int initres = gsl_spline_init(spline, xa, ya, size); | ||
217 | CHECK(initres,initres); | ||
218 | gsl_interp_accel *acc = gsl_interp_accel_alloc(); | ||
219 | if (NULL == acc) { gsl_spline_free(spline); ERROR(MEM); }; | ||
220 | |||
221 | const int res = gsl_spline_eval_deriv2_e(spline, x, acc, y); | ||
222 | CHECK(res,res); | ||
223 | gsl_interp_accel_free(acc); | ||
224 | gsl_spline_free(spline); | ||
225 | OK | ||
226 | } | ||
227 | |||
228 | int spline_eval_integ(const double xa[], const double ya[], unsigned int size, | ||
229 | double a, double b, int method, double *y) { | ||
230 | DEBUGMSG("spline_eval_integ"); | ||
231 | const gsl_interp_type *T; | ||
232 | switch (method) { | ||
233 | case 0: { T = gsl_interp_linear; break; } | ||
234 | case 1: { T = gsl_interp_polynomial; break; } | ||
235 | case 2: { T = gsl_interp_cspline; break; } | ||
236 | case 3: { T = gsl_interp_cspline_periodic; break; } | ||
237 | case 4: { T = gsl_interp_akima; break; } | ||
238 | case 5: { T = gsl_interp_akima_periodic; break; } | ||
239 | default: ERROR(BAD_CODE); | ||
240 | } | ||
241 | |||
242 | gsl_spline *spline = gsl_spline_alloc(T, size); | ||
243 | if (NULL == spline) ERROR(MEM); | ||
244 | const int initres = gsl_spline_init(spline, xa, ya, size); | ||
245 | CHECK(initres,initres); | ||
246 | gsl_interp_accel *acc = gsl_interp_accel_alloc(); | ||
247 | if (NULL == acc) { gsl_spline_free(spline); ERROR(MEM); }; | ||
248 | |||
249 | const int res = gsl_spline_eval_integ_e(spline, a, b, acc, y); | ||
250 | CHECK(res,res); | ||
251 | gsl_interp_accel_free(acc); | ||
252 | gsl_spline_free(spline); | ||
253 | OK | ||
254 | } | ||
143 | 255 | ||
144 | int integrate_qng(double f(double, void*), double a, double b, double aprec, double prec, | 256 | int integrate_qng(double f(double, void*), double a, double b, double aprec, double prec, |
145 | double *result, double*error) { | 257 | double *result, double*error) { |