Index: /soft/giet_vm/applications/rosenfeld/Makefile
===================================================================
--- /soft/giet_vm/applications/rosenfeld/Makefile	(revision 822)
+++ /soft/giet_vm/applications/rosenfeld/Makefile	(revision 823)
@@ -6,4 +6,6 @@
 
 TARGET ?= linux
+IGNORE_ASSERT ?= false
+
 #
 # -- Config ----------
@@ -11,12 +13,11 @@
 ifeq ($(TARGET),giet-vm)
 
-C_DEBUG_FLAGS = -O0
 C_OPTIM_FLAGS = -std=c99 -O2 -fstrict-aliasing
 C_OS_FLAGS = -DGTODay -DTARGET_OS=GIETVM
 C_CONFIG_FLAGS = -DCLI
 C_INC_FLAGS = -I$(INC_PATH) -Inrc2/include -I../.. -I../../giet_libs -I../../giet_xml/
-CFLAGSCPU := -mips32 -EL -G0 -mhard-float -fomit-frame-pointer -fno-builtin -ffreestanding
+CFLAGSCPU = -mips32 -EL -G0 -mhard-float -fomit-frame-pointer -fno-builtin -ffreestanding
 
-LDFLAGS := -Lnrc2 -L../../build/libs -Trosenfeld.ld --start-group -lnrc2x -luser -lmath --end-group
+LDFLAGS = -Lnrc2 -L../../build/libs -Trosenfeld.ld --start-group -lnrc2x -luser -lmath --end-group
 
 endif
@@ -28,5 +29,4 @@
 
 # -- Config ----------
-C_DEBUG_FLAGS = -O0
 C_OPTIM_FLAGS = -std=c99 -O2 -fstrict-aliasing
 C_OS_FLAGS = -DGTODay -DTARGET_OS=LINUX -D_GNU_SOURCE
@@ -34,6 +34,9 @@
 C_INC_FLAGS = -I$(INC_PATH) -Inrc2/include
 CFLAGSCPU = 
+ifeq ($(IGNORE_ASSERT),true)
+C_OPTIM_FLAGS := $(C_OPTIM_FLAGS) -DNDEBUG
+endif
 
-LDFLAGS := -Lnrc2 -Wl,--start-group -lnrc2x -lm -lpthread -Wl,--end-group
+LDFLAGS = -Lnrc2 -Wl,--start-group -lnrc2x -lm -lpthread -Wl,--end-group
 
 endif
@@ -41,8 +44,7 @@
 
 
-CFLAGSW := -Wredundant-decls -Wdisabled-optimization -Winline -Wpointer-arith -Wsign-compare -Wendif-labels -Wno-unused-function -Wno-unused-variable
+CFLAGSW = -Wredundant-decls -Wdisabled-optimization -Winline -Wpointer-arith -Wsign-compare -Wendif-labels -Wno-unused-function -Wno-unused-variable
 
 # -- Flags ----------
-#CFLAGS = $(C_DEBUG_FLAGS) $(C_OS_FLAGS) $(C_INC_FLAGS) $(C_CONFIG_FLAGS)
 CFLAGS = $(C_OPTIM_FLAGS) $(C_OS_FLAGS) $(C_INC_FLAGS) $(C_CONFIG_FLAGS) -g -Wall $(CFLAGSW) $(CFLAGSCPU)
 
Index: /soft/giet_vm/applications/rosenfeld/include/clock.h
===================================================================
--- /soft/giet_vm/applications/rosenfeld/include/clock.h	(revision 822)
+++ /soft/giet_vm/applications/rosenfeld/include/clock.h	(revision 823)
@@ -7,4 +7,5 @@
 #include "nrc_os_config.h"
 #if TARGET_OS == LINUX
+    #include <x86intrin.h>
     #include <sys/time.h>
 #endif
@@ -17,9 +18,11 @@
  * - CLOCK_APP_CREATE;
  * - CLOCK_THREAD_START(thread_id);
