~ubuntu-branches/ubuntu/quantal/psicode/quantal

« back to all changes in this revision

Viewing changes to src/lib/libciomr/long_int_array.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck
  • Date: 2006-09-10 14:01:33 UTC
  • Revision ID: james.westby@ubuntu.com-20060910140133-ib2j86trekykfsfv
Tags: upstream-3.2.3
ImportĀ upstreamĀ versionĀ 3.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*!
 
2
** \file int_array.c
 
3
** \ingroup (CIOMR)
 
4
**
 
5
** LONG_INT_ARRAY.C
 
6
** This file includes the long int versions of several psi routines
 
7
** for handling arrays and matrices of doubles 
 
8
**
 
9
** TDC, 2003
 
10
** based on int_array.c by David Sherrill, 1996
 
11
**
 
12
*/
 
13
 
 
14
#include <psifiles.h>
 
15
#include "includes.h"
 
16
 
 
17
extern int resource_command(void);
 
18
 
 
19
/*!
 
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.
 
23
**
 
24
** \param size = length of array to allocate
 
25
**
 
26
** Returns: pointer to new array
 
27
** \ingroup (CIOMR)
 
28
*/
 
29
long int * init_long_int_array(int size)
 
30
{
 
31
   long int *array;
 
32
 
 
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);
 
36
      resource_command();
 
37
      exit(PSI_RETURN_FAILURE);
 
38
      }
 
39
   bzero(array,sizeof(long int)*size);
 
40
   return(array);
 
41
}
 
42
 
 
43
 
 
44
/*!
 
45
** zero_long_int_array()
 
46
** Zeroes out an array of long integers 'size' integers long
 
47
**
 
48
** \ingroup (CIOMR)
 
49
*/
 
50
void zero_long_int_array(long int *a, int size)
 
51
{
 
52
   bzero(a,sizeof(long int)*size) ;
 
53
}
 
54
 
 
55
 
 
56
/*!
 
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 
 
60
** row ptr).
 
61
**
 
62
** \ingroup (CIOMR)
 
63
*/
 
64
long int **init_long_int_matrix(int rows, int cols)
 
65
{
 
66
   long int **array=NULL ;
 
67
   int i ;
 
68
 
 
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) ;
 
73
      }
 
74
 
 
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) ;
 
80
         }
 
81
      bzero(array[i], sizeof(long int)*cols) ;
 
82
      }
 
83
 
 
84
   return(array) ;
 
85
}
 
86
 
 
87
 
 
88
/*!
 
89
** free_long_int_matrix():
 
90
** Free a matrix of long integers.  Pass a pointer to the matrix and the
 
91
** number of rows.
 
92
** \ingroup (CIOMR)
 
93
*/
 
94
void free_long_int_matrix(long int **array, int size)
 
95
{
 
96
   int i ;
 
97
 
 
98
   for (i=0; i<size; i++) {
 
99
      free(array[i]) ;
 
100
      }
 
101
 
 
102
   free(array) ;
 
103
 
 
104
}
 
105
 
 
106
 
 
107
/*!
 
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.
 
111
** \ingroup (CIOMR)
 
112
*/
 
113
void zero_long_int_matrix(long int **array, int rows, int cols)
 
114
{
 
115
   int i;
 
116
 
 
117
   for (i=0; i<rows; i++) {
 
118
      zero_long_int_array(array[i], cols);
 
119
      }
 
120
}
 
121
 
 
122
 
 
123
/*!
 
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.
 
127
** \ingroup (CIOMR)
 
128
*/
 
129
void print_long_int_mat(long int **a, int m, int n, FILE *out)
 
130
{
 
131
  int ii,jj,kk,nn,ll;
 
132
  int i,j,k;
 
133
 
 
134
  ii=0;jj=0;
 
135
L200:
 
136
  ii++;
 
137
  jj++;
 
138
  kk=10*jj;
 
139
  nn=n;
 
140
  if (nn > kk) nn=kk;
 
141
  ll = 2*(nn-ii+1)+1;
 
142
  fprintf (out,"\n   ");
 
143
  for (i=ii; i <= nn; i++) fprintf(out,"   %5d",i);
 
144
  fprintf (out,"\n");
 
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]);
 
149
    }
 
150
  }
 
151
  fprintf (out,"\n");
 
152
  if (n <= kk) {
 
153
    fflush(out);
 
154
    return;
 
155
  }
 
156
  ii=kk; goto L200;
 
157
}
 
158