~ubuntu-branches/ubuntu/karmic/psicode/karmic

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Michael Banck, Michael Banck, Daniel Leidert
  • Date: 2009-02-23 00:12:02 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090223001202-rutldoy3dimfpesc
Tags: 3.4.0-1
* New upstream release.

[ Michael Banck ]
* debian/patches/01_DESTDIR.dpatch: Refreshed.
* debian/patches/02_FHS.dpatch: Removed, applied upstream.
* debian/patches/03_debian_docdir: Likewise.
* debian/patches/04_man.dpatch: Likewise.
* debian/patches/06_466828_fix_gcc_43_ftbfs.dpatch: Likewise.
* debian/patches/07_464867_move_executables: Fixed and refreshed.
* debian/patches/00list: Adjusted.
* debian/control: Improved description.
* debian/patches-held: Removed.
* debian/rules (install/psi3): Do not ship the ruby bindings for now.

[ Daniel Leidert ]
* debian/rules: Fix txtdir via DEB_MAKE_INSTALL_TARGET.
* debian/patches/01_DESTDIR.dpatch: Refreshed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*!
2
 
** \file int_array.c
3
 
** \ingroup (CIOMR)
4
 
**
5
 
** INT_ARRAY.C
6
 
** This file includes the integer versions of several psi routines
7
 
** for handling arrays and matrices of doubles 
8
 
**
9
 
** David Sherrill, 1996
10
 
**
11
 
*/
12
 
 
13
 
#include <psifiles.h>
14
 
#include "includes.h"
15
 
 
16
 
extern int resource_command(void);
17
 
 
18
 
 
19
 
/*!
20
 
** init_int_array():
21
 
** Allocates memory for one-D array of ints of dimension 'size'
22
 
** and returns pointer to 1st element.  Zeroes all elements.
23
 
**
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.             
27
 
**
28
 
** \param size = length of array to allocate
29
 
**
30
 
** Returns: pointer to new array
31
 
** \ingroup (CIOMR)
32
 
*/
33
 
int * init_int_array(int size)
34
 
{
35
 
   int *array;
36
 
 
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);
40
 
      resource_command();
41
 
      exit(PSI_RETURN_FAILURE);
42
 
      }
43
 
   bzero(array,sizeof(int)*size);
44
 
   return(array);
45
 
}
46
 
 
47
 
 
48
 
/*!
49
 
** zero_int_array()
50
 
** Zeroes out an array of integers 'size' integers long
51
 
**
52
 
** \ingroup (CIOMR)
53
 
*/
54
 
void zero_int_array(int *a, int size)
55
 
{
56
 
   bzero(a,sizeof(int)*size) ;
57
 
}
58
 
 
59
 
 
60
 
/*!
61
 
** init_int_matrix():
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 
64
 
** row ptr).
65
 
**
66
 
** \ingroup (CIOMR)
67
 
*/
68
 
int **init_int_matrix(int rows, int cols)
69
 
{
70
 
   int **array=NULL ;
71
 
   int i ;
72
 
 
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) ;
77
 
      }
78
 
 
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) ;
84
 
         }
85
 
      bzero(array[i], sizeof(int)*cols) ;
86
 
      }
87
 
 
88
 
   return(array) ;
89
 
}
90
 
 
91
 
 
92
 
/*!
93
 
** free_int_matrix():
94
 
** Free a matrix of integers.  Pass a pointer to the matrix and the
95
 
** number of rows.
96
 
** \ingroup (CIOMR)
97
 
*/
98
 
void free_int_matrix(int **array, int size)
99
 
{
100
 
   int i ;
101
 
 
102
 
   for (i=0; i<size; i++) {
103
 
      free(array[i]) ;
104
 
      }
105
 
 
106
 
   free(array) ;
107
 
 
108
 
}
109
 
 
110
 
 
111
 
/*!
112
 
** zero_int_matrix():
113
 
** Zero a matrix of integers.  Pass the matrix, the number of rows,
114
 
** and the number of columns.
115
 
** \ingroup (CIOMR)
116
 
*/
117
 
void zero_int_matrix(int **array, int rows, int cols)
118
 
{
119
 
   int i;
120
 
 
121
 
   for (i=0; i<rows; i++) {
122
 
      zero_int_array(array[i], cols);
123
 
      }
124
 
}
125
 
 
126
 
 
127
 
/*!
128
 
** print_int_mat():
129
 
** Print a matrix of integers.  Pass the matrix, the number of rows and
130
 
** columns, and the output file pointer.
131
 
** \ingroup (CIOMR)
132
 
*/
133
 
void print_int_mat(int **a, int m, int n, FILE *out)
134
 
{
135
 
  int ii,jj,kk,nn,ll;
136
 
  int i,j,k;
137
 
 
138
 
  ii=0;jj=0;
139
 
L200:
140
 
  ii++;
141
 
  jj++;
142
 
  kk=10*jj;
143
 
  nn=n;
144
 
  if (nn > kk) nn=kk;
145
 
  ll = 2*(nn-ii+1)+1;
146
 
  fprintf (out,"\n   ");
147
 
  for (i=ii; i <= nn; i++) fprintf(out,"   %5d",i);
148
 
  fprintf (out,"\n");
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]);
153
 
    }
154
 
  }
155
 
  fprintf (out,"\n");
156
 
  if (n <= kk) {
157
 
    fflush(out);
158
 
    return;
159
 
  }
160
 
  ii=kk; goto L200;
161
 
}
162