- * - CLOCK_THREAD_COMPUTE_START(thread_id;
- * - CLOCK_THREAD_START_STEP(thread_id, step_id)
- * - CLOCK_THREAD_END_STEP(thread_id, step_id)
- * - (repeat num_steps times)
- * - CLOCK_THREAD_COMPUTE_END(thread_id);
+ * - Repeat num_runs times:
+ *     - CLOCK_THREAD_COMPUTE_START(thread_id;
+ *     - Repeat num_step times:
+ *         - CLOCK_THREAD_START_STEP(thread_id, step_id)
+ *         - CLOCK_THREAD_END_STEP(thread_id, step_id)
+ *     - CLOCK_THREAD_COMPUTE_END(thread_id);
+ *     - CLOCK_ACCUMULATE;
  * - CLOCK_THREAD_END(thread_id)
  * - CLOCK_APP_JOIN;
@@ -28,9 +31,12 @@
  * - PRINT_CLOCK;
  * - CLOCK_FREE;
+ * In case of several runs, the THREAD_COMPUTE and all the THREAD_STEP resulting times
+ * are averaged over all the runs. The other times are kind of irrelevant.
+ * TODO: make a struct gathering all variables and change macros to functions
  */
 
 
 static void local_sort_asc(uint64_t tab[], int32_t size) {
-    int32_t tmp;
+    uint64_t tmp;
     int32_t i, j;
     for (i = 0; i < size; i++) {
@@ -61,4 +67,5 @@
                   int32_t step_number;                  \
                   int32_t clock_thread_num;             \
+                  int32_t clock_num_runs;               \
                   uint64_t ** thread_start_step;        \
                   uint64_t ** thread_end_step;          \
@@ -67,15 +74,18 @@
                   uint64_t global_thread_compute_start; \
                   uint64_t global_thread_compute_end;   \
+                  uint64_t accumulated_thread_compute;  \
                   uint64_t * global_thread_start_step;  \
-                  uint64_t * global_thread_end_step;
+                  uint64_t * global_thread_end_step;    \
+                  uint64_t * accumulated_thread_step;
 
 #if TARGET_OS == GIETVM
     #define CLOCK(x)  ({ x = giet_proctime(); })
 #elif TARGET_OS == LINUX
-    #define CLOCK(x)  ({                      \
+    /*#define CLOCK(x)  ({                      \
             struct timeval full_time;         \
             gettimeofday(&full_time, NULL);   \
             x = (uint64_t) ((full_time.tv_usec + full_time.tv_sec * 1000000)); \
-            })
+            }) */
+    #define CLOCK(x) ({ x = __rdtsc(); })
 #endif
 
@@ -84,8 +94,10 @@
     clock_thread_num = (x);                                                         \
     step_number = (y);                                                              \
+    clock_num_runs = 0;                                                             \
     global_thread_start = 0xFFFFFFFFFFFFFFFFLLU;                                    \
     global_thread_end = 0;                                                          \
     global_thread_compute_start = 0xFFFFFFFFFFFFFFFFLLU;                            \
     global_thread_compute_end = 0;                                                  \
+    accumulated_thread_compute = 0;                                                 \
     if ((x) > 0) {                                                                  \
         thread_start = (uint64_t *) malloc(sizeof(uint64_t) * (x));                 \
@@ -98,7 +110,9 @@
             thread_start_step = (uint64_t **) malloc(sizeof(uint64_t *) * (y));     \
             thread_end_step = (uint64_t **) malloc(sizeof(uint64_t *) * (y));       \
+            accumulated_thread_step = (uint64_t *) malloc(sizeof(uint64_t) * (y));  \
             for (int32_t j = 0; j < (y); j++) {                                     \
-                global_thread_start_step[j] = 0xFFFFFFFFFFFFFFFFLU;                 \
+                global_thread_start_step[j] = 0xFFFFFFFFFFFFFFFFLLU;                \
                 global_thread_end_step[j] = 0;                                      \
+                accumulated_thread_step[j] = 0;                                     \
                 thread_start_step[j] = (uint64_t *) malloc(sizeof(uint64_t) * (x)); \
                 thread_end_step[j] = (uint64_t *) malloc(sizeof(uint64_t) * (x));   \
@@ -120,6 +134,37 @@
 #define CLOCK_THREAD_END_STEP(x, y)   ({ CLOCK(thread_end_step[y][x]); })
 
+#define CLOCK_ACCUMULATE ({                                              \
+    for (int32_t i = 0; i < clock_thread_num; i++) {                     \
+        if (thread_compute_start[i] < global_thread_compute_start) {     \
+            global_thread_compute_start = thread_compute_start[i];       \
+        }                                                                \
+        if (thread_compute_end[i] > global_thread_compute_end) {         \
+            global_thread_compute_end = thread_compute_end[i];           \
+        }                                                                \
+        for (int32_t j = 0; j < step_number; j++) {                      \
+            if (thread_start_step[j][i] < global_thread_start_step[j]) { \
+                global_thread_start_step[j] = thread_start_step[j][i];   \
+            }                                                            \
+            if (thread_end_step[j][i] > global_thread_end_step[j]) {     \
+                global_thread_end_step[j] = thread_end_step[j][i];       \
+            }                                                            \
+        }                                                                \
+    }                                                                    \
+    for (int32_t j = 0; j < step_number; j++) {                          \
+        accumulated_thread_step[j] += (global_thread_end_step[j] - global_thread_start_step[j]); \
+        global_thread_start_step[j] = 0xFFFFFFFFFFFFFFFFLLU;             \
+        global_thread_end_step[j] = 0;                                   \
+    }                                                                    \
+    accumulated_thread_compute += (global_thread_compute_end - global_thread_compute_start); \
+    global_thread_compute_start = 0xFFFFFFFFFFFFFFFFLLU;                 \
+    global_thread_compute_end = 0;                                       \
+    clock_num_runs++;                                                    \
+})
+
 
 #define CLOCK_FINALIZE ({                                                \
+    if (clock_num_runs == 0) {                                           \
+        CLOCK_ACCUMULATE;                                                \
+    }                                                                    \
     for (int32_t i = 0; i < clock_thread_num; i++) {                     \
         if (thread_start[i] < global_thread_start) {                     \
@@ -146,47 +191,55 @@
 })
 
-#define PRINT_CLOCK ({                                                                                                         \
-    MCA_VERBOSE1(printf("Timestamps:\n"));                                                                                     \
-    MCA_VERBOSE1(printf("[APP_START]            : %llu\n", app_start));                                                        \
-    MCA_VERBOSE1(printf("[APP_CREATE]           : %llu\n", app_create));                                                       \
-    MCA_VERBOSE1(printf("[THREAD_START]         : %llu\n", global_thread_start));                                              \
-    MCA_VERBOSE1(printf("[THREAD_COMPUTE_START] : %llu\n", global_thread_compute_start));                                      \
-    for (int32_t j = 0; j < step_number; j++) {                                                                                \
-        MCA_VERBOSE1(printf("[THREAD_START_STEP_%d]  : %llu\n", j, global_thread_start_step[j]));                              \
-        MCA_VERBOSE1(printf("[THREAD_END_STEP_%d]    : %llu\n", j, global_thread_end_step[j]));                                \
-    }                                                                                                                          \
-    MCA_VERBOSE1(printf("[THREAD_COMPUTE_END]   : %llu\n", global_thread_compute_end));                                        \
-    MCA_VERBOSE1(printf("[THREAD_END]           : %llu\n", global_thread_end));                                                \
-    MCA_VERBOSE1(printf("[APP_JOIN]             : %llu\n", app_join));                                                         \
-    MCA_VERBOSE1(printf("[APP_END]              : %llu\n", app_end));                                                          \
-    MCA_VERBOSE1(printf("Durations (in cycles):\n"));                                                                          \
-    MCA_VERBOSE1(printf("[TOTAL]                : %llu\n", app_end - app_start));                                              \
-    MCA_VERBOSE1(printf("[THREAD]               : %llu\n", app_join - app_create));                                            \
-    MCA_VERBOSE1(printf("[PARALLEL]             : %llu\n", global_thread_end - global_thread_start));                          \
-    MCA_VERBOSE1(printf("[PARALLEL_COMPUTE]     : %llu\n", global_thread_compute_end - global_thread_compute_start));          \
-    for (int32_t j = 0; j < step_number; j++) {                                                                                \
-        MCA_VERBOSE1(printf("[THREAD_STEP_%d]        : %llu\n", j, global_thread_end_step[j] - global_thread_start_step[j]));  \
-    }                                                                                                                          \
-    MCA_VERBOSE1(printf("\n"));                                                                                                \
-    MCA_VERBOSE1(printf("*** All threads times output in a gnuplot data-style ***\n"));                                        \
-    local_sort_asc(thread_start, clock_thread_num);                                                                            \
-    local_sort_asc(thread_compute_start, clock_thread_num);                                                                    \
-    local_sort_asc(thread_compute_end, clock_thread_num);                                                                      \
-    local_sort_asc(thread_end, clock_thread_num);                                                                              \
-    for (int32_t j = 0; j < step_number; j++) {                                                                                \
-        local_sort_asc(thread_start_step[j], clock_thread_num);                                                                \
-        local_sort_asc(thread_end_step[j], clock_thread_num);                                                                  \
-    }                                                                                                                          \
-    MCA_VERBOSE1(printf("# cycle     thread_id\n"));                                                                           \
-    for (int32_t i = 0; i < clock_thread_num; i++) {                                                                           \
-        MCA_VERBOSE1(printf("%llu\t%d\n", thread_start[i], i));                                                                \
-        MCA_VERBOSE1(printf("%llu\t%d\n", thread_compute_start[i], i));                                                        \
-        for (int32_t j = 0; j < step_number; j++) {                                                                            \
-            MCA_VERBOSE1(printf("%llu\t%d\n", thread_start_step[j][i], i));                                                    \
-            MCA_VERBOSE1(printf("%llu\t%d\n", thread_end_step[j][i], i));                                                      \
-        }                                                                                                                      \
-        MCA_VERBOSE1(printf("%llu\t%d\n", thread_compute_end[i], i));                                                          \
-        MCA_VERBOSE1(printf("%llu\t%d\n", thread_end[i], i));                                                                  \
-    }                                                                                                                          \
+
+#define PRINT_CLOCK ({                                                                                                        \
+    MCA_VERBOSE1(printf("Timestamps:\n"));                                                                                    \
+    if (clock_num_runs > 1) {                                                                                                 \
+        MCA_VERBOSE1(printf("(THREAD_COMPUTE_START, THREAD_COMPUTE_END, THREAD_START_STEPs and THREAD_END_STEPs)\n"));        \
+        MCA_VERBOSE1(printf("(are those of the last run)\n"));                                                                \
+    }                                                                                                                         \
+    MCA_VERBOSE1(printf("[APP_START]            : %llu\n", app_start));                                                       \
+    MCA_VERBOSE1(printf("[APP_CREATE]           : %llu\n", app_create));                                                      \
+    MCA_VERBOSE1(printf("[THREAD_START]         : %llu\n", global_thread_start));                                             \
+    MCA_VERBOSE1(printf("[THREAD_COMPUTE_START] : %llu\n", global_thread_compute_start));                                     \
+    for (int32_t j = 0; j < step_number; j++) {                                                                               \
+        MCA_VERBOSE1(printf("[THREAD_START_STEP_%d]  : %llu\n", j, global_thread_start_step[j]));                             \
+        MCA_VERBOSE1(printf("[THREAD_END_STEP_%d]    : %llu\n", j, global_thread_end_step[j]));                               \
+    }                                                                                                                         \
+    MCA_VERBOSE1(printf("[THREAD_COMPUTE_END]   : %llu\n", global_thread_compute_end));                                       \
+    MCA_VERBOSE1(printf("[THREAD_END]           : %llu\n", global_thread_end));                                               \
+    MCA_VERBOSE1(printf("[APP_JOIN]             : %llu\n", app_join));                                                        \
+    MCA_VERBOSE1(printf("[APP_END]              : %llu\n", app_end));                                                         \
+    MCA_VERBOSE1(printf("Durations (in cycles):\n"));                                                                         \
+    if (clock_num_runs > 1) {                                                                                                 \
+        MCA_VERBOSE1(printf("(PARALLEL_COMPUTE and THREAD_STEPs are averaged over %d runs)\n", clock_num_runs));              \
+    }                                                                                                                         \
+    MCA_VERBOSE1(printf("[TOTAL]                : %llu\n", app_end - app_start));                                             \
+    MCA_VERBOSE1(printf("[THREAD]               : %llu\n", app_join - app_create));                                           \
+    MCA_VERBOSE1(printf("[PARALLEL]             : %llu\n", global_thread_end - global_thread_start));                         \
+    MCA_VERBOSE1(printf("[PARALLEL_COMPUTE]     : %llu\n", accumulated_thread_compute / clock_num_runs));                     \
+    for (int32_t j = 0; j < step_number; j++) {                                                                               \
+        MCA_VERBOSE1(printf("[THREAD_STEP_%d]        : %llu\n", j, accumulated_thread_step[j] / clock_num_runs));             \
+    }                                                                                                                         \
+    MCA_VERBOSE1(printf("\n"));                                                                                               \
+    MCA_VERBOSE1(printf("*** All threads times output in a gnuplot data-style ***\n"));                                       \
+    local_sort_asc(thread_start, clock_thread_num);                                                                           \
+    local_sort_asc(thread_compute_start, clock_thread_num);                                                                   \
+    local_sort_asc(thread_compute_end, clock_thread_num);                                                                     \
+    local_sort_asc(thread_end, clock_thread_num);                                                                             \
+    for (int32_t j = 0; j < step_number; j++) {                                                                               \
+        local_sort_asc(thread_start_step[j], clock_thread_num);                                                               \
+        local_sort_asc(thread_end_step[j], clock_thread_num);                                                                 \
+    }                                                                                                                         \
+    MCA_VERBOSE1(printf("# cycle     thread_id\n"));                                                                          \
+    for (int32_t i = 0; i < clock_thread_num; i++) {                                                                          \
+        MCA_VERBOSE1(printf("%llu\t%d\n", thread_start[i] - app_start, i));                                                   \
+        MCA_VERBOSE1(printf("%llu\t%d\n", thread_compute_start[i] - app_start, i));                                           \
+        for (int32_t j = 0; j < step_number; j++) {                                                                           \
+            MCA_VERBOSE1(printf("%llu\t%d\n", thread_start_step[j][i] - app_start, i));                                       \
+            MCA_VERBOSE1(printf("%llu\t%d\n", thread_end_step[j][i] - app_start, i));                                         \
+        }                                                                                                                     \
+        MCA_VERBOSE1(printf("%llu\t%d\n", thread_compute_end[i] - app_start, i));                                             \
+        MCA_VERBOSE1(printf("%llu\t%d\n", thread_end[i] - app_start, i));                                                     \
+    }                                                                                                                         \
 })
 
@@ -205,4 +258,5 @@
             free(global_thread_start_step);             \
             free(global_thread_end_step);               \
+            free(accumulated_thread_step);              \
             for (int32_t j = 0; j < step_number; j++) { \
                 free(thread_start_step[j]);             \
Index: /soft/giet_vm/applications/rosenfeld/include/config.h
===================================================================
--- /soft/giet_vm/applications/rosenfeld/include/config.h	(revision 822)
+++ /soft/giet_vm/applications/rosenfeld/include/config.h	(revision 823)
@@ -4,8 +4,8 @@
 
 #define SLOW 0
-#define FEATURES 1
+#define FEATURES 0
 #define FAST 1
 #define PYR_BARRIERS 0
-#define PARMERGE 0
+#define PARMERGE 1
 #define ARSP 0
 
@@ -21,30 +21,31 @@
 #if FAST
     #if   !FEATURES && !PARMERGE && !ARSP
-        #define vuse2_Rosenfeld(e, f,    T, D, alpha, F) vuse2_Rosenfeld_Dist(e, f,    T, D, alpha)
-        #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F) vuse3_Rosenfeld_Dist(e, f, g, T, D, alpha)
+        #define vuse2_Rosenfeld(e, f,    T, D, alpha, F)  vuse2_Rosenfeld_Dist(e, f,    T, D, alpha)
+        #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F)  vuse3_Rosenfeld_Dist(e, f, g, T, D, alpha)
     #elif !FEATURES && !PARMERGE &&  ARSP
-        #define vuse2_Rosenfeld(e, f,    T, D, alpha, F) vuse2_Arsp_Rosenfeld_Dist(e, f,    T, D, alpha)
-        #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F) vuse3_Arsp_Rosenfeld_Dist(e, f, g, T, D, alpha)
+        #define vuse2_Rosenfeld(e, f,    T, D, alpha, F)  vuse2_Arsp_Rosenfeld_Dist(e, f,    T, D, alpha)
+        #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F)  vuse3_Arsp_Rosenfeld_Dist(e, f, g, T, D, alpha)
         #error "Configuration Not implemented"
     #elif !FEATURES &&  PARMERGE && !ARSP
-        #define vuse2_Rosenfeld(e, f,    T, D, alpha, F) vuse2_Parallel_Rosenfeld_Dist(e, f,    T, D, alpha, F)
-        #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F) vuse3_Parallel_Rosenfeld_Dist(e, f, g, T, D, alpha, F)
-        #error "Configuration Not implemented"
+        #define vuse2_Rosenfeld(e, f,    T, D, alpha, F)  vuse2_Parallel_Rosenfeld_Dist(e, f,    T, D, alpha, F)
+        #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F)  vuse3_Parallel_Rosenfeld_Dist(e, f, g, T, D, alpha, F)
+        #define SetRoot_Parallel_FNF(D, rl, rd, alpha, F) SetRoot_Parallel_Rosenfeld_Dist(D, rl, rd, alpha, F)
     #elif !FEATURES &&  PARMERGE &&  ARSP
-        #define vuse2_Rosenfeld(e, f,    T, D, alpha, F) vuse2_Parallel_Arsp_Rosenfeld_Dist(e, f,    T, D, alpha, F)
-        #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F) vuse3_Parallel_Arsp_Rosenfeld_Dist(e, f, g, T, D, alpha, F)
+        #define vuse2_Rosenfeld(e, f,    T, D, alpha, F)  vuse2_Parallel_Arsp_Rosenfeld_Dist(e, f,    T, D, alpha, F)
+        #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F)  vuse3_Parallel_Arsp_Rosenfeld_Dist(e, f, g, T, D, alpha, F)
     #elif  FEATURES && !PARMERGE && !ARSP
-        #define vuse2_Rosenfeld(e, f,    T, D, alpha, F) vuse2_Features_Rosenfeld_Dist(e, f,    T, D, alpha, F)
-        #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F) vuse3_Features_Rosenfeld_Dist(e, f, g, T, D, alpha, F)
+        #define vuse2_Rosenfeld(e, f,    T, D, alpha, F)  vuse2_Features_Rosenfeld_Dist(e, f,    T, D, alpha, F)
+        #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F)  vuse3_Features_Rosenfeld_Dist(e, f, g, T, D, alpha, F)
     #elif  FEATURES && !PARMERGE &&  ARSP
-        #define vuse2_Rosenfeld(e, f,    T, D, alpha, F) vuse2_Features_Arsp_Rosenfeld_Dist(e, f,    T, D, alpha, F)
-        #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F) vuse3_Features_Arsp_Rosenfeld_Dist(e, f, g, T, D, alpha, F)
+        #define vuse2_Rosenfeld(e, f,    T, D, alpha, F)  vuse2_Features_Arsp_Rosenfeld_Dist(e, f,    T, D, alpha, F)
+        #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F)  vuse3_Features_Arsp_Rosenfeld_Dist(e, f, g, T, D, alpha, F)
         #error "Configuration Not implemented"
     #elif  FEATURES &&  PARMERGE && !ARSP
-        #define vuse2_Rosenfeld(e, f,    T, D, alpha, F) vuse2_Parallel_Features_Rosenfeld_Dist(e, f,    T, D, alpha, F)
-        #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F) vuse3_Parallel_Features_Rosenfeld_Dist(e, f, g, T, D, alpha, F)
+        #define vuse2_Rosenfeld(e, f,    T, D, alpha, F)  vuse2_Parallel_Rosenfeld_Dist(e, f,    T, D, alpha, F)
+        #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F)  vuse3_Parallel_Rosenfeld_Dist(e, f, g, T, D, alpha, F)
+        #define SetRoot_Parallel_FNF(D, rl, rd, alpha, F) SetRoot_Parallel_Features_Rosenfeld_Dist(D, rl, rd, alpha, F)
     #elif  FEATURES &&  PARMERGE && ARSP
-        #define vuse2_Rosenfeld(e, f,    T, D, alpha, F) vuse2_Parallel_Features_Arsp_Rosenfeld_Dist(e, f,    T, D, alpha, F)
-        #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F) vuse3_Parallel_Features_Arsp_Rosenfeld_Dist(e, f, g, T, D, alpha, F)
+        #define vuse2_Rosenfeld(e, f,    T, D, alpha, F)  vuse2_Parallel_Features_Arsp_Rosenfeld_Dist(e, f,    T, D, alpha, F)
+        #define vuse3_Rosenfeld(e, f, g, T, D, alpha, F)  vuse3_Parallel_Features_Arsp_Rosenfeld_Dist(e, f, g, T, D, alpha, F)
         #error "Configuration Not implemented"
     #endif
@@ -72,7 +73,7 @@
 // 2 : Standard level
 // 3 : Maximum (debug) level
-#define MCA_VERBOSE_LEVEL 2
-
-#endif // __CONFIG_H__
+#define MCA_VERBOSE_LEVEL 1
 
 
+#endif
+
Index: /soft/giet_vm/applications/rosenfeld/include/mca.h
===================================================================
--- /soft/giet_vm/applications/rosenfeld/include/mca.h	(revision 822)
+++ /soft/giet_vm/applications/rosenfeld/include/mca.h	(revision 823)
@@ -67,5 +67,6 @@
 
 typedef struct sMCA {
-    int p, np;         // numero du processeur et nb total de processeurs
+    int p, np;   // numero du processeur et nb total de processeurs
+    int nr;      // nombre de runs successifs Ã  mesurer
     
     uint8  ** X; // image source
@@ -78,10 +79,11 @@
     int j0, j1;
     
-    uint32 e0, e1; // indice pour chaque bande
-    uint32 ne;     // indice max d'etiquettes utilise par bande
+    uint32 e0, e1;  // indice pour chaque bande
+    uint32 ne;      // indice max d'etiquettes utilise par bande
+    uint32 ne_prev; // ne de l'image prÃ©cÃ©dente (pour le reset de T)
 
-    int alpha;     // puissance de 2 >= a la taille d'un bloc
-    uint32  * T;   // table d'quivalence table (Rosenfeld) ou d'indices (Warp)
-    uint32 ** D;   // distributed table (instanciee dans chaque worker)
+    int alpha;      // puissance de 2 >= a la taille d'un bloc
+    uint32  * T;    // table d'quivalence table (Rosenfeld) ou d'indices (Warp)
+    uint32 ** D;    // distributed table (instanciee dans chaque worker)
     
     RegionStats * stats;
@@ -106,4 +108,5 @@
 void MCA_Set_Size(MCA * mca, int width, int height);
 void MCA_Set_NP(MCA * mca, int np);
+void MCA_Set_NR(MCA * mca, int nr);
 
 uint32 MCA_CalcMaxLabels(int connection, uint32 height, uint32 width);
Index: /soft/giet_vm/applications/rosenfeld/nrc2/Makefile
===================================================================
--- /soft/giet_vm/applications/rosenfeld/nrc2/Makefile	(revision 822)
+++ /soft/giet_vm/applications/rosenfeld/nrc2/Makefile	(revision 823)
@@ -8,5 +8,5 @@
 # -- File list ----------
 FILE = nralloc1.c, nralloc2.c, nralloc2x.c, nrarith0.c, nrarith1.c, nrarith2.c, nrarith2x.c, nrbool1.c, nrbool2.c, nrio0.c, nrio1.c, nrio1x.c, nrio2.c, nrlinalg.c, nrlut.c, nrmem1.c, nrmem1x.c, nrmem2.c, nrmem2x.c, nrset1.c, nrset2.c, nrset2x.c, nrsort1.c, nrsort2.c, nrwrap1.c, nrwrap2.c
-FILE := $(FILE), nrio1f.c, nrio1xf.c, nrio2f.c # comment if giet
+FILE := $(FILE), nrio1f.c, nrio1xf.c, nrio2f.c nrio2x.c nrio2xf.c nrio3.c # comment if giet
 
 
Index: /soft/giet_vm/applications/rosenfeld/nrc2/include/nrio2x.h
===================================================================
--- /soft/giet_vm/applications/rosenfeld/nrc2/include/nrio2x.h	(revision 822)
+++ /soft/giet_vm/applications/rosenfeld/nrc2/include/nrio2x.h	(revision 823)
@@ -11,66 +11,29 @@
 #define __NRIO2X_H__
 
-#ifdef __cplusplus
-#pragma message ("C++")
-extern "C" {
-#endif
-    
-#ifdef VERBOSE_PRAGMA
-//#pragma message ("- *** include nrio2x.h ***")
-#endif
 
-IMAGE_EXPORT(void) display_matrix_endline    (byte   **m, long i0, long i1, long j0, long j1, char *format, char *name);
-IMAGE_EXPORT(void) display_i16matrix_endline (int16  **m, long i0, long i1, long j0, long j1, char *format, char *name);
-IMAGE_EXPORT(void) display_ui16matrix_endline(uint16 **m, long i0, long i1, long j0, long j1, char *format, char *name);
-IMAGE_EXPORT(void) display_i32matrix_endline (int32  **m, long i0, long i1, long j0, long j1, char *format, char *name);
-IMAGE_EXPORT(void) display_ui32matrix_endline(uint32 **m, long i0, long i1, long j0, long j1, char *format, char *name);
-IMAGE_EXPORT(void) display_i64matrix_endline (int64  **m, long i0, long i1, long j0, long j1, char *format, char *name);
-IMAGE_EXPORT(void) display_imatrix_endline   (int    **m, long i0, long i1, long j0, long j1, char *format, char *name);
+/* ------------------------------ */
+/* --- display_matrix_endline --- */
+/* --- display_matrix_endline0 --- */
+/* --- display_matrix_endline1 --- */
+/* --- display_matrix_number_endline0 --- */
+/* --- display_matrix_number_endline1 --- */
+/* ------------------------------ */
 
-/* ------------------------------- */
-/* --- display_matrix_endline0 --- */
+#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); \
+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); \
+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); \
+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); \
+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);
 
-IMAGE_EXPORT(void) display_bmatrix_endline0   (byte   **m, long i0, long i1, char *format, char *name);
-IMAGE_EXPORT(void) display_i16matrix_endline0 (int16  **m, long i0, long i1, char *format, char *name);
-IMAGE_EXPORT(void) display_ui16matrix_endline0(uint16 **m, long i0, long i1, char *format, char *name);
-IMAGE_EXPORT(void) display_i32matrix_endline0 (int32  **m, long i0, long i1, char *format, char *name);
-IMAGE_EXPORT(void) display_ui32matrix_endline0(uint32 **m, long i0, long i1, char *format, char *name);
-IMAGE_EXPORT(void) display_i64matrix_endline0 (int64  **m, long i0, long i1, char *format, char *name);
-IMAGE_EXPORT(void) display_imatrix_endline0   (int    **m, long i0, long i1, char *format, char *name);
+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_endline1 --- */
-/* ------------------------------- */
-IMAGE_EXPORT(void) display_bmatrix_endline1   (byte   **m,long i0, long i1, long j0, long j1, char *format, char *name);
-IMAGE_EXPORT(void) display_i16matrix_endline1 (int16  **m,long i0, long i1, long j0, long j1, char *format, char *name);
-IMAGE_EXPORT(void) display_ui16matrix_endline1(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *name);
-IMAGE_EXPORT(void) display_i32matrix_endline1 (int32  **m,long i0, long i1, long j0, long j1, char *format, char *name);
-IMAGE_EXPORT(void) display_ui32matrix_endline1(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *name);
-IMAGE_EXPORT(void) display_i64matrix_endline1 (int64  **m,long i0, long i1, long j0, long j1, char *format, char *name);
-IMAGE_EXPORT(void) display_imatrix_endline1   (int    **m,long i0, long i1, long j0, long j1, char *format, char *name);
-
-/* -------------------------------------- */
-/* --- 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);
-IMAGE_EXPORT(void) display_i16matrix_number_endline0 (int16  **m,long i0, long i1, long j0, long j1, char *format, char *name);
-IMAGE_EXPORT(void) display_ui16matrix_number_endline0(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *name);
-IMAGE_EXPORT(void) display_i32matrix_number_endline0 (int32  **m,long i0, long i1, long j0, long j1, char *format, char *name);
-IMAGE_EXPORT(void) display_ui32matrix_number_endline0(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *name);
-IMAGE_EXPORT(void) display_i64matrix_number_endline0 (int64  **m,long i0, long i1, long j0, long j1, char *format, char *name);
-IMAGE_EXPORT(void) display_imatrix_number_endline0   (int    **m,long i0, long i1, long j0, long j1, char *format, char *name);
-
-/* -------------------------------------- */
-/* --- 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);
-IMAGE_EXPORT(void) display_i16matrix_number_endline1 (int16  **m,long i0, long i1, long j0, long j1, char *format, char *name);
-IMAGE_EXPORT(void) display_ui16matrix_number_endline1(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *name);
-IMAGE_EXPORT(void) display_i32matrix_number_endline1 (int32  **m,long i0, long i1, long j0, long j1, char *format, char *name);
-IMAGE_EXPORT(void) display_ui32matrix_number_endline1(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *name);
-IMAGE_EXPORT(void) display_i64matrix_number_endline1 (int64  **m,long i0, long i1, long j0, long j1, char *format, char *name);
-IMAGE_EXPORT(void) display_imatrix_number_endline1   (int    **m,long i0, long i1, long j0, long j1, char *format, char *name);
 
 /* ------------------------- */
@@ -78,110 +41,65 @@
 /* ------------------------- */
 
-IMAGE_EXPORT(void) display_btrimatrix   (byte    **m, long i0, long i1, long j0, long j1, long step, char *format, char *name);
-IMAGE_EXPORT(void) display_i16trimatrix (int16   **m, long i0, long i1, long j0, long j1, long step, char *format, char *name);
-IMAGE_EXPORT(void) display_ui16trimatrix(uint16  **m, long i0, long i1, long j0, long j1, long step, char *format, char *name);
-IMAGE_EXPORT(void) display_itrimatrix   (int     **m, long i0, long i1, long j0, long j1, long step, char *format, char *name);
-IMAGE_EXPORT(void) display_i32trimatrix (int32   **m, long i0, long i1, long j0, long j1, long step, char *format, char *name);
-IMAGE_EXPORT(void) display_f32trimatrix (float32 **m, long i0, long i1, long j0, long j1, long step, char *format, char *name);
-IMAGE_EXPORT(void) display_f64trimatrix (float64 **m, long i0, long i1, long j0, long j1, long step, char *format, char *name);
+#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);
+
+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);
+
+
+
 
 /* ----------------------- */
 /* --- write_trimatrix --- */
