~ubuntu-branches/debian/jessie/eso-midas/jessie

« back to all changes in this revision

Viewing changes to contrib/wavelet/libsrc/mem_alloc.c

  • Committer: Package Import Robot
  • Author(s): Ole Streicher
  • Date: 2014-04-22 14:44:58 UTC
  • Revision ID: package-import@ubuntu.com-20140422144458-okiwi1assxkkiz39
Tags: upstream-13.09pl1.2+dfsg
ImportĀ upstreamĀ versionĀ 13.09pl1.2+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*===========================================================================
 
2
  Copyright (C) 1993-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: midas@eso.org
 
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
**
 
30
**    UNIT
 
31
**
 
32
**    Version: 19.1
 
33
**
 
34
**    Author: Jean-Luc Starck
 
35
**
 
36
**    Date:  03/02/25
 
37
**    
 
38
**    File:  mem_alloc.c
 
39
.VERSION
 
40
 090804         last modif
 
41
 
 
42
**
 
43
*******************************************************************************
 
44
**
 
45
**    DECRIPTION  This module contains allocation procedures
 
46
**    ---------- 
 
47
**
 
48
******************************************************************************
 
49
**
 
50
** double *d_vector_alloc (Nbr_Elem)
 
51
** int  Nbr_Elem
 
52
**
 
53
** Allocates an array of Nbr_Elem doubles
 
54
** ex: double *Tab;
 
55
**     Tab = d_vector_alloc(10);
 
56
**     
 
57
**
 
58
******************************************************************************
 
59
**
 
60
** float *f_vector_alloc (Nbr_Elem) 
 
61
** int  Nbr_Elem
 
62
**
 
63
** Allocates an array of Nbr_Elem floats
 
64
** ex: float *Tab;
 
65
**     Tab = f_vector_alloc(10);
 
66
**
 
67
******************************************************************************
 
68
**
 
69
** int *i_vector_alloc (Nbr_Elem) 
 
70
** int  Nbr_Elem
 
71
**
 
72
** Allocates an array of Nbr_Elem integers
 
73
** ex: int *Tab;
 
74
**     Tab = i_vector_alloc(10);
 
75
**
 
76
******************************************************************************
 
77
**
 
78
** int  **i_matrix_alloc(nbr_lin,nbr_col)
 
79
** int  nbr_lin, nbr_col;
 
80
**
 
81
** Allocate a matrix of nbr_lin lines and nbr_col columns of integer
 
82
** ex: int **Tab;
 
83
**     Tab = i_matrix_alloc(10,20);
 
84
**
 
85
******************************************************************************
 
86
**
 
87
** complex_float *cf_vector_alloc(Nbr_Elem)
 
88
** int  Nbr_Elem
 
89
** 
 
90
** Allocates an array of Nbr_Elem complex floats
 
91
** ex: complex_float *Tab;
 
92
**     Tab = cf_vector_alloc(10);
 
93
**
 
94
******************************************************************************
 
95
**
 
96
** float  **f_matrix_alloc(nbr_lin,nbr_col)
 
97
** int    nbr_lin, nbr_col;
 
98
**
 
99
** Allocate a matrix of nbr_lin lines and nbr_col columns of floats
 
100
** ex: float **Tab;
 
101
**     Tab = f_matrix_alloc(10,20);
 
102
**
 
103
******************************************************************************
 
104
**
 
105
** float  **cf_matrix_alloc(nbr_lin,nbr_col)
 
106
** int    nbr_lin, nbr_col;
 
107
**
 
108
** Allocate a matrix of nbr_lin lines and nbr_col columns of complex floats
 
109
** ex: complex_float **Tab;
 
110
**     Tab = cf_matrix_alloc(10,20);
 
111
**
 
112
*****************************************************************************/
 
113
 
 
114
 
 
115
#include <stdlib.h>
 
116
#include <stdio.h>
 
117
#include <string.h>
 
118
#include <math.h>
 
119
 
 
120
#include "Def_Math.h"
 
121
#include "Def_Mem.h"
 
122
 
 
123
extern void io_err_message_exit();
 
124
 
 
125
 
 
126
/****************************************************************************/
 
127
 
 
128
static void memory_abort ()
 
129
{
 
130
    io_err_message_exit (ERR_ALLOC_MEMO, " ");
 
131
}
 
132
 
 
133
/****************************************************************************/
 
134
 
 
135
double *d_vector_alloc(Nbr_Elem)
 
136
/* allocates a vector of doubles  */
 
