source: soft/giet_vm/applications/rosenfeld/nrc2/src/nrio3.c @ 823

Last change on this file since 823 was 823, checked in by meunier, 8 years ago
  • Improved scripts for simulations and graphes
  • Continued to clean up the lib nrc2 (from nrio2x.x to nrmem1.c)
  • Added a version (Fast - Parmerge - No stats)
File size: 5.1 KB
Line 
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) \
35void 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
51display_type_cube(int8_t);
52display_type_cube(uint8_t);
53display_type_cube(int16_t);
54display_type_cube(uint16_t);
55display_type_cube(int32_t);
56display_type_cube(uint32_t);
57display_type_cube(int64_t);
58display_type_cube(uint64_t);
59display_type_cube(float);
60display_type_cube(double);
61
62
63
64/* ---------------- */
65/* -- write_cube -- */
66/* ---------------- */
67
68#undef write_type_cube
69#define write_type_cube(t) \
70void 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
88write_type_cube(int8_t);
89write_type_cube(uint8_t);
90write_type_cube(int16_t);
91write_type_cube(uint16_t);
92write_type_cube(int32_t);
93write_type_cube(uint32_t);
94write_type_cube(int64_t);
95write_type_cube(uint64_t);
96write_type_cube(float);
97write_type_cube(double);
98
99
100
101/* ---------------- */
102/* -- fread_cube -- */
103/* ---------------- */
104
105#undef fread_type_cube
106#define fread_type_cube(t) \
107void 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
125fread_type_cube(int8_t);
126fread_type_cube(uint8_t);
127fread_type_cube(int16_t);
128fread_type_cube(uint16_t);
129fread_type_cube(int32_t);
130fread_type_cube(uint32_t);
131fread_type_cube(int64_t);
132fread_type_cube(uint64_t);
133fread_type_cube(float);
134fread_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
Note: See TracBrowser for help on using the repository browser.