1 |
#define EXTERN extern |
2 |
#include "pcwin.h" |
3 |
#include "pcmod.h" |
4 |
#include "utility.h" |
5 |
void pcmfout(int); |
6 |
|
7 |
void message_alert(char *, char *); |
8 |
|
9 |
/* Routines to allocate and free space */ |
10 |
/* ---------------------------------- */ |
11 |
float *vector( int nl, int nh) |
12 |
{ |
13 |
float *v; |
14 |
|
15 |
v = (float *)malloc((unsigned) (nh-nl+1)*sizeof(float)); |
16 |
if (!v) |
17 |
{ |
18 |
message_alert("Error allocation fmemory. Please contact Serena Software. The program will now exit!","Utility"); |
19 |
fprintf(pcmlogfile,"error allocating float vector\n"); |
20 |
pcmfout(2); |
21 |
exit(0); |
22 |
} |
23 |
return v-nl; |
24 |
} |
25 |
/* ---------------------------------- */ |
26 |
int *ivector( int nl, int nh) |
27 |
{ |
28 |
int *v; |
29 |
|
30 |
v = ( int *)malloc((unsigned) (nh-nl+1)*sizeof( int)); |
31 |
if (!v) |
32 |
{ |
33 |
message_alert("Error allocation imemory. Please contact Serena Software. The program will now exit!","Utility"); |
34 |
fprintf(pcmlogfile,"error allocating int vector\n"); |
35 |
pcmfout(2); |
36 |
exit(0); |
37 |
} |
38 |
return v-nl; |
39 |
} |
40 |
/* ---------------------------------- */ |
41 |
long int *ilvector( int nl, int nh) |
42 |
{ |
43 |
long int *v; |
44 |
|
45 |
v = (long int *)malloc((unsigned) (nh-nl+1)*sizeof(long int)); |
46 |
if (!v) |
47 |
{ |
48 |
message_alert("Error allocation imemory. Please contact Serena Software. The program will now exit!","Utility"); |
49 |
fprintf(pcmlogfile,"error allocating int vector\n"); |
50 |
pcmfout(2); |
51 |
exit(0); |
52 |
} |
53 |
return v-nl; |
54 |
} |
55 |
/* ---------------------------------- */ |
56 |
double *dvector( int nl, int nh) |
57 |
{ |
58 |
double *v; |
59 |
|
60 |
v = (double *)malloc((unsigned) (nh-nl+1)*sizeof(double)); |
61 |
if (!v) |
62 |
{ |
63 |
char hatext[128]; |
64 |
sprintf(hatext,"Error allocation dmemory. Size %d\n",nh); |
65 |
message_alert(hatext,"Utility"); |
66 |
fprintf(pcmlogfile,"error allocating double vector\n"); |
67 |
pcmfout(2); |
68 |
exit(0); |
69 |
} |
70 |
return v-nl; |
71 |
} |
72 |
/* ---------------------------------- */ |
73 |
|
74 |
float **matrix( int nrl, int nrh, int ncl, int nch) |
75 |
{ |
76 |
int i; |
77 |
float **m; |
78 |
|
79 |
m = (float **)malloc((unsigned) (nrh-nrl+1)*sizeof(float*)); |
80 |
if (!m) |
81 |
{ |
82 |
message_alert("Error allocation farray. Please contact Serena Software. The program will now exit!","Utility"); |
83 |
fprintf(pcmlogfile,"error allocating float array\n"); |
84 |
pcmfout(2); |
85 |
exit(0); |
86 |
} |
87 |
m -= nrl; |
88 |
|
89 |
for (i = nrl; i <= nrh; i++) |
90 |
{ |
91 |
m[i] = (float *)malloc((unsigned) (nch-ncl+1)*sizeof(float)); |
92 |
if (!m[i]) |
93 |
{ |
94 |
message_alert("Error allocation farray. Please contact Serena Software. The program will now exit!","Utility"); |
95 |
fprintf(pcmlogfile,"error allocating float array\n"); |
96 |
pcmfout(2); |
97 |
exit(0); |
98 |
} |
99 |
m[i] -= ncl; |
100 |
} |
101 |
return m; |
102 |
} |
103 |
/* ---------------------------------- */ |
104 |
|
105 |
double **dmatrix( int nrl, int nrh, int ncl, int nch) |
106 |
{ |
107 |
int i; |
108 |
double **m; |
109 |
|
110 |
m = (double **)malloc((unsigned) (nrh-nrl+1)*sizeof(double*)); |
111 |
if (!m) |
112 |
{ |
113 |
message_alert("Error allocation darray. Please contact Serena Software. The program will now exit!","Utility"); |
114 |
fprintf(pcmlogfile,"error allocating double array\n"); |
115 |
pcmfout(2); |
116 |
exit(0); |
117 |
} |
118 |
m -= nrl; |
119 |
|
120 |
for (i = nrl; i <= nrh; i++) |
121 |
{ |
122 |
m[i] = (double *)malloc((unsigned) (nch-ncl+1)*sizeof(double)); |
123 |
if (!m[i]) |
124 |
{ |
125 |
message_alert("Error allocation darray. Please contact Serena Software. The program will now exit!","Utility"); |
126 |
fprintf(pcmlogfile,"error allocating double array\n"); |
127 |
pcmfout(2); |
128 |
exit(0); |
129 |
} |
130 |
m[i] -= ncl; |
131 |
} |
132 |
return m; |
133 |
} |
134 |
/* ---------------------------------- */ |
135 |
|
136 |
int **imatrix( int nrl, int nrh, int ncl, int nch) |
137 |
{ |
138 |
int i, **m; |
139 |
|
140 |
m = ( int **)malloc((unsigned) (nrh-nrl+1)*sizeof( int*)); |
141 |
if (!m) |
142 |
{ |
143 |
message_alert("Error allocation iarray. Please contact Serena Software. The program will now exit!","Utility"); |
144 |
fprintf(pcmlogfile,"error allocating array\n"); |
145 |
pcmfout(2); |
146 |
exit(0); |
147 |
} |
148 |
m -= nrl; |
149 |
|
150 |
for (i = nrl; i <= nrh; i++) |
151 |
{ |
152 |
m[i] = ( int *)malloc((unsigned) (nch-ncl+1)*sizeof( int)); |
153 |
if (!m[i]) |
154 |
{ |
155 |
message_alert("Error allocation farray. Please contact Serena Software. The program will now exit!","Utility"); |
156 |
fprintf(pcmlogfile,"error allocating array\n"); |
157 |
pcmfout(2); |
158 |
exit(0); |
159 |
} |
160 |
m[i] -= ncl; |
161 |
} |
162 |
return m; |
163 |
} |
164 |
/* ---------------------------------- */ |
165 |
void free_vector(float *v, int nl, int nh) |
166 |
{ |
167 |
free((char*) (v+nl)); |
168 |
} |
169 |
|
170 |
void free_ivector( int *v, int nl, int nh) |
171 |
{ |
172 |
free((char*) (v+nl)); |
173 |
} |
174 |
void free_ilvector( long int *v, int nl, int nh) |
175 |
{ |
176 |
free((char*) (v+nl)); |
177 |
} |
178 |
|
179 |
void free_dvector(double *v, int nl, int nh) |
180 |
{ |
181 |
free((char*) (v+nl)); |
182 |
} |
183 |
|
184 |
void free_matrix(float **m, int nrl, int nrh, int ncl, int nch) |
185 |
{ |
186 |
int i; |
187 |
for (i=nrh; i >= nrl; i--) |
188 |
{ |
189 |
free((char*) (m[i]+ncl)); |
190 |
} |
191 |
free((char*) (m+nrl)); |
192 |
} |
193 |
|
194 |
void free_imatrix( int **m, int nrl, int nrh, int ncl, int nch) |
195 |
{ |
196 |
int i; |
197 |
for (i=nrh; i >= nrl; i--) |
198 |
{ |
199 |
free((char*) (m[i]+ncl)); |
200 |
} |
201 |
free((char*) (m+nrl)); |
202 |
} |
203 |
|
204 |
void free_dmatrix(double **m, int nrl, int nrh, int ncl, int nch) |
205 |
{ |
206 |
int i; |
207 |
for (i=nrh; i >= nrl; i--) |
208 |
{ |
209 |
free((char*) (m[i]+ncl)); |
210 |
} |
211 |
free((char*) (m+nrl)); |
212 |
} |
213 |
|