6
** This file includes the long int versions of several psi routines
7
** for handling arrays and matrices of doubles
10
** based on int_array.c by David Sherrill, 1996
17
extern int resource_command(void);
20
** init_long_int_array():
21
** Allocates memory for one-D array of long ints of dimension 'size'
22
** and returns pointer to 1st element. Zeroes all elements.
24
** \param size = length of array to allocate
26
** Returns: pointer to new array
29
long int * init_long_int_array(int size)
33
if ((array = (long int *) malloc(sizeof(long int)*size))==NULL) {
34
fprintf(stderr,"init_array: trouble allocating memory \n");
35
fprintf(stderr,"size = %d\n",size);
37
exit(PSI_RETURN_FAILURE);
39
bzero(array,sizeof(long int)*size);
45
** zero_long_int_array()
46
** Zeroes out an array of long integers 'size' integers long
50
void zero_long_int_array(long int *a, int size)
52
bzero(a,sizeof(long int)*size) ;
57
** init_long_int_matrix():
58
** Function initializes (allocates and clears) a matrix of integers with
59
** dimensions 'rows' by 'cols' and returns a pointer to it (ptr to first
64
long int **init_long_int_matrix(int rows, int cols)
66
long int **array=NULL ;
69
if ((array = (long int **) malloc(sizeof(long int *)*rows))==NULL) {
70
fprintf(stderr,"init_long_int_matrix: trouble allocating memory \n") ;
71
fprintf(stderr,"rows = %d\n", rows) ;
72
exit(PSI_RETURN_FAILURE) ;
75
for (i=0; i<rows; i++) {
76
if ((array[i] = (long int *) malloc (sizeof(long int)*cols))==NULL) {
77
fprintf(stderr,"init_long_int_matrix: trouble allocating memory \n") ;
78
fprintf(stderr,"row = %d, cols = %d", i, cols) ;
79
exit(PSI_RETURN_FAILURE) ;
81
bzero(array[i], sizeof(long int)*cols) ;
89
** free_long_int_matrix():
90
** Free a matrix of long integers. Pass a pointer to the matrix and the
94
void free_long_int_matrix(long int **array, int size)
98
for (i=0; i<size; i++) {
108
** zero_long_int_matrix():
109
** Zero a matrix of long integers. Pass the matrix, the number of rows,
110
** and the number of columns.
113
void zero_long_int_matrix(long int **array, int rows, int cols)
117
for (i=0; i<rows; i++) {
118
zero_long_int_array(array[i], cols);
124
** print_long_int_mat():
125
** Print a matrix of long integers. Pass the matrix, the number of rows and
126
** columns, and the output file pointer.
129
void print_long_int_mat(long int **a, int m, int n, FILE *out)
143
for (i=ii; i <= nn; i++) fprintf(out," %5d",i);
145
for (i=0; i < m; i++) {
146
fprintf (out,"\n%5d",i+1);
147
for (j=ii-1; j < nn; j++) {
148
fprintf (out,"%16ld",a[i][j]);