Debian Codegraph @

external/gsl/gsl_integration__workspace.c

raw
1 /* integration/workspace.c
2 *
3 * Copyright (C) 1996, 1997, 1998, 1999, 2000, 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 "gsl__config.h"
21 #include <stdlib.h>
22 #include "gsl_integration.h"
23 #include "gsl_errno.h"
24
25 gsl_integration_workspace *
26 gsl_integration_workspace_alloc (const size_t n)
27 {
28 gsl_integration_workspace * w ;
29
30 if (n == 0)
31 {
32 GSL_ERROR_VAL ("workspace length n must be positive integer",
33 GSL_EDOM, 0);
34 }
35
36 w = (gsl_integration_workspace *)
37 malloc (sizeof (gsl_integration_workspace));
38
39 if (w == 0)
40 {
41 GSL_ERROR_VAL ("failed to allocate space for workspace struct",
42 GSL_ENOMEM, 0);
43 }
44
45 w->alist = (double *) malloc (n * sizeof (double));
46
47 if (w->alist == 0)
48 {
49 free (w); /* exception in constructor, avoid memory leak */
50
51 GSL_ERROR_VAL ("failed to allocate space for alist ranges",
52 GSL_ENOMEM, 0);
53 }
54
55 w->blist = (double *) malloc (n * sizeof (double));
56
57 if (w->blist == 0)
58 {
59 free (w->alist);
60 free (w); /* exception in constructor, avoid memory leak */
61
62 GSL_ERROR_VAL ("failed to allocate space for blist ranges",
63 GSL_ENOMEM, 0);
64 }
65
66 w->rlist = (double *) malloc (n * sizeof (double));
67
68 if (w->rlist == 0)
69 {
70 free (w->blist);
71 free (w->alist);
72 free (w); /* exception in constructor, avoid memory leak */
73
74 GSL_ERROR_VAL ("failed to allocate space for rlist ranges",
75 GSL_ENOMEM, 0);
76 }
77
78
79 w->elist = (double *) malloc (n * sizeof (double));
80
81 if (w->elist == 0)
82 {
83 free (w->rlist);
84 free (w->blist);
85 free (w->alist);
86 free (w); /* exception in constructor, avoid memory leak */
87
88 GSL_ERROR_VAL ("failed to allocate space for elist ranges",
89 GSL_ENOMEM, 0);
90 }
91
92 w->order = (size_t *) malloc (n * sizeof (size_t));
93
94 if (w->order == 0)
95 {
96 free (w->elist);
97 free (w->rlist);
98 free (w->blist);
99 free (w->alist);
100 free (w); /* exception in constructor, avoid memory leak */
101
102 GSL_ERROR_VAL ("failed to allocate space for order ranges",
103 GSL_ENOMEM, 0);
104 }
105
106 w->level = (size_t *) malloc (n * sizeof (size_t));
107
108 if (w->level == 0)
109 {
110 free (w->order);
111 free (w->elist);
112 free (w->rlist);
113 free (w->blist);
114 free (w->alist);
115 free (w); /* exception in constructor, avoid memory leak */
116
117 GSL_ERROR_VAL ("failed to allocate space for order ranges",
118 GSL_ENOMEM, 0);
119 }
120
121 w->size = 0 ;
122 w->limit = n ;
123 w->maximum_level = 0 ;
124
125 return w ;
126 }
127
128 void
129 gsl_integration_workspace_free (gsl_integration_workspace * w)
130 {
131 free (w->level) ;
132 free (w->order) ;
133 free (w->elist) ;
134 free (w->rlist) ;
135 free (w->blist) ;
136 free (w->alist) ;
137 free (w) ;
138 }
139
140 /*
141 size_t
142 gsl_integration_workspace_limit (gsl_integration_workspace * w)
143 {
144 return w->limit ;
145 }
146
147
148 size_t
149 gsl_integration_workspace_size (gsl_integration_workspace * w)
150 {
151 return w->size ;
152 }
153 */