Debian Codegraph @

gui/XIdent/src/alloc.c

raw
1 /*===========================================================================
2 Copyright (C) 1995-2009 European Southern Observatory (ESO)
3
4 This program is free software; you can redistribute it and/or
5 modify it under the terms of the GNU General Public License as
6 published by the Free Software Foundation; either version 2 of
7 the License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public
15 License along with this program; if not, write to the Free
16 Software Foundation, Inc., 675 Massachusetts Ave, Cambridge,
17 MA 02139, USA.
18
19 Correspondence concerning ESO-MIDAS should be addressed as follows:
20 Internet e-mail: [email protected]
21 Postal address: European Southern Observatory
22 Data Management Division
23 Karl-Schwarzschild-Strasse 2
24 D 85748 Garching bei Muenchen
25 GERMANY
26 ===========================================================================*/
27
28 /*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
29 .IDENT alloc.c
30 .MODULE subroutines
31 .LANGUAGE C
32 .AUTHOR Cristian Levin - ESO La Silla
33 .PURPOSE Routines for memory [de]allocation
34 .KEYWORDS Memory management.
35 .VERSION 1.0 1-Feb-1991 Implementation
36
37 090819 last modif
38 ------------------------------------------------------------*/
39
40 #include <midas_def.h>
41 #include <stdio.h>
42
43 int **imatrix( nrl, nrh, ncl, nch )
44 int nrl, nrh, ncl, nch;
45 /* Allocates a int matrix with range [nrl..nrh][ncl..nch] */
46 {
47 int i;
48 int **m;
49
50 /* Allocate pointers to rows */
51 m = (int **)osmmget( (unsigned) (nrh-nrl+1) * sizeof(int *) );
52 m -= nrl;
53
54 /* Allocate rows and set pointers to them */
55 for ( i = nrl; i <= nrh; i++ ) {
56 m[i] = (int *)osmmget( (unsigned) (nch-ncl+1) * sizeof(int) );
57 m[i] -= ncl;
58 }
59 return 0;
60 }
61
62 int *ivector( nl, nh )
63 int nl, nh;
64 /* Allocates a int vector with range [nl..nh] */
65 {
66 int *v;
67
68 v = (int *)osmmget( (unsigned) (nh-nl+1) * sizeof(int) );
69 return( v - nl );
70 }
71
72 void free_imatrix( m, nrl, nrh, ncl, nch )
73 int **m;
74 int nrl, nrh, ncl, nch;
75 /* Frees a matrix allocated with imatrix() */
76 {
77 int i;
78
79 for ( i = nrh; i >= nrl; i-- )
80 osmmfree( (char *) (m[i] + ncl) );
81
82 osmmfree( (char *) (m + nrl) );
83 }
84
85 void free_ivector( v, nl, nh )
86 int *v;
87 int nl, nh;
88 /* Frees a vector allocated with ivector() */
89 {
90 osmmfree( (char *) (v + nl) );
91 }
92
93 double **dmatrix( nrl, nrh, ncl, nch )
94 int nrl, nrh, ncl, nch;
95 /* Allocates a double matrix with range [nrl..nrh][ncl..nch] */
96 {
97 int i;
98 double **m;
99
100 /* Allocate pointers to rows */
101 m = (double **)osmmget( (unsigned) (nrh-nrl+1) * sizeof(double *) );
102 m -= nrl;
103
104 /* Allocate rows and set pointers to them */
105 for ( i = nrl; i <= nrh; i++ ) {
106 m[i] = (double *)osmmget( (unsigned) (nch-ncl+1) * sizeof(double) );
107 m[i] -= ncl;
108 }
109 return( m );
110 }
111
112 double *dvector( nl, nh )
113 int nl, nh;
114 /* Allocates a double vector with range [nl..nh] */
115 {
116 double *v;
117
118 v = (double *)osmmget( (unsigned) (nh-nl+1) * sizeof(double) );
119 return( v - nl );
120 }
121
122 void free_dmatrix( m, nrl, nrh, ncl, nch )
123 double **m;
124 int nrl, nrh, ncl, nch;
125 /* Frees a matrix allocated with dmatrix() */
126 {
127 int i;
128
129 for ( i = nrh; i >= nrl; i-- )
130 osmmfree( (char *) (m[i] + ncl) );
131
132 osmmfree( (char *) (m + nrl) );
133 }
134
135 void free_dvector( v, nl, nh )
136 double *v;
137 int nl, nh;
138 /* Frees a vector allocated with dvector() */
139 {
140 osmmfree( (char *) (v + nl) );
141 }
142
143 float **fmatrix( nrl, nrh, ncl, nch )
144 int nrl, nrh, ncl, nch;
145 /* Allocates a float matrix with range [nrl..nrh][ncl..nch] */
146 {
147 int i;
148 float **m;
149
150 /* Allocate pointers to rows */
151 m = (float **)osmmget( (unsigned) (nrh-nrl+1) * sizeof(float *) );
152 m -= nrl;
153
154 /* Allocate rows and set pointers to them */
155 for ( i = nrl; i <= nrh; i++ ) {
156 m[i] = (float *)osmmget( (unsigned) (nch-ncl+1) * sizeof(float) );
157 m[i] -= ncl;
158 }
159 return( m );
160 }
161
162 float *fvector( nl, nh )
163 int nl, nh;
164 /* Allocates a float vector with range [nl..nh] */
165 {
166 float *v;
167
168 v = (float *)osmmget( (unsigned) (nh-nl+1) * sizeof(float) );
169 return( v - nl );
170 }
171
172 void free_fmatrix( m, nrl, nrh, ncl, nch )
173 float **m;
174 int nrl, nrh, ncl, nch;
175 /* Frees a matrix allocated with fmatrix() */
176 {
177 int i;
178
179 for ( i = nrh; i >= nrl; i-- )
180 osmmfree( (char *) (m[i] + ncl) );
181
182 osmmfree( (char *) (m + nrl) );
183 }
184
185 void free_fvector( v, nl, nh )
186 float *v;
187 int nl, nh;
188 /* Frees a vector allocated with fvector() */
189 {
190 osmmfree( (char *) (v + nl) );
191 }
192
193 char **cmatrix( nrl, nrh, ncl, nch )
194 int nrl, nrh, ncl, nch;
195 /* Allocates a char matrix with range [nrl..nrh][ncl..nch] */
196 {
197 int i;
198 char **m;
199
200 /* Allocate pointers to rows */
201 m = (char **)osmmget( (unsigned) (nrh-nrl+1) * sizeof(char *) );
202 m -= nrl;
203
204 /* Allocate rows and set pointers to them */
205 for ( i = nrl; i <= nrh; i++ ) {
206 m[i] = (char *)osmmget( (unsigned) (nch-ncl+1) * sizeof(char) );
207 m[i] -= ncl;
208 }
209 return( m );
210 }
211
212 char *cvector( nl, nh )
213 int nl, nh;
214 /* Allocates a char vector with range [nl..nh] */
215 {
216 char *v;
217
218 v = (char *)osmmget( (unsigned) (nh-nl+1) * sizeof(char) );
219 return( v - nl );
220 }
221
222 void free_cmatrix( m, nrl, nrh, ncl, nch )
223 char **m;
224 int nrl, nrh, ncl, nch;
225 /* Frees a matrix allocated with cmatrix() */
226 {
227 int i;
228
229 for ( i = nrh; i >= nrl; i-- )
230 osmmfree( (char *) (m[i] + ncl) );
231
232 osmmfree( (char *) (m + nrl) );
233 }
234
235 void free_cvector( v, nl, nh )
236 char *v;
237 int nl, nh;
238 /* Frees a vector allocated with cvector() */
239 {
240 osmmfree( (char *) (v + nl) );
241 }