Changeset 823 for soft/giet_vm/applications/rosenfeld/nrc2/src/nrio3.c
- Timestamp:
- Jun 14, 2016, 5:23:56 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
soft/giet_vm/applications/rosenfeld/nrc2/src/nrio3.c
r772 r823 30 30 /* --- display_cube --- */ 31 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 32 38 if(name != NULL) puts(name); 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 } 39 50 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; 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); 55 61 56 if(name != NULL) puts(name);57 62 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 63 159 64 /* ---------------- */ 160 65 /* -- write_cube -- */ 161 66 /* ---------------- */ 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 67 168 FILE *f; 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 } 169 87 170 f = fopen(filename, "wt"); 171 if(f == NULL) { 172 nrerror("Can't open file in write_i8cube"); 173 } 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); 174 98 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 99 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 100 338 101 /* ---------------- */ 339 102 /* -- fread_cube -- */ 340 103 /* ---------------- */ 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 104 349 f = fopen(filename, "rb"); 350 if(f == NULL) 351 nrerror("Can't open file in fread_i8cube"); 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); 352 135 353 136 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 137 394 138 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 139 415 140 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 /* --------------- */ 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: 427 147 428 #ifndef __NRIO3_H__ 429 #define __NRIO3_H__ 148 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 430 149 431 #ifdef __cplusplus432 #pragma message ("C++")433 extern "C" {434 #endif435 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 __cplusplus456 }457 #endif458 459 #endif /* __NRIO3_H__ */
Note: See TracChangeset
for help on using the changeset viewer.