Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nrio3.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrio3.c	(revision 772)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrio3.c	(revision 823)
@@ -30,430 +30,120 @@
 /* --- display_cube --- */
 /* -------------------- */
-/* ------------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_i8cube(int8 ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ------------------------------------------------------------------------------------------------------------------------- */
-{
-  long i,j,k;
 
-  if(name != NULL) puts(name);
+#undef display_type_cube
+#define display_type_cube(t) \
+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) \
+{                                                  \
+    if (name != NULL) {                            \
+        printf(name);                              \
+    }                                              \
+    for (int32_t k = ndl; k <= ndh; k++) {         \
+        for (int32_t i = nrl; i <= nrh; i++) {     \
+            for (int32_t j = ncl; j <= nch; j++) { \
+                printf(format, c[k][i][j]);        \
+            }                                      \
+            printf("\n");                          \
+        }                                          \
+        printf("\n");                              \
+    }                                              \
+}
 
-  for(k=ndl; k<=ndh; k++) {
-    for(i=nrl; i<=nrh; i++) {
-      for(j=ncl; j<=nch; j++) {
-        printf(format, c[k][i][j]);
-      }
-      putchar('\n');
-    }
-    putchar('\n');
-  }
-}
-/* --------------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_i16cube(int16 ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* --------------------------------------------------------------------------------------------------------------------------- */
-{
-  long i,j,k;
+display_type_cube(int8_t);
+display_type_cube(uint8_t);
+display_type_cube(int16_t);
+display_type_cube(uint16_t);
+display_type_cube(int32_t);
+display_type_cube(uint32_t);
+display_type_cube(int64_t);
+display_type_cube(uint64_t);
+display_type_cube(float);
+display_type_cube(double);
 
-  if(name != NULL) puts(name);
 
-  for(k=ndl; k<=ndh; k++) {
-    for(i=nrl; i<=nrh; i++) {
-      for(j=ncl; j<=nch; j++) {
-        printf(format, c[k][i][j]);
-      }
-      putchar('\n');
-    }
-    putchar('\n');
-  }
-}
-/* ----------------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui16cube(uint16 ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ----------------------------------------------------------------------------------------------------------------------------- */
-{
-  long i,j,k;
-
-  if(name != NULL) puts(name);
-
-  for(k=ndl; k<=ndh; k++) {
-    for(i=nrl; i<=nrh; i++) {
-      for(j=ncl; j<=nch; j++) {
-        printf(format, c[k][i][j]);
-      }
-      putchar('\n');
-    }
-    putchar('\n');
-  }
-}
-/* --------------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_i32cube(int32 ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* --------------------------------------------------------------------------------------------------------------------------- */
-{
-  long i,j,k;
-
-  if(name != NULL) puts(name);
-
-  for(k=ndl; k<=ndh; k++) {
-    for(i=nrl; i<=nrh; i++) {
-      for(j=ncl; j<=nch; j++) {
-        printf(format, c[k][i][j]);
-      }
-      putchar('\n');
-    }
-    putchar('\n');
-  }
-}
-/* ----------------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui32cube(uint32 ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ----------------------------------------------------------------------------------------------------------------------------- */
-{
-  long i,j,k;
-
-  if(name != NULL) puts(name);
-
-  for(k=ndl; k<=ndh; k++) {
-    for(i=nrl; i<=nrh; i++) {
-      for(j=ncl; j<=nch; j++) {
-        printf(format, c[k][i][j]);
-      }
-      putchar('\n');
-    }
-    putchar('\n');
-  }
-}
-/* --------------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_i64cube(int64 ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* --------------------------------------------------------------------------------------------------------------------------- */
-{
-  long i,j,k;
-
-  if(name != NULL) puts(name);
-
-  for(k=ndl; k<=ndh; k++) {
-    for(i=nrl; i<=nrh; i++) {
-      for(j=ncl; j<=nch; j++) {
-        printf(format, c[k][i][j]);
-      }
-      putchar('\n');
-    }
-    putchar('\n');
-  }
-}
-/* ----------------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_f32cube(float32 ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ----------------------------------------------------------------------------------------------------------------------------- */
-{
-  long i,j,k;
-
-  if(name != NULL) puts(name);
-
-  for(k=ndl; k<=ndh; k++) {
-    for(i=nrl; i<=nrh; i++) {
-      for(j=ncl; j<=nch; j++) {
-        printf(format, c[k][i][j]);
-      }
-      putchar('\n');
-    }
-    putchar('\n');
-  }
-}
 
 /* ---------------- */
 /* -- write_cube -- */
 /* ---------------- */