+/* --- write_matrix_endline --- */
+/* --- write_imatrix_endline0 --- */
+/* --- write_imatrix_endline1 --- */
+/* --- write_imatrix_number_endline0 --- */
+/* --- write_imatrix_number_endline1 --- */
+/* -- fwrite_trimatrix -- */
+/* -- fread_trimatrix -- */
 /* ----------------------- */
 
-IMAGE_EXPORT(void) write_btrimatrix   (byte    **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename);
-IMAGE_EXPORT(void) write_i16trimatrix (int16   **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui16trimatrix(uint16  **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename);
-IMAGE_EXPORT(void) write_itrimatrix   (int     **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename);
-IMAGE_EXPORT(void) write_i32trimatrix (int32   **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename);
-IMAGE_EXPORT(void) write_f32trimatrix (float32 **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename);
-IMAGE_EXPORT(void) write_f64trimatrix (float64 **m,long i0,long i1,long j0, long j1, long step, char *format, char *filename);
+#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); \
+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); \
+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); \
+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); \
+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); \
+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); \
+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); \
+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);
 
-/* ---------------------------- */
-/* --- write_matrix_endline --- */
-/* ---------------------------- */
+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);
 
-IMAGE_EXPORT(void) write_bmatrix_endline   (byte   **m,long i0, long i1, long j0, long j1, char *format, char *filename);
-IMAGE_EXPORT(void) write_i16matrix_endline (int16  **m,long i0, long i1, long j0, long j1, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui16matrix_endline(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *filename);
-IMAGE_EXPORT(void) write_i32matrix_endline (int32  **m,long i0, long i1, long j0, long j1, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui32matrix_endline(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *filename);
-IMAGE_EXPORT(void) write_i64matrix_endline (int64  **m,long i0, long i1, long j0, long j1, char *format, char *filename);
-IMAGE_EXPORT(void) write_imatrix_endline   (int    **m,long i0, long i1, long j0, long j1, char *format, char *filename);
 
-/* ------------------------------ */
-/* --- write_imatrix_endline0 --- */
-/* ------------------------------ */
-
-IMAGE_EXPORT(void) write_bmatrix_endline0   (byte   **m,long i0, long i1, long j0, long j1, char *format, char *filename);
-IMAGE_EXPORT(void) write_i16matrix_endline0 (int16  **m,long i0, long i1, long j0, long j1, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui16matrix_endline0(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *filename);
-IMAGE_EXPORT(void) write_i32matrix_endline0 (int32  **m,long i0, long i1, long j0, long j1, char *format, char *filename);
-IMAGE_EXPORT(void) write_i64matrix_endline0 (int64  **m,long i0, long i1, long j0, long j1, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui32matrix_endline0(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *filename);
-IMAGE_EXPORT(void) write_imatrix_endline0   (int    **m,long i0, long i1, long j0, long j1, char *format, char *filename);
-
-/* ------------------------------ */
-/* --- write_imatrix_endline1 --- */
-/* ------------------------------ */
-
-IMAGE_EXPORT(void) write_bmatrix_endline1   (byte   **m,long i0, long i1, long j0, long j1, char *format, char *filename);
-IMAGE_EXPORT(void) write_i16matrix_endline1 (int16  **m,long i0, long i1, long j0, long j1, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui16matrix_endline1(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *filename);
-IMAGE_EXPORT(void) write_i32matrix_endline1 (int32  **m,long i0, long i1, long j0, long j1, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui32matrix_endline1(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *filename);
-IMAGE_EXPORT(void) write_i64matrix_endline1 (int64  **m,long i0, long i1, long j0, long j1, char *format, char *filename);
-IMAGE_EXPORT(void) write_imatrix_endline1   (int    **m,long i0, long i1, long j0, long j1, char *format, char *filename);
-
-/* ------------------------------------- */
-/* --- 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);
-IMAGE_EXPORT(void) write_i16matrix_number_endline0 (int16  **m, long i0, long i1, long j0, long j1, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui16matrix_number_endline0(uint16 **m, long i0, long i1, long j0, long j1, char *format, char *filename);
-IMAGE_EXPORT(void) write_i32matrix_number_endline0 (int32  **m, long i0, long i1, long j0, long j1, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui32matrix_number_endline0(uint32 **m, long i0, long i1, long j0, long j1, char *format, char *filename);
-IMAGE_EXPORT(void) write_i64matrix_number_endline0 (int64  **m, long i0, long i1, long j0, long j1, char *format, char *filename);
-IMAGE_EXPORT(void) write_imatrix_number_endline0   (int    **m, long i0, long i1, long j0, long j1, char *format, char *filename);
-
-/* ------------------------------------- */
-/* --- 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);
-IMAGE_EXPORT(void) write_i16matrix_number_endline1 (int16  **m,long i0, long i1, long j0, long j1, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui16matrix_number_endline1(uint16 **m,long i0, long i1, long j0, long j1, char *format, char *filename);
-IMAGE_EXPORT(void) write_i32matrix_number_endline1 (int32  **m,long i0, long i1, long j0, long j1, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui32matrix_number_endline1(uint32 **m,long i0, long i1, long j0, long j1, char *format, char *filename);
-IMAGE_EXPORT(void) write_i64matrix_number_endline1 (int64  **m,long i0, long i1, long j0, long j1, char *format, char *filename);
-IMAGE_EXPORT(void) write_imatrix_number_endline1   (int    **m,long i0, long i1, long j0, long j1, char *format, char *filename);
-
-/* ---------------------- */
-/* -- fwrite_trimatrix -- */
-/* ---------------------- */
-
-IMAGE_EXPORT(void) fwrite_btrimatrix   (byte    **m,long i0,long i1,long j0, long j1, long step, char *filename);
-IMAGE_EXPORT(void) fwrite_i16trimatrix (int16   **m,long i0,long i1,long j0, long j1, long step, char *filename);
-IMAGE_EXPORT(void) fwrite_ui16trimatrix(uint16  **m,long i0,long i1,long j0, long j1, long step, char *filename);
-IMAGE_EXPORT(void) fwrite_i32trimatrix (int32   **m,long i0,long i1,long j0, long j1, long step, char *filename);
-IMAGE_EXPORT(void) fwrite_f32trimatrix (float32 **m,long i0,long i1,long j0, long j1, long step, char *filename);
-IMAGE_EXPORT(void) fwrite_f64trimatrix (float64 **m,long i0,long i1,long j0, long j1, long step, char *filename);
-
-/* --------------------- */
-/* -- fread_trimatrix -- */
-/* --------------------- */
-
-IMAGE_EXPORT(void) fread_btrimatrix   (char *filename, byte    **m,long i0,long i1,long j0, long j1, long step);
-IMAGE_EXPORT(void) fread_i16trimatrix (char *filename, int16   **m,long i0,long i1,long j0, long j1, long step);
-IMAGE_EXPORT(void) fread_ui16trimatrix(char *filename, uint16  **m,long i0,long i1,long j0, long j1, long step);
-IMAGE_EXPORT(void) fread_itrimatrix   (char *filename, int     **m,long i0,long i1,long j0, long j1, long step);
-IMAGE_EXPORT(void) fread_i32trimatrix (char *filename, int32   **m,long i0,long i1,long j0, long j1, long step);
-IMAGE_EXPORT(void) fread_f32trimatrix (char *filename, float32 **m,long i0,long i1,long j0, long j1, long step);
-IMAGE_EXPORT(void) fread_f64trimatrix (char *filename, float64 **m,long i0,long i1,long j0, long j1, long step);
-
-#ifdef __cplusplus
-}
-#endif
 
 #endif /* __NRIO2X_H__ */
+
+
+// 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/include/nrio3.h
===================================================================
--- /soft/giet_vm/applications/rosenfeld/nrc2/include/nrio3.h	(revision 822)
+++ /soft/giet_vm/applications/rosenfeld/nrc2/include/nrio3.h	(revision 823)
@@ -7,41 +7,32 @@
  * Univ Paris Sud XI, CNRS
 */
+
+#ifndef _NR_IO3_H_
+#define _NR_IO3_H_
+
 /* -------------------- */
 /* --- display_cube --- */
+/* -- write_cube -- */
+/* -- fread_cube -- */
+/* -- fwrite_cube -- */
 /* -------------------- */
-IMAGE_EXPORT(void) display_i8cube  (int8    ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_i16cube (int16   ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_ui16cube(uint16  ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_i32cube (int32   ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_ui32cube(uint32  ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_i64cube (int64   ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_f32cube (float32 ***c,long ndl, long ndh, long nrl,long nrh,long ncl, long nch, char *format, char *name);
 
-/* ---------------- */
-/* -- 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);
-IMAGE_EXPORT(void) write_i16cube (int16   ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui16cube(uint16  ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_i32cube (int32   ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui32cube(uint32  ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_i64cube (int64   ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_f32cube (float32 ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch, char *format, char *filename);
+#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); \
+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); \
+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); \
+void short_name(t,fwrite_,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);
 
-IMAGE_EXPORT(void) fread_i8cube(char   *filename, int8    ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(void) fread_i16cube(char  *filename, int16   ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(void) fread_ui16cube(char *filename, uint16  ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch);
-IMAGE_EXPORT(void) fread_i32cube(char  *filename, int32   ***c, long ndl, long ndh, long nrl, long nrh, long ncl, long nch);
-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);
+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);
 
-/* ----------------- */
-/* -- 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);
+#endif
+
Index: /soft/giet_vm/applications/rosenfeld/nrc2/include/nrlinalg.h
===================================================================
--- /soft/giet_vm/applications/rosenfeld/nrc2/include/nrlinalg.h	(revision 822)
+++ /soft/giet_vm/applications/rosenfeld/nrc2/include/nrlinalg.h	(revision 823)
@@ -11,28 +11,22 @@
 #define __NRLINALG_H__
 
-#ifdef __cplusplus
-extern "C" {
-#endif
+#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); \
+void short_name(t,transpose1_,matrix)(t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch);
 
-IMAGE_EXPORT(void) transpose_bmatrix(byte **S, long nrl,long nrh,long ncl, long nch, byte **D);
-IMAGE_EXPORT(void) transpose_si16matrix(sint16 **S, long nrl,long nrh,long ncl, long nch, sint16 **D);
-IMAGE_EXPORT(void) transpose_ui16matrix(uint16 **S, long nrl,long nrh,long ncl, long nch, uint16 **D);
-IMAGE_EXPORT(void) transpose_si32matrix(sint32 **S, long nrl,long nrh,long ncl, long nch, sint32 **D);
-IMAGE_EXPORT(void) transpose_ui32matrix(uint32 **S, long nrl,long nrh,long ncl, long nch, uint32 **D);
-IMAGE_EXPORT(void) transpose_f32matrix(float32 **S, long nrl,long nrh,long ncl, long nch, float32 **D);
-IMAGE_EXPORT(void) transpose_dmatrix(float64 **S, long nrl,long nrh,long ncl, long nch, float64 **D);
-IMAGE_EXPORT(void) transpose_rgb8matrix(rgb8 **S, long nrl,long nrh,long ncl, long nch, rgb8 **D);
-IMAGE_EXPORT(void) transpose1_bmatrix(byte **S, long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(void) transpose1_si16matrix(sint16 **S, long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(void) transpose1_ui16matrix(uint16 **S, long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(void) transpose1_si32matrix(sint32 **S, long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(void) transpose1_ui32matrix(uint32 **S, long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(void) transpose1_f32matrix(float32 **S, long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(void) transpose1_f64matrix(float64 **S, long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(void) transpose1_rgb8matrix(rgb8 **S, long nrl,long nrh,long ncl, long nch);
+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);
 
-#ifdef __cplusplus
-}
-#endif
 
 #endif // __NRLINALG_H__
+
Index: /soft/giet_vm/applications/rosenfeld/nrc2/include/nrlut.h
===================================================================
--- /soft/giet_vm/applications/rosenfeld/nrc2/include/nrlut.h	(revision 822)
+++ /soft/giet_vm/applications/rosenfeld/nrc2/include/nrlut.h	(revision 823)
@@ -5,50 +5,41 @@
 /*
  * Copyright (c) 2000-2014, Lionel Lacassagne, All rights reserved
-* Univ Paris Sud XI, CNRS
-*/
+ * Univ Paris Sud XI, CNRS
+ */
 
 #ifndef _NRLUT_H_
 #define _NRLUT_H_
 
-#ifdef __cplusplus
-#ifdef PRAGMA_VERBOSE
-#pragma message ("C++")
-#endif
-extern "C" {
-#endif
+#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); \
+void short_name(t,lut_,matrix)(t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t * L, t ** D);
 
-#ifdef PRAGMA_VERBOSE
-#pragma message("- include nrlut.h")
-#endif
+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);
+init_type_lut(rgb8);
 
 
-IMAGE_EXPORT(void) init_blut   (byte   *v, int nl, int nh, int n0, int n1, byte   k);
-IMAGE_EXPORT(void) init_i8lut  (int8   *v, int nl, int nh, int n0, int n1, int8   k);
-IMAGE_EXPORT(void) init_i16lut (int16  *v, int nl, int nh, int n0, int n1, int16  k);
-IMAGE_EXPORT(void) init_i32lut (int32  *v, int nl, int nh, int n0, int n1, int32  k);
-IMAGE_EXPORT(void) init_ui16lut(uint16 *v, int nl, int nh, int n0, int n1, uint16 k);
-IMAGE_EXPORT(void) init_rgb8lut(rgb8   *v, int nl, int nh, int n0, int n1, rgb8   k);
+void lut_si16matrix_si8matrix(int16_t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int8_t * L, int8_t ** D);
+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);
+void lut_si32matrix_si16matrix(int32_t ** S, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int16_t * L, int16_t ** D);
+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);
 
-IMAGE_EXPORT(void) lut_bmatrix   (byte    **S, long nrl, long nrh, long ncl, long nch, byte    *L, byte    **D);
-IMAGE_EXPORT(void) lut_ui8matrix (uint8   **S, long nrl, long nrh, long ncl, long nch, uint8   *L, uint8   **D);
-IMAGE_EXPORT(void) lut_si8matrix (sint8   **S, long nrl, long nrh, long ncl, long nch, sint8   *L, sint8   **D);
-IMAGE_EXPORT(void) lut_ui16matrix(uint16  **S, long nrl, long nrh, long ncl, long nch, uint16  *L, uint16  **D);
-IMAGE_EXPORT(void) lut_si16matrix(sint16  **S, long nrl, long nrh, long ncl, long nch, sint16  *L, sint16  **D);
-IMAGE_EXPORT(void) lut_ui32matrix(uint32  **S, long nrl, long nrh, long ncl, long nch, uint32  *L, uint32  **D);
-IMAGE_EXPORT(void) lut_si32matrix(sint32  **S, long nrl, long nrh, long ncl, long nch, sint32  *L, sint32  **D);
-IMAGE_EXPORT(void) lut_rgb8matrix(rgb8    **S, long nrl, long nrh, long ncl, long nch, rgb8    *L, rgb8    **D);
 
-IMAGE_EXPORT(void) lut_si16matrix_si8matrix(sint16 **S, long nrl, long nrh, long ncl, long nch, sint8 *L, sint8 **D);
-IMAGE_EXPORT(void) lut_ui16matrix_ui8matrix(uint16 **S, long nrl, long nrh, long ncl, long nch, uint8 *L, uint8 **D);
-IMAGE_EXPORT(void) lut_si32matrix_si16matrix(sint32 **S, long nrl, long nrh, long ncl, long nch, sint16 *L, sint16 **D);
-IMAGE_EXPORT(void) lut_ui32matrix_ui16matrix(uint32 **S, long nrl, long nrh, long ncl, long nch, uint16 *L, uint16 **D);
-    
-IMAGE_EXPORT(void) histogram_bmatrix   (byte   **S, long nrl, long nrh, long ncl, long nch, int32 *H);
-IMAGE_EXPORT(void) histogram_ui16matrix(uint16 **S, long nrl, long nrh, long ncl, long nch, int32 *H);
-IMAGE_EXPORT(void) histogram_rgb8matrix(rgb8   **S, long nrl, long nrh, long ncl, long nch, rgb32 *H);
+#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);
 
-#ifdef __cplusplus
-}
-#endif
+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);
+
 
 #endif /* _NRLUT_H_ */
+
Index: /soft/giet_vm/applications/rosenfeld/nrc2/include/nrmem1.h
===================================================================
--- /soft/giet_vm/applications/rosenfeld/nrc2/include/nrmem1.h	(revision 822)
+++ /soft/giet_vm/applications/rosenfeld/nrc2/include/nrmem1.h	(revision 823)
@@ -12,90 +12,82 @@
 #define __NRMEM1_H__
 
-#ifdef __cplusplus
-#pragma message ("C++")
-extern "C" {
-#endif
-    
-#ifdef VERBOSE_PRAGMA
-//#pragma message ("- *** include nrmem1.h ***")
-#endif
+
+#define dup_type_vector(t) \
+void short_name(t,dup_,vector)(t * X, int32_t nl, int32_t nh, t * Y);
+
+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);
+
+/* --------------------- */
+/* --- split & merge --- */
+/* --------------------- */
+
+void split_rgb8vector(rgb8 * X, int32_t nl, int32_t nh,  uint8_t * R,  uint8_t * G,  uint8_t * B);
+void split_rgb32vector(rgb32 * X, int32_t nl, int32_t nh, uint32_t * R, uint32_t * G, uint32_t * B);
+
+void merge_rgb8vector(uint8_t * R, uint8_t * G, uint8_t * B, int32_t nl, int32_t nh, rgb8 * X);
+void merge_rgb32vector(uint32_t * R, uint32_t * G, uint32_t * B, int32_t nl, int32_t nh, rgb32 * X);
 
 
-IMAGE_EXPORT(void) dup_si8vector   (sint8   *X, long nl, long nh, sint8   *Y);
-IMAGE_EXPORT(void) dup_ui8vector   (uint8   *X, long nl, long nh, uint8   *Y);
-IMAGE_EXPORT(void) dup_si16vector  (sint16  *X, long nl, long nh, sint16  *Y);
-IMAGE_EXPORT(void) dup_ui16vector  (uint16  *X, long nl, long nh, uint16  *Y);
-IMAGE_EXPORT(void) dup_si32vector  (sint32  *X, long nl, long nh, sint32  *Y);
-IMAGE_EXPORT(void) dup_ui32vector  (uint32  *X, long nl, long nh, uint32  *Y);
-IMAGE_EXPORT(void) dup_si64vector  (sint64  *X, long nl, long nh, sint64  *Y);
-IMAGE_EXPORT(void) dup_ui64vector  (uint64  *X, long nl, long nh, uint64  *Y);
-IMAGE_EXPORT(void) dup_f32vector   (float32 *X, long nl, long nh, float32 *Y);
-IMAGE_EXPORT(void) dup_f64vector   (float64 *X, long nl, long nh, float64 *Y);
-IMAGE_EXPORT(void) dup_rgb8vector  (rgb8    *X, long nl, long nh, rgb8    *Y);
-IMAGE_EXPORT(void) dup_rgbx8vector (rgbx8   *X, long nl, long nh, rgbx8   *Y);
 
 /* ---------------- */
-/* -- Convertion -- */
+/* -- Conversion -- */
 /* ---------------- */
 
-// UP
+#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);
 
-IMAGE_EXPORT(void) convert_si8vector_si16vector (sint8 *X, long nl, long nh, sint16  *Y);
-IMAGE_EXPORT(void) convert_si8vector_si32vector (sint8 *X, long nl, long nh, sint32  *Y);
-IMAGE_EXPORT(void) convert_si8vector_f32vector  (sint8 *X, long nl, long nh, float32 *Y);
-IMAGE_EXPORT(void) convert_si8vector_f64vector  (sint8 *X, long nl, long nh, float64 *Y);
+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);
+convert_type1_vector_type2_vector(uint8_t,rgb8);
+convert_type1_vector_type2_vector(uint8_t,rgbx8);
+convert_type1_vector_type2_vector(rgb8,uint8_t);
+convert_type1_vector_type2_vector(rgbx8,uint8_t);
 
-IMAGE_EXPORT(void) convert_ui8vector_ui16vector (uint8 *X, long nl, long nh, uint16  *Y);
-IMAGE_EXPORT(void) convert_ui8vector_ui32vector (uint8 *X, long nl, long nh, uint32  *Y);
-IMAGE_EXPORT(void) convert_ui8vector_f32vector  (uint8 *X, long nl, long nh, float32 *Y);
-IMAGE_EXPORT(void) convert_ui8vector_f64vector  (uint8 *X, long nl, long nh, float64 *Y);
-IMAGE_EXPORT(void) convert_ui8vector_rgb8vector (uint8 *X, long nl, long nh, rgb8    *Y);
-IMAGE_EXPORT(void) convert_ui8vector_rgbx8vector(uint8 *X, long nl, long nh, rgbx8   *Y);
-
-IMAGE_EXPORT(void) convert_si16vector_si32vector (sint16 *X, long nl, long nh, sint32  *Y);
-IMAGE_EXPORT(void) convert_si16vector_f32vector  (sint16 *X, long nl, long nh, float32 *Y);
-IMAGE_EXPORT(void) convert_si16vector_f64vector  (sint16 *X, long nl, long nh, float64 *Y);
-
-IMAGE_EXPORT(void) convert_ui16vector_ui32vector (uint16 *X, long nl, long nh, uint32  *Y);
-IMAGE_EXPORT(void) convert_ui16vector_f32vector  (uint16 *X, long nl, long nh, float32 *Y);
-IMAGE_EXPORT(void) convert_ui16vector_f64vector  (uint16 *X, long nl, long nh, float64 *Y);
-
-IMAGE_EXPORT(void) convert_si32vector_f32vector (sint32 *X, long nl, long nh, float32 *Y);
-IMAGE_EXPORT(void) convert_si32vector_f64vector (sint32 *X, long nl, long nh, float64 *Y);
-
-IMAGE_EXPORT(void) convert_ui32vector_f32vector (uint32 *X, long nl, long nh, float32 *Y);
-IMAGE_EXPORT(void) convert_ui32vector_f64vector (uint32 *X, long nl, long nh, float64 *Y);
-
-IMAGE_EXPORT(void) convert_f32vector_f64vector (float32 *X, long nl, long nh, float64 *Y);
-
-// DOWN
-
-IMAGE_EXPORT(void) convert_si16vector_si8vector(sint16 *X, long nl, long nh, sint8 *Y);
-
-IMAGE_EXPORT(void) convert_ui16vector_ui8vector(uint16 *X, long nl, long nh, uint8 *Y);
-
-IMAGE_EXPORT(void) convert_si32vector_si8vector (sint32 *X, long nl, long nh, sint8  *Y);
-IMAGE_EXPORT(void) convert_si32vector_si16vector(sint32 *X, long nl, long nh, sint16 *Y);
-
-IMAGE_EXPORT(void) convert_ui32vector_ui8vector (uint32 *X, long nl, long nh, uint8  *Y);
-IMAGE_EXPORT(void) convert_ui32vector_ui16vector(uint32 *X, long nl, long nh, uint16 *Y);
-
-IMAGE_EXPORT(void) convert_f32vector_si8vector (float32 *X, long nl, long nh, sint8  *Y);
-IMAGE_EXPORT(void) convert_f32vector_ui8vector (float32 *X, long nl, long nh, uint8  *Y);
-IMAGE_EXPORT(void) convert_f32vector_si16vector(float32 *X, long nl, long nh, sint16 *Y);
-IMAGE_EXPORT(void) convert_f32vector_ui16vector(float32 *X, long nl, long nh, uint16 *Y);
-IMAGE_EXPORT(void) convert_f32vector_si32vector(float32 *X, long nl, long nh, sint32 *Y);
-IMAGE_EXPORT(void) convert_f32vector_ui32vector(float32 *X, long nl, long nh, uint32 *Y);
-
-IMAGE_EXPORT(void) convert_f64vector_si8vector (float64 *X, long nl, long nh, sint8   *Y);
-IMAGE_EXPORT(void) convert_f64vector_ui8vector (float64 *X, long nl, long nh, uint8   *Y);
-IMAGE_EXPORT(void) convert_f64vector_si16vector(float64 *X, long nl, long nh, sint16  *Y);
-IMAGE_EXPORT(void) convert_f64vector_ui16vector(float64 *X, long nl, long nh, uint16  *Y);
-IMAGE_EXPORT(void) convert_f64vector_si32vector(float64 *X, long nl, long nh, sint32  *Y);
-IMAGE_EXPORT(void) convert_f64vector_ui32vector(float64 *X, long nl, long nh, uint32  *Y);
-IMAGE_EXPORT(void) convert_f64vector_f32vector (float64 *X, long nl, long nh, float32 *Y);
-
-IMAGE_EXPORT(void) convert_rgb8vector_ui8vector (rgb8  *X, long nl, long nh, uint8 *Y);
-IMAGE_EXPORT(void) convert_rgbx8vector_ui8vector(rgbx8 *X, long nl, long nh, uint8 *Y);
 
 /*
@@ -105,20 +97,7 @@
  */
 
-IMAGE_EXPORT(void) lowpart_ui16vector_ui8vector(uint16 *X, long nl,long nh, uint8 *Y);
-IMAGE_EXPORT(void) lowpart_ui32vector_ui8vector(uint32 *X, long nl,long nh, uint8 *Y);
-
-/* --------------------- */
-/* --- split & merge --- */
-/* --------------------- */
-
-IMAGE_EXPORT(void) split_rgb8vector(rgb8   *X, long nl, long nh,  uint8 *R,  uint8 *G,  uint8 *B);
-IMAGE_EXPORT(void) split_rgb32vector(rgb32 *X, long nl, long nh, uint32 *R, uint32 *G, uint32 *B);
-
-IMAGE_EXPORT(void) merge_rgb8vector(uint8   *R, uint8  *G, uint8  *B, long nl, long nh, rgb8  *X);
-IMAGE_EXPORT(void) merge_rgb32vector(uint32 *R, uint32 *G, uint32 *B, long nl, long nh, rgb32 *X);
-
-#ifdef __cplusplus
-}
-#endif
+void lowpart_ui16vector_ui8vector(uint16_t * X, int32_t nl, int32_t nh, uint8_t * Y);
+void lowpart_ui32vector_ui8vector(uint32_t * X, int32_t nl, int32_t nh, uint8_t * Y);
 
 #endif /* __NRMEM1_H__ */
+
Index: /soft/giet_vm/applications/rosenfeld/nrc2/include/nrtype.h
===================================================================
--- /soft/giet_vm/applications/rosenfeld/nrc2/include/nrtype.h	(revision 822)
+++ /soft/giet_vm/applications/rosenfeld/nrc2/include/nrtype.h	(revision 823)
@@ -24,8 +24,8 @@
 // Short names
 
-#define sn_int8_t(p,s)      p##i8##s
-#define sn_int16_t(p,s)     p##i16##s
-#define sn_int32_t(p,s)     p##i32##s
-#define sn_int64_t(p,s)     p##i64##s
+#define sn_int8_t(p,s)      p##si8##s
+#define sn_int16_t(p,s)     p##si16##s
+#define sn_int32_t(p,s)     p##si32##s
+#define sn_int64_t(p,s)     p##si64##s
 #define sn_uint8_t(p,s)     p##ui8##s
 #define sn_uint16_t(p,s)    p##ui16##s
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;
+    }
+}
+
+
Index: /soft/giet_vm/applications/rosenfeld/scripts/create_graph.py
===================================================================
--- /soft/giet_vm/applications/rosenfeld/scripts/create_graph.py	(revision 822)
+++ /soft/giet_vm/applications/rosenfeld/scripts/create_graph.py	(revision 823)
@@ -16,4 +16,5 @@
 import filecmp
 import random
+import math
 
 from stack import Stack
@@ -23,10 +24,9 @@
 
 use_rand_images = True
-with_features = True
+with_features = False
 
-threads = [1, 2, 4]
-nb_step = 0
+threads = [1, 2, 4, 8, 16, 32, 64]
 use_dsk = True
-img_size = 1024
+img_size = 2048
 granularity = 1
 rand_seed = 7
@@ -42,10 +42,8 @@
 # Each of these configuration must have been run with both features activated and deactivated
 configs = [
-        {'SLOW':'1', 'FAST':'0', 'PARMERGE':'0', 'ARSP':'0'},
-        {'SLOW':'0', 'FAST':'1', 'PARMERGE':'0', 'ARSP':'0'},
         #{'SLOW':'1', 'FAST':'0', 'PARMERGE':'0', 'ARSP':'0'},
         #{'SLOW':'0', 'FAST':'1', 'PARMERGE':'0', 'ARSP':'0'},
         #{'SLOW':'0', 'FAST':'1', 'PARMERGE':'1', 'ARSP':'0'},
-        #{'SLOW':'0', 'FAST':'1', 'PARMERGE':'1', 'ARSP':'1'},
+        {'SLOW':'0', 'FAST':'1', 'PARMERGE':'1', 'ARSP':'1'},
 ]
 
@@ -55,4 +53,6 @@
     code = compile(f.read(), pyconf_file, 'exec')
     exec(code)
+
+nb_step = 0
 
 if use_dsk:
@@ -125,8 +125,8 @@
         plotter.add_x(X)
         assert(nb_step == 4)
-        YPAR1 = [float(exec_time[fconfig][thread]["NF"][density][0]) for density in range(0, 101)] # Parallel Labeling
-        YPAR2 = [float(exec_time[fconfig][thread]["NF"][density][1]) for density in range(0, 101)] # Merging (Parallel or Pyramidal)
-        YPTC2 = [float(exec_time[fconfig][thread]["NF"][density][2]) for density in range(0, 101)] # Parallel Transitive Closure
-        YPAR3 = [float(exec_time[fconfig][thread]["NF"][density][3]) for density in range(0, 101)] # Parallel Relabeling
+        YPAR1 = [float(int(exec_time[fconfig][thread]["NF"][density][0]) / math.pow(img_size, 2)) for density in range(0, 101)] # Parallel Labeling
+        YPAR2 = [float(int(exec_time[fconfig][thread]["NF"][density][1]) / math.pow(img_size, 2)) for density in range(0, 101)] # Merging (Parallel or Pyramidal)
+        YPTC2 = [float(int(exec_time[fconfig][thread]["NF"][density][2]) / math.pow(img_size, 2)) for density in range(0, 101)] # Parallel Transitive Closure
+        YPAR3 = [float(int(exec_time[fconfig][thread]["NF"][density][3]) / math.pow(img_size, 2)) for density in range(0, 101)] # Parallel Relabeling
 
         plotter.add_y(YPAR1)
@@ -136,6 +136,6 @@
 
         if with_features:
-            YPAR1f = [float(exec_time[fconfig][thread]["FT"][density][0]) for density in range(0, 101)] # Parallel Labeling
-            YPAR2f = [float(exec_time[fconfig][thread]["FT"][density][1]) for density in range(0, 101)] # Merging (Parallel or Pyramidal)
+            YPAR1f = [float(int(exec_time[fconfig][thread]["FT"][density][0]) / math.pow(img_size, 2)) for density in range(0, 101)] # Parallel Labeling
+            YPAR2f = [float(int(exec_time[fconfig][thread]["FT"][density][1]) / math.pow(img_size, 2)) for density in range(0, 101)] # Merging (Parallel or Pyramidal)
             deltaYPAR1 = [max(0, x - y) for x, y in zip (YPAR1f, YPAR1)]
             deltaYPAR2 = [max(0, x - y) for x, y in zip (YPAR2f, YPAR2)]
Index: /soft/giet_vm/applications/rosenfeld/scripts/run_simus.py
===================================================================
--- /soft/giet_vm/applications/rosenfeld/scripts/run_simus.py	(revision 822)
+++ /soft/giet_vm/applications/rosenfeld/scripts/run_simus.py	(revision 823)
@@ -5,4 +5,6 @@
 # python 2 as it will execute on computation servers
 
+# TODO:
+#       Can we do something about assert in perf eval?
 
 from __future__ import print_function
@@ -37,10 +39,16 @@
 
 # Parameters
-num_runs = 10
+# - with eval_perf, num_internal_runs should be used, as this allows to mitigate the cost of the extra
+#     run required to have the correct "ne" value (number of labels), and only the times from last application run are taken
+# - With check_results, num_app_runs should be used, so as to have a number of checks equals to the number of runs,
+#     because only one check per application run is performed
+num_app_runs = 1        # Number of times the application is launched per configuration
+num_internal_runs = 20  # Number of times the image is processed inside the application
 check_results = False
 eval_perf = True
 use_valgrind = False
 use_rand_images = True
-threads = [1, 2, 4]
+threads = [1, 2, 4, 8, 16, 32, 64]
+#threads = [1, 2]
 use_dsk = True
 # Using dsk will store generated random images, otherwise they are re-generated at each run to save disk space
@@ -48,8 +56,9 @@
 # Configurations
 configs = [
-        {'SLOW':'1', 'FAST':'0', 'FEATURES':'0', 'PARMERGE':'0', 'ARSP':'0'},
-        {'SLOW':'0', 'FAST':'1', 'FEATURES':'0', 'PARMERGE':'0', 'ARSP':'0'},
-        {'SLOW':'1', 'FAST':'0', 'FEATURES':'1', 'PARMERGE':'0', 'ARSP':'0'},
-        {'SLOW':'0', 'FAST':'1', 'FEATURES':'1', 'PARMERGE':'0', 'ARSP':'0'},
+        #{'SLOW':'1', 'FAST':'0', 'FEATURES':'0', 'PARMERGE':'0', 'ARSP':'0'},
+        #{'SLOW':'0', 'FAST':'1', 'FEATURES':'0', 'PARMERGE':'0', 'ARSP':'0'},
+        #{'SLOW':'1', 'FAST':'0', 'FEATURES':'1', 'PARMERGE':'0', 'ARSP':'0'},
+        #{'SLOW':'0', 'FAST':'1', 'FEATURES':'1', 'PARMERGE':'0', 'ARSP':'0'},
+        {'SLOW':'0', 'FAST':'1', 'FEATURES':'0', 'PARMERGE':'1', 'ARSP':'0'},
         #{'SLOW':'0', 'FAST':'1', 'FEATURES':'1', 'PARMERGE':'1', 'ARSP':'0'},
         #{'SLOW':'0', 'FAST':'1', 'FEATURES':'0', 'PARMERGE':'1', 'ARSP':'1'},
@@ -60,5 +69,5 @@
 rand_seed = 7
 granularity = 1 # constant for now
-img_size = 1024
+img_size = 2048
 
 check_pyconf_file(pyconf_file)
@@ -93,4 +102,14 @@
 
 
+if check_results and eval_perf:
+    print("*** Warning: check_results and eval_perf modes are both set\n")
+if eval_perf and use_valgrind:
+    print("*** Warning: using valgrind while eval_perf mode is set\n")
+if eval_perf and num_app_runs != 1:
+    print("*** Warning: using eval_perf with num_app_runs != 1\n")
+if check_results and num_internal_runs != 1:
+    print("*** Warning: using check_results with num_internal_runs != 1\n")
+
+
 
 def gen_random_image(filename, x, y, granularity, density, seed):
@@ -136,5 +155,12 @@
                     break
             if not line_with_key:
-                f.write(line)
+                if "#define MCA_VERBOSE_LEVEL" in line:
+                    if eval_perf:
+                        verb_level = 1
+                    else:
+                        verb_level = 2
+                    f.write("#define MCA_VERBOSE_LEVEL %d\n" % verb_level)  
+                else:
+                    f.write(line)
 
         f.close()
@@ -179,4 +205,6 @@
     my_chdir(top_path)
     cmd = ['make']
+    #if eval_perf:
+    #    cmd.extend(['IGNORE_ASSERT=true'])
     print_and_call(cmd)
     my_chdir(scripts_path)
@@ -205,5 +233,5 @@
         for nthreads in threads:
             perf_array[fconfig][img_basename][nthreads] = {}
-            for run in range(num_runs):
+            for run in range(num_app_runs):
                 if not os.path.exists(ref_bmpfile):
                     bmpfile = ref_bmpfile
@@ -223,4 +251,7 @@
     
                 cmd.extend([short_path(binary_file), '-n', str(nthreads), '-i', short_path(image)])
+
+                if num_internal_runs > 1:
+                    cmd.extend(['-r', str(num_internal_runs)])
                 
                 if check_results:
@@ -236,4 +267,5 @@
 
                 # if performance evaluation, get timing measurements
+                # Only the last application run is considered
                 if eval_perf:
                     for line in outlines:
@@ -247,9 +279,5 @@
                             step = match.group(1)
                             value = tokens[len(tokens) - 1]
-                            if step in perf_array[fconfig][img_basename][nthreads]:
-                                # Accumulating times over the num_runs runs
-                                perf_array[fconfig][img_basename][nthreads][step] += int(value)
-                            else:
-                                perf_array[fconfig][img_basename][nthreads][step] = int(value)
+                            perf_array[fconfig][img_basename][nthreads][step] = int(value)
 
 
@@ -315,5 +343,5 @@
                 for step in sorted(perf_array[fconfig][img_basename][nthreads].keys()):
                     # Average time for each step
-                    file.write("[STEP_%s]   %d\n" % (step, perf_array[fconfig][img_basename][nthreads][step] / num_runs))
+                    file.write("[STEP_%s]   %d\n" % (step, perf_array[fconfig][img_basename][nthreads][step]))
 
         img_idx += 1
Index: /soft/giet_vm/applications/rosenfeld/src-par/mca.c
===================================================================
--- /soft/giet_vm/applications/rosenfeld/src-par/mca.c	(revision 822)
+++ /soft/giet_vm/applications/rosenfeld/src-par/mca.c	(revision 823)
@@ -98,7 +98,7 @@
 
 
-// -----------------------------------------------
+// ------------------------------------------------
 void MCA_Set_Size(MCA * mca, int width, int height)
-// -----------------------------------------------
+// ------------------------------------------------
 {
     MCA_Set_Width(mca, width);
@@ -107,7 +107,7 @@
 
 
-// ----------------------------------------------------
+// -----------------------------------------------------
 void MCA_Set_Dimension(MCA * mca, int width, int height)
-// ----------------------------------------------------
+// -----------------------------------------------------
 {
     MCA_Set_Width(mca, width);
@@ -116,10 +116,19 @@
 
 
-// ------------------------------
+// -------------------------------
 void MCA_Set_NP(MCA * mca, int np)
-// ------------------------------
+// -------------------------------
 {
     mca->np = np;
 }
+
+
+// -------------------------------
+void MCA_Set_NR(MCA * mca, int nr)
+// -------------------------------
+{
+    mca->nr = nr;
+}
+
 
 
@@ -146,4 +155,5 @@
     // input
     int np     = mca->np;
+    int nr     = mca->nr;
     int width  = mca->width;
     int height = mca->height;
@@ -292,6 +302,9 @@
         mca_par->e0 = e0_par;
         mca_par->e1 = e1_par;
+        // Ã  la premiÃšre itÃ©ration, on remet Ã  0 toute la table T
+        mca_par->ne_prev = e1_par;
         mca_par->alpha = pw2;
         mca_par->np = np;
+        mca_par->nr = nr;
         // Pour les barriÃšres pyramidales
         mca_par->nb_level = nb_level;
@@ -311,12 +324,6 @@
         mca_par->E = remote_dist_ui32matrix(i0_par, i1_par, 0, width - 1, x, y); // distributed matrix with border
         
-        if (p == 0) {
-            mca_par->T = remote_ui32vector(e0_par - 1, e1_par, x, y); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot
-            mca_par->stats = remote_RegionStatsVector(e0_par - 1, e1_par, x, y);
-        }
-        else {
-            mca_par->T = remote_ui32vector(e0_par, e1_par, x, y);
-            mca_par->stats = remote_RegionStatsVector(e0_par, e1_par, x, y);
-        }
+        mca_par->T = remote_ui32vector(e0_par, e1_par, x, y);
+        mca_par->stats = remote_RegionStatsVector(e0_par, e1_par, x, y);
         
         mca_par->D = (uint32 **) remote_vvector(0, np - 1, x, y);
@@ -326,12 +333,6 @@
         mca_par->E = dist_ui32matrix(i0_par, i1_par, 0, width - 1); // distributed matrix with border
         
-        if (p == 0) {
-            mca_par->T = ui32vector(e0_par - 1, e1_par); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot
-            mca_par->stats = RegionStatsVector(e0_par - 1, e1_par);
-        }
-        else {
-            mca_par->T = ui32vector(e0_par, e1_par);
-            mca_par->stats = RegionStatsVector(e0_par, e1_par);
-        }
+        mca_par->T = ui32vector(e0_par, e1_par);
+        mca_par->stats = RegionStatsVector(e0_par, e1_par);
         
         mca_par->D = (uint32 **) vvector(0, np - 1);
@@ -353,11 +354,5 @@
     
         MCA_VERBOSE3(printf("p = %d T[%d..%d]\n", p, e0, e1));
-        if (p == 0) {
-            set_ui32vector_j(T, e0 - 1, e1); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot
-        }
-        else {
-            set_ui32vector_j(T, e0, e1);
-        }
-        MCA_VERBOSE3(printf("\n"));
+        set_ui32vector_j(T, e0, e1);
     }
     
@@ -371,10 +366,5 @@
         
         MCA_VERBOSE3(printf("p = %d T[%d..%d]\n", p, e0, e1));
-        if (p == 0) {
-            MCA_VERBOSE3(display_ui32vector_number(T, e0 - 1, e0 + 10, "%5d", "T"));
-        }
-        else {
-            MCA_VERBOSE3(display_ui32vector_number(T, e0, e0 + 10, "%5d", "T"));
-        }
+        MCA_VERBOSE3(display_ui32vector_number(T, e0, e0 + 10, "%5d", "T"));
         MCA_VERBOSE3(printf("\n"));
     }
@@ -506,12 +496,6 @@
         free_dist_ui32matrix(mca_par->E, i0, i1, j0, j1);
         
-        if (p == 0) {
-            free_ui32vector(mca_par->T, e0 - 1, e1); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot
-            free_RegionStatsVector(mca_par->stats, e0 - 1, e1);
-        }
-        else {
-            free_ui32vector(mca_par->T, e0, e1);
-            free_RegionStatsVector(mca_par->stats, e0, e1);
-        }
+        free_ui32vector(mca_par->T, e0, e1);
+        free_RegionStatsVector(mca_par->stats, e0, e1);
         
         free_vvector((void **) mca_par->D, 0, np - 1);
Index: /soft/giet_vm/applications/rosenfeld/src-par/mca_main.c
===================================================================
--- /soft/giet_vm/applications/rosenfeld/src-par/mca_main.c	(revision 822)
+++ /soft/giet_vm/applications/rosenfeld/src-par/mca_main.c	(revision 823)
@@ -43,4 +43,5 @@
 #define MAX_THREADS 256
 #define DEFAULT_NTHREADS 1
+#define DEFAULT_NRUNS 1
 #define DEFAULT_IN_FILENAME "/misc/cadastre.pgm"
 #define DEFAULT_OUT_FILENAME "out.bmp"
@@ -233,7 +234,7 @@
 
 
-// -----------------------------------------------------------
-void mca_test2(int num_threads, char * infile, char * outfile)
-// -----------------------------------------------------------
+// -------------------------------------------------------------------------
+void mca_test2(int num_threads, int num_runs, char * infile, char * outfile)
+// -------------------------------------------------------------------------
 {
     int i0, i1, j0, j1;
@@ -277,4 +278,5 @@
     MCA_Set_ImageL(mca, E);
     MCA_Set_NP(mca, num_threads);
+    MCA_Set_NR(mca, num_runs);
     
     // -- MCA init
@@ -316,12 +318,12 @@
 
 
-// --------------------------------------------------------------
-int main_test_mca(int num_threads, char * infile, char * outfile)
-// --------------------------------------------------------------
+// ----------------------------------------------------------------------------
+int main_test_mca(int num_threads, int num_runs, char * infile, char * outfile)
+// ----------------------------------------------------------------------------
 {
     CLOCK_INIT(num_threads, 4); // 4 = Number of steps in body
     CLOCK_APP_START;
 
-    mca_test2(num_threads, infile, outfile);
+    mca_test2(num_threads, num_runs, infile, outfile);
 
     CLOCK_APP_END;
@@ -349,9 +351,10 @@
     int ch;
     int num_threads = DEFAULT_NTHREADS;
+    int num_runs = DEFAULT_NRUNS;
 
     MCA_VERBOSE1(printf("*** Starting application Rosenfeld ***\n"));
 
 #if TARGET_OS != GIETVM // @QM I think the giet has some random (uninitialized) values for argc and argv
-    while ((ch = getopt(argc, argv, "i:o:n:hdg")) != EOF) {
+    while ((ch = getopt(argc, argv, "i:o:n:r:hdg")) != EOF) {
         switch (ch) {
         case 'i':
@@ -363,4 +366,7 @@
         case 'n':
             num_threads = atoi(optarg);
+            break;
+        case 'r':
+            num_runs = atoi(optarg);
             break;
         case 'h':
@@ -409,4 +415,5 @@
     MCA_VERBOSE1(printf("Parameters:\n"));
     MCA_VERBOSE1(printf("- Number of threads: %d\n", num_threads));
+    MCA_VERBOSE1(printf("- Number of images processed: %d\n", num_runs));
     MCA_VERBOSE1(printf("- Input file: %s\n", infile));
     MCA_VERBOSE1(printf("- Output file: %s\n", outfile));
@@ -450,5 +457,5 @@
 
     pthread_mutex_init(&print_lock, PTHREAD_PROCESS_PRIVATE);
-    main_test_mca(num_threads, infile, outfile);
+    main_test_mca(num_threads, num_runs, infile, outfile);
 
     return 0;
Index: /soft/giet_vm/applications/rosenfeld/src-par/mca_rosenfeld.c
===================================================================
--- /soft/giet_vm/applications/rosenfeld/src-par/mca_rosenfeld.c	(revision 822)
+++ /soft/giet_vm/applications/rosenfeld/src-par/mca_rosenfeld.c	(revision 823)
@@ -142,4 +142,40 @@
 }
 #endif // FEATURES && !PARMERGE
+
+
+#if !FEATURES && PARMERGE
+// -----------------------------------------------------------------------------------------------------------
+static bool SetRoot_Parallel_Rosenfeld_Dist(uint32 ** D, uint32 root, uint32 eps, int shift, RegionStats ** F)
+// -----------------------------------------------------------------------------------------------------------
+{
+    assert(root != 0 && eps != 0);
+
+    MCA_VERBOSE3(printf("F(%d) += F(%d)\n", eps, root));
+    
+    int mask = (1 << shift) - 1;
+
+    uint32 r1 = root >> shift;
+    uint32 r0 = root & mask;
+    
+    uint32 e1 = eps >> shift;
+    uint32 e0 = eps & mask;
+
+    // Locking towards the root (first root, then eps)
+    pthread_spin_lock(&F[r1][r0].lock);
+    pthread_spin_lock(&F[e1][e0].lock);
+    if (D[e1][e0] != eps || D[r1][r0] != root) {
+        // Someone change the root of epsilon or "root", need to find the new root
+        pthread_spin_unlock(&F[e1][e0].lock);
+        pthread_spin_unlock(&F[r1][r0].lock);
+        return false;
+    }
+
+    D[r1][r0] = eps;
+    
+    pthread_spin_unlock(&F[e1][e0].lock);
+    pthread_spin_unlock(&F[r1][r0].lock);
+    return true;
+}
+#endif // !FEATURES && PARMERGE
 
 
@@ -585,7 +621,7 @@
 
 
-#if FAST && FEATURES && PARMERGE && !ARSP
+#if FAST && PARMERGE && !ARSP // Valid for FEATURES and !FEATURES
 // ---------------------------------------------------------------------------------------------------------------------------
-static void vuse2_Parallel_Features_Rosenfeld_Dist(uint32 ed, uint32 el, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
+static void vuse2_Parallel_Rosenfeld_Dist(uint32 ed, uint32 el, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
 // ---------------------------------------------------------------------------------------------------------------------------
 {
@@ -610,16 +646,17 @@
         // qui a fait un test
         if (rd < rl) {
-            ok = SetRoot_Parallel_Features_Rosenfeld_Dist(D, rl, rd, alpha, F);
+            // Features or No Features depending on config
+            ok = SetRoot_Parallel_FNF(D, rl, rd, alpha, F);
         }
         else {
-            ok = SetRoot_Parallel_Features_Rosenfeld_Dist(D, rd, rl, alpha, F);
+            ok = SetRoot_Parallel_FNF(D, rd, rl, alpha, F);
         }
     } while (!ok);
 }
 
-// FAST && FEATURES && PARMERGE && !ARSP
+// FAST && PARMERGE && !ARSP
 
 // -----------------------------------------------------------------------------------------------------------------------------------------
-static void vuse3_Parallel_Features_Rosenfeld_Dist(uint32 ed1, uint32 ed2, uint32 el3, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
+static void vuse3_Parallel_Rosenfeld_Dist(uint32 ed1, uint32 ed2, uint32 el3, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
 // -----------------------------------------------------------------------------------------------------------------------------------------
 {
@@ -649,15 +686,15 @@
         ok3 = true;
         if (r1 > eps) {
-            ok1 = SetRoot_Parallel_Features_Rosenfeld_Dist(D, r1, eps, alpha, F);
+            ok1 = SetRoot_Parallel_FNF(D, r1, eps, alpha, F);
         }
         if (r2 > eps && r2 != r1) {
-            ok2 = SetRoot_Parallel_Features_Rosenfeld_Dist(D, r2, eps, alpha, F);
+            ok2 = SetRoot_Parallel_FNF(D, r2, eps, alpha, F);
         }
         if (r3 > eps && r3 != r2 && r3 != r1) {
-            ok3 = SetRoot_Parallel_Features_Rosenfeld_Dist(D, r3, eps, alpha, F);
+            ok3 = SetRoot_Parallel_FNF(D, r3, eps, alpha, F);
         }
     } while (!(ok1 && ok2 && ok3));
 }
-#endif // FAST && FEATURES && PARMERGE && !ARSP
+#endif // FAST && PARMERGE && !ARSP
 
 
@@ -1381,4 +1418,5 @@
     uint32 e0 = mca->e0;
     uint32 e1 = mca->e1;
+    uint32 ne_prev = mca->ne_prev;
     uint32 ne = e0 - 1;
     uint32 nr = 0;
@@ -1390,17 +1428,10 @@
     RegionStats * stats = mca->stats;
 
-    // reset sous optimal (pour le moment = voir region32)
-    if (mca->p == 0) {
-        set_ui32vector_j(T, e0 - 1, e1); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot
+    CLOCK_THREAD_START_STEP(mca->p, 0);
+
+    set_ui32vector_j(T, e0, ne_prev);
 #if FEATURES
-        zero_RegionStatsVector(stats, e0 - 1, e1);
+    zero_RegionStatsVector(stats, e0, ne_prev);
 #endif
-    }
-    else {
-        set_ui32vector_j(T, e0, e1);
-#if FEATURES
-        zero_RegionStatsVector(stats, e0, e1);
-#endif
-    }
 
     if (mca->p == 0) {
@@ -1411,6 +1442,4 @@
     // -- Etiquetage d'une bande -- //
     // ---------------------------- //
-
-    CLOCK_THREAD_START_STEP(mca->p, 0);
 
     ne = line0Labeling_Rosenfeld(X, i0, width, E, T, ne);
@@ -1644,26 +1673,59 @@
 
     CLOCK_THREAD_START(mca->p);
-    CLOCK_THREAD_COMPUTE_START(mca->p);
-
-    MCA_Scatter_ImageX(mca);
-    pthread_barrier_wait(&main_barrier);
-
-    MCA_Label_Rosenfeld_PAR1(mca);
-    pthread_barrier_wait(&main_barrier);
-   
+
+    int num_runs = mca->nr;
+
+    // We always perform one more run than the num_runs
+    // value, so as to know "ne", i.e. the number of
+    // elements to reset in the T and F tables (labels and stats)
+    // After this first extra run, clock times are not accumulated
+    // and thus are lost.
+    // Note: the CLOCK_THREAD_START will still include this first run,
+    // and in case of multiple runs, only averaged times should be
+    // considered.
+    for (int run = 0; run < num_runs + 1; run++) {
+
+        CLOCK_THREAD_COMPUTE_START(mca->p);
+
+        MCA_Scatter_ImageX(mca);
+        pthread_barrier_wait(&main_barrier);
+
+        MCA_Label_Rosenfeld_PAR1(mca);
+        pthread_barrier_wait(&main_barrier);
+ 
 #if PARMERGE 
-    MCA_Label_Rosenfeld_PAR2(mca);
+        MCA_Label_Rosenfeld_PAR2(mca);
 #else
-    MCA_Label_Rosenfeld_PYR2(mca);
+        MCA_Label_Rosenfeld_PYR2(mca);
 #endif
-    pthread_barrier_wait(&main_barrier);
-    
-    MCA_Label_Rosenfeld_PAR3(mca);
-    pthread_barrier_wait(&main_barrier);
-
-    MCA_Gather_ImageL(mca);
-    pthread_barrier_wait(&main_barrier);
-
-    CLOCK_THREAD_COMPUTE_END(mca->p);
+        pthread_barrier_wait(&main_barrier);
+ 
+        MCA_Label_Rosenfeld_PAR3(mca);
+        pthread_barrier_wait(&main_barrier);
+
+        MCA_Gather_ImageL(mca);
+        pthread_barrier_wait(&main_barrier);
+        
+        CLOCK_THREAD_COMPUTE_END(mca->p);
+
+        if (run == 0) {
+            // Mise Ã  jour du ne_prev par chaque thread
+            mca->ne_prev = mca->ne;
+            mca->ne = 0;
+        }
+        else {
+            // Accumulation du temps COMPUTE et de toutes les STEP
+            if (mca->p == 0) {
+                CLOCK_ACCUMULATE;
+            }
+            assert(mca->ne == mca->ne_prev);
+            // Reinitialisation de "ne" s'il ne s'agit pas du dernier run
+            if (run != num_runs) {
+                mca->ne = 0;
+            }
+        }
+        pthread_barrier_wait(&main_barrier);
+    }
+
  
 #if FEATURES
