3
** \brief Initialize a matrix of doubles
16
** init_matrix(): Initialize an nxm matrix of doubles and return a pointer to
17
** the first row. Note that this does not form a matrix which is
18
** necessarily contiguous in memory. Use block_matrix() for that.
20
** \param n = number of rows (unsigned long to allow large matrices)
21
** \param m = number of columns (unsigned long to allow large matrices)
23
** Returns: pointer to first row
27
double ** init_matrix(unsigned long int n, unsigned long int m)
32
if ((array = (double **) malloc(n*(unsigned long int)sizeof(double *)))
34
fprintf(stderr,"init_matrix: trouble allocating memory \n");
35
fprintf(stderr,"n = %ld\n",n);
36
exit(PSI_RETURN_FAILURE);
39
for (i = 0; i < n; i++) {
40
if ((array[i] = (double *) malloc(m*(unsigned long int)sizeof(double)))
42
fprintf(stderr,"init_matrix: trouble allocating memory \n");
43
fprintf(stderr,"i = %ld m = %ld\n",i,m);
44
exit(PSI_RETURN_FAILURE);
46
//bzero(array[i],m*(unsigned long int)sizeof(double));
47
memset(array[i],'\0',m*(unsigned long int)sizeof(double));
54
** free_matrix(): Free a 2D matrix allocated with init_matrix().
56
** \param array = matrix to free
57
** \param size = number of rows (unsigned long to allow large matrices)
63
void free_matrix(double **array, unsigned long int size)
67
for (i=0; i < size ; i++) {