-/* ------------------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) write_i8cube(int8 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------------------------ */
-{
-  int i, j, k;
 
-  FILE *f;
+#undef write_type_cube
+#define write_type_cube(t) \
+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) \
+{                                                                \
+    FILE * f = fopen(filename, "wt");                            \
+    if (f == NULL) {                                             \
+        nrerror("Can't open file %s in %s", filename, __func__); \
+    }                                                            \
+    for (int32_t k = ndl; k <= ndh; k++) {                       \
+        for (int32_t i = nrl; i <= nrh; i++) {                   \
+            for (int32_t j = ncl; j <= nch; j++) {               \
+                fprintf(f, format, c[k][i][j]);                  \
+            }                                                    \
+            fprintf(f, "\n");                                    \
+        }                                                        \
+        fprintf(f, "\n");                                        \
+    }                                                            \
+    fclose(f);                                                   \
+}
 
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_i8cube");
-  }
+write_type_cube(int8_t);
+write_type_cube(uint8_t);
+write_type_cube(int16_t);
+write_type_cube(uint16_t);
+write_type_cube(int32_t);
+write_type_cube(uint32_t);
+write_type_cube(int64_t);
+write_type_cube(uint64_t);
+write_type_cube(float);
+write_type_cube(double);
 
-  for(k=ndl; k<=ndh; k++) {
-    for(i=nrl; i<=nrh; i++) {
-      for(j=ncl; j<=nch; j++) {
-        fprintf(f, format, c[k][i][j]);
-      }
-      fputc('\n', f);
-    }
-    fputc('\n', f);
-  }
 
-  fclose(f);
-}
-/* -------------------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_i16cube(int16 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename)
-/* -------------------------------------------------------------------------------------------------------------------------------- */
-{
-  int i, j, k;
-
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_i16cube");
-  }
-
-  for(k=ndl; k<=ndh; k++) {
-    for(i=nrl; i<=nrh; i++) {
-      for(j=ncl; j<=nch; j++) {
-        fprintf(f, format, c[k][i][j]);
-      }
-      fputc('\n', f);
-    }
-    fputc('\n', f);
-  }
-
-  fclose(f);
-}
-/* ---------------------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui16cube(uint16 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename)
-/* ---------------------------------------------------------------------------------------------------------------------------------- */
-{
-  int i, j, k;
-
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_ui16cube");
-  }
-
-  for(k=ndl; k<=ndh; k++) {
-    for(i=nrl; i<=nrh; i++) {
-      for(j=ncl; j<=nch; j++) {
-        fprintf(f, format, c[k][i][j]);
-      }
-      fputc('\n', f);
-    }
-    fputc('\n', f);
-  }
-
-  fclose(f);
-}
-/* -------------------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_i32cube(int32 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename)
-/* -------------------------------------------------------------------------------------------------------------------------------- */
-{
-  int i, j, k;
-
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_i32cube");
-  }
-
-  for(k=ndl; k<=ndh; k++) {
-    for(i=nrl; i<=nrh; i++) {
-      for(j=ncl; j<=nch; j++) {
-        fprintf(f, format, c[k][i][j]);
-      }
-      fputc('\n', f);
-    }
-    fputc('\n', f);
-  }
-
-  fclose(f);
-}
-/* ---------------------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui32cube(uint32 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename)
-/* ---------------------------------------------------------------------------------------------------------------------------------- */
-{
-  int i, j, k;
-
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_ui32cube");
-  }
-
-  for(k=ndl; k<=ndh; k++) {
-    for(i=nrl; i<=nrh; i++) {
-      for(j=ncl; j<=nch; j++) {
-        fprintf(f, format, c[k][i][j]);
-      }
-      fputc('\n', f);
-    }
-    fputc('\n', f);
-  }
-
-  fclose(f);
-}
-/* -------------------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_i64cube(int64 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename)
-/* -------------------------------------------------------------------------------------------------------------------------------- */
-{
-  int i, j, k;
-
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_i64cube");
-  }
-
-  for(k=ndl; k<=ndh; k++) {
-    for(i=nrl; i<=nrh; i++) {
-      for(j=ncl; j<=nch; j++) {
-        fprintf(f, format, c[k][i][j]);
-      }
-      fputc('\n', f);
-    }
-    fputc('\n', f);
-  }
-
-  fclose(f);
-}
-/* ---------------------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_f32cube(float32 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename)
-/* ---------------------------------------------------------------------------------------------------------------------------------- */
-{
-  int i, j, k;
-
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_f32cube");
-  }
-
-  for(k=ndl; k<=ndh; k++) {
-    for(i=nrl; i<=nrh; i++) {
-      for(j=ncl; j<=nch; j++) {
-        fprintf(f, format, c[k][i][j]);
-      }
-      fputc('\n', f);
-    }
-    fputc('\n', f);
-  }
-
-  fclose(f);
-}
 
 /* ---------------- */
 /* -- fread_cube -- */
 /* ---------------- */
