1
/*===========================================================================
2
Copyright (C) 1993-2009 European Southern Observatory (ESO)
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.
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.
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,
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
26
===========================================================================*/
28
/******************************************************************************
34
** Author: Jean-Luc Starck
43
*******************************************************************************
45
** DECRIPTION This module contains allocation procedures
48
******************************************************************************
50
** double *d_vector_alloc (Nbr_Elem)
53
** Allocates an array of Nbr_Elem doubles
55
** Tab = d_vector_alloc(10);
58
******************************************************************************
60
** float *f_vector_alloc (Nbr_Elem)
63
** Allocates an array of Nbr_Elem floats
65
** Tab = f_vector_alloc(10);
67
******************************************************************************
69
** int *i_vector_alloc (Nbr_Elem)
72
** Allocates an array of Nbr_Elem integers
74
** Tab = i_vector_alloc(10);
76
******************************************************************************
78
** int **i_matrix_alloc(nbr_lin,nbr_col)
79
** int nbr_lin, nbr_col;
81
** Allocate a matrix of nbr_lin lines and nbr_col columns of integer
83
** Tab = i_matrix_alloc(10,20);
85
******************************************************************************
87
** complex_float *cf_vector_alloc(Nbr_Elem)
90
** Allocates an array of Nbr_Elem complex floats
91
** ex: complex_float *Tab;
92
** Tab = cf_vector_alloc(10);
94
******************************************************************************
96
** float **f_matrix_alloc(nbr_lin,nbr_col)
97
** int nbr_lin, nbr_col;
99
** Allocate a matrix of nbr_lin lines and nbr_col columns of floats
101
** Tab = f_matrix_alloc(10,20);
103
******************************************************************************
105
** float **cf_matrix_alloc(nbr_lin,nbr_col)
106
** int nbr_lin, nbr_col;
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);
112
*****************************************************************************/
120
#include "Def_Math.h"
123
extern void io_err_message_exit();
126
/****************************************************************************/
128
static void memory_abort ()
130
io_err_message_exit (ERR_ALLOC_MEMO, " ");
133
/****************************************************************************/
135
double *d_vector_alloc(Nbr_Elem)
136
/* allocates a vector of doubles */
141
Vector = (double*) calloc ((unsigned) Nbr_Elem * sizeof (double),1);
142
if (Vector == NULL) memory_abort();
146
/****************************************************************************/
148
float *f_vector_alloc(Nbr_Elem)
149
/* allocates a vector of float */
154
Vector = (float*) calloc ((unsigned)Nbr_Elem * sizeof (float),1);
155
if (Vector == NULL) memory_abort();
159
/****************************************************************************/
161
int *i_vector_alloc(Nbr_Elem)
162
/* allocates a vector of integer */
167
Vector = (int*) calloc ((unsigned) Nbr_Elem * sizeof (int),1);
168
if (Vector == NULL) memory_abort();
172
/****************************************************************************/
174
complex_float *cf_vector_alloc(Nbr_Elem)
175
/* allocates a vector of complex float */
178
complex_float *Vector;
180
Vector= (complex_float*) calloc((unsigned)Nbr_Elem * sizeof(complex_float),1);
181
if (Vector == NULL) memory_abort();
185
/****************************************************************************/
187
int **i_matrix_alloc(nbr_lin,nbr_col)
188
int nbr_lin, nbr_col;
189
/* allocates a matrix of integer */
194
matrix = (int **) calloc((unsigned) nbr_lin*sizeof(int *),1);
195
if (matrix == NULL) memory_abort();
197
for (i=0; i<nbr_lin; i++)
199
matrix[i] = (int *) calloc((unsigned) nbr_col*sizeof(int),1);
200
if (matrix[i] == NULL) memory_abort();
203
for (i=0; i<nbr_lin; i++)
204
for (j=0; j<nbr_col; j++) matrix[i][j] = 0;
209
/****************************************************************************/
211
float **f_matrix_alloc(nbr_lin,nbr_col)
212
int nbr_lin, nbr_col;
213
/* allocates a matrix of float */
218
matrix = (float **) calloc((unsigned) nbr_lin*sizeof(float *),1);
219
if (matrix == NULL) memory_abort();
221
for (i=0; i<nbr_lin; i++)
223
matrix[i] = (float *) calloc((unsigned) nbr_col*sizeof(float),1);
224
if (matrix[i] == NULL) memory_abort();
230
/****************************************************************************/
232
complex_float **cf_matrix_alloc(nbr_lin,nbr_col)
233
int nbr_lin, nbr_col;
235
complex_float **matrix;
238
matrix = (complex_float **)
239
calloc((unsigned) nbr_lin*sizeof(complex_float *),1);
240
if (matrix == NULL) memory_abort();
242
for (i=0; i< nbr_lin; i++)
244
matrix[i] = (complex_float *)
245
calloc((unsigned) nbr_col*sizeof(complex_float),1);
246
if (matrix[i] == NULL) memory_abort();
252
/****************************************************************************/