Debian Codegraph @

external/gsl/gsl_wavelet__wavelet.c

raw
1 /* wavelet/wavelet.c
2 *
3 * Copyright (C) 2004 Ivo Alxneit
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 "gsl__config.h"
21 #include <stdlib.h>
22 #include "gsl_errno.h"
23 #include "gsl_wavelet.h"
24
25 gsl_wavelet *
26 gsl_wavelet_alloc (const gsl_wavelet_type * T, size_t k)
27 {
28 int status;
29
30 gsl_wavelet *w = (gsl_wavelet *) malloc (sizeof (gsl_wavelet));
31
32 if (w == NULL)
33 {
34 GSL_ERROR_VAL ("failed to allocate space for wavelet struct",
35 GSL_ENOMEM, 0);
36 };
37
38 w->type = T;
39
40 status = (T->init) (&(w->h1), &(w->g1), &(w->h2), &(w->g2),
41 &(w->nc), &(w->offset), k);
42
43 if (status)
44 {
45 free (w);
46 GSL_ERROR_VAL ("invalid wavelet member", GSL_EINVAL, 0);
47 }
48
49 return w;
50 }
51
52 void
53 gsl_wavelet_free (gsl_wavelet * w)
54 {
55 free (w);
56 }
57
58 const char *
59 gsl_wavelet_name (const gsl_wavelet * w)
60 {
61 return w->type->name;
62 }
63
64
65 /* Let's not export this for now (BJG) */
66 #if 0
67 void
68 gsl_wavelet_print (const gsl_wavelet * w)
69 {
70 size_t n = w->nc;
71 size_t i;
72
73 printf ("Wavelet type: %s\n", w->type->name);
74
75 printf
76 (" h1(%d):%12.8f g1(%d):%12.8f h2(%d):%12.8f g2(%d):%12.8f\n",
77 0, w->h1[0], 0, w->g1[0], 0, w->h2[0], 0, w->g2[0]);
78
79 for (i = 1; i < (n < 10 ? n : 10); i++)
80 {
81 printf
82 (" h1(%d):%12.8f g1(%d):%12.8f h2(%d):%12.8f g2(%d):%12.8f\n",
83 i, w->h1[i], i, w->g1[i], i, w->h2[i], i, w->g2[i]);
84 }
85
86 for (; i < n; i++)
87 {
88 printf
89 ("h1(%d):%12.8f g1(%d):%12.8f h2(%d):%12.8f g2(%d):%12.8f\n",
90 i, w->h1[i], i, w->g1[i], i, w->h2[i], i, w->g2[i]);
91 }
92 }
93 #endif
94
95 gsl_wavelet_workspace *
96 gsl_wavelet_workspace_alloc (size_t n)
97 {
98 gsl_wavelet_workspace *work;
99
100 if (n == 0)
101 {
102 GSL_ERROR_VAL ("length n must be positive integer", GSL_EDOM, 0);
103 }
104
105 work = (gsl_wavelet_workspace *) malloc (sizeof (gsl_wavelet_workspace));
106
107 if (work == NULL)
108 {
109 GSL_ERROR_VAL ("failed to allocate struct", GSL_ENOMEM, 0);
110 }
111
112 work->n = n;
113 work->scratch = (double *) malloc (n * sizeof (double));
114
115 if (work->scratch == NULL)
116 {
117 /* error in constructor, prevent memory leak */
118 free (work);
119 GSL_ERROR_VAL ("failed to allocate scratch space", GSL_ENOMEM, 0);
120 }
121
122 return work;
123 }
124
125 void
126 gsl_wavelet_workspace_free (gsl_wavelet_workspace * work)
127 {
128 /* release scratch space */
129 free (work->scratch);
130 work->scratch = NULL;
131 free (work);
132 }