-/* ----------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fread_i8cube(char *filename, int8 ***c,long ndl,long ndh,long nrl,long nrh,long ncl, long nch)
-/* ----------------------------------------------------------------------------------------------------------- */
-{
-  long  i, k;
-  long ncol = nch-ncl+1, nread;
-  FILE *f;
 
-  f = fopen(filename, "rb");
-  if(f == NULL)
-    nrerror("Can't open file in fread_i8cube");
+#undef fread_type_cube
+#define fread_type_cube(t) \
+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) \
+{                                                                     \
+    int32_t ncol = nch - ncl + 1;                                     \
+    FILE * f = fopen(filename, "rb");                                 \
+    if (f == NULL) {                                                  \
+        nrerror("Can't open file %s in %s", filename, __func__);      \
+    }                                                                 \
+    for (int32_t k = ndl; k <= ndh; k++) {                            \
+        for (int32_t i = nrl; i <= nrh; i++) {                        \
+            int32_t nread = fread(&c[k][i][ncl], sizeof(t), ncol, f); \
+            if (nread != ncol) {                                      \
+                nrerror("%s: Can't write data", __func__);            \
+            }                                                         \
+        }                                                             \
+    }                                                                 \
+    fclose(f);                                                        \
+}
+
+fread_type_cube(int8_t);
+fread_type_cube(uint8_t);
+fread_type_cube(int16_t);
+fread_type_cube(uint16_t);
+fread_type_cube(int32_t);
+fread_type_cube(uint32_t);
+fread_type_cube(int64_t);
+fread_type_cube(uint64_t);
+fread_type_cube(float);
+fread_type_cube(double);
 
 
-  for(k=ndl; k<=ndh; k++) {
-    for(i=nrl; i<=nrh; i++) {
-      nread = fread( &(c[k][i][ncl]), sizeof(int8), ncol, f);
-      if(nread != ncol) nrerror("fread_i8cube : can't write data");
-    }
-  }
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fread_i16cube(char *filename, int16 ***c,long ndl,long ndh,long nrl,long nrh,long ncl, long nch)
-/* ------------------------------------------------------------------------------------------------------------- */
-{
-  long  i, k;
-  long ncol = nch-ncl+1, nread;
-  FILE *f;
-
-  f = fopen(filename, "rb");
-  if(f == NULL)
-    nrerror("Can't open file in fread_i16cube");
-
-  for(k=ndl; k<=ndh; k++) {
-    for(i=nrl; i<=nrh; i++) {
-      nread = fread( &(c[k][i][ncl]), sizeof(int16), ncol, f);
-      if(nread != ncol) nrerror("fread_i16cube : can't write data");
-    }
-  }
-  fclose(f);
-}
-/* -------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fread_ui16cube(char *filename, uint16 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------------------------------------------- */
-{
-  long  i, k;
-  long ncol = nch-ncl+1, nread;
-  FILE *f;
-
-  f = fopen(filename, "rb");
-  if(f == NULL)
-    nrerror("Can't open file in fread_ui16cube");
 
 
-  for(k=ndl; k<=ndh; k++) {
-    for(i=nrl; i<=nrh; i++) {
-      nread = fread( &(c[k][i][ncl]), sizeof(uint16), ncol, f);
-      if(nread != ncol) nrerror("fread_ui16cube : can't write data");
-    }
-  }
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) fread_i32cube(char *filename, int32 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------------------------------------------ */
-{
-  long  i, k;
-  long ncol = nch-ncl+1, nread;
-  FILE *f;
-
-  f = fopen(filename, "rb");
-  if(f == NULL)
-    nrerror("Can't open file in fread_i32cube");
 
 
-  for(k=ndl; k<=ndh; k++) {
-    for(i=nrl; i<=nrh; i++) {
-      nread = fread( &(c[k][i][ncl]), sizeof(int32), ncol, f);
-      if(nread != ncol) nrerror("fread_i32cube : can't write data");
-    }
-  }
-  fclose(f);
-}
-/* --------------- */
-/* --- nrio3.h --- */
-/* --------------- */
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
 
-#ifndef __NRIO3_H__
-#define __NRIO3_H__
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
 
-#ifdef __cplusplus
-#pragma message ("C++")
-extern "C" {
-#endif
-    
-/* ------------------ */
-/* --- fread_cube --- */
-/* ------------------ */
-
-IMAGE_EXPORT(void) fread_ui32cube(char *filename, uint32  ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(void) fread_i64cube (char *filename, int64   ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(void) fread_f32cube (char *filename, float32 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch);
-
-/* ----------------- */
-/* -- fwrite_cube -- */
-/* ----------------- */
-
-IMAGE_EXPORT(void) fwrite_i8cube(int8     ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *filename);
-IMAGE_EXPORT(void) fwrite_i16cube(int16   ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *filename);
-IMAGE_EXPORT(void) fwrite_ui16cube(uint16 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *filename);
-IMAGE_EXPORT(void) fwrite_i32cube(int32   ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *filename);
-IMAGE_EXPORT(void) fwrite_ui32cube(uint32 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *filename);
-IMAGE_EXPORT(void) fwrite_i64cube(int64   ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *filename);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __NRIO3_H__ */
