1 |
|
|
/* |
2 |
|
|
Teem: Tools to process and visualize scientific data and images . |
3 |
|
|
Copyright (C) 2013, 2012, 2011, 2010, 2009 University of Chicago |
4 |
|
|
Copyright (C) 2008, 2007, 2006, 2005 Gordon Kindlmann |
5 |
|
|
Copyright (C) 2004, 2003, 2002, 2001, 2000, 1999, 1998 University of Utah |
6 |
|
|
|
7 |
|
|
This library is free software; you can redistribute it and/or |
8 |
|
|
modify it under the terms of the GNU Lesser General Public License |
9 |
|
|
(LGPL) as published by the Free Software Foundation; either |
10 |
|
|
version 2.1 of the License, or (at your option) any later version. |
11 |
|
|
The terms of redistributing and/or modifying this software also |
12 |
|
|
include exceptions to the LGPL that facilitate static linking. |
13 |
|
|
|
14 |
|
|
This library is distributed in the hope that it will be useful, |
15 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
16 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
17 |
|
|
Lesser General Public License for more details. |
18 |
|
|
|
19 |
|
|
You should have received a copy of the GNU Lesser General Public License |
20 |
|
|
along with this library; if not, write to Free Software Foundation, Inc., |
21 |
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
22 |
|
|
*/ |
23 |
|
|
|
24 |
|
|
|
25 |
|
|
#include "teem/air.h" |
26 |
|
|
|
27 |
|
|
/* |
28 |
|
|
** to test: |
29 |
|
|
|
30 |
|
|
AIR_EXPORT FILE *airFopen(const char *name, FILE *std, const char *mode); |
31 |
|
|
AIR_EXPORT FILE *airFclose(FILE *file); |
32 |
|
|
AIR_EXPORT int airSinglePrintf(FILE *file, char *str, const char *fmt, ...); |
33 |
|
|
AIR_EXPORT airULLong airIndexULL(double min, double val, double max, |
34 |
|
|
airULLong N); |
35 |
|
|
AIR_EXPORT airULLong airIndexClampULL(double min, double val, double max, |
36 |
|
|
airULLong N); |
37 |
|
|
AIR_EXPORT char *airDoneStr(double start, double here, double end, char *str); |
38 |
|
|
AIR_EXPORT void airBinaryPrintUInt(FILE *file, int digits, unsigned int N); |
39 |
|
|
AIR_EXPORT int airILoad(void *v, int t); |
40 |
|
|
AIR_EXPORT float airFLoad(void *v, int t); |
41 |
|
|
AIR_EXPORT double airDLoad(void *v, int t); |
42 |
|
|
AIR_EXPORT int airIStore(void *v, int t, int i); |
43 |
|
|
AIR_EXPORT float airFStore(void *v, int t, float f); |
44 |
|
|
AIR_EXPORT double airDStore(void *v, int t, double d); |
45 |
|
|
AIR_EXPORT void airEqvAdd(airArray *eqvArr, unsigned int j, unsigned int k); |
46 |
|
|
AIR_EXPORT unsigned int airEqvMap(airArray *eqvArr, |
47 |
|
|
unsigned int *map, unsigned int len); |
48 |
|
|
AIR_EXPORT unsigned int airEqvSettle(unsigned int *map, unsigned int len); |
49 |
|
|
|
50 |
|
|
*/ |
51 |
|
|
|
52 |
|
|
static size_t |
53 |
|
|
multiply(size_t aa, size_t bb) { |
54 |
|
66 |
return aa*bb; |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
int |
58 |
|
|
main(int argc, const char *argv[]) { |
59 |
|
|
const char *me; |
60 |
|
2 |
void *ptr, *ptr2; |
61 |
|
|
|
62 |
|
|
AIR_UNUSED(argc); |
63 |
|
1 |
me = argv[0]; |
64 |
|
|
|
65 |
|
|
/* airNull */ |
66 |
|
|
{ |
67 |
|
1 |
ptr = airNull(); |
68 |
✗✓ |
1 |
if (NULL != ptr) { |
69 |
|
|
fprintf(stderr, "%s: airNull() returned %p not NULL\n", me, ptr); |
70 |
|
|
exit(1); |
71 |
|
|
} |
72 |
|
|
} |
73 |
|
|
|
74 |
|
|
/* airSetNull */ |
75 |
|
|
{ |
76 |
|
1 |
char tmp[10]; |
77 |
|
1 |
ptr = AIR_CAST(void *, tmp); |
78 |
✗✓ |
1 |
if (NULL == ptr) { |
79 |
|
|
fprintf(stderr, "%s: couldn't set a non-NULL pointer", me); |
80 |
|
|
exit(1); |
81 |
|
|
} |
82 |
|
1 |
ptr2 = airSetNull(&ptr); |
83 |
✗✓ |
1 |
if (!(NULL == ptr && NULL == ptr2)) { |
84 |
|
|
fprintf(stderr, "%s: airSetNull() didn't set (%p) or return (%p) NULL\n", |
85 |
|
|
me, ptr, ptr2); |
86 |
|
|
exit(1); |
87 |
|
|
} |
88 |
|
1 |
} |
89 |
|
|
|
90 |
|
|
/* AIR_CALLOC, airFree, airTime */ |
91 |
|
|
{ |
92 |
|
|
size_t big = 1024, times = 1, ii, jj; |
93 |
|
|
double time0, dtime; |
94 |
|
|
unsigned int *data, sum; |
95 |
|
|
big = big*big*128; /* 128 megs */ |
96 |
|
1 |
time0 = airTime(); |
97 |
|
|
sum = 0; |
98 |
✓✓ |
4 |
for (ii=0; ii<times; ii++) { |
99 |
|
|
/* will have a memory leak if airFree() didn't free() */ |
100 |
|
1 |
data = AIR_CALLOC(big, unsigned int); |
101 |
✓✓ |
268435458 |
for (jj=0; jj<big; jj++) { |
102 |
|
134217728 |
sum += data[jj]; |
103 |
|
|
} |
104 |
|
1 |
data = airFree(data); |
105 |
|
|
} |
106 |
✗✓ |
1 |
if (sum) { |
107 |
|
|
fprintf(stderr, "%s: AIR_CALLOC produced non-zero values\n", me); |
108 |
|
|
exit(1); |
109 |
|
|
} |
110 |
✗✓ |
1 |
if (!(NULL == data)) { |
111 |
|
|
fprintf(stderr, "%s: airFree() returned %p not NULL\n", |
112 |
|
|
me, AIR_VOIDP(data)); |
113 |
|
|
exit(1); |
114 |
|
|
} |
115 |
|
1 |
dtime = airTime() - time0; |
116 |
✗✓ |
1 |
if (!( dtime > 0 )) { |
117 |
|
|
fprintf(stderr, "%s: airTime() => nonsense delta time %g\n", me, dtime); |
118 |
|
|
exit(1); |
119 |
|
|
} |
120 |
|
|
} |
121 |
|
|
|
122 |
|
|
/* airStderr, airStdout, airStdin */ |
123 |
|
|
{ |
124 |
|
|
FILE *fret; |
125 |
|
1 |
fret = airStderr(); |
126 |
✗✓ |
1 |
if (stderr != fret) { |
127 |
|
|
fprintf(stderr, "%s: airStderr() returned %p not stderr %p\n", me, |
128 |
|
|
AIR_CAST(void *, fret), AIR_CAST(void *, stderr)); |
129 |
|
|
exit(1); |
130 |
|
|
} |
131 |
|
1 |
fret = airStdout(); |
132 |
✗✓ |
1 |
if (stdout != fret) { |
133 |
|
|
fprintf(stdout, "%s: airStdout() returned %p not stdout %p\n", me, |
134 |
|
|
AIR_CAST(void *, fret), AIR_CAST(void *, stdout)); |
135 |
|
|
exit(1); |
136 |
|
|
} |
137 |
|
1 |
fret = airStdin(); |
138 |
✗✓ |
1 |
if (stdin != fret) { |
139 |
|
|
fprintf(stdin, "%s: airStdin() returned %p not stdin %p\n", me, |
140 |
|
|
AIR_CAST(void *, fret), AIR_CAST(void *, stdin)); |
141 |
|
|
exit(1); |
142 |
|
|
} |
143 |
|
|
} |
144 |
|
|
|
145 |
|
|
/* airIndex, airIndexClamp */ |
146 |
|
|
{ |
147 |
|
|
/* admittedly this not much of a test; mainly it serves to |
148 |
|
|
demonstrate how the intervals are divided for N=4 */ |
149 |
|
|
unsigned int N=4; |
150 |
|
|
double min=0.0, max=1.0; |
151 |
|
1 |
double val[]={0.000, 0.001, 0.249, |
152 |
|
|
0.251, 0.400, 0.499, |
153 |
|
|
0.501, 0.700, 0.749, |
154 |
|
|
0.751, 0.999, 1.000}; |
155 |
|
1 |
unsigned int wantIdx[]={0, 0, 0, |
156 |
|
|
1, 1, 1, |
157 |
|
|
2, 2, 2, |
158 |
|
|
3, 3, 3}; |
159 |
|
|
unsigned int vn, vi, ii, ci; |
160 |
|
|
vn = sizeof(wantIdx)/sizeof(unsigned int); |
161 |
✓✓ |
26 |
for (vi=0; vi<vn; vi++) { |
162 |
|
12 |
ii = airIndex(min, val[vi], max, N); |
163 |
|
12 |
ci = airIndexClamp(min, val[vi], max, N); |
164 |
✗✓ |
12 |
if (ii != wantIdx[vi]) { |
165 |
|
|
fprintf(stderr, "%s: %u = airIndex(%.17g, %.17g, %.17g, %u) " |
166 |
|
|
"!= correct %u\n", me, ii, min, val[vi], max, N, wantIdx[vi]); |
167 |
|
|
exit(1); |
168 |
|
|
} |
169 |
✗✓ |
12 |
if (ci != wantIdx[vi]) { |
170 |
|
|
fprintf(stderr, "%s: %u = airIndexClamp(%.17g, %.17g, %.17g, %u) " |
171 |
|
|
"!= correct %u\n", me, ci, min, val[vi], max, N, wantIdx[vi]); |
172 |
|
|
exit(1); |
173 |
|
|
} |
174 |
|
|
} |
175 |
|
1 |
} |
176 |
|
|
|
177 |
|
|
/* airSprintSize_t, airSprintPtrdiff_t in pptest.c */ |
178 |
|
|
|
179 |
|
|
/* airPrettySprintSize_t */ |
180 |
|
|
{ |
181 |
|
1 |
char prstmp[AIR_STRLEN_SMALL]; |
182 |
|
1 |
size_t vals[] = {0, /* 0 */ |
183 |
|
|
800, /* 1 */ |
184 |
|
|
1024, /* 2 = 2^10 */ |
185 |
|
|
1024 + 1, /* 3 */ |
186 |
|
|
500*1024, /* 4 */ |
187 |
|
|
1024*1024, /* 5 = 2^20 */ |
188 |
|
|
1024*(1024 + 1), /* 6 */ |
189 |
|
|
500*1024*1024, /* 7 */ |
190 |
|
|
1024*1024*1024ul, /* 8 = 2^30 */ |
191 |
|
|
1024*1024*(1024ul + 1), /* 9 */ |
192 |
|
|
500*1024ul, /* 10 (will be multiplied below) */ |
193 |
|
|
1024*1024ul, /* 11 = 2^40 */ |
194 |
|
|
1024*(1024ul + 1), /* 12 */ |
195 |
|
|
500*1024*1024, /* 13 */ |
196 |
|
|
1024*1024*1024ul, /* 14 = 2^50 */ |
197 |
|
|
1024*1024*(1024ul + 1), /* 15 */ |
198 |
|
|
500*1024*1024, /* 16 */ |
199 |
|
|
1024*1024*1024ul, /* 17 = 2^60 */ |
200 |
|
|
1024*1024*(1024ul + 1), /* 18 */ |
201 |
|
|
2*1024*1024ul, /* 19 = 2^61 */ |
202 |
|
|
16*1023*1024ul, /* 20 */ |
203 |
|
|
16*1024*1024ul, /* 21 = 2^64 */ |
204 |
|
|
0}; |
205 |
|
|
static const char * const string[] = { |
206 |
|
|
"0 bytes", /* 0 */ |
207 |
|
|
"800 bytes", /* 1 */ |
208 |
|
|
"1024 bytes", /* 2 */ |
209 |
|
|
"1.00098 KB", /* 3 */ |
210 |
|
|
"500 KB", /* 4 */ |
211 |
|
|
"1024 KB", /* 5 */ |
212 |
|
|
"1.00098 MB", /* 6 */ |
213 |
|
|
"500 MB", /* 7 */ |
214 |
|
|
"1024 MB", /* 8 */ |
215 |
|
|
"1.00098 GB", /* 9 */ |
216 |
|
|
"500 GB", /* 10 */ |
217 |
|
|
"1024 GB", /* 11 */ |
218 |
|
|
"1.00098 TB", /* 12 */ |
219 |
|
|
"500 TB", /* 13 */ |
220 |
|
|
"1024 TB", /* 14 */ |
221 |
|
|
"1.00098 PB", /* 15 */ |
222 |
|
|
"500 PB", /* 16 */ |
223 |
|
|
"1024 PB", /* 17 */ |
224 |
|
|
"1.00098 EB", /* 18 */ |
225 |
|
|
"2 EB", /* 19 */ |
226 |
|
|
"15.9844 EB", /* 20 */ |
227 |
|
|
"blah", /* 21 */ |
228 |
|
|
}; |
229 |
|
|
unsigned int ii; |
230 |
|
|
/* hiding some multiplications in function calls, |
231 |
|
|
to quiet compiler warnings. Its ok if there is |
232 |
|
|
wrap-around here because then we'll stop testing. |
233 |
|
|
However, it would be better if we did NOT rely on |
234 |
|
|
what is strictly speaking undefined behavior: the |
235 |
|
|
overflow of *unsigned* integral quantities. */ |
236 |
|
1 |
vals[10] = multiply(multiply(vals[10], 1024), 1024); |
237 |
|
1 |
vals[11] = multiply(multiply(vals[11], 1024), 1024); |
238 |
|
1 |
vals[12] = multiply(multiply(vals[12], 1024), 1024); |
239 |
|
1 |
vals[13] = multiply(multiply(vals[13], 1024), 1024); |
240 |
|
1 |
vals[14] = multiply(multiply(vals[14], 1024), 1024); |
241 |
|
1 |
vals[15] = multiply(multiply(vals[15], 1024), 1024); |
242 |
|
1 |
vals[16] = multiply(multiply(multiply(vals[16], 1024), 1024), 1024); |
243 |
|
1 |
vals[17] = multiply(multiply(multiply(vals[17], 1024), 1024), 1024); |
244 |
|
1 |
vals[18] = multiply(multiply(multiply(vals[18], 1024), 1024), 1024); |
245 |
|
1 |
vals[19] = multiply(multiply(multiply(multiply(vals[19], 1024), 1024), 1024), 1024); |
246 |
|
1 |
vals[20] = multiply(multiply(multiply(multiply(vals[20], 1024), 1024), 1024), 1024); |
247 |
|
1 |
vals[21] = multiply(multiply(multiply(multiply(vals[21], 1024), 1024), 1024), 1024); |
248 |
✓✓✓✓
|
65 |
for (ii=0; !ii || vals[ii] > vals[ii-1]; ii++) { |
249 |
|
21 |
airPrettySprintSize_t(prstmp, vals[ii]); |
250 |
✗✓✗✓
|
42 |
if (strcmp(string[ii], prstmp)) { |
251 |
|
21 |
fprintf(stderr, "%s: airPrettySprintSize_t made |%s| not |%s|\n", |
252 |
|
|
me, prstmp, string[ii]); |
253 |
|
|
exit(1); |
254 |
|
|
} |
255 |
|
21 |
fprintf(stderr, "%u: %s\n", ii, prstmp); |
256 |
|
|
} |
257 |
|
1 |
} |
258 |
|
|
|
259 |
|
|
|
260 |
|
1 |
exit(0); |
261 |
|
|
} |
262 |
|
|
|
263 |
|
|
|
264 |
|
|
|