137
int  Nbr_Elem;
 
138
{
 
139
    double *Vector;
 
140
 
 
141
    Vector = (double*) calloc ((unsigned) Nbr_Elem * sizeof (double),1);
 
142
    if (Vector == NULL) memory_abort();
 
143
    return(Vector);
 
144
}
 
145
 
 
146
/****************************************************************************/
 
147
 
 
148
float *f_vector_alloc(Nbr_Elem)
 
149
/* allocates a vector of float */
 
150
int  Nbr_Elem;
 
151
{
 
152
    float *Vector;
 
153
 
 
154
    Vector = (float*) calloc ((unsigned)Nbr_Elem * sizeof (float),1);
 
155
    if (Vector == NULL) memory_abort();
 
156
    return(Vector);
 
157
}
 
158
 
 
159
/****************************************************************************/
 
160
 
 
161
int *i_vector_alloc(Nbr_Elem)
 
162
/* allocates a vector of integer */
 
163
int  Nbr_Elem;
 
164
{
 
165
    int *Vector;
 
166
 
 
167
    Vector = (int*) calloc ((unsigned) Nbr_Elem * sizeof (int),1);
 
168
    if (Vector == NULL) memory_abort();
 
169
    return(Vector);
 
170
}
 
171
 
 
172
/****************************************************************************/
 
173
 
 
174
complex_float *cf_vector_alloc(Nbr_Elem)
 
175
/* allocates a vector of complex float */
 
176
int  Nbr_Elem;
 
177
{
 
178
    complex_float *Vector;
 
179
 
 
180
    Vector= (complex_float*) calloc((unsigned)Nbr_Elem * sizeof(complex_float),1);
 
181
    if (Vector == NULL) memory_abort();
 
182
    return(Vector);
 
183
}
 
184
 
 
185
/****************************************************************************/
 
186
 
 
187
int **i_matrix_alloc(nbr_lin,nbr_col)
 
188
int nbr_lin, nbr_col;
 
189
/* allocates a matrix of integer */
 
190
{
 
191
   auto int  **matrix;
 
192
   register int i, j;
 
193
 
 
194
    matrix = (int **) calloc((unsigned) nbr_lin*sizeof(int *),1);
 
195
    if (matrix == NULL) memory_abort();
 
196
 
 
197
    for (i=0; i<nbr_lin; i++)
 
198
    {
 
199
       matrix[i] = (int *) calloc((unsigned) nbr_col*sizeof(int),1);
 
200
       if (matrix[i] == NULL) memory_abort();
 
201
    }
 
202
 
 
203
    for (i=0; i<nbr_lin; i++)
 
204
    for (j=0; j<nbr_col; j++)  matrix[i][j] = 0;
 
205
 
 
206
    return(matrix);
 
207
}
 
208
 
 
209
/****************************************************************************/
 
210
 
 
211
float  **f_matrix_alloc(nbr_lin,nbr_col)
 
212
int    nbr_lin, nbr_col;
 
213
/* allocates a matrix of float */
 
214
{
 
215
   auto float **matrix;
 
216
   register int i;
 
217
 
 
218
   matrix = (float **) calloc((unsigned) nbr_lin*sizeof(float *),1);
 
219
   if (matrix == NULL) memory_abort();
 
220
 
 
221
   for (i=0; i<nbr_lin; i++)
 
222
   {
 
223
      matrix[i] = (float *) calloc((unsigned) nbr_col*sizeof(float),1);
 
224
      if (matrix[i] == NULL) memory_abort();
 
225
   }
 
226
 
 
227
   return(matrix);
 
228
}
 
229
 
 
230
/****************************************************************************/
 
231
 
 
232
complex_float  **cf_matrix_alloc(nbr_lin,nbr_col)
 
233
int    nbr_lin, nbr_col;
 
234
{
 
235
    complex_float  **matrix;
 
236
    register int i;
 
237
 
 
238
    matrix = (complex_float **)
 
239
                  calloc((unsigned) nbr_lin*sizeof(complex_float *),1);
 
240
    if (matrix == NULL) memory_abort();
 
241
 
 
242
    for (i=0; i< nbr_lin; i++)
 
243
    {
 
244
        matrix[i] = (complex_float *)
 
245
                         calloc((unsigned) nbr_col*sizeof(complex_float),1);
 
246
        if (matrix[i] == NULL) memory_abort();
 
247
 
 
248
    }
 
249
    return(matrix);
 
250
}
 
251
 
 
252
/****************************************************************************/