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 | #undef display_type_cube |
---|
34 | #define display_type_cube(t) \ |
---|
35 | void short_name(t,display_,cube)(t *** c, int32_t ndl, int32_t ndh, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * format, char * name) \ |
---|
36 | { \ |
---|
37 | if (name != NULL) { \ |
---|
38 | printf(name); \ |
---|
39 | } \ |
---|
40 | for (int32_t k = ndl; k <= ndh; k++) { \ |
---|
41 | for (int32_t i = nrl; i <= nrh; i++) { \ |
---|
42 | for (int32_t j = ncl; j <= nch; j++) { \ |
---|
43 | printf(format, c[k][i][j]); \ |
---|
44 | } \ |
---|
45 | printf("\n"); \ |
---|
46 | } \ |
---|
47 | printf("\n"); \ |
---|
48 | } \ |
---|
49 | } |
---|
50 | |
---|
51 | display_type_cube(int8_t); |
---|
52 | display_type_cube(uint8_t); |
---|
53 | display_type_cube(int16_t); |
---|
54 | display_type_cube(uint16_t); |
---|
55 | display_type_cube(int32_t); |
---|
56 | display_type_cube(uint32_t); |
---|
57 | display_type_cube(int64_t); |
---|
58 | display_type_cube(uint64_t); |
---|
59 | display_type_cube(float); |
---|
60 | display_type_cube(double); |
---|
61 | |
---|
62 | |
---|
63 | |
---|
64 | /* ---------------- */ |
---|
65 | /* -- write_cube -- */ |
---|
66 | /* ---------------- */ |
---|
67 | |
---|
68 | #undef write_type_cube |
---|
69 | #define write_type_cube(t) \ |
---|
70 | void short_name(t,write_,cube)(t *** c, int32_t ndl, int32_t ndh, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * format, char * filename) \ |
---|
71 | { \ |
---|
72 | FILE * f = fopen(filename, "wt"); \ |
---|
73 | if (f == NULL) { \ |
---|
74 | nrerror("Can't open file %s in %s", filename, __func__); \ |
---|
75 | } \ |
---|
76 | for (int32_t k = ndl; k <= ndh; k++) { \ |
---|
77 | for (int32_t i = nrl; i <= nrh; i++) { \ |
---|
78 | for (int32_t j = ncl; j <= nch; j++) { \ |
---|
79 | fprintf(f, format, c[k][i][j]); \ |
---|
80 | } \ |
---|
81 | fprintf(f, "\n"); \ |
---|
82 | } \ |
---|
83 | fprintf(f, "\n"); \ |
---|
84 | } \ |
---|
85 | fclose(f); \ |
---|
86 | } |
---|
87 | |
---|
88 | write_type_cube(int8_t); |
---|
89 | write_type_cube(uint8_t); |
---|
90 | write_type_cube(int16_t); |
---|
91 | write_type_cube(uint16_t); |
---|
92 | write_type_cube(int32_t); |
---|
93 | write_type_cube(uint32_t); |
---|
94 | write_type_cube(int64_t); |
---|
95 | write_type_cube(uint64_t); |
---|
96 | write_type_cube(float); |
---|
97 | write_type_cube(double); |
---|
98 | |
---|
99 | |
---|
100 | |
---|
101 | /* ---------------- */ |
---|
102 | /* -- fread_cube -- */ |
---|
103 | /* ---------------- */ |
---|
104 | |
---|
105 | #undef fread_type_cube |
---|
106 | #define fread_type_cube(t) \ |
---|
107 | void short_name(t,fread_,cube)(t *** c, int32_t ndl, int32_t ndh, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * format, char * filename) \ |
---|
108 | { \ |
---|
109 | int32_t ncol = nch - ncl + 1; \ |
---|
110 | FILE * f = fopen(filename, "rb"); \ |
---|
111 | if (f == NULL) { \ |
---|
112 | nrerror("Can't open file %s in %s", filename, __func__); \ |
---|
113 | } \ |
---|
114 | for (int32_t k = ndl; k <= ndh; k++) { \ |
---|
115 | for (int32_t i = nrl; i <= nrh; i++) { \ |
---|
116 | int32_t nread = fread(&c[k][i][ncl], sizeof(t), ncol, f); \ |
---|
117 | if (nread != ncol) { \ |
---|
118 | nrerror("%s: Can't write data", __func__); \ |
---|
119 | } \ |
---|
120 | } \ |
---|
121 | } \ |
---|
122 | fclose(f); \ |
---|
123 | } |
---|
124 | |
---|
125 | fread_type_cube(int8_t); |
---|
126 | fread_type_cube(uint8_t); |
---|
127 | fread_type_cube(int16_t); |
---|
128 | fread_type_cube(uint16_t); |
---|
129 | fread_type_cube(int32_t); |
---|
130 | fread_type_cube(uint32_t); |
---|
131 | fread_type_cube(int64_t); |
---|
132 | fread_type_cube(uint64_t); |
---|
133 | fread_type_cube(float); |
---|
134 | fread_type_cube(double); |
---|
135 | |
---|
136 | |
---|
137 | |
---|
138 | |
---|
139 | |
---|
140 | |
---|
141 | // Local Variables: |
---|
142 | // tab-width: 4 |
---|
143 | // c-basic-offset: 4 |
---|
144 | // c-file-offsets:((innamespace . 0)(inline-open . 0)) |
---|
145 | // indent-tabs-mode: nil |
---|
146 | // End: |
---|
147 | |
---|
148 | // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 |
---|
149 | |
---|