65#include <gsl/gsl_bspline.h>
66#include <gsl/gsl_multifit.h>
67#include <gsl/gsl_rng.h>
68#include <gsl/gsl_randist.h>
69#include <gsl/gsl_statistics.h>
75#define MODULE_ID "XSH_BSPLINE"
84#define NBREAK (NCOEFFS -2)
95 t=cpl_table_load(fname,1,0);
97 w=cpl_table_get_data_double(t,
"WAVE");
98 f=cpl_table_get_data_double(t,
"FLUX");
99 e=cpl_table_get_data_double(t,
"ERR");
109 const size_t ncoeffs =
NCOEFFS;
110 const size_t nbreak =
NBREAK;
112 gsl_bspline_workspace *bw;
119 gsl_multifit_linear_workspace *mw;
125 r = gsl_rng_alloc(gsl_rng_default);
128 bw = gsl_bspline_alloc(4, nbreak);
129 B = gsl_vector_alloc(ncoeffs);
131 x = gsl_vector_alloc(
n);
132 y = gsl_vector_alloc(
n);
133 X = gsl_matrix_alloc(
n, ncoeffs);
134 c = gsl_vector_alloc(ncoeffs);
135 w = gsl_vector_alloc(
n);
136 cov = gsl_matrix_alloc(ncoeffs, ncoeffs);
138 printf(
"#m=0,S=0\n");
140 for (i = 0; i <
n; ++i)
143 double xi = (15.0 / (
N - 1)) * i;
144 double yi = cos(xi) * exp(-0.1 * xi);
147 dy = gsl_ran_gaussian(r,
sigma);
150 gsl_vector_set(
x, i, xi);
151 gsl_vector_set(
y, i, yi);
158 gsl_bspline_knots_uniform(0.0, 15.0, bw);
161 for (i = 0; i <
n; ++i)
163 double xi = gsl_vector_get(
x, i);
166 gsl_bspline_eval(xi, B, bw);
169 for (j = 0; j < ncoeffs; ++j)
171 double Bj = gsl_vector_get(B, j);
172 gsl_matrix_set(X, i, j, Bj);
175 mw = gsl_multifit_linear_alloc(
n, ncoeffs);
178 printf(
"ok2 n=%d mw->n=%d\n",
n,mw->n);
180 printf(
"ok2 n=%d mw->n=%d\n",
n,mw->n);
181 printf(
"ok3 p=%d mw->p=%d\n",ncoeffs,mw->p);
183 printf(
"ok3 p=%d mw->p=%d\n",ncoeffs,mw->p);
185 gsl_multifit_wlinear(X, w,
y, c, cov, &chisq, mw);
200 printf(
"#m=1,S=0\n");
201 for (xi = 0.0; xi < 15.0; xi += 0.1)
203 gsl_bspline_eval(xi, B, bw);
204 gsl_multifit_linear_est(B, c, cov, &yi, &yerr);
210 gsl_bspline_free(bw);
217 gsl_matrix_free(cov);
218 gsl_multifit_linear_free(mw);
229int main(
int argc,
char *
const argv[])
233 const char* file_on = NULL ;
235 cpl_test_init(
"amodigli@eso.org", CPL_MSG_WARNING);
246 fprintf(stderr,
"usage: %s table.fits\n", argv[0]);
251 if (cpl_error_get_code() != CPL_ERROR_NONE) {
int test_gsl_table(const char *fname)
int main()
Unit test of xsh_bspline_interpol.
#define xsh_error_dump(level)