Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nrio2x.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrio2x.c	(revision 822)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrio2x.c	(revision 823)
@@ -26,867 +26,211 @@
 #include "nrio2x.h"
 
+
+
 /* ------------------------------ */
 /* --- display_matrix_endline --- */
 /* ------------------------------ */
-/* ---------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_matrix_endline(byte **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* ---------------------------------------------------------------------------------------------------------- */
-{
-  int i, j;
-  int n = (i1-i0+1) * (j1-j0+1);
-  byte *p = &m[i0][j0];
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    for(j=j0; j<=j0+n; j++) {
-      printf(format, *p++);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* -------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_i16matrix_endline(int16 **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* -------------------------------------------------------------------------------------------------------------- */
-{
-  int i, j;
-  int n = (i1-i0+1) * (j1-j0+1);
-  int16 *p = &m[i0][j0];
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    for(j=j0; j<=j0+n; j++) {
-      printf(format, *p++);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* ---------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui16matrix_endline(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* ---------------------------------------------------------------------------------------------------------------- */
-{
-  int i, j;
-  int n = (i1-i0+1) * (j1-j0+1);
-  uint16 *p = &m[i0][j0];
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    for(j=j0; j<=j0+n; j++) {
-      printf(format, *p++);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* -------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_i32matrix_endline(int32 **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* -------------------------------------------------------------------------------------------------------------- */
-{
-  int i, j;
-  int n = (i1-i0+1) * (j1-j0+1);
-  int32 *p = &m[i0][j0];
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    for(j=j0; j<=j0+n; j++) {
-      printf(format, *p++);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui32matrix_endline(uint32 **m, long i0, long i1, long j0, long j1, char *format, char *name)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-  int i, j;
-  int n = (i1-i0+1) * (j1-j0+1);
-  uint32 *p = &m[i0][j0];
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    for(j=j0; j<=j0+n; j++) {
-      printf(format, *p++);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* -------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_i64matrix_endline(int64 **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* -------------------------------------------------------------------------------------------------------------- */
-{
-  int i, j;
-  int n = (i1-i0+1) * (j1-j0+1);
-  int64 *p = &m[i0][j0];
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    for(j=j0; j<=j0+n; j++) {
-      printf(format, *p++);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* ---------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_imatrix_endline(int **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* ---------------------------------------------------------------------------------------------------------- */
-{
-  int i, j;
-  int n = (i1-i0+1) * (j1-j0+1);
-  int *p = &m[i0][j0];
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    for(j=j0; j<=j0+n; j++) {
-      printf(format, *p++);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
+
+#undef display_type_matrix_endline
+#define display_type_matrix_endline(t) \
+void short_name(t,display_,matrix_endline)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * name) \
+{                                                \
+    int32_t n = (i1 - i0 + 1) * (j1 - j0 + 1);   \
+    t * p = &m[i0][j0];                          \
+                                                 \
+    if (name != NULL) {                          \
+        printf(name);                            \
+    }                                            \
+                                                 \
+    for (int32_t i = i0; i <= i1; i++) {         \
+        for (int32_t j = j0; j <= j0 + n; j++) { \
+            printf(format, *p++);                \
+        }                                        \
+        printf("\n");                            \
+    }                                            \
+    printf("\n");                                \
+}
+
+display_type_matrix_endline(int8_t);
+display_type_matrix_endline(uint8_t);
+display_type_matrix_endline(int16_t);
+display_type_matrix_endline(uint16_t);
+display_type_matrix_endline(int32_t);
+display_type_matrix_endline(uint32_t);
+display_type_matrix_endline(int64_t);
+display_type_matrix_endline(uint64_t);
+
+
 /* ------------------------------- */
 /* --- display_matrix_endline0 --- */
 /* ------------------------------- */
-/* ------------------------------------------------------------------------------------------------------------ */
-//IMAGE_EXPORT(void) display_bmatrix_endline0(byte **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* ------------------------------------------------------------------------------------------------------------ */
-/*{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    n = m[i][j0];
-    for(j=j0; j<=j0+n; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}*/
-/* ----------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_bmatrix_endline0(byte **m,long i0, long i1,char *format, char *name)
-/* ----------------------------------------------------------------------------------------- */
-{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    printf("[%3d] ", i);
-    n = m[i][0];
-    for(j=1; j<=+n; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* --------------------------------------------------------------------------------------------------------------- */
-//IMAGE_EXPORT(void) display_i16matrix_endline0(int16 **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* --------------------------------------------------------------------------------------------------------------- */
-/*{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    n = m[i][j0];
-    for(j=j0; j<=j0+n; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}*/
-/* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_i16matrix_endline0(int16 **m,long i0, long i1, char *format, char *name)
-/* --------------------------------------------------------------------------------------------- */
-{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    printf("[%3d] ", i);
-    n = m[i][0];
-    for(j=1; j<=+n; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* ---------------------------------------------------------------------------------------------------------------- */
-//IMAGE_EXPORT(void) display_ui16matrix_endline0(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* ---------------------------------------------------------------------------------------------------------------- */
-/*{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    n = m[i][j0];
-    for(j=j0; j<=j0+n; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}*/
-/* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui16matrix_endline0(uint16 **m,long i0, long i1, char *format, char *name)
-/* ----------------------------------------------------------------------------------------------- */
-{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    printf("[%3d] ", i);
-    n = m[i][0];
-    for(j=1; j<=+n; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* --------------------------------------------------------------------------------------------------------------- */
-//IMAGE_EXPORT(void) display_i32matrix_endline0(int32 **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* --------------------------------------------------------------------------------------------------------------- */
-/*{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    n = m[i][j0];
-    for(j=j0; j<=j0+n; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}*/
-/* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_i32matrix_endline0(int32 **m,long i0, long i1, char *format, char *name)
-/* --------------------------------------------------------------------------------------------- */
-{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    printf("[%3d] ", i);
-    n = m[i][0];
-    for(j=1; j<=+n; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* ---------------------------------------------------------------------------------------------------------------- */
-//IMAGE_EXPORT(void) display_ui32matrix_endline0(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* ---------------------------------------------------------------------------------------------------------------- */
-/*{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    n = m[i][j0];
-    for(j=j0; j<=j0+n; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}*/
-/* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui32matrix_endline0(uint32 **m,long i0, long i1, char *format, char *name)
-/* ----------------------------------------------------------------------------------------------- */
-{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    printf("[%3d] ", i);
-    n = m[i][0];
-    for(j=1; j<=+n; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_i64matrix_endline0(int64 **m,long i0, long i1, char *format, char *name)
-/* --------------------------------------------------------------------------------------------- */
-{
-  int i, j;
-  int64 n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    printf("[%3d] ", i);
-    n = m[i][0];
-    for(j=1; j<=+n; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* ----------------------------------------------------------------------------------------------------------- */
-//IMAGE_EXPORT(void) display_imatrix_endline0(int **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* ----------------------------------------------------------------------------------------------------------- */
-/*{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    n = m[i][j0];
-    for(j=j0; j<=j0+n; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}*/
-/* ----------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_imatrix_endline0(int **m,long i0, long i1, char *format, char *name)
-/* ----------------------------------------------------------------------------------------- */
-{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    printf("[%3d] ", i);
-    n = m[i][0];
-    for(j=1; j<=+n; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
+
+#undef display_type_matrix_endline0
+#define display_type_matrix_endline0(t) \
+void short_name(t,display_,matrix_endline0)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * name) \
+{                                                \
+    if (name != NULL) {                          \
+        printf(name);                            \
+    }                                            \
+                                                 \
+    for (int32_t i = i0; i <= i1; i++) {         \
+        int32_t n = (int32_t) m[i][j0];          \
+        for (int32_t j = j0; j <= j0 + n; j++) { \
+            printf(format, m[i][j]);             \
+        }                                        \
+        printf("\n");                            \
+    }                                            \
+    printf("\n");                                \
+}
+
+display_type_matrix_endline0(int8_t);
+display_type_matrix_endline0(uint8_t);
+display_type_matrix_endline0(int16_t);
+display_type_matrix_endline0(uint16_t);
+display_type_matrix_endline0(int32_t);
+display_type_matrix_endline0(uint32_t);
+display_type_matrix_endline0(int64_t);
+display_type_matrix_endline0(uint64_t);
+
+
 /* ------------------------------- */
 /* --- display_matrix_endline1 --- */
 /* ------------------------------- */
-/* ------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_bmatrix_endline1(byte **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* ------------------------------------------------------------------------------------------------------------ */
-{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    n = m[i][j0-1];
-    for(j=j0; j<=j0+n-1; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* --------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_i16matrix_endline1(int16 **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* --------------------------------------------------------------------------------------------------------------- */
-{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    n = m[i][j0-1];
-    for(j=j0; j<=j0+n-1; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui16matrix_endline1(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    n = m[i][j0-1];
-    for(j=j0; j<=j0+n-1; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* --------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_i32matrix_endline1(int32 **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* --------------------------------------------------------------------------------------------------------------- */
-{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    n = m[i][j0-1];
-    for(j=j0; j<=j0+n-1; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui32matrix_endline1(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    n = m[i][j0-1];
-    for(j=j0; j<=j0+n-1; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* --------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_i64matrix_endline1(int64 **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* --------------------------------------------------------------------------------------------------------------- */
-{
-  int i, j;
-  int64 n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    n = m[i][j0-1];
-    for(j=j0; j<=j0+n-1; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* ----------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_imatrix_endline1(int **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* ----------------------------------------------------------------------------------------------------------- */
-{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    n = m[i][j0-1];
-    for(j=j0; j<=j0+n-1; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
+
+#undef display_type_matrix_endline1
+#define display_type_matrix_endline1(t) \
+void short_name(t,display_,matrix_endline1)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * name) \
+{                                                    \
+    if (name != NULL) {                              \
+        printf(name);                                \
+    }                                                \
+                                                     \
+    for (int32_t i = i0; i <= i1; i++) {             \
+        int32_t n = (int32_t) m[i][j0 - 1];          \
+        for (int32_t j = j0; j <= j0 + n - 1; j++) { \
+            printf(format, m[i][j]);                 \
+        }                                            \
+        printf("\n");                                \
+    }                                                \
+    printf("\n");                                    \
+}
+
+display_type_matrix_endline1(int8_t);
+display_type_matrix_endline1(uint8_t);
+display_type_matrix_endline1(int16_t);
+display_type_matrix_endline1(uint16_t);
+display_type_matrix_endline1(int32_t);
+display_type_matrix_endline1(uint32_t);
+display_type_matrix_endline1(int64_t);
+display_type_matrix_endline1(uint64_t);
+
+
 /* -------------------------------------- */
 /* --- display_matrix_number_endline0 --- */
 /* -------------------------------------- */
-/* ------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_bmatrix_number_endline0(byte **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* ------------------------------------------------------------------------------------------------------------------- */
-{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    printf("[%3d]", i);
-    n = m[i][j0];
-    for(j=j0; j<=j0+n; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* ---------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_i16matrix_number_endline0(int16 **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* ---------------------------------------------------------------------------------------------------------------------- */
-{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    printf("[%3d]", i);
-    n = m[i][j0];
-    for(j=j0; j<=j0+n; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* ------------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_ui16matrix_number_endline0(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* ------------------------------------------------------------------------------------------------------------------------ */
-{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    printf("[%3d]", i);
-    n = m[i][j0];
-    for(j=j0; j<=j0+n; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* ---------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_i32matrix_number_endline0(int32 **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* ---------------------------------------------------------------------------------------------------------------------- */
-{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    printf("[%3d]", i);
-    n = m[i][j0];
-    for(j=j0; j<=j0+n; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* ------------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_ui32matrix_number_endline0(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* ------------------------------------------------------------------------------------------------------------------------ */
-{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    printf("[%3d]", i);
-    n = m[i][j0];
-    for(j=j0; j<=j0+n; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* ---------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_i64matrix_number_endline0(int64 **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* ---------------------------------------------------------------------------------------------------------------------- */
-{
-  int i, j;
-  int64 n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    printf("[%3d]", i);
-    n = m[i][j0];
-    for(j=j0; j<=j0+n; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* ------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_imatrix_number_endline0(int **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* ------------------------------------------------------------------------------------------------------------------ */
-{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    printf("[%3d]", i);
-    n = m[i][j0];
-    for(j=j0; j<=j0+n; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
+
+#undef display_type_matrix_number_endline0
+#define display_type_matrix_number_endline0(t) \
+void short_name(t,display_,matrix_number_endline0)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * name) \
+{                                                    \
+    if (name != NULL) {                              \
+        printf(name);                                \
+    }                                                \
+                                                     \
+    for (int32_t i = i0; i <= i1; i++) {             \
+        printf("[%3d] ", i);                         \
+        int32_t n = (int32_t) m[i][j0];              \
+        for (int32_t j = j0; j <= j0 + n; j++) {     \
+            printf(format, m[i][j]);                 \
+        }                                            \
+        printf("\n");                                \
+    }                                                \
+    printf("\n");                                    \
+}
+
+display_type_matrix_number_endline0(int8_t);
+display_type_matrix_number_endline0(uint8_t);
+display_type_matrix_number_endline0(int16_t);
+display_type_matrix_number_endline0(uint16_t);
+display_type_matrix_number_endline0(int32_t);
+display_type_matrix_number_endline0(uint32_t);
+display_type_matrix_number_endline0(int64_t);
+display_type_matrix_number_endline0(uint64_t);
+
+
 /* -------------------------------------- */
 /* --- display_matrix_number_endline1 --- */
 /* -------------------------------------- */
-/* ------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_bmatrix_number_endline1(byte **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* ------------------------------------------------------------------------------------------------------------------- */
-{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    printf("[%3d]", i);
-    n = m[i][j0-1];
-    for(j=j0; j<=j0+n-1; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* ---------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_i16matrix_number_endline1(int16 **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* ---------------------------------------------------------------------------------------------------------------------- */
-{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    printf("[%3d]", i);
-    n = m[i][j0-1];
-    for(j=j0; j<=j0+n-1; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* ------------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_ui16matrix_number_endline1(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* ------------------------------------------------------------------------------------------------------------------------ */
-{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    printf("[%3d]", i);
-    n = m[i][j0-1];
-    for(j=j0; j<=j0+n-1; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* ---------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_i32matrix_number_endline1(int32 **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* ---------------------------------------------------------------------------------------------------------------------- */
-{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    printf("[%3d]", i);
-    n = m[i][j0-1];
-    for(j=j0; j<=j0+n-1; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* ------------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_ui32matrix_number_endline1(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* ------------------------------------------------------------------------------------------------------------------------ */
-{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    printf("[%3d]", i);
-    n = m[i][j0-1];
-    for(j=j0; j<=j0+n-1; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* ---------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_i64matrix_number_endline1(int64 **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* ---------------------------------------------------------------------------------------------------------------------- */
-{
-  int i, j;
-  int64 n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    printf("[%3d]", i);
-    n = m[i][j0-1];
-    for(j=j0; j<=j0+n-1; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
-/* ------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_imatrix_number_endline1(int **m,long i0, long i1, long j0, long j1, char *format, char *name)
-/* ------------------------------------------------------------------------------------------------------------------ */
-{
-  int i, j, n;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    printf("[%3d]", i);
-    n = m[i][j0-1];
-    for(j=j0; j<=j0+n-1; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-  }
-  putchar('\n');
-}
+
+#undef display_type_matrix_number_endline1
+#define display_type_matrix_number_endline1(t) \
+void short_name(t,display_,matrix_number_endline1)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * name) \
+{                                                    \
+    if (name != NULL) {                              \
+        printf(name);                                \
+    }                                                \
+                                                     \
+    for (int32_t i = i0; i <= i1; i++) {             \
+        printf("[%3d] ", i);                         \
+        int32_t n = (int32_t) m[i][j0 - 1];          \
+        for (int32_t j = j0; j <= j0 + n - 1; j++) { \
+            printf(format, m[i][j]);                 \
+        }                                            \
+        printf("\n");                                \
+    }                                                \
+    printf("\n");                                    \
+}
+
+display_type_matrix_number_endline1(int8_t);
+display_type_matrix_number_endline1(uint8_t);
+display_type_matrix_number_endline1(int16_t);
+display_type_matrix_number_endline1(uint16_t);
+display_type_matrix_number_endline1(int32_t);
+display_type_matrix_number_endline1(uint32_t);
+display_type_matrix_number_endline1(int64_t);
+display_type_matrix_number_endline1(uint64_t);
+
+
 /* ------------------------- */
 /* --- display_trimatrix --- */
 /* ------------------------- */
-/* ------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_btrimatrix(byte **m, long i0, long i1, long j0, long j1, long step, char *format, char *name)
-/* ------------------------------------------------------------------------------------------------------------------ */
-{
-  int i, j;
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    for(j=j0; j<=j1; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-    j1 += step;
-  }
-  putchar('\n');
-}
-/* --------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_i16trimatrix(int16 **m, long i0, long i1, long j0, long j1, long step, char *format, char *name)
-/* --------------------------------------------------------------------------------------------------------------------- */
-{
-  int i, j;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    for(j=j0; j<=j1; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-    j1 += step;
-  }
-  putchar('\n');
-}
-/* ----------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui16trimatrix(uint16 **m, long i0, long i1, long j0, long j1, long step, char *format, char *name)
-/* ----------------------------------------------------------------------------------------------------------------------- */
-{
-  int i, j;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    for(j=j0; j<=j1; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-    j1 += step;
-  }
-  putchar('\n');
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_itrimatrix(int **m, long i0, long i1, long j0, long j1, long step, char *format, char *name)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-  int i, j;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    for(j=j0; j<=j1; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-    j1 += step;
-  }
-  putchar('\n');
-}
-/* --------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_i32trimatrix(int32 **m, long i0, long i1, long j0, long j1, long step, char *format, char *name)
-/* --------------------------------------------------------------------------------------------------------------------- */
-{
-  int i, j;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    for(j=j0; j<=j1; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-    j1 += step;
-  }
-  putchar('\n');
-}
-/* ------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_f32trimatrix(float32 **m, long i0, long i1, long j0, long j1, long step, char *format, char *name)
-/* ------------------------------------------------------------------------------------------------------------------ */
-{
-  int i, j;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    for(j=j0; j<=j1; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-    j1 += step;
-  }
-  putchar('\n');
-}
-/* ------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_f64trimatrix(float64 **m, long i0, long i1, long j0, long j1, long step, char *format, char *name)
-/* ------------------------------------------------------------------------------------------------------------------ */
-{
-  int i, j;
-
-  if(name != NULL) puts(name);
-
-  for(i=i0; i<=i1; i++) {
-    for(j=j0; j<=j1; j++) {
-      printf(format, m[i][j]);
-    }
-    putchar('\n');
-    j1 += step;
-  }
-  putchar('\n');
-}
+
+#undef display_type_trimatrix
+#define display_type_trimatrix(t) \
+void short_name(t,display_,trimatrix)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, int32_t step, char * format, char * name) \
+{                                                    \
+    if (name != NULL) {                              \
+        printf(name);                                \
+    }                                                \
+                                                     \
+    for (int32_t i = i0; i <= i1; i++) {             \
+        for (int32_t j = j0; j <= j1; j++) {         \
+            printf(format, m[i][j]);                 \
+        }                                            \
+        printf("\n");                                \
+        j1 += step;                                  \
+    }                                                \
+    printf("\n");                                    \
+}
+
+display_type_trimatrix(int8_t);
+display_type_trimatrix(uint8_t);
+display_type_trimatrix(int16_t);
+display_type_trimatrix(uint16_t);
+display_type_trimatrix(int32_t);
+display_type_trimatrix(uint32_t);
+display_type_trimatrix(int64_t);
+display_type_trimatrix(uint64_t);
+display_type_trimatrix(float);
+display_type_trimatrix(double);
+
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nrio2xf.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrio2xf.c	(revision 822)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrio2xf.c	(revision 823)
@@ -25,1209 +25,290 @@
 #include "nrio2x.h"
 
-/* ------------------------------ */
-/* --- display_matrix_endline --- */
-/* ------------------------------ */
 /* ----------------------- */
 /* --- write_trimatrix --- */
 /* ----------------------- */
 
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_btrimatrix(byte **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_btrimatrix");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    for(j=j0; j<=j1; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-    j1 += step;
-  }
-  fputc('\n', f);
-
-  fclose(f);
-}
-
-/* -------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_i16trimatrix(int16 **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename)
-/* -------------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_i16trimatrix");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    for(j=j0; j<=j1; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-    j1 += step;
-  }
-  fputc('\n', f);
-
-  fclose(f);
-}
-/* ---------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui16trimatrix(uint16 **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename)
-/* ---------------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_ui16trimatrix");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    for(j=j0; j<=j1; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-    j1 += step;
-  }
-  fputc('\n', f);
-
-  fclose(f);
-}
-/* ---------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_itrimatrix(int **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename)
-/* ---------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_itrimatrix");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    for(j=j0; j<=j1; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-    j1 += step;
-  }
-  fputc('\n', f);
-
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) write_i32trimatrix(int32 **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------------------ */
-{
-  int i,j;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_i32trimatrix");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    for(j=j0; j<=j1; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-    j1 += step;
-  }
-  fputc('\n', f);
-
-  fclose(f);
-}
-/* ---------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_f32trimatrix(float32 **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename)
-/* ---------------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_f32trimatrix");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    for(j=j0; j<=j1; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-    j1 += step;
-  }
-  fputc('\n', f);
-
-  fclose(f);
-}
-/* ---------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_f64trimatrix(float64 **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename)
-/* ---------------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_f64trimatrix");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    for(j=j0; j<=j1; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-    j1 += step;
-  }
-  fputc('\n', f);
-
-  fclose(f);
-}
+#undef write_type_trimatrix
+#define write_type_trimatrix(t) \
+void short_name(t,write_,trimatrix)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, int32_t step, 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 i = i0; i <= i1; i++) {                         \
+        for (int32_t j = j0; j <= j1; j++) {                     \
+            fprintf(f, format, m[i][j]);                         \
+        }                                                        \
+        fprintf(f, "\n");                                        \
+        j1 += step;                                              \
+    }                                                            \
+    fprintf(f, "\n");                                            \
+    fclose(f);                                                   \
+}
+
+write_type_trimatrix(int8_t);
+write_type_trimatrix(uint8_t);
+write_type_trimatrix(int16_t);
+write_type_trimatrix(uint16_t);
+write_type_trimatrix(int32_t);
+write_type_trimatrix(uint32_t);
+write_type_trimatrix(int64_t);
+write_type_trimatrix(uint64_t);
+write_type_trimatrix(float);
+write_type_trimatrix(double);
+
+
 /* ---------------------------- */
 /* --- write_matrix_endline --- */
 /* ---------------------------- */
-/* ------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) write_bmatrix_endline(byte **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------ */
-{
-  int i,j;
-  //int n = (i1-i0+1) * (j1-j0+1);
-  byte *p = &m[i0][j0];
-
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_bmatrix_endline");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    for(j=j0; j<=j1; j++) {
-      fprintf(f, format, *p++);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* ---------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_i16matrix_endline(int16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* ---------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j;
-  //int n = (i1-i0+1) * (j1-j0+1);
-  int16 *p = &m[i0][j0];
-
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_i16matrix_endline");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    for(j=j0; j<=j1; j++) {
-      fprintf(f, format, *p++);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) write_ui16matrix_endline(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------------ */
-{
-  int i,j;
-  //int n = (i1-i0+1) * (j1-j0+1);
-  uint16 *p = &m[i0][j0];
-
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_ui16matrix_endline");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    for(j=j0; j<=j1; j++) {
-      fprintf(f, format, *p++);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* ---------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_i32matrix_endline(int32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* ---------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j;
-  //int n = (i1-i0+1) * (j1-j0+1);
-  int32 *p = &m[i0][j0];
-
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_i32matrix_endline");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    for(j=j0; j<=j1; j++) {
-      fprintf(f, format, *p++);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) write_ui32matrix_endline(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------------ */
-{
-  int i,j;
-  //int n = (i1-i0+1) * (j1-j0+1);
-  uint32 *p = &m[i0][j0];
-
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_ui32matrix_endline");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    for(j=j0; j<=j1; j++) {
-      fprintf(f, format, *p++);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* ---------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_i64matrix_endline(int64 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* ---------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j;
-  //int n = (i1-i0+1) * (j1-j0+1);
-  int64 *p = &m[i0][j0];
-
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_i64matrix_endline");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    for(j=j0; j<=j1; j++) {
-      fprintf(f, format, *p++);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) write_imatrix_endline(int **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------ */
-{
-  int i,j;
-  //int n = (i1-i0+1) * (j1-j0+1);
-  int *p = &m[i0][j0];
-
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_imatrix_endline");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    for(j=j0; j<=j1; j++) {
-      fprintf(f, format, *p++);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
+
+#undef write_type_matrix_endline
+#define write_type_matrix_endline(t) \
+void short_name(t,write_,matrix_endline)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, char * format, char * filename) \
+{                                                                \
+    t * p = &m[i0][j0];                                          \
+    FILE * f = fopen(filename, "wt");                            \
+    if (f == NULL) {                                             \
+        nrerror("Can't open file %s in %s", filename, __func__); \
+    }                                                            \
+    for (int32_t i = i0; i <= i1; i++) {                         \
+        for (int32_t j = j0; j <= j1; j++) {                     \
+            fprintf(f, format, *p++);                            \
+        }                                                        \
+        fprintf(f, "\n");                                        \
+    }                                                            \
+    fprintf(f, "\n");                                            \
+    fclose(f);                                                   \
+}
+
+write_type_matrix_endline(int8_t);
+write_type_matrix_endline(uint8_t);
+write_type_matrix_endline(int16_t);
+write_type_matrix_endline(uint16_t);
+write_type_matrix_endline(int32_t);
+write_type_matrix_endline(uint32_t);
+write_type_matrix_endline(int64_t);
+write_type_matrix_endline(uint64_t);
+write_type_matrix_endline(float);
+write_type_matrix_endline(double);
+
+
 /* ------------------------------ */
 /* --- write_imatrix_endline0 --- */
 /* ------------------------------ */
-/* -------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_bmatrix_endline0(byte **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* -------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j, n;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_bmatrix_endline0");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    n = m[i][j0];
-    for(j=j0; j<=j0+n; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_i16matrix_endline0(int16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j, n;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_i16matrix_endline0");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    n = m[i][j0];
-    for(j=j0; j<=j0+n; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui16matrix_endline0(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j, n;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_ui16matrix_endline0");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    n = m[i][j0];
-    for(j=j0; j<=j0+n; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_i32matrix_endline0(int32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j, n;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_i32matrix_endline0");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    n = m[i][j0];
-    for(j=j0; j<=j0+n; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_i64matrix_endline0(int64 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j;
-  int64 n;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_i64matrix_endline0");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    n = m[i][j0];
-    for(j=j0; j<=j0+n; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui32matrix_endline0(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j, n;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_ui32matrix_endline0");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    n = m[i][j0];
-    for(j=j0; j<=j0+n; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_imatrix_endline0(int **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j, n;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_imatrix_endline0");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    n = m[i][j0];
-    for(j=j0; j<=j0+n; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
+
+#undef write_type_matrix_endline0
+#define write_type_matrix_endline0(t) \
+void short_name(t,write_,matrix_endline0)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, 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 i = i0; i <= i1; i++) {                         \
+        int32_t n = (int32_t) m[i][j0];                          \
+        for (int32_t j = j0; j <= j0 + n; j++) {                 \
+            fprintf(f, format, m[i][j]);                         \
+        }                                                        \
+        fprintf(f, "\n");                                        \
+    }                                                            \
+    fprintf(f, "\n");                                            \
+    fclose(f);                                                   \
+}
+
+write_type_matrix_endline0(int8_t);
+write_type_matrix_endline0(uint8_t);
+write_type_matrix_endline0(int16_t);
+write_type_matrix_endline0(uint16_t);
+write_type_matrix_endline0(int32_t);
+write_type_matrix_endline0(uint32_t);
+write_type_matrix_endline0(int64_t);
+write_type_matrix_endline0(uint64_t);
+write_type_matrix_endline0(float);
+write_type_matrix_endline0(double);
+
+
+
 /* ------------------------------ */
 /* --- write_imatrix_endline1 --- */
 /* ------------------------------ */
-/* -------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_bmatrix_endline1(byte **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* -------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j, n;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_bmatrix_endline1");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    n = m[i][j0-1];
-    for(j=j0; j<=j0+n-1; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_i16matrix_endline1(int16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j, n;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_i16matrix_endline0");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    n = m[i][j0-1];
-    for(j=j0; j<=j0+n-1; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui16matrix_endline1(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j, n;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_ui16matrix_endline0");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    n = m[i][j0-1];
-    for(j=j0; j<=j0+n-1; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_i32matrix_endline1(int32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j, n;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_i32matrix_endline0");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    n = m[i][j0-1];
-    for(j=j0; j<=j0+n-1; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui32matrix_endline1(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j, n;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_ui32matrix_endline0");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    n = m[i][j0-1];
-    for(j=j0; j<=j0+n-1; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_i64matrix_endline1(int64 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j;
-  int64 n;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_i64matrix_endline0");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    n = m[i][j0-1];
-    for(j=j0; j<=j0+n-1; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_imatrix_endline1(int **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j, n;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_imatrix_endline0");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    n = m[i][j0-1];
-    for(j=j0; j<=j0+n-1; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
+
+#undef write_type_matrix_endline1
+#define write_type_matrix_endline1(t) \
+void short_name(t,write_,matrix_endline1)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, 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 i = i0; i <= i1; i++) {                         \
+        int32_t n = (int32_t) m[i][j0 - 1];                      \
+        for (int32_t j = j0; j <= j0 + n - 1; j++) {             \
+            fprintf(f, format, m[i][j]);                         \
+        }                                                        \
+        fprintf(f, "\n");                                        \
+    }                                                            \
+    fprintf(f, "\n");                                            \
+    fclose(f);                                                   \
+}
+
+write_type_matrix_endline1(int8_t);
+write_type_matrix_endline1(uint8_t);
+write_type_matrix_endline1(int16_t);
+write_type_matrix_endline1(uint16_t);
+write_type_matrix_endline1(int32_t);
+write_type_matrix_endline1(uint32_t);
+write_type_matrix_endline1(int64_t);
+write_type_matrix_endline1(uint64_t);
+write_type_matrix_endline1(float);
+write_type_matrix_endline1(double);
+
+
 /* ------------------------------------- */
 /* --- write_imatrix_number_endline0 --- */
 /* ------------------------------------- */
-/* --------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_bmatrix_number_endline0(byte **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* --------------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j, n;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_bmatrix_number_endline0");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    fprintf(f, "[%3d] ", i);
-    n = m[i][j0];
-    for(j=j0; j<=j0+n; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_i16matrix_number_endline0(int16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------------------ */
-{
-  int i,j, n;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_i16matrix_number_endline0");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    fprintf(f, "[%3d] ", i);
-    n = m[i][j0];
-    for(j=j0; j<=j0+n; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* -------------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui16matrix_number_endline0(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* -------------------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j, n;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_ui16matrix_number_endline0");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    fprintf(f, "[%3d] ", i);
-    n = m[i][j0];
-    for(j=j0; j<=j0+n; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) write_i32matrix_number_endline0(int32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------------------ */
-{
-  int i,j, n;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_i32matrix_number_endline0");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    fprintf(f, "[%3d] ", i);
-    n = m[i][j0];
-    for(j=j0; j<=j0+n; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* -------------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui32matrix_number_endline0(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* -------------------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j, n;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_ui32matrix_number_endline0");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    fprintf(f, "[%3d] ", i);
-    n = m[i][j0];
-    for(j=j0; j<=j0+n; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) write_i64matrix_number_endline0(int64 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------------------ */
-{
-  int i,j;
-  int64 n;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_i64matrix_number_endline0");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    fprintf(f, "[%3d] ", i);
-    n = m[i][j0];
-    for(j=j0; j<=j0+n; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* -------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_imatrix_number_endline0(int **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* -------------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j, n;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_imatrix_number_endline0");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    fprintf(f, "[%3d] ", i);
-    n = m[i][j0];
-    for(j=j0; j<=j0+n; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
+
+#undef write_type_matrix_number_endline0
+#define write_type_matrix_number_endline0(t) \
+void short_name(t,write_,matrix_number_endline0)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, 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 i = i0; i <= i1; i++) {                         \
+        fprintf(f, "[%3d] ", i);                                 \
+        int32_t n = (int32_t) m[i][j0];                          \
+        for (int32_t j = j0; j <= j0 + n; j++) {                 \
+            fprintf(f, format, m[i][j]);                         \
+        }                                                        \
+        fprintf(f, "\n");                                        \
+    }                                                            \
+    fprintf(f, "\n");                                            \
+    fclose(f);                                                   \
+}
+
+write_type_matrix_number_endline0(int8_t);
+write_type_matrix_number_endline0(uint8_t);
+write_type_matrix_number_endline0(int16_t);
+write_type_matrix_number_endline0(uint16_t);
+write_type_matrix_number_endline0(int32_t);
+write_type_matrix_number_endline0(uint32_t);
+write_type_matrix_number_endline0(int64_t);
+write_type_matrix_number_endline0(uint64_t);
+write_type_matrix_number_endline0(float);
+write_type_matrix_number_endline0(double);
+
+
 /* ------------------------------------- */
 /* --- write_imatrix_number_endline1 --- */
 /* ------------------------------------- */
-/* --------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_bmatrix_number_endline1(byte **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* --------------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j, n;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_bmatrix_number_endline1");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    fprintf(f, "[%3d] ", i);
-    n = m[i][j0-1];
-    for(j=j0; j<=j0+n-1; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) write_i16matrix_number_endline1(int16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------------------ */
-{
-  int i,j, n;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_i16matrix_number_endline0");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    fprintf(f, "[%3d] ", i);
-    n = m[i][j0-1];
-    for(j=j0; j<=j0+n-1; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* -------------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui16matrix_number_endline1(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* -------------------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j, n;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_ui16matrix_number_endline0");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    fprintf(f, "[%3d] ", i);
-    n = m[i][j0-1];
-    for(j=j0; j<=j0+n-1; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) write_i32matrix_number_endline1(int32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------------------ */
-{
-  int i,j, n;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_i32matrix_number_endline0");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    fprintf(f, "[%3d] ", i);
-    n = m[i][j0-1];
-    for(j=j0; j<=j0+n-1; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* -------------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui32matrix_number_endline1(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* -------------------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j, n;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_ui32matrix_number_endline0");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    fprintf(f, "[%3d] ", i);
-    n = m[i][j0-1];
-    for(j=j0; j<=j0+n-1; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) write_i64matrix_number_endline1(int64 **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------------------ */
-{
-  int i,j;
-  int64 n;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_i64matrix_number_endline0");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    fprintf(f, "[%3d] ", i);
-    n = m[i][j0-1];
-    for(j=j0; j<=j0+n-1; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
-/* -------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_imatrix_number_endline1(int **m,long i0, long i1, long j0, long j1, char *format, char *filename)
-/* -------------------------------------------------------------------------------------------------------------------- */
-{
-  int i,j, n;
-  
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) {
-    nrerror("Can't open file in write_imatrix_number_endline0");
-  }
-
-  for(i=i0; i<=i1; i++) {
-    fprintf(f, "[%3d] ", i);
-    n = m[i][j0-1];
-    for(j=j0; j<=j0+n-1; j++) {
-      fprintf(f, format, m[i][j]);
-    }
-    fputc('\n', f);
-  }
-  fclose(f);
-}
+
+#undef write_type_matrix_number_endline1
+#define write_type_matrix_number_endline1(t) \
+void short_name(t,write_,matrix_number_endline1)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, 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 i = i0; i <= i1; i++) {                         \
+        fprintf(f, "[%3d] ", i);                                 \
+        int32_t n = (int32_t) m[i][j0 - 1];                      \
+        for (int32_t j = j0; j <= j0 + n - 1; j++) {             \
+            fprintf(f, format, m[i][j]);                         \
+        }                                                        \
+        fprintf(f, "\n");                                        \
+    }                                                            \
+    fprintf(f, "\n");                                            \
+    fclose(f);                                                   \
+}
+
+write_type_matrix_number_endline1(int8_t);
+write_type_matrix_number_endline1(uint8_t);
+write_type_matrix_number_endline1(int16_t);
+write_type_matrix_number_endline1(uint16_t);
+write_type_matrix_number_endline1(int32_t);
+write_type_matrix_number_endline1(uint32_t);
+write_type_matrix_number_endline1(int64_t);
+write_type_matrix_number_endline1(uint64_t);
+write_type_matrix_number_endline1(float);
+write_type_matrix_number_endline1(double);
+
+
 /* ---------------------- */
 /* -- fwrite_trimatrix -- */
 /* ---------------------- */
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fwrite_btrimatrix(byte **m,long i0,long i1,long j0, long j1, long step, char *filename)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-  long  i, ncol = j1-j0+1;
-  FILE *f;
-
-  f = fopen(filename, "wb");
-  if(f == NULL) nrerror("Can't open file in fwrite_btrimatrix");
-
-  for(i=i0; i<=i1; i++) {
-    fwrite(m[i]+j0, sizeof(byte), ncol, f);
-    ncol += step;
-  }
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fwrite_i16trimatrix(int16 **m,long i0,long i1,long j0, long j1, long step, char *filename)
-/* ------------------------------------------------------------------------------------------------------- */
-{
-  long  i, ncol = j1-j0+1;
-  FILE *f;
-
-  f = fopen(filename, "wb");
-  if(f == NULL) nrerror("Can't open file in fwrite_i16trimatrix");
-
-  for(i=i0; i<=i1; i++) {
-    fwrite(m[i]+j0, sizeof(int16), ncol, f);
-    ncol += step;
-  }
-  fclose(f);
-}
-/* --------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fwrite_ui16trimatrix(uint16 **m,long i0,long i1,long j0, long j1, long step, char *filename)
-/* --------------------------------------------------------------------------------------------------------- */
-{
-  long  i, ncol = j1-j0+1;
-  FILE *f;
-
-  f = fopen(filename, "wb");
-  if(f == NULL) nrerror("Can't open file in fwrite_ui16trimatrix");
-
-  for(i=i0; i<=i1; i++) {
-    fwrite(m[i]+j0, sizeof(uint16), ncol, f);
-    ncol += step;
-  }
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fwrite_i32trimatrix(int32 **m,long i0,long i1,long j0, long j1, long step, char *filename)
-/* ------------------------------------------------------------------------------------------------------- */
-{
-  long  i, ncol = j1-j0+1;
-  FILE *f;
-
-  f = fopen(filename, "wb");
-  if(f == NULL) nrerror("Can't open file in fwrite_i32trimatrix");
-
-  for(i=i0; i<=i1; i++) {
-    fwrite(m[i]+j0, sizeof(int32), ncol, f);
-    ncol += step;
-  }
-  fclose(f);
-}
-/* --------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fwrite_f32trimatrix(float32 **m,long i0,long i1,long j0, long j1, long step, char *filename)
-/* --------------------------------------------------------------------------------------------------------- */
-{
-  long  i, ncol = j1-j0+1;
-  FILE *f;
-
-  f = fopen(filename, "wb");
-  if(f == NULL) nrerror("Can't open file in fwrite_f32trimatrix");
-
-  for(i=i0; i<=i1; i++) {
-    fwrite(m[i]+j0, sizeof(float32), ncol, f);
-    ncol += step;
-  }
-  fclose(f);
-}
-/* --------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fwrite_f64trimatrix(float64 **m,long i0,long i1,long j0, long j1, long step, char *filename)
-/* --------------------------------------------------------------------------------------------------------- */
-{
-  long  i, ncol = j1-j0+1;
-  FILE *f;
-
-  f = fopen(filename, "wb");
-  if(f == NULL) nrerror("Can't open file in fwrite_f64trimatrix");
-
-  for(i=i0; i<=i1; i++) {
-    fwrite(m[i]+j0, sizeof(float64), ncol, f);
-  }
-  fclose(f);
-}
+
+#undef fwrite_type_trimatrix
+#define fwrite_type_trimatrix(t) \
+void short_name(t,fwrite_,trimatrix)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, int32_t step, char * filename) \
+{                                                                \
+    int32_t ncol = j1 - j0 + 1;                                  \
+    FILE * f = fopen(filename, "wb");                            \
+    if (f == NULL) {                                             \
+        nrerror("Can't open file %s in %s", filename, __func__); \
+    }                                                            \
+    for (int32_t i = i0; i <= i1; i++) {                         \
+        fwrite(m[i] + j0, sizeof(t), ncol, f);                   \
+        ncol += step;                                            \
+    }                                                            \
+    fclose(f);                                                   \
+}
+
+fwrite_type_trimatrix(int8_t);
+fwrite_type_trimatrix(uint8_t);
+fwrite_type_trimatrix(int16_t);
+fwrite_type_trimatrix(uint16_t);
+fwrite_type_trimatrix(int32_t);
+fwrite_type_trimatrix(uint32_t);
+fwrite_type_trimatrix(int64_t);
+fwrite_type_trimatrix(uint64_t);
+fwrite_type_trimatrix(float);
+fwrite_type_trimatrix(double);
+
+
+
 
 /* --------------------- */
 /* -- fread_trimatrix -- */
 /* --------------------- */
-/* --------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fread_btrimatrix(char *filename, byte **m,long i0,long i1,long j0, long j1, long step)
-/* --------------------------------------------------------------------------------------------------- */
-{
-  long  i, ncol = j1-j0+1, nread;
-  FILE *f;
-
-  f = fopen(filename, "rb");
-  if(f == NULL) nrerror("Can't open file in fread_btrimatrix"); 
-
-  for(i=i0; i<=i1; i++) {
-    nread = fread(m[i]+j0, sizeof(byte), ncol, f);
-    if(nread != ncol) nrerror("fread_btrimatrix : can't read data");
-    ncol += step;
-  }
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) fread_i16trimatrix(char *filename, int16 **m,long i0,long i1,long j0, long j1, long step)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-  long  i, ncol = j1-j0+1, nread;
-  FILE *f;
-
-  f = fopen(filename, "rb");
-  if(f == NULL) nrerror("Can't open file in fread_i16trimatrix"); 
-
-  for(i=i0; i<=i1; i++) {
-    nread = fread(m[i]+j0, sizeof(int16), ncol, f);
-    if(nread != ncol) nrerror("fread_i16trimatrix : can't read data");
-    ncol += step;
-  }
-  fclose(f);
-}
-/* -------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fread_ui16trimatrix(char *filename, uint16 **m,long i0,long i1,long j0, long j1, long step)
-/* -------------------------------------------------------------------------------------------------------- */
-{
-  long  i, ncol = j1-j0+1, nread;
-  FILE *f;
-
-  f = fopen(filename, "rb");
-  if(f == NULL) nrerror("Can't open file in fread_ui16trimatrix"); 
-
-  for(i=i0; i<=i1; i++) {
-    nread = fread(m[i]+j0, sizeof(uint16), ncol, f);
-    if(nread != ncol) nrerror("fread_ui16trimatrix : can't read data");
-    ncol += step;
-  }
-  fclose(f);
-}
-/* -------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fread_itrimatrix(char *filename, int **m,long i0,long i1,long j0, long j1, long step)
-/* -------------------------------------------------------------------------------------------------- */
-{
-  long  i, ncol = j1-j0+1, nread;
-  FILE *f;
-
-  f = fopen(filename, "rb");
-  if(f == NULL) nrerror("Can't open file in fread_itrimatrix"); 
-
-  for(i=i0; i<=i1; i++) {
-    nread = fread(m[i]+j0, sizeof(int), ncol, f);
-    if(nread != ncol) nrerror("fread_itrimatrix : can't read data");
-    ncol += step;
-  }
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) fread_i32trimatrix(char *filename, int32 **m,long i0,long i1,long j0, long j1, long step)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-  long  i, ncol = j1-j0+1, nread;
-  FILE *f;
-
-  f = fopen(filename, "rb");
-  if(f == NULL) nrerror("Can't open file in fread_i32trimatrix"); 
-
-  for(i=i0; i<=i1; i++) {
-    nread = fread(m[i]+j0, sizeof(byte), ncol, f);
-    if(nread != ncol) nrerror("fread_i32trimatrix : can't read data");
-    ncol += step;
-  }
-  fclose(f);
-}
-/* -------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fread_f32trimatrix(char *filename, float32 **m,long i0,long i1,long j0, long j1, long step)
-/* -------------------------------------------------------------------------------------------------------- */
-{
-  long  i, ncol = j1-j0+1, nread;
-  FILE *f;
-
-  f = fopen(filename, "rb");
-  if(f == NULL) nrerror("Can't open file in fread_f32trimatrix"); 
-
-  for(i=i0; i<=i1; i++) {
-    nread = fread(m[i]+j0, sizeof(byte), ncol, f);
-    if(nread != ncol) nrerror("fread_f32trimatrix : can't read data");
-    ncol += step;
-  }
-  fclose(f);
-}
-/* -------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fread_f64trimatrix(char *filename, float64 **m,long i0,long i1,long j0, long j1, long step)
-/* -------------------------------------------------------------------------------------------------------- */
-{
-  long  i, ncol = j1-j0+1, nread;
-  FILE *f;
-
-  f = fopen(filename, "rb");
-  if(f == NULL) nrerror("Can't open file in fread_f64trimatrix"); 
-
-  for(i=i0; i<=i1; i++) {
-    nread = fread(m[i]+j0, sizeof(byte), ncol, f);
-    if(nread != ncol) nrerror("fread_f64trimatrix : can't read data");
-    ncol += step;
-  }
-  fclose(f);
-}
+
+#undef fread_type_trimatrix
+#define fread_type_trimatrix(t) \
+void short_name(t,fread_,trimatrix)(char * filename, t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, int32_t step) \
+{                                                                \
+    int32_t ncol = j1 - j0 + 1;                                  \
+    FILE * f = fopen(filename, "rb");                            \
+    if (f == NULL) {                                             \
+        nrerror("Can't open file %s in %s", filename, __func__); \
+    }                                                            \
+    for (int32_t i = i0; i <= i1; i++) {                         \
+        fread(m[i] + j0, sizeof(t), ncol, f);    \
+        ncol += step;                                            \
+    }                                                            \
+    fclose(f);                                                   \
+}
+
+fread_type_trimatrix(int8_t);
+fread_type_trimatrix(uint8_t);
+fread_type_trimatrix(int16_t);
+fread_type_trimatrix(uint16_t);
+fread_type_trimatrix(int32_t);
+fread_type_trimatrix(uint32_t);
+fread_type_trimatrix(int64_t);
+fread_type_trimatrix(uint64_t);
+fread_type_trimatrix(float);
+fread_type_trimatrix(double);
+
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nrio3.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrio3.c	(revision 822)
+++ 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__ */
Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nrlinalg.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrlinalg.c	(revision 822)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrlinalg.c	(revision 823)
@@ -24,219 +24,66 @@
 #include "nrlinalg.h"
 
+#undef transpose_type_matrix
+#define transpose_type_matrix(t) \
+void short_name(t,transpose_,matrix)(t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t ** D) \
+{                                              \
+	for (int32_t i = nrl; i <= nch; i++) {     \
+		for (int32_t j = ncl; j <= nch; j++) { \
+			D[j][i] = S[i][j];                 \
+		}                                      \
+	}                                          \
+}
 
-/* ---------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) transpose_bmatrix(byte **S, long nrl,long nrh,long ncl, long nch, byte **D)
-/* ---------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	
-	for(i=nrl; i<=nch; i++) {
-		for(j=ncl; j<=nch; j++) {
-			D[j][i] = S[i][j];
-		}
-	}
+transpose_type_matrix(int8_t);
+transpose_type_matrix(uint8_t);
+transpose_type_matrix(int16_t);
+transpose_type_matrix(uint16_t);
+transpose_type_matrix(int32_t);
+transpose_type_matrix(uint32_t);
+transpose_type_matrix(int64_t);
+transpose_type_matrix(uint64_t);
+transpose_type_matrix(float);
+transpose_type_matrix(double);
+transpose_type_matrix(rgb8);
+transpose_type_matrix(rgbx8);
+
+
+#undef transpose1_type_matrix
+#define transpose1_type_matrix(t) \
+void short_name(t,transpose1_,matrix)(t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \
+{                                                \
+    t tmp;                                       \
+	for (int32_t i = nrl; i <= nch; i++) {       \
+		for (int32_t j = i + 1; j <= nch; j++) { \
+			tmp = S[j][i];                       \
+            S[j][i] = S[i][j];                   \
+            S[i][j] = tmp;                       \
+		}                                        \
+	}                                            \
 }
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) transpose_si16matrix(sint16 **S, long nrl,long nrh,long ncl, long nch, sint16 **D)
-/* ------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	
-	for(i=nrl; i<=nch; i++) {
-		for(j=ncl; j<=nch; j++) {
-			D[j][i] = S[i][j];
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) transpose_ui16matrix(uint16 **S, long nrl,long nrh,long ncl, long nch, uint16 **D)
-/* ------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	
-	for(i=nrl; i<=nch; i++) {
-		for(j=ncl; j<=nch; j++) {
-			D[j][i] = S[i][j];
-		}
-	}
-}
-/* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) transpose_si32matrix(sint32 **S, long nrl,long nrh,long ncl, long nch, sint32 **D)
-/* ----------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	
-	for(i=nrl; i<=nch; i++) {
-		for(j=ncl; j<=nch; j++) {
-			D[j][i] = S[i][j];
-		}
-	}
-}
-/* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) transpose_ui32matrix(uint32 **S, long nrl,long nrh,long ncl, long nch, uint32 **D)
-/* ----------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	
-	for(i=nrl; i<=nch; i++) {
-		for(j=ncl; j<=nch; j++) {
-			D[j][i] = S[i][j];
-		}
-	}
-}
-/* ----------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) transpose_f32matrix(float32 **S, long nrl,long nrh,long ncl, long nch, float32 **D)
-/* ----------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	
-	for(i=nrl; i<=nch; i++) {
-		for(j=ncl; j<=nch; j++) {
-			D[j][i] = S[i][j];
-		}
-	}
-}
-/* -------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) transpose_dmatrix(float64 **S, long nrl,long nrh,long ncl, long nch, float64 **D)
-/* -------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	
-	for(i=nrl; i<=nch; i++) {
-		for(j=ncl; j<=nch; j++) {
-			D[j][i] = S[i][j];
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) transpose_rgb8matrix(rgb8 **S, long nrl,long nrh,long ncl, long nch, rgb8 **D)
-/* ------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	
-	for(i=nrl; i<=nch; i++) {
-		for(j=ncl; j<=nch; j++) {
-			D[j][i] = S[i][j];
-		}
-	}
-}
-/* ------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) transpose1_bmatrix(byte **S, long nrl,long nrh,long ncl, long nch)
-/* ------------------------------------------------------------------------------- */
-{
-	int i, j;
-	byte t;
-	
-	for(i=nrl; i<=nch; i++) {
-		for(j=i+1; j<=nch; j++) {
-			t       = S[j][i];
-			S[j][i] = S[i][j];
-			S[i][j] = t;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) transpose1_si16matrix(sint16 **S, long nrl,long nrh,long ncl, long nch)
-/* ---------------------------------------------------------------------------------- */
-{
-	int i, j;
-	int16 t;
-	
-	for(i=nrl; i<=nch; i++) {
-		for(j=i+1; j<=nch; j++) {
-			t       = S[j][i];
-			S[j][i] = S[i][j];
-			S[i][j] = t;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) transpose1_ui16matrix(uint16 **S, long nrl,long nrh,long ncl, long nch)
-/* ------------------------------------------------------------------------------------ */
-{
-	int i, j;
-	uint16 t;
-	
-	for(i=nrl; i<=nch; i++) {
-		for(j=i+1; j<=nch; j++) {
-			t       = S[j][i];
-			S[j][i] = S[i][j];
-			S[i][j] = t;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) transpose1_si32matrix(sint32 **S, long nrl,long nrh,long ncl, long nch)
-/* ---------------------------------------------------------------------------------- */
-{
-	int i, j;
-	int32 t;
-	
-	for(i=nrl; i<=nch; i++) {
-		for(j=i+1; j<=nch; j++) {
-			t       = S[j][i];
-			S[j][i] = S[i][j];
-			S[i][j] = t;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) transpose1_ui32matrix(uint32 **S, long nrl,long nrh,long ncl, long nch)
-/* ------------------------------------------------------------------------------------ */
-{
-	int i, j;
-	uint32 t;
-	
-	for(i=nrl; i<=nch; i++) {
-		for(j=i+1; j<=nch; j++) {
-			t       = S[j][i];
-			S[j][i] = S[i][j];
-			S[i][j] = t;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) transpose1_f32matrix(float32 **S, long nrl,long nrh,long ncl, long nch)
-/* ------------------------------------------------------------------------------- */
-{
-	int i, j;
-	float t;
-	
-	for(i=nrl; i<=nch; i++) {
-		for(j=i+1; j<=nch; j++) {
-			t       = S[j][i];
-			S[j][i] = S[i][j];
-			S[i][j] = t;
-		}
-	}
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) transpose1_f64matrix(float64 **S, long nrl,long nrh,long ncl, long nch)
-/* --------------------------------------------------------------------------------- */
-{
-	int i, j;
-	double t;
-	
-	for(i=nrl; i<=nch; i++) {
-		for(j=i+1; j<=nch; j++) {
-			t       = S[j][i];
-			S[j][i] = S[i][j];
-			S[i][j] = t;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) transpose1_rgb8matrix(rgb8 **S, long nrl,long nrh,long ncl, long nch)
-/* ---------------------------------------------------------------------------------- */
-{
-	int i, j;
-	rgb8 t;
-	
-	for(i=nrl; i<=nch; i++) {
-		for(j=i+1; j<=nch; j++) {
-			t       = S[j][i];
-			S[j][i] = S[i][j];
-			S[i][j] = t;
-		}
-	}
-}
+
+transpose1_type_matrix(int8_t);
+transpose1_type_matrix(uint8_t);
+transpose1_type_matrix(int16_t);
+transpose1_type_matrix(uint16_t);
+transpose1_type_matrix(int32_t);
+transpose1_type_matrix(uint32_t);
+transpose1_type_matrix(int64_t);
+transpose1_type_matrix(uint64_t);
+transpose1_type_matrix(float);
+transpose1_type_matrix(double);
+transpose1_type_matrix(rgb8);
+transpose1_type_matrix(rgbx8);
+
+
+
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nrlut.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrlut.c	(revision 822)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrlut.c	(revision 823)
@@ -13,6 +13,6 @@
 
 /* 
-* 2002/06/11 ajout des fonctions endline
-*/
+ * 2002/06/11 ajout des fonctions endline
+ */
 #include <stdio.h>
 #include <stddef.h>
@@ -28,304 +28,203 @@
 #include "nrlut.h"
 
-/* ----------------------------------------------------------------------- */
-IMAGE_EXPORT(void) init_blut(byte *v, int nl, int nh, int n0, int n1, byte k)
-/* ----------------------------------------------------------------------- */
-{
-	int i;
-	
-	if(nl<=nh) {
-		// normal case 
-		for(i=nl;   i< n0; i++) v[i] = 0;
-		for(i=n0;   i<=n1; i++) v[i] = k;
-		for(i=n1+1; i<nh; i++)  v[i] = 0;
-	} else {
-		for(i=nl;   i< n1; i++) v[i] = k;
-		for(i=n1;   i<=n0; i++) v[i] = 0;
-		for(i=n1+1; i<nh;  i++) v[i] = k;
-	}
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) init_ui8lut(uint8 *v, int nl, int nh, int n0, int n1, uint8 k)
-/* ------------------------------------------------------------------------ */
-{
-	int i;
-	
-	if(nl<=nh) {
-		// normal case 
-		for(i=nl;   i< n0; i++) v[i] = 0;
-		for(i=n0;   i<=n1; i++) v[i] = k;
-		for(i=n1+1; i<nh; i++)  v[i] = 0;
-	} else {
-		for(i=nl;   i< n1; i++) v[i] = k;
-		for(i=n1;   i<=n0; i++) v[i] = 0;
-		for(i=n1+1; i<nh;  i++) v[i] = k;
-	}
-}
-/* --------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) init_ui16lut(uint16 *v, int nl, int nh, int n0, int n1, uint16 k)
-/* --------------------------------------------------------------------------- */
-{
-	int i;
-	
-	if(nl<=nh) {
-		// normal case 
-		for(i=nl;   i< n0; i++) v[i] = 0;
-		for(i=n0;   i<=n1; i++) v[i] = k;
-		for(i=n1+1; i<=nh; i++) v[i] = 0;
-	} else {
-		for(i=nl;   i< n1; i++) v[i] = k;
-		for(i=n1;   i<=n0; i++) v[i] = 0;
-		for(i=n1+1; i<=nh; i++) v[i] = k;
-	}
-}
-/* --------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) init_si16lut(sint16 *v, int nl, int nh, int n0, int n1, sint16 k)
-/* --------------------------------------------------------------------------- */
-{
-	int i;
-	
-	if(nl<=nh) {
-		// normal case 
-		for(i=nl;   i< n0; i++) v[i] = 0;
-		for(i=n0;   i<=n1; i++) v[i] = k;
-		for(i=n1+1; i<=nh; i++) v[i] = 0;
-	} else {
-		for(i=nl;   i< n1; i++) v[i] = k;
-		for(i=n1;   i<=n0; i++) v[i] = 0;
-		for(i=n1+1; i<=nh; i++) v[i] = k;
-	}
-}
-/* --------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) init_ui32lut(uint32 *v, int nl, int nh, int n0, int n1, uint32 k)
-/* --------------------------------------------------------------------------- */
-{
-	int i;
-	
-	if(nl<=nh) {
-		// normal case 
-		for(i=nl;   i< n0; i++) v[i] = 0;
-		for(i=n0;   i<=n1; i++) v[i] = k;
-		for(i=n1+1; i<=nh; i++) v[i] = 0;
-	} else {
-		for(i=nl;   i< n1; i++) v[i] = k;
-		for(i=n1;   i<=n0; i++) v[i] = 0;
-		for(i=n1+1; i<=nh; i++) v[i] = k;
-	}
-}
-/* --------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) init_i32lut(sint32 *v, int nl, int nh, int n0, int n1, sint32 k)
-/* --------------------------------------------------------------------------- */
-{
-	int i;
-	
-	if(nl<=nh) {
-		// normal case 
-		for(i=nl;   i< n0; i++) v[i] = 0;
-		for(i=n0;   i<=n1; i++) v[i] = k;
-		for(i=n1+1; i<=nh; i++) v[i] = 0;
-	} else {
-		for(i=nl;   i< n1; i++) v[i] = k;
-		for(i=n1;   i<=n0; i++) v[i] = 0;
-		for(i=n1+1; i<=nh; i++) v[i] = k;
-	}
-}
-/* -------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) init_rgb8lut(rgb8 *v, int nl, int nh, int n0, int n1, rgb8 k)
-/* -------------------------------------------------------------------------- */
-{
-	int i;
-	
-	if(nl<=nh) {
-		// normal case 
-		for(i=nl;   i< n0; i++) { v[i].r = 0;   v[i].g = 0;   v[i].b = 0;}
-		for(i=n0;   i<=n1; i++) { v[i].r = k.r; v[i].g = k.g; v[i].b = k.b;}
-		for(i=n1+1; i<=nh; i++)  { v[i].r = 0;   v[i].g = 0;  v[i].b = 0;}
-	} else {
-		for(i=nl;   i< n1; i++) { v[i].r = k.r; v[i].g = k.g; v[i].b = k.b;}
-		for(i=n1;   i<=n0; i++) { v[i].r = 0;   v[i].g = 0;   v[i].b = 0;}
-		for(i=n1+1; i<=nh; i++) { v[i].r = k.r; v[i].g = k.g; v[i].b = k.b;}
-	}
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) lut_bmatrix(byte **S, long nrl,long nrh,long ncl, long nch, byte *L, byte **D)
-/* ------------------------------------------------------------------------------------------- */
-{
-    int i, j;
-
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            D[i][j] = L[(int)S[i][j]];
-        }
-    }
-}
-/* -------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) lut_ui8matrix(uint8 **S, long nrl,long nrh,long ncl, long nch, uint8 *L, uint8 **D)
-/* -------------------------------------------------------------------------------------------- */
-{
-    int i, j;
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            D[i][j] = L[(int)S[i][j]];
-        }
-    }
-}
-/* -------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) lut_si8matrix(sint8 **S, long nrl,long nrh,long ncl, long nch, sint8 *L, sint8 **D)
-/* -------------------------------------------------------------------------------------------- */
-{
-    int i, j;
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            D[i][j] = L[(int)S[i][j]];
-        }
-    }
-}
-/* -------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) lut_ui16matrix(uint16 **S, long nrl, long nrh, long ncl, long nch, uint16 *L, uint16 **D)
-/* -------------------------------------------------------------------------------------------------- */
-{
-    int i, j;
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            D[i][j] = L[(int)S[i][j]];
-        }
-    }
-}
-/* -------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) lut_si16matrix(sint16 **S, long nrl, long nrh, long ncl, long nch, sint16 *L, sint16 **D)
-/* -------------------------------------------------------------------------------------------------- */
-{
-    int i, j;
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            D[i][j] = L[(int)S[i][j]];
-        }
-    }
-}
-/* -------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) lut_ui32matrix(uint32 **S, long nrl, long nrh, long ncl, long nch, uint32 *L, uint32 **D)
-/* -------------------------------------------------------------------------------------------------- */
-{
-    int i, j;
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            D[i][j] = L[(int)S[i][j]];
-        }
-    }
-}
-/* -------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) lut_si32matrix(sint32 **S, long nrl, long nrh, long ncl, long nch, sint32 *L, sint32 **D)
-/* -------------------------------------------------------------------------------------------------- */
-{
-    int i, j;
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            D[i][j] = L[(int)S[i][j]];
-        }
-    }
-}
-/* ------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) lut_rgb8matrix(rgb8 **S, long nrl, long nrh, long ncl, long nch, rgb8 *L, rgb8 **D)
-/* ------------------------------------------------------------------------------------------------ */
-{
-	int i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			D[i][j].r = L[S[i][j].r].r;
-			D[i][j].g = L[S[i][j].g].g;
-			D[i][j].b = L[S[i][j].b].b;
-		}
-	}
-}
-/* --------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) lut_ui16matrix_ui8matrix(uint16 **S, long nrl, long nrh, long ncl, long nch, uint8 *L, uint8 **D)
-/* --------------------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			D[i][j] = L[(int)S[i][j]];
-		}
-	}
-}
-/* --------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) lut_ui32matrix_ui16matrix(uint32 **S, long nrl, long nrh, long ncl, long nch, uint16 *L, uint16 **D)
-/* --------------------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			D[i][j] = L[(int)S[i][j]];
-		}
-	}
-}
-/* ---------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) histogram_bmatrix(byte **S, long nrl, long nrh, long ncl, long nch, int32 *H)
-/* ---------------------------------------------------------------------------- */
-{
-	int i, j;
-	byte *Si;
-	
-	for(i=nrl; i<=nrh; i++) {
-		Si = S[i];
-		for(j=ncl; j<=nch; j++) {
-			H[(int) Si[j]]++;
-		}
-	}
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) histogram_ui16matrix(uint16 **S, long nrl, long nrh, long ncl, long nch, int32 *H)
-/* --------------------------------------------------------------------------------- */
-{
-	int i, j;
-	uint16 *Si;
-	
-	for(i=nrl; i<=nrh; i++) {
-		Si = S[i];
-		for(j=ncl; j<=nch; j++) {
-			H[Si[j]]++;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) histogram_rgb8matrix(rgb8 **S, long nrl, long nrh, long ncl, long nch, rgb32 *H)
-/* ------------------------------------------------------------------------------- */
-{
-	int i, j;
-	rgb8 *Si;
-	int r, b, g;
+
+#undef init_type_lut
+#define init_type_lut(t) \
+void short_name(t,init_,lut)(t * v, int32_t nl, int32_t nh, int32_t n0, int32_t n1, t k) \
+{                                                \
+    if (nl <= nh) {                              \
+        for (int32_t i = nl; i < n0; i++) {      \
+            v[i] = 0;                            \
+        }                                        \
+        for (int32_t i = n0; i <= n1; i++) {     \
+            v[i] = k;                            \
+        }                                        \
+        for (int32_t i = n1 + 1; i <= nh; i++) { \
+            v[i] = 0;                            \
+        }                                        \
+    }                                            \
+    else {                                       \
+        for (int32_t i = nl; i < n1; i++) {      \
+            v[i] = k;                            \
+        }                                        \
+        for (int32_t i = n1; i <= n0; i++) {     \
+            v[i] = 0;                            \
+        }                                        \
+        for (int32_t i = n1 + 1; i <= nh; i++) { \
+            v[i] = k;                            \
+        }                                        \
+    }                                            \
+}
+
+
+init_type_lut(int8_t);
+init_type_lut(uint8_t);
+init_type_lut(int16_t);
+init_type_lut(uint16_t);
+init_type_lut(int32_t);
+init_type_lut(uint32_t);
+
+
+
+void init_rgb8lut(rgb8 * v, int32_t nl, int32_t nh, int32_t n0, int32_t n1, rgb8 k)
+{
+    if (nl <= nh) {
+        // normal case 
+        for (int32_t i = nl; i < n0; i++) {
+            v[i].r = 0;
+            v[i].g = 0;
+            v[i].b = 0;
+        }
+        for (int32_t i = n0; i <= n1; i++) {
+            v[i].r = k.r;
+            v[i].g = k.g;
+            v[i].b = k.b;
+        }
+        for (int32_t i = n1 + 1; i <= nh; i++) {
+            v[i].r = 0;
+            v[i].g = 0;
+            v[i].b = 0;
+        }
+    }
+    else {
+        for (int32_t i = nl; i < n1; i++) {
+            v[i].r = k.r;
+            v[i].g = k.g;
+            v[i].b = k.b;
+        }
+        for (int32_t i = n1; i <= n0; i++) {
+            v[i].r = 0;
+            v[i].g = 0;
+            v[i].b = 0;
+        }
+        for (int32_t i = n1 + 1; i <= nh; i++) {
+            v[i].r = k.r;
+            v[i].g = k.g;
+            v[i].b = k.b;
+        }
+    }
+}
+
+
+#undef lut_type_matrix
+#define lut_type_matrix(t) \
+void short_name(t,lut_,matrix)(t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t * L, t ** D) \
+{                                              \
+    for (int32_t i = nrl; i <= nrh; i++) {     \
+        for (int32_t j = ncl; j <= nch; j++) { \
+            D[i][j] = L[(int32_t) S[i][j]];    \
+        }                                      \
+    }                                          \
+}
+
+lut_type_matrix(int8_t);
+lut_type_matrix(uint8_t);
+lut_type_matrix(int16_t);
+lut_type_matrix(uint16_t);
+lut_type_matrix(int32_t);
+lut_type_matrix(uint32_t);
+
+
+
+void lut_rgb8matrix(rgb8 ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8 * L, rgb8 ** D)
+{
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            D[i][j].r = L[S[i][j].r].r;
+            D[i][j].g = L[S[i][j].g].g;
+            D[i][j].b = L[S[i][j].b].b;
+        }
+    }
+}
+
+
+void lut_ui16matrix_ui8matrix(uint16_t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, uint8_t * L, uint8_t ** D)
+{
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            D[i][j] = L[(int32_t) S[i][j]];
+        }
+    }
+}
+
+void lut_i16matrix_i8matrix(int16_t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, uint8_t * L, int8_t ** D)
+{
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            D[i][j] = L[(int32_t) S[i][j]];
+        }
+    }
+}
+
+void lut_ui32matrix_ui16matrix(uint32_t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, uint16_t * L, uint16_t ** D)
+{
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            D[i][j] = L[(int32_t) S[i][j]];
+        }
+    }
+}
+
+void lut_i32matrix_i16matrix(int32_t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, uint16_t * L, int16_t ** D)
+{
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            D[i][j] = L[(int32_t) S[i][j]];
+        }
+    }
+}
+
+
+#undef histogram_type_matrix
+#define histogram_type_matrix(t) \
+void short_name(t,histogram_,matrix)(t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t * H) \
+{                                              \
+    t * Si;                                    \
+    for (int32_t i = nrl; i <= nrh; i++) {     \
+        Si = S[i];                             \
+        for (int32_t j = ncl; j <= nch; j++) { \
+            H[(int32_t) Si[j]]++;              \
+        }                                      \
+    }                                          \
+}
+
+histogram_type_matrix(int8_t);
+histogram_type_matrix(uint8_t);
+histogram_type_matrix(int16_t);
+histogram_type_matrix(uint16_t);
+histogram_type_matrix(int32_t);
+histogram_type_matrix(uint32_t);
+
+
+
+void histogram_rgb8matrix(rgb8 ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb32 * H)
+{
+    rgb8 * Si;
+    int r, b, g;
     (void) Si;
-	
-	//FUNCTION_NAME("Histogram_rgbmatrix");
-	
-	for(i=nrl; i<=nrh; i++) {
-		Si = S[i];
-		//PROGRESS_INFO(function_name, i, nrl, nrh);
-		for(j=ncl; j<=nch; j++) {
-			
-			//H[Si[j].r].r++;
-			//H[Si[j].g].g++;
-			//H[Si[j].b].b++;
-			
-			r = S[i][j].r;
-			g = S[i][j].g;
-			b = S[i][j].b;
-			
-			H[r].r++;
-			H[g].g++;
-			H[b].b++;
-		}
-	}
-	
-	//END;
-	return;
-}
+
+
+    for (int32_t i = nrl; i <= nrh; i++) {
+        Si = S[i];
+        for (int32_t j = ncl; j <= nch; j++) {
+            r = S[i][j].r;
+            g = S[i][j].g;
+            b = S[i][j].b;
+
+            H[r].r++;
+            H[g].g++;
+            H[b].b++;
+        }
+    }
+    return;
+}
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nrmem1.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrmem1.c	(revision 822)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrmem1.c	(revision 823)
@@ -30,112 +30,29 @@
  * -----------
  */
-/* ---------------------------------------------------------------- */
-IMAGE_EXPORT(void) dup_si8vector(sint8 *X, long nl, long nh, sint8 *Y)
-/* ---------------------------------------------------------------- */
-{
-    int i;
-    for(i=nl; i<=nh; i++) {
-        Y[i] = X[i];
-    }
-}
-/* ---------------------------------------------------------------- */
-IMAGE_EXPORT(void) dup_ui8vector(uint8 *X, long nl, long nh, uint8 *Y)
-/* ---------------------------------------------------------------- */
-{
-    int i;
-    for(i=nl; i<=nh; i++) {
-        Y[i] = X[i];
-    }
-}
-/* ------------------------------------------------------------------- */
-IMAGE_EXPORT(void) dup_si16vector(sint16 *X, long nl, long nh, sint16 *Y)
-/* ------------------------------------------------------------------- */
-{
-    int i;
-    for(i=nl; i<=nh; i++) {
-        Y[i] = X[i];
-    }
-}
-/* ------------------------------------------------------------------- */
-IMAGE_EXPORT(void) dup_ui16vector(uint16 *X, long nl, long nh, uint16 *Y)
-/* ------------------------------------------------------------------- */
-{
-    int i;
-    for(i=nl; i<=nh; i++) {
-        Y[i] = X[i];
-    }
-}
-/* -------------------------------------------------------------------- */
-IMAGE_EXPORT(void) dup_si32vector(sint32 *X, long nl, long nh, sint32 *Y)
-/* -------------------------------------------------------------------- */
-{
-    int i;
-    for(i=nl; i<=nh; i++) {
-        Y[i] = X[i];
-    }
-}
-/* ------------------------------------------------------------------- */
-IMAGE_EXPORT(void) dup_ui32vector(uint32 *X, long nl, long nh, uint32 *Y)
-/* ------------------------------------------------------------------- */
-{
-    int i;
-    for(i=nl; i<=nh; i++) {
-        Y[i] = X[i];
-    }
-}
-/* -------------------------------------------------------------------- */
-IMAGE_EXPORT(void) dup_si64vector(sint64 *X, long nl, long nh, sint64 *Y)
-/* -------------------------------------------------------------------- */
-{
-    int i;
-    for(i=nl; i<=nh; i++) {
-        Y[i] = X[i];
-    }
-}
-/* ------------------------------------------------------------------- */
-IMAGE_EXPORT(void) dup_ui64vector(uint64 *X, long nl, long nh, uint64 *Y)
-/* ------------------------------------------------------------------- */
-{
-    int i;
-    for(i=nl; i<=nh; i++) {
-        Y[i] = X[i];
-    }
-}
-/* -------------------------------------------------------------------- */
-IMAGE_EXPORT(void) dup_f32vector(float32 *X, long nl, long nh, float32 *Y)
-/* -------------------------------------------------------------------- */
-{
-    int i;
-    for(i=nl; i<=nh; i++) {
-        Y[i] = X[i];
-    }
-}
-/* -------------------------------------------------------------------- */
-IMAGE_EXPORT(void) dup_f64vector(float64 *X, long nl, long nh, float64 *Y)
-/* -------------------------------------------------------------------- */
-{
-    int i;
-    for(i=nl; i<=nh; i++) {
-        Y[i] = X[i];
-    }
-}
-/* --------------------------------------------------------------- */
-IMAGE_EXPORT(void) dup_rgb8vector(rgb8 *X, long nl, long nh, rgb8 *Y)
-/* --------------------------------------------------------------- */
-{
-    int i;
-    for(i=nl; i<=nh; i++) {
-        Y[i] = X[i];
-    }
-}
-/* ------------------------------------------------------------------ */
-IMAGE_EXPORT(void) dup_rgbx8vector(rgbx8 *X, long nl, long nh, rgbx8 *Y)
-/* ------------------------------------------------------------------ */
-{
-    int i;
-    for(i=nl; i<=nh; i++) {
-        Y[i] = X[i];
-    }
-}
+
+
+#undef dup_type_vector
+#define dup_type_vector(t) \
+void short_name(t,dup_,vector)(t * X, int32_t nl, int32_t nh, t * Y) \
+{                                        \
+    for (int32_t i = nl; i <= nh; i++) { \
+        Y[i] = X[i];                     \
+    }                                    \
+}
+
+dup_type_vector(int8_t);
+dup_type_vector(uint8_t);
+dup_type_vector(int16_t);
+dup_type_vector(uint16_t);
+dup_type_vector(int32_t);
+dup_type_vector(uint32_t);
+dup_type_vector(int64_t);
+dup_type_vector(uint64_t);
+dup_type_vector(float);
+dup_type_vector(double);
+dup_type_vector(rgb8);
+dup_type_vector(rgbx8);
+
+
 /*
  * --------------------
@@ -143,125 +60,103 @@
  * --------------------
  */
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) split_rgb8vector(rgb8 *X, long nl, long nh, uint8 *R, uint8 *G, uint8 *B)
-/* -------------------------------------------------------------------------------------- */
-{
-	long i;
-	rgb8 x;
-	for(i=nl; i<=nh; i++) {
-		x    = X[i];
-		R[i] = x.r;
-		G[i] = x.g;
-		B[i] = x.b;
-	}
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) split_rgb32vector(rgb32 *X, long nl, long nh, uint32 *R, uint32 *G, uint32 *B)
-/* ------------------------------------------------------------------------------------------- */
-{
-	long i;
-	for(i=nl; i<=nh; i++) {
-		R[i] = X[i].r;
-		G[i] = X[i].g;
-		B[i] = X[i].b;
-	}
-}
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) merge_rgb8vector(uint8 *R, uint8 *G, uint8 *B, long nl, long nh, rgb8 *X)
-/* -------------------------------------------------------------------------------------- */
-{
-	long i;
-	for(i=nl; i<=nh; i++) {
-		X[i].r = R[i];
-		X[i].g = G[i];
-		X[i].b = B[i];
-	}
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) merge_rgb32vector(uint32 *R, uint32 *G, uint32 *B, long nl, long nh, rgb32 *X)
-/* ------------------------------------------------------------------------------------------- */
-{
-	long i;
-	for(i=nl; i<=nh; i++) {
-		X[i].r = R[i];
-		X[i].g = G[i];
-		X[i].b = B[i];
-	}
-}
-
-/* ---------------- */
-/* -- Convertion -- */
-/* ---------------- */
-
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_si8vector_si16vector(sint8 *X, long nl, long nh, sint16 *Y)
-/* -------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (sint16) X[i];
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_si8vector_si32vector(sint8 *X, long nl, long nh, sint32 *Y)
-/* -------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (sint32) X[i];
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_si8vector_f32vector(sint8 *X, long nl, long nh, float32 *Y)
-/* -------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (float32) X[i];
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_si8vector_f64vector(sint8 *X, long nl, long nh, float64 *Y)
-/* -------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (float64) X[i];
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_ui8vector_ui16vector(uint8 *X, long nl, long nh, uint16 *Y)
-/* -------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (uint16) X[i];
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_ui8vector_ui32vector(uint8 *X, long nl, long nh, uint32 *Y)
-/* -------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (uint32) X[i];
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_ui8vector_f32vector(uint8 *X, long nl, long nh, float32 *Y)
-/* -------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (float32) X[i];
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_ui8vector_f64vector(uint8 *X, long nl, long nh, float64 *Y)
-/* -------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (float64) X[i];
-}
-/* ------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) convert_ui8vector_rgb8vector(uint8 *X, long nl, long nh, rgb8 *Y)
-/* ------------------------------------------------------------------------------ */
-{
-    long i;
-    for(i=nl; i<=nh; i++) {
+
+
+void split_rgb8vector(rgb8 * X, int32_t nl, int32_t nh, uint8_t * R, uint8_t * G, uint8_t * B)
+{
+    for (int32_t i = nl; i <= nh; i++) {
+        R[i] = X[i].r;
+        G[i] = X[i].g;
+        B[i] = X[i].b;
+    }
+}
+
+void split_rgb32vector(rgb32 * X, int32_t nl, int32_t nh, uint32_t * R, uint32_t * G, uint32_t * B)
+{
+    for (int32_t i = nl; i <= nh; i++) {
+        R[i] = X[i].r;
+        G[i] = X[i].g;
+        B[i] = X[i].b;
+    }
+}
+
+void merge_rgb8vector(uint8_t * R, uint8_t * G, uint8_t * B, int32_t nl, int32_t nh, rgb8 * X)
+{
+    for (int32_t i = nl; i <= nh; i++) {
+        X[i].r = R[i];
+        X[i].g = G[i];
+        X[i].b = B[i];
+    }
+}
+
+
+void merge_rgb32vector(uint32_t * R, uint32_t * G, uint32_t * B, int32_t nl, int32_t nh, rgb32 * X)
+{
+    for (int32_t i = nl; i <= nh; i++) {
+        X[i].r = R[i];
+        X[i].g = G[i];
+        X[i].b = B[i];
+    }
+}
+
+/* ---------------- */
+/* -- Conversion -- */
+/* ---------------- */
+
+#undef convert_type1_vector_type2_vector
+#define convert_type1_vector_type2_vector(t1, t2) \
+void short_name(t1,convert_,short_name(t2,vector_,vector))(t1 * X, int32_t nl, int32_t nh, t2 * Y) \
+{                                        \
+    for (int32_t i = nl; i <= nh; i++) { \
+        Y[i] = (t2) X[i];                \
+    }                                    \
+}
+
+convert_type1_vector_type2_vector(int8_t,int16_t);
+convert_type1_vector_type2_vector(int8_t,int32_t);
+convert_type1_vector_type2_vector(int8_t,float);
+convert_type1_vector_type2_vector(int8_t,double);
+convert_type1_vector_type2_vector(uint8_t,uint16_t);
+convert_type1_vector_type2_vector(uint8_t,uint32_t);
+convert_type1_vector_type2_vector(uint8_t,float);
+convert_type1_vector_type2_vector(uint8_t,double);
+convert_type1_vector_type2_vector(int16_t,int32_t);
+convert_type1_vector_type2_vector(int16_t,float);
+convert_type1_vector_type2_vector(int16_t,double);
+convert_type1_vector_type2_vector(uint16_t,uint32_t);
+convert_type1_vector_type2_vector(uint16_t,float);
+convert_type1_vector_type2_vector(uint16_t,double);
+convert_type1_vector_type2_vector(int32_t,float);
+convert_type1_vector_type2_vector(int32_t,double);
+convert_type1_vector_type2_vector(uint32_t,float);
+convert_type1_vector_type2_vector(uint32_t,double);
+convert_type1_vector_type2_vector(int16_t,int8_t);
+convert_type1_vector_type2_vector(uint16_t,uint8_t);
+convert_type1_vector_type2_vector(int32_t,int8_t);
+convert_type1_vector_type2_vector(int32_t,int16_t);
+convert_type1_vector_type2_vector(uint32_t,uint8_t);
+convert_type1_vector_type2_vector(uint32_t,uint16_t);
+convert_type1_vector_type2_vector(float,int8_t);
+convert_type1_vector_type2_vector(float,uint8_t);
+convert_type1_vector_type2_vector(float,int16_t);
+convert_type1_vector_type2_vector(float,uint16_t);
+convert_type1_vector_type2_vector(float,int32_t);
+convert_type1_vector_type2_vector(float,uint32_t);
+convert_type1_vector_type2_vector(double,int8_t);
+convert_type1_vector_type2_vector(double,uint8_t);
+convert_type1_vector_type2_vector(double,int16_t);
+convert_type1_vector_type2_vector(double,uint16_t);
+convert_type1_vector_type2_vector(double,int32_t);
+convert_type1_vector_type2_vector(double,uint32_t);
+convert_type1_vector_type2_vector(double,float);
+
+
+
+
+
+
+
+void convert_ui8vector_rgb8vector(uint8_t * X, int32_t nl, int32_t nh, rgb8 * Y)
+{
+    for (int32_t i = nl; i <= nh; i++) {
         Y[i].r = X[i];
         Y[i].g = X[i];
@@ -269,10 +164,8 @@
     }
 }
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_ui8vector_rgbx8vector(uint8 *X, long nl, long nh, rgbx8 *Y)
-/* -------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++) {
+
+void convert_ui8vector_rgbx8vector(uint8_t * X, int32_t nl, int32_t nh, rgbx8 * Y)
+{
+    for (int32_t i = nl; i <= nh; i++) {
         Y[i].r = X[i];
         Y[i].g = X[i];
@@ -281,256 +174,20 @@
     }
 }
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_si16vector_si32vector(sint16 *X, long nl, long nh, sint32 *Y)
-/* ---------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (sint32) X[i];
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_si16vector_f32vector(sint16 *X, long nl, long nh, float32 *Y)
-/* ---------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (float32) X[i];
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_si16vector_f64vector(sint16 *X, long nl, long nh, float64 *Y)
-/* ---------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (float64) X[i];
-}
-
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_ui16vector_ui32vector(uint16 *X, long nl, long nh, uint32 *Y)
-/* ---------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (uint32) X[i];
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_ui16vector_f32vector(uint16 *X, long nl, long nh, float32 *Y)
-/* ---------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (float32) X[i];
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_ui16vector_f64vector(uint16 *X, long nl, long nh, float64 *Y)
-/* ---------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (float64) X[i];
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_si32vector_f32vector(sint32 *X, long nl, long nh, float32 *Y)
-/* ---------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (float32) X[i];
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_si32vector_f64vector(sint32 *X, long nl, long nh, float64 *Y)
-/* ---------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (float64) X[i];
-}
-/* ----------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_ui32vector_f32vector(uint32 *X, long nl, long nh, float32 *Y)
-/* ----------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (float32) X[i];
-}
-/* ----------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_ui32vector_f64vector(uint32 *X, long nl, long nh, float64 *Y)
-/* ----------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (float64) X[i];
-}
-// === Down === //
-/* ------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_si16vector_si8vector(sint16 *X, long nl, long nh, sint8 *Y)
-/* ------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (sint8) X[i];
-}
-/* ------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_ui16vector_ui8vector(uint16 *X, long nl, long nh, uint8 *Y)
-/* ------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (uint8) X[i];
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_si32vector_si8vector(sint32 *X, long nl, long nh, sint8 *Y)
-/* -------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (sint8) X[i];
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_si32vector_si16vector(sint32 *X, long nl, long nh, sint16 *Y)
-/* ---------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (sint16) X[i];
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_ui32vector_ui8vector(uint32 *X, long nl, long nh, uint8 *Y)
-/* -------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (uint8) X[i];
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_ui32vector_ui16vector(uint32 *X, long nl, long nh, uint16 *Y)
-/* ---------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (uint16) X[i];
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_f32vector_si8vector(float32 *X, long nl, long nh, sint8 *Y)
-/* -------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (sint8) X[i];
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_f32vector_ui8vector(float32 *X, long nl, long nh, uint8 *Y)
-/* -------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (uint8) X[i];
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_f32vector_si16vector(float32 *X, long nl, long nh, sint16 *Y)
-/* ---------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (sint16) X[i];
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_f32vector_ui16vector(float32 *X, long nl, long nh, uint16 *Y)
-/* ---------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (uint16) X[i];
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_f32vector_si32vector(float32 *X, long nl, long nh, sint32 *Y)
-/* ---------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (sint32) X[i];
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_f32vector_ui32vector(float32 *X, long nl, long nh, uint32 *Y)
-/* ---------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (uint32) X[i];
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_f64vector_si8vector(float64 *X, long nl, long nh, sint8 *Y)
-/* -------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (sint8) X[i];
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_f64vector_ui8vector(float64 *X, long nl, long nh, uint8 *Y)
-/* -------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (uint8) X[i];
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_f64vector_si16vector(float64 *X, long nl, long nh, sint16 *Y)
-/* ---------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (sint16) X[i];
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_f64vector_ui16vector(float64 *X, long nl, long nh, uint16 *Y)
-/* ---------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (uint16) X[i];
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_f64vector_si32vector(float64 *X, long nl, long nh, sint32 *Y)
-/* ---------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (sint32) X[i];
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_f64vector_ui32vector(float64 *X, long nl, long nh, uint32 *Y)
-/* ---------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (uint32) X[i];
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_f64vector_f32vector(float64 *X, long nl, long nh, float32 *Y)
-/* ---------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++)
-        Y[i] = (float32) X[i];
-}
-/* ------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) convert_rgb8vector_ui8vector(rgb8 *X, long nl, long nh, uint8 *Y)
-/* ------------------------------------------------------------------------------ */
-{
-    long i;
-    for(i=nl; i<=nh; i++) {
+
+
+void convert_rgb8vector_ui8vector(rgb8 * X, int32_t nl, int32_t nh, uint8_t * Y)
+{
+    for (int32_t i = nl; i <= nh; i++) {
         Y[i] = (X[i].r + X[i].g + X[i].b) / 3;
     }
 }
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) convert_rgbx8vector_ui8vector(rgbx8 *X, long nl, long nh, uint8 *Y)
-/* -------------------------------------------------------------------------------- */
-{
-    long i;
-    for(i=nl; i<=nh; i++) {
+
+void convert_rgbx8vector_ui8vector(rgbx8 * X, int32_t nl, int32_t nh, uint8_t * Y)
+{
+    for (int32_t i = nl; i <= nh; i++) {
         Y[i] = (X[i].r + X[i].g + X[i].b) / 3;
     }
 }
+
 /*
  * ---------------
@@ -538,22 +195,18 @@
  * ---------------
  */
-/* ------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) lowpart_ui16vector_ui8vector(uint16 *X, long nl,long nh, uint8 *Y)
-/* ------------------------------------------------------------------------------- */
-{
-	int i;
-	for(i=nl; i<=nh; i++) {
-		Y[i] = X[i] & 0xff;
-	}
-}
-/* ------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) lowpart_ui32vector_ui8vector(uint32 *X, long nl,long nh, uint8 *Y)
-/* ------------------------------------------------------------------------------- */
-{
-	int i;
-	for(i=nl; i<=nh; i++) {
-		Y[i] = X[i] & 0xff;
-	}
-}
-
-
+
+void lowpart_ui16vector_ui8vector(uint16_t * X, int32_t nl, int32_t nh, uint8_t * Y)
+{
+    for(int32_t i = nl; i <= nh; i++) {
+        Y[i] = X[i] & 0xff;
+    }
+}
+
+void lowpart_ui32vector_ui8vector(uint32_t * X, int32_t nl, int32_t nh, uint8_t * Y)
+{
+    for (int32_t i = nl; i <= nh; i++) {
+        Y[i] = X[i] & 0xff;
+    }
+}
+
+
