1 | /* --------------- */ |
---|
2 | /* --- nrio3.c --- */ |
---|
3 | /* --------------- */ |
---|
4 | |
---|
5 | /* |
---|
6 | * Copyright (c) 2000-2014, Lionel Lacassagne, All rights reserved |
---|
7 | * Univ Paris Sud XI, CNRS |
---|
8 | * |
---|
9 | * Distributed under the Boost Software License, Version 1.0 |
---|
10 | * see accompanying file LICENSE.txt or copy it at |
---|
11 | * http://www.boost.org/LICENSE_1_0.txt |
---|
12 | */ |
---|
13 | |
---|
14 | #include <stdio.h> |
---|
15 | #include <stddef.h> |
---|
16 | #include <stdlib.h> |
---|
17 | |
---|
18 | #include "nrc_os_config.h" |
---|
19 | #include "mypredef.h" |
---|
20 | #include "nrtype.h" |
---|
21 | #include "nrdef.h" |
---|
22 | #include "nrmacro.h" |
---|
23 | #include "nrkernel.h" |
---|
24 | |
---|
25 | #include "nralloc1.h" |
---|
26 | #include "nrio3.h" |
---|
27 | |
---|
28 | |
---|
29 | /* -------------------- */ |
---|
30 | /* --- display_cube --- */ |
---|
31 | /* -------------------- */ |
---|
32 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
---|
33 | IMAGE_EXPORT(void) display_i8cube(int8 ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
34 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
---|
35 | { |
---|
36 | long i,j,k; |
---|
37 | |
---|
38 | if(name != NULL) puts(name); |
---|
39 | |
---|
40 | for(k=ndl; k<=ndh; k++) { |
---|
41 | for(i=nrl; i<=nrh; i++) { |
---|
42 | for(j=ncl; j<=nch; j++) { |
---|
43 | printf(format, c[k][i][j]); |
---|
44 | } |
---|
45 | putchar('\n'); |
---|
46 | } |
---|
47 | putchar('\n'); |
---|
48 | } |
---|
49 | } |
---|
50 | /* --------------------------------------------------------------------------------------------------------------------------- */ |
---|
51 | IMAGE_EXPORT(void) display_i16cube(int16 ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
52 | /* --------------------------------------------------------------------------------------------------------------------------- */ |
---|
53 | { |
---|
54 | long i,j,k; |
---|
55 | |
---|
56 | if(name != NULL) puts(name); |
---|
57 | |
---|
58 | for(k=ndl; k<=ndh; k++) { |
---|
59 | for(i=nrl; i<=nrh; i++) { |
---|
60 | for(j=ncl; j<=nch; j++) { |
---|
61 | printf(format, c[k][i][j]); |
---|
62 | } |
---|
63 | putchar('\n'); |
---|
64 | } |
---|
65 | putchar('\n'); |
---|
66 | } |
---|
67 | } |
---|
68 | /* ----------------------------------------------------------------------------------------------------------------------------- */ |
---|
69 | IMAGE_EXPORT(void) display_ui16cube(uint16 ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
70 | /* ----------------------------------------------------------------------------------------------------------------------------- */ |
---|
71 | { |
---|
72 | long i,j,k; |
---|
73 | |
---|
74 | if(name != NULL) puts(name); |
---|
75 | |
---|
76 | for(k=ndl; k<=ndh; k++) { |
---|
77 | for(i=nrl; i<=nrh; i++) { |
---|
78 | for(j=ncl; j<=nch; j++) { |
---|
79 | printf(format, c[k][i][j]); |
---|
80 | } |
---|
81 | putchar('\n'); |
---|
82 | } |
---|
83 | putchar('\n'); |
---|
84 | } |
---|
85 | } |
---|
86 | /* --------------------------------------------------------------------------------------------------------------------------- */ |
---|
87 | IMAGE_EXPORT(void) display_i32cube(int32 ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
88 | /* --------------------------------------------------------------------------------------------------------------------------- */ |
---|
89 | { |
---|
90 | long i,j,k; |
---|
91 | |
---|
92 | if(name != NULL) puts(name); |
---|
93 | |
---|
94 | for(k=ndl; k<=ndh; k++) { |
---|
95 | for(i=nrl; i<=nrh; i++) { |
---|
96 | for(j=ncl; j<=nch; j++) { |
---|
97 | printf(format, c[k][i][j]); |
---|
98 | } |
---|
99 | putchar('\n'); |
---|
100 | } |
---|
101 | putchar('\n'); |
---|
102 | } |
---|
103 | } |
---|
104 | /* ----------------------------------------------------------------------------------------------------------------------------- */ |
---|
105 | IMAGE_EXPORT(void) display_ui32cube(uint32 ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
106 | /* ----------------------------------------------------------------------------------------------------------------------------- */ |
---|
107 | { |
---|
108 | long i,j,k; |
---|
109 | |
---|
110 | if(name != NULL) puts(name); |
---|
111 | |
---|
112 | for(k=ndl; k<=ndh; k++) { |
---|
113 | for(i=nrl; i<=nrh; i++) { |
---|
114 | for(j=ncl; j<=nch; j++) { |
---|
115 | printf(format, c[k][i][j]); |
---|
116 | } |
---|
117 | putchar('\n'); |
---|
118 | } |
---|
119 | putchar('\n'); |
---|
120 | } |
---|
121 | } |
---|
122 | /* --------------------------------------------------------------------------------------------------------------------------- */ |
---|
123 | IMAGE_EXPORT(void) display_i64cube(int64 ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
124 | /* --------------------------------------------------------------------------------------------------------------------------- */ |
---|
125 | { |
---|
126 | long i,j,k; |
---|
127 | |
---|
128 | if(name != NULL) puts(name); |
---|
129 | |
---|
130 | for(k=ndl; k<=ndh; k++) { |
---|
131 | for(i=nrl; i<=nrh; i++) { |
---|
132 | for(j=ncl; j<=nch; j++) { |
---|
133 | printf(format, c[k][i][j]); |
---|
134 | } |
---|
135 | putchar('\n'); |
---|
136 | } |
---|
137 | putchar('\n'); |
---|
138 | } |
---|
139 | } |
---|
140 | /* ----------------------------------------------------------------------------------------------------------------------------- */ |
---|
141 | IMAGE_EXPORT(void) display_f32cube(float32 ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name) |
---|
142 | /* ----------------------------------------------------------------------------------------------------------------------------- */ |
---|
143 | { |
---|
144 | long i,j,k; |
---|
145 | |
---|
146 | if(name != NULL) puts(name); |
---|
147 | |
---|
148 | for(k=ndl; k<=ndh; k++) { |
---|
149 | for(i=nrl; i<=nrh; i++) { |
---|
150 | for(j=ncl; j<=nch; j++) { |
---|
151 | printf(format, c[k][i][j]); |
---|
152 | } |
---|
153 | putchar('\n'); |
---|
154 | } |
---|
155 | putchar('\n'); |
---|
156 | } |
---|
157 | } |
---|
158 | |
---|
159 | /* ---------------- */ |
---|
160 | /* -- write_cube -- */ |
---|
161 | /* ---------------- */ |
---|
162 | /* ------------------------------------------------------------------------------------------------------------------------------ */ |
---|
163 | IMAGE_EXPORT(void) write_i8cube(int8 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename) |
---|
164 | /* ------------------------------------------------------------------------------------------------------------------------------ */ |
---|
165 | { |
---|
166 | int i, j, k; |
---|
167 | |
---|
168 | FILE *f; |
---|
169 | |
---|
170 | f = fopen(filename, "wt"); |
---|
171 | if(f == NULL) { |
---|
172 | nrerror("Can't open file in write_i8cube"); |
---|
173 | } |
---|
174 | |
---|
175 | for(k=ndl; k<=ndh; k++) { |
---|
176 | for(i=nrl; i<=nrh; i++) { |
---|
177 | for(j=ncl; j<=nch; j++) { |
---|
178 | fprintf(f, format, c[k][i][j]); |
---|
179 | } |
---|
180 | fputc('\n', f); |
---|
181 | } |
---|
182 | fputc('\n', f); |
---|
183 | } |
---|
184 | |
---|
185 | fclose(f); |
---|
186 | } |
---|
187 | /* -------------------------------------------------------------------------------------------------------------------------------- */ |
---|
188 | IMAGE_EXPORT(void) write_i16cube(int16 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename) |
---|
189 | /* -------------------------------------------------------------------------------------------------------------------------------- */ |
---|
190 | { |
---|
191 | int i, j, k; |
---|
192 | |
---|
193 | FILE *f; |
---|
194 | |
---|
195 | f = fopen(filename, "wt"); |
---|
196 | if(f == NULL) { |
---|
197 | nrerror("Can't open file in write_i16cube"); |
---|
198 | } |
---|
199 | |
---|
200 | for(k=ndl; k<=ndh; k++) { |
---|
201 | for(i=nrl; i<=nrh; i++) { |
---|
202 | for(j=ncl; j<=nch; j++) { |
---|
203 | fprintf(f, format, c[k][i][j]); |
---|
204 | } |
---|
205 | fputc('\n', f); |
---|
206 | } |
---|
207 | fputc('\n', f); |
---|
208 | } |
---|
209 | |
---|
210 | fclose(f); |
---|
211 | } |
---|
212 | /* ---------------------------------------------------------------------------------------------------------------------------------- */ |
---|
213 | IMAGE_EXPORT(void) write_ui16cube(uint16 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename) |
---|
214 | /* ---------------------------------------------------------------------------------------------------------------------------------- */ |
---|
215 | { |
---|
216 | int i, j, k; |
---|
217 | |
---|
218 | FILE *f; |
---|
219 | |
---|
220 | f = fopen(filename, "wt"); |
---|
221 | if(f == NULL) { |
---|
222 | nrerror("Can't open file in write_ui16cube"); |
---|
223 | } |
---|
224 | |
---|
225 | for(k=ndl; k<=ndh; k++) { |
---|
226 | for(i=nrl; i<=nrh; i++) { |
---|
227 | for(j=ncl; j<=nch; j++) { |
---|
228 | fprintf(f, format, c[k][i][j]); |
---|
229 | } |
---|
230 | fputc('\n', f); |
---|
231 | } |
---|
232 | fputc('\n', f); |
---|
233 | } |
---|
234 | |
---|
235 | fclose(f); |
---|
236 | } |
---|
237 | /* -------------------------------------------------------------------------------------------------------------------------------- */ |
---|
238 | IMAGE_EXPORT(void) write_i32cube(int32 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename) |
---|
239 | /* -------------------------------------------------------------------------------------------------------------------------------- */ |
---|
240 | { |
---|
241 | int i, j, k; |
---|
242 | |
---|
243 | FILE *f; |
---|
244 | |
---|
245 | f = fopen(filename, "wt"); |
---|
246 | if(f == NULL) { |
---|
247 | nrerror("Can't open file in write_i32cube"); |
---|
248 | } |
---|
249 | |
---|
250 | for(k=ndl; k<=ndh; k++) { |
---|
251 | for(i=nrl; i<=nrh; i++) { |
---|
252 | for(j=ncl; j<=nch; j++) { |
---|
253 | fprintf(f, format, c[k][i][j]); |
---|
254 | } |
---|
255 | fputc('\n', f); |
---|
256 | } |
---|
257 | fputc('\n', f); |
---|
258 | } |
---|
259 | |
---|
260 | fclose(f); |
---|
261 | } |
---|
262 | /* ---------------------------------------------------------------------------------------------------------------------------------- */ |
---|
263 | IMAGE_EXPORT(void) write_ui32cube(uint32 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename) |
---|
264 | /* ---------------------------------------------------------------------------------------------------------------------------------- */ |
---|
265 | { |
---|
266 | int i, j, k; |
---|
267 | |
---|
268 | FILE *f; |
---|
269 | |
---|
270 | f = fopen(filename, "wt"); |
---|
271 | if(f == NULL) { |
---|
272 | nrerror("Can't open file in write_ui32cube"); |
---|
273 | } |
---|
274 | |
---|
275 | for(k=ndl; k<=ndh; k++) { |
---|
276 | for(i=nrl; i<=nrh; i++) { |
---|
277 | for(j=ncl; j<=nch; j++) { |
---|
278 | fprintf(f, format, c[k][i][j]); |
---|
279 | } |
---|
280 | fputc('\n', f); |
---|
281 | } |
---|
282 | fputc('\n', f); |
---|
283 | } |
---|
284 | |
---|
285 | fclose(f); |
---|
286 | } |
---|
287 | /* -------------------------------------------------------------------------------------------------------------------------------- */ |
---|
288 | IMAGE_EXPORT(void) write_i64cube(int64 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename) |
---|
289 | /* -------------------------------------------------------------------------------------------------------------------------------- */ |
---|
290 | { |
---|
291 | int i, j, k; |
---|
292 | |
---|
293 | FILE *f; |
---|
294 | |
---|
295 | f = fopen(filename, "wt"); |
---|
296 | if(f == NULL) { |
---|
297 | nrerror("Can't open file in write_i64cube"); |
---|
298 | } |
---|
299 | |
---|
300 | for(k=ndl; k<=ndh; k++) { |
---|
301 | for(i=nrl; i<=nrh; i++) { |
---|
302 | for(j=ncl; j<=nch; j++) { |
---|
303 | fprintf(f, format, c[k][i][j]); |
---|
304 | } |
---|
305 | fputc('\n', f); |
---|
306 | } |
---|
307 | fputc('\n', f); |
---|
308 | } |
---|
309 | |
---|
310 | fclose(f); |
---|
311 | } |
---|
312 | /* ---------------------------------------------------------------------------------------------------------------------------------- */ |
---|
313 | IMAGE_EXPORT(void) write_f32cube(float32 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename) |
---|
314 | /* ---------------------------------------------------------------------------------------------------------------------------------- */ |
---|
315 | { |
---|
316 | int i, j, k; |
---|
317 | |
---|
318 | FILE *f; |
---|
319 | |
---|
320 | f = fopen(filename, "wt"); |
---|
321 | if(f == NULL) { |
---|
322 | nrerror("Can't open file in write_f32cube"); |
---|
323 | } |
---|
324 | |
---|
325 | for(k=ndl; k<=ndh; k++) { |
---|
326 | for(i=nrl; i<=nrh; i++) { |
---|
327 | for(j=ncl; j<=nch; j++) { |
---|
328 | fprintf(f, format, c[k][i][j]); |
---|
329 | } |
---|
330 | fputc('\n', f); |
---|
331 | } |
---|
332 | fputc('\n', f); |
---|
333 | } |
---|
334 | |
---|
335 | fclose(f); |
---|
336 | } |
---|
337 | |
---|
338 | /* ---------------- */ |
---|
339 | /* -- fread_cube -- */ |
---|
340 | /* ---------------- */ |
---|
341 | /* ----------------------------------------------------------------------------------------------------------- */ |
---|
342 | IMAGE_EXPORT(void) fread_i8cube(char *filename, int8 ***c,long ndl,long ndh,long nrl,long nrh,long ncl, long nch) |
---|
343 | /* ----------------------------------------------------------------------------------------------------------- */ |
---|
344 | { |
---|
345 | long i, k; |
---|
346 | long ncol = nch-ncl+1, nread; |
---|
347 | FILE *f; |
---|
348 | |
---|
349 | f = fopen(filename, "rb"); |
---|
350 | if(f == NULL) |
---|
351 | nrerror("Can't open file in fread_i8cube"); |
---|
352 | |
---|
353 | |
---|
354 | for(k=ndl; k<=ndh; k++) { |
---|
355 | for(i=nrl; i<=nrh; i++) { |
---|
356 | nread = fread( &(c[k][i][ncl]), sizeof(int8), ncol, f); |
---|
357 | if(nread != ncol) nrerror("fread_i8cube : can't write data"); |
---|
358 | } |
---|
359 | } |
---|
360 | fclose(f); |
---|
361 | } |
---|
362 | /* ------------------------------------------------------------------------------------------------------------- */ |
---|
363 | IMAGE_EXPORT(void) fread_i16cube(char *filename, int16 ***c,long ndl,long ndh,long nrl,long nrh,long ncl, long nch) |
---|
364 | /* ------------------------------------------------------------------------------------------------------------- */ |
---|
365 | { |
---|
366 | long i, k; |
---|
367 | long ncol = nch-ncl+1, nread; |
---|
368 | FILE *f; |
---|
369 | |
---|
370 | f = fopen(filename, "rb"); |
---|
371 | if(f == NULL) |
---|
372 | nrerror("Can't open file in fread_i16cube"); |
---|
373 | |
---|
374 | for(k=ndl; k<=ndh; k++) { |
---|
375 | for(i=nrl; i<=nrh; i++) { |
---|
376 | nread = fread( &(c[k][i][ncl]), sizeof(int16), ncol, f); |
---|
377 | if(nread != ncol) nrerror("fread_i16cube : can't write data"); |
---|
378 | } |
---|
379 | } |
---|
380 | fclose(f); |
---|
381 | } |
---|
382 | /* -------------------------------------------------------------------------------------------------------------------- */ |
---|
383 | IMAGE_EXPORT(void) fread_ui16cube(char *filename, uint16 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch) |
---|
384 | /* -------------------------------------------------------------------------------------------------------------------- */ |
---|
385 | { |
---|
386 | long i, k; |
---|
387 | long ncol = nch-ncl+1, nread; |
---|
388 | FILE *f; |
---|
389 | |
---|
390 | f = fopen(filename, "rb"); |
---|
391 | if(f == NULL) |
---|
392 | nrerror("Can't open file in fread_ui16cube"); |
---|
393 | |
---|
394 | |
---|
395 | for(k=ndl; k<=ndh; k++) { |
---|
396 | for(i=nrl; i<=nrh; i++) { |
---|
397 | nread = fread( &(c[k][i][ncl]), sizeof(uint16), ncol, f); |
---|
398 | if(nread != ncol) nrerror("fread_ui16cube : can't write data"); |
---|
399 | } |
---|
400 | } |
---|
401 | fclose(f); |
---|
402 | } |
---|
403 | /* ------------------------------------------------------------------------------------------------------------------ */ |
---|
404 | IMAGE_EXPORT(void) fread_i32cube(char *filename, int32 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch) |
---|
405 | /* ------------------------------------------------------------------------------------------------------------------ */ |
---|
406 | { |
---|
407 | long i, k; |
---|
408 | long ncol = nch-ncl+1, nread; |
---|
409 | FILE *f; |
---|
410 | |
---|
411 | f = fopen(filename, "rb"); |
---|
412 | if(f == NULL) |
---|
413 | nrerror("Can't open file in fread_i32cube"); |
---|
414 | |
---|
415 | |
---|
416 | for(k=ndl; k<=ndh; k++) { |
---|
417 | for(i=nrl; i<=nrh; i++) { |
---|
418 | nread = fread( &(c[k][i][ncl]), sizeof(int32), ncol, f); |
---|
419 | if(nread != ncol) nrerror("fread_i32cube : can't write data"); |
---|
420 | } |
---|
421 | } |
---|
422 | fclose(f); |
---|
423 | } |
---|
424 | /* --------------- */ |
---|
425 | /* --- nrio3.h --- */ |
---|
426 | /* --------------- */ |
---|
427 | |
---|
428 | #ifndef __NRIO3_H__ |
---|
429 | #define __NRIO3_H__ |
---|
430 | |
---|
431 | #ifdef __cplusplus |
---|
432 | #pragma message ("C++") |
---|
433 | extern "C" { |
---|
434 | #endif |
---|
435 | |
---|
436 | /* ------------------ */ |
---|
437 | /* --- fread_cube --- */ |
---|
438 | /* ------------------ */ |
---|
439 | |
---|
440 | IMAGE_EXPORT(void) fread_ui32cube(char *filename, uint32 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch); |
---|
441 | IMAGE_EXPORT(void) fread_i64cube (char *filename, int64 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch); |
---|
442 | IMAGE_EXPORT(void) fread_f32cube (char *filename, float32 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch); |
---|
443 | |
---|
444 | /* ----------------- */ |
---|
445 | /* -- fwrite_cube -- */ |
---|
446 | /* ----------------- */ |
---|
447 | |
---|
448 | IMAGE_EXPORT(void) fwrite_i8cube(int8 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *filename); |
---|
449 | IMAGE_EXPORT(void) fwrite_i16cube(int16 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *filename); |
---|
450 | IMAGE_EXPORT(void) fwrite_ui16cube(uint16 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *filename); |
---|
451 | IMAGE_EXPORT(void) fwrite_i32cube(int32 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *filename); |
---|
452 | IMAGE_EXPORT(void) fwrite_ui32cube(uint32 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *filename); |
---|
453 | IMAGE_EXPORT(void) fwrite_i64cube(int64 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *filename); |
---|
454 | |
---|
455 | #ifdef __cplusplus |
---|
456 | } |
---|
457 | #endif |
---|
458 | |
---|
459 | #endif /* __NRIO3_H__ */ |
---|