6
** This file includes the integer versions of several psi routines
7
** for handling arrays and matrices of doubles
9
** David Sherrill, 1996
16
extern int resource_command(void);
21
** Allocates memory for one-D array of ints of dimension 'size'
22
** and returns pointer to 1st element. Zeroes all elements.
24
** Just modified the init_array() routine to do int's instead.
25
** This will avoid the temptation to allocate 5 integers by
26
** p = (int *) init_array(5/2), which is bad.
28
** \param size = length of array to allocate
30
** Returns: pointer to new array
33
int * init_int_array(int size)
37
if ((array = (int *) malloc(sizeof(int)*size))==NULL) {
38
fprintf(stderr,"init_array: trouble allocating memory \n");
39
fprintf(stderr,"size = %d\n",size);
41
exit(PSI_RETURN_FAILURE);
43
bzero(array,sizeof(int)*size);
50
** Zeroes out an array of integers 'size' integers long
54
void zero_int_array(int *a, int size)
56
bzero(a,sizeof(int)*size) ;
62
** Function initializes (allocates and clears) a matrix of integers with
63
** dimensions 'rows' by 'cols' and returns a pointer to it (ptr to first
68
int **init_int_matrix(int rows, int cols)
73
if ((array = (int **) malloc(sizeof(int *)*rows))==NULL) {
74
fprintf(stderr,"init_int_matrix: trouble allocating memory \n") ;
75
fprintf(stderr,"rows = %d\n", rows) ;
76
exit(PSI_RETURN_FAILURE) ;
79
for (i=0; i<rows; i++) {
80
if ((array[i] = (int *) malloc (sizeof(int)*cols))==NULL) {
81
fprintf(stderr,"init_int_matrix: trouble allocating memory \n") ;
82
fprintf(stderr,"row = %d, cols = %d", i, cols) ;
83
exit(PSI_RETURN_FAILURE) ;
85
bzero(array[i], sizeof(int)*cols) ;
94
** Free a matrix of integers. Pass a pointer to the matrix and the
98
void free_int_matrix(int **array, int size)
102
for (i=0; i<size; i++) {
112
** zero_int_matrix():
113
** Zero a matrix of integers. Pass the matrix, the number of rows,
114
** and the number of columns.
117
void zero_int_matrix(int **array, int rows, int cols)
121
for (i=0; i<rows; i++) {
122
zero_int_array(array[i], cols);
129
** Print a matrix of integers. Pass the matrix, the number of rows and
130
** columns, and the output file pointer.
133
void print_int_mat(int **a, int m, int n, FILE *out)
147
for (i=ii; i <= nn; i++) fprintf(out," %5d",i);
149
for (i=0; i < m; i++) {
150
fprintf (out,"\n%5d",i+1);
151
for (j=ii-1; j < nn; j++) {
152
fprintf (out,"%8d",a[i][j]);