Added script front-end for primer-design code
[htsworkflow.git] / htswanalysis / MACS / lib / gsl / gsl-1.11 / interpolation / spline.c
1 /* interpolation/spline.c
2  * 
3  * Copyright (C) 2001, 2007 Brian Gough
4  * 
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.
9  * 
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.
14  * 
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.
18  */
19
20 #include <config.h>
21 #include <string.h>
22 #include <gsl/gsl_errno.h>
23 #include <gsl/gsl_interp.h>
24 #include <gsl/gsl_spline.h>
25
26 gsl_spline *
27 gsl_spline_alloc (const gsl_interp_type * T, size_t size)
28 {
29   gsl_spline * spline = (gsl_spline *) malloc (sizeof(gsl_spline));
30   
31   if (spline == NULL)
32     {
33       GSL_ERROR_NULL ("failed to allocate space for spline struct", 
34                       GSL_ENOMEM);
35     }
36   
37   spline->interp = gsl_interp_alloc (T, size);
38   
39   if (spline->interp == NULL)
40     {
41       free (spline);          
42       GSL_ERROR_NULL ("failed to allocate space for interp", GSL_ENOMEM);
43     };
44     
45   spline->x = (double *) malloc (size * sizeof(double));
46
47   if (spline->x == NULL)
48     {
49       gsl_interp_free(spline->interp);
50       free(spline);
51       GSL_ERROR_NULL ("failed to allocate space for x", GSL_ENOMEM);
52     }
53
54   spline->y = (double *) malloc (size * sizeof(double));
55
56   if (spline->y == NULL)
57     {
58       free(spline->x);
59       gsl_interp_free(spline->interp);
60       free(spline);
61       GSL_ERROR_NULL ("failed to allocate space for y", GSL_ENOMEM);
62     }
63   
64   spline->size = size;
65
66   return spline;
67 }
68
69 int
70 gsl_spline_init (gsl_spline * spline, const double x_array[], const double y_array[], size_t size)
71 {
72   if (size != spline->size)
73     {
74       GSL_ERROR ("data must match size of spline object", GSL_EINVAL);
75     }
76   
77   memcpy (spline->x, x_array, size * sizeof(double));
78   memcpy (spline->y, y_array, size * sizeof(double));
79
80   {
81     int status = gsl_interp_init (spline->interp, x_array, y_array, size);
82     return status;
83   }
84 }
85
86 const char *
87 gsl_spline_name(const gsl_spline * spline)
88 {
89   return gsl_interp_name(spline->interp);
90 }
91
92 unsigned int
93 gsl_spline_min_size(const gsl_spline * spline)
94 {
95   return gsl_interp_min_size(spline->interp);
96 }
97
98 void
99 gsl_spline_free (gsl_spline * spline)
100 {
101   gsl_interp_free (spline->interp);
102   free (spline->x);
103   free (spline->y);
104   free (spline);
105 }
106
107 int
108 gsl_spline_eval_e (const gsl_spline * spline, 
109                    double x,
110                    gsl_interp_accel * a, double *y)
111 {
112   return gsl_interp_eval_e (spline->interp, 
113                             spline->x, spline->y,
114                             x, a, y);
115 }
116
117 double
118 gsl_spline_eval (const gsl_spline * spline,
119                  double x,
120                  gsl_interp_accel * a)
121 {
122   return gsl_interp_eval (spline->interp, 
123                           spline->x, spline->y,
124                           x, a);
125 }
126
127
128 int
129 gsl_spline_eval_deriv_e (const gsl_spline * spline,
130                          double x,
131                          gsl_interp_accel * a,
132                          double *dydx)
133 {
134   return gsl_interp_eval_deriv_e (spline->interp, 
135                                   spline->x, spline->y,
136                                   x, a, dydx);
137 }
138
139 double
140 gsl_spline_eval_deriv (const gsl_spline * spline,
141                        double x,
142                        gsl_interp_accel * a)
143 {
144   return gsl_interp_eval_deriv (spline->interp, 
145                                 spline->x, spline->y,
146                                 x, a);
147 }
148
149
150 int
151 gsl_spline_eval_deriv2_e (const gsl_spline * spline,
152                           double x,
153                           gsl_interp_accel * a,
154                           double * d2)
155 {
156   return gsl_interp_eval_deriv2_e (spline->interp, 
157                                    spline->x, spline->y,
158                                    x, a, d2);
159 }
160
161 double
162 gsl_spline_eval_deriv2 (const gsl_spline * spline,
163                         double x,
164                         gsl_interp_accel * a)
165 {
166   return gsl_interp_eval_deriv2 (spline->interp, 
167                                  spline->x, spline->y,
168                                  x, a);
169 }
170
171
172 int
173 gsl_spline_eval_integ_e (const gsl_spline * spline,
174                          double a, double b,
175                          gsl_interp_accel * acc,
176                          double * result)
177 {
178   return gsl_interp_eval_integ_e (spline->interp, 
179                                   spline->x, spline->y,
180                                   a, b, acc, result);
181 }
182
183
184 double
185 gsl_spline_eval_integ (const gsl_spline * spline,
186                        double a, double b,
187                        gsl_interp_accel * acc)
188 {
189   return gsl_interp_eval_integ (spline->interp, 
190                                 spline->x, spline->y,
191                                 a, b, acc);
192 }
193