Index: soft/giet_vm/applications/rosenfeld/Makefile
===================================================================
--- soft/giet_vm/applications/rosenfeld/Makefile	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/Makefile	(revision 822)
@@ -3,5 +3,4 @@
 SRC_PATH = src-par
 OBJ_PATH = obj
-EXE_PATH = bin
 INC_PATH = include
 
@@ -61,8 +60,14 @@
 
 
-all: $(APP_NAME)
+all: nrclib $(APP_NAME)
+
+nrclib:
+	make -C nrc2
 
 $(APP_NAME): $(OBJ_FILE)
 	$(LD) -o $@ $^ $(LDFLAGS)
+
+#obj/bmpNR.o: src-par/bmpNR.c $(INC_FILE) nrc2/libnrc2x.a ../../build/libs/libuser.a nrc2/include/nrc_os_config.h
+#	$(CC) -c $(CFLAGS) -o $@ $<
 
 $(OBJ_PATH)/%.o: $(SRC_PATH)/%.c $(INC_FILE) nrc2/libnrc2x.a ../../build/libs/libuser.a nrc2/include/nrc_os_config.h
Index: soft/giet_vm/applications/rosenfeld/check.py
===================================================================
--- soft/giet_vm/applications/rosenfeld/check.py	(revision 821)
+++ 	(revision )
@@ -1,241 +1,0 @@
-#!/usr/bin/python
-# -*- coding: utf-8 -*-
-
-from __future__ import print_function
-import os
-import sys
-import re
-import subprocess
-import shutil
-import filecmp
-
-#images = ['../../images/boulons.pgm', '../../images/cadastre.pgm', '../../images/alea1.pgm', '../../images/alea2.pgm', '../../images/alea3.pgm']
-images = ['../../images/alea1.pgm']
-config_file = "include/config.h"
-
-use_valgrind = False
-infinite_mode = True
-
-threads = [64]
-binary = "./appli.elf"
-outimages_dir = "output_images"
-log_dir = "logs"
-
-configs = [
-#        {
-#            'SLOW':'1',
-#            'FAST':'0',
-#            'FEATURES':'0',
-#            'PARMERGE':'0'
-#        },
-#        {
-#            'SLOW':'0',
-#            'FAST':'1',
-#            'FEATURES':'0',
-#            'PARMERGE':'0'
-#        },
-#        {
-#            'SLOW':'1',
-#            'FAST':'0',
-#            'FEATURES':'1',
-#            'PARMERGE':'0'
-#        },
-#        {
-#            'SLOW':'0',
-#            'FAST':'1',
-#            'FEATURES':'1',
-#            'PARMERGE':'0'
-#        },
-        {
-            'SLOW':'0',
-            'FAST':'1',
-            'FEATURES':'1',
-            'PARMERGE':'1'
-        }
-]
-
-
-
-def my_mkdir(dirname):
-    try:
-        print("mkdir %s" % (dirname))
-        os.mkdir(dirname)
-    except OSError:
-        print("*** Error: impossible to create directory %s" % (dirname), file=sys.stderr)
-        sys.exit(1)
-
-def my_chdir(dirname):
-    print("cd %s" % (dirname));
-    os.chdir(dirname)
-
-def my_cp(src, dst):
-    print("cp %s %s" % (src, dst))
-    shutil.copy(src, dst)
-
-def print_and_call(cmd):
-    print(subprocess.list2cmdline(cmd))
-    retval = subprocess.call(cmd)
-    return retval
-
-def print_and_popen(cmd, outfile):
-    print(subprocess.list2cmdline(cmd), end = "")
-    print(" >", outfile)
-    output = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT).communicate()[0]
-    return output
-
-
-
-
-def update_config_file(config):
-    if os.path.isfile(config_file):
-        print("# Updating file %s" % (config_file))
-        f = open(config_file, "r")
-        lines = f.readlines()
-        f.close()
-
-        f = open(config_file, "w")
-
-        for line in lines:
-            line_with_key = False
-            for key in config.keys():
-                if "#define %s" % (key) in line:
-                    f.write("#define %s %s\n" % (key, config[key]))
-                    line_with_key = True
-                    break
-            if not line_with_key:
-                f.write(line)
-
-        f.close()
-    else:
-        print("# Creating file %s" % (config_file))
-        f = open(config_file, "w")
-        f.write("\n")
-        for key in config.keys():
-            f.write("#define %s %s\n" % (key, config[key]))
-        f.write("\n")
-        f.close()
-
-
-root_dir = os.getcwd()
-
-
-if not os.path.exists(outimages_dir):
-    my_mkdir(outimages_dir)
-
-if not os.path.exists(log_dir):
-    my_mkdir(log_dir)
-
-
-stat_array = {}
-finished = False
-
-for config in configs:
-    update_config_file(config)
-    cmd = ['make']
-    print_and_call(cmd)
-    for image in images:
-        ref_bmpfile = os.path.join(outimages_dir, os.path.splitext(os.path.basename(image))[0] + "_ref.bmp")
-        ref_statfile = os.path.join(outimages_dir, os.path.splitext(os.path.basename(image))[0] + "_ref.txt")
-        for nthreads in threads:
-            while not finished:
-                if not os.path.exists(ref_bmpfile):
-                    bmpfile = ref_bmpfile
-                else:
-                    bmpfile = os.path.join(outimages_dir, os.path.splitext(os.path.basename(image))[0] + ".bmp")
-
-                if not os.path.exists(ref_statfile):
-                    statfile = ref_statfile
-                else:
-                    statfile = os.path.join(outimages_dir, os.path.splitext(os.path.basename(image))[0] + ".txt")
-
-                cmd = []
-                if use_valgrind:
-                    cmd.append('valgrind')
-
-                cmd.extend([binary, '-n', str(nthreads), '-i', image, '-o', bmpfile, '-g'])
-                
-                if config['FEATURES'] == '1':
-                    cmd.append('-d')
-
-                config_keys = config.keys()
-                logfile = os.path.join(log_dir, os.path.splitext(os.path.basename(image))[0] + "_" + str(nthreads) + "_" + "_".join(map(lambda x:'%s_%s' % (x, config[x]), config_keys)) + ".txt")
-                output = print_and_popen(cmd, logfile)
-                
-                # Write simulation results to log file
-                file = open(logfile, 'w')
-                file.write(output)
-                file.close()
-
-                if bmpfile != ref_bmpfile:
-                    if filecmp.cmp(bmpfile, ref_bmpfile):
-                        print("# Files %s and %s are identical" % (bmpfile, ref_bmpfile))
-                    else:
-                        print("*** Error: files %s and %s differ" % (bmpfile, ref_bmpfile))
-                        sys.exit(1)
-
-                if use_valgrind:
-                    if not "== ERROR SUMMARY: 0 errors from 0 contexts" in output:
-                        print("*** Error: Valgrind error")
-                        sys.exit(1)
-                    if not "== All heap blocks were freed -- no leaks are possible" in output:
-                        print("*** Error: Valgrind detected a memory leak")
-                        sys.exit(1)
-
-                if config['FEATURES'] == '1':
-                    stat_array = {}
-                    in_stats = False
-                    outlines = output.splitlines()
-                    index = 0
-                    for line in outlines:
-                        #print("bla i")
-                        #print(line)
-                        if "[STATS]" in line:
-                            in_stats = True
-                            continue
-                        if "[/STATS]" in line:
-                            in_stat = False
-                            break
-                        if in_stats:
-                            tokens = line.split()
-                            #print("#len : %d" % len(tokens))
-                            #print(tokens[0])
-                            assert(len(tokens) == 8)
-                            stat_array[index] = {}
-                            for j in range(len(tokens)):
-                                stat_array[index][j] = tokens[j]
-                            index += 1
-
-
-                    # Dump stat array in stat file
-                    file = open(statfile, 'w')
-                    for i in range(len(stat_array)):
-                        for j in range(8):
-                            file.write("%s " % stat_array[i][j])
-                        file.write("\n");
-                    file.close()
-
-                    # Comparison to reference
-                    if statfile != ref_statfile:
-                        if filecmp.cmp(statfile, ref_statfile):
-                            print("# Feature files %s and %s are identical" % (statfile, ref_statfile))
-                        else:
-                            print("*** Error: feature files %s and %s differ" % (statfile, ref_statfile))
-                            sys.exit(1)
-
-                if not infinite_mode:
-                    finished = True
-                
-
-
-
-
-
-
-
-
-
-
-
-
-
-
Index: soft/giet_vm/applications/rosenfeld/include/clock.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/include/clock.h	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/include/clock.h	(revision 822)
@@ -31,10 +31,10 @@
 
 
-static void local_sort_asc(uint32_t tab[], int size) {
-    int tmp;
-    int i, j;
+static void local_sort_asc(uint64_t tab[], int32_t size) {
+    int32_t tmp;
+    int32_t i, j;
     for (i = 0; i < size; i++) {
-        uint32_t min = tab[i];
-        int jmin = i;
+        uint64_t min = tab[i];
+        int32_t jmin = i;
         for (j = i + 1; j < size; j++) {
             if (tab[j] < min) {
@@ -51,22 +51,22 @@
 
 
-#define CLOCK_DEC uint32_t app_start;                   \
-                  uint32_t app_end;                     \
-                  uint32_t app_create;                  \
-                  uint32_t app_join;                    \
-                  uint32_t * thread_start;              \
-                  uint32_t * thread_end;                \
-                  uint32_t * thread_compute_start;      \
-                  uint32_t * thread_compute_end;        \
+#define CLOCK_DEC uint64_t app_start;                   \
+                  uint64_t app_end;                     \
+                  uint64_t app_create;                  \
+                  uint64_t app_join;                    \
+                  uint64_t * thread_start;              \
+                  uint64_t * thread_end;                \
+                  uint64_t * thread_compute_start;      \
+                  uint64_t * thread_compute_end;        \
                   int32_t step_number;                  \
                   int32_t clock_thread_num;             \
-                  uint32_t ** thread_start_step;        \
-                  uint32_t ** thread_end_step;          \
-                  uint32_t global_thread_start;         \
-                  uint32_t global_thread_end;           \
-                  uint32_t global_thread_compute_start; \
-                  uint32_t global_thread_compute_end;   \
-                  uint32_t * global_thread_start_step;  \
-                  uint32_t * global_thread_end_step;    \
+                  uint64_t ** thread_start_step;        \
+                  uint64_t ** thread_end_step;          \
+                  uint64_t global_thread_start;         \
+                  uint64_t global_thread_end;           \
+                  uint64_t global_thread_compute_start; \
+                  uint64_t global_thread_compute_end;   \
+                  uint64_t * global_thread_start_step;  \
+                  uint64_t * global_thread_end_step;
 
 #if TARGET_OS == GIETVM
@@ -76,5 +76,5 @@
             struct timeval full_time;         \
             gettimeofday(&full_time, NULL);   \
-            x = (unsigned long) ((full_time.tv_usec + full_time.tv_sec * 1000000) / 1000); \
+            x = (uint64_t) ((full_time.tv_usec + full_time.tv_sec * 1000000)); \
             })
 #endif
@@ -84,23 +84,23 @@
     clock_thread_num = (x);                                                         \
     step_number = (y);                                                              \
-    global_thread_start = 0xFFFFFFFFLLU;                                            \
+    global_thread_start = 0xFFFFFFFFFFFFFFFFLLU;                                    \
     global_thread_end = 0;                                                          \
-    global_thread_compute_start = 0xFFFFFFFFLLU;                                    \
+    global_thread_compute_start = 0xFFFFFFFFFFFFFFFFLLU;                            \
     global_thread_compute_end = 0;                                                  \
     if ((x) > 0) {                                                                  \
-        thread_start = (uint32_t *) malloc(sizeof(uint32_t) * (x));                 \
-        thread_end = (uint32_t *) malloc(sizeof(uint32_t) * (x));                   \
-        thread_compute_start = (uint32_t *) malloc(sizeof(uint32_t) * (x));         \
-        thread_compute_end = (uint32_t *) malloc(sizeof(uint32_t) * (x));           \
+        thread_start = (uint64_t *) malloc(sizeof(uint64_t) * (x));                 \
+        thread_end = (uint64_t *) malloc(sizeof(uint64_t) * (x));                   \
+        thread_compute_start = (uint64_t *) malloc(sizeof(uint64_t) * (x));         \
+        thread_compute_end = (uint64_t *) malloc(sizeof(uint64_t) * (x));           \
         if ((y) > 0) {                                                              \
-            global_thread_start_step = (uint32_t *) malloc(sizeof(uint32_t) * (y)); \
-            global_thread_end_step = (uint32_t *) malloc(sizeof(uint32_t) * (y));   \
-            thread_start_step = (uint32_t **) malloc(sizeof(uint32_t *) * (y));     \
-            thread_end_step = (uint32_t **) malloc(sizeof(uint32_t *) * (y));       \
-            for (int j = 0; j < (y); j++) {                                         \
-                global_thread_start_step[j] = 0xFFFFFFFFLU;                         \
+            global_thread_start_step = (uint64_t *) malloc(sizeof(uint64_t) * (y)); \
+            global_thread_end_step = (uint64_t *) malloc(sizeof(uint64_t) * (y));   \
+            thread_start_step = (uint64_t **) malloc(sizeof(uint64_t *) * (y));     \
+            thread_end_step = (uint64_t **) malloc(sizeof(uint64_t *) * (y));       \
+            for (int32_t j = 0; j < (y); j++) {                                     \
+                global_thread_start_step[j] = 0xFFFFFFFFFFFFFFFFLU;                 \
                 global_thread_end_step[j] = 0;                                      \
-                thread_start_step[j] = (uint32_t *) malloc(sizeof(uint32_t) * (x)); \
-                thread_end_step[j] = (uint32_t *) malloc(sizeof(uint32_t) * (x));   \
+                thread_start_step[j] = (uint64_t *) malloc(sizeof(uint64_t) * (x)); \
+                thread_end_step[j] = (uint64_t *) malloc(sizeof(uint64_t) * (x));   \
             }                                                                       \
         }                                                                           \
@@ -121,7 +121,6 @@
 
 
-// x = number of threads
 #define CLOCK_FINALIZE ({                                                \
-    for (int i = 0; i < clock_thread_num; i++) {                         \
+    for (int32_t i = 0; i < clock_thread_num; i++) {                     \
         if (thread_start[i] < global_thread_start) {                     \
             global_thread_start = thread_start[i];                       \
@@ -136,5 +135,5 @@
             global_thread_compute_end = thread_compute_end[i];           \
         }                                                                \
-        for (int j = 0; j < step_number; j++) {                          \
+        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];   \
@@ -147,47 +146,47 @@
 })
 
-#define PRINT_CLOCK ({                                                                                         \
-    printf("Timestamps:\n");                                                                                   \
-    printf("[APP_START]            : %d\n", app_start);                                                        \
-    printf("[APP_CREATE]           : %d\n", app_create);                                                       \
-    printf("[THREAD_START]         : %d\n", global_thread_start);                                              \
-    printf("[THREAD_COMPUTE_START] : %d\n", global_thread_compute_start);                                      \
-    for (int j = 0; j < step_number; j++) {                                                                    \
-        printf("[THREAD_START_STEP_%d]  : %d\n", j, global_thread_start_step[j]);                              \
-        printf("[THREAD_END_STEP_%d]    : %d\n", j, global_thread_end_step[j]);                                \
-    }                                                                                                          \
-    printf("[THREAD_COMPUTE_END]   : %d\n", global_thread_compute_end);                                        \
-    printf("[THREAD_END]           : %d\n", global_thread_end);                                                \
-    printf("[APP_JOIN]             : %d\n", app_join);                                                         \
-    printf("[APP_END]              : %d\n", app_end);                                                          \
-    printf("Durations (in cycles):\n");                                                                        \
-    printf("[TOTAL]                : %d\n", app_end - app_start);                                              \
-    printf("[THREAD]               : %d\n", app_join - app_create);                                            \
-    printf("[PARALLEL]             : %d\n", global_thread_end - global_thread_start);                          \
-    printf("[PARALLEL_COMPUTE]     : %d\n", global_thread_compute_end - global_thread_compute_start);          \
-    for (int j = 0; j < step_number; j++) {                                                                    \
-        printf("[THREAD_STEP_%d]        : %d\n", j, global_thread_end_step[j] - global_thread_start_step[j]);  \
-    }                                                                                                          \
-    printf("\n");                                                                                              \
-    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 (int 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);                                                  \
-    }                                                                                                          \
-    printf("# cycle     thread_id\n");                                                                         \
-    for (int i = 0; i < clock_thread_num; i++) {                                                               \
-        printf("%d\t%d\n", thread_start[i], i);                                                                \
-        printf("%d\t%d\n", thread_compute_start[i], i);                                                        \
-        for (int j = 0; j < step_number; j++) {                                                                \
-            printf("%d\t%d\n", thread_start_step[j][i], i);                                                    \
-            printf("%d\t%d\n", thread_end_step[j][i], i);                                                      \
-        }                                                                                                      \
-        printf("%d\t%d\n", thread_compute_end[i], i);                                                          \
-        printf("%d\t%d\n", thread_end[i], i);                                                                  \
-    }                                                                                                          \
+#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));                                                                  \
+    }                                                                                                                          \
 })
 
@@ -197,21 +196,21 @@
 
 
-#define CLOCK_FREE ({                                                \
-    if (clock_thread_num > 0) {                                      \
-        free(thread_start);                                          \
-        free(thread_end);                                            \
-        free(thread_compute_start);                                  \
-        free(thread_compute_end);                                    \
-        if (step_number > 0) {                                       \
-            free(global_thread_start_step);                          \
-            free(global_thread_end_step);                            \
-            for (int j = 0; j < step_number; j++) {                  \
-                free(thread_start_step[j]);                          \
-                free(thread_end_step[j]);                            \
-            }                                                        \
-            free(thread_start_step);                                 \
-            free(thread_end_step);                                   \
-        }                                                            \
-    }                                                                \
+#define CLOCK_FREE ({                                   \
+    if (clock_thread_num > 0) {                         \
+        free(thread_start);                             \
+        free(thread_end);                               \
+        free(thread_compute_start);                     \
+        free(thread_compute_end);                       \
+        if (step_number > 0) {                          \
+            free(global_thread_start_step);             \
+            free(global_thread_end_step);               \
+            for (int32_t j = 0; j < step_number; j++) { \
+                free(thread_start_step[j]);             \
+                free(thread_end_step[j]);               \
+            }                                           \
+            free(thread_start_step);                    \
+            free(thread_end_step);                      \
+        }                                               \
+    }                                                   \
 })
 
Index: soft/giet_vm/applications/rosenfeld/include/config.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/include/config.h	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/include/config.h	(revision 822)
@@ -1,2 +1,5 @@
+
+#ifndef __CONFIG_H_
+#define __CONFIG_H_
 
 #define SLOW 0
@@ -4,5 +7,6 @@
 #define FAST 1
 #define PYR_BARRIERS 0
-#define PARMERGE 1
+#define PARMERGE 0
+#define ARSP 0
 
 #if FAST && SLOW
@@ -14,6 +18,61 @@
 #endif
 
-#if PARMERGE && (!FEATURES || !FAST)
-#error "PARMERGE is only supported for the FAST version with FEATURES enabled"
+
+#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)
+    #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)
+        #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"
+    #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)
+    #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)
+    #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)
+        #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)
+    #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)
+        #error "Configuration Not implemented"
+    #endif
 #endif
 
+#if SLOW
+    #if FEATURES
+        #define SetRoot_Rosenfeld(D, r, eps, alpha, F) SetRoot_Features_Rosenfeld_Dist(D, r, eps, alpha, F)
+    #else
+        #define SetRoot_Rosenfeld(D, r, eps, alpha, F) SetRoot_Rosenfeld_Dist(D, r, eps, alpha)
+    #endif
+    #if PARMERGE
+        #error "Configuration SLOW and PARMERGE Not implemented"
+    #endif
+    #if ARSP
+        #error "Configuration SLOW and ARSP Not implemented"
+    #endif
+#endif
+
+// Verbose level
+// 0 : No trace at all
+// 1 : Traces compatible with execution times measurements,
+//     in particular, there must not be any traces in the
+//     "compute" sections
+// 2 : Standard level
+// 3 : Maximum (debug) level
+#define MCA_VERBOSE_LEVEL 2
+
+#endif // __CONFIG_H__
+
+
Index: soft/giet_vm/applications/rosenfeld/include/ecc_features.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/include/ecc_features.h	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/include/ecc_features.h	(revision 822)
@@ -25,19 +25,27 @@
 // ------------------------------------------------------------------------
 
+// @QM
+// Je m'autorise Ã  mettre des champs de la structure
+// conditionnellement vis-Ã -vis de flags, car :
+// 1. Il ne s'agit pas d'une bibliothÃšque
+// 2. Tous les fichiers .c dÃ©pendent de tous les .h, et donc
+//    en particulier du fichier config.h qui dÃ©finit les flags
+// Il est donc impossible de mÃ©langer deux fichiers binaires
+// qui ont des dÃ©finitions diffÃ©rentes de cette structure
 typedef struct {
-
-  uint16  xmin;
-  uint16  xmax;
-  uint16  ymin;
-  uint16  ymax;
-
-  uint32  S;
-
-  uint32  Sx;
-  uint32  Sy;
+#if FEATURES
+  uint16 xmin;
+  uint16 xmax;
+  uint16 ymin;
+  uint16 ymax;
+
+  uint32 S;
+
+  uint32 Sx;
+  uint32 Sy;
+#endif
 #if PARMERGE
   pthread_spinlock_t lock;
 #endif
-
 } RegionStats;
 
@@ -210,7 +218,4 @@
 int RegionStatsVector_Match  (RegionStats *S1, int i0, int i1, RegionStats *S2, int j0, int j1);
 
-#ifdef __cplusplus
-}
-#endif
 
 #endif /* __FEATURES_H__ */
Index: soft/giet_vm/applications/rosenfeld/include/mca.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/include/mca.h	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/include/mca.h	(revision 822)
@@ -26,43 +26,42 @@
 
 
-// QM : using mutex lock instead of mutexlock,
-// because apparently mutexlocks cause a bug in valgrind
+// QM : using mutex lock instead of spinlock,
+// because apparently spinlocks cause a bug in valgrind
 // (solved but the installed version is not recent enough)
 // cf. https://bugs.kde.org/show_bug.cgi?id=336435
 pthread_mutex_t print_lock;
 
-#define MCA_VERBOSE0(X) ({                 \
+
+
+
+#if MCA_VERBOSE_LEVEL >= 1
+    #define MCA_VERBOSE1(X) ({             \
         pthread_mutex_lock(&print_lock);   \
         X;                                 \
         pthread_mutex_unlock(&print_lock); \
         })
-#define MCA_VERBOSE1(X) ({                 \
+#else
+    #define MCA_VERBOSE1(X)
+#endif
+
+#if MCA_VERBOSE_LEVEL >= 2
+    #define MCA_VERBOSE2(X) ({             \
         pthread_mutex_lock(&print_lock);   \
         X;                                 \
         pthread_mutex_unlock(&print_lock); \
         })
-#define MCA_DISPLAY0(X) ({                 \
+#else
+    #define MCA_VERBOSE2(X)
+#endif
+
+#if MCA_VERBOSE_LEVEL >= 3
+    #define MCA_VERBOSE3(X) ({             \
         pthread_mutex_lock(&print_lock);   \
         X;                                 \
         pthread_mutex_unlock(&print_lock); \
         })
-#define MCA_DISPLAY1(X) ({                 \
-        pthread_mutex_lock(&print_lock);   \
-        X;                                 \
-        pthread_mutex_unlock(&print_lock); \
-        })
-
-
-#define MCA_VERBOSE2(X)
-/*
-#define MCA_VERBOSE2(X) ({                 \
-        pthread_mutex_lock(&print_lock);   \
-        X;                                 \
-        pthread_mutex_unlock(&print_lock); \
-        })
-*/
-
-#define MCA_DISPLAY2(X) 
-
+#else
+    #define MCA_VERBOSE3(X)
+#endif
 
 
Index: soft/giet_vm/applications/rosenfeld/nrc2/Makefile
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/Makefile	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/nrc2/Makefile	(revision 822)
@@ -7,5 +7,6 @@
 
 # -- File list ----------
-FILE = nralloc1.c, nralloc2.c, nralloc2x.c, nrarith0.c, nrarith1.c, nrarith2.c, nrarith2x.c, nrbool1.c, nrbool2.c, nrhisto.c, nrio0.c, nrio1.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 = 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
 
 
@@ -16,4 +17,7 @@
 OBJ_PATH = obj
 INC_PATH = include
+PRODUCT = libnrc2x.a
+
+all: checktarget $(PRODUCT)
 
 ifeq ($(TARGET),giet-vm)
@@ -36,4 +40,10 @@
 CFLAGSCPU := -mips32 -EL -G0 -mhard-float
 
+checktarget:
+	@if [ -f $(PRODUCT) ] && objdump -f $(PRODUCT) | grep "little" > /dev/null ; then \
+		echo -ne "" ; \
+	else \
+		rm -f $(OBJS) $(PRODUCT) ;\
+	fi
 endif
 
@@ -50,4 +60,11 @@
 C_CONFIG_FLAGS = -DCLI
 C_INC_FLAGS = -I$(INC_PATH)
+
+checktarget:
+	@if [ -f $(PRODUCT) ] && objdump -f  $(PRODUCT) | grep "86" > /dev/null ; then \
+		echo -ne "" ; \
+	else \
+		rm -f $(OBJS) $(PRODUCT) ;\
+	fi
 
 endif
@@ -66,11 +83,9 @@
 
 
-PRODUCT = libnrc2x.a
 
 OBJS = $(addprefix $(OBJ_PATH)/, $(addsuffix .o, $(basename $(FILE))))
 
-all: $(PRODUCT)
 
-$(OBJ_PATH)/%.o: $(SRC_PATH)/%.c
+$(OBJ_PATH)/%.o: $(SRC_PATH)/%.c $(INC_PATH)/*.h
 	$(CC) -c $(CFLAGS) -o $@ $<
 
Index: soft/giet_vm/applications/rosenfeld/nrc2/include/nrbool1.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/include/nrbool1.h	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/nrc2/include/nrbool1.h	(revision 822)
@@ -11,18 +11,8 @@
 #define _NR_BOOL1_H_
 
-#ifdef __cplusplus
-#ifdef PRAGMA_VERBOSE
-#pragma message ("C++")
-#endif
-extern "C" {
-#endif
 
-#ifdef PRAGMA_VERBOSE
-//#pragma message("- include nrbool1.h")
-#endif
-
-/* ========================= */
-/* === Logical operation === */
-/* ========================= */
+/* ========================== */
+/* === Logical operations === */
+/* ========================== */
 
 /* ----------- */
@@ -30,15 +20,19 @@
 /* ----------- */
 /* Y = ! Y */
-IMAGE_EXPORT(void) not_bvector    (byte   *X, long ncl, long nch, byte   *Y);
-IMAGE_EXPORT(void) not_si8vector  (sint8  *X, long ncl, long nch, sint8  *Y);
-IMAGE_EXPORT(void) not_ui8vector  (uint8  *X, long ncl, long nch, uint8  *Y);
-IMAGE_EXPORT(void) not_si16vector (sint16 *X, long ncl, long nch, sint16 *Y);
-IMAGE_EXPORT(void) not_ui16vector (uint16 *X, long ncl, long nch, uint16 *Y);
-IMAGE_EXPORT(void) not_si32vector (sint32 *X, long ncl, long nch, sint32 *Y);
-IMAGE_EXPORT(void) not_ui32vector (uint32 *X, long ncl, long nch, uint32 *Y);
-IMAGE_EXPORT(void) not_si64vector (sint64 *X, long ncl, long nch, sint64 *Y);
-IMAGE_EXPORT(void) not_ui64vector (uint64 *X, long ncl, long nch, uint64 *Y);
-IMAGE_EXPORT(void) not_rgb8vector (rgb8   *X, long ncl, long nch, rgb8   *Y);
-IMAGE_EXPORT(void) not_rgbx8vector(rgbx8  *X, long ncl, long nch, rgbx8  *Y);
+
+#define not_type_vector(t) \
+void short_name(t,not_,vector)(t * X, int32_t ncl, int32_t nch, t * Y)
+
+not_type_vector(int8_t);
+not_type_vector(uint8_t);
+not_type_vector(int16_t);
+not_type_vector(uint16_t);
+not_type_vector(int32_t);
+not_type_vector(uint32_t);
+not_type_vector(int64_t);
+not_type_vector(uint64_t);
+not_type_vector(rgb8);
+not_type_vector(rgbx8);
+
 
 /* ---------- */
@@ -47,27 +41,19 @@
 /* Z = X | Y */
 
-IMAGE_EXPORT(void) or_bvector    (byte   *X, long ncl, long nch, byte   *Y, byte    *Z);
-IMAGE_EXPORT(void) or_si8vector  (sint8  *X, long ncl, long nch, sint8  *Y, sint8   *Z);
-IMAGE_EXPORT(void) or_ui8vector  (uint8  *X, long ncl, long nch, uint8  *Y, uint8   *Z);
-IMAGE_EXPORT(void) or_si16vector (sint16 *X, long ncl, long nch, sint16 *Y, sint16  *Z);
-IMAGE_EXPORT(void) or_ui16vector (uint16 *X, long ncl, long nch, uint16 *Y, uint16  *Z);
-IMAGE_EXPORT(void) or_si32vector (sint32 *X, long ncl, long nch, sint32 *Y, sint32  *Z);
-IMAGE_EXPORT(void) or_ui32vector (uint32 *X, long ncl, long nch, uint32 *Y, uint32  *Z);
-IMAGE_EXPORT(void) or_si64vector (sint64 *X, long ncl, long nch, sint64 *Y, sint64  *Z);
-IMAGE_EXPORT(void) or_ui64vector (uint64 *X, long ncl, long nch, uint64 *Y, uint64  *Z);
-IMAGE_EXPORT(void) or_rgb8vector (rgb8   *X, long ncl, long nch, rgb8   *Y, rgb8    *Z);
-IMAGE_EXPORT(void) or_rgbx8vector(rgbx8  *X, long ncl, long nch, rgbx8  *Y, rgbx8   *Z);
+#define or_type_vector(t) \
+void short_name(t,or_,vector)(t * X, int32_t ncl, int32_t nch, t * Y, t * Z); \
+void short_name(t,orc_,vector)(t * X, int32_t ncl, int32_t nch, t y, t * Z)
 
-IMAGE_EXPORT(void) orc_bvector    (byte   *X, long ncl, long nch, byte   y, byte    *Z);
-IMAGE_EXPORT(void) orc_si8vector  (sint8  *X, long ncl, long nch, sint8  y, sint8   *Z);
-IMAGE_EXPORT(void) orc_ui8vector  (uint8  *X, long ncl, long nch, uint8  y, uint8   *Z);
-IMAGE_EXPORT(void) orc_si16vector (sint16 *X, long ncl, long nch, sint16 y, sint16  *Z);
-IMAGE_EXPORT(void) orc_ui16vector (uint16 *X, long ncl, long nch, uint16 y, uint16  *Z);
-IMAGE_EXPORT(void) orc_si32vector (sint32 *X, long ncl, long nch, sint32 y, sint32  *Z);
-IMAGE_EXPORT(void) orc_ui32vector (uint32 *X, long ncl, long nch, uint32 y, uint32  *Z);
-IMAGE_EXPORT(void) orc_si64vector (sint64 *X, long ncl, long nch, sint64 y, sint64  *Z);
-IMAGE_EXPORT(void) orc_ui64vector (uint64 *X, long ncl, long nch, uint64 y, uint64  *Z);
-IMAGE_EXPORT(void) orc_rgb8vector (rgb8   *X, long ncl, long nch, rgb8   y, rgb8    *Z);
-IMAGE_EXPORT(void) orc_rgbx8vector(rgbx8  *X, long ncl, long nch, rgbx8  y, rgbx8   *Z);
+or_type_vector(int8_t);
+or_type_vector(uint8_t);
+or_type_vector(int16_t);
+or_type_vector(uint16_t);
+or_type_vector(int32_t);
+or_type_vector(uint32_t);
+or_type_vector(int64_t);
+or_type_vector(uint64_t);
+or_type_vector(rgb8);
+or_type_vector(rgbx8);
+
 
 /* ----------- */
@@ -76,27 +62,19 @@
 /* Z = X ^ Y */
 
-IMAGE_EXPORT(void) xor_bvector    (byte   *X, long ncl, long nch, byte   *Y, byte    *Z);
-IMAGE_EXPORT(void) xor_si8vector  (sint8  *X, long ncl, long nch, sint8  *Y, sint8   *Z);
-IMAGE_EXPORT(void) xor_ui8vector  (uint8  *X, long ncl, long nch, uint8  *Y, uint8   *Z);
-IMAGE_EXPORT(void) xor_si16vector (sint16 *X, long ncl, long nch, sint16 *Y, sint16  *Z);
-IMAGE_EXPORT(void) xor_ui16vector (uint16 *X, long ncl, long nch, uint16 *Y, uint16  *Z);
-IMAGE_EXPORT(void) xor_si32vector (sint32 *X, long ncl, long nch, sint32 *Y, sint32  *Z);
-IMAGE_EXPORT(void) xor_ui32vector (uint32 *X, long ncl, long nch, uint32 *Y, uint32  *Z);
-IMAGE_EXPORT(void) xor_si64vector (sint64 *X, long ncl, long nch, sint64 *Y, sint64  *Z);
-IMAGE_EXPORT(void) xor_ui64vector (uint64 *X, long ncl, long nch, uint64 *Y, uint64  *Z);
-IMAGE_EXPORT(void) xor_rgb8vector (rgb8   *X, long ncl, long nch, rgb8   *Y, rgb8    *Z);
-IMAGE_EXPORT(void) xor_rgbx8vector(rgbx8  *X, long ncl, long nch, rgbx8  *Y, rgbx8   *Z);
+#define xor_type_vector(t) \
+void short_name(t,xor_,vector)(t * X, int32_t ncl, int32_t nch, t * Y, t * Z); \
+void short_name(t,xorc_,vector)(t * X, int32_t ncl, int32_t nch, t y, t * Z)
 
-IMAGE_EXPORT(void) xorc_bvector    (byte   *X, long ncl, long nch, byte   y, byte    *Z);
-IMAGE_EXPORT(void) xorc_si8vector  (sint8  *X, long ncl, long nch, sint8  y, sint8   *Z);
-IMAGE_EXPORT(void) xorc_ui8vector  (uint8  *X, long ncl, long nch, uint8  y, uint8   *Z);
-IMAGE_EXPORT(void) xorc_si16vector (sint16 *X, long ncl, long nch, sint16 y, sint16  *Z);
-IMAGE_EXPORT(void) xorc_ui16vector (uint16 *X, long ncl, long nch, uint16 y, uint16  *Z);
-IMAGE_EXPORT(void) xorc_si32vector (sint32 *X, long ncl, long nch, sint32 y, sint32  *Z);
-IMAGE_EXPORT(void) xorc_ui32vector (uint32 *X, long ncl, long nch, uint32 y, uint32  *Z);
-IMAGE_EXPORT(void) xorc_si64vector (sint64 *X, long ncl, long nch, sint64 y, sint64  *Z);
-IMAGE_EXPORT(void) xorc_ui64vector (uint64 *X, long ncl, long nch, uint64 y, uint64  *Z);
-IMAGE_EXPORT(void) xorc_rgb8vector (rgb8   *X, long ncl, long nch, rgb8   y, rgb8    *Z);
-IMAGE_EXPORT(void) xorc_rgbx8vector(rgbx8  *X, long ncl, long nch, rgbx8  y, rgbx8   *Z);
+xor_type_vector(int8_t);
+xor_type_vector(uint8_t);
+xor_type_vector(int16_t);
+xor_type_vector(uint16_t);
+xor_type_vector(int32_t);
+xor_type_vector(uint32_t);
+xor_type_vector(int64_t);
+xor_type_vector(uint64_t);
+xor_type_vector(rgb8);
+xor_type_vector(rgbx8);
+
 
 /* ----------- */
@@ -105,32 +83,29 @@
 /* Z = X & Y */
 
-IMAGE_EXPORT(void) and_bvector    (byte   *X, long ncl, long nch, byte   *Y, byte    *Z);
-IMAGE_EXPORT(void) and_si8vector  (sint8  *X, long ncl, long nch, sint8  *Y, sint8   *Z);
-IMAGE_EXPORT(void) and_ui8vector  (uint8  *X, long ncl, long nch, uint8  *Y, uint8   *Z);
-IMAGE_EXPORT(void) and_si16vector (sint16 *X, long ncl, long nch, sint16 *Y, sint16  *Z);
-IMAGE_EXPORT(void) and_ui16vector (uint16 *X, long ncl, long nch, uint16 *Y, uint16  *Z);
-IMAGE_EXPORT(void) and_si32vector (sint32 *X, long ncl, long nch, sint32 *Y, sint32  *Z);
-IMAGE_EXPORT(void) and_ui32vector (uint32 *X, long ncl, long nch, uint32 *Y, uint32  *Z);
-IMAGE_EXPORT(void) and_si64vector (sint64 *X, long ncl, long nch, sint64 *Y, sint64  *Z);
-IMAGE_EXPORT(void) and_ui64vector (uint64 *X, long ncl, long nch, uint64 *Y, uint64  *Z);
-IMAGE_EXPORT(void) and_rgb8vector (rgb8   *X, long ncl, long nch, rgb8   *Y, rgb8    *Z);
-IMAGE_EXPORT(void) and_rgbx8vector(rgbx8  *X, long ncl, long nch, rgbx8  *Y, rgbx8   *Z);
+#define and_type_vector(t) \
+void short_name(t,and_,vector)(t * X, int32_t ncl, int32_t nch, t * Y, t * Z); \
+void short_name(t,andc_,vector)(t * X, int32_t ncl, int32_t nch, t y, t * Z)
 
-IMAGE_EXPORT(void) andc_bvector    (byte   *X, long ncl, long nch, byte   y, byte    *Z);
-IMAGE_EXPORT(void) andc_si8vector  (sint8  *X, long ncl, long nch, sint8  y, sint8   *Z);
-IMAGE_EXPORT(void) andc_ui8vector  (uint8  *X, long ncl, long nch, uint8  y, uint8   *Z);
-IMAGE_EXPORT(void) andc_si16vector (sint16 *X, long ncl, long nch, sint16 y, sint16  *Z);
-IMAGE_EXPORT(void) andc_ui16vector (uint16 *X, long ncl, long nch, uint16 y, uint16  *Z);
-IMAGE_EXPORT(void) andc_si32vector (sint32 *X, long ncl, long nch, sint32 y, sint32  *Z);
-IMAGE_EXPORT(void) andc_ui32vector (uint32 *X, long ncl, long nch, uint32 y, uint32  *Z);
-IMAGE_EXPORT(void) andc_si64vector (sint64 *X, long ncl, long nch, sint64 y, sint64  *Z);
-IMAGE_EXPORT(void) andc_ui64vector (uint64 *X, long ncl, long nch, uint64 y, uint64  *Z);
-IMAGE_EXPORT(void) andc_rgb8vector (rgb8   *X, long ncl, long nch, rgb8   y, rgb8    *Z);
-IMAGE_EXPORT(void) andc_rgbx8vector(rgbx8  *X, long ncl, long nch, rgbx8  y, rgbx8   *Z);
+and_type_vector(int8_t);
+and_type_vector(uint8_t);
+and_type_vector(int16_t);
+and_type_vector(uint16_t);
+and_type_vector(int32_t);
+and_type_vector(uint32_t);
+and_type_vector(int64_t);
+and_type_vector(uint64_t);
+and_type_vector(rgb8);
+and_type_vector(rgbx8);
 
 
-#ifdef __cplusplus
-}
-#endif
+#endif // _NR_BOOL1_H_
 
-#endif // _NR_BOOL1_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/nrbool2.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/include/nrbool2.h	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/nrc2/include/nrbool2.h	(revision 822)
@@ -11,22 +11,18 @@
 #define _NR_BOOL2_H_
 
-#ifdef __cplusplus
-#ifdef PRAGMA_VERBOSE
-#pragma message ("C++")
-#endif
-extern "C" {
-#endif
+#include "nrc_os_config.h"
 
-#ifdef PRAGMA_VERBOSE
-//#pragma message("- include nrbool2.h")
-#endif
 
-IMAGE_EXPORT(int) cmpeq_bmatrix(byte **X, long nrl,long nrh,long ncl, long nch, byte **Y);
-IMAGE_EXPORT(int) cmpeq_si8matrix(sint8 **X, long nrl,long nrh,long ncl, long nch, sint8 **Y);
-IMAGE_EXPORT(int) cmpeq_ui8matrix(uint8 **X, long nrl,long nrh,long ncl, long nch, uint8 **Y);
-IMAGE_EXPORT(int) cmpeq_si16matrix(sint16 **X, long nrl,long nrh,long ncl, long nch, sint16 **Y);
-IMAGE_EXPORT(int) cmpeq_ui16matrix(uint16 **X, long nrl, long nrh, long ncl, long nch, uint16 **Y);
-IMAGE_EXPORT(int) cmpeq_si32matrix(sint32 **X, long nrl, long nrh, long ncl, long nch, sint32 **Y);
-IMAGE_EXPORT(int) cmpeq_ui32matrix(uint32 **X, long nrl, long nrh, long ncl, long nch, uint32 **Y);
+#define cmpeq_type_matrix(t) \
+int32_t short_name(t,cmpeq_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t ** Y)
+
+cmpeq_type_matrix(int8_t);
+cmpeq_type_matrix(uint8_t);
+cmpeq_type_matrix(int16_t);
+cmpeq_type_matrix(uint16_t);
+cmpeq_type_matrix(int32_t);
+cmpeq_type_matrix(uint32_t);
+cmpeq_type_matrix(int64_t);
+cmpeq_type_matrix(uint64_t);
 
 
@@ -37,15 +33,18 @@
  */
 
-IMAGE_EXPORT(void) not_bmatrix    (byte   **X, long nrl,long nrh,long ncl, long nch, byte   **Y);
-IMAGE_EXPORT(void) not_si8matrix  (sint8  **X, long nrl,long nrh,long ncl, long nch, sint8  **Y);
-IMAGE_EXPORT(void) not_ui8matrix  (uint8  **X, long nrl,long nrh,long ncl, long nch, uint8  **Y);
-IMAGE_EXPORT(void) not_si16matrix (sint16 **X, long nrl,long nrh,long ncl, long nch, sint16 **Y);
-IMAGE_EXPORT(void) not_ui16matrix (uint16 **X, long nrl,long nrh,long ncl, long nch, uint16 **Y);
-IMAGE_EXPORT(void) not_si32matrix (sint32 **X, long nrl,long nrh,long ncl, long nch, sint32 **Y);
-IMAGE_EXPORT(void) not_ui32matrix (uint32 **X, long nrl,long nrh,long ncl, long nch, uint32 **Y);
-IMAGE_EXPORT(void) not_si64matrix (sint64 **X, long nrl,long nrh,long ncl, long nch, sint64 **Y);
-IMAGE_EXPORT(void) not_ui64matrix (uint64 **X, long nrl,long nrh,long ncl, long nch, uint64 **Y);
-IMAGE_EXPORT(void) not_rgb8matrix (rgb8   **X, long nrl,long nrh,long ncl, long nch, rgb8   **Y);
-IMAGE_EXPORT(void) not_rgbx8matrix(rgbx8  **X, long nrl,long nrh,long ncl, long nch, rgbx8  **Y);
+#define not_type_matrix(t) \
+void short_name(t,not_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t ** Y)
+
+not_type_matrix(int8_t);
+not_type_matrix(uint8_t);
+not_type_matrix(int16_t);
+not_type_matrix(uint16_t);
+not_type_matrix(int32_t);
+not_type_matrix(uint32_t);
+not_type_matrix(int64_t);
+not_type_matrix(uint64_t);
+not_type_matrix(rgb8);
+not_type_matrix(rgbx8);
+
 
 /*
@@ -55,27 +54,19 @@
  */
 
-IMAGE_EXPORT(void) or_bmatrix    (byte   **X, long nrl,long nrh,long ncl, long nch, byte   **Y, byte    **Z);
-IMAGE_EXPORT(void) or_si8matrix  (sint8  **X, long nrl,long nrh,long ncl, long nch, sint8  **Y, sint8   **Z);
-IMAGE_EXPORT(void) or_ui8matrix  (uint8  **X, long nrl,long nrh,long ncl, long nch, uint8  **Y, uint8   **Z);
-IMAGE_EXPORT(void) or_si16matrix (sint16 **X, long nrl,long nrh,long ncl, long nch, sint16 **Y, sint16  **Z);
-IMAGE_EXPORT(void) or_ui16matrix (uint16 **X, long nrl,long nrh,long ncl, long nch, uint16 **Y, uint16  **Z);
-IMAGE_EXPORT(void) or_si32matrix (sint32 **X, long nrl,long nrh,long ncl, long nch, sint32 **Y, sint32  **Z);
-IMAGE_EXPORT(void) or_ui32matrix (uint32 **X, long nrl,long nrh,long ncl, long nch, uint32 **Y, uint32  **Z);
-IMAGE_EXPORT(void) or_si64matrix (sint64 **X, long nrl,long nrh,long ncl, long nch, sint64 **Y, sint64  **Z);
-IMAGE_EXPORT(void) or_ui64matrix (uint64 **X, long nrl,long nrh,long ncl, long nch, uint64 **Y, uint64  **Z);
-IMAGE_EXPORT(void) or_rgb8matrix (rgb8   **X, long nrl,long nrh,long ncl, long nch, rgb8   **Y, rgb8    **Z);
-IMAGE_EXPORT(void) or_rgbx8matrix(rgbx8  **X, long nrl,long nrh,long ncl, long nch, rgbx8  **Y, rgbx8   **Z);
+#define or_type_matrix(t) \
+void short_name(t,or_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t ** Y, t ** Z); \
+void short_name(t,orc_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t y, t ** Z)
 
-IMAGE_EXPORT(void) orc_bmatrix    (byte   **X, long nrl,long nrh,long ncl, long nch, byte   y, byte    **Z);
-IMAGE_EXPORT(void) orc_si8matrix  (sint8  **X, long nrl,long nrh,long ncl, long nch, sint8  y, sint8   **Z);
-IMAGE_EXPORT(void) orc_ui8matrix  (uint8  **X, long nrl,long nrh,long ncl, long nch, uint8  y, uint8   **Z);
-IMAGE_EXPORT(void) orc_si16matrix (sint16 **X, long nrl,long nrh,long ncl, long nch, sint16 y, sint16  **Z);
-IMAGE_EXPORT(void) orc_ui16matrix (uint16 **X, long nrl,long nrh,long ncl, long nch, uint16 y, uint16  **Z);
-IMAGE_EXPORT(void) orc_si32matrix (sint32 **X, long nrl,long nrh,long ncl, long nch, sint32 y, sint32  **Z);
-IMAGE_EXPORT(void) orc_ui32matrix (uint32 **X, long nrl,long nrh,long ncl, long nch, uint32 y, uint32  **Z);
-IMAGE_EXPORT(void) orc_si64matrix (sint64 **X, long nrl,long nrh,long ncl, long nch, sint64 y, sint64  **Z);
-IMAGE_EXPORT(void) orc_ui64matrix (uint64 **X, long nrl,long nrh,long ncl, long nch, uint64 y, uint64  **Z);
-IMAGE_EXPORT(void) orc_rgb8matrix (rgb8   **X, long nrl,long nrh,long ncl, long nch, rgb8   y, rgb8    **Z);
-IMAGE_EXPORT(void) orc_rgbx8matrix(rgbx8  **X, long nrl,long nrh,long ncl, long nch, rgbx8  y, rgbx8   **Z);
+or_type_matrix(int8_t);
+or_type_matrix(uint8_t);
+or_type_matrix(int16_t);
+or_type_matrix(uint16_t);
+or_type_matrix(int32_t);
+or_type_matrix(uint32_t);
+or_type_matrix(int64_t);
+or_type_matrix(uint64_t);
+or_type_matrix(rgb8);
+or_type_matrix(rgbx8);
+
 
 /*
@@ -85,61 +76,51 @@
  */
 
-IMAGE_EXPORT(void) xor_bmatrix    (byte   **X, long nrl,long nrh,long ncl, long nch, byte   **Y, byte    **Z);
-IMAGE_EXPORT(void) xor_si8matrix  (sint8  **X, long nrl,long nrh,long ncl, long nch, sint8  **Y, sint8   **Z);
-IMAGE_EXPORT(void) xor_ui8matrix  (uint8  **X, long nrl,long nrh,long ncl, long nch, uint8  **Y, uint8   **Z);
-IMAGE_EXPORT(void) xor_si16matrix (sint16 **X, long nrl,long nrh,long ncl, long nch, sint16 **Y, sint16  **Z);
-IMAGE_EXPORT(void) xor_ui16matrix (uint16 **X, long nrl,long nrh,long ncl, long nch, uint16 **Y, uint16  **Z);
-IMAGE_EXPORT(void) xor_si32matrix (sint32 **X, long nrl,long nrh,long ncl, long nch, sint32 **Y, sint32  **Z);
-IMAGE_EXPORT(void) xor_ui32matrix (uint32 **X, long nrl,long nrh,long ncl, long nch, uint32 **Y, uint32  **Z);
-IMAGE_EXPORT(void) xor_si64matrix (sint64 **X, long nrl,long nrh,long ncl, long nch, sint64 **Y, sint64  **Z);
-IMAGE_EXPORT(void) xor_ui64matrix (uint64 **X, long nrl,long nrh,long ncl, long nch, uint64 **Y, uint64  **Z);
-IMAGE_EXPORT(void) xor_rgb8matrix (rgb8   **X, long nrl,long nrh,long ncl, long nch, rgb8   **Y, rgb8    **Z);
-IMAGE_EXPORT(void) xor_rgbx8matrix(rgbx8  **X, long nrl,long nrh,long ncl, long nch, rgbx8  **Y, rgbx8   **Z);
+#define xor_type_matrix(t) \
+void short_name(t,xor_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t ** Y, t ** Z); \
+void short_name(t,xorc_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t y, t ** Z)
 
-IMAGE_EXPORT(void) xorc_bmatrix    (byte   **X, long nrl,long nrh,long ncl, long nch, byte   y, byte    **Z);
-IMAGE_EXPORT(void) xorc_si8matrix  (sint8  **X, long nrl,long nrh,long ncl, long nch, sint8  y, sint8   **Z);
-IMAGE_EXPORT(void) xorc_ui8matrix  (uint8  **X, long nrl,long nrh,long ncl, long nch, uint8  y, uint8   **Z);
-IMAGE_EXPORT(void) xorc_si16matrix (sint16 **X, long nrl,long nrh,long ncl, long nch, sint16 y, sint16  **Z);
-IMAGE_EXPORT(void) xorc_ui16matrix (uint16 **X, long nrl,long nrh,long ncl, long nch, uint16 y, uint16  **Z);
-IMAGE_EXPORT(void) xorc_si32matrix (sint32 **X, long nrl,long nrh,long ncl, long nch, sint32 y, sint32  **Z);
-IMAGE_EXPORT(void) xorc_ui32matrix (uint32 **X, long nrl,long nrh,long ncl, long nch, uint32 y, uint32  **Z);
-IMAGE_EXPORT(void) xorc_si64matrix (sint64 **X, long nrl,long nrh,long ncl, long nch, sint64 y, sint64  **Z);
-IMAGE_EXPORT(void) xorc_ui64matrix (uint64 **X, long nrl,long nrh,long ncl, long nch, uint64 y, uint64  **Z);
-IMAGE_EXPORT(void) xorc_rgb8matrix (rgb8   **X, long nrl,long nrh,long ncl, long nch, rgb8   y, rgb8    **Z);
-IMAGE_EXPORT(void) xorc_rgbx8matrix(rgbx8  **X, long nrl,long nrh,long ncl, long nch, rgbx8  y, rgbx8   **Z);
+xor_type_matrix(int8_t);
+xor_type_matrix(uint8_t);
+xor_type_matrix(int16_t);
+xor_type_matrix(uint16_t);
+xor_type_matrix(int32_t);
+xor_type_matrix(uint32_t);
+xor_type_matrix(int64_t);
+xor_type_matrix(uint64_t);
+xor_type_matrix(rgb8);
+xor_type_matrix(rgbx8);
+
 
 /*
- * -----------
+ * ----------
  * --- And ---
- * -----------
+ * ----------
  */
 
-IMAGE_EXPORT(void) and_bmatrix    (byte   **X, long nrl,long nrh,long ncl, long nch, byte   **Y, byte    **Z);
-IMAGE_EXPORT(void) and_si8matrix  (sint8  **X, long nrl,long nrh,long ncl, long nch, sint8  **Y, sint8   **Z);
-IMAGE_EXPORT(void) and_ui8matrix  (uint8  **X, long nrl,long nrh,long ncl, long nch, uint8  **Y, uint8   **Z);
-IMAGE_EXPORT(void) and_si16matrix (sint16 **X, long nrl,long nrh,long ncl, long nch, sint16 **Y, sint16  **Z);
-IMAGE_EXPORT(void) and_ui16matrix (uint16 **X, long nrl,long nrh,long ncl, long nch, uint16 **Y, uint16  **Z);
-IMAGE_EXPORT(void) and_si32matrix (sint32 **X, long nrl,long nrh,long ncl, long nch, sint32 **Y, sint32  **Z);
-IMAGE_EXPORT(void) and_ui32matrix (uint32 **X, long nrl,long nrh,long ncl, long nch, uint32 **Y, uint32  **Z);
-IMAGE_EXPORT(void) and_si64matrix (sint64 **X, long nrl,long nrh,long ncl, long nch, sint64 **Y, sint64  **Z);
-IMAGE_EXPORT(void) and_ui64matrix (uint64 **X, long nrl,long nrh,long ncl, long nch, uint64 **Y, uint64  **Z);
-IMAGE_EXPORT(void) and_rgb8matrix (rgb8   **X, long nrl,long nrh,long ncl, long nch, rgb8   **Y, rgb8    **Z);
-IMAGE_EXPORT(void) and_rgbx8matrix(rgbx8  **X, long nrl,long nrh,long ncl, long nch, rgbx8  **Y, rgbx8   **Z);
+#define and_type_matrix(t) \
+void short_name(t,and_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t ** Y, t ** Z); \
+void short_name(t,andc_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t y, t ** Z)
 
-IMAGE_EXPORT(void) andc_bmatrix    (byte   **X, long nrl,long nrh,long ncl, long nch, byte   y, byte    **Z);
-IMAGE_EXPORT(void) andc_si8matrix  (sint8  **X, long nrl,long nrh,long ncl, long nch, sint8  y, sint8   **Z);
-IMAGE_EXPORT(void) andc_ui8matrix  (uint8  **X, long nrl,long nrh,long ncl, long nch, uint8  y, uint8   **Z);
-IMAGE_EXPORT(void) andc_si16matrix (sint16 **X, long nrl,long nrh,long ncl, long nch, sint16 y, sint16  **Z);
-IMAGE_EXPORT(void) andc_ui16matrix (uint16 **X, long nrl,long nrh,long ncl, long nch, uint16 y, uint16  **Z);
-IMAGE_EXPORT(void) andc_si32matrix (sint32 **X, long nrl,long nrh,long ncl, long nch, sint32 y, sint32  **Z);
-IMAGE_EXPORT(void) andc_ui32matrix (uint32 **X, long nrl,long nrh,long ncl, long nch, uint32 y, uint32  **Z);
-IMAGE_EXPORT(void) andc_si64matrix (sint64 **X, long nrl,long nrh,long ncl, long nch, sint64 y, sint64  **Z);
-IMAGE_EXPORT(void) andc_ui64matrix (uint64 **X, long nrl,long nrh,long ncl, long nch, uint64 y, uint64  **Z);
-IMAGE_EXPORT(void) andc_rgb8matrix (rgb8   **X, long nrl,long nrh,long ncl, long nch, rgb8   y, rgb8    **Z);
-IMAGE_EXPORT(void) andc_rgbx8matrix(rgbx8  **X, long nrl,long nrh,long ncl, long nch, rgbx8  y, rgbx8   **Z);
+and_type_matrix(int8_t);
+and_type_matrix(uint8_t);
+and_type_matrix(int16_t);
+and_type_matrix(uint16_t);
+and_type_matrix(int32_t);
+and_type_matrix(uint32_t);
+and_type_matrix(int64_t);
+and_type_matrix(uint64_t);
+and_type_matrix(rgb8);
+and_type_matrix(rgbx8);
 
-#ifdef __cplusplus
-}
-#endif
 
 #endif // _NR_BOOL2_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/nrio.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/include/nrio.h	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/nrc2/include/nrio.h	(revision 822)
@@ -11,13 +11,4 @@
 #define __NRIO_H__
 
-#ifdef __cplusplus
-#pragma message ("C++")
-extern "C" {
-#endif
-    
-#ifdef VERBOSE_PRAGMA
-//#pragma message ("- *** include nrio.h ***")
-#endif
-
 #include "nrio0.h"
 #include "nrio1.h"
@@ -25,7 +16,3 @@
 #include "nrio3.h"
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif // __NRIO_H__
Index: soft/giet_vm/applications/rosenfeld/nrc2/include/nrio0.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/include/nrio0.h	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/nrc2/include/nrio0.h	(revision 822)
@@ -11,27 +11,15 @@
 #define _NR_IO0_H_
 
-#ifdef __cplusplus
-#pragma message ("C++")
-extern "C" {
-#endif
-    
-#ifdef VERBOSE_PRAGMA
-//#pragma message ("- *** include nrio0.h ***")
-#endif
+void generate_filename_k_ndigit          (char * filename, int k, int ndigit,                   char * complete_filename, int maxlen);
+void generate_filename_k_ndigit_extension(char * filename, int k, int ndigit, char * extension, char * complete_filename, int maxlen);
 
-IMAGE_EXPORT(void) generate_filename_k_ndigit          (char *filename, int k, int ndigit,                  char *complete_filename, int maxlen);
-IMAGE_EXPORT(void) generate_filename_k_ndigit_extension(char *filename, int k, int ndigit, char *extension, char *complete_filename, int maxlen);
+void generate_path_filename                     (char * path, char * filename,                                             char * complete_filename, int maxlen);
+void generate_path_filename_extension           (char * path, char * filename,                           char * extension, char * complete_filename, int maxlen);
+void generate_path_filename_suffix_extension    (char * path, char * filename, char * suffix,            char * extension, char * complete_filename, int maxlen);
+void generate_path_filename_k_ndigit_extension  (char * path, char * filename, int k, int ndigit,        char * extension, char * complete_filename, int maxlen);
+void generate_path_filename_k_ndigit_l_extension(char * path, char * filename, int k, int ndigit, int l, char * extension, char * complete_filename, int maxlen);
 
-IMAGE_EXPORT(void) generate_path_filename                     (char *path, char *filename,                                            char *complete_filename, int maxlen);
-IMAGE_EXPORT(void) generate_path_filename_extension           (char *path, char *filename,                           char *extension, char *complete_filename, int maxlen);
-IMAGE_EXPORT(void) generate_path_filename_suffix_extension    (char *path, char *filename, char *suffix,             char *extension, char *complete_filename, int maxlen);
-IMAGE_EXPORT(void) generate_path_filename_k_ndigit_extension  (char *path, char *filename, int k, int ndigit,        char *extension, char *complete_filename, int maxlen);
-IMAGE_EXPORT(void) generate_path_filename_k_ndigit_l_extension(char *path, char *filename, int k, int ndigit, int l, char *extension, char *complete_filename, int maxlen);
+void select_display_positive_parameters(int iformat, char ** format, char ** str);
 
-void select_display_positive_parameters(int iformat, char **format, char **str);
-
-#ifdef __cplusplus
-}
-#endif
 
 #endif // _NR_IO0_H_
Index: soft/giet_vm/applications/rosenfeld/nrc2/include/nrio1.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/include/nrio1.h	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/nrc2/include/nrio1.h	(revision 822)
@@ -11,98 +11,29 @@
 #define _NR_IO1_H_
 
-#ifdef __cplusplus
-#pragma message ("C++")
-extern "C" {
-#endif
-    
-#ifdef VERBOSE_PRAGMA
-//#pragma message ("- *** include nrio1.h ***")
-#endif
-
 /*
- * ----------------------
- * --- display_vector ---
- * ----------------------
+ * -----------------------------------------------------------------------------------
+ * --- display_vector + display_vector_number + display_vector_T + vector_number_T ---
+ * -----------------------------------------------------------------------------------
  */
 
-IMAGE_EXPORT(void) display_bvector    (byte    *v, long nl,long nh, char *format, char *name);
-IMAGE_EXPORT(void) display_si8vector  (sint8   *v, long nl,long nh, char *format, char *name);
-IMAGE_EXPORT(void) display_ui8vector  (uint8   *v, long nl,long nh, char *format, char *name);
-IMAGE_EXPORT(void) display_si16vector (sint16  *v, long nl,long nh, char *format, char *name);
-IMAGE_EXPORT(void) display_ui16vector (uint16  *v, long nl,long nh, char *format, char *name);
-IMAGE_EXPORT(void) display_si32vector (sint32  *v, long nl,long nh, char *format, char *name);
-IMAGE_EXPORT(void) display_ui32vector (uint32  *v, long nl,long nh, char *format, char *name);
-IMAGE_EXPORT(void) display_si64vector (sint64  *v, long nl,long nh, char *format, char *name);
-IMAGE_EXPORT(void) display_ui64vector (uint64  *v, long nl,long nh, char *format, char *name);
+#define display_type_vector(t) \
+void short_name(t,display_,vector)(t * v, int32_t nl, int32_t nh, char * format, char * name); \
+void short_name(t,display_,vector_number)(t * v, int32_t nl, int32_t nh, char * format, char * name); \
+void short_name(t,display_,vector_T)(t * v, int32_t i0, int32_t i1, char * format, char * name); \
+void short_name(t,display_,vector_number_T)(t * v, int32_t i0, int32_t i1, char * format, char * name)
 
-IMAGE_EXPORT(void) display_f32vector  (float32 *v, long nl,long nh, char *format, char *name);
-IMAGE_EXPORT(void) display_f64vector  (float64 *v, long nl,long nh, char *format, char *name);
+display_type_vector(int8_t);
+display_type_vector(uint8_t);
+display_type_vector(int16_t);
+display_type_vector(uint16_t);
+display_type_vector(int32_t);
+display_type_vector(uint32_t);
+display_type_vector(int64_t);
+display_type_vector(uint64_t);
+display_type_vector(float);
+display_type_vector(double);
+display_type_vector(rgb8);
+display_type_vector(rgbx8);
 
-IMAGE_EXPORT(void) display_rgb8vector (rgb8    *v, long nl,long nh, char *format, char *name);
-IMAGE_EXPORT(void) display_rgbx8vector(rgbx8   *v, long nl,long nh, char *format, char *name);
-
-/*
- * -----------------------------
- * --- display_vector_number ---
- * -----------------------------
- */
-
-IMAGE_EXPORT(void) display_bvector_number    (byte    *v, long nl,long nh, char *format, char *name);
-IMAGE_EXPORT(void) display_si8vector_number  (sint8   *v, long nl,long nh, char *format, char *name);
-IMAGE_EXPORT(void) display_ui8vector_number  (uint8   *v, long nl,long nh, char *format, char *name);
-IMAGE_EXPORT(void) display_si16vector_number (sint16  *v, long nl,long nh, char *format, char *name);
-IMAGE_EXPORT(void) display_ui16vector_number (uint16  *v, long nl,long nh, char *format, char *name);
-IMAGE_EXPORT(void) display_si32vector_number (sint32  *v, long nl,long nh, char *format, char *name);
-IMAGE_EXPORT(void) display_ui32vector_number (uint32  *v, long nl,long nh, char *format, char *name);
-IMAGE_EXPORT(void) display_si64vector_number (sint64  *v, long nl,long nh, char *format, char *name);
-IMAGE_EXPORT(void) display_ui64vector_number (uint64  *v, long nl,long nh, char *format, char *name);
-
-IMAGE_EXPORT(void) display_f32vector_number  (float32 *v, long nl,long nh, char *format, char *name);
-IMAGE_EXPORT(void) display_f64vector_number  (float64 *v, long nl,long nh, char *format, char *name);
-
-IMAGE_EXPORT(void) display_rgb8vector_number (rgb8    *v, long nl,long nh, char *format, char *name);
-IMAGE_EXPORT(void) display_rgbx8vector_number(rgbx8   *v, long nl,long nh, char *format, char *name);
-
-/*
- * ------------------------
- * --- display_vector_T ---
- * ------------------------
- */
-
-IMAGE_EXPORT(void) display_si8vector_T  (sint8   *v,int i0, int i1, char *format, char *name);
-IMAGE_EXPORT(void) display_ui8vector_T  (uint8   *v,int i0, int i1, char *format, char *name);
-IMAGE_EXPORT(void) display_si16vector_T (sint16  *v,int i0, int i1, char *format, char *name);
-IMAGE_EXPORT(void) display_ui16vector_T (uint16  *v,int i0, int i1, char *format, char *name);
-IMAGE_EXPORT(void) display_si32vector_T (sint32  *v,int i0, int i1, char *format, char *name);
-IMAGE_EXPORT(void) display_ui32vector_T (uint32  *v,int i0, int i1, char *format, char *name);
-IMAGE_EXPORT(void) display_si64vector_T (sint64  *v,int i0, int i1, char *format, char *name);
-IMAGE_EXPORT(void) display_ui64vector_T (uint64  *v,int i0, int i1, char *format, char *name);
-
-IMAGE_EXPORT(void) display_f32vector_T  (float32 *v,int i0, int i1, char *format, char *name);
-IMAGE_EXPORT(void) display_f64vector_T  (float64 *v,int i0, int i1, char *format, char *name);
-
-IMAGE_EXPORT(void) display_rgb8vector_T (rgb8    *v, int i0, int i1, char *format, char *name);
-IMAGE_EXPORT(void) display_rgbx8vector_T(rgbx8   *v, int i0, int i1, char *format, char *name);
-
-/*
- * -------------------------------
- * --- display_vector_number_T ---
- * -------------------------------
- */
-
-IMAGE_EXPORT(void) display_si8vector_number_T (sint8   *v,int i0, int i1, char *format, char *name);
-IMAGE_EXPORT(void) display_ui8vector_number_T (uint8   *v,int i0, int i1, char *format, char *name);
-IMAGE_EXPORT(void) display_si16vector_number_T(sint16  *v,int i0, int i1, char *format, char *name);
-IMAGE_EXPORT(void) display_ui16vector_number_T(uint16  *v,int i0, int i1, char *format, char *name);
-IMAGE_EXPORT(void) display_si32vector_number_T(sint32  *v,int i0, int i1, char *format, char *name);
-IMAGE_EXPORT(void) display_ui32vector_number_T(uint32  *v,int i0, int i1, char *format, char *name);
-IMAGE_EXPORT(void) display_si64vector_number_T(sint64  *v,int i0, int i1, char *format, char *name);
-IMAGE_EXPORT(void) display_ui64vector_number_T(uint64  *v,int i0, int i1, char *format, char *name);
-
-IMAGE_EXPORT(void) display_f32vector_number_T (float32 *v,int i0, int i1, char *format, char *name);
-IMAGE_EXPORT(void) display_f64vector_number_T (float64 *v,int i0, int i1, char *format, char *name);
-
-IMAGE_EXPORT(void) display_rgb8vector_number_T (rgb8  *v,int i0, int i1, char *format, char *name);
-IMAGE_EXPORT(void) display_rgbx8vector_number_T(rgbx8 *v,int i0, int i1, char *format, char *name);
 
 /*
@@ -111,136 +42,63 @@
  * -------------------------------
  */
-    
-void display_ui8vector_positive (uint8  *v, int j0, int j1, int iformat, char *name);
-void display_ui16vector_positive(uint16 *v, int j0, int j1, int iformat, char *name);
-void display_ui32vector_positive(uint32 *v, int j0, int j1, int iformat, char *name);
-    
+
+#undef display_type_vector_positive
+#define display_type_vector_positive(t) \
+void short_name(t,display_,vector_positive)(t * v, int32_t j0, int32_t j1, int32_t iformat, char * name)
+
+display_type_vector_positive(int8_t);
+display_type_vector_positive(uint8_t);
+display_type_vector_positive(int16_t);
+display_type_vector_positive(uint16_t);
+display_type_vector_positive(int32_t);
+display_type_vector_positive(uint32_t);
+display_type_vector_positive(int64_t);
+display_type_vector_positive(uint64_t);
+display_type_vector_positive(float);
+display_type_vector_positive(double);
+
+ 
 /*
  * --------------------
  * --- write_vector ---
+ * --- write_vector_T ---
+ * --- write_vector_number ---
+ * --- write_vector_T_number ---
+ * --- fread_vector ---
+ * --- fwrite_vector ---
  * --------------------
  */
 
-IMAGE_EXPORT(void) write_si8vector  (sint8   *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui8vector  (uint8   *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_si16vector (sint16  *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui16vector (uint16  *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_si32vector (sint32  *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui32vector (uint32  *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_si64vector (sint64  *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui64vector (uint64  *v,long nl,long nh, char *format, char *filename);
+#define write_type_vector(t) \
+void short_name(t,write_,vector)(t * v, int32_t nl, int32_t nh, char * format, char * filename); \
+void short_name(t,write_,vector_T)(t * v, int32_t nl, int32_t nh, char * format, char * filename); \
+void short_name(t,write_,vector_number)(t * v, int32_t nl, int32_t nh, char * format, char * filename); \
+void short_name(t,write_,vector_T_number)(t * v, int32_t nl, int32_t nh, char * format, char * filename); \
+void short_name(t,fread_,vector)(char * filename, t * v, int32_t nl, int32_t nh); \
+void short_name(t,fwrite_,vector)(t * v, int32_t nl, int32_t nh, char * filename) \
 
-IMAGE_EXPORT(void) write_f32vector  (float32 *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_f64vector  (float64 *v,long nl,long nh, char *format, char *filename);
+write_type_vector(int8_t);
+write_type_vector(uint8_t);
+write_type_vector(int16_t);
+write_type_vector(uint16_t);
+write_type_vector(int32_t);
+write_type_vector(uint32_t);
+write_type_vector(int64_t);
+write_type_vector(uint64_t);
+write_type_vector(float);
+write_type_vector(double);
+write_type_vector(rgb8);
+write_type_vector(rgbx8);
 
-IMAGE_EXPORT(void) write_rgb8vector (rgb8    *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_rgbx8vector(rgbx8   *v,long nl,long nh, char *format, char *filename);
-
-/*
- * ----------------------
- * --- write_vector_T ---
- * ----------------------
- */
-
-IMAGE_EXPORT(void) write_si8vector_T  (sint8   *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui8vector_T  (uint8   *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_si16vector_T (sint16  *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui16vector_T (uint16  *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_si32vector_T (sint32  *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui32vector_T (uint32  *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_si64vector_T (sint64  *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui64vector_T (uint64  *v,long nl,long nh, char *format, char *filename);
-
-IMAGE_EXPORT(void) write_f32vector_T  (float32 *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_f64vector_T  (float64 *v,long nl,long nh, char *format, char *filename);
-
-IMAGE_EXPORT(void) write_rgb8vector_T (rgb8    *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_rgbx8vector_T(rgbx8   *v,long nl,long nh, char *format, char *filename);
-
-/*
- * ---------------------------
- * --- write_vector_number ---
- * ---------------------------
- */
-
-IMAGE_EXPORT(void) write_si8vector_number  (sint8   *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui8vector_number  (uint8   *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_si16vector_number (sint16  *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui16vector_number (uint16  *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_si32vector_number (sint32  *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui32vector_number (uint32  *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_si64vector_number (sint64  *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui64vector_number (uint64  *v,long nl,long nh, char *format, char *filename);
-
-IMAGE_EXPORT(void) write_f32vector_number  (float32 *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_f64vector_number  (float64 *v,long nl,long nh, char *format, char *filename);
-
-IMAGE_EXPORT(void) write_rgb8vector_number (rgb8    *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_rgbx8vector_number(rgbx8   *v,long nl,long nh, char *format, char *filename);
-
-/*
- * -----------------------------
- * --- write_vector_T_number ---
- * -----------------------------
- */
-
-IMAGE_EXPORT(void) write_si8vector_T_number  (sint8   *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui8vector_T_number  (uint8   *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_si16vector_T_number (sint16  *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui16vector_T_number (uint16  *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_si32vector_T_number (sint32  *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui32vector_T_number (uint32  *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_si64vector_T_number (sint64  *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui64vector_T_number (uint64  *v,long nl,long nh, char *format, char *filename);
-
-IMAGE_EXPORT(void) write_f32vector_T_number  (float32 *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_f64vector_T_number  (float64 *v,long nl,long nh, char *format, char *filename);
-
-IMAGE_EXPORT(void) write_rgb8vector_T_number (rgb8    *v,long nl,long nh, char *format, char *filename);
-IMAGE_EXPORT(void) write_rgbx8vector_T_number(rgbx8   *v,long nl,long nh, char *format, char *filename);
-
-/*
- * --------------------
- * --- fread_vector ---
- * --------------------
- */
-IMAGE_EXPORT(void) fread_si8vector  (char *filename, sint8   *v,long nl,long nh);
-IMAGE_EXPORT(void) fread_ui8vector  (char *filename, uint8   *v,long nl,long nh);
-IMAGE_EXPORT(void) fread_si16vector (char *filename, sint16  *v,long nl,long nh);
-IMAGE_EXPORT(void) fread_ui16vector (char *filename, uint16  *v,long nl,long nh);
-IMAGE_EXPORT(void) fread_si32vector (char *filename, sint32  *v,long nl,long nh);
-IMAGE_EXPORT(void) fread_ui32vector (char *filename, uint32  *v,long nl,long nh);
-IMAGE_EXPORT(void) fread_si64vector (char *filename, sint64  *v,long nl,long nh);
-IMAGE_EXPORT(void) fread_ui64vector (char *filename, uint64  *v,long nl,long nh);
-
-IMAGE_EXPORT(void) fread_f32vector  (char *filename, float32 *v,long nl,long nh);
-IMAGE_EXPORT(void) fread_f64vector  (char *filename, float64 *v,long nl,long nh);
-
-IMAGE_EXPORT(void) fread_rgb8vector (char *filename, rgb8    *v,long nl,long nh);
-IMAGE_EXPORT(void) fread_rgbx8vector(char *filename, rgbx8   *v,long nl,long nh);
-
-/*
- * ---------------------
- * --- fwrite_vector ---
- * ---------------------
- */
-IMAGE_EXPORT(void) fwrite_si8vector  (sint8   *v,long nl,long nh,char *filename);
-IMAGE_EXPORT(void) fwrite_ui8vector  (uint8   *v,long nl,long nh,char *filename);
-IMAGE_EXPORT(void) fwrite_si16vector (sint16  *v,long nl,long nh,char *filename);
-IMAGE_EXPORT(void) fwrite_ui16vector (uint16  *v,long nl,long nh,char *filename);
-IMAGE_EXPORT(void) fwrite_si32vector (sint32  *v,long nl,long nh,char *filename);
-IMAGE_EXPORT(void) fwrite_ui32vector (uint32  *v,long nl,long nh,char *filename);
-IMAGE_EXPORT(void) fwrite_si64vector (sint64  *v,long nl,long nh,char *filename);
-IMAGE_EXPORT(void) fwrite_ui64vector (uint64  *v,long nl,long nh,char *filename);
-
-IMAGE_EXPORT(void) fwrite_f32vector  (float32 *v,long nl,long nh,char *filename);
-IMAGE_EXPORT(void) fwrite_f64vector  (float64 *v,long nl,long nh,char *filename);
-
-IMAGE_EXPORT(void) fwrite_rgb8vector (rgb8    *v,long nl,long nh,char *filename);
-IMAGE_EXPORT(void) fwrite_rgbx8vector(rgbx8   *v,long nl,long nh,char *filename);
-
-#ifdef __cplusplus
-}
-#endif
 
 #endif // _NR_IO1_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/nrio1x.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/include/nrio1x.h	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/nrc2/include/nrio1x.h	(revision 822)
@@ -11,31 +11,31 @@
 #define _NR_IO1X_H_
 
-#ifdef __cplusplus
-#pragma message ("C++")
-extern "C" {
-#endif
-    
-IMAGE_EXPORT(void) display_bvector_circular    (byte     *v,long nl,long nh, long c0, long c1, char *format, char *name);
-IMAGE_EXPORT(void) display_si16vector_circular (sint16   *v,long nl,long nh, long c0, long c1, char *format, char *name);
-IMAGE_EXPORT(void) display_ui16vector_circular (uint16   *v,long nl,long nh, long c0, long c1, char *format, char *name);
-IMAGE_EXPORT(void) display_f32vector_circular     (float32  *v,long nl,long nh, long c0, long c1, char *format, char *name);
-IMAGE_EXPORT(void) display_f64vector_circular    (float64  *v,long nl,long nh, long c0, long c1, char *format, char *name);
+#define display_type_vector_circular(t) \
+void short_name(t,display_,vector_circular)(t * v, int32_t nl, int32_t nh, int32_t c0, int32_t c1, char * format, char * name); \
+void short_name(t,display_,vector_circular_number)(t * v, int32_t nl, int32_t nh, int32_t c0, int32_t c1, char * format, char * name); \
+void short_name(t,display_,vector_cycle)(t * v, int32_t nl, int32_t nh, char * format, char * name); \
+void short_name(t,write_,vector_circular)(t * v, int32_t nl, int32_t nh, int32_t c0, int32_t c1, char * format, char * filename)
 
-IMAGE_EXPORT(void) display_bvector_circular_number   (byte    *v,long nl,long nh, long c0, long c1, char *format, char *name);
-IMAGE_EXPORT(void) display_si16vector_circular_number(sint16  *v,long nl,long nh, long c0, long c1, char *format, char *name);
-IMAGE_EXPORT(void) display_ui16vector_circular_number(uint16  *v,long nl,long nh, long c0, long c1, char *format, char *name);
-IMAGE_EXPORT(void) display_f32vector_circular_number (float32 *v,long nl,long nh, long c0, long c1, char *format, char *name);
-IMAGE_EXPORT(void) display_f64vector_circular_number (float64 *v,long nl,long nh, long c0, long c1, char *format, char *name);
+display_type_vector_circular(int8_t);
+display_type_vector_circular(uint8_t);
+display_type_vector_circular(int16_t);
+display_type_vector_circular(uint16_t);
+display_type_vector_circular(int32_t);
+display_type_vector_circular(uint32_t);
+display_type_vector_circular(int64_t);
+display_type_vector_circular(uint64_t);
+display_type_vector_circular(float);
+display_type_vector_circular(double);
 
-IMAGE_EXPORT(void) display_bvector_cycle   (byte   *v,long nl,long nh, char *format, char *name);
-IMAGE_EXPORT(void) display_si16vector_cycle(sint16 *v,long nl,long nh, char *format, char *name);
-IMAGE_EXPORT(void) display_ui16vector_cycle(uint16 *v,long nl,long nh, char *format, char *name);
-
-IMAGE_EXPORT(void) write_bvector_circular(byte *v,long nl,long nh, long c0, long c1, char *format, char *filename);
-
-    
-#ifdef __cplusplus
-}
-#endif
 
 #endif // _NR_IO1X_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/nrio2.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/include/nrio2.h	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/nrc2/include/nrio2.h	(revision 822)
@@ -11,216 +11,67 @@
 #define _NR_IO2_H_
 
-#ifdef __cplusplus
-#pragma message ("C++")
-extern "C" {
-#endif
-    
-#ifdef VERBOSE_PRAGMA
-//#pragma message ("- *** include nrio2.h ***")
-#endif
-
 
 /*
  * ----------------------
  * --- display_matrix ---
+ * --- display_matrix_T ---
+ * --- display_matrix_number ---
+ * --- display_matrix_positive ---
  * ----------------------
  */
 
-IMAGE_EXPORT(void) display_si8matrix  (sint8   **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_ui8matrix  (uint8   **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_si16matrix (sint16  **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_ui16matrix (uint16  **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_si32matrix (sint32  **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_ui32matrix (uint32  **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_si64matrix (sint64  **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_ui64matrix (uint64  **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
+#define display_type_matrix(t) \
+void short_name(t,display_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * format, char * name); \
+void short_name(t,display_,matrix_T)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * format, char * name); \
+void short_name(t,display_,matrix_number)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * format, char * name); \
+void short_name(t,display_,matrix_positive)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, int32_t iformat, char * name)
 
-IMAGE_EXPORT(void) display_f32matrix  (float32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_f64matrix  (float64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
 
-IMAGE_EXPORT(void) display_rgb8matrix (rgb8    **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_rgbx8matrix(rgbx8   **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
+display_type_matrix(int8_t);
+display_type_matrix(uint8_t);
+display_type_matrix(int16_t);
+display_type_matrix(uint16_t);
+display_type_matrix(int32_t);
+display_type_matrix(uint32_t);
+display_type_matrix(int64_t);
+display_type_matrix(uint64_t);
+display_type_matrix(float);
+display_type_matrix(double);
+display_type_matrix(rgb8);
+display_type_matrix(rgbx8);
 
-/*
- * ------------------------
- * --- display_matrix_T ---
- * ------------------------
- */
-
-IMAGE_EXPORT(void) display_si8matrix_T (sint8   **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_ui8matrix_T (uint8   **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_si16matrix_T(sint16  **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_ui16matrix_T(uint16  **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_si32matrix_T(sint32  **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_ui32matrix_T(uint32  **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_si64matrix_T(sint64  **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_ui64matrix_T(uint64  **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-
-IMAGE_EXPORT(void) display_f32matrix_T (float32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_f64matrix_T (float64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-
-IMAGE_EXPORT(void) display_rgb8matrix_T (rgb8   **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_rgbx8matrix_T(rgbx8  **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-
-/*
- * -----------------------------
- * --- display_matrix_number ---
- * -----------------------------
- */
-
-IMAGE_EXPORT(void) display_si8matrix_number (sint8  **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_ui8matrix_number (uint8  **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_si16matrix_number(sint16 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_ui16matrix_number(uint16 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_i32matrix_number (sint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_ui32matrix_number(uint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_si64matrix_number(sint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_ui64matrix_number(uint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-
-IMAGE_EXPORT(void) display_f32matrix_number (float32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_f64matrix_number (float64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-
-IMAGE_EXPORT(void) display_rgb8matrix_number (rgb8  **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
-IMAGE_EXPORT(void) display_rgbx8matrix_number(rgbx8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name);
 
 /*
  * --------------------
  * --- write_matrix ---
- * --------------------
- */
-
-IMAGE_EXPORT(void) write_si8matrix  (sint8  **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui8matrix  (uint8  **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_si16matrix (sint16 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui16matrix (uint16 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_si32matrix (sint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui32matrix (uint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_si64matrix (sint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui64matrix (uint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-
-IMAGE_EXPORT(void) write_f32matrix (float32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_f64matrix (float64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-
-IMAGE_EXPORT(void) write_rgb8matrix (rgb8   **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_rgbx8matrix(rgbx8  **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-
-/*
- * ----------------------
  * --- write_matrix_T ---
- * ----------------------
- */
-
-IMAGE_EXPORT(void) write_si8matrix_T  (sint8   **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui8matrix_T  (uint8   **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_si16matrix_T (sint16  **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui16matrix_T (uint16  **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_si32matrix_T (sint32  **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui32matrix_T (uint32  **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_si64matrix_T (sint64  **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui64matrix_T (uint64  **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-
-IMAGE_EXPORT(void) write_f32matrix_T  (float32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_f64matrix_T  (float64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-
-IMAGE_EXPORT(void) write_rgb8matrix_T (rgb8    **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_rgbx8matrix_T(rgbx8   **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-
-/*
- * ---------------------------
  * --- write_matrix_number ---
- * ---------------------------
- */
-
-IMAGE_EXPORT(void) write_si8matrix_number  (sint8   **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui8matrix_number  (uint8   **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_si16matrix_number (sint16  **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui16matrix_number (uint16  **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_si32matrix_number (sint32  **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui32matrix_number (uint32  **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_si64matrix_number (sint64  **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui64matrix_number (uint64  **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-
-IMAGE_EXPORT(void) write_f32matrix_number  (float32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_f64matrix_number  (float64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-
-IMAGE_EXPORT(void) write_rgb8matrix_number (rgb8    **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_rgbx8matrix_number(rgbx8   **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-
-/*
- * -----------------------------
  * --- write_matrix_T_number ---
- * -----------------------------
- */
-
-IMAGE_EXPORT(void) write_si8matrix_T_number  (sint8   **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui8matrix_T_number  (uint8   **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_si16matrix_T_number (sint16  **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui16matrix_T_number (uint16  **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_si32matrix_T_number (sint32  **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui32matrix_T_number (uint32  **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_si64matrix_T_number (sint64  **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_ui64matrix_T_number (uint64  **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-
-IMAGE_EXPORT(void) write_f32matrix_T_number  (float32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_f64matrix_T_number  (float64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-
-IMAGE_EXPORT(void) write_rgb8matrix_T_number (rgb8    **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-IMAGE_EXPORT(void) write_rgbx8matrix_T_number(rgbx8   **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename);
-
-/*
- * ---------------------
  * --- fwrite_matrix ---
- * ---------------------
- */
-
-IMAGE_EXPORT(void) fwrite_si8matrix  (sint8  **m,long nrl,long nrh,long ncl, long nch, char *filename);
-IMAGE_EXPORT(void) fwrite_ui8matrix  (uint8  **m,long nrl,long nrh,long ncl, long nch, char *filename);
-IMAGE_EXPORT(void) fwrite_si16matrix (sint16 **m,long nrl,long nrh,long ncl, long nch, char *filename);
-IMAGE_EXPORT(void) fwrite_ui16matrix (uint16 **m,long nrl,long nrh,long ncl, long nch, char *filename);
-IMAGE_EXPORT(void) fwrite_si32matrix (sint32 **m,long nrl,long nrh,long ncl, long nch, char *filename);
-IMAGE_EXPORT(void) fwrite_ui32matrix (uint32 **m,long nrl,long nrh,long ncl, long nch, char *filename);
-IMAGE_EXPORT(void) fwrite_si64matrix (sint64 **m,long nrl,long nrh,long ncl, long nch, char *filename);
-IMAGE_EXPORT(void) fwrite_ui64matrix (uint64 **m,long nrl,long nrh,long ncl, long nch, char *filename);
-
-IMAGE_EXPORT(void) fwrite_f32matrix (float32 **m,long nrl,long nrh,long ncl, long nch, char *filename);
-IMAGE_EXPORT(void) fwrite_f64matrix (float64 **m,long nrl,long nrh,long ncl, long nch, char *filename);
-
-IMAGE_EXPORT(void) fwrite_rgb8matrix(rgb8    **m,long nrl,long nrh,long ncl, long nch, char *filename);
-IMAGE_EXPORT(void) fwrite_rgbx8matrix(rgbx8  **m,long nrl,long nrh,long ncl, long nch, char *filename);
-
-/*
- * --------------------
  * --- fread_matrix ---
  * --------------------
  */
 
-IMAGE_EXPORT(void) fread_si8matrix  (char *filename, sint8    **m,long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(void) fread_ui8matrix  (char *filename, uint8    **m,long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(void) fread_si16matrix (char *filename, sint16   **m,long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(void) fread_ui16matrix (char *filename, uint16   **m,long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(void) fread_si32matrix (char *filename, sint32   **m,long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(void) fread_ui32matrix (char *filename, uint32   **m,long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(void) fread_si64matrix (char *filename, sint64   **m,long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(void) fread_ui64matrix (char *filename, uint64   **m,long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(void) fread_f32matrix  (char *filename, float32  **m,long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(void) fread_f64matrix  (char *filename, float64  **m,long nrl,long nrh,long ncl, long nch);
+#define write_type_matrix(t) \
+void short_name(t,write_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * format, char * filename); \
+void short_name(t,write_,matrix_T)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * format, char * filename); \
+void short_name(t,write_,matrix_number)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * format, char * filename); \
+void short_name(t,write_,matrix_T_number)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * format, char * filename); \
+void short_name(t,fwrite_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * filename); \
+void short_name(t,fread_,matrix)(char * filename, t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch)  \
 
-IMAGE_EXPORT(void) fread_rgb8matrix (char *filename, rgb8     **m,long nrl,long nrh,long ncl, long nch);
-IMAGE_EXPORT(void) fread_rgbx8matrix(char *filename, rgbx8    **m,long nrl,long nrh,long ncl, long nch);
+write_type_matrix(int8_t);
+write_type_matrix(uint8_t);
+write_type_matrix(int16_t);
+write_type_matrix(uint16_t);
+write_type_matrix(int32_t);
+write_type_matrix(uint32_t);
+write_type_matrix(int64_t);
+write_type_matrix(uint64_t);
+write_type_matrix(float);
+write_type_matrix(double);
+write_type_matrix(rgb8);
+write_type_matrix(rgbx8);
 
-/*
- * -------------------------------
- * --- display_matrix_positive ---
- * -------------------------------
- */
-
-void display_si8matrix_positive (sint8 * *m, int i0, int i1, int j0, int j1, int iformat, char *name);
-void display_ui8matrix_positive (uint8 * *m, int i0, int i1, int j0, int j1, int iformat, char *name);
-void display_si16matrix_positive(sint16 **m, int i0, int i1, int j0, int j1, int iformat, char *name);
-void display_ui16matrix_positive(uint16 **m, int i0, int i1, int j0, int j1, int iformat, char *name);
-void display_si32matrix_positive(sint32 **m, int i0, int i1, int j0, int j1, int iformat, char *name);
-void display_ui32matrix_positive(uint32 **m, int i0, int i1, int j0, int j1, int iformat, char *name);
-void display_si64matrix_positive(sint64 **m, int i0, int i1, int j0, int j1, int iformat, char *name);
-void display_ui64matrix_positive(uint64 **m, int i0, int i1, int j0, int j1, int iformat, char *name);
 
 // -------------------------------
@@ -228,7 +79,10 @@
 // -------------------------------
 
-void write_ui8matrix_positive (uint8  **m,int i0, int i1, int j0, int j1, int iformat, char *filename);
-void write_ui16matrix_positive(uint16 **m,int i0, int i1, int j0, int j1, int iformat, char *filename);
-void write_ui32matrix_positive(uint32 **m,int i0, int i1, int j0, int j1, int iformat, char *filename);
+#define write_type_matrix_positive(t) \
+void short_name(t,write_,matrix_positive)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, int32_t iformat, char * filename)
+
+write_type_matrix_positive(uint8_t);
+write_type_matrix_positive(uint16_t);
+write_type_matrix_positive(uint32_t);
 
 /* ------------------------ */
@@ -236,23 +90,15 @@
 /* ------------------------ */
 
-IMAGE_EXPORT(uint8 **) LoadPGM_ui8matrix(char *filename, int *nrl, int *nrh, int *ncl, int *nch);
-IMAGE_EXPORT(uint8 **) LoadPGM_bmatrix  (char *filename, int *nrl, int *nrh, int *ncl, int *nch);
-IMAGE_EXPORT(void)     LoadPGM_bmatrix2 (char *filename, int *nrl, int *nrh, int *ncl, int *nch, uint8 **m);
-IMAGE_EXPORT(void)     MLoadPGM_bmatrix (char *filename, int nrl, int nrh, int ncl, int nch, uint8 **m);
+uint8_t ** LoadPGM_ui8matrix  (char * filename, int32_t * nrl, int32_t * nrh, int32_t * ncl, int32_t * nch);
+void       LoadPGM_ui8matrix2 (char * filename, int32_t * nrl, int32_t * nrh, int32_t * ncl, int32_t * nch, uint8_t ** m);
+rgb8 **    LoadPPM_rgb8matrix (char * filename, int32_t * nrl, int32_t * nrh, int32_t * ncl, int32_t * nch);
+void       LoadPPM_rgb8matrix2(char * filename, int32_t * nrl, int32_t * nrh, int32_t * ncl, int32_t * nch, rgb8 ** m);
 
-IMAGE_EXPORT(void)     SavePGM_bmatrix  (uint8 **m, int nrl, int nrh, int ncl, int nch, char *filename);
-IMAGE_EXPORT(void)     SavePGM_ui8matrix(uint8 **m, int nrl, int nrh, int ncl, int nch, char *filename);
-
-IMAGE_EXPORT(rgb8 **)  LoadPPM_rgb8matrix (char *filename, int *nrl, int *nrh, int *ncl, int *nch);
-IMAGE_EXPORT(void)     LoadPPM_rgb8matrix2(char *filename, int *nrl, int *nrh, int *ncl, int *nch, rgb8 **m);
-
-IMAGE_EXPORT(void)     SavePPM_rgb8matrix(rgb8 **m, int nrl, int nrh, int ncl, int nch, char *filename);
+void MLoadPGM_ui8matrix(char * filename, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, uint8 ** m);
+void SavePGM_ui8matrix    (uint8_t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * filename);
+void SavePPM_rgb8matrix      (rgb8 ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * filename);
 
 
 
-#ifdef __cplusplus
-}
-#endif
-
 #endif // _NR_IO2_H_
 
Index: soft/giet_vm/applications/rosenfeld/nrc2/include/nrtype.h
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/include/nrtype.h	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/nrc2/include/nrtype.h	(revision 822)
@@ -17,8 +17,4 @@
 
 #include <stdint.h>
-
-// ---------------------------------- //
-// -- don not write under the line -- //
-// ---------------------------------- //
 
 
Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc1.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc1.c	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc1.c	(revision 822)
@@ -157,5 +157,5 @@
 #undef remote_type_vector
 #define remote_type_vector(t)                                                   \
-t * short_name(t,remote_,vector)(int32_t nl, int32_t nh, int32_t x, int32_t y) \
+t * short_name(t,remote_,vector)(int32_t nl, int32_t nh, int32_t x, int32_t y)  \
 {                                                                               \
     t * v;                                                                      \
Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nrbool1.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrbool1.c	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrbool1.c	(revision 822)
@@ -17,4 +17,5 @@
 #include <math.h> // fabs
 
+#include "nrc_os_config.h"
 #include "mypredef.h"
 #include "nrtype.h"
@@ -31,120 +32,41 @@
  */
 
-/* -------------------------------------------------------------- */
-IMAGE_EXPORT(void) not_bvector(byte *X, long ncl, long nch, byte *Y)
-/* -------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Y[j] = ~X[j];
-	}
-}
-/* ------------------------------------------------------------------ */
-IMAGE_EXPORT(void) not_si8vector(sint8 *X, long ncl, long nch, sint8 *Y)
-/* ------------------------------------------------------------------ */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Y[j] = ~X[j];
-	}
-}
-/* ------------------------------------------------------------------ */
-IMAGE_EXPORT(void) not_ui8vector(uint8 *X, long ncl, long nch, uint8 *Y)
-/* ------------------------------------------------------------------ */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Y[j] = ~X[j];
-	}
-}
-/* --------------------------------------------------------------------- */
-IMAGE_EXPORT(void) not_si16vector(sint16 *X, long ncl, long nch, sint16 *Y)
-/* --------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Y[j] = ~X[j];
-	}
-}
-/* --------------------------------------------------------------------- */
-IMAGE_EXPORT(void) not_ui16vector(uint16 *X, long ncl, long nch, uint16 *Y)
-/* --------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Y[j] = ~X[j];
-	}
-}
-/* --------------------------------------------------------------------- */
-IMAGE_EXPORT(void) not_si32vector(sint32 *X, long ncl, long nch, sint32 *Y)
-/* --------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Y[j] = ~X[j];
-	}
-}
-/* --------------------------------------------------------------------- */
-IMAGE_EXPORT(void) not_ui32vector(uint32 *X, long ncl, long nch, uint32 *Y)
-/* --------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Y[j] = ~X[j];
-	}
-}
-/* --------------------------------------------------------------------- */
-IMAGE_EXPORT(void) not_si64vector(sint64 *X, long ncl, long nch, sint64 *Y)
-/* --------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Y[j] = ~X[j];
-	}
-}
-/* --------------------------------------------------------------------- */
-IMAGE_EXPORT(void) not_ui64vector(uint64 *X, long ncl, long nch, uint64 *Y)
-/* --------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Y[j] = ~X[j];
-	}
-}
+#undef not_type_vector
+#define not_type_vector(t) \
+void short_name(t,not_,vector)(t * X, int32_t ncl, int32_t nch, t * Y) \
+{                                          \
+	for (int32_t j = ncl; j <= nch; j++) { \
+		Y[j] = ~X[j];                      \
+	}                                      \
+}
+
+not_type_vector(int8_t);
+not_type_vector(uint8_t);
+not_type_vector(int16_t);
+not_type_vector(uint16_t);
+not_type_vector(int32_t);
+not_type_vector(uint32_t);
+not_type_vector(int64_t);
+not_type_vector(uint64_t);
+
+
 /* ----------------------------------------------------------------- */
-IMAGE_EXPORT(void) not_rgb8vector(rgb8 *X, long ncl, long nch, rgb8 *Y)
+void not_rgb8vector(rgb8 * X, int32_t ncl, int32_t nch, rgb8 * Y)
 /* ----------------------------------------------------------------- */
 {
-	long j;
-    rgb8 x, y;
-	
-	for(j=ncl; j<=nch; j++) {
-        x = X[j];
-        RGB8_NOT(x,y);
-		Y[j] = y;
-	}
-}
+	for (int32_t j = ncl; j <= nch; j++) {
+        RGB8_NOT(X[j], Y[j]);
+	}
+}
+
 /* -------------------------------------------------------------------- */
-IMAGE_EXPORT(void) not_rgbx8vector(rgbx8 *X, long ncl, long nch, rgbx8 *Y)
+void not_rgbx8vector(rgbx8 * X, int32_t ncl, int32_t nch, rgbx8 * Y)
 /* -------------------------------------------------------------------- */
 {
-	long j;
-    rgbx8 x, y;
-	
-	for(j=ncl; j<=nch; j++) {
-        x = X[j];
-        RGBX8_NOT(x,y);
-		Y[j] = y;
-	}
-}
+	for (int32_t j = ncl; j <= nch; j++) {
+        RGBX8_NOT(X[j], Y[j]);
+	}
+}
+
 /*
  * -----------
@@ -153,238 +75,79 @@
  */
 
-/* ---------------------------------------------------------------------- */
-IMAGE_EXPORT(void) or_bvector(byte *X, long ncl, long nch, byte *Y, byte *Z)
-/* ---------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] | Y[j];
-	}
-}
-/* --------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) or_si8vector(sint8 *X, long ncl, long nch, sint8 *Y, sint8 *Z)
-/* --------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] | Y[j];
-	}
-}
-/* --------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) or_ui8vector(uint8 *X, long ncl, long nch, uint8 *Y, uint8 *Z)
-/* --------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] | Y[j];
-	}
-}
-/* ------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) or_si16vector(sint16 *X, long ncl, long nch, sint16 *Y, sint16 *Z)
-/* ------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] | Y[j];
-	}
-}
-/* ------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) or_ui16vector(uint16 *X, long ncl, long nch, uint16 *Y, uint16 *Z)
-/* ------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] | Y[j];
-	}
-}
-/* ------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) or_si32vector(sint32 *X, long ncl, long nch, sint32 *Y, sint32 *Z)
-/* ------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] | Y[j];
-	}
-}
-/* ------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) or_ui32vector(uint32 *X, long ncl, long nch, uint32 *Y, uint32 *Z)
-/* ------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] | Y[j];
-	}
-}
-/* ------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) or_si64vector(sint64 *X, long ncl, long nch, sint64 *Y, sint64 *Z)
-/* ------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] | Y[j];
-	}
-}
-/* ------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) or_ui64vector(uint64 *X, long ncl, long nch, uint64 *Y, uint64 *Z)
-/* ------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] | Y[j];
-	}
-}
+#undef or_type_vector
+#define or_type_vector(t) \
+void short_name(t,or_,vector)(t * X, int32_t ncl, int32_t nch, t * Y, t * Z) \
+{                                          \
+	for (int32_t j = ncl; j <= nch; j++) { \
+		Z[j] = X[j] | Y[j];                \
+	}                                      \
+}
+
+or_type_vector(int8_t);
+or_type_vector(uint8_t);
+or_type_vector(int16_t);
+or_type_vector(uint16_t);
+or_type_vector(int32_t);
+or_type_vector(uint32_t);
+or_type_vector(int64_t);
+or_type_vector(uint64_t);
+
+
 /* ------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) or_rgb8vector(rgb8 *X, long ncl, long nch, rgb8 *Y, rgb8 *Z)
+void or_rgb8vector(rgb8 * X, int32_t ncl, int32_t nch, rgb8 * Y, rgb8 * Z)
 /* ------------------------------------------------------------------------- */
 {
-	long j;
-    rgb8 x, y, z;
-	
-	for(j=ncl; j<=nch; j++) {
-        x = X[j];
-        y = Y[j];
-        RGB8_OR(x,y,z);
-		Z[j] = z;
+	for (int32_t j = ncl; j <= nch; j++) {
+        RGB8_OR(X[j], Y[j], Z[j]);
 	}
 }
 /* ----------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) or_rgbx8vector(rgbx8 *X, long ncl, long nch, rgbx8 *Y, rgbx8 *Z)
+void or_rgbx8vector(rgbx8 * X, int32_t ncl, int32_t nch, rgbx8 * Y, rgbx8 * Z)
 /* ----------------------------------------------------------------------------- */
 {
-	long j;
-    rgbx8 x, y, z;
-	
-	for(j=ncl; j<=nch; j++) {
-        x = X[j];
-        y = Y[j];
-        RGBX8_OR(x,y,z);
-		Z[j] = z;
-	}
-}
-/* ---------------------------------------------------------------------- */
-IMAGE_EXPORT(void) orc_bvector(byte *X, long ncl, long nch, byte y, byte *Z)
-/* ---------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] | y;
-	}
-}
-/* --------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) orc_si8vector(sint8 *X, long ncl, long nch, sint8 y, sint8 *Z)
-/* --------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] | y;
-	}
-}
-/* --------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) orc_ui8vector(uint8 *X, long ncl, long nch, uint8 y, uint8 *Z)
-/* --------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] | y;
-	}
-}
-/* ------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) orc_si16vector(sint16 *X, long ncl, long nch, sint16 y, sint16 *Z)
-/* ------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] | y;
-	}
-}
-/* ------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) orc_ui16vector(uint16 *X, long ncl, long nch, uint16 y, uint16 *Z)
-/* ------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] | y;
-	}
-}
-/* ------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) orc_si32vector(sint32 *X, long ncl, long nch, sint32 y, sint32 *Z)
-/* ------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] | y;
-	}
-}
-/* ------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) orc_ui32vector(uint32 *X, long ncl, long nch, uint32 y, uint32 *Z)
-/* ------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] | y;
-	}
-}
-/* ------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) orc_si64vector(sint64 *X, long ncl, long nch, sint64 y, sint64 *Z)
-/* ------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] | y;
-	}
-}
-/* ------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) orc_ui64vector(uint64 *X, long ncl, long nch, uint64 y, uint64 *Z)
-/* ------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] | y;
-	}
-}
+	for (int32_t j = ncl; j <= nch; j++) {
+        RGBX8_OR(X[j], Y[j], Z[j]);
+	}
+}
+
+
+#undef orc_type_vector
+#define orc_type_vector(t) \
+void short_name(t,orc_,vector)(t * X, int32_t ncl, int32_t nch, t y, t * Z) \
+{                                          \
+	for (int32_t j = ncl; j <= nch; j++) { \
+		Z[j] = X[j] | y;                   \
+	}                                      \
+}
+
+orc_type_vector(int8_t);
+orc_type_vector(uint8_t);
+orc_type_vector(int16_t);
+orc_type_vector(uint16_t);
+orc_type_vector(int32_t);
+orc_type_vector(uint32_t);
+orc_type_vector(int64_t);
+orc_type_vector(uint64_t);
+
+
 /* ------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) orc_rgb8vector(rgb8 *X, long ncl, long nch, rgb8 y, rgb8 *Z)
+void orc_rgb8vector(rgb8 * X, int32_t ncl, int32_t nch, rgb8 y, rgb8 * Z)
 /* ------------------------------------------------------------------------- */
 {
-	long j;
-    rgb8 x, z;
-	
-	for(j=ncl; j<=nch; j++) {
-        x = X[j];
-        RGB8_OR(x,y,z);
-		Z[j] = z;
-	}
-}
+	for (int32_t j = ncl; j <= nch; j++) {
+        RGB8_OR(X[j], y, Z[j]);
+	}
+}
+
 /* ----------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) orc_rgbx8vector(rgbx8 *X, long ncl, long nch, rgbx8 y, rgbx8 *Z)
+void orc_rgbx8vector(rgbx8 * X, int32_t ncl, int32_t nch, rgbx8 y, rgbx8 * Z)
 /* ----------------------------------------------------------------------------- */
 {
-	long j;
-    rgbx8 x, z;
-	
-	for(j=ncl; j<=nch; j++) {
-        x = X[j];
-        RGBX8_OR(x,y,z);
-		Z[j] = z;
-	}
-}
+	for (int32_t j = ncl; j <= nch; j++) {
+        RGBX8_OR(X[j], y, Z[j]);
+	}
+}
+
+
 /*
  * -----------
@@ -392,238 +155,81 @@
  * -----------
  */
-/* ----------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xor_bvector(byte *X, long ncl, long nch, byte *Y, byte *Z)
-/* ----------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] ^ Y[j];
-	}
-}
-/* ---------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xor_si8vector(sint8 *X, long ncl, long nch, sint8 *Y, sint8 *Z)
-/* ---------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] ^ Y[j];
-	}
-}
-/* ---------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xor_ui8vector(uint8 *X, long ncl, long nch, uint8 *Y, uint8 *Z)
-/* ---------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] ^ Y[j];
-	}
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xor_si16vector(sint16 *X, long ncl, long nch, sint16 *Y, sint16 *Z)
-/* -------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] ^ Y[j];
-	}
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xor_ui16vector(uint16 *X, long ncl, long nch, uint16 *Y, uint16 *Z)
-/* -------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] ^ Y[j];
-	}
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xor_si32vector(sint32 *X, long ncl, long nch, sint32 *Y, sint32 *Z)
-/* -------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] ^ Y[j];
-	}
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xor_ui32vector(uint32 *X, long ncl, long nch, uint32 *Y, uint32 *Z)
-/* -------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] ^ Y[j];
-	}
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xor_si64vector(sint64 *X, long ncl, long nch, sint64 *Y, sint64 *Z)
-/* -------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] ^ Y[j];
-	}
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xor_ui64vector(uint64 *X, long ncl, long nch, uint64 *Y, uint64 *Z)
-/* -------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] ^ Y[j];
-	}
-}
-/* -------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xor_rgb8vector(rgb8 *X, long ncl, long nch, rgb8 *Y, rgb8 *Z)
-/* -------------------------------------------------------------------------- */
-{
-	long j;
-    rgb8 x, y, z;
-	
-	for(j=ncl; j<=nch; j++) {
-        x = X[j];
-        y = Y[j];
-        RGB8_XOR(x,y,z);
-		Z[j] = z;
-	}
-}
-/* ------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) xor_rgbx8vector(rgbx8 *X, long ncl, long nch, rgbx8 *Y, rgbx8 *Z)
-/* ------------------------------------------------------------------------------ */
-{
-	long j;
-    rgbx8 x, y, z;
-	
-	for(j=ncl; j<=nch; j++) {
-        x = X[j];
-        y = Y[j];
-        RGBX8_XOR(x,y,z);
-		Z[j] = z;
-	}
-}
-/* ----------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xorc_bvector(byte *X, long ncl, long nch, byte y, byte *Z)
-/* ----------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] ^ y;
-	}
-}
-/* ---------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xorc_si8vector(sint8 *X, long ncl, long nch, sint8 y, sint8 *Z)
-/* ---------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] ^ y;
-	}
-}
-/* ---------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xorc_ui8vector(uint8 *X, long ncl, long nch, uint8 y, uint8 *Z)
-/* ---------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] ^ y;
-	}
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xorc_si16vector(sint16 *X, long ncl, long nch, sint16 y, sint16 *Z)
-/* -------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] ^ y;
-	}
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xorc_ui16vector(uint16 *X, long ncl, long nch, uint16 y, uint16 *Z)
-/* -------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] ^ y;
-	}
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xorc_si32vector(sint32 *X, long ncl, long nch, sint32 y, sint32 *Z)
-/* -------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] ^ y;
-	}
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xorc_ui32vector(uint32 *X, long ncl, long nch, uint32 y, uint32 *Z)
-/* -------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] ^ y;
-	}
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xorc_si64vector(sint64 *X, long ncl, long nch, sint64 y, sint64 *Z)
-/* -------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] ^ y;
-	}
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xorc_ui64vector(uint64 *X, long ncl, long nch, uint64 y, uint64 *Z)
-/* -------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] ^ y;
-	}
-}
-/* -------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xorc_rgb8vector(rgb8 *X, long ncl, long nch, rgb8 y, rgb8 *Z)
-/* -------------------------------------------------------------------------- */
-{
-	long j;
-    rgb8 x, z;
-	
-	for(j=ncl; j<=nch; j++) {
-        x = X[j];
-        RGB8_XOR(x,y,z);
-		Z[j] = z;
-	}
-}
-/* ------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) xorc_rgbx8vector(rgbx8 *X, long ncl, long nch, rgbx8 y, rgbx8 *Z)
-/* ------------------------------------------------------------------------------ */
-{
-	long j;
-    rgbx8 x, z;
-	
-	for(j=ncl; j<=nch; j++) {
-        x = X[j];
-        RGBX8_XOR(x,y,z);
-		Z[j] = z;
-	}
-}
+
+#undef xor_type_vector
+#define xor_type_vector(t) \
+void short_name(t,xor_,vector)(t * X, int32_t ncl, int32_t nch, t * Y, t * Z) \
+{                                          \
+	for (int32_t j = ncl; j <= nch; j++) { \
+		Z[j] = X[j] ^ Y[j];                \
+	}                                      \
+}
+
+xor_type_vector(int8_t);
+xor_type_vector(uint8_t);
+xor_type_vector(int16_t);
+xor_type_vector(uint16_t);
+xor_type_vector(int32_t);
+xor_type_vector(uint32_t);
+xor_type_vector(int64_t);
+xor_type_vector(uint64_t);
+
+
+/* -------------------------------------------------------------------------- */
+void xor_rgb8vector(rgb8 * X, int32_t ncl, int32_t nch, rgb8 * Y, rgb8 * Z)
+/* -------------------------------------------------------------------------- */
+{
+	for (int32_t j = ncl; j <= nch; j++) {
+        RGB8_XOR(X[j], Y[j], Z[j]);
+	}
+}
+
+/* ------------------------------------------------------------------------------ */
+void xor_rgbx8vector(rgbx8 * X, int32_t ncl, int32_t nch, rgbx8 * Y, rgbx8 * Z)
+/* ------------------------------------------------------------------------------ */
+{
+	for (int32_t j = ncl; j <= nch; j++) {
+        RGBX8_XOR(X[j], Y[j], Z[j]);
+	}
+}
+
+
+#undef xorc_type_vector
+#define xorc_type_vector(t) \
+void short_name(t,xorc_,vector)(t * X, int32_t ncl, int32_t nch, t y, t * Z) \
+{                                          \
+	for (int32_t j = ncl; j <= nch; j++) { \
+		Z[j] = X[j] ^ y;                   \
+	}                                      \
+}
+
+xorc_type_vector(int8_t);
+xorc_type_vector(uint8_t);
+xorc_type_vector(int16_t);
+xorc_type_vector(uint16_t);
+xorc_type_vector(int32_t);
+xorc_type_vector(uint32_t);
+xorc_type_vector(int64_t);
+xorc_type_vector(uint64_t);
+
+
+/* -------------------------------------------------------------------------- */
+void xorc_rgb8vector(rgb8 * X, int32_t ncl, int32_t nch, rgb8 y, rgb8 * Z)
+/* -------------------------------------------------------------------------- */
+{
+	for (int32_t j = ncl; j <= nch; j++) {
+        RGB8_XOR(X[j], y, Z[j]);
+	}
+}
+
+/* ------------------------------------------------------------------------------ */
+void xorc_rgbx8vector(rgbx8 * X, int32_t ncl, int32_t nch, rgbx8 y, rgbx8 * Z)
+/* ------------------------------------------------------------------------------ */
+{
+	for (int32_t j = ncl; j <= nch; j++) {
+        RGBX8_XOR(X[j], y, Z[j]);
+	}
+}
+
+
 /*
  * -----------
@@ -631,236 +237,89 @@
  * -----------
  */
-/* ----------------------------------------------------------------------- */
-IMAGE_EXPORT(void) and_bvector(byte *X, long ncl, long nch, byte *Y, byte *Z)
-/* ----------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] & Y[j];
-	}
-}
-/* ---------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) and_si8vector(sint8 *X, long ncl, long nch, sint8 *Y, sint8 *Z)
-/* ---------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] & Y[j];
-	}
-}
-/* ---------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) and_ui8vector(uint8 *X, long ncl, long nch, uint8 *Y, uint8 *Z)
-/* ---------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] & Y[j];
-	}
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) and_si16vector(sint16 *X, long ncl, long nch, sint16 *Y, sint16 *Z)
-/* -------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] & Y[j];
-	}
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) and_ui16vector(uint16 *X, long ncl, long nch, uint16 *Y, uint16 *Z)
-/* -------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] & Y[j];
-	}
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) and_si32vector(sint32 *X, long ncl, long nch, sint32 *Y, sint32 *Z)
-/* -------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] & Y[j];
-	}
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) and_ui32vector(uint32 *X, long ncl, long nch, uint32 *Y, uint32 *Z)
-/* -------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] & Y[j];
-	}
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) and_si64vector(sint64 *X, long ncl, long nch, sint64 *Y, sint64 *Z)
-/* -------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] & Y[j];
-	}
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) and_ui64vector(uint64 *X, long ncl, long nch, uint64 *Y, uint64 *Z)
-/* -------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] & Y[j];
-	}
-}
-/* -------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) and_rgb8vector(rgb8 *X, long ncl, long nch, rgb8 *Y, rgb8 *Z)
-/* -------------------------------------------------------------------------- */
-{
-	long j;
-    rgb8 x, y, z;
-	
-	for(j=ncl; j<=nch; j++) {
-        x = X[j];
-        y = Y[j];
-        RGB8_AND(x,y,z);
-		Z[j] = z;
-	}
-}
-/* ------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) and_rgbx8vector(rgbx8 *X, long ncl, long nch, rgbx8 *Y, rgbx8 *Z)
-/* ------------------------------------------------------------------------------ */
-{
-	long j;
-    rgbx8 x, y, z;
-	
-	for(j=ncl; j<=nch; j++) {
-        x = X[j];
-        y = Y[j];
-        RGBX8_AND(x,y,z);
-		Z[j] = z;
-	}
-}
-/* ----------------------------------------------------------------------- */
-IMAGE_EXPORT(void) andc_bvector(byte *X, long ncl, long nch, byte y, byte *Z)
-/* ----------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] & y;
-	}
-}
-/* ---------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) andc_si8vector(sint8 *X, long ncl, long nch, sint8 y, sint8 *Z)
-/* ---------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] & y;
-	}
-}
-/* ---------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) andc_ui8vector(uint8 *X, long ncl, long nch, uint8 y, uint8 *Z)
-/* ---------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] & y;
-	}
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) andc_si16vector(sint16 *X, long ncl, long nch, sint16 y, sint16 *Z)
-/* -------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] & y;
-	}
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) andc_ui16vector(uint16 *X, long ncl, long nch, uint16 y, uint16 *Z)
-/* -------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] & y;
-	}
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) andc_si32vector(sint32 *X, long ncl, long nch, sint32 y, sint32 *Z)
-/* -------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] & y;
-	}
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) andc_ui32vector(uint32 *X, long ncl, long nch, uint32 y, uint32 *Z)
-/* -------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] & y;
-	}
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) andc_si64vector(sint64 *X, long ncl, long nch, sint64 y, sint64 *Z)
-/* -------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] & y;
-	}
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) andc_ui64vector(uint64 *X, long ncl, long nch, uint64 y, uint64 *Z)
-/* -------------------------------------------------------------------------------- */
-{
-	long j;
-	
-	for(j=ncl; j<=nch; j++) {
-		Z[j] = X[j] & y;
-	}
-}
-/* -------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) andc_rgb8vector(rgb8 *X, long ncl, long nch, rgb8 y, rgb8 *Z)
-/* -------------------------------------------------------------------------- */
-{
-	long j;
-    rgb8 x, z;
-	
-	for(j=ncl; j<=nch; j++) {
-        x = X[j];
-        RGB8_AND(x,y,z);
-		Z[j] = z;
-	}
-}
-/* ------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) andc_rgbx8vector(rgbx8 *X, long ncl, long nch, rgbx8 y, rgbx8 *Z)
-/* ------------------------------------------------------------------------------ */
-{
-	long j;
-    rgbx8 x, z;
-	
-	for(j=ncl; j<=nch; j++) {
-        x = X[j];
-        RGBX8_AND(x,y,z);
-		Z[j] = z;
-	}
-}
+
+
+#undef and_type_vector
+#define and_type_vector(t) \
+void short_name(t,and_,vector)(t * X, int32_t ncl, int32_t nch, t * Y, t * Z) \
+{                                          \
+	for (int32_t j = ncl; j <= nch; j++) { \
+		Z[j] = X[j] & Y[j];                \
+	}                                      \
+}
+
+and_type_vector(int8_t);
+and_type_vector(uint8_t);
+and_type_vector(int16_t);
+and_type_vector(uint16_t);
+and_type_vector(int32_t);
+and_type_vector(uint32_t);
+and_type_vector(int64_t);
+and_type_vector(uint64_t);
+
+
+/* -------------------------------------------------------------------------- */
+void and_rgb8vector(rgb8 * X, int32_t ncl, int32_t nch, rgb8 * Y, rgb8 * Z)
+/* -------------------------------------------------------------------------- */
+{
+	for (int32_t j = ncl; j <= nch; j++) {
+        RGB8_AND(X[j], Y[j], Z[j]);
+	}
+}
+
+/* ------------------------------------------------------------------------------ */
+void and_rgbx8vector(rgbx8 * X, int32_t ncl, int32_t nch, rgbx8 * Y, rgbx8 * Z)
+/* ------------------------------------------------------------------------------ */
+{
+	for (int32_t j = ncl; j <= nch; j++) {
+        RGBX8_AND(X[j], Y[j], Z[j]);
+	}
+}
+
+
+#undef andc_type_vector
+#define andc_type_vector(t) \
+void short_name(t,andc_,vector)(t * X, int32_t ncl, int32_t nch, t y, t * Z) \
+{                                          \
+	for (int32_t j = ncl; j <= nch; j++) { \
+		Z[j] = X[j] ^ y;                   \
+	}                                      \
+}
+
+andc_type_vector(int8_t);
+andc_type_vector(uint8_t);
+andc_type_vector(int16_t);
+andc_type_vector(uint16_t);
+andc_type_vector(int32_t);
+andc_type_vector(uint32_t);
+andc_type_vector(int64_t);
+andc_type_vector(uint64_t);
+
+
+/* -------------------------------------------------------------------------- */
+void andc_rgb8vector(rgb8 * X, int32_t ncl, int32_t nch, rgb8 y, rgb8 * Z)
+/* -------------------------------------------------------------------------- */
+{
+	for (int32_t j = ncl; j <= nch; j++) {
+        RGB8_AND(X[j], y, Z[j]);
+	}
+}
+
+/* ------------------------------------------------------------------------------ */
+void andc_rgbx8vector(rgbx8 * X, int32_t ncl, int32_t nch, rgbx8 y, rgbx8 * Z)
+/* ------------------------------------------------------------------------------ */
+{
+	for (int32_t j = ncl; j <= nch; j++) {
+        RGBX8_AND(X[j], y, Z[j]);
+	}
+}
+
+
+// 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/nrbool2.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrbool2.c	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrbool2.c	(revision 822)
@@ -16,6 +16,8 @@
 #include <stddef.h>
 #include <stdlib.h>
-#include <math.h> // fabs
+#include <math.h>
+#include <stdbool.h>
 
+#include "nrc_os_config.h"
 #include "mypredef.h"
 #include "nrtype.h"
@@ -27,95 +29,29 @@
 #include "nrbool2.h"
 
-/* ----------------------------------------------------------------------------------- */
-IMAGE_EXPORT(int) cmpeq_bmatrix(byte **X, long nrl,long nrh,long ncl, long nch, byte **Y)
-/* ----------------------------------------------------------------------------------- */
-{
-	int i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(X[i][j] != Y[i][j]) return 1;
-		}
-	}
-	return 0;
+
+#undef cmpeq_type_matrix
+#define cmpeq_type_matrix(t) \
+int32_t short_name(t,cmpeq_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t ** Y) \
+{                                              \
+    for (int32_t i = nrl; i <= nrh; i++) {     \
+        for (int32_t j = ncl; j <= nch; j++) { \
+            if (X[i][j] != Y[i][j]) {          \
+                return 1;                      \
+            }                                  \
+        }                                      \
+    }                                          \
+    return 0;                                  \
 }
-/* --------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(int) cmpeq_si8matrix(sint8 **X, long nrl,long nrh,long ncl, long nch, sint8 **Y)
-/* --------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(X[i][j] != Y[i][j]) return 1;
-		}
-	}
-	return 0;
-}
-/* ----------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(int) cmpeq_ui8matrix(uint8 **X, long nrl, long nrh, long ncl, long nch, uint8 **Y)
-/* ----------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(X[i][j] != Y[i][j]) return 1;
-		}
-	}
-	return 0;
-}
-/* -------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(int) cmpeq_si16matrix(sint16 **X, long nrl ,long nrh, long ncl, long nch, sint16 **Y)
-/* -------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(X[i][j] != Y[i][j]) return 1;
-		}
-	}
-	return 0;
-}
-/* -------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(int) cmpeq_ui16matrix(uint16 **X, long nrl, long nrh, long ncl, long nch, uint16 **Y)
-/* -------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(X[i][j] != Y[i][j]) return 1;
-		}
-	}
-	return 0;
-}
-/* -------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(int) cmpeq_si32matrix(sint32 **X, long nrl, long nrh, long ncl, long nch, sint32 **Y)
-/* -------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(X[i][j] != Y[i][j]) return 1;
-		}
-	}
-	return 0;
-}
-/* -------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(int) cmpeq_ui32matrix(uint32 **X, long nrl, long nrh, long ncl, long nch, uint32 **Y)
-/* -------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(X[i][j] != Y[i][j]) return 1;
-		}
-	}
-	return 0;
-}
+
+cmpeq_type_matrix(int8_t);
+cmpeq_type_matrix(uint8_t);
+cmpeq_type_matrix(int16_t);
+cmpeq_type_matrix(uint16_t);
+cmpeq_type_matrix(int32_t);
+cmpeq_type_matrix(uint32_t);
+cmpeq_type_matrix(int64_t);
+cmpeq_type_matrix(uint64_t);
+
+
 
 /*
@@ -125,94 +61,25 @@
  */
 
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) not_bmatrix(byte **X, long nrl,long nrh,long ncl, long nch, byte **Y)
-/* ---------------------------------------------------------------------------------- */
-{
-	long i;
-	
-	for(i=nrl; i<=nrh; i++) {
-		not_bvector(X[i], ncl, nch, Y[i]);
-	}
+#undef not_type_matrix
+#define not_type_matrix(t) \
+void short_name(t,not_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t ** Y) \
+{                                                        \
+    for (int32_t i = nrl; i <= nrh; i++) {               \
+        short_name(t,not_,vector)(X[i], ncl, nch, Y[i]); \
+    }                                                    \
 }
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) not_si8matrix(sint8 **X, long nrl,long nrh,long ncl, long nch, sint8 **Y)
-/* -------------------------------------------------------------------------------------- */
-{
-	long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        not_si8vector(X[i], ncl, nch, Y[i]);
-    }
-}
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) not_ui8matrix(uint8 **X, long nrl,long nrh,long ncl, long nch, uint8 **Y)
-/* -------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        not_ui8vector(X[i], ncl, nch, Y[i]);
-    }
-}
-/* ----------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) not_si16matrix(sint16 **X, long nrl,long nrh,long ncl, long nch, sint16 **Y)
-/* ----------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        not_si16vector(X[i], ncl, nch, Y[i]);
-    }
-}
-/* ----------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) not_ui16matrix(uint16 **X, long nrl,long nrh,long ncl, long nch, uint16 **Y)
-/* ----------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        not_ui16vector(X[i], ncl, nch, Y[i]);
-    }
-}
-/* ---------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) not_si32matrix(int32 **X, long nrl,long nrh,long ncl, long nch, sint32 **Y)
-/* ---------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        not_si32vector(X[i], ncl, nch, Y[i]);
-    }
-}
-/* ----------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) not_ui32matrix(uint32 **X, long nrl,long nrh,long ncl, long nch, uint32 **Y)
-/* ----------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        not_ui32vector(X[i], ncl, nch, Y[i]);
-    }
-}
-/* --------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) not_rgb8matrix(rgb8 **X, long nrl,long nrh,long ncl, long nch, rgb8 **Y)
-/* --------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        not_rgb8vector(X[i], ncl, nch, Y[i]);
-    }
-}
-/* ------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) not_rgbx8matrix(rgbx8 **X, long nrl,long nrh,long ncl, long nch, rgbx8 **Y)
-/* ------------------------------------------------------------------------------------------ */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        not_rgbx8vector(X[i], ncl, nch, Y[i]);
-    }
-}
+
+not_type_matrix(int8_t);
+not_type_matrix(uint8_t);
+not_type_matrix(int16_t);
+not_type_matrix(uint16_t);
+not_type_matrix(int32_t);
+not_type_matrix(uint32_t);
+not_type_matrix(int64_t);
+not_type_matrix(uint64_t);
+not_type_matrix(rgb8);
+not_type_matrix(rgbx8);
+
+
 
 /*
@@ -222,225 +89,30 @@
  */
 
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) or_bmatrix(byte **X, long nrl,long nrh,long ncl, long nch, byte **Y, byte **Z)
-/* ------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        or_bvector(X[i], ncl, nch, Y[i], Z[i]);
-    }
+#undef or_type_matrix
+#define or_type_matrix(t) \
+void short_name(t,or_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t ** Y, t ** Z) \
+{                                                             \
+    for (int32_t i = nrl; i <= nrh; i++) {                    \
+        short_name(t,or_,vector)(X[i], ncl, nch, Y[i], Z[i]); \
+    }                                                         \
+}                                                             \
+void short_name(t,orc_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t y, t ** Z) \
+{                                                             \
+    for (int32_t i = nrl; i <= nrh; i++) {                    \
+        short_name(t,orc_,vector)(X[i], ncl, nch, y, Z[i]);   \
+    }                                                         \
 }
-/* ------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) or_si8matrix(sint8 **X, long nrl,long nrh,long ncl, long nch, sint8 **Y, sint8 **Z)
-/* ------------------------------------------------------------------------------------------------ */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        or_si8vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* ------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) or_ui8matrix(uint8 **X, long nrl,long nrh,long ncl, long nch, uint8 **Y, uint8 **Z)
-/* ------------------------------------------------------------------------------------------------ */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        or_ui8vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) or_si16matrix(sint16 **X, long nrl,long nrh,long ncl, long nch, sint16 **Y, sint16 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        or_si16vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) or_ui16matrix(uint16 **X, long nrl,long nrh,long ncl, long nch, uint16 **Y, uint16 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        or_ui16vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) or_si32matrix(sint32 **X, long nrl,long nrh,long ncl, long nch, sint32 **Y, sint32 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        or_si32vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) or_ui32matrix(uint32 **X, long nrl,long nrh,long ncl, long nch, uint32 **Y, uint32 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        or_ui32vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) or_si64matrix(sint64 **X, long nrl,long nrh,long ncl, long nch, sint64 **Y, sint64 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        or_si64vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) or_ui64matrix(uint64 **X, long nrl,long nrh,long ncl, long nch, uint64 **Y, uint64 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        or_ui64vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* ---------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) or_rgb8matrix(rgb8 **X, long nrl,long nrh,long ncl, long nch, rgb8 **Y, rgb8 **Z)
-/* ---------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        or_rgb8vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* -------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) or_rgb8xmatrix(rgbx8 **X, long nrl,long nrh,long ncl, long nch, rgbx8 **Y, rgbx8 **Z)
-/* -------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        or_rgbx8vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* ------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) orc_bmatrix(byte **X, long nrl,long nrh,long ncl, long nch, byte y, byte **Z)
-/* ------------------------------------------------------------------------------------------ */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        orc_bvector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) orc_si8matrix(sint8 **X, long nrl,long nrh,long ncl, long nch, sint8 y, sint8 **Z)
-/* ----------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        orc_si8vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) orc_ui8matrix(uint8 **X, long nrl,long nrh,long ncl, long nch, uint8 y, uint8 **Z)
-/* ----------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        orc_ui8vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* -------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) orc_i16matrix(sint16 **X, long nrl,long nrh,long ncl, long nch, sint16 y, sint16 **Z)
-/* -------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        orc_si16vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* --------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) orc_ui16matrix(uint16 **X, long nrl,long nrh,long ncl, long nch, uint16 y, uint16 **Z)
-/* --------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        orc_ui16vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* --------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) orc_si32matrix(sint32 **X, long nrl,long nrh,long ncl, long nch, sint32 y, sint32 **Z)
-/* --------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        orc_si32vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* --------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) orc_ui32matrix(uint32 **X, long nrl,long nrh,long ncl, long nch, uint32 y, uint32 **Z)
-/* --------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        orc_ui32vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* --------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) orc_si64matrix(sint64 **X, long nrl,long nrh,long ncl, long nch, sint64 y, sint64 **Z)
-/* --------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        orc_si64vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* --------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) orc_ui64matrix(uint64 **X, long nrl,long nrh,long ncl, long nch, uint64 y, uint64 **Z)
 
-/* --------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        orc_ui64vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) orc_rgb8matrix(rgb8 **X, long nrl,long nrh,long ncl, long nch, rgb8 y, rgb8 **Z)
-/* --------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        orc_rgb8vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* ------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) orc_rgb8xmatrix(rgbx8 **X, long nrl,long nrh,long ncl, long nch, rgbx8 y, rgbx8 **Z)
-/* ------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        orc_rgbx8vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
+or_type_matrix(int8_t);
+or_type_matrix(uint8_t);
+or_type_matrix(int16_t);
+or_type_matrix(uint16_t);
+or_type_matrix(int32_t);
+or_type_matrix(uint32_t);
+or_type_matrix(int64_t);
+or_type_matrix(uint64_t);
+or_type_matrix(rgb8);
+or_type_matrix(rgbx8);
+
 
 /*
@@ -450,224 +122,29 @@
  */
 
-/* -------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xor_bmatrix(byte **X, long nrl,long nrh,long ncl, long nch, byte **Y, byte **Z)
-/* -------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        xor_bvector(X[i], ncl, nch, Y[i], Z[i]);
-    }
+#undef xor_type_matrix
+#define xor_type_matrix(t) \
+void short_name(t,xor_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t ** Y, t ** Z) \
+{                                                              \
+    for (int32_t i = nrl; i <= nrh; i++) {                     \
+        short_name(t,xor_,vector)(X[i], ncl, nch, Y[i], Z[i]); \
+    }                                                          \
+}                                                              \
+void short_name(t,xorc_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t y, t ** Z) \
+{                                                              \
+    for (int32_t i = nrl; i <= nrh; i++) {                     \
+        short_name(t,xorc_,vector)(X[i], ncl, nch, y, Z[i]);   \
+    }                                                          \
 }
-/* ------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xor_si8matrix(sint8 **X, long nrl,long nrh,long ncl, long nch, sint8 **Y, sint8 **Z)
-/* ------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        xor_si8vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* ------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xor_ui8matrix(uint8 **X, long nrl,long nrh,long ncl, long nch, uint8 **Y, uint8 **Z)
-/* ------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        xor_ui8vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* ----------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xor_si16matrix(sint16 **X, long nrl,long nrh,long ncl, long nch, sint16 **Y, sint16 **Z)
-/* ----------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        xor_si16vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* ----------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xor_ui16matrix(uint16 **X, long nrl,long nrh,long ncl, long nch, uint16 **Y, uint16 **Z)
-/* ----------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        xor_ui16vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* ----------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xor_si32matrix(sint32 **X, long nrl,long nrh,long ncl, long nch, sint32 **Y, sint32 **Z)
-/* ----------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        xor_si32vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* ----------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xor_ui32matrix(uint32 **X, long nrl,long nrh,long ncl, long nch, uint32 **Y, uint32 **Z)
-/* ----------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        xor_ui32vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* ----------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xor_si64matrix(sint64 **X, long nrl,long nrh,long ncl, long nch, sint64 **Y, sint64 **Z)
-/* ----------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        xor_si64vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* ----------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xor_ui64matrix(uint64 **X, long nrl,long nrh,long ncl, long nch, uint64 **Y, uint64 **Z)
-/* ----------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        xor_ui64vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xor_rgb8matrix(rgb8 **X, long nrl,long nrh,long ncl, long nch, rgb8 **Y, rgb8 **Z)
-/* ----------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        xor_rgb8vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* --------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xor_rgb8xmatrix(rgbx8 **X, long nrl,long nrh,long ncl, long nch, rgbx8 **Y, rgbx8 **Z)
-/* --------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        xor_rgbx8vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xorc_bmatrix(byte **X, long nrl,long nrh,long ncl, long nch, byte y, byte **Z)
-/* ------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        xorc_bvector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* ------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) xorc_si8matrix(sint8 **X, long nrl,long nrh,long ncl, long nch, sint8 y, sint8 **Z)
-/* ------------------------------------------------------------------------------------------------ */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        xorc_si8vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* ------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) xorc_ui8matrix(uint8 **X, long nrl,long nrh,long ncl, long nch, uint8 y, uint8 **Z)
-/* ------------------------------------------------------------------------------------------------ */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        xorc_ui8vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* --------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xorc_i16matrix(sint16 **X, long nrl,long nrh,long ncl, long nch, sint16 y, sint16 **Z)
-/* --------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        xorc_si16vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xorc_ui16matrix(uint16 **X, long nrl,long nrh,long ncl, long nch, uint16 y, uint16 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        xorc_ui16vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xorc_si32matrix(sint32 **X, long nrl,long nrh,long ncl, long nch, sint32 y, sint32 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        xorc_si32vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xorc_ui32matrix(uint32 **X, long nrl,long nrh,long ncl, long nch, uint32 y, uint32 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        xorc_ui32vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xorc_si64matrix(sint64 **X, long nrl,long nrh,long ncl, long nch, sint64 y, sint64 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        xorc_si64vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xorc_ui64matrix(uint64 **X, long nrl,long nrh,long ncl, long nch, uint64 y, uint64 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        xorc_ui64vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* ---------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xorc_rgb8matrix(rgb8 **X, long nrl,long nrh,long ncl, long nch, rgb8 y, rgb8 **Z)
-/* ---------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        xorc_rgb8vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* -------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) xorc_rgb8xmatrix(rgbx8 **X, long nrl,long nrh,long ncl, long nch, rgbx8 y, rgbx8 **Z)
-/* -------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        xorc_rgbx8vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
+
+xor_type_matrix(int8_t);
+xor_type_matrix(uint8_t);
+xor_type_matrix(int16_t);
+xor_type_matrix(uint16_t);
+xor_type_matrix(int32_t);
+xor_type_matrix(uint32_t);
+xor_type_matrix(int64_t);
+xor_type_matrix(uint64_t);
+xor_type_matrix(rgb8);
+xor_type_matrix(rgbx8);
 
 
@@ -678,222 +155,38 @@
  */
 
-/* -------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) and_bmatrix(byte **X, long nrl,long nrh,long ncl, long nch, byte **Y, byte **Z)
-/* -------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        and_bvector(X[i], ncl, nch, Y[i], Z[i]);
-    }
+#undef and_type_matrix
+#define and_type_matrix(t) \
+void short_name(t,and_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t ** Y, t ** Z) \
+{                                                              \
+    for (int32_t i = nrl; i <= nrh; i++) {                     \
+        short_name(t,and_,vector)(X[i], ncl, nch, Y[i], Z[i]); \
+    }                                                          \
+}                                                              \
+void short_name(t,andc_,matrix)(t ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t y, t ** Z) \
+{                                                              \
+    for (int32_t i = nrl; i <= nrh; i++) {                     \
+        short_name(t,andc_,vector)(X[i], ncl, nch, y, Z[i]);   \
+    }                                                          \
 }
-/* ------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) and_si8matrix(sint8 **X, long nrl,long nrh,long ncl, long nch, sint8 **Y, sint8 **Z)
-/* ------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        and_si8vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* ------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) and_ui8matrix(uint8 **X, long nrl,long nrh,long ncl, long nch, uint8 **Y, uint8 **Z)
-/* ------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        and_ui8vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* ----------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) and_si16matrix(sint16 **X, long nrl,long nrh,long ncl, long nch, sint16 **Y, sint16 **Z)
-/* ----------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        and_si16vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* ----------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) and_ui16matrix(uint16 **X, long nrl,long nrh,long ncl, long nch, uint16 **Y, uint16 **Z)
-/* ----------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        and_ui16vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* ----------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) and_si32matrix(sint32 **X, long nrl,long nrh,long ncl, long nch, sint32 **Y, sint32 **Z)
-/* ----------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        and_si32vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* ----------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) and_ui32matrix(uint32 **X, long nrl,long nrh,long ncl, long nch, uint32 **Y, uint32 **Z)
-/* ----------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        and_ui32vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* ----------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) and_si64matrix(sint64 **X, long nrl,long nrh,long ncl, long nch, sint64 **Y, sint64 **Z)
-/* ----------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        and_si64vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* ----------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) and_ui64matrix(uint64 **X, long nrl,long nrh,long ncl, long nch, uint64 **Y, uint64 **Z)
-/* ----------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        and_ui64vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) and_rgb8matrix(rgb8 **X, long nrl,long nrh,long ncl, long nch, rgb8 **Y, rgb8 **Z)
-/* ----------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        and_rgb8vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* --------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) and_rgb8xmatrix(rgbx8 **X, long nrl,long nrh,long ncl, long nch, rgbx8 **Y, rgbx8 **Z)
-/* --------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        and_rgbx8vector(X[i], ncl, nch, Y[i], Z[i]);
-    }
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) andc_bmatrix(byte **X, long nrl,long nrh,long ncl, long nch, byte y, byte **Z)
-/* ------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        andc_bvector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* ------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) andc_si8matrix(sint8 **X, long nrl,long nrh,long ncl, long nch, sint8 y, sint8 **Z)
-/* ------------------------------------------------------------------------------------------------ */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        andc_si8vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* ------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) andc_ui8matrix(uint8 **X, long nrl,long nrh,long ncl, long nch, uint8 y, uint8 **Z)
-/* ------------------------------------------------------------------------------------------------ */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        andc_ui8vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* --------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) andc_i16matrix(sint16 **X, long nrl,long nrh,long ncl, long nch, sint16 y, sint16 **Z)
-/* --------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        andc_si16vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) andc_ui16matrix(uint16 **X, long nrl,long nrh,long ncl, long nch, uint16 y, uint16 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        andc_ui16vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) andc_si32matrix(sint32 **X, long nrl,long nrh,long ncl, long nch, sint32 y, sint32 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        andc_si32vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) andc_ui32matrix(uint32 **X, long nrl,long nrh,long ncl, long nch, uint32 y, uint32 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        andc_ui32vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) andc_si64matrix(sint64 **X, long nrl,long nrh,long ncl, long nch, sint64 y, sint64 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        andc_si64vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) andc_ui64matrix(uint64 **X, long nrl,long nrh,long ncl, long nch, uint64 y, uint64 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        andc_ui64vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* ---------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) andc_rgb8matrix(rgb8 **X, long nrl,long nrh,long ncl, long nch, rgb8 y, rgb8 **Z)
-/* ---------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        andc_rgb8vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
-/* -------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) andc_rgb8xmatrix(rgbx8 **X, long nrl,long nrh,long ncl, long nch, rgbx8 y, rgbx8 **Z)
-/* -------------------------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    for(i=nrl; i<=nrh; i++) {
-        andc_rgbx8vector(X[i], ncl, nch, y, Z[i]);
-    }
-}
+
+and_type_matrix(int8_t);
+and_type_matrix(uint8_t);
+and_type_matrix(int16_t);
+and_type_matrix(uint16_t);
+and_type_matrix(int32_t);
+and_type_matrix(uint32_t);
+and_type_matrix(int64_t);
+and_type_matrix(uint64_t);
+and_type_matrix(rgb8);
+and_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/nrhisto.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrhisto.c	(revision 821)
+++ 	(revision )
@@ -1,22 +1,0 @@
-/* ----------------- */
-/* --- nrhisto.c --- */
-/* ----------------- */
-
-/*
- * Copyright (c) 2000-2014, Lionel Lacassagne, All rights reserved
- * Univ Paris Sud XI, CNRS
- * 
- */
-
-/* 
-* 2002/06/11 ajout des fonctions endline
-*/
-#include <stdio.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <math.h> // fabs
-
-#include "mypredef.h"
-#include "nrtype.h"
-#include "nrdef.h"
-#include "nrmacro.h"
Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nrio0.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrio0.c	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrio0.c	(revision 822)
@@ -26,116 +26,128 @@
 
 /* --------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) generate_filename_k_ndigit(char *filename, int k, int ndigit, char *complete_filename, int maxlen)
+void generate_filename_k_ndigit(char * filename, int k, int ndigit, char * complete_filename, int maxlen)
 /* --------------------------------------------------------------------------------------------------- */
 {
-  char *format = "%s%d.txt";
+    char * format = "%s%d.txt";
 
-  switch(ndigit) {
-    case 0 : format = "%s%d.txt";   break;
-    case 1 : format = "%s%01d.txt"; break;
-    case 2 : format = "%s%02d.txt"; break;
-    case 3 : format = "%s%03d.txt"; break;
-    case 4 : format = "%s%04d.txt"; break;
-    case 5 : format = "%s%05d.txt"; break;
-    case 6 : format = "%s%06d.txt"; break;
-    case 7 : format = "%s%07d.txt"; break;
-    case 8 : format = "%s%08d.txt"; break;
-    case 9 : format = "%s%09d.txt"; break;
-  }
-  snprintf(complete_filename, maxlen, format, filename, k);
+    switch (ndigit) {
+        case 0 : format = "%s%d.txt";   break;
+        case 1 : format = "%s%01d.txt"; break;
+        case 2 : format = "%s%02d.txt"; break;
+        case 3 : format = "%s%03d.txt"; break;
+        case 4 : format = "%s%04d.txt"; break;
+        case 5 : format = "%s%05d.txt"; break;
+        case 6 : format = "%s%06d.txt"; break;
+        case 7 : format = "%s%07d.txt"; break;
+        case 8 : format = "%s%08d.txt"; break;
+        case 9 : format = "%s%09d.txt"; break;
+    }
+    snprintf(complete_filename, maxlen, format, filename, k);
 }
 /* ------------------------------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) generate_filename_k_ndigit_extension(char *filename, int k, int ndigit, char *extension, char *complete_filename, int maxlen)
+void generate_filename_k_ndigit_extension(char * filename, int k, int ndigit, char * extension, char * complete_filename, int maxlen)
 /* ------------------------------------------------------------------------------------------------------------------------------------------ */
 {
-  char *format = "%s%d.%s";
+    char * format = "%s%d.%s";
 
-  switch(ndigit) {
-    case 0 : format = "%s%d.%s";   break;
-    case 1 : format = "%s%01d.%s"; break;
-    case 2 : format = "%s%02d.%s"; break;
-    case 3 : format = "%s%03d.%s"; break;
-    case 4 : format = "%s%04d.%s"; break;
-    case 5 : format = "%s%05d.%s"; break;
-    case 6 : format = "%s%06d.%s"; break;
-    case 7 : format = "%s%07d.%s"; break;
-    case 8 : format = "%s%08d.%s"; break;
-    case 9 : format = "%s%09d.%s"; break;
-  }
-  snprintf(complete_filename, maxlen, format, filename, k, extension);
+    switch (ndigit) {
+        case 0 : format = "%s%d.%s";   break;
+        case 1 : format = "%s%01d.%s"; break;
+        case 2 : format = "%s%02d.%s"; break;
+        case 3 : format = "%s%03d.%s"; break;
+        case 4 : format = "%s%04d.%s"; break;
+        case 5 : format = "%s%05d.%s"; break;
+        case 6 : format = "%s%06d.%s"; break;
+        case 7 : format = "%s%07d.%s"; break;
+        case 8 : format = "%s%08d.%s"; break;
+        case 9 : format = "%s%09d.%s"; break;
+    }
+    snprintf(complete_filename, maxlen, format, filename, k, extension);
 }
+
+
 /* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) generate_path_filename(char *path, char *filename, char *complete_filename, int maxlen)
+void generate_path_filename(char * path, char * filename, char * complete_filename, int maxlen)
 /* ---------------------------------------------------------------------------------------------------- */
 {
-  snprintf(complete_filename, maxlen, "%s%s", path, filename);
+    snprintf(complete_filename, maxlen, "%s%s", path, filename);
 }
+
+
 /* ------------------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) generate_path_filename_extension(char *path, char *filename, char *extension, char *complete_filename, int maxlen)
+void generate_path_filename_extension(char * path, char * filename, char * extension, char * complete_filename, int maxlen)
 /* ------------------------------------------------------------------------------------------------------------------------------- */
 {
-  snprintf(complete_filename, maxlen, "%s%s.%s", path, filename, extension);
+    snprintf(complete_filename, maxlen, "%s%s.%s", path, filename, extension);
 }
+
+
 /* ---------------------------------------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) generate_path_filename_suffix_extension(char *path, char *filename, char *suffix, char *extension, char *complete_filename, int maxlen)
+void generate_path_filename_suffix_extension(char * path, char * filename, char * suffix, char * extension, char * complete_filename, int maxlen)
 /* ---------------------------------------------------------------------------------------------------------------------------------------------------- */
 {
     snprintf(complete_filename, maxlen, "%s%s%s.%s", path, filename, suffix, extension);
 }
+
+
 /* ----------------------------------------------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) generate_path_filename_k_ndigit_extension(char *path, char *filename, int k, int ndigit, char *extension, char *complete_filename, int maxlen)
+void generate_path_filename_k_ndigit_extension(char * path, char * filename, int k, int ndigit, char * extension, char * complete_filename, int maxlen)
 /* ----------------------------------------------------------------------------------------------------------------------------------------------------------- */
 {
-  char *format = "%s%s%d.%s";
+    char * format = "%s%s%d.%s";
 
-  switch(ndigit) {
-    case 0 : format = "%s%s%d.%s";   break;
-    case 1 : format = "%s%s%01d.%s"; break;
-    case 2 : format = "%s%s%02d.%s"; break;
-    case 3 : format = "%s%s%03d.%s"; break;
-    case 4 : format = "%s%s%04d.%s"; break;
-    case 5 : format = "%s%s%05d.%s"; break;
-    case 6 : format = "%s%s%06d.%s"; break;
-    case 7 : format = "%s%s%07d.%s"; break;
-    case 8 : format = "%s%s%08d.%s"; break;
-    case 9 : format = "%s%s%09d.%s"; break;
-  }
-  snprintf(complete_filename, maxlen, format, path, filename, k, extension);
+    switch(ndigit) {
+        case 0 : format = "%s%s%d.%s";   break;
+        case 1 : format = "%s%s%01d.%s"; break;
+        case 2 : format = "%s%s%02d.%s"; break;
+        case 3 : format = "%s%s%03d.%s"; break;
+        case 4 : format = "%s%s%04d.%s"; break;
+        case 5 : format = "%s%s%05d.%s"; break;
+        case 6 : format = "%s%s%06d.%s"; break;
+        case 7 : format = "%s%s%07d.%s"; break;
+        case 8 : format = "%s%s%08d.%s"; break;
+        case 9 : format = "%s%s%09d.%s"; break;
+    }
+    snprintf(complete_filename, maxlen, format, path, filename, k, extension);
 }
+
+
 /* -------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) generate_path_filename_k_ndigit_l_extension(char *path, char *filename, int k, int ndigit, int l, char *extension, char *complete_filename, int maxlen)
+void generate_path_filename_k_ndigit_l_extension(char * path, char * filename, int k, int ndigit, int l, char * extension, char * complete_filename, int maxlen)
 /* -------------------------------------------------------------------------------------------------------------------------------------------------------------------- */
 {
-  char *format = "%s%s%d_%d.%s";
+    char * format = "%s%s%d_%d.%s";
 
-  switch(ndigit) {
-    case 0 : format = "%s%s%d_%d.%s";   break;
-    case 1 : format = "%s%s%01d_%01d.%s"; break;
-    case 2 : format = "%s%s%02d_%02d.%s"; break;
-    case 3 : format = "%s%s%03d_%03d.%s"; break;
-    case 4 : format = "%s%s%04d_%04d.%s"; break;
-    case 5 : format = "%s%s%05d_%05d.%s"; break;
-    case 6 : format = "%s%s%06d_%06d.%s"; break;
-    case 7 : format = "%s%s%07d_%07d.%s"; break;
-    case 8 : format = "%s%s%08d_%08d.%s"; break;
-    case 9 : format = "%s%s%09d_%09d.%s"; break;
-  }
-  snprintf(complete_filename, maxlen, format, path, filename, k, l, extension);
+    switch (ndigit) {
+        case 0 : format = "%s%s%d_%d.%s";     break;
+        case 1 : format = "%s%s%01d_%01d.%s"; break;
+        case 2 : format = "%s%s%02d_%02d.%s"; break;
+        case 3 : format = "%s%s%03d_%03d.%s"; break;
+        case 4 : format = "%s%s%04d_%04d.%s"; break;
+        case 5 : format = "%s%s%05d_%05d.%s"; break;
+        case 6 : format = "%s%s%06d_%06d.%s"; break;
+        case 7 : format = "%s%s%07d_%07d.%s"; break;
+        case 8 : format = "%s%s%08d_%08d.%s"; break;
+        case 9 : format = "%s%s%09d_%09d.%s"; break;
+    }
+    snprintf(complete_filename, maxlen, format, path, filename, k, l, extension);
 }
-// ----------------------------------------------------------------------------
-void select_display_positive_parameters(int iformat, char **format, char **str)
-// ----------------------------------------------------------------------------
+
+
+// ------------------------------------------------------------------------------
+void select_display_positive_parameters(int iformat, char ** format, char ** str)
+// ------------------------------------------------------------------------------
 {
-    char *format1 = "%1d", *str1 = " ";
-    char *format2 = "%2d", *str2 = "  ";
-    char *format3 = "%3d", *str3 = "   ";
-    char *format4 = "%4d", *str4 = "    ";
-    char *format5 = "%5d", *str5 = "     ";
-    char *format6 = "%6d", *str6 = "      ";
-    char *format7 = "%7d", *str7 = "       ";
-    char *format8 = "%8d", *str8 = "        ";
-    char *format9 = "%9d", *str9 = "         ";
-    
-    switch(iformat) {
+    char * format1 = "%1d", * str1 = " ";
+    char * format2 = "%2d", * str2 = "  ";
+    char * format3 = "%3d", * str3 = "   ";
+    char * format4 = "%4d", * str4 = "    ";
+    char * format5 = "%5d", * str5 = "     ";
+    char * format6 = "%6d", * str6 = "      ";
+    char * format7 = "%7d", * str7 = "       ";
+    char * format8 = "%8d", * str8 = "        ";
+    char * format9 = "%9d", * str9 = "         ";
+
+    switch (iformat) {
         case 1:  *format = format1; *str = str1; break;
         case 2:  *format = format2; *str = str2; break;
@@ -150,2 +162,12 @@
     }
 }
+
+// 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/nrio1.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrio1.c	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrio1.c	(revision 822)
@@ -33,173 +33,30 @@
  */
 
-/* ------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_bvector(byte *v,long nl,long nh, char *format, char *name)
-/* ------------------------------------------------------------------------------- */
-{
-  long i;
-
-  if(name != NULL) printf("%s", name);
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, v[i]);
-  }
-  printf("\n");
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_si8vector(sint8 *v,long nl,long nh, char *format, char *name)
-/* ---------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    if(name != NULL) printf("%s", name);
-    
-    for(i=nl; i<=nh; i++) {
-        printf(format, v[i]);
-    }
-    printf("\n");
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui8vector(uint8 *v,long nl,long nh, char *format, char *name)
-/* ---------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    if(name != NULL) printf("%s", name);
-    
-    for(i=nl; i<=nh; i++) {
-        printf(format, v[i]);
-    }
-    printf("\n");
-}
-/* ------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_si16vector(sint16 *v,long nl,long nh, char *format, char *name)
-/* ------------------------------------------------------------------------------------ */
-{
-  long i;
-
-  if(name != NULL) printf("%s", name);
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, v[i]);
-  }
-  printf("\n");
-}
-/* ------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui16vector(uint16 *v,long nl,long nh, char *format, char *name)
-/* ------------------------------------------------------------------------------------- */
-{
-  long i;
-
-  if(name != NULL) printf("%s", name);
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, v[i]);
-  }
-  printf("\n");
-}
-/* ------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_si32vector(sint32 *v,long nl,long nh, char *format, char *name)
-/* ------------------------------------------------------------------------------------ */
-{
-  long i;
-
-  if(name != NULL) printf("%s", name);
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, v[i]);
-  }
-  printf("\n");
-}
-/* ------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_ui32vector(uint32 *v,long nl,long nh, char *format, char *name)
-/* ------------------------------------------------------------------------------------ */
-{
-  long i;
-
-  if(name != NULL) printf("%s", name);
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, v[i]);
-  }
-  printf("\n");
-}
-/* ------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_si64vector(sint64 *v,long nl,long nh, char *format, char *name)
-/* ------------------------------------------------------------------------------------ */
-{
-  long i;
-
-  if(name != NULL) printf("%s", name);
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, v[i]);
-  }
-  printf("\n");
-}
-/* ------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_ui64vector(uint64 *v,long nl,long nh, char *format, char *name)
-/* ------------------------------------------------------------------------------------ */
-{
-  long i;
-
-  if(name != NULL) printf("%s", name);
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, v[i]);
-  }
-  printf("\n");
-}
-/* ------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_f32vector(float32 *v,long nl,long nh, char *format, char *name)
-/* ------------------------------------------------------------------------------------ */
-{
-    long i;
-    
-    if(name != NULL) printf("%s", name);
-    
-    for(i=nl; i<=nh; i++) {
-        printf(format, v[i]);
-    }
-    printf("\n");
-}
-/* ------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_f64vector(float64 *v,long nl,long nh, char *format, char *name)
-/* ------------------------------------------------------------------------------------ */
-{
-    long i;
-    
-    if(name != NULL) printf("%s", name);
-    
-    for(i=nl; i<=nh; i++) {
-        printf(format, v[i]);
-    }
-    printf("\n");
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_rgb8vector(rgb8 *v,long nl,long nh, char *format, char *name)
-/* ---------------------------------------------------------------------------------- */
-{
-    long i;
-    
-    if(name != NULL) printf("%s", name);
-    
-    for(i=nl; i<=nh; i++) {
-        printf(format, v[i]);
-    }
-    printf("\n");
-}
-/* ------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_rgbx8vector(rgbx8 *v,long nl,long nh, char *format, char *name)
-/* ------------------------------------------------------------------------------------ */
-{
-    long i;
-    
-    if(name != NULL) printf("%s", name);
-    
-    for(i=nl; i<=nh; i++) {
-        printf(format, v[i]);
-    }
-    printf("\n");
-}
+#undef display_type_vector
+#define display_type_vector(t) \
+void short_name(t,display_,vector)(t * v, int32_t nl, int32_t nh, char * format, char * name) \
+{                                        \
+    if (name != NULL) {                  \
+        printf("%s", name);              \
+    }                                    \
+    for (int32_t i = nl; i <= nh; i++) { \
+        printf(format, v[i]);            \
+    }                                    \
+    printf("\n");                        \
+}
+
+display_type_vector(int8_t);
+display_type_vector(uint8_t);
+display_type_vector(int16_t);
+display_type_vector(uint16_t);
+display_type_vector(int32_t);
+display_type_vector(uint32_t);
+display_type_vector(int64_t);
+display_type_vector(uint64_t);
+display_type_vector(float);
+display_type_vector(double);
+display_type_vector(rgb8);
+display_type_vector(rgbx8);
+
 
 /*
@@ -209,236 +66,36 @@
  */
 
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_bvector_number(byte *v,long nl,long nh, char *format, char *name)
-/* -------------------------------------------------------------------------------------- */
-{
-  long i;
-
-  if(name != NULL) printf("%s\n", name);
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, i);
-  }
-  printf("\n");
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, v[i]);
-  }
-  printf("\n");
-}
-/* ----------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_si8vector_number(sint8 *v,long nl,long nh, char *format, char *name)
-/* ----------------------------------------------------------------------------------------- */
-{
-  long i;
-
-  if(name != NULL) printf(name);
-  for(i=nl; i<=nh; i++) {
-    printf(format, i);
-  }
-  printf("\n");
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, v[i]);
-  }
-  printf("\n");
-}
-/* ----------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui8vector_number(uint8 *v,long nl,long nh, char *format, char *name)
-/* ----------------------------------------------------------------------------------------- */
-{
-  long i;
-
-  if(name != NULL) printf(name);
-  for(i=nl; i<=nh; i++) {
-    printf(format, i);
-  }
-  printf("\n");
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, v[i]);
-  }
-  printf("\n");
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_si16vector_number(sint16 *v,long nl,long nh, char *format, char *name)
-/* ------------------------------------------------------------------------------------------- */
-{
-  long i;
-
-  if(name != NULL) printf(name);
-  for(i=nl; i<=nh; i++) {
-    printf(format, i);
-  }
-  printf("\n");
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, v[i]);
-  }
-  printf("\n");
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui16vector_number(uint16 *v,long nl,long nh, char *format, char *name)
-/* ------------------------------------------------------------------------------------------- */
-{
-  long i;
-
-  if(name != NULL) printf(name);
-  for(i=nl; i<=nh; i++) {
-    printf(format, i);
-  }
-  printf("\n");
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, v[i]);
-  }
-  printf("\n");
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_si32vector_number(sint32 *v,long nl,long nh, char *format, char *name)
-/* ------------------------------------------------------------------------------------------- */
-{
-  long i;
-
-  if(name != NULL) printf("%s\n", name);
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, i);
-  }
-  printf("\n");
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, v[i]);
-  }
-  printf("\n");
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui32vector_number(uint32 *v,long nl,long nh, char *format, char *name)
-/* ------------------------------------------------------------------------------------------- */
-{
-  long i;
-
-  if(name != NULL) printf("%s\n", name);
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, i);
-    printf(" ");
-  }
-  printf("\n");
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, v[i]);
-    printf(" ");
-  }
-  printf("\n");
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_si64vector_number(sint64 *v,long nl,long nh, char *format, char *name)
-/* ------------------------------------------------------------------------------------------- */
-{
-  long i;
-
-  if(name != NULL) printf("%s\n", name);
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, i);
-  }
-  printf("\n");
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, v[i]);
-  }
-  printf("\n");
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui64vector_number(uint64 *v,long nl,long nh, char *format, char *name)
-/* ------------------------------------------------------------------------------------------- */
-{
-  long i;
-
-  if(name != NULL) printf("%s\n", name);
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, i);
-  }
-  printf("\n");
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, v[i]);
-  }
-  printf("\n");
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_f32vector_number(float32 *v,long nl,long nh, char *format, char *name)
-/* ------------------------------------------------------------------------------------------- */
-{
-  long i;
-
-  if(name != NULL) printf("%s\n", name);
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, i);
-  }
-  printf("\n");
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, v[i]);
-  }
-  printf("\n");
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_f64vector_number(float64 *v,long nl,long nh, char *format, char *name)
-/* ------------------------------------------------------------------------------------------- */
-{
-  long i;
-
-  if(name != NULL) printf("%s\n", name);
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, i);
-  }
-  printf("\n");
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, v[i]);
-  }
-  printf("\n");
-}
-/* ----------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_rgb8vector_number(rgb8 *v,long nl,long nh, char *format, char *name)
-/* ----------------------------------------------------------------------------------------- */
-{
-  long i;
-
-  if(name != NULL) printf("%s\n", name);
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, i);
-  }
-  printf("\n");
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, v[i]);
-  }
-  printf("\n");
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_rgbx8vector_number(rgbx8 *v,long nl,long nh, char *format, char *name)
-/* ------------------------------------------------------------------------------------------- */
-{
-  long i;
-
-  if(name != NULL) printf("%s\n", name);
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, i);
-  }
-  printf("\n");
-
-  for(i=nl; i<=nh; i++) {
-    printf(format, v[i]);
-  }
-  printf("\n");
-}
+#undef display_type_vector_number
+#define display_type_vector_number(t) \
+void short_name(t,display_,vector_number)(t * v, int32_t nl, int32_t nh, char * format, char * name) \
+{                                        \
+    if (name != NULL) {                  \
+        printf("%s\n", name);            \
+    }                                    \
+    for (int32_t i = nl; i <= nh; i++) { \
+        printf(format, i);               \
+    }                                    \
+    printf("\n");                        \
+    for (int32_t i = nl; i <= nh; i++) { \
+        printf(format, v[i]);            \
+    }                                    \
+    printf("\n");                        \
+}
+
+
+display_type_vector_number(int8_t);
+display_type_vector_number(uint8_t);
+display_type_vector_number(int16_t);
+display_type_vector_number(uint16_t);
+display_type_vector_number(int32_t);
+display_type_vector_number(uint32_t);
+display_type_vector_number(int64_t);
+display_type_vector_number(uint64_t);
+display_type_vector_number(float);
+display_type_vector_number(double);
+display_type_vector_number(rgb8);
+display_type_vector_number(rgbx8);
+
+
 /*
  * ------------------------
@@ -447,160 +104,32 @@
  */
 
-/* ----------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_si8vector_T(sint8 *v,int i0, int i1, char *format, char *name)
-/* ----------------------------------------------------------------------------------- */
-{
-    int i;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {           
-        printf(format, v[i]);
-        printf("\n");
-    }
-}
-/* ----------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui8vector_T(uint8 *v,int i0, int i1, char *format, char *name)
-/* ----------------------------------------------------------------------------------- */
-{
-    int i;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {           
-        printf(format, v[i]);
-        printf("\n");
-    }
-}
-/* ------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_si16vector_T(sint16 *v,int i0, int i1, char *format, char *name)
-/* ------------------------------------------------------------------------------------- */
-{
-    int i;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {           
-        printf(format, v[i]);
-        printf("\n");
-    }
-}
-/* ------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui16vector_T(uint16 *v,int i0, int i1, char *format, char *name)
-/* ------------------------------------------------------------------------------------- */
-{
-    int i;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {           
-        printf(format, v[i]);
-        printf("\n");
-    }
-}
-/* ------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_si32vector_T(sint32 *v,int i0, int i1, char *format, char *name)
-/* ------------------------------------------------------------------------------------- */
-{
-    int i;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {           
-        printf(format, v[i]);
-        printf("\n");
-    }
-}
-/* ------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui32vector_T(uint32 *v,int i0, int i1, char *format, char *name)
-/* ------------------------------------------------------------------------------------- */
-{
-    int i;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {           
-        printf(format, v[i]);
-        printf("\n");
-    }
-}
-/* ------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_si64vector_T(sint64 *v,int i0, int i1, char *format, char *name)
-/* ------------------------------------------------------------------------------------- */
-{
-    int i;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {           
-        printf(format, v[i]);
-        printf("\n");
-    }
-}
-/* ------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui64vector_T(uint64 *v,int i0, int i1, char *format, char *name)
-/* ------------------------------------------------------------------------------------- */
-{
-    int i;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {           
-        printf(format, v[i]);
-        printf("\n");
-    }
-}
-/* ------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_f32vector_T(float32 *v,int i0, int i1, char *format, char *name)
-/* ------------------------------------------------------------------------------------- */
-{
-    int i;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {           
-        printf(format, v[i]);
-        printf("\n");
-    }
-}
-/* ------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_f64vector_T(float64 *v,int i0, int i1, char *format, char *name)
-/* ------------------------------------------------------------------------------------- */
-{
-    int i;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {           
-        printf(format, v[i]);
-        printf("\n");
-    }
-}
-/* ----------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_rgb8vector_T(rgb8 *v,int i0, int i1, char *format, char *name)
-/* ----------------------------------------------------------------------------------- */
-{
-    int i;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {           
-        printf(format, v[i]);
-        printf("\n");
-    }
-}
-/* ------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_rgbx8vector_T(rgbx8 *v,int i0, int i1, char *format, char *name)
-/* ------------------------------------------------------------------------------------- */
-{
-    int i;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {           
-        printf(format, v[i]);
-        printf("\n");
-    }
-}
+
+#undef display_type_vector_T
+#define display_type_vector_T(t) \
+void short_name(t,display_,vector_T)(t * v, int32_t i0, int32_t i1, char * format, char * name) \
+{                                        \
+    if (name != NULL) {                  \
+        printf("%s", name);              \
+    }                                    \
+    for (int32_t i = i0; i <= i1; i++) { \
+        printf(format, v[i]);            \
+        printf("\n");                    \
+    }                                    \
+    printf("\n");                        \
+}
+
+display_type_vector_T(int8_t);
+display_type_vector_T(uint8_t);
+display_type_vector_T(int16_t);
+display_type_vector_T(uint16_t);
+display_type_vector_T(int32_t);
+display_type_vector_T(uint32_t);
+display_type_vector_T(int64_t);
+display_type_vector_T(uint64_t);
+display_type_vector_T(float);
+display_type_vector_T(double);
+display_type_vector_T(rgb8);
+display_type_vector_T(rgbx8);
+
 
 /*
@@ -610,172 +139,33 @@
  */
 
-/* ------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_si8vector_number_T(sint8 *v,int i0, int i1, char *format, char *name)
-/* ------------------------------------------------------------------------------------------ */
-{
-    int i;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {
-        printf("%8d ", i);
-        printf(format, v[i]);
-        printf("\n");
-    }
-}
-/* ------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_ui8vector_number_T(uint8 *v,int i0, int i1, char *format, char *name)
-/* ------------------------------------------------------------------------------------------ */
-{
-    int i;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {
-        printf("%8d ", i);
-        printf(format, v[i]);
-        printf("\n");
-    }
-}
-/* -------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_si16vector_number_T(sint16 *v,int i0, int i1, char *format, char *name)
-/* -------------------------------------------------------------------------------------------- */
-{
-    int i;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {           
-        printf("%8d ", i);
-        printf(format, v[i]);
-        printf("\n");
-    }
-}
-/* -------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui16vector_number_T(uint16 *v,int i0, int i1, char *format, char *name)
-/* -------------------------------------------------------------------------------------------- */
-{
-    int i;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {
-        printf("%8d ", i);
-        printf(format, v[i]);
-        printf("\n");
-    }
-}
-/* -------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_si32vector_number_T(sint32 *v,int i0, int i1, char *format, char *name)
-/* -------------------------------------------------------------------------------------------- */
-{
-    int i;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {           
-        printf("%8d ", i);
-        printf(format, v[i]);
-        printf("\n");
-    }
-}
-/* -------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui32vector_number_T(uint32 *v,int i0, int i1, char *format, char *name)
-/* -------------------------------------------------------------------------------------------- */
-{
-    int i;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {           
-        printf("%8d ", i);
-        printf(format, v[i]);
-        printf("\n");
-    }
-}
-/* -------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_si64vector_number_T(sint64 *v,int i0, int i1, char *format, char *name)
-/* -------------------------------------------------------------------------------------------- */
-{
-    int i;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {           
-        printf("%8d ", i);
-        printf(format, v[i]);
-        printf("\n");
-    }
-}
-/* -------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui64vector_number_T(uint64 *v,int i0, int i1, char *format, char *name)
-/* -------------------------------------------------------------------------------------------- */
-{
-    int i;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {           
-        printf("%8d ", i);
-        printf(format, v[i]);
-        printf("\n");
-    }
-}
-/* -------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_f32vector_number_T(float32 *v,int i0, int i1, char *format, char *name)
-/* -------------------------------------------------------------------------------------------- */
-{
-    int i;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {  
-        printf("%8d ", i);
-        printf(format, v[i]);
-        printf("\n");
-    }
-}
-/* -------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_f64vector_number_T(float64 *v,int i0, int i1, char *format, char *name)
-/* -------------------------------------------------------------------------------------------- */
-{
-    int i;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {           
-        printf("%8d ", i);
-        printf(format, v[i]);
-        printf("\n");
-    }
-}
-/* ------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_rgb8vector_number_T(rgb8 *v,int i0, int i1, char *format, char *name)
-/* ------------------------------------------------------------------------------------------ */
-{
-    int i;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {           
-        printf("%8d ", i);
-        printf(format, v[i]);
-        printf("\n");
-    }
-}
-/* -------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_rgbx8vector_number_T(rgbx8 *v,int i0, int i1, char *format, char *name)
-/* -------------------------------------------------------------------------------------------- */
-{
-    int i;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {           
-        printf("%8d ", i);
-        printf(format, v[i]);
-        printf("\n");
-    }
-}
+
+#undef display_type_vector_number_T
+#define display_type_vector_number_T(t) \
+void short_name(t,display_,vector_number_T)(t * v, int32_t i0, int32_t i1, char * format, char * name) \
+{                                        \
+    if (name != NULL) {                  \
+        printf("%s", name);              \
+    }                                    \
+    for (int32_t i = i0; i <= i1; i++) { \
+        printf("%8d ", i);               \
+        printf(format, v[i]);            \
+        printf("\n");                    \
+    }                                    \
+    printf("\n");                        \
+}
+
+display_type_vector_number_T(int8_t);
+display_type_vector_number_T(uint8_t);
+display_type_vector_number_T(int16_t);
+display_type_vector_number_T(uint16_t);
+display_type_vector_number_T(int32_t);
+display_type_vector_number_T(uint32_t);
+display_type_vector_number_T(int64_t);
+display_type_vector_number_T(uint64_t);
+display_type_vector_number_T(float);
+display_type_vector_number_T(double);
+display_type_vector_number_T(rgb8);
+display_type_vector_number_T(rgbx8);
+
 
 /*
@@ -785,63 +175,44 @@
  */
 
-// -------------------------------------------------------------------------------
-void display_ui8vector_positive(uint8 *v, int j0, int j1, int iformat, char *name)
-// -------------------------------------------------------------------------------
-{
-    int j;
-    char *format, *str;
-    
-    select_display_positive_parameters(iformat, &format, &str);
-    
-    if(name != NULL) printf(name);
-    
-    for(j=j0; j<=j1; j++) {
-        if(v[j]) {
-            printf(format, v[j]);
-        } else {
-            printf("%s", str);
-        }
-    }
-    printf("\n");
-}
-
-// ---------------------------------------------------------------------------------
-void display_ui16vector_positive(uint16 *v, int j0, int j1, int iformat, char *name)
-// ---------------------------------------------------------------------------------
-{
-    int j;
-    char *format, *str;
-    
-    select_display_positive_parameters(iformat, &format, &str);
-    
-    if(name != NULL) printf(name);
-    
-    for(j=j0; j<=j1; j++) {
-        if(v[j]) {
-            printf(format, v[j]);
-        } else {
-            printf("%s", str);
-        }
-    }
-    printf("\n");
-}
-// ---------------------------------------------------------------------------------
-void display_ui32vector_positive(uint32 *v, int j0, int j1, int iformat, char *name)
-// ---------------------------------------------------------------------------------
-{
-    int j;
-    char *format, *str;
-    
-    select_display_positive_parameters(iformat, &format, &str);
-    
-    if(name != NULL) printf(name);
-    
-    for(j=j0; j<=j1; j++) {
-        if(v[j]) {
-            printf(format, v[j]);
-        } else {
-            printf("%s", str);
-        }
-    }
-    printf("\n");
-}
+#undef display_type_vector_positive
+#define display_type_vector_positive(t) \
+void short_name(t,display_,vector_positive)(t * v, int32_t j0, int32_t j1, int32_t iformat, char * name) \
+{                                                               \
+    char * format;                                              \
+    char * str;                                                 \
+    select_display_positive_parameters(iformat, &format, &str); \
+    if (name != NULL) {                                         \
+        printf(name);                                           \
+    }                                                           \
+    for (int32_t j = j0; j <= j1; j++) {                        \
+        if (v[j] != 0) {                                        \
+            printf(format, v[j]);                               \
+        }                                                       \
+        else {                                                  \
+            printf("%s", str);                                  \
+        }                                                       \
+    }                                                           \
+    printf("\n");                                               \
+}
+
+
+display_type_vector_positive(int8_t);
+display_type_vector_positive(uint8_t);
+display_type_vector_positive(int16_t);
+display_type_vector_positive(uint16_t);
+display_type_vector_positive(int32_t);
+display_type_vector_positive(uint32_t);
+display_type_vector_positive(int64_t);
+display_type_vector_positive(uint64_t);
+display_type_vector_positive(float);
+display_type_vector_positive(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/nrio1f.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrio1f.c	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrio1f.c	(revision 822)
@@ -16,4 +16,5 @@
 #include <stdlib.h>
 
+#include "nrc_os_config.h"
 #include "mypredef.h"
 #include "nrtype.h"
@@ -31,149 +32,63 @@
  * --------------------
  */
-/* ------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) write_si8vector(sint8 *v,long nl,long nh, char *format, char *filename)
-/* ------------------------------------------------------------------------------------ */
-{
-  long  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_si8vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) write_ui8vector(uint8 *v,long nl,long nh, char *format, char *filename)
-/* ------------------------------------------------------------------------------------ */
-{
-  long  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_ui8vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
-  fclose(f);
+
+#undef write_type_vector
+#define write_type_vector(t) \
+void short_name(t,write_,vector)(t * v, int32_t nl, int32_t nh, char * format, char * filename) \
+{                                                                  \
+    FILE * f = fopen(filename, "wt");                              \
+    if (f == NULL) {                                               \
+        nrerror("Can't open file %s in %s\n", filename, __func__); \
+    }                                                              \
+    for (int32_t k = nl; k <= nh; k++) {                           \
+        fprintf(f, format, v[k]);                                  \
+    }                                                              \
+    fprintf(f, "\n");                                              \
+    fclose(f);                                                     \
+}
+
+write_type_vector(int8_t);
+write_type_vector(uint8_t);
+write_type_vector(int16_t);
+write_type_vector(uint16_t);
+write_type_vector(int32_t);
+write_type_vector(uint32_t);
+write_type_vector(int64_t);
+write_type_vector(uint64_t);
+write_type_vector(float);
+write_type_vector(double);
+
+
+/* ---------------------------------------------------------------------------------- */
+void write_rgb8vector(rgb8 * v,int32_t nl, int32_t nh, char * format, char * filename)
+/* ---------------------------------------------------------------------------------- */
+{
+    FILE * f = fopen(filename, "wt");
+    if (f == NULL) {
+        nrerror("Can't open file %s in %s\n", filename, __func__); \
+    }
+    for (int32_t k = nl; k <= nh; k++) {
+        fprintf(f, format, v[k].r, v[k].g, v[k].b);
+    }
+    fprintf(f, "\n");
+    fclose(f);
 }
 
 /* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_si16vector(sint16 *v,long nl,long nh, char *format, char *filename)
+void write_rgbx8vector(rgbx8 * v, int32_t nl, int32_t nh, char * format, char * filename)
 /* -------------------------------------------------------------------------------------- */
 {
-  long  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_si16vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
-  fclose(f);
-}
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui16vector(uint16 *v,long nl,long nh, char *format, char *filename)
-/* -------------------------------------------------------------------------------------- */
-{
-  long  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_ui16vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
-  fclose(f);
-}
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_si32vector(sint32 *v,long nl,long nh, char *format, char *filename)
-/* -------------------------------------------------------------------------------------- */
-{
-  long  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_si32vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
-  fclose(f);
-}
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui32vector(uint32 *v,long nl,long nh, char *format, char *filename)
-/* -------------------------------------------------------------------------------------- */
-{
-  long  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_ui32vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
-  fclose(f);
-}
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_si64vector(sint64 *v,long nl,long nh, char *format, char *filename)
-/* -------------------------------------------------------------------------------------- */
-{
-  long  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_si64vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_i64vector(uint64 *v,long nl,long nh, char *format, char *filename)
-/* ------------------------------------------------------------------------------------- */
-{
-  long  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_ui64vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
-  fclose(f);
-}
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_f32vector(float32 *v,long nl,long nh, char *format, char *filename)
-/* -------------------------------------------------------------------------------------- */
-{
-  long  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_f32vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
-  fclose(f);
-}
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_f64vector(float64 *v,long nl,long nh, char *format, char *filename)
-/* -------------------------------------------------------------------------------------- */
-{
-  long  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_f64vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
-  fclose(f);
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_rgb8vector(rgb8 *v,long nl,long nh, char *format, char *filename)
-/* ---------------------------------------------------------------------------------- */
-{
-  long  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_rgb8vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k].r, v[k].g, v[k].b); } fputc('\n', f);
-  fclose(f);
-}
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_rgbx8vector(rgbx8 *v,long nl,long nh, char *format, char *filename)
-/* -------------------------------------------------------------------------------------- */
-{
-  long  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_rgbx8vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k].r, v[k].g, v[k].b); } fputc('\n', f);
-  fclose(f);
-}
+    FILE * f = fopen(filename, "wt");
+    if (f == NULL) {
+        nrerror("Can't open file %s in %s\n", filename, __func__); \
+    }
+    for (int32_t k = nl; k <= nh; k++) {
+        fprintf(f, format, v[k].r, v[k].g, v[k].b);
+    }
+    fprintf(f, "\n");
+    fclose(f);
+}
+
+
 /*
  * ----------------------
@@ -181,124 +96,62 @@
  * ----------------------
  */
+
+#undef write_type_vector_T
+#define write_type_vector_T(t) \
+void short_name(t,write_,vector_T)(t * v, int32_t nl, int32_t nh, char * format, char * filename) \
+{                                                                  \
+    FILE * f = fopen(filename, "wt");                              \
+    if (f == NULL) {                                               \
+        nrerror("Can't open file %s in %s\n", filename, __func__); \
+    }                                                              \
+    for (int32_t k = nl; k <= nh; k++) {                           \
+        fprintf(f, format, v[k]);                                  \
+        fprintf(f, "\n");                                          \
+    }                                                              \
+    fclose(f);                                                     \
+}
+
+write_type_vector_T(int8_t);
+write_type_vector_T(uint8_t);
+write_type_vector_T(int16_t);
+write_type_vector_T(uint16_t);
+write_type_vector_T(int32_t);
+write_type_vector_T(uint32_t);
+write_type_vector_T(int64_t);
+write_type_vector_T(uint64_t);
+write_type_vector_T(float);
+write_type_vector_T(double);
+
+
+/* ---------------------------------------------------------------------------------- */
+void write_rgb8vector_T(rgb8 * v,int32_t nl, int32_t nh, char * format, char * filename)
+/* ---------------------------------------------------------------------------------- */
+{
+    FILE * f = fopen(filename, "wt");
+    if (f == NULL) {
+        nrerror("Can't open file %s in %s\n", filename, __func__); \
+    }
+    for (int32_t k = nl; k <= nh; k++) {
+        fprintf(f, format, v[k].r, v[k].g, v[k].b);
+        fprintf(f, "\n");
+    }
+    fclose(f);
+}
+
 /* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_si8vector_T(sint8 *v,long nl,long nh, char *format, char *filename)
+void write_rgbx8vector_T(rgbx8 * v, int32_t nl, int32_t nh, char * format, char * filename)
 /* -------------------------------------------------------------------------------------- */
 {
-  long  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_si8vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); fputc('\n', f); }
-  fclose(f);
-}
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui8vector_T(uint8 *v,long nl,long nh, char *format, char *filename)
-/* -------------------------------------------------------------------------------------- */
-{
-  long  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_ui8vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); fputc('\n', f); }
-  fclose(f);
-}
-/* ---------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_si16vector_T(sint16 *v,long nl,long nh, char *format, char *filename)
-/* ---------------------------------------------------------------------------------------- */
-{
-  long  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_si16vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); fputc('\n', f); }
-  fclose(f);
-}
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui16vector_T(uint16 *v,long nl,long nh, char *format, char *filename)
-/* -------------------------------------------------------------------------------------- */
-{
-  long  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_ui16vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); fputc('\n', f); }
-  fclose(f);
-}
-/* ---------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_si32vector_T(sint32 *v,long nl,long nh, char *format, char *filename)
-/* ---------------------------------------------------------------------------------------- */
-{
-  long  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_si32vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); fputc('\n', f); }
-  fclose(f);
-}
-/* ---------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui32vector_T(uint32 *v,long nl,long nh, char *format, char *filename)
-/* ---------------------------------------------------------------------------------------- */
-{
-  long  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_ui32vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); fputc('\n', f); }
-  fclose(f);
-}
-/* ---------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_si64vector_T(sint64 *v,long nl,long nh, char *format, char *filename)
-/* ---------------------------------------------------------------------------------------- */
-{
-  long  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_si64vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); fputc('\n', f); }
-  fclose(f);
-}
-/* ---------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui64vector_T(uint64 *v,long nl,long nh, char *format, char *filename)
-/* ---------------------------------------------------------------------------------------- */
-{
-  long  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_ui64vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); fputc('\n', f); }
-  fclose(f);
-}
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_rgb8vector_T(rgb8 *v,long nl,long nh, char *format, char *filename)
-/* -------------------------------------------------------------------------------------- */
-{
-  long  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_rgb8vector_T"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k].r, v[k].g, v[k].b); fputc('\n', f); }
-  fclose(f);
-}
-/* ---------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_rgbx8vector_T(rgbx8 *v,long nl,long nh, char *format, char *filename)
-/* ---------------------------------------------------------------------------------------- */
-{
-  long  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_rgbx8vector_T"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k].r, v[k].g, v[k].b); fputc('\n', f); }
-  fclose(f);
-}
+    FILE * f = fopen(filename, "wt");
+    if (f == NULL) {
+        nrerror("Can't open file %s in %s\n", filename, __func__); \
+    }
+    for (int32_t k = nl; k <= nh; k++) {
+        fprintf(f, format, v[k].r, v[k].g, v[k].b);
+        fprintf(f, "\n");
+    }
+    fclose(f);
+}
+
 
 /*
@@ -307,160 +160,77 @@
  * ---------------------------
  */
+
+// @QM : fprintf(f, format, k, k, k); ?
+#undef write_type_vector_number
+#define write_type_vector_number(t) \
+void short_name(t,write_,vector_number)(t * v, int32_t nl, int32_t nh, char * format, char * filename) \
+{                                                                  \
+    FILE * f = fopen(filename, "wt");                              \
+    if (f == NULL) {                                               \
+        nrerror("Can't open file %s in %s\n", filename, __func__); \
+    }                                                              \
+    for (int32_t k = nl; k <= nh; k++) {                           \
+        fprintf(f, format, k);                                     \
+    }                                                              \
+    fprintf(f, "\n");                                              \
+    for (int32_t k = nl; k <= nh; k++) {                           \
+        fprintf(f, format, v[k]);                                  \
+    }                                                              \
+    fprintf(f, "\n");                                              \
+    fclose(f);                                                     \
+}
+
+write_type_vector_number(int8_t);
+write_type_vector_number(uint8_t);
+write_type_vector_number(int16_t);
+write_type_vector_number(uint16_t);
+write_type_vector_number(int32_t);
+write_type_vector_number(uint32_t);
+write_type_vector_number(int64_t);
+write_type_vector_number(uint64_t);
+write_type_vector_number(float);
+write_type_vector_number(double);
+
+
+/* ------------------------------------------------------------------------------------------- */
+void write_rgb8vector_number(rgb8 * v, int32_t nl, int32_t nh, char * format, char * filename)
+/* ------------------------------------------------------------------------------------------- */
+{
+    FILE * f = fopen(filename, "wt");
+    if (f == NULL) {
+        nrerror("Can't open file %s in %s\n", filename, __func__);
+    }
+    for (int32_t k = nl; k <= nh; k++) {
+        fprintf(f, "%3d", k);
+    }
+    fprintf(f, "\n");
+    for (int32_t k = nl; k <= nh; k++) {
+        fprintf(f, format, v[k].r, v[k].g, v[k].b);
+    }
+    fprintf(f, "\n");
+    fclose(f);
+}
+
+
 /* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_si8vector_number(sint8 *v,long nl,long nh, char *format, char *filename)
+void write_rgbx8vector_number(rgbx8 * v, int32_t nl, int32_t nh, char * format, char * filename)
 /* --------------------------------------------------------------------------------------------- */
 {
-  int  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_si8vector_number"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, k,k,k);} fputc('\n', f);
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui8vector_number(uint8 *v,long nl,long nh, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------- */
-{
-  int  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_ui8vector_number"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, k,k,k);} fputc('\n', f);
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
-  fclose(f);
-}
-/* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_si16vector_number(sint16 *v,long nl,long nh, char *format, char *filename)
-/* --------------------------------------------------------------------------------------------- */
-{
-  int  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_si16vector_number"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, k,k,k);} fputc('\n', f);
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui16vector_number(uint16 *v,long nl,long nh, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------- */
-{
-  int  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_ui16vector_number"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, k,k,k);} fputc('\n', f);
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
-  fclose(f);
-}
-/* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_si32vector_number(sint32 *v,long nl,long nh, char *format, char *filename)
-/* --------------------------------------------------------------------------------------------- */
-{
-  int  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_si32vector_number"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, k,k,k);} fputc('\n', f);
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui32vector_number(uint32 *v,long nl,long nh, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------- */
-{
-  int  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_ui32vector_number"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, k,k,k);} fputc('\n', f);
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
-  fclose(f);
-}
-/* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_si64vector_number(sint64 *v,long nl,long nh, char *format, char *filename)
-/* --------------------------------------------------------------------------------------------- */
-{
-  int  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_si64vector_number"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, k,k,k);} fputc('\n', f);
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui64vector_number(uint64 *v,long nl,long nh, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------- */
-{
-  int  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_ui64vector_number"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, k,k,k);} fputc('\n', f);
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
-  fclose(f);
-}
-/* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_f32vector_number(float32 *v,long nl,long nh, char *format, char *filename)
-/* --------------------------------------------------------------------------------------------- */
-{
-  int k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_f32vector_number"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, k,k,k);} fputc('\n', f);
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
-  fclose(f);
-}
-/* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_f64vector_number(float64 *v,long nl,long nh, char *format, char *filename)
-/* --------------------------------------------------------------------------------------------- */
-{
-  int k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_f32vector_number"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, k,k,k);} fputc('\n', f);
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k]); } fputc('\n', f);
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_rgb8vector_number(rgb8 *v,long nl,long nh, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------- */
-{
-  int  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_rgb8vector_number"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, k,k,k);} fputc('\n', f);
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k].r, v[k].g, v[k].b); } fputc('\n', f);
-  fclose(f);
-}
-/* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_rgbx8vector_number(rgbx8 *v,long nl,long nh, char *format, char *filename)
-/* --------------------------------------------------------------------------------------------- */
-{
-  int  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_rgbx8vector_number"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, format, k,k,k);} fputc('\n', f);
-  for(k=nl; k<=nh; k++) { fprintf(f, format, v[k].r, v[k].g, v[k].b); } fputc('\n', f);
-  fclose(f);
-}
+    FILE * f = fopen(filename, "wt");
+    if (f == NULL) {
+        nrerror("Can't open file %s in %s\n", filename, __func__);
+    }
+    for (int32_t k = nl; k <= nh; k++) {
+        fprintf(f, "%3d", k);
+    }
+    fprintf(f, "\n");
+    for (int32_t k = nl; k <= nh; k++) {
+        fprintf(f, format, v[k].r, v[k].g, v[k].b);
+    }
+    fprintf(f, "\n");
+    fclose(f);
+}
+
+
 /*
  * -----------------------------
@@ -469,148 +239,66 @@
  */
 
+#undef write_type_vector_T_number
+#define write_type_vector_T_number(t) \
+void short_name(t,write_,vector_T_number)(t * v, int32_t nl, int32_t nh, char * format, char * filename) \
+{                                                                  \
+    FILE * f = fopen(filename, "wt");                              \
+    if (f == NULL) {                                               \
+        nrerror("Can't open file %s in %s\n", filename, __func__); \
+    }                                                              \
+    for (int32_t k = nl; k <= nh; k++) {                           \
+        fprintf(f, "%3d", k);                                      \
+        fprintf(f, format, v[k]);                                  \
+        fprintf(f, "\n");                                          \
+    }                                                              \
+    fclose(f);                                                     \
+}
+
+write_type_vector_T_number(int8_t);
+write_type_vector_T_number(uint8_t);
+write_type_vector_T_number(int16_t);
+write_type_vector_T_number(uint16_t);
+write_type_vector_T_number(int32_t);
+write_type_vector_T_number(uint32_t);
+write_type_vector_T_number(int64_t);
+write_type_vector_T_number(uint64_t);
+write_type_vector_T_number(float);
+write_type_vector_T_number(double);
+
+
+/* ------------------------------------------------------------------------------------------- */
+void write_rgb8vector_T_number(rgb8 * v, int32_t nl, int32_t nh, char * format, char * filename)
+/* ------------------------------------------------------------------------------------------- */
+{
+    FILE * f = fopen(filename, "wt");
+    if (f == NULL) {
+        nrerror("Can't open file %s in %s\n", filename, __func__);
+    }
+    for (int32_t k = nl; k <= nh; k++) {
+        fprintf(f, "%3d", k);
+        fprintf(f, format, v[k].r, v[k].g, v[k].b);
+        fprintf(f, "\n");
+    }
+    fclose(f);
+}
+
+
 /* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_si8vector_T_number(sint8 *v,long nl,long nh, char *format, char *filename)
+void write_rgbx8vector_T_number(rgbx8 * v, int32_t nl, int32_t nh, char * format, char * filename)
 /* --------------------------------------------------------------------------------------------- */
 {
-  int  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_si8vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, "%3d ", k); fprintf(f, format, v[k]); fputc('\n', f); }
-  fclose(f);
-}
-/* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui8vector_T_number(uint8 *v,long nl,long nh, char *format, char *filename)
-/* --------------------------------------------------------------------------------------------- */
-{
-  int  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_ui8vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, "%3d ", k); fprintf(f, format, v[k]); fputc('\n', f); }
-  fclose(f);
-}
-/* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_si16vector_T_number(sint16 *v,long nl,long nh, char *format, char *filename)
-/* ----------------------------------------------------------------------------------------------- */
-{
-  int  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_si16vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, "%3d ", k); fprintf(f, format, v[k]); fputc('\n', f); }
-  fclose(f);
-}
-/* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui16vector_T_number(uint16 *v,long nl,long nh, char *format, char *filename)
-/* ----------------------------------------------------------------------------------------------- */
-{
-  int  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_ui16vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, "%3d ", k); fprintf(f, format, v[k]); fputc('\n', f); }
-  fclose(f);
-}
-/* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_si32vector_T_number(sint32 *v,long nl,long nh, char *format, char *filename)
-/* ----------------------------------------------------------------------------------------------- */
-{
-  int  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_si32vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, "%3d ", k); fprintf(f, format, v[k]); fputc('\n', f); }
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui32vector_T_number(uint32 *v,long nl,long nh, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------- */
-{
-  int  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_ui32vector_T_number"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, "%3d ", k); fprintf(f, format, v[k]); fputc('\n', f); }
-  fclose(f);
-}
-/* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_si64vector_T_number(sint64 *v,long nl,long nh, char *format, char *filename)
-/* ----------------------------------------------------------------------------------------------- */
-{
-  int  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_i64vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, "%3d ", k); fprintf(f, format, v[k]); fputc('\n', f); }
-  fclose(f);
-}
-/* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui64vector_T_number(uint64 *v,long nl,long nh, char *format, char *filename)
-/* ----------------------------------------------------------------------------------------------- */
-{
-  int  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_i64vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, "%3d ", k); fprintf(f, format, v[k]); fputc('\n', f); }
-  fclose(f);
-}
-/* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_f32vector_T_number(float32 *v,long nl,long nh, char *format, char *filename)
-/* ----------------------------------------------------------------------------------------------- */
-{
-  int  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_f32vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, "%3d ", k); fprintf(f, format, v[k]); fputc('\n', f); }
-  fclose(f);
-}
-/* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_f64vector_T_number(float64 *v,long nl,long nh, char *format, char *filename)
-/* ----------------------------------------------------------------------------------------------- */
-{
-  int  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_f64vector"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, "%3d ", k); fprintf(f, format, v[k]); fputc('\n', f); }
-  fclose(f);
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_rgb8vector_T_number(rgb8 *v,long nl,long nh, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------- */
-{
-  int  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_rgb8vector_T"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, "%3d ", k); fprintf(f, format, v[k].r, v[k].g, v[k].b); fputc('\n', f); }
-  fclose(f);
-}
-/* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_rgbx8vector_T_number(rgbx8 *v,long nl,long nh, char *format, char *filename)
-/* ----------------------------------------------------------------------------------------------- */
-{
-  int  k;
-  FILE *f;
-
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_rgb8vector_T"); }
-  for(k=nl; k<=nh; k++) { fprintf(f, "%3d ", k); fprintf(f, format, v[k].r, v[k].g, v[k].b); fputc('\n', f); }
-  fclose(f);
-}
+    FILE * f = fopen(filename, "wt");
+    if (f == NULL) {
+        nrerror("Can't open file %s in %s\n", filename, __func__);
+    }
+    for (int32_t k = nl; k <= nh; k++) {
+        fprintf(f, "%3d", k);
+        fprintf(f, format, v[k].r, v[k].g, v[k].b);
+        fprintf(f, "\n");
+    }
+    fclose(f);
+}
+
+
 
 /*
@@ -620,317 +308,75 @@
  */
 
-/* ---------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fread_si8vector(char *filename, sint8 *v,long nl,long nh)
-/* ---------------------------------------------------------------------- */
-{
-  long ncol=nh-nl+1, nread;
-  FILE *f;
-
-  f = fopen(filename, "rb");
-  if(f == NULL) nrerror("Can't open file in fread_si8vector");
-
-  nread = fread(v+nl, sizeof(sint8), ncol, f);
-  if(nread != ncol) nrerror("fread_si8vector can't read the whole vector");
-  fclose(f);
-}
-/* ---------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fread_ui8vector(char *filename, uint8 *v,long nl,long nh)
-/* ---------------------------------------------------------------------- */
-{
-  long ncol=nh-nl+1, nread;
-  FILE *f;
-
-  f = fopen(filename, "rb");
-  if(f == NULL) nrerror("Can't open file in fread_ui8vector");
-
-  nread = fread(v+nl, sizeof(uint8), ncol, f);
-  if(nread != ncol) nrerror("fread_ui8vector can't read the whole vector");
-  fclose(f);
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) fread_si16vector(char *filename, sint16 *v,long nl,long nh)
-/* ------------------------------------------------------------------------ */
-{
-  long ncol=nh-nl+1, nread;
-  FILE *f;
-
-  f = fopen(filename, "rb");
-  if(f == NULL) nrerror("Can't open file in fread_si16vector");
-
-  nread = fread(v+nl, sizeof(int16), ncol, f);
-  if(nread != ncol) nrerror("fread_si16vector can't read the whole vector");
-  fclose(f);
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) fread_ui16vector(char *filename, uint16 *v,long nl,long nh)
-/* ------------------------------------------------------------------------ */
-{
-  long ncol=nh-nl+1, nread;
-  FILE *f;
-
-  f = fopen(filename, "rb");
-  if(f == NULL) nrerror("Can't open file in fread_ui16vector");
-
-  nread = fread(v+nl, sizeof(int16), ncol, f);
-  if(nread != ncol) nrerror("fread_ui16vector can't read the whole vector");
-  fclose(f);
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) fread_si32vector(char *filename, sint32 *v,long nl,long nh)
-/* ------------------------------------------------------------------------ */
-{
-  long ncol=nh-nl+1, nread;
-  FILE *f;
-
-  f = fopen(filename, "rb");
-  if(f == NULL) nrerror("Can't open file in fread_si32vector");
-
-  nread = fread(v+nl, sizeof(sint32), ncol, f);
-  if(nread != ncol) nrerror("fread_si32vector can't read the whole vector");
-  fclose(f);
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) fread_ui32vector(char *filename, uint32 *v,long nl,long nh)
-/* ------------------------------------------------------------------------ */
-{
-  long ncol=nh-nl+1, nread;
-  FILE *f;
-
-  f = fopen(filename, "rb");
-  if(f == NULL) nrerror("Can't open file in fread_ui32vector");
-
-  nread = fread(v+nl, sizeof(uint32), ncol, f);
-  if(nread != ncol) nrerror("fread_ui32vector can't read the whole vector");
-  fclose(f);
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) fread_si64vector(char *filename, sint64 *v,long nl,long nh)
-/* ------------------------------------------------------------------------ */
-{
-  long ncol=nh-nl+1, nread;
-  FILE *f;
-
-  f = fopen(filename, "rb");
-  if(f == NULL) nrerror("Can't open file in fread_si64vector");
-
-  nread = fread(v+nl, sizeof(sint64), ncol, f);
-  if(nread != ncol) nrerror("fread_si64vector can't read the whole vector");
-  fclose(f);
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) fread_ui64vector(char *filename, uint64 *v,long nl,long nh)
-/* ------------------------------------------------------------------------ */
-{
-  long ncol=nh-nl+1, nread;
-  FILE *f;
-
-  f = fopen(filename, "rb");
-  if(f == NULL) nrerror("Can't open file in fread_ui64vector");
-
-  nread = fread(v+nl, sizeof(uint64), ncol, f);
-  if(nread != ncol) nrerror("fread_ui64vector can't read the whole vector");
-  fclose(f);
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) fread_f32vector(char *filename, float32 *v,long nl,long nh)
-/* ------------------------------------------------------------------------ */
-{
-  long ncol=nh-nl+1, nread;
-  FILE *f;
-
-  f = fopen(filename, "rb");
-  if(f == NULL) nrerror("Can't open file in fread_f32vector");
-
-  nread = fread(v+nl, sizeof(float32), ncol, f);
-  if(nread != ncol) nrerror("fread_f32vector can't read the whole vector");
-  fclose(f);
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) fread_f64vector(char *filename, float64 *v,long nl,long nh)
-/* ------------------------------------------------------------------------ */
-{
-  long ncol=nh-nl+1, nread;
-  FILE *f;
-
-  f = fopen(filename, "rb");
-  if(f == NULL) nrerror("Can't open file in fread_f64vector");
-
-  nread = fread(v+nl, sizeof(float64), ncol, f);
-  if(nread != ncol) nrerror("fread_f64vector can't read the whole vector");
-  fclose(f);
-}
-/* ---------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fread_rgb8vector(char *filename, rgb8 *v,long nl,long nh)
-/* ---------------------------------------------------------------------- */
-{
-  long ncol=nh-nl+1, nread;
-  FILE *f;
-
-  f = fopen(filename, "rb");
-  if(f == NULL) nrerror("Can't open file in fread_rgb8vector");
-
-  nread = fread(v+nl, sizeof(float32), ncol, f);
-  if(nread != ncol) nrerror("fread_rgb8vector can't read the whole vector");
-  fclose(f);
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) fread_rgbx8vector(char *filename, rgbx8 *v,long nl,long nh)
-/* ------------------------------------------------------------------------ */
-{
-  long ncol=nh-nl+1, nread;
-  FILE *f;
-
-  f = fopen(filename, "rb");
-  if(f == NULL) nrerror("Can't open file in fread_rgbx8vector");
-
-  nread = fread(v+nl, sizeof(float32), ncol, f);
-  if(nread != ncol) nrerror("fread_rgbx8vector can't read the whole vector");
-  fclose(f);
-}
+#undef fread_type_vector
+#define fread_type_vector(t) \
+void short_name(t,fread_,vector)(char * filename, t * v, int32_t nl, int32_t nh) \
+{                                                                  \
+    int32_t ncol = nh - nl + 1;                                    \
+    int32_t nread;                                                 \
+    FILE * f = fopen(filename, "rb");                              \
+    if (f == NULL) {                                               \
+        nrerror("Can't open file %s in %s\n", filename, __func__); \
+    }                                                              \
+                                                                   \
+    nread = fread(v + nl, sizeof(t), ncol, f);                     \
+    if (nread != ncol) {                                           \
+        nrerror("%s can't read the whole vector", __func__);       \
+    }                                                              \
+    fclose(f);                                                     \
+}
+
+fread_type_vector(int8_t);
+fread_type_vector(uint8_t);
+fread_type_vector(int16_t);
+fread_type_vector(uint16_t);
+fread_type_vector(int32_t);
+fread_type_vector(uint32_t);
+fread_type_vector(int64_t);
+fread_type_vector(uint64_t);
+fread_type_vector(float);
+fread_type_vector(double);
+fread_type_vector(rgb8);
+fread_type_vector(rgbx8);
+
+
 /* ------------------- */
 /* -- fwrite_vector -- */
 /* ------------------- */
-/* ---------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fwrite_si8vector(sint8 *v,long nl,long nh,char *filename)
-/* ---------------------------------------------------------------------- */
-{
-  long  ncol = nh-nl+1;
-  FILE *f;
-
-  f = fopen(filename, "wb");
-  if(f == NULL) nrerror("Can't open file in fwrite_si8vector"); 
-  fwrite(v+nl, sizeof(sint8), ncol, f);
-  fclose(f);
-}
-/* ---------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fwrite_ui8vector(uint8 *v,long nl,long nh,char *filename)
-/* ---------------------------------------------------------------------- */
-{
-  long  ncol = nh-nl+1;
-  FILE *f;
-
-  f = fopen(filename, "wb");
-  if(f == NULL) nrerror("Can't open file in fwrite_ui8vector"); 
-  fwrite(v+nl, sizeof(uint8), ncol, f);
-  fclose(f);
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) fwrite_si16vector(sint16 *v,long nl,long nh,char *filename)
-/* ------------------------------------------------------------------------ */
-{
-  long  ncol = nh-nl+1;
-  FILE *f;
-
-  f = fopen(filename, "wb");
-  if(f == NULL) nrerror("Can't open file in fwrite_si16vector"); 
-  fwrite(v+nl, sizeof(sint16), ncol, f);
-  fclose(f);
-}
-/* ------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fwrite_ui16vector(uint16 *v,long nl,long nh,char *filename)
-/* ------------------------------------------------------------------------- */
-{
-  long  ncol = nh-nl+1;
-  FILE *f;
-
-  f = fopen(filename, "wb");
-  if(f == NULL) nrerror("Can't open file in fwrite_ui16vector"); 
-  fwrite(v+nl, sizeof(uint16), ncol, f);
-  fclose(f);
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) fwrite_si32vector(sint32 *v,long nl,long nh,char *filename)
-/* ------------------------------------------------------------------------ */
-{
-  long  ncol = nh-nl+1;
-  FILE *f;
-
-  f = fopen(filename, "wb");
-  if(f == NULL) nrerror("Can't open file in fwrite_si32vector"); 
-  fwrite(v+nl, sizeof(sint32), ncol, f);
-  fclose(f);
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) fwrite_ui32vector(uint32 *v,long nl,long nh,char *filename)
-/* ------------------------------------------------------------------------ */
-{
-  long  ncol = nh-nl+1;
-  FILE *f;
-
-  f = fopen(filename, "wb");
-  if(f == NULL) nrerror("Can't open file in fwrite_ui32vector"); 
-  fwrite(v+nl, sizeof(uint32), ncol, f);
-  fclose(f);
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) fwrite_si64vector(sint64 *v,long nl,long nh,char *filename)
-/* ------------------------------------------------------------------------ */
-{
-  long  ncol = nh-nl+1;
-  FILE *f;
-
-  f = fopen(filename, "wb");
-  if(f == NULL) nrerror("Can't open file in fwrite_si64vector");
-  fwrite(v+nl, sizeof(sint64), ncol, f);
-  fclose(f);
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) fwrite_ui64vector(uint64 *v,long nl,long nh,char *filename)
-/* ------------------------------------------------------------------------ */
-{
-  long  ncol = nh-nl+1;
-  FILE *f;
-
-  f = fopen(filename, "wb");
-  if(f == NULL) nrerror("Can't open file in fwrite_ui-'vector");
-  fwrite(v+nl, sizeof(uint64), ncol, f);
-  fclose(f);
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) fwrite_f32vector(float32 *v,long nl,long nh,char *filename)
-/* ------------------------------------------------------------------------ */
-{
-  long  ncol = nh-nl+1;
-  FILE *f;
-
-  f = fopen(filename, "wb");
-  if(f == NULL) nrerror("Can't open file in f32write_vector"); 
-  fwrite(v+nl, sizeof(float32), ncol, f);
-  fclose(f);
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) fwrite_f64vector(float64 *v,long nl,long nh,char *filename)
-/* ------------------------------------------------------------------------ */
-{
-  long  ncol = nh-nl+1;
-  FILE *f;
-
-  f = fopen(filename, "wb");
-  if(f == NULL) nrerror("Can't open file in f64write_vector"); 
-  fwrite(v+nl, sizeof(float64), ncol, f);
-  fclose(f);
-}
-/* ---------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fwrite_rgb8vector(rgb8 *v,long nl,long nh,char *filename)
-/* ---------------------------------------------------------------------- */
-{
-  long  ncol = nh-nl+1;
-  FILE *f;
-
-  f = fopen(filename, "wb");
-  if(f == NULL) nrerror("Can't open file in write_rgb8vector"); 
-  fwrite(v+nl, sizeof(rgb8), ncol, f);
-  fclose(f);
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) fwrite_rgbx8vector(rgbx8 *v,long nl,long nh,char *filename)
-/* ------------------------------------------------------------------------ */
-{
-  long  ncol = nh-nl+1;
-  FILE *f;
-
-  f = fopen(filename, "wb");
-  if(f == NULL) nrerror("Can't open file in write_rgbx8vector");
-  fwrite(v+nl, sizeof(rgbx8), ncol, f);
-  fclose(f);
-}
+
+#undef fwrite_type_vector
+#define fwrite_type_vector(t) \
+void short_name(t,fwrite_,vector)(t * v, int32_t nl, int32_t nh, char * filename) \
+{                                                                  \
+    int32_t ncol = nh - nl + 1;                                    \
+    FILE * f = fopen(filename, "rb");                              \
+    if (f == NULL) {                                               \
+        nrerror("Can't open file %s in %s\n", filename, __func__); \
+    }                                                              \
+    fwrite(v + nl, sizeof(t), ncol, f);                            \
+    fclose(f);                                                     \
+}
+
+fwrite_type_vector(int8_t);
+fwrite_type_vector(uint8_t);
+fwrite_type_vector(int16_t);
+fwrite_type_vector(uint16_t);
+fwrite_type_vector(int32_t);
+fwrite_type_vector(uint32_t);
+fwrite_type_vector(int64_t);
+fwrite_type_vector(uint64_t);
+fwrite_type_vector(float);
+fwrite_type_vector(double);
+fwrite_type_vector(rgb8);
+fwrite_type_vector(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/nrio1x.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrio1x.c	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrio1x.c	(revision 822)
@@ -21,203 +21,115 @@
 #include "nrio1x.h"
 
-/* ---------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_bvector_circular(byte *v,long nl,long nh, long c0, long c1, char *format, char *name)
-/* ---------------------------------------------------------------------------------------------------------- */
-{
-  long i, n=nh-nl+1;
-
-  if(name != NULL) puts(name);
-
-  for(i=c0; i<=c1; i++) { printf(format, v[i%n+nl]);} putchar('\n');
-}
-/* ----------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_si16vector_circular(sint16 *v,long nl,long nh, long c0, long c1, char *format, char *name)
-/* ----------------------------------------------------------------------------------------------------------- */
-{
-  long i, n=nh-nl+1;
-
-  if(name != NULL) puts(name); 
-
-  for(i=c0; i<=c1; i++) { printf(format, v[i%n+nl]);} putchar('\n');
-}
-/* --------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui32vector_circular(uint32 *v,long nl,long nh, long c0, long c1, char *format, char *name)
-/* --------------------------------------------------------------------------------------------------------- */
-{
-  long i, n=nh-nl+1;
-
-  if(name != NULL) puts(name);
-
-  for(i=c0; i<=c1; i++) { printf(format, v[i%n+nl]);} putchar('\n');
-}
-/* ---------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_f32vector_circular(float32 *v,long nl,long nh, long c0, long c1, char *format, char *name)
-/* ---------------------------------------------------------------------------------------------------------- */
-{
-  long i, n=nh-nl+1;
-
-  if(name != NULL) puts(name);
-
-  for(i=c0; i<=c1; i++) { printf(format, v[i%n+nl]);} putchar('\n');
-}
-/* ------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_f64vector_circular(float64 *v,long nl,long nh, long c0, long c1, char *format, char *name)
-/* ------------------------------------------------------------------------------------------------------------ */
-{
-  long i, n=nh-nl+1;
-
-  if(name != NULL) puts(name);
-
-  for(i=c0; i<=c1; i++) { printf(format, v[i%n+nl]);} putchar('\n');
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_bvector_circular_number(byte *v,long nl,long nh, long c0, long c1, char *format, char *name)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-  long i, n=nh-nl+1;
-
-  if(name != NULL) puts(name);
-
-  putchar('#');
-  for(i=c0; i<=c1; i++) {
-    printf(format,   i%n+nl);
-  }
-  putchar('\n');
-  putchar(' ');
-  for(i=c0; i<=c1; i++) {
-    printf(format, v[i%n+nl]);
-  }
-  putchar('\n');
-}
-/* ------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_si16vector_circular_number(sint16 *v,long nl,long nh, long c0, long c1, char *format, char *name)
-/* ------------------------------------------------------------------------------------------------------------------ */
-{
-  long i, n=nh-nl+1;
-
-  if(name != NULL) puts(name);
-
-  putchar('#'); for(i=c0; i<=c1; i++) { printf(format,   i%n+nl); } putchar('\n');
-  putchar(' ');  for(i=c0; i<=c1; i++) { printf(format, v[i%n+nl]);} putchar('\n');
-}
-/* ---------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui32vector_circular_number(uint32 *v,long nl,long nh, long c0, long c1, char *format, char *name)
-/* ---------------------------------------------------------------------------------------------------------------- */
-{
-  long i, n=nh-nl+1;
-
-  if(name != NULL) puts(name);
-
-  putchar('#'); for(i=c0; i<=c1; i++) { printf(format,   i%n+nl); } putchar('\n');
-  putchar(' '); for(i=c0; i<=c1; i++) { printf(format, v[i%n+nl]);} putchar('\n');
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_f32vector_circular_number(float32 *v,long nl,long nh, long c0, long c1, char *format, char *name)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-  long i, n=nh-nl+1;
-
-  if(name != NULL) puts(name);
-
-  putchar('#'); for(i=c0; i<=c1; i++) { printf(format,   i%n+nl); } putchar('\n');
-  putchar(' ');  for(i=c0; i<=c1; i++) { printf(format, v[i%n+nl]);} putchar('\n');
-}
-/* ------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_dvector_circular_number(float64 *v,long nl,long nh, long c0, long c1, char *format, char *name)
-/* ------------------------------------------------------------------------------------------------------------------- */
-{
-  long i, n=nh-nl+1;
-
-  if(name != NULL) puts(name);
-
-  putchar('#'); for(i=c0; i<=c1; i++) { printf(format,   i%n+nl); } putchar('\n');
-  putchar(' '); for(i=c0; i<=c1; i++) { printf(format, v[i%n+nl]);} putchar('\n');
+#undef display_type_vector_circular
+#define display_type_vector_circular(t) \
+void short_name(t,display_,vector_circular)(t * v, int32_t nl, int32_t nh, int32_t c0, int32_t c1, char * format, char * name) \
+{                                        \
+    int32_t n = nh - nl + 1;             \
+    if (name != NULL) {                  \
+        printf("%s\n", name);            \
+    }                                    \
+    for (int32_t i = c0; i <= c1; i++) { \
+        printf(format, v[i % n + nl]);   \
+    }                                    \
+    printf("\n");                        \
 }
 
-/* ------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_bvector_cycle(byte *v,long nl,long nh, char *format, char *name)
-/* ------------------------------------------------------------------------------------- */
-{
-  long i;
-  uint8 first, next;
-  uint8 *displayed;
 
-  if(name != NULL) printf("%s", name);
+display_type_vector_circular(int8_t);
+display_type_vector_circular(uint8_t);
+display_type_vector_circular(int16_t);
+display_type_vector_circular(uint16_t);
+display_type_vector_circular(int32_t);
+display_type_vector_circular(uint32_t);
+display_type_vector_circular(int64_t);
+display_type_vector_circular(uint64_t);
+display_type_vector_circular(float);
+display_type_vector_circular(double);
 
-  displayed = ui8vector0(nl, nh);
-  
-  for(i=nl; i<=nh; i++) {
-    if(!displayed[i]) {
-      displayed[i] = 1;
-      printf(format, i);
-      first = (byte) i;
-      next = v[i];
-      while(first != next) {
-        displayed[next] = 1;
-        printf(format, next);
-        next = v[next];
-      }
-      putchar('\n');
-    }
-  }
-  putchar('\n');
-  free_ui8vector(displayed, nl, nh);
+
+
+#undef display_type_vector_circular_number
+#define display_type_vector_circular_number(t) \
+void short_name(t,display_,vector_circular_number)(t * v, int32_t nl, int32_t nh, int32_t c0, int32_t c1, char * format, char * name) \
+{                                        \
+    int32_t n = nh - nl + 1;             \
+    if (name != NULL) {                  \
+        printf("%s", name);              \
+    }                                    \
+    printf("#");                         \
+    for (int32_t i = c0; i <= c1; i++) { \
+        printf(format, i % n + nl);      \
+    }                                    \
+    printf("\n ");                       \
+    for (int32_t i = c0; i <= c1; i++) { \
+        printf(format, v[i % n + nl]);   \
+    }                                    \
+    printf("\n");                        \
 }
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_si16vector_cycle(sint16 *v,long nl,long nh, char *format, char *name)
-/* -------------------------------------------------------------------------------------- */
-{
-  long i;
-  uint16 first, next;
-  uint8 *displayed;
 
-  if(name != NULL) printf("%s", name);
 
-  displayed = ui8vector0(nl, nh);
-  
-  for(i=nl; i<=nh; i++) {
-    if(!displayed[i]) {
-      displayed[i] = 1;
-      printf(format, i);
-      first = (sint16) i;
-      next = v[i];
-      while(first != next) {
-        displayed[next] = 1;
-        printf(format, next);
-        next = v[next];
-      }
-      putchar('\n');
-    }
-  }
-  putchar('\n');
-  free_ui8vector(displayed, nl, nh);
+display_type_vector_circular_number(int8_t);
+display_type_vector_circular_number(uint8_t);
+display_type_vector_circular_number(int16_t);
+display_type_vector_circular_number(uint16_t);
+display_type_vector_circular_number(int32_t);
+display_type_vector_circular_number(uint32_t);
+display_type_vector_circular_number(int64_t);
+display_type_vector_circular_number(uint64_t);
+display_type_vector_circular_number(float);
+display_type_vector_circular_number(double);
+
+
+
+#undef display_type_vector_cycle
+#define display_type_vector_cycle(t) \
+void short_name(t,display_,vector_cycle)(t * v, int32_t nl, int32_t nh, char * format, char * name) \
+{                                        \
+    uint8_t first;                       \
+    uint8_t next;                        \
+    uint8_t * displayed;                 \
+                                         \
+    if (name != NULL) {                  \
+        printf("%s", name);              \
+    }                                    \
+    displayed = ui8vector0(nl, nh);      \
+    for (int32_t i = nl; i <= nh; i++) { \
+        if (!displayed[i]) {             \
+            displayed[i] = 1;            \
+            printf(format, i);           \
+            first = (t) i;               \
+            next = v[i];                 \
+            while (first != next) {      \
+                displayed[next] = 1;     \
+                printf(format, next);    \
+                next = v[next];          \
+            }                            \
+            printf("\n");                \
+        }                                \
+    }                                    \
+    printf("\n");                        \
+    free_ui8vector(displayed, nl, nh);   \
 }
-/* ---------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui16vector_cycle(uint16 *v,long nl,long nh, char *format, char *name)
-/* ---------------------------------------------------------------------------------------- */
-{
-  long i;
-  uint16 first, next;
-  uint8 *displayed;
 
-  if(name != NULL) printf("%s", name);
 
-  displayed = ui8vector0(nl, nh);
-  
-  for(i=nl; i<=nh; i++) {
-    if(!displayed[i]) {
-      displayed[i] = 1;
-      printf(format, i);
-      first = (uint16) i;
-      next = v[i];
-      while(first != next) {
-        displayed[next] = 1;
-        printf(format, next);
-        next = v[next];
-      }
-      putchar('\n');
-    }
-  }
-  putchar('\n');
-  free_ui8vector(displayed, nl, nh);
-}
+display_type_vector_cycle(int8_t);
+display_type_vector_cycle(uint8_t);
+display_type_vector_cycle(int16_t);
+display_type_vector_cycle(uint16_t);
+display_type_vector_cycle(int32_t);
+display_type_vector_cycle(uint32_t);
+display_type_vector_cycle(int64_t);
+display_type_vector_cycle(uint64_t);
+display_type_vector_cycle(float);
+display_type_vector_cycle(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/nrio1xf.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrio1xf.c	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrio1xf.c	(revision 822)
@@ -11,4 +11,5 @@
 #include <stdio.h>
 
+#include "nrc_os_config.h"
 #include "mypredef.h"
 #include "nrtype.h"
@@ -18,5 +19,5 @@
 
 #include "nralloc1.h"
-#include "nrio1xf.h"
+#include "nrio1x.h"
 
 
@@ -24,15 +25,41 @@
 /* -- write_vector_circular -- */
 /* --------------------------- */
-/* ------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) write_bvector_circular(byte *v,long nl,long nh, long c0, long c1, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------ */
-{
-  long i, n=nh-nl+1;
-  FILE *f;
 
-  f = fopen(filename, "wt");
-  if(f == NULL) { nrerror("Can't open file in write_bvector_circular"); }
+#undef write_type_vector_circular
+#define write_type_vector_circular(t) \
+void short_name(t,write_,vector_circular)(t * v, int32_t nl, int32_t nh, int32_t c0, int32_t c1, char * format, char * filename) \
+{                                                                  \
+    int32_t n = nh - nl + 1;                                       \
+    FILE * f = fopen(filename, "wt");                              \
+    if (f == NULL) {                                               \
+        nrerror("Can't open file %s in %s\n", filename, __func__); \
+    }                                                              \
+    for (int32_t i = c0; i <= c1; i++) {                           \
+        fprintf(f, format, v[i % n + nl]);                         \
+    }                                                              \
+    fprintf(f, "\n");                                              \
+    fclose(f);                                                     \
+}
 
-  for(i=c0; i<=c1; i++) { fprintf(f, format, v[i%n+nl]);} fputc('\n', f);
-  fclose(f);
-}
+write_type_vector_circular(int8_t);
+write_type_vector_circular(uint8_t);
+write_type_vector_circular(int16_t);
+write_type_vector_circular(uint16_t);
+write_type_vector_circular(int32_t);
+write_type_vector_circular(uint32_t);
+write_type_vector_circular(int64_t);
+write_type_vector_circular(uint64_t);
+write_type_vector_circular(float);
+write_type_vector_circular(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/nrio2.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrio2.c	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrio2.c	(revision 822)
@@ -49,370 +49,65 @@
  */
 
+
+#undef display_type_matrix
+#define display_type_matrix(t) \
+void short_name(t,display_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * format, char * name) \
+{                                              \
+    if (name != NULL) {                        \
+        printf("%s\n", name);                  \
+    }                                          \
+                                               \
+    for (int32_t i = nrl; i <= nrh; i++) {     \
+        for (int32_t j = ncl; j <= nch; j++) { \
+            printf(format, m[i][j]);           \
+        }                                      \
+        printf("\n");                          \
+    }                                          \
+}
+
+display_type_matrix(int8_t);
+display_type_matrix(uint8_t);
+display_type_matrix(int16_t);
+display_type_matrix(uint16_t);
+display_type_matrix(int32_t);
+display_type_matrix(uint32_t);
+display_type_matrix(int64_t);
+display_type_matrix(uint64_t);
+display_type_matrix(float);
+display_type_matrix(double);
+
+
 /* -------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui8matrix(uint8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
+void display_rgb8matrix(rgb8 ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * format, char * name)
 /* -------------------------------------------------------------------------------------------------------- */
 {
-    long i,j;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            printf(format, m[i][j]);
+    if (name != NULL) {
+        printf(name);
+    }
+    
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            printf(format, m[i][j].r, m[i][j].g, m[i][j].b);
         }
         printf("\n");
     }
 }
-/* -------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_si8matrix(sint8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* -------------------------------------------------------------------------------------------------------- */
-{
-    long i,j;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            printf(format, m[i][j]);
+
+/* ---------------------------------------------------------------------------------------------------------- */
+void display_rgbx8matrix(rgbx8 ** m,int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * format, char * name)
+/* ---------------------------------------------------------------------------------------------------------- */
+{
+    if (name != NULL) {
+        printf(name);
+    }
+    
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            printf(format, m[i][j].r, m[i][j].g, m[i][j].b, m[i][j].x);
         }
         printf("\n");
     }
 }
-/* ---------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_si16matrix(sint16 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ---------------------------------------------------------------------------------------------------------- */
-{
-    long i,j;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            printf(format, m[i][j]);
-        }
-        printf("\n");
-    }
-}
-/* ---------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui16matrix(uint16 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ---------------------------------------------------------------------------------------------------------- */
-{
-    long i,j;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            printf(format, m[i][j]);
-        }
-        printf("\n");
-    }
-}
-/* ---------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_si32matrix(sint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ---------------------------------------------------------------------------------------------------------- */
-{
-    long i,j;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            printf(format, m[i][j]);
-        }
-        printf("\n");
-    }
-}
-/* ---------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui32matrix(uint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ---------------------------------------------------------------------------------------------------------- */
-{
-    long i,j;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            printf(format, m[i][j]);
-        }
-        printf("\n");
-    }
-}
-/* ---------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_si64matrix(sint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ---------------------------------------------------------------------------------------------------------- */
-{
-    long i,j;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            printf(format, m[i][j]);
-        }
-        printf("\n");
-    }
-}
-/* --------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_i64matrix(uint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* --------------------------------------------------------------------------------------------------------- */
-{
-    long i,j;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            printf(format, m[i][j]);
-        }
-        printf("\n");
-    }
-}
-/* ---------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_f32matrix(float32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ---------------------------------------------------------------------------------------------------------- */
-{
-    long i,j;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            printf(format, m[i][j]);
-        }
-        printf("\n");
-    }
-}
-/* ---------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_f64matrix(float64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ---------------------------------------------------------------------------------------------------------- */
-{
-    long i,j;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            printf(format, m[i][j]);
-        }
-        printf("\n");
-    }
-}
-/* -------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_rgb8matrix(rgb8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* -------------------------------------------------------------------------------------------------------- */
-{
-    long i,j;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            printf(format, m[i][j].r, m[i][j].g, m[i][j].b);
-        }
-        printf("\n");
-    }
-}
-/* ---------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_rgbx8matrix(rgbx8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ---------------------------------------------------------------------------------------------------------- */
-{
-    long i,j;
-    
-    if(name != NULL) printf(name);
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            printf(format, m[i][j].r, m[i][j].g, m[i][j].b, m[i][j].x);
-        }
-        printf("\n");
-    }
-}
-/*
- * ----------------------
- * --- display_matrix ---
- * ----------------------
- */
-
-/* ---------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_si8matrix_T(sint8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ---------------------------------------------------------------------------------------------------------- */
-{
-    long i,j;
-    
-    if(name != NULL) printf(name);
-    
-    for(j=ncl; j<=nch; j++) {
-        for(i=nrl; i<=nrh; i++) {           
-            printf(format, m[i][j]);
-        }
-        printf("\n");
-    }
-}
-/* ---------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui8matrix_T(uint8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ---------------------------------------------------------------------------------------------------------- */
-{
-    long i,j;
-    
-    if(name != NULL) printf(name);
-    
-    for(j=ncl; j<=nch; j++) {
-        for(i=nrl; i<=nrh; i++) {           
-            printf(format, m[i][j]);
-        }
-        printf("\n");
-    }
-}
-/* ------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_si16matrix_T(sint16 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ------------------------------------------------------------------------------------------------------------ */
-{
-    long i,j;
-    
-    if(name != NULL) printf(name);
-    
-    for(j=ncl; j<=nch; j++) {
-        for(i=nrl; i<=nrh; i++) {           
-            printf(format, m[i][j]);
-        }
-        printf("\n");
-    }
-}
-/* ------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_ui16matrix_T(uint16 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ------------------------------------------------------------------------------------------------------------ */
-{
-    long i,j;
-    
-    if(name != NULL) printf(name);
-    
-    for(j=ncl; j<=nch; j++) {
-        for(i=nrl; i<=nrh; i++) {           
-            printf(format, m[i][j]);
-        }
-        printf("\n");
-    }
-}
-/* ------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_si32matrix_T(sint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ------------------------------------------------------------------------------------------------------------ */
-{
-    long i,j;
-    
-    if(name != NULL) printf(name);
-    
-    for(j=ncl; j<=nch; j++) {
-        for(i=nrl; i<=nrh; i++) {           
-            printf(format, m[i][j]);
-        }
-        printf("\n");
-    }
-}
-/* ---------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui32matrix_T(uint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ---------------------------------------------------------------------------------------------------------- */
-{
-    long i,j;
-    
-    if(name != NULL) printf(name);
-    
-    for(j=ncl; j<=nch; j++) {
-        for(i=nrl; i<=nrh; i++) {           
-            printf(format, m[i][j]);
-        }
-        printf("\n");
-    }
-}
-/* ------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_si64matrix_T(sint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ------------------------------------------------------------------------------------------------------------ */
-{
-    long i,j;
-    
-    if(name != NULL) printf(name);
-    
-    for(j=ncl; j<=nch; j++) {
-        for(i=nrl; i<=nrh; i++) {           
-            printf(format, m[i][j]);
-        }
-        printf("\n");
-    }
-}
-/* ------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_ui64matrix_T(uint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ------------------------------------------------------------------------------------------------------------ */
-{
-    long i,j;
-    
-    if(name != NULL) printf(name);
-    
-    for(j=ncl; j<=nch; j++) {
-        for(i=nrl; i<=nrh; i++) {           
-            printf(format, m[i][j]);
-        }
-        printf("\n");
-    }
-}
-/* ------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_f32matrix_T(float32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ------------------------------------------------------------------------------------------------------------ */
-{
-    long i,j;
-    
-    if(name != NULL) printf(name);
-    
-    for(j=ncl; j<=nch; j++) {
-        for(i=nrl; i<=nrh; i++) {           
-            printf(format, m[i][j]);
-        }
-        printf("\n");
-    }
-}
-/* ------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_f64matrix_T(float64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ------------------------------------------------------------------------------------------------------------ */
-{
-    long i,j;
-    
-    if(name != NULL) printf(name);
-    
-    for(j=ncl; j<=nch; j++) {
-        for(i=nrl; i<=nrh; i++) {           
-            printf(format, m[i][j]);
-        }
-        printf("\n");
-    }
-}
-/* ---------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_rgb8matrix_T(rgb8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ---------------------------------------------------------------------------------------------------------- */
-{
-    long i,j;
-    
-    if(name != NULL) printf(name);
-    
-    for(j=ncl; j<=nch; j++) {
-        for(i=nrl; i<=nrh; i++) {           
-            printf(format, m[i][j].r, m[i][j].g, m[i][j].b);
-        }
-        printf("\n");
-    }
-}
-/* ------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) display_rgbx8matrix_T(rgbx8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ------------------------------------------------------------------------------------------------------------ */
-{
-    long i,j;
-    
-    if(name != NULL) printf(name);
-    
-    for(j=ncl; j<=nch; j++) {
-        for(i=nrl; i<=nrh; i++) {           
-            printf(format, m[i][j].r, m[i][j].g, m[i][j].b, m[i][j].x);
-        }
-        printf("\n");
-    }
-}
+
 
 /*
@@ -422,22 +117,123 @@
  */
 
+#undef display_type_matrix_T
+#define display_type_matrix_T(t) \
+void short_name(t,display_,matrix_T)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * format, char * name) \
+{                                              \
+    if (name != NULL) {                        \
+        printf("%s\n", name);                  \
+    }                                          \
+                                               \
+    for (int32_t j = ncl; j <= nch; j++) {     \
+        for (int32_t i = nrl; i <= nrh; i++) { \
+            printf(format, m[i][j]);           \
+        }                                      \
+        printf("\n");                          \
+    }                                          \
+}
+
+display_type_matrix_T(int8_t);
+display_type_matrix_T(uint8_t);
+display_type_matrix_T(int16_t);
+display_type_matrix_T(uint16_t);
+display_type_matrix_T(int32_t);
+display_type_matrix_T(uint32_t);
+display_type_matrix_T(int64_t);
+display_type_matrix_T(uint64_t);
+display_type_matrix_T(float);
+display_type_matrix_T(double);
+
+
+/* -------------------------------------------------------------------------------------------------------- */
+void display_rgb8matrix_T(rgb8 ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * format, char * name)
+/* -------------------------------------------------------------------------------------------------------- */
+{
+    if (name != NULL) {
+        printf(name);
+    }
+    
+    for (int32_t j = ncl; j <= nch; j++) {
+        for (int32_t i = nrl; i <= nrh; i++) {
+            printf(format, m[i][j].r, m[i][j].g, m[i][j].b);
+        }
+        printf("\n");
+    }
+}
+
+/* ---------------------------------------------------------------------------------------------------------- */
+void display_rgbx8matrix_T(rgbx8 ** m,int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * format, char * name)
+/* ---------------------------------------------------------------------------------------------------------- */
+{
+    if (name != NULL) {
+        printf(name);
+    }
+    
+    for (int32_t j = ncl; j <= nch; j++) {
+        for (int32_t i = nrl; i <= nrh; i++) {
+            printf(format, m[i][j].r, m[i][j].g, m[i][j].b, m[i][j].x);
+        }
+        printf("\n");
+    }
+}
+
+
+
+/*
+ * -----------------------------
+ * --- display_matrix_number ---
+ * -----------------------------
+ */
+
+#undef display_type_matrix_number
+#define display_type_matrix_number(t) \
+void short_name(t,display_,matrix_number)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * format, char * name) \
+{                                              \
+    if (name != NULL) {                        \
+        printf("%s\n", name);                  \
+    }                                          \
+    printf("%5c", '#');                        \
+    for (int32_t j = ncl; j <= nch; j++) {     \
+        printf(format, j);                     \
+    }                                          \
+    printf("\n");                              \
+    for (int32_t i = nrl; i <= nrh; i++) {     \
+        printf("[%3d]", i);                    \
+        for (int32_t j = ncl; j <= nch; j++) { \
+            printf(format, m[i][j]);           \
+        }                                      \
+        printf("\n");                          \
+    }                                          \
+    printf("\n");                              \
+}
+
+display_type_matrix_number(int8_t);
+display_type_matrix_number(uint8_t);
+display_type_matrix_number(int16_t);
+display_type_matrix_number(uint16_t);
+display_type_matrix_number(int32_t);
+display_type_matrix_number(uint32_t);
+display_type_matrix_number(int64_t);
+display_type_matrix_number(uint64_t);
+display_type_matrix_number(float);
+display_type_matrix_number(double);
+
+
 /* --------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_si8matrix_number(sint8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
+void display_rgb8matrix_number(rgb8 ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * format, char * name)
 /* --------------------------------------------------------------------------------------------------------------- */
 {
-    int i,j;
-    
-    if(name != NULL) printf(name);
-    
+    if (name != NULL) {
+        printf(name);
+    }
     // 1ere ligne
     printf("%5c", '#');
-    for(j=ncl; j<=nch; j++) {
+    for (int32_t j = ncl; j <= nch; j++) {
         printf(format, j);
     }
     printf("\n");
-    for(i=nrl; i<=nrh; i++) {
+    for (int32_t i = nrl; i <= nrh; i++) {
         printf("[%3d]", i);
-        for(j=ncl; j<=nch; j++) {
-            printf(format, m[i][j]);
+        for (int32_t j = ncl; j <= nch; j++) {
+            printf(format, m[i][j].r, m[i][j].g, m[i][j].b);
         }
         printf("\n");
@@ -445,22 +241,22 @@
     printf("\n");
 }
-/* --------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui8matrix_number(uint8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* --------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    if(name != NULL) printf(name);
-    
+
+/* ----------------------------------------------------------------------------------------------------------------- */
+void display_rgbx8matrix_number(rgbx8 **m,int32_t nrl,int32_t nrh,int32_t ncl, int32_t nch, char *format, char *name)
+/* ----------------------------------------------------------------------------------------------------------------- */
+{
+    if (name != NULL) {
+        printf(name);
+    }
     // 1ere ligne
     printf("%5c", '#');
-    for(j=ncl; j<=nch; j++) {
+    for (int32_t j = ncl; j <= nch; j++) {
         printf(format, j);
     }
     printf("\n");
-    for(i=nrl; i<=nrh; i++) {
+    for (int32_t i = nrl; i <= nrh; i++) {
         printf("[%3d]", i);
-        for(j=ncl; j<=nch; j++) {
-            printf(format, m[i][j]);
+        for (int32_t j = ncl; j <= nch; j++) {
+            printf(format, m[i][j].r, m[i][j].g, m[i][j].b, m[i][j].x);
         }
         printf("\n");
@@ -468,234 +264,6 @@
     printf("\n");
 }
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_si16matrix_number(sint16 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    if(name != NULL) printf(name);
-    
-    // 1ere ligne
-    printf("%5c", '#');
-    for(j=ncl; j<=nch; j++) {
-        printf(format, j);
-    }
-    printf("\n");
-    for(i=nrl; i<=nrh; i++) {
-        printf("[%3d]", i);
-        for(j=ncl; j<=nch; j++) {
-            printf(format, m[i][j]);
-        }
-        printf("\n");
-    }
-    printf("\n");
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui16matrix_number(uint16 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    if(name != NULL) printf(name);
-    
-    // 1ere ligne
-    printf("%5c", '#');
-    for(j=ncl; j<=nch; j++) {
-        printf(format, j);
-    }
-    printf("\n");
-    for(i=nrl; i<=nrh; i++) {
-        printf("[%3d]", i);
-        for(j=ncl; j<=nch; j++) {
-            printf(format, m[i][j]);
-        }
-        printf("\n");
-    }
-    printf("\n");
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_si32matrix_number(sint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    if(name != NULL) printf(name);
-    
-    // 1ere ligne
-    printf("%5c", '#');
-    for(j=ncl; j<=nch; j++) {
-        printf(format, j);
-    }
-    printf("\n");
-    for(i=nrl; i<=nrh; i++) {
-        printf("[%3d]", i);
-        for(j=ncl; j<=nch; j++) {
-            printf(format, m[i][j]);
-        }
-        printf("\n");
-    }
-    printf("\n");
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui32matrix_number(uint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    if(name != NULL) printf(name);
-    
-    // 1ere ligne
-    printf("%5c", '#');
-    for(j=ncl; j<=nch; j++) {
-        printf(format, j);
-    }
-    printf("\n");
-    for(i=nrl; i<=nrh; i++) {
-        printf("[%3d]", i);
-        for(j=ncl; j<=nch; j++) {
-            printf(format, m[i][j]);
-        }
-        printf("\n");
-    }
-    printf("\n");
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_si64matrix_number(sint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    if(name != NULL) printf(name);
-    
-    // 1ere ligne
-    printf("%5c", '#');
-    for(j=ncl; j<=nch; j++) {
-        printf(format, j);
-    }
-    printf("\n");
-    for(i=nrl; i<=nrh; i++) {
-        printf("[%3d]", i);
-        for(j=ncl; j<=nch; j++) {
-            printf(format, m[i][j]);
-        }
-        printf("\n");
-    }
-    printf("\n");
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_ui64matrix_number(uint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    if(name != NULL) printf(name);
-    
-    // 1ere ligne
-    printf("%5c", '#');
-    for(j=ncl; j<=nch; j++) {
-        printf(format, j);
-    }
-    printf("\n");
-    for(i=nrl; i<=nrh; i++) {
-        printf("[%3d]", i);
-        for(j=ncl; j<=nch; j++) {
-            printf(format, m[i][j]);
-        }
-        printf("\n");
-    }
-    printf("\n");
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_f32matrix_number(float32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    if(name != NULL) printf(name);
-    
-    // 1ere ligne
-    printf("%5c", '#');
-    for(j=ncl; j<=nch; j++) {
-        printf(format, j);
-    }
-    printf("\n");
-    for(i=nrl; i<=nrh; i++) {
-        printf("[%3d]", i);
-        for(j=ncl; j<=nch; j++) {
-            printf(format, m[i][j]);
-        }
-        printf("\n");
-    }
-    printf("\n");
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_f64matrix_number(float64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    if(name != NULL) printf(name);
-    
-    // 1ere ligne
-    printf("%5c", '#');
-    for(j=ncl; j<=nch; j++) {
-        printf(format, j);
-    }
-    printf("\n");
-    for(i=nrl; i<=nrh; i++) {
-        printf("[%3d]", i);
-        for(j=ncl; j<=nch; j++) {
-            printf(format, m[i][j]);
-        }
-        printf("\n");
-    }
-    printf("\n");
-}
-/* --------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_rgb8matrix_number(rgb8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* --------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    if(name != NULL) printf(name);
-    
-    // 1ere ligne
-    printf("%5c", '#');
-    for(j=ncl; j<=nch; j++) {
-        printf(format, j);
-    }
-    printf("\n");
-    for(i=nrl; i<=nrh; i++) {
-        printf("[%3d]", i);
-        for(j=ncl; j<=nch; j++) {
-            printf(format, m[i][j].r, m[i][j].g, m[i][j].b);
-        }
-        printf("\n");
-    }
-    printf("\n");
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) display_rgbx8matrix_number(rgbx8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *name)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    if(name != NULL) printf(name);
-    
-    // 1ere ligne
-    printf("%5c", '#');
-    for(j=ncl; j<=nch; j++) {
-        printf(format, j);
-    }
-    printf("\n");
-    for(i=nrl; i<=nrh; i++) {
-        printf("[%3d]", i);
-        for(j=ncl; j<=nch; j++) {
-            printf(format, m[i][j].r, m[i][j].g, m[i][j].b, m[i][j].x);
-        }
-        printf("\n");
-    }
-    printf("\n");
-}
+
+
 
 /*
@@ -705,226 +273,83 @@
  */
 
-// ------------------------------------------------------------------------------------------------
-void display_si8matrix_positive(sint8 **m, int i0, int i1, int j0, int j1, int iformat, char *name)
-// ------------------------------------------------------------------------------------------------
-{
-    int i, j;
-    
-    char *format, *str;
-    
-    select_display_positive_parameters(iformat, &format, &str);
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {
-        for(j=j0; j<=j1; j++) {
-            if(m[i][j]) {
-                printf(format, m[i][j]);
-            } else {
-                printf("%s", str);
-            }
-        }
-        printf("\n");
-    }    
-}
-// ------------------------------------------------------------------------------------------------
-void display_ui8matrix_positive(uint8 **m, int i0, int i1, int j0, int j1, int iformat, char *name)
-// ------------------------------------------------------------------------------------------------
-{
-    int i, j;
-    
-    char * format;
-    char * str;
-    
-    select_display_positive_parameters(iformat, &format, &str);
-    
-    if (name != NULL) {
-        printf("%s\n", name);
-    }
-    
-    // @QM have to hack this function for the giet
-    for (i = i0; i <= i1; i++) {
-        for (j = j0; j <= j1; j++) {
-            if (m[i][j]) {
-                // For the giet
-                int a = m[i][j];
-                int len = 0;
-                if (a == 0) {
-                    len = 1;
-                }
-                else {
-                    while (a != 0) {
-                        a = a / 10;
-                        len++;
-                    }
-                }
-                for (int k = len; k < iformat; k++) {
-                    printf(" ");
-                }
-                printf("%d", m[i][j]);
-            }
-            else {
-                printf("%s", str);
-            }
-        }
-        printf("\n");
-    }    
-}
-
-
-// --------------------------------------------------------------------------------------------------
-void display_si16matrix_positive(sint16 **m, int i0, int i1, int j0, int j1, int iformat, char *name)
-// --------------------------------------------------------------------------------------------------
-{
-    int i, j;
-    
-    char *format, *str;
-    
-    select_display_positive_parameters(iformat, &format, &str);
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {
-        for(j=j0; j<=j1; j++) {
-            if(m[i][j]) {
-                printf(format, m[i][j]);
-            } else {
-                printf("%s", str);
-            }
-        }
-        printf("\n");
-    }    
-}
-// --------------------------------------------------------------------------------------------------
-void display_ui16matrix_positive(uint16 **m, int i0, int i1, int j0, int j1, int iformat, char *name)
-// --------------------------------------------------------------------------------------------------
-{
-    int i, j;
-    char *format, *str;
-    
-    select_display_positive_parameters(iformat, &format, &str);
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {
-        for(j=j0; j<=j1; j++) {
-            if(m[i][j]) {
-                printf(format, m[i][j]);
-            } else {
-                printf("%s", str);
-            }
-        }
-        printf("\n");
-    }    
-}
-// --------------------------------------------------------------------------------------------------
-void display_si32matrix_positive(sint32 **m, int i0, int i1, int j0, int j1, int iformat, char *name)
-// --------------------------------------------------------------------------------------------------
-{
-    int i, j;
-    char *format, *str;
-    
-    select_display_positive_parameters(iformat, &format, &str);
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {
-        for(j=j0; j<=j1; j++) {
-            if(m[i][j]) {
-                printf(format, m[i][j]);
-            } else {
-                printf("%s", str);
-            }
-        }
-        printf("\n");
-    }    
-}
-// --------------------------------------------------------------------------------------------------
-void display_ui32matrix_positive(uint32 **m, int i0, int i1, int j0, int j1, int iformat, char *name)
-// --------------------------------------------------------------------------------------------------
-{
-    int i, j;
-    char * format;
-    char * str;
-    
-    select_display_positive_parameters(iformat, &format, &str);
-    
-    if (name != NULL) {
-        printf("%s\n", name);
-    }
-    
-    // @QM have to hack this function for the giet
-    for (i = i0; i <= i1; i++) {
-        for (j = j0; j <= j1; j++) {
-            if (m[i][j] != 0) {
-                int a = m[i][j];
-                int len = 0;
-                if (a == 0) {
-                    len = 1;
-                }
-                else {
-                    while (a != 0) {
-                        a = a / 10;
-                        len++;
-                    }
-                }
-                for (int k = len; k < iformat; k++) {
-                    printf(" ");
-                }
-                printf("%d", m[i][j]);
-            }
-            else {
-                printf("%s", str);
-            }
-        }
-        printf("\n");
-    }    
-
-}
-// --------------------------------------------------------------------------------------------------
-void display_si64matrix_positive(sint64 **m, int i0, int i1, int j0, int j1, int iformat, char *name)
-// --------------------------------------------------------------------------------------------------
-{
-    int i, j;
-    char *format, *str;
-    
-    select_display_positive_parameters(iformat, &format, &str);
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {
-        for(j=j0; j<=j1; j++) {
-            if(m[i][j]) {
-                printf(format, m[i][j]);
-            } else {
-                printf("%s", str);
-            }
-        }
-        printf("\n");
-    }    
-}
-// --------------------------------------------------------------------------------------------------
-void display_ui64matrix_positive(uint64 **m, int i0, int i1, int j0, int j1, int iformat, char *name)
-// --------------------------------------------------------------------------------------------------
-{
-    int i, j;
-    char *format, *str;
-    
-    select_display_positive_parameters(iformat, &format, &str);
-    
-    if(name != NULL) printf(name);
-    
-    for(i=i0; i<=i1; i++) {
-        for(j=j0; j<=j1; j++) {
-            if(m[i][j]) {
-                printf(format, m[i][j]);
-            } else {
-                printf("%s", str);
-            }
-        }
-        printf("\n");
-    }    
-}
-
+#if TARGET_OS != GIETVM
+
+#undef display_type_matrix_positive
+#define display_type_matrix_positive(t) \
+void short_name(t,display_,matrix_positive)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, int32_t iformat, char * name) \
+{                                                               \
+    char * format;                                              \
+    char * str;                                                 \
+    select_display_positive_parameters(iformat, &format, &str); \
+    if (name != NULL) {                                         \
+        printf("%s\n", name);                                   \
+    }                                                           \
+    for (int32_t i = i0; i <= i1; i++) {                        \
+        for (int32_t j = j0; j <= j1; j++) {                    \
+            if (m[i][j] != 0) {                                 \
+                printf(format, m[i][j]);                        \
+            }                                                   \
+            else {                                              \
+                printf("%s", str);                              \
+            }                                                   \
+        }                                                       \
+        printf("\n");                                           \
+    }                                                           \
+    printf("\n");                                               \
+}
+
+#else
+
+#undef display_type_matrix_positive
+#define display_type_matrix_positive(t) \
+void short_name(t,display_,matrix_positive)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, int32_t iformat, char * name) \
+{                                                               \
+    char * format;                                              \
+    char * str;                                                 \
+    select_display_positive_parameters(iformat, &format, &str); \
+    if (name != NULL) {                                         \
+        printf("%s\n", name);                                   \
+    }                                                           \
+    for (int32_t i = i0; i <= i1; i++) {                        \
+        for (int32_t j = j0; j <= j1; j++) {                    \
+            if (m[i][j] != 0) {                                 \
+                int32_t a = m[i][j];                            \
+                int32_t len = 0;                                \
+                if (a == 0) {                                   \
+                    len = 1;                                    \
+                }                                               \
+                else {                                          \
+                    while (a != 0) {                            \
+                        a = a / 10;                             \
+                        len++;                                  \
+                    }                                           \
+                }                                               \
+                for (int32_t k = len; k < iformat; k++) {       \
+                    printf(" ");                                \
+                }                                               \
+                printf(format, m[i][j]);                        \
+            }                                                   \
+            else {                                              \
+                printf("%s", str);                              \
+            }                                                   \
+        }                                                       \
+        printf("\n");                                           \
+    }                                                           \
+    printf("\n");                                               \
+}
+
+#endif
+
+
+display_type_matrix_positive(int8_t);
+display_type_matrix_positive(uint8_t);
+display_type_matrix_positive(int16_t);
+display_type_matrix_positive(uint16_t);
+display_type_matrix_positive(int32_t);
+display_type_matrix_positive(uint32_t);
+display_type_matrix_positive(int64_t);
+display_type_matrix_positive(uint64_t);
+display_type_matrix_positive(float);
+display_type_matrix_positive(double);
 
 
@@ -974,31 +399,30 @@
 
 /* ------------------------------------------------- */
-static void ReadPGMrow(int fd, int width, uint8 * line)
+static void ReadPGMrow(int32_t fd, int32_t width, uint8 * line)
 /* ------------------------------------------------- */
 {
-    read(fd, &line[0], sizeof(uint8) * width);
+    read(fd, &line[0], sizeof(uint8_t) * width);
 }
 
 
 /* -------------------------------------------------- */
-static void WritePGMrow(uint8 * line, int width, int fd)
+static void WritePGMrow(uint8_t * line, int32_t width, int32_t fd)
 /* -------------------------------------------------- */
 {
-    write(fd, &line[0], sizeof(uint8) * width);
+    write(fd, &line[0], sizeof(uint8_t) * width);
 }
 
 
 /* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(uint8 **) LoadPGM_ui8matrix(char * filename, int * nrl, int * nrh, int * ncl, int * nch)
+uint8_t ** LoadPGM_ui8matrix(char * filename, int * nrl, int * nrh, int * ncl, int * nch)
 /* ----------------------------------------------------------------------------------------------- */
 {
     // only for P5 binary type, not for text type
     
-    int height, width, gris;
-    uint8 ** m;
-    int fd;
+    int32_t height, width, gris;
+    uint8_t ** m;
+    int32_t fd;
     
     char buffer[80];
-    int i;
     (void) gris;
     
@@ -1026,5 +450,5 @@
     m = ui8matrix(*nrl, *nrh, *ncl, *nch);
     
-    for (i = 0; i < height; i++) {
+    for (int32_t i = 0; i < height; i++) {
         ReadPGMrow(fd, width, m[i]);
     }
@@ -1037,14 +461,13 @@
 
 /* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) SavePGM_ui8matrix(uint8 ** m, int nrl, int nrh, int ncl, int nch, char * filename)
+void SavePGM_ui8matrix(uint8 ** m, int nrl, int nrh, int ncl, int nch, char * filename)
 /* ----------------------------------------------------------------------------------------------- */
 {
-    int nrow = nrh - nrl + 1;
-    int ncol = nch - ncl + 1;
+    int32_t nrow = nrh - nrl + 1;
+    int32_t ncol = nch - ncl + 1;
     
     char buffer[80];
     
-    int fd;
-    int i;
+    int32_t fd;
     
     //fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT);
@@ -1058,5 +481,5 @@
     snprintf(buffer, 80, "P5\n%d %d\n255\n", ncol, nrow);
     write(fd, buffer, strlen(buffer));
-    for (i = nrl; i <= nrh; i++) {
+    for (int32_t i = nrl; i <= nrh; i++) {
         WritePGMrow(m[i], ncol, fd);
     }
@@ -1068,2 +491,11 @@
 
 
+// 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/nrio2f.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrio2f.c	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrio2f.c	(revision 822)
@@ -15,5 +15,8 @@
 #include <stddef.h>
 #include <stdlib.h>
-
+#include <string.h>
+#include <ctype.h>
+
+#include "nrc_os_config.h"
 #include "mypredef.h"
 #include "nrtype.h"
@@ -34,256 +37,40 @@
  */
 
-/* ---------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_si8matrix(sint8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ---------------------------------------------------------------------------------------------------------- */
-{
-    int  i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_si8matrix");
-    }
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* ---------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui8matrix(uint8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ---------------------------------------------------------------------------------------------------------- */
-{
-    int  i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_ui8matrix");
-    }
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) write_si16matrix(sint16 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------ */
-{
-    int  i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_si16matrix");
-    }
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) write_ui16matrix(uint16 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------ */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_ui16matrix");
-    }
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) write_si32matrix(sint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------ */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_si32matrix");
-    }
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) write_ui32matrix(uint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------ */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_ui32matrix");
-    }
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) write_si64matrix(sint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------ */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_si64matrix");
-    }
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) write_ui64matrix(uint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------ */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_ui64matrix");
-    }
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) write_f32matrix(float32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------ */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_f32matrix");
-    }
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) write_f64matrix(float64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------ */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_f64matrix");
-    }
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* ---------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_rgb8matrix(rgb8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ---------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_rgb8matrix");
-    }
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            fprintf(f, format, m[i][j].r, m[i][j].g, m[i][j].b);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) write_rgbx8matrix(rgbx8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------ */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_rgbx8matrix");
-    }
-    
-    for(i=nrl; i<=nrh; i++) {
-        for(j=ncl; j<=nch; j++) {
-            fprintf(f, format, m[i][j].r, m[i][j].g, m[i][j].b, m[i][j].x);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
+#undef write_type_matrix
+#define write_type_matrix(t) \
+void short_name(t,write_,matrix)(t ** m, 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 i = nrl; i <= nrh; i++) {                       \
+        for (int32_t j = ncl; j <= nch; j++) {                   \
+            fprintf(f, format, elem);                            \
+        }                                                        \
+        fprintf(f, "\n");                                        \
+    }                                                            \
+    fclose(f);                                                   \
+}
+
+#undef elem
+#define elem m[i][j]
+write_type_matrix(int8_t);
+write_type_matrix(uint8_t);
+write_type_matrix(int16_t);
+write_type_matrix(uint16_t);
+write_type_matrix(int32_t);
+write_type_matrix(uint32_t);
+write_type_matrix(int64_t);
+write_type_matrix(uint64_t);
+write_type_matrix(float);
+write_type_matrix(double);
+#undef elem
+#define elem m[i][j].r, m[i][j].g, m[i][j].b
+write_type_matrix(rgb8);
+#undef elem
+#define elem m[i][j].r, m[i][j].g, m[i][j].b, m[i][j].x
+write_type_matrix(rgbx8);
+
 
 /*
@@ -293,214 +80,42 @@
  */
 
-/* ------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) write_si8matrix_T(sint8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------ */
-{
-    long  i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_si8matrix_T");
-    }
-    
-    for(j=ncl; j<=nch; j++) {
-        for(i=nrl; i<=nrh; i++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) write_ui8matrix_T(uint8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------ */
-{
-    long  i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_ui8matrix_T");
-    }
-    
-    for(j=ncl; j<=nch; j++) {
-        for(i=nrl; i<=nrh; i++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* -------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_si32matrix_T(sint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* -------------------------------------------------------------------------------------------------------------- */
-{
-    long  i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_si32matrix_T");
-    }
-    
-    for(j=ncl; j<=nch; j++) {
-        for(i=nrl; i<=nrh; i++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* -------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui32matrix_T(uint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* -------------------------------------------------------------------------------------------------------------- */
-{
-    long  i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_ui32matrix_T");
-    }
-    
-    for(j=ncl; j<=nch; j++) {
-        for(i=nrl; i<=nrh; i++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* -------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_si64matrix_T(sint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* -------------------------------------------------------------------------------------------------------------- */
-{
-    long  i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_si64matrix_T");
-    }
-    
-    for(j=ncl; j<=nch; j++) {
-        for(i=nrl; i<=nrh; i++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* -------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui64matrix_T(uint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* -------------------------------------------------------------------------------------------------------------- */
-{
-    long  i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_ui64matrix_T");
-    }
-    
-    for(j=ncl; j<=nch; j++) {
-        for(i=nrl; i<=nrh; i++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* -------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_f32matrix_T(float32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* -------------------------------------------------------------------------------------------------------------- */
-{
-    long  i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_f32matrix");
-    }
-    
-    for(j=ncl; j<=nch; j++) {
-        for(i=nrl; i<=nrh; i++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* -------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_f64matrix_T(float64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* -------------------------------------------------------------------------------------------------------------- */
-{
-    long  i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_f64matrix");
-    }
-    
-    for(j=ncl; j<=nch; j++) {
-        for(i=nrl; i<=nrh; i++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) write_rgb8matrix_T(rgb8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------ */
-{
-    long  i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_rgb8matrix");
-    }
-    
-    for(j=ncl; j<=nch; j++) {
-        for(i=nrl; i<=nrh; i++) {
-            fprintf(f, format, m[i][j].r, m[i][j].g, m[i][j].b);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* -------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_rgbx8matrix_T(rgbx8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* -------------------------------------------------------------------------------------------------------------- */
-{
-    long  i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_rgb8matrix");
-    }
-    
-    for(j=ncl; j<=nch; j++) {
-        for(i=nrl; i<=nrh; i++) {
-            fprintf(f, format, m[i][j].r, m[i][j].g, m[i][j].b, m[i][j].x);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
+
+#undef write_type_matrix_T
+#define write_type_matrix_T(t) \
+void short_name(t,write_,matrix_T)(t ** m, 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 j = ncl; j <= nch; j++) {                       \
+        for (int32_t i = nrl; i <= nrh; i++) {                   \
+            fprintf(f, format, elem);                            \
+        }                                                        \
+        fprintf(f, "\n");                                        \
+    }                                                            \
+    fclose(f);                                                   \
+}
+
+#undef elem
+#define elem m[i][j]
+write_type_matrix_T(int8_t);
+write_type_matrix_T(uint8_t);
+write_type_matrix_T(int16_t);
+write_type_matrix_T(uint16_t);
+write_type_matrix_T(int32_t);
+write_type_matrix_T(uint32_t);
+write_type_matrix_T(int64_t);
+write_type_matrix_T(uint64_t);
+write_type_matrix_T(float);
+write_type_matrix_T(double);
+#undef elem
+#define elem m[i][j].r, m[i][j].g, m[i][j].b
+write_type_matrix_T(rgb8);
+#undef elem
+#define elem m[i][j].r, m[i][j].g, m[i][j].b, m[i][j].x
+write_type_matrix_T(rgbx8);
+
+
 
 /*
@@ -510,352 +125,49 @@
  */
 
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_si8matrix_number(sint8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_si8matrix_number");
-    }
-    
-    // entete
-    fprintf(f, "%5c", '#');
-    for(j=ncl; j<=nch; j++) {
-        fprintf(f, format, j);
-    }
-    fputc('\n', f);
-    
-    for(i=nrl; i<=nrh; i++) {
-        fprintf(f, "[%3d]", i);
-        for(j=ncl; j<=nch; j++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui8matrix_number(uint8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_ui8matrix_number");
-    }
-    
-    // entete
-    fprintf(f, "%5c", '#');
-    for(j=ncl; j<=nch; j++) {
-        fprintf(f, format, j);
-    }
-    fputc('\n', f);
-    
-    for(i=nrl; i<=nrh; i++) {
-        fprintf(f, "[%3d]", i);
-        for(j=ncl; j<=nch; j++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_si16matrix_number(sint16 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_si16matrix");
-    }
-    
-    // entete
-    fprintf(f, "%5c", '#');
-    for(j=ncl; j<=nch; j++) {
-        fprintf(f, format, j);
-    }
-    fputc('\n', f);
-    
-    for(i=nrl; i<=nrh; i++) {
-        fprintf(f, "[%3d]", i);
-        for(j=ncl; j<=nch; j++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui16matrix_number(uint16 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_ui16matrix");
-    }
-    
-    // entete
-    fprintf(f, "%5c", '#');
-    for(j=ncl; j<=nch; j++) {
-        fprintf(f, format, j);
-    }
-    fputc('\n', f);
-    
-    for(i=nrl; i<=nrh; i++) {
-        fprintf(f, "[%3d]", i);
-        for(j=ncl; j<=nch; j++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_si32matrix_number(sint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_si32matrix");
-    }
-    
-    // entete
-    fprintf(f, "%5c", '#');
-    for(j=ncl; j<=nch; j++) {
-        fprintf(f, format, j);
-    }
-    fputc('\n', f);
-    
-    for(i=nrl; i<=nrh; i++) {
-        fprintf(f, "[%3d]", i);
-        for(j=ncl; j<=nch; j++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui32matrix_number(uint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_ui32matrix");
-    }
-    
-    // entete
-    fprintf(f, "%5c", '#');
-    for(j=ncl; j<=nch; j++) {
-        fprintf(f, format, j);
-    }
-    fputc('\n', f);
-    
-    for(i=nrl; i<=nrh; i++) {
-        fprintf(f, "[%3d]", i);
-        for(j=ncl; j<=nch; j++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_si64matrix_number(sint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_si64matrix");
-    }
-    
-    // entete
-    fprintf(f, "%5c", '#');
-    for(j=ncl; j<=nch; j++) {
-        fprintf(f, format, j);
-    }
-    fputc('\n', f);
-    
-    for(i=nrl; i<=nrh; i++) {
-        fprintf(f, "[%3d]", i);
-        for(j=ncl; j<=nch; j++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui64matrix_number(uint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_ui64matrix");
-    }
-    
-    // entete
-    fprintf(f, "%5c", '#');
-    for(j=ncl; j<=nch; j++) {
-        fprintf(f, format, j);
-    }
-    fputc('\n', f);
-    
-    for(i=nrl; i<=nrh; i++) {
-        fprintf(f, "[%3d]", i);
-        for(j=ncl; j<=nch; j++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_f32matrix_number(float32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_f32matrix_number");
-    }
-    
-    // entete
-    fprintf(f, "%4d", 0);
-    for(j=ncl; j<=nch; j++) {
-        fprintf(f, format, (float32)j);
-    }
-    fputc('\n', f);
-    
-    for(i=nrl; i<=nrh; i++) {
-        fprintf(f, "%4d", i);
-        for(j=ncl; j<=nch; j++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_f64matrix_number(float64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_f64matrix_number");
-    }
-    
-    // entete
-    fprintf(f, "%4d", 0);
-    for(j=ncl; j<=nch; j++) {
-        fprintf(f, format, (float32)j);
-    }
-    fputc('\n', f);
-    
-    for(i=nrl; i<=nrh; i++) {
-        fprintf(f, "%4d", i);
-        for(j=ncl; j<=nch; j++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_rgb8matrix_number(rgb8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_rgb8matrix_number");
-    }
-    
-    // entete
-    fprintf(f, "%4d", 0);
-    for(j=ncl; j<=nch; j++) {
-        fprintf(f, format, (float32)j);
-    }
-    fputc('\n', f);
-    
-    for(i=nrl; i<=nrh; i++) {
-        fprintf(f, "%4d", i);
-        for(j=ncl; j<=nch; j++) {
-            fprintf(f, format, m[i][j].r, m[i][j].g, m[i][j].b);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_rgb8xmatrix_number(rgbx8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_rgbx8matrix_number");
-    }
-    
-    // entete
-    fprintf(f, "%4d", 0);
-    for(j=ncl; j<=nch; j++) {
-        fprintf(f, format, (float32)j);
-    }
-    fputc('\n', f);
-    
-    for(i=nrl; i<=nrh; i++) {
-        fprintf(f, "%4d", i);
-        for(j=ncl; j<=nch; j++) {
-            fprintf(f, format, m[i][j].r, m[i][j].g, m[i][j].b, m[i][j].x);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
+
+#undef write_type_matrix_number
+#define write_type_matrix_number(t) \
+void short_name(t,write_,matrix_number)(t ** m, 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__); \
+    }                                                            \
+    fprintf(f, "%5c", '#');                                      \
+    for (int32_t j = ncl; j <= nch; j++) {                       \
+        fprintf(f, format, j);                                   \
+    }                                                            \
+    fprintf(f, "\n");                                            \
+    for (int32_t i = nrl; i <= nrh; i++) {                       \
+        fprintf(f, "[%3d]", i);                                  \
+        for (int32_t j = ncl; j <= nch; j++) {                   \
+            fprintf(f, format, m[i][j]);                         \
+        }                                                        \
+        fprintf(f, "\n");                                        \
+    }                                                            \
+    fclose(f);                                                   \
+}
+
+
+#undef elem
+#define elem m[i][j]
+write_type_matrix_number(int8_t);
+write_type_matrix_number(uint8_t);
+write_type_matrix_number(int16_t);
+write_type_matrix_number(uint16_t);
+write_type_matrix_number(int32_t);
+write_type_matrix_number(uint32_t);
+write_type_matrix_number(int64_t);
+write_type_matrix_number(uint64_t);
+write_type_matrix_number(float);
+write_type_matrix_number(double);
+#undef elem
+#define elem m[i][j].r, m[i][j].g, m[i][j].b
+write_type_matrix_number(rgb8);
+#undef elem
+#define elem m[i][j].r, m[i][j].g, m[i][j].b, m[i][j].x
+write_type_matrix_number(rgbx8);
+
+
 /*
  * -----------------------------
@@ -863,344 +175,50 @@
  * -----------------------------
  */
-/* ------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_si8matrix_T_number(sint8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_si8matrix_T_number");
-    }
-    
-    fprintf(f, "%5c", '#');
-    for(i=nrl; i<=nrh; i++) {
-        fprintf(f, format, i);
-    }
-    fputc('\n', f);
-       
-    for(j=ncl; j<=nch; j++) {
-        fprintf(f, "[%3d]", j);
-        for(i=nrl; i<=nrh; i++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui8matrix_T_number(uint8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_ui8matrix_T_number");
-    }
-    
-    fprintf(f, "%5c", '#');
-    for(i=nrl; i<=nrh; i++) {
-        fprintf(f, format, i);
-    }
-    fputc('\n', f);
-    
-    
-    for(j=ncl; j<=nch; j++) {
-        fprintf(f, "[%3d]", j);
-        for(i=nrl; i<=nrh; i++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* --------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_si16matrix_T_number(sint16 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* --------------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_si16matrix_T_number");
-    }
-    
-    fprintf(f, "%5c", '#');
-    for(i=nrl; i<=nrh; i++) {
-        fprintf(f, format, (float)i);
-    }
-    fputc('\n', f);
-    
-    for(j=ncl; j<=nch; j++) {
-        fprintf(f, "[%3d]", j);
-        for(i=nrl; i<=nrh; i++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* --------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui16matrix_T_number(uint16 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* --------------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_ui16matrix_T_number");
-    }
-    
-    fprintf(f, "%5c", '#');
-    for(i=nrl; i<=nrh; i++) {
-        fprintf(f, format, (float)i);
-    }
-    fputc('\n', f);
-    
-    for(j=ncl; j<=nch; j++) {
-        fprintf(f, "[%3d]", j);
-        for(i=nrl; i<=nrh; i++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* --------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_si32matrix_T_number(sint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* --------------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_si32matrix_T_number");
-    }
-    
-    fprintf(f, "%5c", '#');
-    for(i=nrl; i<=nrh; i++) {
-        fprintf(f, format, (float)i);
-    }
-    fputc('\n', f);
-    
-    for(j=ncl; j<=nch; j++) {
-        fprintf(f, "[%3d]", j);
-        for(i=nrl; i<=nrh; i++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-
-/* --------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui32matrix_T_number(uint32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* --------------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_ui32matrix_T_number");
-    }
-    
-    fprintf(f, "%5c", '#');
-    for(i=nrl; i<=nrh; i++) {
-        fprintf(f, format, (float)i);
-    }
-    fputc('\n', f);
-    
-    
-    for(j=ncl; j<=nch; j++) {
-        fprintf(f, "[%3d]", j);
-        for(i=nrl; i<=nrh; i++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* --------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_si64matrix_T_number(sint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* --------------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_si64matrix_T_number");
-    }
-    
-    fprintf(f, "%5c", '#');
-    for(i=nrl; i<=nrh; i++) {
-        fprintf(f, format, (float)i);
-    }
-    fputc('\n', f);
-    
-    for(j=ncl; j<=nch; j++) {
-        fprintf(f, "[%3d]", j);
-        for(i=nrl; i<=nrh; i++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* --------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_ui64matrix_T_number(uint64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* --------------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_ui64matrix_T_number");
-    }
-    
-    fprintf(f, "%5c", '#');
-    for(i=nrl; i<=nrh; i++) {
-        fprintf(f, format, (float)i);
-    }
-    fputc('\n', f);
-    
-    for(j=ncl; j<=nch; j++) {
-        fprintf(f, "[%3d]", j);
-        for(i=nrl; i<=nrh; i++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-
-/* --------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_f32matrix_T_number(float32 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* --------------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_f32matrix_T_number");
-    }
-    
-    fprintf(f, "%5c", '#');
-    for(i=nrl; i<=nrh; i++) {
-        fprintf(f, format, (float)i);
-    }
-    fputc('\n', f);
-    
-    for(j=ncl; j<=nch; j++) {
-        fprintf(f, "[%3d]", j);
-        for(i=nrl; i<=nrh; i++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* --------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_f64matrix_T_number(float64 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* --------------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_f64matrix_T_number");
-    }
-    
-    fprintf(f, "%5c", '#');
-    for(i=nrl; i<=nrh; i++) {
-        fprintf(f, format, (float)i);
-    }
-    fputc('\n', f);
-    
-    for(j=ncl; j<=nch; j++) {
-        fprintf(f, "[%3d]", j);
-        for(i=nrl; i<=nrh; i++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_rgb8matrix_T_number(rgb8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* ------------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_rgb8matrix_T_number");
-    }
-    
-    fprintf(f, "%5c", '#');
-    for(i=nrl; i<=nrh; i++) {
-        fprintf(f, format, (float)i);
-    }
-    fputc('\n', f);   
-    
-    for(j=ncl; j<=nch; j++) {
-        fprintf(f, "[%3d]", j);
-        for(i=nrl; i<=nrh; i++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-/* --------------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) write_rgbx8matrix_T_number(rgbx8 **m,long nrl,long nrh,long ncl, long nch, char *format, char *filename)
-/* --------------------------------------------------------------------------------------------------------------------- */
-{
-    int i,j;
-    
-    FILE *f;
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_rgbx8matrix_T_number");
-    }
-    
-    fprintf(f, "%5c", '#');
-    for(i=nrl; i<=nrh; i++) {
-        fprintf(f, format, (float)i);
-    }
-    fputc('\n', f);
-    
-    for(j=ncl; j<=nch; j++) {
-        fprintf(f, "[%3d]", j);
-        for(i=nrl; i<=nrh; i++) {
-            fprintf(f, format, m[i][j]);
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
+
+
+#undef write_type_matrix_T_number
+#define write_type_matrix_T_number(t) \
+void short_name(t,write_,matrix_T_number)(t ** m, 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__); \
+    }                                                            \
+    fprintf(f, "%5c", '#');                                      \
+    for (int32_t i = nrl; i <= nrh; i++) {                       \
+        fprintf(f, format, i);                                   \
+    }                                                            \
+    fprintf(f, "\n");                                            \
+    for (int32_t j = ncl; j <= nch; j++) {                       \
+        fprintf(f, "[%3d]", j);                                  \
+        for (int32_t i = nrl; i <= nrh; i++) {                   \
+            fprintf(f, format, m[i][j]);                         \
+        }                                                        \
+        fprintf(f, "\n");                                        \
+    }                                                            \
+    fclose(f);                                                   \
+}
+
+
+#undef elem
+#define elem m[i][j]
+write_type_matrix_T_number(int8_t);
+write_type_matrix_T_number(uint8_t);
+write_type_matrix_T_number(int16_t);
+write_type_matrix_T_number(uint16_t);
+write_type_matrix_T_number(int32_t);
+write_type_matrix_T_number(uint32_t);
+write_type_matrix_T_number(int64_t);
+write_type_matrix_T_number(uint64_t);
+write_type_matrix_T_number(float);
+write_type_matrix_T_number(double);
+#undef elem
+#define elem m[i][j].r, m[i][j].g, m[i][j].b
+write_type_matrix_T_number(rgb8);
+#undef elem
+#define elem m[i][j].r, m[i][j].g, m[i][j].b, m[i][j].x
+write_type_matrix_T_number(rgbx8);
+
+
 /*
  * ---------------------
@@ -1209,190 +227,33 @@
  */
 
-/* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fwrite_si8matrix(sint8 **m,long nrl, long nrh, long ncl, long nch, char *filename)
-/* ----------------------------------------------------------------------------------------------- */
-{
-    long  i, ncol = nch-ncl+1;
-    FILE *f;
-    
-    f = fopen(filename, "wb");
-    if(f == NULL) nrerror("Can't open file in fwrite_si8matrix"); 
-    
-    for(i=nrl; i<=nrh; i++) {
-        fwrite(m[i]+nrl, sizeof(sint8), ncol, f);
-    }
-    fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) fwrite_ui8matrix(uint8 **m, long nrl, long nrh, long ncl, long nch, char *filename)
-/* ------------------------------------------------------------------------------------------------ */
-{
-    long  i, ncol = nch-ncl+1;
-    FILE *f;
-    
-    f = fopen(filename, "wb");
-    if(f == NULL) nrerror("Can't open file in fwrite_ui8matrix"); 
-    
-    for(i=nrl; i<=nrh; i++) {
-        fwrite(m[i]+nrl, sizeof(int8), ncol, f);
-    }
-    fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fwrite_si16matrix(sint16 **m,long nrl, long nrh, long ncl, long nch, char *filename)
-/* ------------------------------------------------------------------------------------------------- */
-{
-    long  i, ncol = nch-ncl+1;
-    FILE *f;
-    
-    f = fopen(filename, "wb");
-    if(f == NULL)
-        nrerror("Can't open file in fwrite_i16matrix");
-    
-    for(i=nrl; i<=nrh; i++) {
-        fwrite(m[i]+nrl, sizeof(sint16), ncol, f);
-    }
-    fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fwrite_ui16matrix(uint16 **m,long nrl, long nrh, long ncl, long nch, char *filename)
-/* ------------------------------------------------------------------------------------------------- */
-{
-    long  i, ncol = nch-ncl+1;
-    FILE *f;
-    
-    f = fopen(filename, "wb");
-    if(f == NULL)
-        nrerror("Can't open file in fwrite_ui16matrix");
-    
-    for(i=nrl; i<=nrh; i++) {
-        fwrite(m[i]+nrl, sizeof(uint16), ncol, f);
-    }
-    fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fwrite_si32matrix(sint32 **m,long nrl, long nrh, long ncl, long nch, char *filename)
-/* ------------------------------------------------------------------------------------------------- */
-{
-    long  i, ncol = nch-ncl+1;
-    FILE *f;
-    
-    f = fopen(filename, "wb");
-    if(f == NULL)
-        nrerror("Can't open file in fwrite_si32matrix");
-    
-    for(i=nrl; i<=nrh; i++) {
-        fwrite(m[i]+nrl, sizeof(sint32), ncol, f);
-    }
-    fclose(f);
-}
-/* ------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fwrite_ui32matrix(uint32 **m,long nrl, long nrh, long ncl, long nch, char *filename)
-/* ------------------------------------------------------------------------------------------------- */
-{
-    long  i, ncol = nch-ncl+1;
-    FILE *f;
-    
-    f = fopen(filename, "wb");
-    if(f == NULL)
-        nrerror("Can't open file in fwrite_ui32matrix");
-    
-    for(i=nrl; i<=nrh; i++) {
-        fwrite(m[i]+nrl, sizeof(uint32), ncol, f);
-    }
-    fclose(f);
-}
-/* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fwrite_si64matrix(sint64 **m,long nrl,long nrh,long ncl, long nch, char *filename)
-/* ----------------------------------------------------------------------------------------------- */
-{
-    long  i, ncol = nch-ncl+1;
-    FILE *f;
-    
-    f = fopen(filename, "wb");
-    if(f == NULL)
-        nrerror("Can't open file in fwrite_si64matrix");
-    
-    for(i=nrl; i<=nrh; i++) {
-        fwrite(m[i]+nrl, sizeof(sint64), ncol, f);
-    }
-    fclose(f);
-}
-/* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fwrite_ui64matrix(uint64 **m,long nrl,long nrh,long ncl, long nch, char *filename)
-/* ----------------------------------------------------------------------------------------------- */
-{
-    long  i, ncol = nch-ncl+1;
-    FILE *f;
-    
-    f = fopen(filename, "wb");
-    if(f == NULL)
-        nrerror("Can't open file in fwrite_ui64matrix");
-    
-    for(i=nrl; i<=nrh; i++) {
-        fwrite(m[i]+nrl, sizeof(uint64), ncol, f);
-    }
-    fclose(f);
-}
-/* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fwrite_f32matrix(float32 **m,long nrl,long nrh,long ncl, long nch, char *filename)
-/* ----------------------------------------------------------------------------------------------- */
-{
-    long  i, ncol = nch-ncl+1;
-    FILE *f;
-    
-    f = fopen(filename, "wb");
-    if(f == NULL) nrerror("Can't open file in fwrite_f32matrix");
-    
-    for(i=nrl; i<=nrh; i++) {
-        fwrite(m[i]+nrl, sizeof(float32), ncol, f);
-    }
-    fclose(f);
-}
-/* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fwrite_f64matrix(float64 **m,long nrl,long nrh,long ncl, long nch, char *filename)
-/* ----------------------------------------------------------------------------------------------- */
-{
-    long  i, ncol = nch-ncl+1;
-    FILE *f;
-    
-    f = fopen(filename, "wb");
-    if(f == NULL) nrerror("Can't open file in f64write_matrix");
-    
-    for(i=nrl; i<=nrh; i++) {
-        fwrite(m[i]+nrl, sizeof(float64), ncol, f);
-    }
-    fclose(f);
-}
-/* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fwrite_rgb8matrix(rgb8 **m,long nrl,long nrh,long ncl, long nch, char *filename)
-/* --------------------------------------------------------------------------------------------- */
-{
-    long  i, ncol = nch-ncl+1;
-    FILE *f;
-    
-    f = fopen(filename, "wb");
-    if(f == NULL) nrerror("Can't open file in fwrite_rgb8matrix");
-    
-    for(i=nrl; i<=nrh; i++) {
-        fwrite(m[i]+nrl, sizeof(rgb8), ncol, f);
-    }
-    fclose(f);
-}
-/* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fwrite_rgbx8matrix(rgbx8 **m,long nrl,long nrh,long ncl, long nch, char *filename)
-/* ----------------------------------------------------------------------------------------------- */
-{
-    long  i, ncol = nch-ncl+1;
-    FILE *f;
-    
-    f = fopen(filename, "wb");
-    if(f == NULL) nrerror("Can't open file in fwrite_rgbx8matrix");
-    
-    for(i=nrl; i<=nrh; i++) {
-        fwrite(m[i]+nrl, sizeof(rgbx8), ncol, f);
-    }
-    fclose(f);
-}
+#undef fwrite_type_matrix
+#define fwrite_type_matrix(t) \
+void short_name(t,fwrite_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * filename) \
+{                                                                \
+    int32_t ncol = nch - ncl + 1;                                \
+    FILE * f = fopen(filename, "wb");                            \
+    if (f == NULL) {                                             \
+        nrerror("Can't open file %s in %s", filename, __func__); \
+    }                                                            \
+    for (int32_t i = nrl; i <= nrh; i++) {                       \
+        fwrite(m[i] + nrl, sizeof(t), ncol, f);                  \
+    }                                                            \
+    fclose(f);                                                   \
+}
+
+fwrite_type_matrix(int8_t);
+fwrite_type_matrix(uint8_t);
+fwrite_type_matrix(int16_t);
+fwrite_type_matrix(uint16_t);
+fwrite_type_matrix(int32_t);
+fwrite_type_matrix(uint32_t);
+fwrite_type_matrix(int64_t);
+fwrite_type_matrix(uint64_t);
+fwrite_type_matrix(float);
+fwrite_type_matrix(double);
+fwrite_type_matrix(rgb8);
+fwrite_type_matrix(rgbx8);
+
+
 
 /*
@@ -1402,250 +263,68 @@
  */
 
-/* -------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fread_si8matrix(char *filename, sint8 **m,long nrl,long nrh,long ncl, long nch)
-/* -------------------------------------------------------------------------------------------- */
-{
-    long  i, ncol = nch-ncl+1, nread;
-    FILE *f;
-    
-    f = fopen(filename, "rb");
-    if(f == NULL) nrerror("Can't open file in fread_i8matrix"); 
-    
-    for(i=nrl; i<=nrh; i++) {
-        nread = fread(m[i]+ncl, sizeof(sint8), ncol, f);
-        if(nread != ncol) nrerror("fread_si8matrix : can't read data");
-    }
-    fclose(f);
-}
-/* -------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fread_ui8matrix(char *filename, uint8 **m,long nrl,long nrh,long ncl, long nch)
-/* -------------------------------------------------------------------------------------------- */
-{
-    long  i, ncol = nch-ncl+1, nread;
-    FILE *f;
-    
-    f = fopen(filename, "rb");
-    if(f == NULL) nrerror("Can't open file in fread_ui8matrix"); 
-    
-    for(i=nrl; i<=nrh; i++) {
-        nread = fread(m[i]+ncl, sizeof(uint8), ncol, f);
-        if(nread != ncol) nrerror("fread_ui8matrix : can't read data");
-    }
-    fclose(f);
-}
-/* ---------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fread_si32matrix(char *filename, sint32 **m,long nrl,long nrh,long ncl, long nch)
-/* ---------------------------------------------------------------------------------------------- */
-{
-    long  i, ncol = nch-ncl+1, nread;
-    FILE *f;
-    
-    f = fopen(filename, "rb");
-    if(f == NULL)
-        nrerror("Can't open file in fread_si32matrix");
-    
-    for(i=nrl; i<=nrh; i++) {
-        nread = fread(m[i]+ncl, sizeof(sint32), ncol, f);
-        if(nread != ncol) nrerror("fread_si32matrix : can't read data");
-    }
-    fclose(f);
-}
-/* ---------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fread_ui32matrix(char *filename, uint32 **m,long nrl,long nrh,long ncl, long nch)
-/* ---------------------------------------------------------------------------------------------- */
-{
-    long  i, ncol = nch-ncl+1, nread;
-    FILE *f;
-    
-    f = fopen(filename, "rb");
-    if(f == NULL)
-        nrerror("Can't open file in fread_ui32matrix");
-    
-    for(i=nrl; i<=nrh; i++) {
-        nread = fread(m[i]+ncl, sizeof(uint32), ncol, f);
-        if(nread != ncol) nrerror("fread_ui32matrix : can't read data");
-    }
-    fclose(f);
-}
-/* ---------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fread_si64matrix(char *filename, sint64 **m,long nrl,long nrh,long ncl, long nch)
-/* ---------------------------------------------------------------------------------------------- */
-{
-    long  i, ncol = nch-ncl+1, nread;
-    FILE *f;
-    
-    f = fopen(filename, "rb");
-    if(f == NULL)
-        nrerror("Can't open file in fread_si64matrix");
-    
-    for(i=nrl; i<=nrh; i++) {
-        nread = fread(m[i]+ncl, sizeof(sint32), ncol, f);
-        if(nread != ncol) nrerror("fread_si64matrix : can't read data");
-    }
-    fclose(f);
-}
-/* ---------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fread_ui64matrix(char *filename, uint64 **m,long nrl,long nrh,long ncl, long nch)
-/* ---------------------------------------------------------------------------------------------- */
-{
-    long  i, ncol = nch-ncl+1, nread;
-    FILE *f;
-    
-    f = fopen(filename, "rb");
-    if(f == NULL)
-        nrerror("Can't open file in fread_ui64matrix");
-    
-    for(i=nrl; i<=nrh; i++) {
-        nread = fread(m[i]+ncl, sizeof(uint64), ncol, f);
-        if(nread != ncol) nrerror("fread_ui64matrix : can't read data");
-    }
-    fclose(f);
-}
-/* ---------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fread_f32matrix(char *filename, float32 **m,long nrl,long nrh,long ncl, long nch)
-/* ---------------------------------------------------------------------------------------------- */
-{
-    long  i, ncol = nch-ncl+1, nread;
-    FILE *f;
-    
-    f = fopen(filename, "rb");
-    if(f == NULL) nrerror("Can't open file in fread_f32matrix");
-    
-    for(i=nrl; i<=nrh; i++) {
-        nread = fread(m[i]+ncl, sizeof(float32), ncol, f);
-        if(nread != ncol) nrerror("fread_f32matrix : can't read data");
-    }
-    fclose(f);
-}
-/* ---------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fread_f64matrix(char *filename, float64 **m,long nrl,long nrh,long ncl, long nch)
-/* ---------------------------------------------------------------------------------------------- */
-{
-    long  i, ncol = nch-ncl+1, nread;
-    FILE *f;
-    
-    f = fopen(filename, "rb");
-    if(f == NULL) nrerror("Can't open file in fread_f64matrix");
-    
-    for(i=nrl; i<=nrh; i++) {
-        nread = fread(m[i]+ncl, sizeof(float64), ncol, f);
-        if(nread != ncol) nrerror("fread_f64matrix : can't read data");
-    }
-    fclose(f);
-}
-/* -------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fread_rgb8matrix(char *filename, rgb8 **m,long nrl,long nrh,long ncl, long nch)
-/* -------------------------------------------------------------------------------------------- */
-{
-    long  i, ncol = nch-ncl+1, nread;
-    FILE *f;
-    
-    f = fopen(filename, "rb");
-    if(f == NULL) nrerror("Can't open file in fread_rgb8matrix");
-    
-    for(i=nrl; i<=nrh; i++) {
-        nread = fread(m[i]+ncl, sizeof(rgb8), ncol, f);
-        if(nread != ncol) nrerror("fread_rgb8matrix : can't read data");
-    }
-    fclose(f);
-}
-/* ---------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) fread_rgbx8matrix(char *filename, rgbx8 **m,long nrl,long nrh,long ncl, long nch)
-/* ---------------------------------------------------------------------------------------------- */
-{
-    long  i, ncol = nch-ncl+1, nread;
-    FILE *f;
-    
-    f = fopen(filename, "rb");
-    if(f == NULL) nrerror("Can't open file in fread_rgbx8matrix");
-    
-    for(i=nrl; i<=nrh; i++) {
-        nread = fread(m[i]+ncl, sizeof(rgbx8), ncol, f);
-        if(nread != ncol) nrerror("fread_rgbx8matrix : can't read data");
-    }
-    fclose(f);
-}
-// --------------------------------------------------------------------------------------------------
-void write_ui8matrix_positive(uint8 **m, int i0, int i1, int j0, int j1, int iformat, char *filename)
-// --------------------------------------------------------------------------------------------------
-{
-    int i, j;
-    char *format, *str;
-    FILE *f;
-    
-    select_display_positive_parameters(iformat, &format, &str);
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_ui8matrix_positive");
-    }
-    
-    for(i=i0; i<=i1; i++) {
-        for(j=j0; j<=j1; j++) {
-            if(m[i][j]) {
-                fprintf(f, format, m[i][j]);
-            } else {
-                fprintf(f, "%s", str);
-            }
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-
-// ----------------------------------------------------------------------------------------------------
-void write_ui16matrix_positive(uint16 **m, int i0, int i1, int j0, int j1, int iformat, char *filename)
-// ----------------------------------------------------------------------------------------------------
-{
-    int i, j;
-    char *format, *str;
-    FILE *f;
-    
-    select_display_positive_parameters(iformat, &format, &str);
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_ui16matrix_positive");
-    }
-    
-    for(i=i0; i<=i1; i++) {
-        for(j=j0; j<=j1; j++) {
-            if(m[i][j]) {
-                fprintf(f, format, m[i][j]);
-            } else {
-                fprintf(f, "%s", str);
-            }
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
-// ---------------------------------------------------------------------------------------------------
-void write_ui32matrix_positive(uint32 **m,int i0, int i1, int j0, int j1, int iformat, char *filename)
-// ---------------------------------------------------------------------------------------------------
-{
-    int i, j;
-    char *format, *str;
-    FILE *f;
-    
-    select_display_positive_parameters(iformat, &format, &str);
-    
-    f = fopen(filename, "wt");
-    if(f == NULL) {
-        nrerror("Can't open file in write_ui32matrix_positive");
-    }
-    
-    for(i=i0; i<=i1; i++) {
-        for(j=j0; j<=j1; j++) {
-            if(m[i][j]) {
-                fprintf(f, format, m[i][j]);
-            } else {
-                fprintf(f, "%s", str);
-            }
-        }
-        fputc('\n', f);
-    }
-    fclose(f);
-}
+#undef fread_type_matrix
+#define fread_type_matrix(t) \
+void short_name(t,fread_,matrix)(char * filename, t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch)  \
+{                                                                \
+    int32_t ncol = nch - ncl + 1;                                \
+    int32_t nread;                                               \
+    FILE * f = fopen(filename, "rb");                            \
+    if (f == NULL) {                                             \
+        nrerror("Can't open file %s in %s", filename, __func__); \
+    }                                                            \
+    for (int32_t i = nrl; i <= nrh; i++) {                       \
+        nread = fread(m[i] + ncl, sizeof(t), ncol, f);           \
+        if (nread != ncol) {                                     \
+            nrerror("%s : can't read data", __func__);           \
+        }                                                        \
+    }                                                            \
+    fclose(f);                                                   \
+}
+
+fread_type_matrix(int8_t);
+fread_type_matrix(uint8_t);
+fread_type_matrix(int16_t);
+fread_type_matrix(uint16_t);
+fread_type_matrix(int32_t);
+fread_type_matrix(uint32_t);
+fread_type_matrix(int64_t);
+fread_type_matrix(uint64_t);
+fread_type_matrix(float);
+fread_type_matrix(double);
+fread_type_matrix(rgb8);
+fread_type_matrix(rgbx8);
+
+
+
+#undef write_type_matrix_positive
+#define write_type_matrix_positive(t) \
+void short_name(t,write_,matrix_positive)(t ** m, int32_t i0, int32_t i1, int32_t j0, int32_t j1, int32_t iformat, char * filename) \
+{                                                                \
+    char * format;                                               \
+    char * str;                                                  \
+    FILE * f;                                                    \
+    select_display_positive_parameters(iformat, &format, &str);  \
+    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++) {                     \
+            if (m[i][j] != 0) {                                  \
+                fprintf(f, format, m[i][j]);                     \
+            }                                                    \
+            else {                                               \
+                fprintf(f, "%s", str);                           \
+            }                                                    \
+        }                                                        \
+        fprintf(f, "\n");                                        \
+    }                                                            \
+    fclose(f);                                                   \
+}
+
+write_type_matrix_positive(uint8_t);
+write_type_matrix_positive(uint16_t);
+write_type_matrix_positive(uint32_t);
+
 
 /* ------------------------ */
@@ -1653,93 +332,97 @@
 /* ------------------------ */
 
-PRIVATE char *readitem   (FILE *file, char *buffer);
-PRIVATE void  ReadPGMrow (FILE *file, int width, uint8  *line);
-PRIVATE void  WritePGMrow(uint8 *line, int width, FILE  *file);
 
 /* ------------------------------------------ */
-PRIVATE char *readitem(FILE *file, char *buffer)
+static char * readitem(FILE * file, char * buffer)
 /* ------------------------------------------ */
-// read a word
-// public domain function: author is unknown
-{
-    char *aux;
-    int k;
-    
-    k=0;
-    aux=buffer;
-    while (!feof(file))
-    {
-        *aux=fgetc(file);
-        switch(k)
-        {
-        case 0:
-            if (*aux=='#') k=1;
-            if (isalnum(*aux)) k=2, aux++;
-            break;
-        case 1:
-            if (*aux==0xA) k=0;
-            break;
-        case 2:
-            if (!isalnum(*aux))
-            {
-                *aux=0;
-                return buffer;
-            }
-            aux++;
-            break;
+    // read a word
+    // public domain function: author is unknown
+{
+    char * aux;
+    int32_t k;
+
+    k = 0;
+    aux = buffer;
+    while (!feof(file)) {
+        *aux = fgetc(file);
+        switch (k) {
+            case 0:
+                if (*aux == '#') {
+                    k = 1;
+                }
+                if (isalnum(*aux)) {
+                    k = 2;
+                    aux++;
+                }
+                break;
+            case 1:
+                if (*aux == 0xA) {
+                    k = 0;
+                }
+                break;
+            case 2:
+                if (!isalnum(*aux)) {
+                    *aux = 0;
+                    return buffer;
+                }
+                aux++;
+                break;
         }
     }
-    *aux=0;
+    *aux = 0;
     return buffer;
 }
+
 /* ----------------------------------------------------- */
-PRIVATE void ReadPGMrow(FILE  *file, int width, uint8 *line)
+static void ReadPGMrow(FILE * file, int32_t width, uint8_t * line)
 /* ----------------------------------------------------- */
 {
     // file is already open (in read) and will not be closed at the end
-    fread(&(line[0]), sizeof(uint8), width, file);
-}
+    fread(&(line[0]), sizeof(uint8_t), width, file);
+}
+
+
 /* ------------------------------------------------------- */
-PRIVATE void WritePGMrow(uint8  *line, int width, FILE  *file)
+static void WritePGMrow(uint8_t * line, int32_t width, FILE  * file)
 /* ------------------------------------------------------- */
 {
     // file is already open (in read) and will not be closed at the end
-    fwrite(&(line[0]), sizeof(uint8), width, file);
-}
+    fwrite(&(line[0]), sizeof(uint8_t), width, file);
+}
+
+
 /* --------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(uint8 **) LoadPGM_ui8matrix(char *filename, int *nrl, int *nrh, int *ncl, int *nch)
+uint8_t ** LoadPGM_ui8matrix(char * filename, int32_t * nrl, int32_t * nrh, int32_t * ncl, int32_t * nch)
 /* --------------------------------------------------------------------------------------- */
 {
     // only for P5 binary type, not for text type
-    
-    int height, width, gris;
-    uint8 **m;
-    FILE *file;
-    
-    char *buffer;
+
+    int32_t height, width, gris;
+    uint8_t ** m;
+    FILE * file;
+
+    char * buffer;
     char msg[1024];
-    //char  c;
-    int i;
-    
-    buffer = (char*) calloc(80, sizeof(char));
+    (void) gris;
+
+    buffer = (char *) calloc(80, sizeof(char));
 
     // open file
-    file = fopen(filename,"rb");
-    if (file==NULL) {
-        //nrerror("ouverture du fichier impossible\n");
-        sprintf(msg, "ouverture du fichier %s impossible dans LoadPGM_ui8matrix\n", filename);
+    file = fopen(filename, "rb");
+    if (file == NULL) {
+        snprintf(msg, 1024, "ouverture du fichier %s impossible dans %s\n", filename, __func__);
         nrerror(msg);
     }
-    
+
     // read PGM header
     readitem(file, buffer);
-    /*fscanf(fichier, "%s", buffer);*/
-    if(strcmp(buffer, "P5") != 0) nrerror("entete du fichier %s invalide\n");
-    //nrerror("entete du fichier %s invalide\n", filename);
-    
+    if (strcmp(buffer, "P5") != 0) {
+        nrerror("Entete du fichier %s invalide\n", filename);
+    }
+
     width  = atoi(readitem(file, buffer));
     height = atoi(readitem(file, buffer));
     gris   = atoi(readitem(file, buffer));
-    
+
     *nrl = 0;
     *nrh = height - 1;
@@ -1747,264 +430,182 @@
     *nch = width - 1;
     m = ui8matrix(*nrl, *nrh, *ncl, *nch);
-    
-    for(i=0; i<height; i++) {
+
+    for(int32_t i = 0; i < height; i++) {
         ReadPGMrow(file, width, m[i]);
     }
-    
+
     fclose(file);
     free(buffer);
-    
+
     return m;
 }
-/* ---------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(uint8 **) LoadPGM_bmatrix(char *filename, int *nrl, int *nrh, int *ncl, int *nch)
-/* ---------------------------------------------------------------------------------------- */
+
+
+/* ----------------------------------------------------------------------------------------------- */
+void LoadPGM_ui8matrix2(char * filename, int32_t * nrl, int32_t * nrh, int32_t * ncl, int32_t * nch, uint8_t ** m)
+/* ----------------------------------------------------------------------------------------------- */
 {
     // only for P5 binary type, not for text type
-    
-    int height, width, gris;
-    uint8 **m;
-    FILE *file;
-    
-    char *buffer;
+    int32_t height, width, gris;
+    FILE * file;
+
+    char * buffer;
     char msg[1024];
-    //char  c;
-    int i;
-    
-    buffer = (char*) calloc(80, sizeof(char));
-    
-    // open file
-    file = fopen(filename,"rb");
-    if (file==NULL) {
-        //nrerror("ouverture du fichier impossible\n");
-        sprintf(msg, "ouverture du fichier %s impossible dans SavePGM_bmatrix\n", filename);
+    (void) gris;
+
+    buffer = (char *) calloc(80, sizeof(char));
+    /* ouverture du fichier */
+    file = fopen(filename, "rb");
+    if (file == NULL) {
+        snprintf(msg, 1024, "ouverture du fichier %s impossible dans %s\n", filename, __func__);
         nrerror(msg);
     }
-    
-    // read PGM header
+
+    /* lecture de l'entete du fichier pgm */
     readitem(file, buffer);
-    /*fscanf(fichier, "%s", buffer);*/
-    if(strcmp(buffer, "P5") != 0)
-        nrerror("entete du fichier %s invalide\n");
-    //nrerror("entete du fichier %s invalide\n", filename);
-    
+    if (strcmp(buffer, "P5") != 0) {
+        nrerror("Entete du fichier %s invalide\n", filename);
+    }
+
     width  = atoi(readitem(file, buffer));
     height = atoi(readitem(file, buffer));
     gris   = atoi(readitem(file, buffer));
-    
+
     *nrl = 0;
     *nrh = height - 1;
     *ncl = 0;
     *nch = width - 1;
-    m = ui8matrix(*nrl, *nrh, *ncl, *nch);
-    
-    for(i=0; i<height; i++) {
+
+    for (int32_t i = 0; i < height; i++) {
         ReadPGMrow(file, width, m[i]);
     }
-    
+
     fclose(file);
     free(buffer);
-    
-    return m;
-}
-/* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) LoadPGM_bmatrix2(char *filename, int *nrl, int *nrh, int *ncl, int *nch, uint8 **m)
-/* ----------------------------------------------------------------------------------------------- */
+}
+
+
+/* -------------------------------------------------------------------------------------------- */
+void MLoadPGM_ui8matrix(char * filename, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, uint8_t ** m)
+/* -------------------------------------------------------------------------------------------- */
 {
     // only for P5 binary type, not for text type
-    
-    int height, width, gris;
-    FILE *file;
-    
-    char *buffer;
+    int32_t height, width, gris;
+    FILE * file;
+
+    char * buffer;
     char msg[1024];
-    int i;
-    
-    buffer = (char*) calloc(80, sizeof(char));
+    (void) gris;
+
+    buffer = (char *) calloc(80, sizeof(char));
     /* ouverture du fichier */
-    file = fopen(filename,"rb");
-    if (file==NULL) {
-        //nrerror("ouverture du fichier impossible\n");
-        sprintf(msg, "ouverture du fichier %s impossible dans SavePGM_bmatrix\n", filename);
+    file = fopen(filename, "rb");
+    if (file == NULL) {
+        snprintf(msg, 1024, "ouverture du fichier %s impossible dans %s\n", filename, __func__);
         nrerror(msg);
     }
-    
+
     /* lecture de l'entete du fichier pgm */
     readitem(file, buffer);
-    /*fscanf(fichier, "%s", buffer);*/
-    if(strcmp(buffer, "P5") != 0)
-        nrerror("entete du fichier %s invalide\n");
-    //nrerror("entete du fichier %s invalide\n", filename);
-    
+    if (strcmp(buffer, "P5") != 0) {
+        nrerror("Entete du fichier %s invalide\n", filename);
+    }
+
     width  = atoi(readitem(file, buffer));
     height = atoi(readitem(file, buffer));
     gris   = atoi(readitem(file, buffer));
-    
-    *nrl = 0;
-    *nrh = height - 1;
-    *ncl = 0;
-    *nch = width - 1;
-    
-    for(i=0; i<height; i++) {
+
+    for (int32_t i = 0; i < height; i++) {
         ReadPGMrow(file, width, m[i]);
     }
-    
+
     fclose(file);
     free(buffer);
 }
-/* -------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) MLoadPGM_bmatrix(char *filename, int nrl, int nrh, int ncl, int nch, uint8 **m)
-/* -------------------------------------------------------------------------------------------- */
-{
-    // only for P5 binary type, not for text type
-    
-    int height, width, gris;
-    FILE *file;
-    
-    char *buffer;
+
+
+/* ------------------------------------------------------------------------------------------ */
+void SavePGM_ui8matrix(uint8_t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * filename)
+/* ------------------------------------------------------------------------------------------ */
+{
+    int nrow = nrh - nrl + 1;
+    int ncol = nch - ncl + 1;
+
+    char buffer[80];
     char msg[1024];
-    
-    int i;
-    
-    buffer = (char*) calloc(80, sizeof(char));
+
+    FILE * file;
+
+    file = fopen(filename, "wb");
+    if (file == NULL) {
+        snprintf(msg, 1024, "ouverture du fichier %s impossible dans %s\n", filename, __func__);
+        nrerror(msg);
+    }
+
+    /* enregistrement de l'image au format rpgm */
+    snprintf(buffer, 80, "P5\n%d %d\n255\n", ncol, nrow);
+    fwrite(buffer, strlen(buffer), 1, file);
+    for (int32_t i = nrl; i <= nrh; i++) {
+        WritePGMrow(m[i], ncol, file);
+    }
+
+    /* fermeture du fichier */
+    fclose(file);
+}
+
+
+/* --------------------------- */
+/* -- PNM IO for rgb8matrix -- */
+/* --------------------------- */
+
+/* ------------------------------------------------------ */
+static void ReadPNMrow(FILE * file, int32_t width, uint8_t * line)
+/* ------------------------------------------------------ */
+{
+    /* Le fichier est ouvert (en lecture) et ne sera pas ferme a la fin */
+    fread(&(line[0]), sizeof(uint8_t), 3 * sizeof(uint8_t) * width, file);
+}
+
+
+/* ------------------------------------------------------- */
+static void WritePNMrow(uint8_t * line, int32_t width, FILE * file)
+/* ------------------------------------------------------- */
+{
+    /* Le fichier est deja ouvert et ne sera pas ferme a la fin */
+    fwrite(&(line[0]), sizeof(uint8_t), 3 * sizeof(uint8_t) * width, file);
+}
+
+
+/* ------------------------------------------------------------------------------------------ */
+rgb8 ** LoadPPM_rgb8matrix(char * filename, int32_t * nrl, int32_t * nrh, int32_t * ncl, int32_t * nch)
+/* ------------------------------------------------------------------------------------------ */
+{
+    /* cette version ne lit plus que le type P6 */
+    int32_t height, width, gris;
+    rgb8 ** m;
+    FILE * file;
+
+    char * buffer;
+    char msg[1024];
+    (void) gris;
+
+    buffer = (char *) calloc(80, sizeof(char));
     /* ouverture du fichier */
     file = fopen(filename,"rb");
-    if (file==NULL) {
-        //nrerror("ouverture du fichier impossible\n");
-        sprintf(msg, "ouverture du fichier %s impossible dans SavePGM_bmatrix\n", filename);
+    if (file == NULL) {
+        snprintf(msg, 1024, "ouverture du fichier %s impossible dans %s\n", filename, __func__);
         nrerror(msg);
     }
-    
+
     /* lecture de l'entete du fichier pgm */
     readitem(file, buffer);
-    /*fscanf(fichier, "%s", buffer);*/
-    if(strcmp(buffer, "P5") != 0)
-        nrerror("entete du fichier %s invalide\n");
-    //nrerror("entete du fichier %s invalide\n", filename);
-    
+    if (strcmp(buffer, "P6") != 0) {
+        nrerror("Entete du fichier %s invalide\n", filename);
+    }
+
     width  = atoi(readitem(file, buffer));
     height = atoi(readitem(file, buffer));
     gris   = atoi(readitem(file, buffer));
-    
-    for(i=0; i<height; i++) {
-        ReadPGMrow(file, width, m[i]);
-    }
-    
-    fclose(file);
-    free(buffer);
-}
-/* ------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) SavePGM_bmatrix(uint8 **m, int nrl, int nrh, int ncl, int nch, char *filename)
-/* ------------------------------------------------------------------------------------------ */
-{
-    int nrow = nrh-nrl+1;
-    int ncol = nch-ncl+1;
-    
-    char buffer[80];
-    char msg[1024];
-    
-    FILE *file;
-    int  i;
-    
-    file = fopen(filename, "wb");
-    if (file == NULL) {
-        //nrerror("ouverture du fichier %s impossible dans SavePGM_bmatrix\n", filename);
-        sprintf(msg, "ouverture du fichier %s impossible dans SavePGM_bmatrix\n", filename);
-        nrerror(msg);
-    }
-    
-    /* enregistrement de l'image au format rpgm */
-    sprintf(buffer,"P5\n%d %d\n255\n",ncol, nrow);
-    fwrite(buffer,strlen(buffer),1,file);
-    for(i=nrl; i<=nrh; i++)
-        WritePGMrow(m[i], ncol, file);
-    
-    /* fermeture du fichier */
-    fclose(file);
-}
-/* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) SavePGM_ui8matrix(uint8 **m, int nrl, int nrh, int ncl, int nch, char *filename)
-/* --------------------------------------------------------------------------------------------- */
-{
-    int nrow = nrh-nrl+1;
-    int ncol = nch-ncl+1;
-    
-    char buffer[80];
-    char msg[1024];
-    
-    FILE *file;
-    int  i;
-    
-    file = fopen(filename, "wb");
-    if (file == NULL) {
-        //nrerror("ouverture du fichier %s impossible dans SavePGM_bmatrix\n", filename);
-        sprintf(msg, "ouverture du fichier %s impossible dans SavePGM_bmatrix\n", filename);
-        nrerror(msg);
-    }
-    
-    /* enregistrement de l'image au format rpgm */
-    sprintf(buffer,"P5\n%d %d\n255\n",ncol, nrow);
-    fwrite(buffer,strlen(buffer),1,file);
-    for(i=nrl; i<=nrh; i++)
-        WritePGMrow(m[i], ncol, file);
-    
-    /* fermeture du fichier */
-    fclose(file);
-}
-/* --------------------------- */
-/* -- PNM IO for rgb8matrix -- */
-/* --------------------------- */
-
-/* ------------------------------------------------------ */
-PRIVATE void ReadPNMrow(FILE  *file, int width, byte  *line)
-/* ------------------------------------------------------ */
-{
-    /* Le fichier est ouvert (en lecture) et ne sera pas ferme a la fin */
-    fread(&(line[0]), sizeof(byte), 3*sizeof(byte)*width, file);
-}
-/* ------------------------------------------------------- */
-PRIVATE void WritePNMrow(byte  *line, int width, FILE  *file)
-/* ------------------------------------------------------- */
-{
-    /* Le fichier est deja ouvert et ne sera pas ferme a la fin */
-    
-    fwrite(&(line[0]), sizeof(byte), 3*sizeof(byte)*width, file);
-}
-/* ------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(rgb8 **) LoadPPM_rgb8matrix(char *filename, int *nrl, int *nrh, int *ncl, int *nch)
-/* ------------------------------------------------------------------------------------------ */
-{
-    /* cette version ne lit plus que le type P6 */
-    
-    int height, width, gris;
-    rgb8 **m;
-    FILE *file;
-    //int   format;
-    
-    char *buffer;
-    char msg[1024];
-    //char  c;
-    int i;
-    
-    buffer = (char*) calloc(80, sizeof(char));
-    /* ouverture du fichier */
-    file = fopen(filename,"rb");
-    if (file==NULL) {
-        //nrerror("ouverture du fichier impossible\n");
-        sprintf(msg, "ouverture du fichier %s impossible dans SavePGM_bmatrix\n", filename);
-        nrerror(msg);
-    }
-    
-    /* lecture de l'entete du fichier pgm */
-    readitem(file, buffer);
-    /*fscanf(fichier, "%s", buffer);*/
-    if(strcmp(buffer, "P6") != 0)
-        nrerror("entete du fichier %s invalide\n");
-    //nrerror("entete du fichier %s invalide\n", filename);
-    
-    width  = atoi(readitem(file, buffer));
-    height = atoi(readitem(file, buffer));
-    gris   = atoi(readitem(file, buffer));
-    
+
     *nrl = 0;
     *nrh = height - 1;
@@ -2012,90 +613,97 @@
     *nch = width - 1;
     m = rgb8matrix(*nrl, *nrh, *ncl, *nch);
-    
-    for(i=0; i<height; i++) {
-        ReadPNMrow(file, width, (byte*)m[i]);
-    }
-    
+
+    for (int32_t i = 0; i < height; i++) {
+        ReadPNMrow(file, width, (uint8_t *) m[i]);
+    }
+
     fclose(file);
     free(buffer);
-    
+
     return m;
 }
+
+
 /* -------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) LoadPPM_rgb8matrix2(char *filename, int *nrl, int *nrh, int *ncl, int *nch, rgb8 **m)
-/* -------------------------------------------------------------------------------------------------- */
+void LoadPPM_rgb8matrix2(char * filename, int * nrl, int * nrh, int * ncl, int * nch, rgb8 ** m)
+    /* -------------------------------------------------------------------------------------------------- */
 {
     /* cette version ne lit plus que le type P6 */
-    
     int height, width, gris;
-    FILE *file;
-    //int   format;
-    
-    char *buffer;
+    FILE * file;
+
+    char * buffer;
     char msg[1024];
-    //char  c;
-    int i;
-    
-    buffer = (char*) calloc(80, sizeof(char));
+    (void) gris;
+
+    buffer = (char *) calloc(80, sizeof(char));
     /* ouverture du fichier */
-    file = fopen(filename,"rb");
-    if (file==NULL) {
-        //nrerror("ouverture du fichier impossible\n");
-        sprintf(msg, "ouverture du fichier %s impossible dans LoadPPM_rgb8matrix2\n", filename);
+    file = fopen(filename, "rb");
+    if (file == NULL) {
+        snprintf(msg, 1024, "ouverture du fichier %s impossible dans LoadPPM_rgb8matrix2\n", filename);
         nrerror(msg);
     }
-    
+
     /* lecture de l'entete du fichier pgm */
     readitem(file, buffer);
-    /*fscanf(fichier, "%s", buffer);*/
-    if(strcmp(buffer, "P6") != 0)
-        nrerror("entete du fichier %s invalide\n");
+    if (strcmp(buffer, "P6") != 0) {
+        nrerror("Entete du fichier %s invalide\n", filename);
+    }
     //nrerror("entete du fichier %s invalide\n", filename);
-    
+
     width  = atoi(readitem(file, buffer));
     height = atoi(readitem(file, buffer));
     gris   = atoi(readitem(file, buffer));
-    
+
     *nrl = 0;
     *nrh = height - 1;
     *ncl = 0;
     *nch = width - 1;
-    
-    for(i=0; i<height; i++) {
-        ReadPNMrow(file, width, (byte*)m[i]);
+
+    for (int32_t i = 0; i < height; i++) {
+        ReadPNMrow(file, width, (uint8_t *) m[i]);
     }
     fclose(file);
     free(buffer);
 }
+
+
 /* ------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) SavePPM_rgb8matrix(rgb8 **m, int nrl, int nrh, int ncl, int nch, char *filename)
+void SavePPM_rgb8matrix(rgb8 ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, char * filename)
 /* ------------------------------------------------------------------------------------------------- */
 {
-    int nrow = nrh-nrl+1;
-    int ncol = nch-ncl+1;
-    
+    int32_t nrow = nrh - nrl + 1;
+    int32_t ncol = nch - ncl + 1;
+
     char buffer[80];
     char msg[1024];
-    
-    FILE *file;
-    int  i;
-    
+
+    FILE * file;
+
     file = fopen(filename, "wb");
     if (file == NULL) {
-        //nrerror("ouverture du fichier %s impossible dans SavePGM_bmatrix\n", filename);
-        //nrerror("ouverture du fichier %s impossible dans SavePPM_bmatrix\n");
-        sprintf(msg, "ouverture du fichier %s impossible dans SavePPM_rgb8matrix\n", filename);
-        
+        snprintf(msg, 1024, "ouverture du fichier %s impossible dans %s\n", filename, __func__);
         nrerror(msg);
     }
-    
+
     /* enregistrement de l'image au format rpgm */
-    
-    sprintf(buffer,"P6\n%d %d\n255\n",ncol, nrow);
-    fwrite(buffer,strlen(buffer),1,file);
-    for(i=nrl; i<=nrh; i++)
-        WritePNMrow((byte*)m[i], ncol, file);
-    
+    snprintf(buffer, 80, "P6\n%d %d\n255\n", ncol, nrow);
+    fwrite(buffer, strlen(buffer), 1, file);
+    for (int32_t i = nrl; i <= nrh; i++) {
+        WritePNMrow((uint8_t *) m[i], ncol, file);
+    }
+
     /* fermeture du fichier */
     fclose(file);
 }
+
+
+// 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/scripts/common.py
===================================================================
--- soft/giet_vm/applications/rosenfeld/scripts/common.py	(revision 822)
+++ soft/giet_vm/applications/rosenfeld/scripts/common.py	(revision 822)
@@ -0,0 +1,114 @@
+
+from __future__ import print_function
+import os
+import subprocess
+import sys
+
+
+
+
+def short_path(name):
+    abs_path = os.path.abspath(name)
+    rel_path = os.path.relpath(name)
+    if len(abs_path) < len(rel_path):
+        return abs_path
+    else:
+        return rel_path
+
+
+def check_pyconf_file(pyconf_file):
+    if not os.path.isfile(pyconf_file):
+        help_str = '''
+You should create a file named %s in this directory with the following definitions:
+ - ... (to complete)
+Optional definitions:
+ - dsk_dir: path to a local storage (typically in /dsk/l1/misc) to store generated data and images
+*** Stopping execution
+''' % (short_path(pyconf_file))
+        print(help_str)
+        sys.exit()
+
+
+    
+def my_mkdir(abs_dirname):
+    dirname = short_path(abs_dirname)
+    try:
+        print("mkdir %s" % (dirname))
+        os.mkdir(dirname)
+    except OSError:
+        print("*** Error: impossible to create directory %s" % (dirname), file = sys.stderr)
+        sys.exit(1)
+
+def my_chdir(abs_dirname):
+    dirname = short_path(abs_dirname)
+    print("cd %s" % (dirname));
+    os.chdir(dirname)
+
+def my_cp(abs_src, abs_dst):
+    src = short_path(abs_src)
+    dst = short_path(abs_dst)
+    print("cp %s %s" % (src, dst))
+    shutil.copy(src, dst)
+
+
+def get_random_img_file(density, x, y, granularity, seed):
+    density_str = str(density)
+    if density < 10:
+        density_str = "0" + density_str
+    if density < 100:
+        density_str = "0" + density_str
+
+    return "rand_" + str(x) + "_" + str(y) + "_" + density_str + "_G" + str(granularity) + ".pgm"
+
+
+def get_filename(dir, nthreads, config, ftrs, basename):
+    if ftrs:
+        ftrs_str = "_FEATURES_1"
+    else:
+        ftrs_str = "_FEATURES_0"
+
+    config_keys = list(config.keys()) # duplicates list
+    try:
+        config_keys.remove('FEATURES')
+    except:
+        pass
+    config_keys = sorted(config_keys)
+    filename = os.path.join(dir, basename + "_" + str(nthreads) + "_" + "_".join(map(lambda x:'%s_%s' % (x, config[x]), config_keys)) + ftrs_str + ".txt")
+    
+    return filename
+
+
+def get_graph_filename(dir, nthreads, config, ext):
+    config_keys = list(config.keys()) # duplicates list
+    config_keys = sorted(config_keys)
+    filename = os.path.join(dir, "random_" + str(nthreads) + "_" + "_".join(map(lambda x:'%s_%s' % (x, config[x]), config_keys)) + ext)
+    
+    return filename
+
+
+
+def print_and_call(cmd):
+    print(subprocess.list2cmdline(cmd))
+    retval = subprocess.call(cmd)
+    return retval
+
+def print_and_popen(cmd, abs_outfile):
+    outfile = short_path(abs_outfile)
+    print(subprocess.list2cmdline(cmd), end = "")
+    print(" >", outfile)
+    child = subprocess.Popen(cmd, stdout = subprocess.PIPE, stderr = subprocess.STDOUT)
+    output = child.communicate()[0]
+    retval = child.returncode
+                
+    # Write simulation results to log file
+    file = open(outfile, 'w')
+    file.write(output)
+    file.close()
+
+    if retval != 0:
+        print("*** Error while executing command '%s'" % subprocess.list2cmdline(cmd))
+        sys.exit(1)
+
+    return output
+
+
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 822)
@@ -0,0 +1,154 @@
+#!/dsk/l1/misc/meunier/tools/bin/python3
+# -*- coding: utf-8 -*-
+
+# Note:
+# This code requires python 3, and I haven't found
+# a proper way of mixing python 2 and 3 without using
+# the she/bang line at the top, which includes a local
+# path...
+
+from __future__ import print_function
+import os
+import sys
+import re
+import subprocess
+import shutil
+import filecmp
+import random
+
+from stack import Stack
+
+from common import *
+
+
+use_rand_images = True
+with_features = True
+
+threads = [1, 2, 4]
+nb_step = 0
+use_dsk = True
+img_size = 1024
+granularity = 1
+rand_seed = 7
+
+top_path = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), ".."))
+scripts_path  = os.path.join(top_path, 'scripts')
+pyconf_file   = os.path.join(scripts_path, "config.py")
+
+base_data_dir  = "data"    # For timing information extracted
+base_graph_dir = "graphes" # For storing generated graphes
+
+
+# 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'},
+]
+
+
+# Loading config file
+with open(pyconf_file) as f:
+    code = compile(f.read(), pyconf_file, 'exec')
+    exec(code)
+
+if use_dsk:
+    try:
+        dsk_dir
+        if not os.path.exists(dsk_dir):
+            print("*** Warning: variable dsk_dir is not defined in %s file; using current directory for reading data files" % (short_path(pyconf_file)))
+            use_dsk = False
+    except OSError:
+        print("*** Warning: directory %s does not exist; using current directory for reading data files" % (dsk_dir))
+        use_dsk = False
+
+# Updating output directories
+if use_dsk:
+    data_dir     = os.path.join(dsk_dir, base_data_dir)
+    graph_dir    = os.path.join(dsk_dir, base_graph_dir)
+else:
+    data_dir   = os.path.join(scripts_path, base_data_dir)
+    graph_dir  = os.path.join(scripts_path, base_graph_dir)
+
+
+
+if not os.path.exists(graph_dir):
+    my_mkdir(graph_dir)
+
+
+
+if with_features:
+    features = ["FT", "NF"] # Features and No-Features
+else:
+    features = ["NF"] # No features only
+
+
+exec_time = {}
+for config in configs:
+    fconfig = frozenset(config.items())
+    exec_time[fconfig] = {}
+    for thread in threads:
+        exec_time[fconfig][thread] = {}
+        for ftrs in features: # Features or No features
+            exec_time[fconfig][thread][ftrs] = {}
+            for density in range(0, 101):
+                exec_time[fconfig][thread][ftrs][density] = {}
+                random_img_file = get_random_img_file(density, img_size, img_size, granularity, rand_seed)
+                img_basename = os.path.splitext(random_img_file)[0]
+                log_file = get_filename(data_dir, thread, config, ftrs == "FT", img_basename)
+                lines = open(log_file, 'r')
+                for line in lines:
+                    tokens = line.split()
+                    if len(tokens) == 0:
+                        continue
+                    tag = tokens[0]
+                    pattern = re.compile('\[STEP_([0-9]+)\]')
+                    match = pattern.match(tag)
+                    if match:
+                        step = int(match.group(1))
+                        nb_step = max(int(step) + 1, nb_step)
+                        value = tokens[len(tokens) - 1]
+                        exec_time[fconfig][thread][ftrs][density][step] = value
+                        #print("exec_time[fconfig][%d][%s][%d][%s] = %s" % (thread, ftrs, density, step, exec_time[fconfig][thread][ftrs][density][step]))
+
+                    
+
+
+for config in configs:
+    fconfig = frozenset(config.items())
+    for thread in threads:
+        plotter = Stack(["red", "blue", "#CAFE01", "#CA01FE", "#01CAFE"], "LÃ©gende", "X", "Y")
+        X = [x for x in range(0, 101)]
+        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
+
+        plotter.add_y(YPAR1)
+        plotter.add_y(YPAR2)
+        plotter.add_y(YPTC2)
+        # Not displaying PAR3
+
+        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)
+            deltaYPAR1 = [max(0, x - y) for x, y in zip (YPAR1f, YPAR1)]
+            deltaYPAR2 = [max(0, x - y) for x, y in zip (YPAR2f, YPAR2)]
+            YFTC = [x + y for x, y in zip (deltaYPAR1, deltaYPAR2)] # Features Computation
+            plotter.add_y(YFTC)
+
+        plotter.plot()
+        graph_name = get_graph_filename(graph_dir, thread, config, ".pdf")
+        print("# Creating graph %s" % short_path(graph_name))
+        plotter.save(graph_name)
+
+
+
+
+
+
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 822)
@@ -0,0 +1,336 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+# Note: This code should stay compatible with
+# python 2 as it will execute on computation servers
+
+
+from __future__ import print_function
+import os
+import sys
+import re
+import filecmp
+import shutil
+import random
+
+from common import *
+
+# Directories and files
+top_path = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), ".."))
+scripts_path  = os.path.join(top_path, "scripts")
+pyconf_file   = os.path.join(scripts_path, "config.py")
+config_file   = os.path.join(top_path, "include/config.h")
+images_dir    = os.path.join(top_path, "../../images")
+binary_file   = os.path.join(top_path, "appli.elf")
+
+base_output_dir   = "output" # For output images and stat files (ref + exec)
+base_logs_dir     = "logs"   # Log of execution, i.e. what is printed on screen
+base_data_dir     = "data"   # For timing information extracted
+base_rand_img_dir = "random_images" # For storing random images if using dsk
+
+
+
+#images = ['boulons.pgm', 'cadastre.pgm', 'alea1.pgm', 'alea2.pgm', 'alea3.pgm']
+images = ['cadastre.pgm']
+
+images = map(lambda x:os.path.join(images_dir, x), images)
+
+# Parameters
+num_runs = 10
+check_results = False
+eval_perf = True
+use_valgrind = False
+use_rand_images = True
+threads = [1, 2, 4]
+use_dsk = True
+# Using dsk will store generated random images, otherwise they are re-generated at each run to save disk space
+
+# 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':'0', 'FAST':'1', 'FEATURES':'1', 'PARMERGE':'1', 'ARSP':'0'},
+        #{'SLOW':'0', 'FAST':'1', 'FEATURES':'0', 'PARMERGE':'1', 'ARSP':'1'},
+]
+
+
+# Other parameters which shouldn't be changed
+rand_seed = 7
+granularity = 1 # constant for now
+img_size = 1024
+
+check_pyconf_file(pyconf_file)
+
+# Loading config file
+exec(file(pyconf_file))
+
+if use_dsk:
+    try:
+        dsk_dir
+        if not os.path.exists(dsk_dir):
+            print("mkdir %s", dsk_dir)
+            os.mkdir(dsk_dir)
+    except NameError:
+        print("*** Warning: variable dsk_dir is not defined in %s file; using current directory for storing output files" % (short_path(pyconf_file)))
+        use_dsk = False
+    except OSError:
+        print("*** Warning: Impossible to create directory %s; using current directory for storing output files" % (dsk_dir))
+        use_dsk = False
+
+
+# Updating output directories
+if use_dsk:
+    output_dir   = os.path.join(dsk_dir, base_output_dir)
+    logs_dir     = os.path.join(dsk_dir, base_logs_dir)
+    data_dir     = os.path.join(dsk_dir, base_data_dir)
+    rand_img_dir = os.path.join(dsk_dir, base_rand_img_dir)
+else:
+    output_dir = os.path.join(scripts_path, base_output_dir)
+    logs_dir   = os.path.join(scripts_path, base_logs_dir)
+    data_dir   = os.path.join(scripts_path, base_data_dir)
+
+
+
+def gen_random_image(filename, x, y, granularity, density, seed):
+    random.seed(seed)
+    img = [[0 for a in range(x)] for b in range(y)] 
+    for i in range(0, x, granularity):
+        for j in range(0, y, granularity):
+            r = random.random();
+            if r < density:
+                px = 255
+            else:
+                px = 0
+
+            for di in range(0, granularity):
+                for dj in range(0, granularity):
+                    if i + di < x and j + dj < y:
+                        img[i + di][j + dj] = px;
+
+    f = open(filename, 'wb')
+    f.write("P5\n%d %d\n255\n" % (x, y))
+    for j in range(0, y):
+        bimg = bytearray(img[j])
+        f.write(bimg)
+    f.close()
+
+
+
+def update_config_file(config):
+    if os.path.isfile(config_file):
+        print("# Updating file %s" % (config_file))
+        f = open(config_file, "r")
+        lines = f.readlines()
+        f.close()
+
+        f = open(config_file, "w")
+
+        for line in lines:
+            line_with_key = False
+            for key in config.keys():
+                if "#define %s" % (key) in line:
+                    f.write("#define %s %s\n" % (key, config[key]))
+                    line_with_key = True
+                    break
+            if not line_with_key:
+                f.write(line)
+
+        f.close()
+    else:
+        print("# Creating file %s" % (config_file))
+        f = open(config_file, "w")
+        f.write("\n")
+        for key in config.keys():
+            f.write("#define %s %s\n" % (key, config[key]))
+        f.write("\n")
+        f.close()
+
+
+
+
+if not os.path.exists(output_dir):
+    my_mkdir(output_dir)
+
+if not os.path.exists(logs_dir):
+    my_mkdir(logs_dir)
+
+if not os.path.exists(data_dir):
+    my_mkdir(data_dir)
+
+if use_dsk and not os.path.exists(rand_img_dir):
+    my_mkdir(rand_img_dir)
+
+
+
+
+stat_array = {}
+perf_array = {}
+
+for config in configs:
+    img_idx = 0
+    fconfig = frozenset(config.iteritems())
+    perf_array[fconfig] = {}
+    update_config_file(config)
+    features = config['FEATURES'] == '1'
+    
+    # Compile application
+    my_chdir(top_path)
+    cmd = ['make']
+    print_and_call(cmd)
+    my_chdir(scripts_path)
+
+    while not use_rand_images and img_idx != len(images) or use_rand_images and img_idx != 101:
+        # Compute image and stat filenames
+        if use_rand_images:
+            if use_dsk:
+                random_img_file = get_random_img_file(img_idx, img_size, img_size, granularity, rand_seed)
+                random_img_file = os.path.join(rand_img_dir, random_img_file)
+            else:
+                random_img_file = "random.pgm"
+            if not (use_dsk and os.path.isfile(random_img_file)):
+                # We re-generate the random image if not using the dsk or if it does not exist
+                print("# Generating random image %s with density = %d" % (random_img_file, img_idx))
+                gen_random_image(random_img_file, img_size, img_size, 1, float(img_idx) / 100, rand_seed)
+
+            image = random_img_file
+        else:
+            image = images[img_idx]
+        img_basename = os.path.splitext(os.path.basename(image))[0]
+        perf_array[fconfig][img_basename] = {}
+        ref_bmpfile  = os.path.join(output_dir, os.path.splitext(os.path.basename(image))[0] + "_ref.bmp")
+        ref_statfile = os.path.join(output_dir, os.path.splitext(os.path.basename(image))[0] + "_ref.txt")
+
+        for nthreads in threads:
+            perf_array[fconfig][img_basename][nthreads] = {}
+            for run in range(num_runs):
+                if not os.path.exists(ref_bmpfile):
+                    bmpfile = ref_bmpfile
+                else:
+                    bmpfile = os.path.join(output_dir, os.path.splitext(os.path.basename(image))[0] + ".bmp")
+                    if os.path.exists(bmpfile):
+                        os.remove(bmpfile)
+    
+                if not os.path.exists(ref_statfile):
+                    statfile = ref_statfile
+                else:
+                    statfile = os.path.join(output_dir, os.path.splitext(os.path.basename(image))[0] + ".txt")
+    
+                cmd = []
+                if use_valgrind:
+                    cmd.append('valgrind')
+    
+                cmd.extend([short_path(binary_file), '-n', str(nthreads), '-i', short_path(image)])
+                
+                if check_results:
+                    cmd.extend(['-o', short_path(bmpfile), '-g'])
+                
+                if check_results and features:
+                    cmd.append('-d')
+    
+                config_keys = config.keys()
+                logfile = get_filename(logs_dir, nthreads, config, features, img_basename)
+                output = print_and_popen(cmd, logfile)
+                outlines = output.splitlines()
+
+                # if performance evaluation, get timing measurements
+                if eval_perf:
+                    for line in outlines:
+                        tokens = line.split()
+                        if len(tokens) == 0:
+                            continue
+                        tag = tokens[0]
+                        pattern = re.compile('\[THREAD_STEP_([0-9]+)\]');
+                        match = pattern.match(tag)
+                        if match:
+                            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)
+
+
+                # Checking against reference output image    
+                if check_results and bmpfile != ref_bmpfile:
+                    print("diff %s %s" % (short_path(bmpfile), short_path(ref_bmpfile)))
+                    if not filecmp.cmp(bmpfile, ref_bmpfile):
+                        print("*** Error: files %s and %s differ" % (short_path(bmpfile), short_path(ref_bmpfile)))
+                        sys.exit(1)
+    
+                # Checking for valgrind errors
+                if use_valgrind:
+                    if not "== ERROR SUMMARY: 0 errors from 0 contexts" in output:
+                        print("*** Error: Valgrind error")
+                        sys.exit(1)
+                    if not "== All heap blocks were freed -- no leaks are possible" in output:
+                        print("*** Error: Valgrind detected a memory leak")
+                        sys.exit(1)
+    
+                # Extracting features for correctness verification
+                if check_results and features:
+                    stat_array = {}
+                    in_stats = False
+                    index = 0
+                    for line in outlines:
+                        if "[STATS]" in line:
+                            in_stats = True
+                            continue
+                        if "[/STATS]" in line:
+                            in_stats = False
+                            break
+                        if in_stats:
+                            tokens = line.split()
+                            assert(len(tokens) == 8)
+                            stat_array[index] = {}
+                            for j in range(len(tokens)):
+                                stat_array[index][j] = tokens[j]
+                            index += 1
+    
+                    # Dump stat array in stat file
+                    file = open(statfile, 'w')
+                    for i in range(len(stat_array)):
+                        for j in range(8):
+                            file.write("%s " % stat_array[i][j])
+                        file.write("\n");
+                    file.close()
+    
+                    # Comparison to reference
+                    if statfile != ref_statfile:
+                        print("diff %s %s" % (short_path(statfile), short_path(ref_statfile)))
+                        if not filecmp.cmp(statfile, ref_statfile):
+                            print("*** Error: feature files %s and %s differ" % (short_path(statfile), short_path(ref_statfile)))
+                            sys.exit(1)
+
+            # End of the num_runs simus
+            if eval_perf:
+                if use_rand_images:
+                    idx = img_idx
+                else:
+                    idx = None
+                datafile = get_filename(data_dir, nthreads, config, features, img_basename)
+                file = open(datafile, 'w')
+                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))
+
+        img_idx += 1
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
Index: soft/giet_vm/applications/rosenfeld/scripts/stack.py
===================================================================
--- soft/giet_vm/applications/rosenfeld/scripts/stack.py	(revision 822)
+++ soft/giet_vm/applications/rosenfeld/scripts/stack.py	(revision 822)
@@ -0,0 +1,117 @@
+#!/dsk/l1/misc/meunier/tools/bin/python3
+# -*- coding: utf-8 -*-
+
+import matplotlib
+matplotlib.use('PDF')
+import matplotlib.pyplot as plt
+from matplotlib.ticker import MultipleLocator
+
+class Stack:
+    def __init__(self, couleurs, title, label_X, label_Y):
+        self.xlabel = label_X
+        self.ylabel = label_Y
+        self.title = title
+        self.couleurs = couleurs
+        self.actual_colors = []
+        self.color_index = 0
+        self.dataset = []
+        self.X = []
+        #self.clear()
+        self.init_picture()
+
+    def add_y(self, data):
+        self.dataset.append(data)
+        self.actual_colors.append(self.couleurs[self.get_color()])
+
+    def add_x(self, data):
+        self.X = data
+
+
+    def init_picture(self):
+        plt.clf() # Clear previous figure
+        textcolor = '#000000'
+        plt.rcParams['font.family'] = 'serif'
+        plt.rcParams['font.size'] = 10
+
+        plt.rcParams['mathtext.fontset'] = 'cm'
+        plt.rcParams['mathtext.fallback_to_cm'] = True
+        plt.rcParams['mathtext.default'] = 'regular'
+        plt.rcParams['mathtext.default'] = 'sf'
+        
+        plt.rcParams['lines.linewidth'] = '1'
+        plt.rcParams['lines.antialiased'] = True
+
+        plt.rcParams['text.latex.unicode'] = True
+        plt.rcParams['text.color'] = textcolor
+        plt.rcParams['text.hinting'] = 'auto'
+        plt.rcParams['axes.labelcolor'] = textcolor
+        plt.rcParams['axes.edgecolor'] = textcolor # couleur du cadre
+        plt.rcParams['axes.facecolor'] = '#FFFFFF' # couleur du fond
+        plt.rcParams['axes.linewidth'] = '0.1'
+        #plt.rcParams['ytick.major.pad'] = 8
+
+        plt.rcParams['grid.color'] = textcolor
+        plt.rcParams['grid.alpha'] = '0.1'
+        plt.rcParams['grid.linestyle'] = ':'
+        plt.rcParams['grid.linewidth'] = '0.1'
+        plt.rcParams['xtick.direction'] = 'in'
+        plt.rcParams['ytick.direction'] = 'in'
+        plt.rcParams['xtick.color'] = textcolor
+        plt.rcParams['ytick.color'] = textcolor
+        plt.rcParams['xtick.major.size'] = 6
+        plt.rcParams['ytick.major.size'] = 6
+        plt.rcParams['xtick.minor.size'] = 3
+        plt.rcParams['ytick.minor.size'] = 3
+        plt.rcParams['legend.fancybox'] = True
+        plt.rcParams['xtick.major.pad'] = 4
+        plt.rcParams['ytick.major.pad'] = 12
+        plt.rcParams['figure.figsize'] = 7,4
+        
+        axes = plt.gca()
+        axes.set_xlim([0, 100])
+        plt.axes().xaxis.set_tick_params(width = 0.1)
+        plt.axes().yaxis.set_tick_params(width = 0.1)
+        
+        plt.grid(True)
+        self.draw_labels()
+
+
+    def draw_labels(self):
+        plt.xlabel(self.xlabel)
+        plt.ylabel(self.ylabel)
+        pass
+
+    def draw_title(self):
+        plt.title(self.title)
+        pass
+
+    def plot(self):
+        plt.stackplot(self.X, self.dataset, colors = self.actual_colors)
+
+    def save(self, filename):
+        plt.savefig(filename, bbox_inches = 'tight')
+
+    def get_color(self):
+        color_index = self.color_index
+        self.color_index = (self.color_index + 1) % len(self.couleurs)
+        return color_index
+
+    def clear(self):
+        # Other options to explore
+        #plt.clf()
+        #self.color_index = 0
+        #yminorLocator   = MultipleLocator(5)
+        #xmajorLocator   = MultipleLocator(10)
+        #xminorLocator   = MultipleLocator(1)
+
+        #plt.axes().yaxis.set_minor_locator(yminorLocator)
+        #plt.axes().yaxis.set_label_position('left')
+        #plt.axes().xaxis.set_minor_locator(xminorLocator)
+        #plt.axes().xaxis.set_major_locator(xmajorLocator)
+        #ylabel = plt.axes().yaxis.get_label()
+        #ylabel.set_va('baseline')
+        #ylabel.set_ha('center')
+        #plt.grid(True)
+        #self.draw_labels()
+        #self.draw_title()    
+        pass
Index: soft/giet_vm/applications/rosenfeld/src-par/mca.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/src-par/mca.c	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/src-par/mca.c	(revision 822)
@@ -42,5 +42,4 @@
 {
     printf("MCA ERROR: %s\n", msg);
-    printf("now exiting to system...\n");
     exit(1);
 }
@@ -164,7 +163,7 @@
     MCA *  mca_par;
     
-    printf("*** %s ***\n", __func__);
-    MCA_VERBOSE1(printf("   height = %d\n", height));
-    MCA_VERBOSE1(printf("   width  = %d\n", width));
+    MCA_VERBOSE1(printf("*** %s ***\n", __func__));
+    MCA_VERBOSE2(printf("   height = %d\n", height));
+    MCA_VERBOSE2(printf("   width  = %d\n", width));
     
     // array of pointers to mca workers
@@ -179,6 +178,6 @@
     height_mod = height % np;
 
-    MCA_VERBOSE1(printf("   height_par = %d x %d + %d\n", height_par, np, height_mod));
-    MCA_VERBOSE1(printf("   ========================\n"));
+    MCA_VERBOSE2(printf("   height_par = %d x %d + %d\n", height_par, np, height_mod));
+    MCA_VERBOSE2(printf("   ========================\n"));
     
     i1_par_previous = 0;
@@ -186,5 +185,5 @@
     // puissance de 2 de chaque bande
     ne_par = height_par * width + 1;
-    MCA_VERBOSE1(printf("   ne_par    = %d\n", ne_par));
+    MCA_VERBOSE2(printf("   ne_par    = %d\n", ne_par));
     pw2 = i32log2(ne_par);
     if (ne_par > (1 << pw2)) {
@@ -192,6 +191,7 @@
     }
     nemax_par = 1 << pw2;
-
-    MCA_VERBOSE1(printf("   nemax_par = %d\n", nemax_par));
+    mca->alpha = pw2;
+
+    MCA_VERBOSE2(printf("   nemax_par = %d\n", nemax_par));
 
     nb_level = i32log2(np);
@@ -230,5 +230,5 @@
         // -- constructor -- //
         // ----------------- //
-        MCA_VERBOSE2(printf("-- p = %d ----------------\n", p));
+        MCA_VERBOSE3(printf("-- p = %d ----------------\n", p));
     
         // alloc of mca workers into array of pointers
@@ -245,5 +245,5 @@
         x = (p / NB_PROCS_MAX) / Y_SIZE;
         y = (p / NB_PROCS_MAX) % Y_SIZE;
-        MCA_VERBOSE2(printf("p = %d (x = %d, y = %d)\n", p, x, y));
+        MCA_VERBOSE3(printf("p = %d (x = %d, y = %d)\n", p, x, y));
 #endif
         
@@ -268,6 +268,6 @@
         i1_par_previous = i1_par;
         
-        MCA_VERBOSE2(printf("i0_par = %d\n", i0_par));
-        MCA_VERBOSE2(printf("i1_par = %d\n", i1_par));
+        MCA_VERBOSE3(printf("i0_par = %d\n", i0_par));
+        MCA_VERBOSE3(printf("i1_par = %d\n", i1_par));
         
         // etiquettes
@@ -281,6 +281,6 @@
         }
     
-        MCA_VERBOSE2(printf("e0_par = %d\n", e0_par));
-        MCA_VERBOSE2(printf("e1_par = %d\n", e1_par));
+        MCA_VERBOSE3(printf("e0_par = %d\n", e0_par));
+        MCA_VERBOSE3(printf("e1_par = %d\n", e1_par));
 
         mca_par->width  = width;
@@ -313,19 +313,13 @@
         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
-#if FEATURES
             mca_par->stats = remote_RegionStatsVector(e0_par - 1, e1_par, x, y);
-#endif
         }
         else {
             mca_par->T = remote_ui32vector(e0_par, e1_par, x, y);
-#if FEATURES
             mca_par->stats = remote_RegionStatsVector(e0_par, e1_par, x, y);
-#endif
         }
         
         mca_par->D = (uint32 **) remote_vvector(0, np - 1, x, y);
-#if FEATURES
         mca_par->F = (RegionStats **) remote_vvector(0, np - 1, x, y);
-#endif
 #else // !GIETVM
         mca_par->X = ui8matrix (i0_par, i1_par, 0, width - 1);
@@ -334,25 +328,18 @@
         if (p == 0) {
             mca_par->T = ui32vector(e0_par - 1, e1_par); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot
-#if FEATURES
             mca_par->stats = RegionStatsVector(e0_par - 1, e1_par);
-
-#endif
         }
         else {
             mca_par->T = ui32vector(e0_par, e1_par);
-#if FEATURES
             mca_par->stats = RegionStatsVector(e0_par, e1_par);
-#endif
         }
         
         mca_par->D = (uint32 **) vvector(0, np - 1);
-#if FEATURES
         mca_par->F = (RegionStats **) vvector(0, np - 1);
-#endif
 #endif   
-        MCA_VERBOSE2(printf("X = %p\n", mca_par->X));
-        MCA_VERBOSE2(printf("E = %p\n", mca_par->E));
-        MCA_VERBOSE2(printf("T = %p\n", mca_par->T));
-        MCA_VERBOSE2(printf("D = %p\n", mca_par->D));
+        MCA_VERBOSE3(printf("X = %p\n", mca_par->X));
+        MCA_VERBOSE3(printf("E = %p\n", mca_par->E));
+        MCA_VERBOSE3(printf("T = %p\n", mca_par->T));
+        MCA_VERBOSE3(printf("D = %p\n", mca_par->D));
     } // p
     
@@ -365,5 +352,5 @@
         uint32 e1 = mca_par->e1;
     
-        MCA_VERBOSE2(printf("p = %d T[%d..%d]\n", p, e0, e1));
+        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
@@ -372,8 +359,8 @@
             set_ui32vector_j(T, e0, e1);
         }
-        MCA_VERBOSE2(printf("\n"));
-    }
-    
-    MCA_VERBOSE2(printf("display des tables d'EQ\n"));
+        MCA_VERBOSE3(printf("\n"));
+    }
+    
+    MCA_VERBOSE3(printf("display des tables d'EQ\n"));
     for (int p = 0; p < np; p++) {
         MCA * mca_par = mcas[p];
@@ -383,12 +370,12 @@
         uint32 e1 = mca_par->e1;
         
-        MCA_VERBOSE2(printf("p = %d T[%d..%d]\n", p, e0, e1));
-        if (p == 0) {
-            MCA_VERBOSE2(display_ui32vector_number(T, e0 - 1, e0 + 10, "%5d", "T"));
-        }
-        else {
-            MCA_VERBOSE2(display_ui32vector_number(T, e0, e0 + 10, "%5d", "T"));
-        }
-        MCA_VERBOSE2(printf("\n"));
+        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(printf("\n"));
     }
     //exit(-1);
@@ -399,5 +386,5 @@
     
     // table d'indirection distribuee D
-    MCA_VERBOSE2(printf("nemax_par = %d\n", nemax_par));
+    MCA_VERBOSE3(printf("nemax_par = %d\n", nemax_par));
     for (int p = 0; p < np; p++) {
         MCA * mca_p = mcas[p];
@@ -409,15 +396,13 @@
             uint32 * T = mca_k->T;
             D[k] = T + k * nemax_par; // il faut soustraire le "MSB"
-#if FEATURES
             RegionStats * stat = mca_k->stats;
             F[k] = stat + k * nemax_par; // il faut soustraire le "MSB"
-#endif
         } // k
     } // p
     
-    MCA_VERBOSE2(printf("table d'indirection distribuee D\n"));
-    
-    for (int p = 0; p < np; p++) {
-        MCA_VERBOSE2(printf("== p = %d ==========\n", p));
+    MCA_VERBOSE3(printf("table d'indirection distribuee D\n"));
+    
+    for (int p = 0; p < np; p++) {
+        MCA_VERBOSE3(printf("== p = %d ==========\n", p));
         
         MCA * mca_p = mcas[p];
@@ -430,20 +415,11 @@
             uint32 e0 = mca_k->e0;
             uint32 e1 = mca_k->e1;
-            MCA_VERBOSE2(display_ui32vector_number(T, e0, e0 + 9, "%5d", "T"));
-            MCA_VERBOSE2(display_ui32vector(D[k], 0, 9, "%5d", "D\n"));
-        }
-        MCA_VERBOSE2(printf("\n"));
-    }
-    
-    /**/
-    //exit(-1);
-    
-    //printf("[MCA_Initialize] positionnement des pointeurs de lignes (i0-1) et (i1+1)");
-    
-    for (int p = 0; p < np; p++) {
-    
-        //printf(" --p = %d ------------------\n", p);
-        // cas general
-        
+            MCA_VERBOSE3(display_ui32vector_number(T, e0, e0 + 9, "%5d", "T"));
+            MCA_VERBOSE3(display_ui32vector(D[k], 0, 9, "%5d", "D\n"));
+        }
+        MCA_VERBOSE3(printf("\n"));
+    }
+    
+    for (int p = 0; p < np; p++) {
         if (p > 0) {
             //printf("i0_(%d) = %d i1_{%d} = %d\n", p, mcas[p]->i0, p-1, mcas[p-1]->i1);
@@ -476,18 +452,18 @@
     (void) mca_par;
     
-    printf("*** MCA_Display_Parameters ***\n");
-    
-    MCA_VERBOSE1(printf("   height = %d\n", mca->height));
-    MCA_VERBOSE1(printf("   width  = %d\n", mca->width));
-    MCA_VERBOSE1(printf("   np     = %d\n", mca->np));
+    MCA_VERBOSE1(printf("*** MCA_Display_Parameters ***\n"));
+    
+    MCA_VERBOSE2(printf("   height = %d\n", mca->height));
+    MCA_VERBOSE2(printf("   width  = %d\n", mca->width));
+    MCA_VERBOSE2(printf("   np     = %d\n", mca->np));
     
     for (int p = 0; p < np; p++) {
         mca_par = mcas[p];
         
-        MCA_VERBOSE2(printf("Display MCA[%d]\n", p));
-        MCA_VERBOSE2(printf("p = %d\n", mca_par->p));
-        MCA_VERBOSE2(printf("i0 = %8d  i1 = %8d\n", mca_par->i0, mca_par->i1));
-        MCA_VERBOSE2(printf("j0 = %8d  j1 = %8d\n", mca_par->j0, mca_par->j1));
-        MCA_VERBOSE2(printf("e0 = %8d  e1 = %8d\n", mca_par->e0, mca_par->e1));
+        MCA_VERBOSE3(printf("Display MCA[%d]\n", p));
+        MCA_VERBOSE3(printf("p = %d\n", mca_par->p));
+        MCA_VERBOSE3(printf("i0 = %8d  i1 = %8d\n", mca_par->i0, mca_par->i1));
+        MCA_VERBOSE3(printf("j0 = %8d  j1 = %8d\n", mca_par->j0, mca_par->j1));
+        MCA_VERBOSE3(printf("e0 = %8d  e1 = %8d\n", mca_par->e0, mca_par->e1));
     }
 }
@@ -507,5 +483,5 @@
     uint32 e0, e1;
     
-    printf("*** MCA_Finalize ***\n");
+    MCA_VERBOSE1(printf("*** MCA_Finalize ***\n"));
     
 #if PYR_BARRIERS
@@ -532,19 +508,13 @@
         if (p == 0) {
             free_ui32vector(mca_par->T, e0 - 1, e1); // car e0 = 1, on a besoin que T[0] = 0 pour FindRoot
-#if FEATURES
             free_RegionStatsVector(mca_par->stats, e0 - 1, e1);
-#endif
         }
         else {
             free_ui32vector(mca_par->T, e0, e1);
-#if FEATURES
             free_RegionStatsVector(mca_par->stats, e0, e1);
-#endif
         }
         
         free_vvector((void **) mca_par->D, 0, np - 1);
-#if FEATURES
         free_vvector((void **) mca_par->F, 0, np - 1);
-#endif
         free(mca_par);
     }
@@ -564,5 +534,5 @@
     
     if (mca->p == 0) { 
-        printf("*** MCA_Scatter_ImageX ***\n");
+        MCA_VERBOSE1(printf("*** MCA_Scatter_ImageX ***\n"));
     }
     
@@ -593,5 +563,5 @@
 
     if (mca->p == 0) { 
-        printf("*** MCA_Gather_ImageL ***\n");
+        MCA_VERBOSE1(printf("*** MCA_Gather_ImageL ***\n"));
     }
 
Index: soft/giet_vm/applications/rosenfeld/src-par/mca_main.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/src-par/mca_main.c	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/src-par/mca_main.c	(revision 822)
@@ -126,42 +126,49 @@
 
 
-// QM : The cost of this function is horrible
-// but it is only for testing purpose
 // Renumbers object in a contiguous way, for an image which has already
 // been processed with several threads
-// --------------------------------------------------------------------
-static void renumber_image(uint32 ** E, int i0, int i1, int j0, int j1)
-// --------------------------------------------------------------------
-{
-    int size = 10;
-    int idx = 1; // next label to give, first invalid index in the equiv table
-    uint32 * equiv = malloc(sizeof(uint32) * size);
-    equiv[0] = 0; // unused
-    int found;
-
-    for (int i = i0; i <= i1; i++) {
-        for (int j = j0; j <= j1; j++) {
-            if (E[i][j] != 0) {
-                found = 0;
-                for (int k = 1; k < idx; k++) {
-                    if (equiv[k] == E[i][j]) {
-                        E[i][j] = k;
-                        found = 1;
-                        break;
-                    }
-                }
-                if (found == 0) {
-                    equiv[idx] = E[i][j];
-                    E[i][j] = idx;
-                    idx += 1;
-                    if (idx == size) {
-                        size = size * 2;
-                        equiv = realloc(equiv, sizeof(uint32) * size);
-                    }
-                }
+// ------------------------------------------------------------------
+static void renumber_image(MCA * mca, int i0, int i1, int j0, int j1)
+// ------------------------------------------------------------------
+{
+    int32_t na = 0;
+    uint32_t ** E = mca->E;
+    uint32_t ** D = mca->mcas[0]->D;
+
+    uint32_t shift = mca->alpha;
+    uint32_t mask = (1 << shift) - 1;
+    
+    for (int32_t p = 0; p < mca->np; p++) {
+        MCA * mca_par = mca->mcas[p];
+        uint32 * T = mca_par->T;
+        for (uint32_t e = mca_par->e0; e <= mca_par->ne; e++) {
+            if (T[e] != e) {
+                // FindRoot_Dist
+                uint32_t r = T[e];
+                uint32_t a = e;
+                do {
+                    uint32_t e1 = r >> shift;
+                    uint32_t e0 = r & mask;
+                    a = r;
+                    r = D[e1][e0];
+                } while (r < a);
+                T[e] = r;
+            }
+            else {
+                na += 1;
+                T[e] = na;
             }
         }
     }
-    free(equiv);
+
+    for (int32_t i = i0; i <= i1; i++) {
+        for (int32_t j = j0; j <= j1; j++) {
+            if (E[i][j] != 0) {
+                uint32_t e0 = E[i][j] & mask;
+                uint32_t e1 = E[i][j] >> shift;
+                E[i][j] = D[e1][e0];
+            }
+        }
+    }
 }
 
@@ -203,15 +210,10 @@
     
     display_ui8matrix_positive(mca->X, i0, i1, j0, j1, 5, "X0");
-#if FEATURES
-    for (int i = 1; i < num_threads; i++) {
-        pthread_create(&thread_table[i], NULL, MCA_Label_Features_Rosenfeld, (void *) mca->mcas[i]);
-    }
-    MCA_Label_Features_Rosenfeld(mca->mcas[0]);
-#else
     for (int i = 1; i < num_threads; i++) {
         pthread_create(&thread_table[i], NULL, MCA_Label_Rosenfeld, (void *) mca->mcas[i]);
     }
+    
     MCA_Label_Rosenfeld(mca->mcas[0]);
-#endif
+
     for (int i = 1; i < num_threads; i++) {
         pthread_join(thread_table[i], NULL);
@@ -221,8 +223,8 @@
     
     // -- free --
-    printf("Finalize\n");
+    MCA_VERBOSE1(printf("Finalize\n"));
     MCA_Finalize(mca);
     
-    printf("Free_matrix\n");
+    MCA_VERBOSE1(printf("Free_matrix\n"));
     free_ui8matrix (X0, i0, i1, j0, j1);
     free_ui32matrix(E,  i0, i1, j0, j1);
@@ -249,9 +251,9 @@
     Palette_18ColorsBW(palette);
     
-    printf("Loading file %s... ", infile);
+    MCA_VERBOSE1(printf("Loading file %s... ", infile));
     X = LoadPGM_ui8matrix(infile, &i0, &i1, &j0, &j1);
-    printf("done.\n");
-
-    printf("Allocating memory... ");
+    MCA_VERBOSE1(printf("done.\n"));
+
+    MCA_VERBOSE1(printf("Allocating memory... "));
     height = i1 - i0 + 1;
     width  = j1 - j0 + 1;
@@ -265,7 +267,7 @@
     // pre-traitements
     binarisation_ui8matrix(X, i0, i1, j0, j1, 20, 1, X); // pour le traitement
-    printf("done.\n");
-
-    printf("Allocating and initializing MCA... \n");
+    MCA_VERBOSE1(printf("done.\n"));
+
+    MCA_VERBOSE1(printf("Allocating and initializing MCA... \n"));
     mca = MCA_pConstructor_Empty();
     
@@ -279,18 +281,13 @@
     MCA_Initialize(mca);
     MCA_Display_Parameters(mca);
-    printf("End of MCA allocation and initialization.\n");
+    MCA_VERBOSE1(printf("End of MCA allocation and initialization.\n"));
     
     CLOCK_APP_CREATE;
-#if FEATURES
-    for (int i = 1; i < num_threads; i++) {
-        pthread_create(&thread_table[i], NULL, MCA_Label_Features_Rosenfeld, (void *) mca->mcas[i]);
-    }
-    MCA_Label_Features_Rosenfeld(mca->mcas[0]);
-#else
     for (int i = 1; i < num_threads; i++) {
         pthread_create(&thread_table[i], NULL, MCA_Label_Rosenfeld, (void *) mca->mcas[i]);
     }
+    
     MCA_Label_Rosenfeld(mca->mcas[0]);
-#endif
+
     for (int i = 1; i < num_threads; i++) {
         pthread_join(thread_table[i], NULL);
@@ -300,20 +297,20 @@
     if (generate_output_image) {
 #if TARGET_OS != GIETVM
-        renumber_image(mca->E, i0, i1, j0, j1);
+        renumber_image(mca, i0, i1, j0, j1);
 #else
         printf("Warning: the output image has not been renumbered, it cannot be used as a comparison with the reference\n");
 #endif
         mod_ui32matrix_ui8matrix(mca->E, i0, i1, j0, j1, E8);
-        printf("Saving file %s for verification... ", outfile);
+        MCA_VERBOSE1(printf("Saving file %s for verification... ", outfile));
         SaveBMP2_ui8matrix(E8, width, height, palette, outfile);
-        printf("done.\n");
+        MCA_VERBOSE1(printf("done.\n"));
     }
 
     MCA_Finalize(mca);
-    printf("Deallocating memory...");
+    MCA_VERBOSE1(printf("Deallocating memory..."));
     free_ui8matrix (X,  i0, i1, j0, j1);
     free_ui8matrix (E8, i0, i1, j0, j1);
     free_ui32matrix(E,  i0, i1, j0, j1);
-    printf("done.\n");
+    MCA_VERBOSE1(printf("done.\n"));
 }
 
@@ -353,5 +350,5 @@
     int num_threads = DEFAULT_NTHREADS;
 
-    printf("*** Starting application Rosenfeld ***\n");
+    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
@@ -410,17 +407,32 @@
     }
 
-    printf("Parameters:\n");
-    printf("- Number of threads: %d\n", num_threads);
-    printf("- Input file: %s\n", infile);
-    printf("- Output file: %s\n", outfile);
+    MCA_VERBOSE1(printf("Parameters:\n"));
+    MCA_VERBOSE1(printf("- Number of threads: %d\n", num_threads));
+    MCA_VERBOSE1(printf("- Input file: %s\n", infile));
+    MCA_VERBOSE1(printf("- Output file: %s\n", outfile));
 #if FAST
-    printf("- Using decision trees (fast): yes\n");
+    MCA_VERBOSE1(printf("- Using decision trees (fast): yes\n"));
 #elif SLOW
-    printf("- Using decision trees (fast): no\n");
+    MCA_VERBOSE1(printf("- Using decision trees (fast): no\n"));
 #endif
 #if FEATURES
-    printf("- Computing features: yes\n");
-#else
-    printf("- Computing features: no\n");
+    MCA_VERBOSE1(printf("- Computing features: yes\n"));
+#else
+    MCA_VERBOSE1(printf("- Computing features: no\n"));
+#endif
+#if PARMERGE
+    MCA_VERBOSE1(printf("- Parallel Merge: yes\n"));
+#else
+    MCA_VERBOSE1(printf("- Parallel Merge: no\n"));
+#endif
+#if ARSP
+    MCA_VERBOSE1(printf("- Optimization ARemSP: yes\n"));
+#else
+    MCA_VERBOSE1(printf("- Optimization ARemSP: no\n"));
+#endif
+#if PYR_BARRIERS
+    MCA_VERBOSE1(printf("- Pyramidal Barriers: yes\n"));
+#else
+    MCA_VERBOSE1(printf("- Pyramidal Barriers: no\n"));
 #endif
 
@@ -428,5 +440,5 @@
 #if TARGET_OS == GIETVM
     giet_tty_alloc(1);
-    printf("Initializing heaps... ");
+    MCA_VERBOSE1(printf("Initializing heaps... "));
     for (int i = 0; i < X_SIZE; i++) {
         for (int j = 0; j < X_SIZE; j++) {
@@ -434,5 +446,5 @@
         }
     }
-    printf("done.\n");
+    MCA_VERBOSE1(printf("done.\n"));
 #endif
 
@@ -443,2 +455,11 @@
 }
 
+// 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/src-par/mca_rosenfeld.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/src-par/mca_rosenfeld.c	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/src-par/mca_rosenfeld.c	(revision 822)
@@ -61,8 +61,6 @@
         r = T[r];
     }
-    if (r == 0) {
-        printf("e = %d\n",e);
-        assert(0);
-    }
+
+    assert(r != 0);
     return r;
 }
@@ -81,5 +79,5 @@
     int mask = (1 << shift) - 1;
     
-    MCA_VERBOSE2(printf("%s(%d, %d) \n", __func__, r, shift));
+    MCA_VERBOSE3(printf("%s(%d, %d) \n", __func__, r, shift));
     do {
         e  = r;
@@ -87,7 +85,7 @@
         e0 = r & mask;
         r = D[e1][e0];
-        MCA_VERBOSE2(printf("%s: D(%d) = D[%d,%d] = %d (alpha = %d)\n", __func__, e, e1, e0, r, shift));
+        MCA_VERBOSE3(printf("%s: D(%d) = D[%d,%d] = %d (alpha = %d)\n", __func__, e, e1, e0, r, shift));
     } while (r < e);
-    MCA_VERBOSE2(printf("%s = %d \n\n", __func__, r));
+    MCA_VERBOSE3(printf("%s = %d \n\n", __func__, r));
     assert(r != 0);
     return r;
@@ -112,15 +110,14 @@
 
 #if FEATURES && !PARMERGE
-// ----------------------------------------------------------------------------------------------------
-void SetRoot_Features_Rosenfeld_Dist(uint32 ** D, uint32 root, uint32 eps, int shift, RegionStats ** F)
-// ----------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------------------------------------
+static void SetRoot_Features_Rosenfeld_Dist(uint32 ** D, uint32 root, uint32 eps, int shift, RegionStats ** F)
+// -----------------------------------------------------------------------------------------------------------
 {
     assert(root != 0 && eps != 0);
 
-    MCA_VERBOSE2(printf("F(%d) += F(%d)\n", eps, root));
+    MCA_VERBOSE3(printf("F(%d) += F(%d)\n", eps, root));
     
     int mask = (1 << shift) - 1;
 
-    // SetRoot_Rosenfeld_Dist
     uint32 r1 = root >> shift;
     uint32 r0 = root & mask;
@@ -148,15 +145,14 @@
 
 #if FEATURES && PARMERGE
-// -------------------------------------------------------------------------------------------------------------
-bool SetRoot_Parallel_Features_Rosenfeld_Dist(uint32 ** D, uint32 root, uint32 eps, int shift, RegionStats ** F)
-// -------------------------------------------------------------------------------------------------------------
+// --------------------------------------------------------------------------------------------------------------------
+static bool SetRoot_Parallel_Features_Rosenfeld_Dist(uint32 ** D, uint32 root, uint32 eps, int shift, RegionStats ** F)
+// --------------------------------------------------------------------------------------------------------------------
 {
     assert(root != 0 && eps != 0);
 
-    MCA_VERBOSE2(printf("F(%d) += F(%d)\n", eps, root));
+    MCA_VERBOSE3(printf("F(%d) += F(%d)\n", eps, root));
     
     int mask = (1 << shift) - 1;
 
-    // SetRoot_Rosenfeld_Dist
     uint32 r1 = root >> shift;
     uint32 r0 = root & mask;
@@ -177,5 +173,5 @@
     }
     if (D[r1][r0] != root) {
-        // Someone change the root of epsilon, need to find the new root
+        // Someone change the root of "root", need to find the new root
         printf("race cond 2\n");
         pthread_spin_unlock(&F[e1][e0].lock);
@@ -249,5 +245,5 @@
 
 
-#if FAST && !FEATURES
+#if FAST && !FEATURES && !PARMERGE && !ARSP
 // ---------------------------------------------------------------------------------------
 static void vuse2_Rosenfeld_Dist(uint32 ed, uint32 el, uint32 * T, uint32 ** D, int alpha)
@@ -273,8 +269,7 @@
     }
 }
-#endif // FAST && !FEATURES
-
-
-#if FAST && !FEATURES
+
+// FAST && !FEATURES && !PARMERGE && !ARSP
+
 // -----------------------------------------------------------------------------------------------------
 static void vuse3_Rosenfeld_Dist(uint32 ed1, uint32 ed2, uint32 el3, uint32 * T, uint32 ** D, int alpha)
@@ -284,6 +279,4 @@
     uint32 r2 = FindRoot_Dist(D, ed2, alpha);
     
-    // QM
-    //uint32 r3 = FindRoot(T, el3); // local - distant
     uint32 r3 = T[el3]; // local - distant
     r3 = FindRoot_Dist(D, r3, alpha);
@@ -297,24 +290,22 @@
     uint32 eps = ui32Min3(r1, r2, r3);  // forcement positifs car appel depuis optimizedBorder qui a fait un test
     
+    // On ne fait pas le test car on peut faire le SetRoot plusieurs fois sur le mÃªme Ã©lÃ©ment (on n'accumule pas de stats)
     if (r1 > eps) {
         SetRoot_Rosenfeld_Dist(D, r1, eps, alpha);
     }
-    //r2 = T[r2]; // @QM est-ce indispensable s'il n'y a pas de features ? (cf. slow no features)
-    // comment est-on sur que r2 (ou r3) est local ???
     if (r2 > eps) {
         SetRoot_Rosenfeld_Dist(D, r2, eps, alpha);
     }
-    //r3 = T[r3];
     if (r3 > eps) {
         SetRoot_Rosenfeld_Dist(D, r3, eps, alpha);
     }
 }
-#endif // FAST && !FEATURES
-
-
-#if FAST && FEATURES && !PARMERGE
-// -----------------------------------------------------------------------------------------------------------
-void vuse2_Features_Rosenfeld_Dist(uint32 ed, uint32 el, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
-// -----------------------------------------------------------------------------------------------------------
+#endif // FAST && !FEATURES && !PARMERGE && !ARSP
+
+
+#if FAST && FEATURES && !PARMERGE && !ARSP
+// ------------------------------------------------------------------------------------------------------------------
+static void vuse2_Features_Rosenfeld_Dist(uint32 ed, uint32 el, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
+// ------------------------------------------------------------------------------------------------------------------
 {
     assert(ed != 0 && el != 0);
@@ -341,11 +332,10 @@
     }
 }
-#endif // FAST && FEATURES && !PARMERGE
-
-
-#if FAST && FEATURES && !PARMERGE
-// -------------------------------------------------------------------------------------------------------------------------
-void vuse3_Features_Rosenfeld_Dist(uint32 ed1, uint32 ed2, uint32 el3, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
-// -------------------------------------------------------------------------------------------------------------------------
+
+// FAST && FEATURES && !PARMERGE && !ARSP
+
+// --------------------------------------------------------------------------------------------------------------------------------
+static void vuse3_Features_Rosenfeld_Dist(uint32 ed1, uint32 ed2, uint32 el3, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
+// --------------------------------------------------------------------------------------------------------------------------------
 {
     assert(ed1 != 0 && ed2 != 0 && el3 != 0);
@@ -354,5 +344,4 @@
     uint32 r2 = FindRoot_Dist(D, ed2, alpha);
     
-    //uint32 r3 = FindRoot(T, el3); // local - distant
     uint32 r3 = T[el3]; // local - distant
     assert(r3 != 0);
@@ -370,20 +359,234 @@
         SetRoot_Features_Rosenfeld_Dist(D, r1, eps, alpha, F);
     }
-    //r2 = T[r2];
     if (r2 > eps && r2 != r1) {
         SetRoot_Features_Rosenfeld_Dist(D, r2, eps, alpha, F);
     }
-    //r3 = T[r3];
     if (r3 > eps && r3 != r2 && r3 != r1) {
         SetRoot_Features_Rosenfeld_Dist(D, r3, eps, alpha, F);
     }
 }
-#endif // FAST && FEATURES && !PARMERGE
-
-
-#if FAST && FEATURES && PARMERGE
-// --------------------------------------------------------------------------------------------------------------------
-void vuse2_Parallel_Features_Rosenfeld_Dist(uint32 ed, uint32 el, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
-// --------------------------------------------------------------------------------------------------------------------
+#endif // FAST && FEATURES && !PARMERGE && !ARSP
+
+
+#if FAST && !FEATURES && PARMERGE && ARSP
+// ----------------------------------------------------------------------------------------------------------------
+static bool SetRoot_Parallel_Arsp_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));
+    
+    uint32_t mask = (1 << shift) - 1;
+
+    uint32_t r1 = root >> shift;
+    uint32_t r0 = root & mask;
+    
+    pthread_spin_lock(&F[r1][r0].lock);
+    if (D[r1][r0] != root) {
+        pthread_spin_unlock(&F[r1][r0].lock);
+        return false;
+    }
+
+    D[r1][r0] = eps;
+    
+    pthread_spin_unlock(&F[r1][r0].lock);
+    return true;
+}
+
+// FAST && !FEATURES && PARMERGE && ARSP
+
+// ------------------------------------------------------------------------------------------------------------------------------
+static inline bool FindSmallerAncestor_Link(uint32 ** D, uint32_t rl, uint32_t el, uint32_t rd, uint32_t shift, RegionStats ** F)
+// ------------------------------------------------------------------------------------------------------------------------------
+{
+    bool ok;
+    uint32_t el1, el0;
+    uint32_t mask = (1 << shift) - 1;
+    while (rl < el && rl > rd) {
+        el = rl;
+        el1 = rl >> shift;
+        el0 = rl & mask;
+        rl = D[el1][el0];
+    }
+    if (rd != rl) {
+        if (rl == el && rl > rd) {
+            // L'ordre s'est inversÃ© : on fait pointer rl vers rd
+            ok = SetRoot_Parallel_Arsp_Rosenfeld_Dist(D, rl, rd, shift, F);
+        }
+        else {
+            // On fait pointer rd vers rl
+            ok = SetRoot_Parallel_Arsp_Rosenfeld_Dist(D, rd, rl, shift, F);
+        }
+    }
+    else {
+        ok = true;
+    }
+    return ok;
+}
+
+// FAST && !FEATURES && PARMERGE && ARSP
+
+// -----------------------------------------------------------------------------------------------------------------------
+static void vuse2_Parallel_Arsp_Rosenfeld_Dist(uint32 ed, uint32 el, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
+// -----------------------------------------------------------------------------------------------------------------------
+{
+    assert(ed != 0 && el != 0);
+ 
+    uint32_t shift = alpha;
+    uint32_t mask = (1 << shift) - 1;
+    
+    uint32_t rd = ed;
+    uint32_t rl = el;
+
+    uint32_t ed1;
+    uint32_t el1;
+    uint32_t ed0;
+    uint32_t el0;
+
+    bool ok;
+
+    // Fusion ed - el
+    do {
+        do {
+            ed = rd;
+            el = rl;
+            ed1 = rd >> shift;
+            el1 = rl >> shift;
+            ed0 = rd & mask;
+            el0 = rl & mask;
+            rd = D[ed1][ed0];
+            rl = D[el1][el0];
+        } while (rl < el && rd < ed);
+
+        assert(rl != 0 && rd != 0);
+
+        if (rd != rl) {
+            if (rd == ed) {
+                ok = FindSmallerAncestor_Link(D, rl, el, rd, shift, F);
+            }
+            else {
+                assert(rl == el);
+                ok = FindSmallerAncestor_Link(D, rd, ed, rl, shift, F);
+            }
+        }
+        else {
+            ok = true;
+        }
+    } while (!ok);
+}
+
+// FAST && !FEATURES && PARMERGE && ARSP
+
+// -------------------------------------------------------------------------------------------------------------------------------------
+static void vuse3_Parallel_Arsp_Rosenfeld_Dist(uint32 ed1, uint32 ed2, uint32 el3, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
+// -------------------------------------------------------------------------------------------------------------------------------------
+{
+    assert(ed1 != 0 && ed2 != 0 && el3 != 0);
+ 
+    uint32_t shift = alpha;
+    uint32_t mask = (1 << shift) - 1;
+    
+    uint32_t r1 = ed1;
+    uint32_t r2 = ed2;
+    uint32_t r3 = el3;
+
+    uint32_t e11;
+    uint32_t e21;
+    uint32_t e31;
+    uint32_t e10;
+    uint32_t e20;
+    uint32_t e30;
+
+    uint32_t r0;
+    uint32_t ed0;
+    uint32_t e00;
+    uint32_t e01;
+
+    // Pas d'init pour que valgrind dÃ©tecte une erreur si bool est lu sans Ãªtre affectÃ©
+    bool ok;
+
+    // Fusion ed1 - ed2
+    do {
+        do {
+            ed1 = r1;
+            ed2 = r2;
+            e11 = r1 >> shift;
+            e21 = r2 >> shift;
+            e10 = r1 & mask;
+            e20 = r2 & mask;
+            r1 = D[e11][e10];
+            r2 = D[e21][e20];
+        } while (r1 < ed1 && r2 < ed2);
+
+        assert(r1 != 0 && r2 != 0);
+
+        if (r1 != r2) {
+            if (r1 == ed1) {
+                ok = FindSmallerAncestor_Link(D, r2, ed2, r1, shift, F);
+            }
+            else {
+                assert(r2 == ed2);
+                ok = FindSmallerAncestor_Link(D, r1, ed1, r2, shift, F);
+            }
+        }
+        else {
+            ok = true;
+        }
+    } while (!ok);
+
+    // Fusion r0 = min(r1, r2) avec r3
+    if (r1 < r2) {
+        r0 = r1;
+        ed0 = r1;
+        e00 = e10;
+        e01 = e11;
+    }
+    else {
+        r0 = r2;
+        ed0 = r2;
+        e00 = e20;
+        e01 = e21;
+    }
+
+    // r0 est dÃ©jÃ  une racine
+    goto r0_is_root;
+    do {
+        do {
+            ed0 = r0;
+            el3 = r3;
+            e01 = r0 >> shift;
+            e31 = r3 >> shift;
+            e00 = r0 & mask;
+            e30 = r3 & mask;
+            r0 = D[e01][e00];
+            r3 = D[e31][e30];
+        } while (r0 < ed0 && r3 < el3);
+
+        assert(r0 != 0 && r3 != 0);
+
+        if (r0 != r3) {
+            if (r0 == ed0) {
+r0_is_root:
+                ok = FindSmallerAncestor_Link(D, r3, el3, r0, shift, F);
+            }
+            else {
+                assert(r3 == el3);
+                ok = FindSmallerAncestor_Link(D, r0, ed0, r3, shift, F);
+            }
+        }
+        else {
+            ok = true;
+        }
+    } while (!ok);
+}
+#endif // FAST && !FEATURES && PARMERGE && ARSP
+
+
+
+#if FAST && FEATURES && PARMERGE && !ARSP
+// ---------------------------------------------------------------------------------------------------------------------------
+static void vuse2_Parallel_Features_Rosenfeld_Dist(uint32 ed, uint32 el, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
+// ---------------------------------------------------------------------------------------------------------------------------
 {
     bool ok;
@@ -414,11 +617,10 @@
     } while (!ok);
 }
-#endif // FAST && FEATURES && PARMERGE
-
-
-#if FAST && FEATURES && PARMERGE
-// ----------------------------------------------------------------------------------------------------------------------------------
-void vuse3_Parallel_Features_Rosenfeld_Dist(uint32 ed1, uint32 ed2, uint32 el3, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
-// ----------------------------------------------------------------------------------------------------------------------------------
+
+// FAST && FEATURES && PARMERGE && !ARSP
+
+// -----------------------------------------------------------------------------------------------------------------------------------------
+static void vuse3_Parallel_Features_Rosenfeld_Dist(uint32 ed1, uint32 ed2, uint32 el3, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
+// -----------------------------------------------------------------------------------------------------------------------------------------
 {
     bool ok1, ok2, ok3;
@@ -457,13 +659,12 @@
     } while (!(ok1 && ok2 && ok3));
 }
-#endif // FAST && FEATURES && PARMERGE
-
-
-
-
-#if FAST && !FEATURES
-// ------------------------------------------------------------------------------------------------------
-static void optimizedBorder_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha)
-// ------------------------------------------------------------------------------------------------------
+#endif // FAST && FEATURES && PARMERGE && !ARSP
+
+
+
+#if FAST
+// ------------------------------------------------------------------------------------------------------------------------
+static void optimizedBorder_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
+// ------------------------------------------------------------------------------------------------------------------------
 {
     uint32 a, b, c, x;
@@ -473,5 +674,5 @@
         b = E[i - 1][j];
         if (b) {
-            vuse2_Rosenfeld_Dist(b, x, T, D, alpha); // dist, local
+            vuse2_Rosenfeld(b, x, T, D, alpha, F); // dist, local
         }
         else {
@@ -480,8 +681,8 @@
                 a = E[i - 1][j - 1];
                 if (a) {
-                    vuse3_Rosenfeld_Dist(a, c, x, T, D, alpha); // dist, local
+                    vuse3_Rosenfeld(a, c, x, T, D, alpha, F); // dist, local
                 }
                 else {
-                    vuse2_Rosenfeld_Dist(c, x, T, D, alpha); // dist, local
+                    vuse2_Rosenfeld(c, x, T, D, alpha, F); // dist, local
                 }
             }
@@ -489,5 +690,5 @@
                 a = E[i - 1][j - 1];
                 if (a) {
-                    vuse2_Rosenfeld_Dist(a, x, T, D, alpha); // dist, local
+                    vuse2_Rosenfeld(a, x, T, D, alpha, F); // dist, local
                 }
             }
@@ -495,11 +696,10 @@
     }
 }
-#endif // FAST && !FEATURES
-
-
-#if FAST && !FEATURES
-// ---------------------------------------------------------------------------------------------------
-static void optimizedBorderLeft_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha)
-// ---------------------------------------------------------------------------------------------------
+
+// FAST
+
+// ----------------------------------------------------------------------------------------------------------------------------
+static void optimizedBorderLeft_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
+// ----------------------------------------------------------------------------------------------------------------------------
 {
     uint32 x = E[i][j];
@@ -507,21 +707,20 @@
         uint32 b = E[i - 1][j];
         if (b) {
-            vuse2_Rosenfeld_Dist(b, x, T, D, alpha); // dist, local
+            vuse2_Rosenfeld(b, x, T, D, alpha, F); // dist, local
         }
         else {
             uint32 c = E[i - 1][j + 1];
             if (c) {
-                vuse2_Rosenfeld_Dist(c, x, T, D, alpha); // dist, local
-            }
-        }
-    }
-}
-#endif // FAST && !FEATURES
-
-
-#if FAST && !FEATURES
-// -----------------------------------------------------------------------------------------------------------
-static void optimizedBorderRight_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha)
-// -----------------------------------------------------------------------------------------------------------
+                vuse2_Rosenfeld(c, x, T, D, alpha, F); // dist, local
+            }
+        }
+    }
+}
+
+// FAST
+
+// -----------------------------------------------------------------------------------------------------------------------------
+static void optimizedBorderRight_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
+// -----------------------------------------------------------------------------------------------------------------------------
 {
     // copie de optimizedBorder_Rosenfeld
@@ -533,40 +732,40 @@
     if (x) {
         if (b) {
-            vuse2_Rosenfeld_Dist(b, x, T, D, alpha); // dist, local
+            vuse2_Rosenfeld(b, x, T, D, alpha, F); // dist, local
         }
         else {
             uint32 a = E[i - 1][j - 1];
             if (a) {
-                vuse2_Rosenfeld_Dist(a, x, T, D, alpha); // dist, local
-            }
-        }
-    }
-}
-#endif // FAST && !FEATURES
-
-
-#if FAST && !FEATURES
-// ------------------------------------------------------------------------------------------------------------------------
-static void borderMerging_Fast_Rosenfeld_Dist(uint8 **X, int i, int width, uint32 ** E, uint32 * T, uint32 ** D, int alpha)
-// ------------------------------------------------------------------------------------------------------------------------
+                vuse2_Rosenfeld(a, x, T, D, alpha, F); // dist, local
+            }
+        }
+    }
+}
+
+// FAST
+
+// -------------------------------------------------------------------------------------------------------------------------------------------
+static void borderMerging_Fast_Rosenfeld_Dist(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
+// -------------------------------------------------------------------------------------------------------------------------------------------
 {
     // Prologue
-    optimizedBorderLeft_Rosenfeld_Dist(E, i, 0, T, D, alpha);
+    optimizedBorderLeft_Rosenfeld_Dist(E, i, 0, T, D, alpha, F);
     // Boucle principale
     for (int j = 1; j < width - 1; j++) {
-        optimizedBorder_Rosenfeld_Dist(E, i, j, T, D, alpha);
+        optimizedBorder_Rosenfeld_Dist(E, i, j, T, D, alpha, F);
     }
     // Epilogue
-    optimizedBorderRight_Rosenfeld_Dist(E, i, width - 1, T, D, alpha);
-}
-#endif // FAST && !FEATURES
-
-
-#if SLOW && !FEATURES
-// -------------------------------------------------------------------------------------------------------------------------
-static void borderMerging_Slow_Rosenfeld_Dist(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ** D, int alpha)
-// -------------------------------------------------------------------------------------------------------------------------
-{
-    int j;
+    optimizedBorderRight_Rosenfeld_Dist(E, i, width - 1, T, D, alpha, F);
+}
+#endif // FAST
+
+
+
+#if SLOW
+// -------------------------------------------------------------------------------------------------------------------------------------------
+static void borderMerging_Slow_Rosenfeld_Dist(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
+// -------------------------------------------------------------------------------------------------------------------------------------------
+{
+    int j = 0;
     
     uint32 eps;
@@ -577,170 +776,11 @@
     // -- prologue --
     // --------------
-    MCA_VERBOSE2(printf("[%s] i = %d\n", __func__, i));
-    
-    j = 0;
+    MCA_VERBOSE3(printf("[%s] i = %d\n", __func__, i));
+    
     ex = E[i][j];
     
     if (ex) {
         
-        MCA_VERBOSE2(printf("[%s] j = %d\n", __func__, j));
-        
-        e2 = E[i - 1][j];
-        e3 = E[i - 1][j + 1];
-
-        // test pour eviter acces distant
-        r2 = e2 ? FindRoot_Dist(D, e2, alpha) : 0;
-        r3 = e3 ? FindRoot_Dist(D, e3, alpha) : 0;
-
-        rx = T[ex];
-        rx = FindRoot_Dist(D, rx, alpha);
- 
-        MCA_VERBOSE2(printf("\n"));
-        MCA_VERBOSE2(printf("e2 = %4d -> %4d\n", e2, r2));
-        MCA_VERBOSE2(printf("e3 = %4d -> %4d\n", e3, r3));
-        MCA_VERBOSE2(printf("ex = %4d -> %4d\n", ex, rx));
-        
-        eps = ui32MinNonNul3(r2, r3, rx);
-        
-        // Quick-Union
-        if (r2 > eps) {
-            SetRoot_Rosenfeld_Dist(D, r2, eps, alpha);
-            MCA_VERBOSE2(printf("D[%4d] <- %d\n", r2, eps));
-        }
-        if (r3 > eps) {
-            SetRoot_Rosenfeld_Dist(D, r3, eps, alpha);
-            MCA_VERBOSE2(printf("D[%4d] <- %d\n", r3, eps));
-        }
-        if (rx > eps) {
-            SetRoot_Rosenfeld_Dist(D, rx, eps, alpha);
-            MCA_VERBOSE2(printf("D[%4d] <- %d\n", rx, eps));
-        }
-        MCA_VERBOSE2(printf("\n"));
-    }
-    
-    // -----------------------
-    // -- boucle principale --
-    // -----------------------
-    
-    for (j = 0 + 1; j < width - 1; j++) {
-    
-        ex = E[i][j];
-        
-        // que le cas general (pour faire un code simple)
-        if (ex) {
-            MCA_VERBOSE2(printf("[%s] j = %d\n", __func__, j));
-            
-            e1 = E[i - 1][j - 1];
-            e2 = E[i - 1][j];
-            e3 = E[i - 1][j + 1];
-        
-            // test pour eviter acces distant
-            r1 = e1 ? FindRoot_Dist(D, e1, alpha) : 0;
-            r2 = e2 ? FindRoot_Dist(D, e2, alpha) : 0;
-            r3 = e3 ? FindRoot_Dist(D, e3, alpha) : 0;
-
-            rx = T[ex];
-            rx = FindRoot_Dist(D, rx, alpha);
-
-            MCA_VERBOSE2(printf("\n"));
-            MCA_VERBOSE2(printf("e1 = %4d -> %4d\n", e1, r1));
-            MCA_VERBOSE2(printf("e2 = %4d -> %4d\n", e2, r2));
-            MCA_VERBOSE2(printf("e3 = %4d -> %4d\n", e3, r3));
-            MCA_VERBOSE2(printf("ex = %4d -> %4d\n", ex, rx));
-            
-            eps = ui32MinNonNul4(r1, r2, r3, rx);
-            
-            // Quick-Union
-            if (r1 > eps) {
-                SetRoot_Rosenfeld_Dist(D, r1, eps, alpha);
-                MCA_VERBOSE2(printf("D[%4d] <- %d\n", r1, eps));
-            }
-            if (r2 > eps) {
-                SetRoot_Rosenfeld_Dist(D, r2, eps, alpha);
-                MCA_VERBOSE2(printf("D[%4d] <- %d\n", r2, eps));
-            }
-            if (r3 > eps) {
-                SetRoot_Rosenfeld_Dist(D, r3, eps, alpha);
-                MCA_VERBOSE2(printf("D[%4d] <- %d\n", r3, eps));
-            }
-            if (rx > eps) {
-                SetRoot_Rosenfeld_Dist(D, rx, eps, alpha);
-                MCA_VERBOSE2(printf("D[%4d] <- %d\n", rx, eps));
-            }
-            MCA_VERBOSE2(printf("\n"));
-            // attention SetRoot fait un while inutile
-        }
-    }
-    
-    // --------------
-    // -- epilogue --
-    // --------------
-    
-    j = width - 1;
-    ex = E[i][j];
-    
-    if (ex) {
-        
-        MCA_VERBOSE2(printf("[%s] j = %d\n", __func__, j));
-        
-        e1 = E[i - 1][j - 1];
-        e2 = E[i - 1][j];
-
-        // test pour eviter acces distant
-        r1 = e1 ? FindRoot_Dist(D, e1, alpha) : 0;
-        r2 = e2 ? FindRoot_Dist(D, e2, alpha) : 0;
-
-        rx = T[ex];
-        rx = FindRoot_Dist(D, rx, alpha);
-
-        MCA_VERBOSE2(printf("\n"));
-        MCA_VERBOSE2(printf("e1 = %4d -> %4d\n", e1, r1));
-        MCA_VERBOSE2(printf("e2 = %4d -> %4d\n", e2, r2));
-        MCA_VERBOSE2(printf("ex = %4d -> %4d\n", ex, rx));
-        
-        eps = ui32MinNonNul3(r1, r2, rx);
-        
-        // Quick-Union
-        if (r1 > eps) {
-            SetRoot_Rosenfeld_Dist(D, r1, eps, alpha);
-            MCA_VERBOSE2(printf("D[%4d] <- %d\n", r1, eps));
-        }
-        if (r2 > eps) {
-            SetRoot_Rosenfeld_Dist(D, r2, eps, alpha);
-            MCA_VERBOSE2(printf("D[%4d] <- %d\n", r2, eps));
-        }
-        if (rx > eps) {
-            SetRoot_Rosenfeld_Dist(D, rx, eps, alpha);
-            MCA_VERBOSE2(printf("D[%4d] <- %d\n", rx, eps));
-        }
-        MCA_VERBOSE2(printf("\n"));
-    }
-    return;
-}
-#endif // SLOW && !FEATURES
-
-
-#if SLOW && FEATURES
-// ----------------------------------------------------------------------------------------------------------------------------------------------------
-static void borderMerging_Slow_Features_Rosenfeld_Dist(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
-// ----------------------------------------------------------------------------------------------------------------------------------------------------
-{
-    int j = 0;
-    
-    uint32 eps;
-    
-    uint32 e1, e2, e3, ex;
-    uint32 r1, r2, r3, rx;
-    
-    // --------------
-    // -- prologue --
-    // --------------
-    MCA_VERBOSE2(printf("[%s] i = %d\n", __func__, i));
-    
-    ex = E[i][j];
-    
-    if (ex) {
-        
-        MCA_VERBOSE2(printf("[%s] j = %d\n", __func__, j));
+        MCA_VERBOSE3(printf("[%s] j = %d\n", __func__, j));
         
         e2 = E[i - 1][j];
@@ -758,32 +798,31 @@
             eps = ui32MinNonNul3(r2, r3, rx);
             
-            MCA_VERBOSE2(printf("\n"));
-            MCA_VERBOSE2(printf("e2  = %5d -> r2 = %5d\n", e2, r2));
-            MCA_VERBOSE2(printf("e3  = %5d -> r3 = %5d\n", e3, r3));
-            MCA_VERBOSE2(printf("ex  = %5d -> rx = %5d\n", ex, rx));
-            MCA_VERBOSE2(printf("eps = %5d\n", eps));
+            MCA_VERBOSE3(printf("\n"));
+            MCA_VERBOSE3(printf("e2  = %5d -> r2 = %5d\n", e2, r2));
+            MCA_VERBOSE3(printf("e3  = %5d -> r3 = %5d\n", e3, r3));
+            MCA_VERBOSE3(printf("ex  = %5d -> rx = %5d\n", ex, rx));
+            MCA_VERBOSE3(printf("eps = %5d\n", eps));
             
             // Quick-Union
-            // @QM
             if (r2 > eps) {
-                SetRoot_Features_Rosenfeld_Dist(D, r2, eps, alpha, F);
-                MCA_VERBOSE2(printf("D[%5d] <- %d\n", r2, eps));
-            }
-            if (r3 > 0) {
-                r3 = FindRoot_Dist(D, r3, alpha);
+                SetRoot_Rosenfeld(D, r2, eps, alpha, F);
+                MCA_VERBOSE3(printf("D[%5d] <- %d\n", r2, eps));
             }
             // Pour le cas oÃ¹ r2 == r3, il ne faut pas ajouter deux fois les features
-            //if (r3 > eps && r3 != r2) {
-            if (r3 > eps) {
-                SetRoot_Features_Rosenfeld_Dist(D, r3, eps, alpha, F);
-                MCA_VERBOSE2(printf("D[%5d] <- %d\n", r3, eps));
-            }
-            rx = FindRoot_Dist(D, rx, alpha);
-            //if (rx > eps && rx != r3 && rx != r2) {
-            if (rx > eps) {
-                SetRoot_Features_Rosenfeld_Dist(D, rx, eps, alpha, F);
-                MCA_VERBOSE2(printf("D[%5d] <- %d\n", rx, eps));
-            }
-            MCA_VERBOSE2(printf("---------------------------\n"));
+            //if (r3 > 0) {
+            //    r3 = FindRoot_Dist(D, r3, alpha);
+            //}
+            //if (r3 > eps) {
+            if (r3 > eps && r3 != r2) {
+                SetRoot_Rosenfeld(D, r3, eps, alpha, F);
+                MCA_VERBOSE3(printf("D[%5d] <- %d\n", r3, eps));
+            }
+            //rx = FindRoot_Dist(D, rx, alpha);
+            //if (rx > eps) {
+            if (rx > eps && rx != r3 && rx != r2) {
+                SetRoot_Rosenfeld(D, rx, eps, alpha, F);
+                MCA_VERBOSE3(printf("D[%5d] <- %d\n", rx, eps));
+            }
+            MCA_VERBOSE3(printf("---------------------------\n"));
         }
     }
@@ -799,5 +838,5 @@
         if (ex) {
             
-            MCA_VERBOSE2(printf("[%s] j = %d\n", __func__, j));
+            MCA_VERBOSE3(printf("[%s] j = %d\n", __func__, j));
             
             e1 = E[i - 1][j - 1];
@@ -816,42 +855,40 @@
                 eps = ui32MinNonNul4(r1, r2, r3, rx);
 
-                MCA_VERBOSE2(printf("\n"));
-                MCA_VERBOSE2(printf("e1  = %5d -> r1 = %5d\n", e1, r1));
-                MCA_VERBOSE2(printf("e2  = %5d -> r2 = %5d\n", e2, r2));
-                MCA_VERBOSE2(printf("e3  = %5d -> r3 = %5d\n", e3, r3));
-                MCA_VERBOSE2(printf("ex  = %5d -> rx = %5d\n", ex, rx));
-                MCA_VERBOSE2(printf("eps = %5d\n", eps));
+                MCA_VERBOSE3(printf("\n"));
+                MCA_VERBOSE3(printf("e1  = %5d -> r1 = %5d\n", e1, r1));
+                MCA_VERBOSE3(printf("e2  = %5d -> r2 = %5d\n", e2, r2));
+                MCA_VERBOSE3(printf("e3  = %5d -> r3 = %5d\n", e3, r3));
+                MCA_VERBOSE3(printf("ex  = %5d -> rx = %5d\n", ex, rx));
+                MCA_VERBOSE3(printf("eps = %5d\n", eps));
+                
                 
                 // Quick-Union
-                // @QM
                 if (r1 > eps) {
-                    SetRoot_Features_Rosenfeld_Dist(D, r1, eps, alpha, F);
-                    MCA_VERBOSE2(printf("D[%5d] <- %d\n", r1, eps));
+                    SetRoot_Rosenfeld(D, r1, eps, alpha, F);
+                    MCA_VERBOSE3(printf("D[%5d] <- %d\n", r1, eps));
                 }
-                if (r2 > 0) {
-                    r2 = FindRoot_Dist(D, r2, alpha);
+                //if (r2 > 0) {
+                //    r2 = FindRoot_Dist(D, r2, alpha);
+                //}
+                if (r2 > eps && r2 != r1) {
+                //if (r2 > eps) {
+                    SetRoot_Rosenfeld(D, r2, eps, alpha, F);
+                    MCA_VERBOSE3(printf("D[%5d] <- %d\n", r2, eps));
                 }
-                //if (r2 > eps && r2 != r1) {
-                if (r2 > eps) {
-                    SetRoot_Features_Rosenfeld_Dist(D, r2, eps, alpha, F);
-                    MCA_VERBOSE2(printf("D[%5d] <- %d\n", r2, eps));
+                //if (r3 > 0) {
+                //    r3 = FindRoot_Dist(D, r3, alpha);
+                //}
+                if (r3 > eps && r3 != r2 && r3 != r1) {
+                //if (r3 > eps) {
+                    SetRoot_Rosenfeld(D, r3, eps, alpha, F);
+                    MCA_VERBOSE3(printf("D[%5d] <- %d\n", r3, eps));
                 }
-                if (r3 > 0) {
-                    r3 = FindRoot_Dist(D, r3, alpha);
+                //rx = FindRoot_Dist(D, rx, alpha);
+                if (rx > eps && rx != r3 && rx != r2 && rx != r1) {
+                //if (rx > eps) {
+                    SetRoot_Rosenfeld(D, rx, eps, alpha, F);
+                    MCA_VERBOSE3(printf("D[%5d] <- %d\n", rx, eps));
                 }
-                //if (r3 > eps && r3 != r2 && r3 != r1) {
-                if (r3 > eps) {
-                    SetRoot_Features_Rosenfeld_Dist(D, r3, eps, alpha, F);
-                    MCA_VERBOSE2(printf("D[%5d] <- %d\n", r3, eps));
-                }
-                rx = FindRoot_Dist(D, rx, alpha);
-                //if (rx > eps && rx != r3 && rx != r2 && rx != r1) {
-                if (rx > eps) {
-                    SetRoot_Features_Rosenfeld_Dist(D, rx, eps, alpha, F);
-                    MCA_VERBOSE2(printf("D[%5d] <- %d\n", rx, eps));
-                }
-                MCA_VERBOSE2(puts("---------------------------\n"));
-                
-                // attention SetRoot fait un while inutile
+                MCA_VERBOSE3(puts("---------------------------\n"));
             }
         }
@@ -867,5 +904,5 @@
     if (ex) {
         
-        MCA_VERBOSE2(printf("[%s] j = %d\n", __func__, j));
+        MCA_VERBOSE3(printf("[%s] j = %d\n", __func__, j));
         
         e1 = E[i - 1][j - 1];
@@ -883,271 +920,48 @@
             eps = ui32MinNonNul3(r1, r2, rx);
             
-            MCA_VERBOSE2(printf("\n"));
-            MCA_VERBOSE2(printf("e1  = %5d -> r1 = %5d\n", e1, r1));
-            MCA_VERBOSE2(printf("e2  = %5d -> r2 = %5d\n", e2, r2));
-            MCA_VERBOSE2(printf("ex  = %5d -> rx = %5d\n", ex, rx));
-            MCA_VERBOSE2(printf("eps = %5d\n", eps));
+            MCA_VERBOSE3(printf("\n"));
+            MCA_VERBOSE3(printf("e1  = %5d -> r1 = %5d\n", e1, r1));
+            MCA_VERBOSE3(printf("e2  = %5d -> r2 = %5d\n", e2, r2));
+            MCA_VERBOSE3(printf("ex  = %5d -> rx = %5d\n", ex, rx));
+            MCA_VERBOSE3(printf("eps = %5d\n", eps));
             
             // Quick-Union
             if (r1 > eps) {
-                SetRoot_Features_Rosenfeld_Dist(D, r1, eps, alpha, F);
-                MCA_VERBOSE2(printf("D[%5d] <- %d\n", r1, eps));
-            }
-            if (r2 > 0) {
-                r2 = FindRoot_Dist(D, r2, alpha);
-            }
-            //if (r2 > eps && r2 != r1) {
-            if (r2 > eps) {
-                SetRoot_Features_Rosenfeld_Dist(D, r2, eps, alpha, F);
-                MCA_VERBOSE2(printf("D[%5d] <- %d\n", r2, eps));
-            }
-            rx = FindRoot_Dist(D, rx, alpha);
-            //if (rx > eps && rx != r2 && rx != r1) {
-            if (rx > eps) {
-                SetRoot_Features_Rosenfeld_Dist(D, rx, eps, alpha, F);
-                MCA_VERBOSE2(printf("D[%5d] <- %d\n", rx, eps));
-            }
-            MCA_VERBOSE2(printf("---------------------------\n"));
-        }
-    }
-    return;
-}
-#endif // SLOW && FEATURES
-
-
-#if FAST && FEATURES && !PARMERGE
-// --------------------------------------------------------------------------------------------------------------------------
-void optimizedBorder_Features_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
-// --------------------------------------------------------------------------------------------------------------------------
-{
-    // copie de optimizedBorder_Rosenfeld
-    uint32 a, b, c, x;
-    
-    x = E[i][j];
-    
-    if (x) {
-        b = E[i - 1][j];
-        if (b) {
-            vuse2_Features_Rosenfeld_Dist(b, x, T, D, alpha, F); // dist, local
-        }
-        else {
-            c = E[i - 1][j + 1];
-            if (c) {
-                a = E[i - 1][j - 1];
-                if (a) {
-                    vuse3_Features_Rosenfeld_Dist(a, c, x, T, D, alpha, F); // dist, local
-                }
-                else {
-                    vuse2_Features_Rosenfeld_Dist(c, x, T, D, alpha, F); // dist, local
-                }
-            }
-            else {
-                a = E[i - 1][j - 1];
-                if (a) {
-                    vuse2_Features_Rosenfeld_Dist(a, x, T, D, alpha, F); // dist, local
-                }
-            }
-        }
-    }
-}
-#endif // FAST && FEATURES && !PARMERGE
-
-
-#if FAST && FEATURES && !PARMERGE
-// ------------------------------------------------------------------------------------------------------------------------------
-void optimizedBorderLeft_Features_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
-// ------------------------------------------------------------------------------------------------------------------------------
-{
-    uint32 x = E[i][j];
-    
-    if (x) {
-        uint32 b = E[i - 1][j];
-        if (b) {
-            vuse2_Features_Rosenfeld_Dist(b, x, T, D, alpha, F); // dist, local
-        }
-        else {
-            uint32 c = E[i - 1][j + 1];
-            if (c) {
-                vuse2_Features_Rosenfeld_Dist(c, x, T, D, alpha, F); // dist, local
-            }
-        }
-    }
-}
-#endif // FAST && FEATURES && !PARMERGE
-
-
-#if FAST && FEATURES && !PARMERGE
-// -------------------------------------------------------------------------------------------------------------------------------
-void optimizedBorderRight_Features_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
-// -------------------------------------------------------------------------------------------------------------------------------
-{
-    // copie de optimizedBorder_Rosenfeld
-    // test d'existance de ex en local local
-    
-    uint32 x = E[i][j];
-    
-    if (x) {
-        uint32 b = E[i - 1][j];
-        if (b) {
-            vuse2_Features_Rosenfeld_Dist(b, x, T, D, alpha, F); // dist, local
-        }
-        else {
-            uint32 a = E[i - 1][j - 1];
-            if (a) {
-                vuse2_Features_Rosenfeld_Dist(a, x, T, D, alpha, F); // dist, local
-            }
-        }
-    }
-}
-#endif // FAST && FEATURES && !PARMERGE
-
-
-#if FAST && FEATURES && PARMERGE
-// -----------------------------------------------------------------------------------------------------------------------------------
-void optimizedBorder_Parallel_Features_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
-// -----------------------------------------------------------------------------------------------------------------------------------
-{
-    // copie de optimizedBorder_Rosenfeld
-    uint32 a, b, c, x;
-    
-    x = E[i][j];
-    
-    if (x) {
-        b = E[i - 1][j];
-        if (b) {
-            vuse2_Parallel_Features_Rosenfeld_Dist(b, x, T, D, alpha, F); // dist, local
-        }
-        else {
-            c = E[i - 1][j + 1];
-            if (c) {
-                a = E[i - 1][j - 1];
-                if (a) {
-                    vuse3_Parallel_Features_Rosenfeld_Dist(a, c, x, T, D, alpha, F); // dist, local
-                }
-                else {
-                    vuse2_Parallel_Features_Rosenfeld_Dist(c, x, T, D, alpha, F); // dist, local
-                }
-            }
-            else {
-                a = E[i - 1][j - 1];
-                if (a) {
-                    vuse2_Parallel_Features_Rosenfeld_Dist(a, x, T, D, alpha, F); // dist, local
-                }
-            }
-        }
-    }
-}
-#endif // FAST && FEATURES && PARMERGE
-
-
-#if FAST && FEATURES && PARMERGE
-// ---------------------------------------------------------------------------------------------------------------------------------------
-void optimizedBorderLeft_Parallel_Features_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
-// ---------------------------------------------------------------------------------------------------------------------------------------
-{
-    uint32 x = E[i][j];
-    
-    if (x) {
-        uint32 b = E[i - 1][j];
-        if (b) {
-            vuse2_Parallel_Features_Rosenfeld_Dist(b, x, T, D, alpha, F); // dist, local
-        }
-        else {
-            uint32 c = E[i - 1][j + 1];
-            if (c) {
-                vuse2_Parallel_Features_Rosenfeld_Dist(c, x, T, D, alpha, F); // dist, local
-            }
-        }
-    }
-}
-#endif // FAST && FEATURES && PARMERGE
-
-
-#if FAST && FEATURES && PARMERGE
-// ----------------------------------------------------------------------------------------------------------------------------------------
-void optimizedBorderRight_Parallel_Features_Rosenfeld_Dist(uint32 ** E, int i, int j, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
-// ----------------------------------------------------------------------------------------------------------------------------------------
-{
-    // copie de optimizedBorder_Rosenfeld
-    // test d'existance de ex en local local
-    
-    uint32 x = E[i][j];
-    
-    if (x) {
-        uint32 b = E[i - 1][j];
-        if (b) {
-            vuse2_Parallel_Features_Rosenfeld_Dist(b, x, T, D, alpha, F); // dist, local
-        }
-        else {
-            uint32 a = E[i - 1][j - 1];
-            if (a) {
-                vuse2_Parallel_Features_Rosenfeld_Dist(a, x, T, D, alpha, F); // dist, local
-            }
-        }
-    }
-}
-#endif // FAST && FEATURES && PARMERGE
-
-
-#if FAST && FEATURES
-// ---------------------------------------------------------------------------------------------------------------------------------------------
-void borderMerging_Fast_Features_Rosenfeld_Dist(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
-// ---------------------------------------------------------------------------------------------------------------------------------------------
-{
-    MCA_VERBOSE2(printf("[%s]", __func__));
-    
-#if PARMERGE
-    optimizedBorderLeft_Parallel_Features_Rosenfeld_Dist(E, i, 0, T, D, alpha, F);
-#else
-    optimizedBorderLeft_Features_Rosenfeld_Dist(E, i, 0, T, D, alpha, F);
-#endif
-    
-    for (int j = 1; j < width - 1; j++) {
-#if PARMERGE
-        optimizedBorder_Parallel_Features_Rosenfeld_Dist(E, i, j, T, D, alpha, F);
-#else
-        optimizedBorder_Features_Rosenfeld_Dist(E, i, j, T, D, alpha, F);
-#endif
-    }
-    
-#if PARMERGE
-    optimizedBorderRight_Parallel_Features_Rosenfeld_Dist(E, i, width - 1, T, D, alpha, F);
-#else
-    optimizedBorderRight_Features_Rosenfeld_Dist(E, i, width - 1, T, D, alpha, F);
-#endif
-}
-#endif // FAST && FEATURES
-
-
-#if !FEATURES
-// --------------------------------------------------------------------------------------------------------------------
-static void borderMerging_Rosenfeld_Dist(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ** D, int alpha)
-// --------------------------------------------------------------------------------------------------------------------
-{
+                SetRoot_Rosenfeld(D, r1, eps, alpha, F);
+                MCA_VERBOSE3(printf("D[%5d] <- %d\n", r1, eps));
+            }
+            //if (r2 > 0) {
+            //    r2 = FindRoot_Dist(D, r2, alpha);
+            //}
+            if (r2 > eps && r2 != r1) {
+            //if (r2 > eps) {
+                SetRoot_Rosenfeld(D, r2, eps, alpha, F);
+                MCA_VERBOSE3(printf("D[%5d] <- %d\n", r2, eps));
+            }
+            //rx = FindRoot_Dist(D, rx, alpha);
+            if (rx > eps && rx != r2 && rx != r1) {
+            //if (rx > eps) {
+                SetRoot_Rosenfeld(D, rx, eps, alpha, F);
+                MCA_VERBOSE3(printf("D[%5d] <- %d\n", rx, eps));
+            }
+            MCA_VERBOSE3(printf("---------------------------\n"));
+        }
+    }
+}
+#endif // SLOW
+
+
+
+// --------------------------------------------------------------------------------------------------------------------------------------
+static void borderMerging_Rosenfeld_Dist(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
+// --------------------------------------------------------------------------------------------------------------------------------------
+{
+#if FAST
+    borderMerging_Fast_Rosenfeld_Dist(X, i, width, E, T, D, alpha, F);
+#endif // FAST
 #if SLOW
-    borderMerging_Slow_Rosenfeld_Dist(X, i, width, E, T, D, alpha);
-#elif FAST
-    borderMerging_Fast_Rosenfeld_Dist(X, i, width, E, T, D, alpha);
-#else
-#error "Please define SLOW or FAST for the Rosenfeld version"
-#endif
-}
-#endif // !FEATURES
-
-
-#if FEATURES
-// -----------------------------------------------------------------------------------------------------------------------------------------------
-static void borderMerging_Features_Rosenfeld_Dist(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ** D, int alpha, RegionStats ** F)
-// -----------------------------------------------------------------------------------------------------------------------------------------------
-{
-#if SLOW
-    borderMerging_Slow_Features_Rosenfeld_Dist(X, i, width, E, T, D, alpha, F);
-#elif FAST
-    borderMerging_Fast_Features_Rosenfeld_Dist(X, i, width, E, T, D, alpha, F);
-#else
-#error "Please define SLOW or FAST for the Rosenfeld version"
-#endif
-}
-#endif // FEATURES
+    borderMerging_Slow_Rosenfeld_Dist(X, i, width, E, T, D, alpha, F);
+#endif // SLOW
+}
 
 
@@ -1383,8 +1197,7 @@
     return ne;
 }
-#endif // FAST
-
-
-#if FAST
+
+// FAST
+
 // ----------------------------------------------------------------------------------------------
 static uint32 optimizedAccessRight_DT_Rosenfeld(uint32 ** E, int i, int j, uint32 * T, uint32 ne)
@@ -1416,8 +1229,7 @@
     return ne;
 }
-#endif // FAST
-
-
-#if FAST
+
+// FAST
+
 // -----------------------------------------------------------------------------------------
 static uint32 optimizedAccess_DT_Rosenfeld(uint32 ** E, int i, int j, uint32 * T, uint32 ne)
@@ -1467,9 +1279,7 @@
     return ne;
 }
-#endif // FAST
-
-
-
-#if FAST
+
+// FAST
+
 // --------------------------------------------------------------------------------------------------------
 static uint32 lineLabeling_Fast_Rosenfeld(uint8 ** X, int i, int width, uint32 ** E, uint32 * T, uint32 ne)
@@ -1517,6 +1327,4 @@
 #elif FAST
     return lineLabeling_Fast_Rosenfeld(X, i, width, E, T, ne);
-#else
-#error "Please define SLOW or FAST for the Rosenfeld version"
 #endif
 }
@@ -1539,25 +1347,7 @@
 
 
-#if !FEATURES
-// ---------------------------------------------------------------------
-static void solveTable_Range_Rosenfeld(uint32 * T, uint32 e0, uint32 e1)
-// ---------------------------------------------------------------------
-{
-    uint32 e, r;
-    
-    for (e = e0; e <= e1; e++) {
-        r = T[T[e]];
-        if (r < e) {
-            T[e] = r; // racine de la classe d'equivalence
-        }
-    }
-}
-#endif // !FEATURES
-
-
-#if FEATURES
-// ----------------------------------------------------------------------------------------------------------
-static void solveTable_solveFeatures_Range_Rosenfeld(uint32 * T, uint32 e0, uint32 e1, RegionStats * Stats)
-// ----------------------------------------------------------------------------------------------------------
+// ------------------------------------------------------------------------------------------
+static void solveTable_Range_Rosenfeld(uint32 * T, uint32 e0, uint32 e1, RegionStats * Stats)
+// ------------------------------------------------------------------------------------------
 {
     uint32 e, r;
@@ -1568,25 +1358,25 @@
         if (r < e) {
             T[e] = r; // racine de la classe d'equivalence
+#if FEATURES
             RegionStats_Accumulate_Stats1_From_Index(Stats, r, e);
-        }
-    }
-}
-#endif // FEATURES
-
-
-#if !FEATURES
-// -------------------------------------
-void MCA_Label_Rosenfeld_PAR1(MCA * mca)
-// -------------------------------------
+#endif
+        }
+    }
+}
+
+
+// --------------------------------------------
+static void MCA_Label_Rosenfeld_PAR1(MCA * mca)
+// --------------------------------------------
 {
     if (mca->p == 0) { 
-        printf("*** %s ***\n", __func__);
-    }
-    
-    CLOCK_THREAD_START_STEP(mca->p, 0);
+        MCA_VERBOSE2(printf("*** %s ***\n", __func__));
+    }
+    
 
     int i0 = mca->i0;
     int i1 = mca->i1;
-    int width = mca->width; 
+    int width = mca->width;
+
     uint32 e0 = mca->e0;
     uint32 e1 = mca->e1;
@@ -1598,54 +1388,79 @@
     uint32 ** E = mca->E;
     uint32 *  T = mca->T;
-
+    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
+#if FEATURES
+        zero_RegionStatsVector(stats, e0 - 1, e1);
+#endif
     }
     else {
         set_ui32vector_j(T, e0, e1);
-    }
-
-    MCA_VERBOSE2(display_ui8matrix_positive(X, i0, i1, 0, width - 1, 5, "Xp"); printf("\n"));
+#if FEATURES
+        zero_RegionStatsVector(stats, e0, e1);
+#endif
+    }
+
+    if (mca->p == 0) {
+        MCA_VERBOSE3(display_ui8matrix_positive(X, i0, i1, 0, width - 1, 5, "Xp"); printf("\n"));
+    }
+
+    // ---------------------------- //
+    // -- Etiquetage d'une bande -- //
+    // ---------------------------- //
+
+    CLOCK_THREAD_START_STEP(mca->p, 0);
 
     ne = line0Labeling_Rosenfeld(X, i0, width, E, T, ne);
+#if FEATURES
+    lineFeaturesComputation(E, i0, width, stats);
+#endif
+
     for (int i = i0 + 1; i <= i1; i++) {
-        ne = lineLabeling_Rosenfeld(X, i, width, E, T, ne);
-    }
-
-    MCA_VERBOSE2(display_ui32matrix_positive(E, i0, i1, 0, width - 1, 5, "Ep"); printf("\n"));
+        ne = lineLabeling_Rosenfeld(X, i, width, E, T, ne); // Slow or Fast
+#if FEATURES
+        lineFeaturesComputation(E, i, width, stats);
+#endif
+    }
+    mca->ne = ne; //plus grande etiquette de l'intervalle [e0..e1]
+
     if (mca->p == 0) {
-        MCA_VERBOSE2(display_ui32vector_number(T, e0, ne, "%5d", "Tp_avant"));
-    }
-
-    // fermeture transitive sans pack
-    solveTable_Range_Rosenfeld(T, e0, ne);
-    mca->ne = ne; // Plus grande etiquette de l'intervalle [e0..e1]
-
-    MCA_VERBOSE2(nr = countTable_Range_Rosenfeld(T, e0, ne));
-    MCA_VERBOSE2(printf("p = %d : e = [%d..%d] -> ne = %d -> nr = %d\n", mca->p, e0, ne, (ne - e0 + 1), nr));
+        MCA_VERBOSE3(printf("ne = %d\n", ne));
+        MCA_VERBOSE3(display_ui32matrix_positive(E, i0, i1, 0, width - 1, 5, "Ep"); printf("\n"));
+        MCA_VERBOSE3(display_ui32vector_number(T, e0, ne, "%5d", "Tp_avant"));
+    }
+
+    // ------------------------------------------------------ //
+    // -- Fermeture transitive sans pack de chaque table T -- //
+    // ------------------------------------------------------ //
+
+    solveTable_Range_Rosenfeld(T, e0, ne, stats);
+
     if (mca->p == 0) {
-        MCA_VERBOSE2(display_ui32vector_number(T, e0, ne, "%5d", "Tp_apres"));
-    }
-    
+        MCA_VERBOSE3(nr = countTable_Range_Rosenfeld(T, e0, ne);
+                     printf("p = %d : e = [%d..%d] -> ne = %d -> nr = %d\n", mca->p, e0, ne, (ne - e0 + 1), nr));
+        MCA_VERBOSE3(display_ui32vector_number(T, e0, ne, "%5d", "Tp_apres"));
+    }
     CLOCK_THREAD_END_STEP(mca->p, 0);
 }
-#endif // !FEATURES
-
-
-#if !FEATURES
-// -------------------------------------
-void MCA_Label_Rosenfeld_PYR2(MCA * mca)
-// -------------------------------------
-{
-    // input
+
+
+
+#if PARMERGE
+// -----------------------------------------------------
+static void MCA_Label_Rosenfeld_PAR2(MCA * mca)
+// -----------------------------------------------------
+{
     int p = mca->p;
     int nb_level = mca->nb_level;
 
     if (mca->p == 0) {
-        printf("*** %s ***\n", __func__);
+        MCA_VERBOSE2(printf("*** %s ***\n", __func__));
     }
     
     // ------------------------------
-    // -- pyramidal border merging --
+    // -- parallel border merging --
     // ------------------------------
     
@@ -1662,300 +1477,9 @@
     uint32 *  T = mca->T;
     uint32 ** D = mca->D;
-
-    CLOCK_THREAD_START_STEP(p, 1);
-#if PYR_BARRIERS
-    // Version optimisÃ©e qui fait faire un break aux processeurs qui n'ont plus
-    // Ã  faire de merge.
-    // Implique de prÃ©-calculer le nombre de threads Ã  chaque barriÃšre
-    if (p != 0) { // thread 0 never has any merge to do
-        int been_active = 0;
-        for (int level = 0; level < nb_level; level++) {
-            if ((p + (1 << level)) % (1 << (level + 1)) == 0) {
-                borderMerging_Rosenfeld_Dist(X, i, width, E, T, D, alpha);  // en (i) et (i-1)
-                been_active = 1;
-            }
-            else if (been_active) {
-                break;
-            }
-            pthread_barrier_wait(&mca->barriers[level]);
-        }
-    }
-    pthread_barrier_wait(&main_barrier);
-#else
-    for (int level = 1; level <= nb_level; level++) {
-        if ((p + (1 << (level - 1))) % (1 << level) == 0) {
-            // thread actif
-            borderMerging_Rosenfeld_Dist(X, i, width, E, T, D, alpha);  // en (i) et (i-1)
-        }
-        pthread_barrier_wait(&main_barrier);
-    }
-#endif
-    CLOCK_THREAD_END_STEP(p, 1);
-    
-
-    // ---------------------------------
-    // -- parallel transitive closure --
-    // ---------------------------------
-    
-    CLOCK_THREAD_START_STEP(p, 2);
-    for (uint32 e = e0; e <= e1; e++) {
-        uint32 r = T[e]; // acces local
-        if (r < e) {
-            r = FindRoot_Dist(D, e, alpha); // acces distant
-            T[e] = r; // @QM Ã©tait en dehors du "if" (je pense que dÃ©jÃ  demandÃ©)
-        }
-        MCA_VERBOSE2(printf("p%d : T[%d] <- %d\n", p, e, r));
-    }
-    CLOCK_THREAD_END_STEP(p, 2);
-}
-#endif // !FEATURES
-
-
-// -------------------------------------
-void MCA_Label_Rosenfeld_PAR3(MCA * mca)
-// -------------------------------------
-{
-    // input
-    if (mca->p == 0) {
-        printf("*** %s ***\n", __func__);
-    }
-    
-    int i0 = mca->i0;
-    int i1 = mca->i1;
-    int j0 = 0;
-    int j1 = mca->width - 1;
-
-    uint32 ** E = mca->E;
-    uint32 * T = mca->T;
-
-    CLOCK_THREAD_START_STEP(mca->p, 3);
-    for (int i = i0; i <= i1; i++) {
-        for (int j = j0; j <= j1; j++) {
-            uint32 e = E[i][j];
-            if (e != 0) {
-                E[i][j] = T[e];
-            }
-        }
-    }
-    CLOCK_THREAD_END_STEP(mca->p, 3);
-}
-
-
-#if FEATURES
-// -----------------------------------------------------
-static void MCA_Label_Features_Rosenfeld_PAR1(MCA * mca)
-// -----------------------------------------------------
-{
-    if (mca->p == 0) { 
-        printf("*** %s ***\n", __func__);
-    }
-    
-    CLOCK_THREAD_START_STEP(mca->p, 0);
-
-    int i0 = mca->i0;
-    int i1 = mca->i1;
-    int width = mca->width;
-
-    uint32 e0 = mca->e0;
-    uint32 e1 = mca->e1;
-    uint32 ne = e0 - 1;
-    uint32 nr = 0;
-
-    // local memory zones
-    uint8 **  X = mca->X;
-    uint32 ** E = mca->E;
-    uint32 *  T = mca->T;
-
-    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
-        zero_RegionStatsVector(stats, e0 - 1, e1);
-    }
-    else {
-        set_ui32vector_j(T, e0, e1);
-        zero_RegionStatsVector(stats, e0, e1);
-    }
-
-    if (mca->p == 0) {
-        MCA_DISPLAY2(display_ui8matrix_positive(X, i0, i1, 0, width - 1, 5, "Xp"); printf("\n"));
-    }
-
-    // ---------------------------- //
-    // -- Etiquetage d'une bande -- //
-    // ---------------------------- //
-
-    ne = line0Labeling_Rosenfeld(X, i0, width, E, T, ne);
-    lineFeaturesComputation(E, i0, width, stats);
-
-    for (int i = i0 + 1; i <= i1; i++) {
-        ne = lineLabeling_Rosenfeld(X, i, width, E, T, ne); // Slow or Fast
-        lineFeaturesComputation(E, i, width, stats);
-    }
-    mca->ne = ne; //plus grande etiquette de l'intervalle [e0..e1]
-
-    if (mca->p == 0) {
-        MCA_VERBOSE2(printf("ne = %d\n", ne));
-        MCA_DISPLAY2(display_ui32matrix_positive(E, i0, i1, 0, width - 1, 5, "Ep"); printf("\n"));
-        MCA_DISPLAY2(display_ui32vector_number(T, e0, ne, "%5d", "Tp_avant"));
-    }
-
-    // ------------------------------------------------------ //
-    // -- Fermeture transitive sans pack de chaque table T -- //
-    // ------------------------------------------------------ //
-
-    solveTable_solveFeatures_Range_Rosenfeld(T, e0, ne, stats);
-
-    if (mca->p == 0) {
-        MCA_VERBOSE2(nr = countTable_Range_Rosenfeld(T, e0, ne);
-                printf("p = %d : e = [%d..%d] -> ne = %d -> nr = %d\n", mca->p, e0, ne, (ne - e0 + 1), nr));
-        MCA_DISPLAY2(display_ui32vector_number(T, e0, ne, "%5d", "Tp_apres"));
-    }
-    CLOCK_THREAD_END_STEP(mca->p, 0);
-}
-#endif // FEATURES
-
-
-#if FEATURES && !PARMERGE
-// -----------------------------------------------------
-static void MCA_Label_Features_Rosenfeld_PYR2(MCA * mca)
-// -----------------------------------------------------
-{
-    int p = mca->p;
-    int nb_level = mca->nb_level;
-
-    if (mca->p == 0) {
-        printf("*** %s ***\n", __func__);
-    }
-    
-    // ------------------------------
-    // -- pyramidal border merging --
-    // ------------------------------
-    
-    // local variables
-    int i = mca->i0;
-    int width = mca->width;
-    int alpha = mca->alpha;
-    uint32 e0 = mca->e0;
-    uint32 e1 = mca->ne;
-
-    // local memory zones
-    uint8 **  X = mca->X;
-    uint32 ** E = mca->E;
-    uint32 *  T = mca->T;
-    uint32 ** D = mca->D;
-    RegionStats ** F = mca->F;
-
-    CLOCK_THREAD_START_STEP(p, 1);
-#if PYR_BARRIERS
-    // Version optimisÃ©e qui fait faire un break aux processeurs qui n'ont plus
-    // Ã  faire de merge.
-    // Implique de prÃ©-calculer le nombre de threads Ã  chaque barriÃšre
-    if (p != 0) { // thread 0 never has any merge to do
-        int been_active = 0;
-        for (int level = 0; level < nb_level; level++) {
-            if ((p + (1 << level)) % (1 << (level + 1)) == 0) {
-                borderMerging_Features_Rosenfeld_Dist(X, i, width, E, T, D, alpha, F);  // (i) et (i-1)
-                been_active = 1;
-            }
-            else if (been_active) {
-                break;
-            }
-            pthread_barrier_wait(&mca->barriers[level]);
-        }
-    }
-    pthread_barrier_wait(&main_barrier);
-#else
-    for (int level = 1; level <= nb_level; level++) {
-        if ((p + (1 << (level - 1))) % (1 << level) == 0) {
-            // thread actif
-            borderMerging_Features_Rosenfeld_Dist(X, i, width, E, T, D, alpha, F);  // (i) et (i-1)
-        }
-        pthread_barrier_wait(&main_barrier);
-    }
-#endif
-    CLOCK_THREAD_END_STEP(p, 1);
-
-
-    /**
-     * To remove?
-    // -- Affichage de debug
-    if (mca->p == 0) {
-        MCA_VERBOSE1(puts("-----------------------------"));
-        MCA_VERBOSE1(puts("[PYR2]: avant pack sequentiel"));
-        MCA_VERBOSE1(puts("-----------------------------"));
-    
-        for (int p = 0; p < mca->np; p++) {
-    
-            MCA* mca_par = mcas[p];
-            uint32 e0 = mca_par->e0;
-            uint32 e1 = mca_par->ne;
-            
-            uint32*  T = mca_par->T;
-            RegionStats* Stats = mca_par->Stats;
-        
-            RegionStats_DisplayStats_Sparse(T, e0, e1, Stats, NULL);
-            puts("");
-        }
-    }
-    */
-
-    // ---------------------------------
-    // -- parallel transitive closure --
-    // ---------------------------------
-    // identique a la version sans Features
-      
-    CLOCK_THREAD_START_STEP(p, 2);
-    for (uint32 e = e0; e <= e1; e++) {
-        uint32 r = T[e]; // acces local
-        if (r < e) {
-            r = FindRoot_Dist(D, e, alpha); // acces distant
-            T[e] = r;
-        }
-        MCA_VERBOSE2(printf("p%d : T[%d] <- %d\n", p, e, r));
-    }
-    CLOCK_THREAD_END_STEP(p, 2);
-
-    // To avoid uninitialized accesses
-    CLOCK_THREAD_START_STEP(p, 3);
-    CLOCK_THREAD_END_STEP(p, 3);
-}
-#endif // FEATURES && !PARMERGE
-
-
-#if FEATURES && PARMERGE
-// -----------------------------------------------------
-static void MCA_Label_Features_Rosenfeld_PAR2(MCA * mca)
-// -----------------------------------------------------
-{
-    int p = mca->p;
-    int nb_level = mca->nb_level;
-
-    if (mca->p == 0) {
-        printf("*** %s ***\n", __func__);
-    }
-    
-    // ------------------------------
-    // -- parallel border merging --
-    // ------------------------------
-    
-    // local variables
-    int i = mca->i0;
-    int width = mca->width;
-    int alpha = mca->alpha;
-    uint32 e0 = mca->e0;
-    uint32 e1 = mca->ne;
-
-    // local memory zones
-    uint8 **  X = mca->X;
-    uint32 ** E = mca->E;
-    uint32 *  T = mca->T;
-    uint32 ** D = mca->D;
     RegionStats ** F = mca->F;
 
     CLOCK_THREAD_START_STEP(p, 1);
     if (p != 0) { // thread 0 never has any merge to do
-        borderMerging_Features_Rosenfeld_Dist(X, i, width, E, T, D, alpha, F);  // (i) et (i-1)
+        borderMerging_Rosenfeld_Dist(X, i, width, E, T, D, alpha, F);  // (i) et (i-1)
     }
     pthread_barrier_wait(&main_barrier);
@@ -1975,5 +1499,5 @@
             T[e] = r;
         }
-        MCA_VERBOSE2(printf("p%d : T[%d] <- %d\n", p, e, r));
+        MCA_VERBOSE3(printf("p%d : T[%d] <- %d\n", p, e, r));
     }
     CLOCK_THREAD_END_STEP(p, 2);
@@ -1983,67 +1507,123 @@
     CLOCK_THREAD_END_STEP(p, 3);
 }
-#endif // FEATURES
-
-
-
-
-#if !FEATURES
-// =============================================================
-#if TARGET_OS == GIETVM
-__attribute__((constructor)) void MCA_Label_Rosenfeld(MCA * mca)
+#endif // PARMERGE
+
+
+#if !PARMERGE
+// --------------------------------------------
+static void MCA_Label_Rosenfeld_PYR2(MCA * mca)
+// --------------------------------------------
+{
+    // input
+    int p = mca->p;
+    int nb_level = mca->nb_level;
+
+    if (mca->p == 0) {
+        MCA_VERBOSE2(printf("*** %s ***\n", __func__));
+    }
+    
+    // ------------------------------
+    // -- pyramidal border merging --
+    // ------------------------------
+    
+    // local variables
+    int i = mca->i0;
+    int width = mca->width;
+    int alpha = mca->alpha;
+    uint32 e0 = mca->e0;
+    uint32 e1 = mca->ne;
+
+    // local memory zones
+    uint8 **  X = mca->X;
+    uint32 ** E = mca->E;
+    uint32 *  T = mca->T;
+    uint32 ** D = mca->D;
+    RegionStats ** F = mca->F;
+
+    CLOCK_THREAD_START_STEP(p, 1);
+#if PYR_BARRIERS
+    // Version optimisÃ©e qui fait faire un break aux processeurs qui n'ont plus
+    // Ã  faire de merge.
+    // Implique de prÃ©-calculer le nombre de threads Ã  chaque barriÃšre
+    if (p != 0) { // thread 0 never has any merge to do
+        int been_active = 0;
+        for (int level = 0; level < nb_level; level++) {
+            if ((p + (1 << level)) % (1 << (level + 1)) == 0) {
+                borderMerging_Rosenfeld_Dist(X, i, width, E, T, D, alpha, F);  // (i) et (i-1)
+                been_active = 1;
+            }
+            else if (been_active) {
+                break;
+            }
+            pthread_barrier_wait(&mca->barriers[level]);
+        }
+    }
+    pthread_barrier_wait(&main_barrier);
 #else
-void MCA_Label_Rosenfeld(MCA * mca)
+    for (int level = 1; level <= nb_level; level++) {
+        if ((p + (1 << (level - 1))) % (1 << level) == 0) {
+            // thread actif
+            borderMerging_Rosenfeld_Dist(X, i, width, E, T, D, alpha, F);  // (i) et (i-1)
+        }
+        pthread_barrier_wait(&main_barrier);
+    }
 #endif
-// =============================================================
-{
-#if TARGET_OS == GIETVM
-    unsigned int x, y, lpid;
-    giet_proc_xyp(&x, &y, &lpid);
-    // Mettre Ã  jour mca->p en fonction de x, y, lpid
-    // pour que les allocations faites par le main soient locales,
-    // i.e. 
-    mca->p = (x * Y_SIZE + y) * NB_PROCS_MAX + lpid;
-    // We have :
-    // mca->p = 4 pour (x = 0, y = 1, lpid = 0)
-    // mca->p = 5 pour (x = 0, y = 1, lpid = 1)
-    MCA_VERBOSE2(printf("mca->p = %d pour (x = %d, y = %d, lpid = %d)\n", mca->p, x, y, lpid));
-#endif
-
-    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);
-    
-    MCA_Label_Rosenfeld_PYR2(mca);
-    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);
-    CLOCK_THREAD_END(mca->p);
-
-#if TARGET_OS == GIETVM
-    if (mca->p != 0) {
-        exit(0);
-    }
-#endif
+    CLOCK_THREAD_END_STEP(p, 1);
+    
+
+    // ---------------------------------
+    // -- parallel transitive closure --
+    // ---------------------------------
+    
+    CLOCK_THREAD_START_STEP(p, 2);
+    for (uint32 e = e0; e <= e1; e++) {
+        uint32 r = T[e]; // acces local
+        if (r < e) {
+            r = FindRoot_Dist(D, e, alpha); // acces distant
+            T[e] = r;
+        }
+        MCA_VERBOSE3(printf("p%d : T[%d] <- %d\n", p, e, r));
+    }
+    CLOCK_THREAD_END_STEP(p, 2);
 }
 #endif // !FEATURES
 
 
-#if FEATURES
+// -------------------------------------
+void MCA_Label_Rosenfeld_PAR3(MCA * mca)
+// -------------------------------------
+{
+    // input
+    if (mca->p == 0) {
+        MCA_VERBOSE2(printf("*** %s ***\n", __func__));
+    }
+    
+    int i0 = mca->i0;
+    int i1 = mca->i1;
+    int j0 = 0;
+    int j1 = mca->width - 1;
+
+    uint32 ** E = mca->E;
+    uint32 * T = mca->T;
+
+    CLOCK_THREAD_START_STEP(mca->p, 3);
+    for (int i = i0; i <= i1; i++) {
+        for (int j = j0; j <= j1; j++) {
+            uint32 e = E[i][j];
+            if (e != 0) {
+                E[i][j] = T[e];
+            }
+        }
+    }
+    CLOCK_THREAD_END_STEP(mca->p, 3);
+}
+
+
+
 // ======================================================================
 #if TARGET_OS == GIETVM
-__attribute__((constructor)) void * MCA_Label_Features_Rosenfeld(void * arg)
+__attribute__((constructor)) void * MCA_Label_Rosenfeld(void * arg)
 #else
-void * MCA_Label_Features_Rosenfeld(void * arg)
+void * MCA_Label_Rosenfeld(void * arg)
 #endif
 // ======================================================================
@@ -2060,5 +1640,5 @@
     // mca->p = 4 pour (x = 0, y = 1, lpid = 0)
     // mca->p = 5 pour (x = 0, y = 1, lpid = 1)
-    MCA_VERBOSE2(printf("mca->p = %d pour (x = %d, y = %d, lpid = %d)\n", mca->p, x, y, lpid));
+    MCA_VERBOSE3(printf("mca->p = %d pour (x = %d, y = %d, lpid = %d)\n", mca->p, x, y, lpid));
 #endif
 
@@ -2069,11 +1649,11 @@
     pthread_barrier_wait(&main_barrier);
 
-    MCA_Label_Features_Rosenfeld_PAR1(mca);
+    MCA_Label_Rosenfeld_PAR1(mca);
     pthread_barrier_wait(&main_barrier);
    
 #if PARMERGE 
-    MCA_Label_Features_Rosenfeld_PAR2(mca);
+    MCA_Label_Rosenfeld_PAR2(mca);
 #else
-    MCA_Label_Features_Rosenfeld_PYR2(mca);
+    MCA_Label_Rosenfeld_PYR2(mca);
 #endif
     pthread_barrier_wait(&main_barrier);
@@ -2087,8 +1667,9 @@
     CLOCK_THREAD_COMPUTE_END(mca->p);
  
+#if FEATURES
     if (display_features) {
         if (mca->p == 0) {
             int i = 1;
-            printf("[STATS]\n");
+            MCA_VERBOSE1(printf("[STATS]\n"));
             for (int p = 0; p < mca->np; p++) {
                 MCA * mca_par = mca->mca->mcas[p];
@@ -2097,9 +1678,10 @@
                 uint32 * T = mca_par->T;
                 RegionStats * stats = mca_par->stats;
-                RegionStats_DisplayStats_Sparse(T, e0, e0 + ne, stats, NULL, &i);
-            }
-            printf("[/STATS]\n");
-        }
-    }
+                MCA_VERBOSE1(RegionStats_DisplayStats_Sparse(T, e0, e0 + ne, stats, NULL, &i));
+            }
+            MCA_VERBOSE1(printf("[/STATS]\n"));
+        }
+    }
+#endif
 
     CLOCK_THREAD_END(mca->p);
@@ -2113,5 +1695,4 @@
     return NULL;
 }
-#endif // FEATURES
 
 
Index: soft/giet_vm/applications/rosenfeld/src/dummy_func.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/src/dummy_func.c	(revision 821)
+++ 	(revision )
@@ -1,13 +1,0 @@
-
-#include <stddef.h>
-#include <stdlib.h>
-
-#include "mypredef.h"
-#include "nrtype.h"
-#include "nrdef.h"
-#include "nrmacro.h"
-#include "nrkernel.h"
-
-
-void write_ui8matrix_positive (uint8  **m,int i0, int i1, int j0, int j1, int iformat, char *filename) {}
-
Index: soft/giet_vm/applications/rosenfeld/src/ecc_features.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/src/ecc_features.c	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/src/ecc_features.c	(revision 822)
@@ -35,4 +35,16 @@
 
 
+// -----------------------------------------------------
+void RegionStats_Init(RegionStats * Stats, uint32 nemax)
+// -----------------------------------------------------
+{
+    for (int i = 0; i < (int) nemax; i++) {
+#if PARMERGE
+        pthread_spin_init(&Stats[i].lock, PTHREAD_PROCESS_PRIVATE);
+#endif
+    }
+}
+
+
 // -------------------------------------------------------------
 void RegionStats_Constructor(RegionStats ** Stats, uint32 nemax)
@@ -54,5 +66,5 @@
     }
     
-    RegionStats_Clear(Stats, nemax);
+    RegionStats_Init(Stats, nemax);
     
     return Stats;
@@ -72,8 +84,7 @@
 // ------------------------------------------------------------
 {
-    RegionStats_Clear(Stats, nemax);
+    //RegionStats_Clear(Stats, nemax);
     free(Stats);
 }
-
 
 // ------------------------------------------------------
@@ -82,4 +93,5 @@
 {
     for (int i = 0; i < (int) nemax; i++) {
+#if FEATURES
         Stats[i].xmin = 65535;
         Stats[i].xmax = 0;
@@ -91,11 +103,9 @@
         Stats[i].Sx = 0;
         Stats[i].Sy = 0;
-#if PARMERGE
-        pthread_spin_init(&Stats[i].lock, PTHREAD_PROCESS_PRIVATE);
 #endif
     }
 }
 
-
+#if FEATURES
 // -----------------------------------------
 void RegionStats_Clear1(RegionStats * stats)
@@ -396,5 +406,5 @@
     dst->Sy   = src->Sy;
 }
-
+#endif
 
 // ===============================
@@ -414,5 +424,5 @@
         return NULL;
     }
-    RegionStats_Clear(v, i1 - i0 + 1 + NR_END);
+    RegionStats_Init(v, i1 - i0 + 1 + NR_END);
     return v - i0 + NR_END;
 }
@@ -432,5 +442,5 @@
         return NULL;
     }
-    RegionStats_Clear(v, i1 - i0 + 1 + NR_END);
+    RegionStats_Init(v, i1 - i0 + 1 + NR_END);
     return v - i0 + NR_END;
 }
@@ -542,4 +552,5 @@
 
 
+#if FEATURES
 // -----------------------------------
 void zero_RegionStats(RegionStats * x)
@@ -1420,4 +1431,5 @@
     return n1 - s;
 }
+#endif // FEATURES
 
 // Local Variables:
Index: soft/giet_vm/applications/rosenfeld/src/ecc_generation.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/src/ecc_generation.c	(revision 821)
+++ soft/giet_vm/applications/rosenfeld/src/ecc_generation.c	(revision 822)
@@ -23,12 +23,9 @@
 
 
-// -------------------------------------------------------------------------------------------------------------------------
-void generate_granularity_density_float(uint8 **X, int i0, int i1, int j0, int j1, int granularity, float density, int seed)
-// -------------------------------------------------------------------------------------------------------------------------
+// --------------------------------------------------------------------------------------------------------------------------
+void generate_granularity_density_float(uint8 ** X, int i0, int i1, int j0, int j1, int granularity, float density, int seed)
+// --------------------------------------------------------------------------------------------------------------------------
 {
     uint8 x;
-    int i, j;
-    int di, dj;
-    
     double r;
 
@@ -36,59 +33,68 @@
     init_genrand(seed);
 
-    for(i=i0; i<=i1; i+=granularity) {
-        for(j=j0; j<=j1; j+=granularity) {
+    for (int i = i0; i <= i1; i += granularity) {
+        for (int j = j0; j <= j1; j += granularity) {
 
             //r = 100.0*(double)rand() / rmax;
             //r = 100.0*(double)rand() / rmax;
-            r = 100.0*(double)genrand_real2();
-            if(r <= density) x = 1; else x = 0;
-
-            for(di=0; di<granularity; di++) {
-                for(dj=0; dj<granularity; dj++) {
-                    if ((i+di<=i1) && (j+dj<=j1)) X[i+di][j+dj] = x;
+            r = 100.0 * (double) genrand_real2();
+            if (r <= density) {
+                x = 1;
+            }
+            else {
+                x = 0;
+            }
+
+            for (int di = 0; di < granularity; di++) {
+                for (int dj = 0; dj < granularity; dj++) {
+                    if ((i + di <= i1) && (j + dj <= j1)) {
+                        X[i + di][j + dj] = x;
+                    }
                 } // dj
             } // di
-
-        } //j
+        } // j
     } // i
 }
-// ---------------------------------------------------------------------------------------------------------------------
-void generate_granularity_density_int(uint8 **X, int i0, int i1, int j0, int j1, int granularity, int density, int seed)
-// ---------------------------------------------------------------------------------------------------------------------
+
+// ----------------------------------------------------------------------------------------------------------------------
+void generate_granularity_density_int(uint8 ** X, int i0, int i1, int j0, int j1, int granularity, int density, int seed)
+// ----------------------------------------------------------------------------------------------------------------------
 {
     generate_granularity_density_float(X, i0, i1, j0, j1, granularity, (float) density, seed);
 }
-// ---------------------------------------------------------------------------------------------------------
-void generate_granularity_density_name(char *name, int granularity, int density, char *filename, int maxlen)
-// ---------------------------------------------------------------------------------------------------------
+
+// -----------------------------------------------------------------------------------------------------------
+void generate_granularity_density_name(char * name, int granularity, int density, char * filename, int maxlen)
+// -----------------------------------------------------------------------------------------------------------
 {
     snprintf(filename, maxlen, "%s_%02d_%03d.pgm", name, granularity, density);
 }
-// ------------------------------------------------------------------------------------------------------------------------------
-void generate_granularity_density_ext_name(char *name, int granularity, int density, char *extension, char *filename, int maxlen)
-// ------------------------------------------------------------------------------------------------------------------------------
+
+// ---------------------------------------------------------------------------------------------------------------------------------
+void generate_granularity_density_ext_name(char * name, int granularity, int density, char * extension, char * filename, int maxlen)
+// ---------------------------------------------------------------------------------------------------------------------------------
 {
     snprintf(filename, maxlen, "%s_%02d_%03d.%s", name, granularity, density, extension);
 }
-// ------------------------------------------------------------------------------------------------------------------------
-void generate_size_granularity_density_name(char *name, int size, int granularity, int density, char *filename, int maxlen)
-// ------------------------------------------------------------------------------------------------------------------------
+// --------------------------------------------------------------------------------------------------------------------------
+void generate_size_granularity_density_name(char * name, int size, int granularity, int density, char * filename, int maxlen)
+// --------------------------------------------------------------------------------------------------------------------------
 {
     snprintf(filename, maxlen, "%s_%d_%02d_%03d.pgm", name, size, granularity, density);
 }
-// ---------------------------------------------------------------------------------------------------------------------------------------------
-void generate_size_granularity_density_ext_name(char *name, int size, int granularity, int density, char *extension, char *filename, int maxlen)
-// ---------------------------------------------------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------------------------------------------------------------------------
+void generate_size_granularity_density_ext_name(char * name, int size, int granularity, int density, char *extension, char * filename, int maxlen)
+// -----------------------------------------------------------------------------------------------------------------------------------------------
 {
     snprintf(filename, maxlen, "%s_%d_%02d_%03d.%s", name, size, granularity, density, extension);
 }
-// ---------------------------------------------------------------------------------------------------
-void generate_size_granularity_name(char *name, int size, int granularity, char *filename, int maxlen)
-// ---------------------------------------------------------------------------------------------------
+// -----------------------------------------------------------------------------------------------------
+void generate_size_granularity_name(char * name, int size, int granularity, char * filename, int maxlen)
+// -----------------------------------------------------------------------------------------------------
 {
     snprintf(filename, maxlen, "%s_%d_%02d.pgm", name, size, granularity);
-}// -----------------------------------------------------------------------------------------
-void generate_name100(char *name, int granularity, float density, char *filename, int maxlen)
-// ------------------------------------------------------------------------------------------
+}// ------------------------------------------------------------------------------------------
+void generate_name100(char * name, int granularity, float density, char *filename, int maxlen)
+// -------------------------------------------------------------------------------------------
 {
     // density en pourcentage: 0:100
@@ -98,9 +104,9 @@
 }
 // ----------------------------------------
-int test_generation(int argc, char* argv[])
+int test_generation(int argc, char * argv[])
 // ----------------------------------------
 {
-    uint8 **X;
-    uint8 **X255;
+    uint8 ** X;
+    uint8 ** X255;
     char filename[32];
 
@@ -123,38 +129,42 @@
     n = 4096;
     
-    X    = ui8matrix(0-border, n-1+border, 0-border, n-1+border);
-    X255 = ui8matrix(0-border, n-1+border, 0-border, n-1+border);
-
-    for(g=gmin; g<=gmax; g*=2) {
-        for(d=dmin; d<=dmax; d+=dstep) {
-            generate_granularity_density_int(X, 0, n-1, 0, n-1, g, d, seed);
+    X    = ui8matrix(0 - border, n - 1 + border, 0 - border, n - 1 + border);
+    X255 = ui8matrix(0 - border, n - 1 + border, 0 - border, n - 1 + border);
+
+    for (g = gmin; g <= gmax; g *= 2) {
+        for (d = dmin; d <= dmax; d += dstep) {
+            generate_granularity_density_int(X, 0, n - 1, 0, n - 1, g, d, seed);
             generate_granularity_density_name("I", g, d, filename, 32);
             printf(filename);
-            bin2gray_ui8matrix(X, 0, n-1, 0, n-1, X255);
-            SavePGM_ui8matrix(X255, 0, n-1, 0, n-1, filename); 
-        }
-    }
-    free_ui8matrix(X,    0-border, n-1+border, 0-border, n-1+border);
-    free_ui8matrix(X255, 0-border, n-1+border, 0-border, n-1+border);
+            bin2gray_ui8matrix(X, 0, n - 1, 0, n - 1, X255);
+            SavePGM_ui8matrix(X255, 0, n - 1, 0, n - 1, filename); 
+        }
+    }
+    free_ui8matrix(X,    0 - border, n - 1 + border, 0 - border, n - 1 + border);
+    free_ui8matrix(X255, 0 - border, n - 1 + border, 0 - border, n - 1 + border);
 
     return 0;
 }
-// -----------------------------------------
-void hline(uint8 **X, int i, int j0, int j1)
-// -----------------------------------------
-{
-    int j;
-    for(j=j0; j<=j1; j++) X[i][j] = 1;
-}
-// -----------------------------------------
-void vline(uint8 **X, int i0, int i1, int j)
-// -----------------------------------------
-{
-    int i;
-    for(i=i0; i<=i1; i++) X[i][j] = 1;
-}
-// -----------------------------------------------------------
-void draw_rectangle(uint8 **X, int i0, int i1, int j0, int j1)
-// -----------------------------------------------------------
+
+// ------------------------------------------
+void hline(uint8 ** X, int i, int j0, int j1)
+// ------------------------------------------
+{
+    for (int j = j0; j <= j1; j++) {
+        X[i][j] = 1;
+    }
+}
+// ------------------------------------------
+void vline(uint8 ** X, int i0, int i1, int j)
+// ------------------------------------------
+{
+    for (int i = i0; i <= i1; i++) {
+        X[i][j] = 1;
+    }
+}
+
+// ------------------------------------------------------------
+void draw_rectangle(uint8 ** X, int i0, int i1, int j0, int j1)
+// ------------------------------------------------------------
 {
     hline(X, i0, j0, j1);
@@ -163,7 +173,8 @@
     hline(X, i1, j0, j1);
 }
-// --------------------------------------------------
-void spirale_simple(uint8 **X, int height, int width)
-// --------------------------------------------------
+
+// ---------------------------------------------------
+void spirale_simple(uint8 ** X, int height, int width)
+// ---------------------------------------------------
 {
     int i0, j0; // point de depart haut
@@ -172,9 +183,10 @@
     int n;      //min(height, width)
     
-    zero_ui8matrix(X, 0, height-1, 0, width-1);
-    
-    if(height<width) {
+    zero_ui8matrix(X, 0, height - 1, 0, width - 1);
+    
+    if (height < width) {
         n = height;
-    } else {
+    }
+    else {
         n = width;
     }
@@ -184,21 +196,24 @@
     
     // avec correction
-    i0 = 0; i1 = 2*(n/2)-1;
-    j0 = 0; j1 = 2*(n/2)-1;
+    i0 = 0;
+    i1 = 2 * (n / 2) - 1;
+    j0 = 0;
+    j1 = 2 * (n / 2) - 1;
     
     nc = n / 4;
     
-    for(c=0; c<nc; c++) {
-        draw_rectangle(X, i0+2*c, i1-2*c, j0+2*c, j1-2*c);
-        X[1+2*c  ][0+2*c  ] = 0;
-        X[1+2*c+1][0+2*c+1] = 1;
+    for (c = 0; c < nc; c++) {
+        draw_rectangle(X, i0 + 2 * c, i1 - 2 * c, j0 + 2 * c, j1 - 2 * c);
+        X[1 + 2 * c    ][0 + 2 * c    ] = 0;
+        X[1 + 2 * c + 1][0 + 2 * c + 1] = 1;
     }
     
     // centre
     //X[n/2][n/2] = 1;
-    for(c=i0+2*nc; c<=i1-2*nc; c++) {
-        hline(X, c, j0+2*nc, j1-2*nc);
-    }
-}
+    for (c = i0 + 2 * nc; c <= i1 - 2 * nc; c++) {
+        hline(X, c, j0 + 2 * nc, j1 - 2 * nc);
+    }
+}
+
 // --------------------------------------------------
 void spirale_double(uint8 **X, int height, int width)
@@ -212,7 +227,8 @@
     zero_ui8matrix(X, 0, height-1, 0, width-1);
     
-    if(height<width) {
+    if (height < width) {
         n = height;
-    } else {
+    }
+    else {
         n = width;
     }
@@ -221,23 +237,25 @@
     //n = ((n-1) & (~0x3))+1;
     
-    i0 = 0; i1 = 2*(n/2)-1;
-    j0 = 0; j1 = 2*(n/2)-1;
+    i0 = 0;
+    i1 = 2 * (n / 2) - 1;
+    j0 = 0;
+    j1 = 2 * (n / 2) - 1;
     
     nc = n / 4;
     
-    for(c=0; c<nc; c++) {
-        draw_rectangle(X, i0+2*c, i1-2*c, j0+2*c, j1-2*c);
-    }
-    for(c=0; c<nc; c++) {
-        X[(i0+1)+(2*c  )][(j0)+(2*c  )] = 0;
-        X[(i0+1)+(2*c+1)][(j0)+(2*c+1)] = 1;
+    for (c = 0; c < nc; c++) {
+        draw_rectangle(X, i0 + 2 * c, i1 - 2 * c, j0 + 2 * c, j1 - 2 * c);
+    }
+    for (c = 0; c < nc; c++) {
+        X[(i0 + 1) + (2 * c    )][(j0) + (2 * c    )] = 0;
+        X[(i0 + 1) + (2 * c + 1)][(j0) + (2 * c + 1)] = 1;
         
-        X[(i1-1)-(2*c  )][(j1)-(2*c  )] = 0;
-        X[(i1-1)-(2*c+1)][(j1)-(2*c+1)] = 1;
+        X[(i1 - 1) - (2 * c    )][(j1) - (2 * c    )] = 0;
+        X[(i1 - 1) - (2 * c + 1)][(j1) - (2 * c + 1)] = 1;
     }
     // centre
     //X[n/2][n/2] = 1;
-    for(c=i0+2*nc; c<=i1-2*nc; c++) {
-        hline(X, c, j0+2*nc, j1-2*nc);
+    for (c = i0 + 2 * nc; c <= i1 - 2 * nc; c++) {
+        hline(X, c, j0 + 2 * nc, j1 - 2 * nc);
     }
 }
@@ -246,6 +264,6 @@
 // ------------------------
 {
-    uint8 **X;
-    uint8 **X255;
+    uint8 ** X;
+    uint8 ** X255;
     char filename[128];
     //char *ptr = (char*) filename;
@@ -254,23 +272,24 @@
     h = w = n;
     
-    X    = ui8matrix(0, h-1, 0, w-1);
-    X255 = ui8matrix(0, h-1, 0, w-1);
+    X    = ui8matrix(0, h - 1, 0, w - 1);
+    X255 = ui8matrix(0, h - 1, 0, w - 1);
     
     snprintf(filename, 128, "spirale_simple_%d.pgm", n);
     spirale_simple(X, h, w);
-    bin2gray_ui8matrix(X,   0, h-1, 0, w-1, X255);
-    SavePGM_ui8matrix(X255, 0, h-1, 0, w-1, filename); 
+    bin2gray_ui8matrix(X,   0, h - 1, 0, w - 1, X255);
+    SavePGM_ui8matrix(X255, 0, h - 1, 0, w - 1, filename); 
     
     snprintf(filename, 128, "spirale_double_%d.pgm", n);
     spirale_double(X, h, w);
-    bin2gray_ui8matrix(X,   0, h-1, 0, w-1, X255);
-    SavePGM_ui8matrix(X255, 0, h-1, 0, w-1, filename);/**/
-    
-    free_ui8matrix(X,    0, h-1, 0, w-1);
-    free_ui8matrix(X255, 0, h-1, 0, w-1);
-}
-// --------------------------------------
-void test_spirale(int argc, char* argv[])
-// --------------------------------------
+    bin2gray_ui8matrix(X,   0, h - 1, 0, w - 1, X255);
+    SavePGM_ui8matrix(X255, 0, h - 1, 0, w - 1, filename);/**/
+    
+    free_ui8matrix(X,    0, h - 1, 0, w - 1);
+    free_ui8matrix(X255, 0, h - 1, 0, w - 1);
+}
+
+// ---------------------------------------
+void test_spirale(int argc, char * argv[])
+// ---------------------------------------
 {
     routine_spirale(128);
@@ -283,14 +302,15 @@
     routine_spirale(1024);
 }
-// --------------------------------------------
-int test_generation_HGH(int argc, char* argv[])
-// --------------------------------------------
-{
-    uint8 **X;
-    uint8 **X255;
+
+// ---------------------------------------------
+int test_generation_HGH(int argc, char * argv[])
+// ---------------------------------------------
+{
+    uint8 ** X;
+    uint8 ** X255;
     char filename[32];
 
     int h = 1280;
-    int w = 90*1024;
+    int w = 90 * 1024;
 
     int border = 2;
@@ -303,21 +323,22 @@
     //w = h;
 
-    X    = ui8matrix(0-border, h-1+border, 0-border, w-1+border);
-    X255 = ui8matrix(0-border, h-1+border, 0-border, w-1+border);
-
-    generate_granularity_density_float(X, 0, h-1, 0, w-1, g, d, seed);
+    X    = ui8matrix(0 - border, h - 1 + border, 0 - border, w - 1 + border);
+    X255 = ui8matrix(0 - border, h - 1 + border, 0 - border, w - 1 + border);
+
+    generate_granularity_density_float(X, 0, h - 1, 0, w - 1, g, d, seed);
     generate_granularity_density_name("HGH", g, d, filename, 32);
     printf(filename);
-    bin2gray_ui8matrix(X,   0, h-1, 0, w-1, X255);
-    SavePGM_ui8matrix(X255, 0, h-1, 0, w-1, filename); 
-
-    free_ui8matrix(X,    0-border, h-1+border, 0-border, w-1+border);
-    free_ui8matrix(X255, 0-border, h-1+border, 0-border, w-1+border);
+    bin2gray_ui8matrix(X,   0, h - 1, 0, w - 1, X255);
+    SavePGM_ui8matrix(X255, 0, h - 1, 0, w - 1, filename); 
+
+    free_ui8matrix(X,    0 - border, h - 1 + border, 0 - border, w - 1 + border);
+    free_ui8matrix(X255, 0 - border, h - 1 + border, 0 - border, w - 1 + border);
 
     return 0;
 }
-// --------------------------------------------
-int image_analysis_2014(int argc, char* argv[])
-// --------------------------------------------
+
+// ---------------------------------------------
+int image_analysis_2014(int argc, char * argv[])
+// ---------------------------------------------
 {
     // uint8 **X;
@@ -466,5 +487,5 @@
 // --------------------------
 {
-    int i, n = 32;
+    int n = 32;
     
     printf("---------------------------");
@@ -474,79 +495,48 @@
     
     init_genrand(0);
-    for(i=0; i<n; i++) {
+    for (int i = 0; i < n; i++) {
         printf("%10lu ", genrand_int32());
-        if (i%8==7) printf("\n");
+        if (i % 8 == 7) {
+            printf("\n");
+        }
     }
     printf("\n---");
     
     init_genrand(1);
-    for(i=0; i<n; i++) {
+    for (int i = 0; i < n; i++) {
         printf("%10lu ", genrand_int32());
-        if (i%8==7) printf("\n");
+        if (i % 8== 7) {
+            printf("\n");
+        }
     }
     printf("\n---");
     
     init_genrand(0);
-    for(i=0; i<n; i++) {
+    for (int i = 0; i < n; i++) {
         printf("%10lu ", genrand_int32());
-        if (i%8==7) printf("\n");
+        if (i % 8== 7) {
+            printf("\n");
+        }
     }
     printf("\n---");
     
     init_genrand(1);
-    for(i=0; i<n; i++) {
+    for (int i = 0; i < n; i++) {
         printf("%10lu ", genrand_int32());
-        if (i%8==7) printf("\n");
-    }
-}
-// -------------------------------------
-void image_zoom2(int argc, char *argv[])
-// -------------------------------------
-{
-    uint8 x, **X, **Y;
-    int i, j, i0, i1, j0, j1;
+        if (i % 8 == 7) {
+            printf("\n");
+        }
+    }
+}
+
+// --------------------------------------
+void image_zoom2(int argc, char * argv[])
+// --------------------------------------
+{
+    uint8 x, ** X, ** Y;
+    int i0, i1, j0, j1;
     int height, width;
-    char *src_filename;
-    char *dst_filename;
-    
-    if(argc<3) {
-        printf("too few arguments");
-        printf("%s src.pgm dst.pgm\n", argv[0]);
-        return;
-    }
-    
-    src_filename = argv[1];
-    dst_filename = argv[2];
-    
-    X = LoadPGM_ui8matrix(src_filename, &i0, &i1, &j0, &j1);
-    
-    height = i1-i0+1;
-    width  = j1-j0+1;
-    
-    printf("width = %d height = %d\n", width, height);
-    
-    Y = ui8matrix(0, 2*height-1, 0, 2*width-1);
-    
-    for(i=0; i<=height-1; i++) {
-        for(j=0; j<=width-1; j++) {
-            x = X[i][j];
-            Y[2*i+0][2*j+0] = x; Y[2*i+0][2*j+1] = x;
-            Y[2*i+1][2*j+0] = x; Y[2*i+1][2*j+1] = x;
-        }
-    }
-    SavePGM_ui8matrix(Y, 0, 2*height-1, 0, 2*width-1, dst_filename);
-    
-    free_ui8matrix(X, 0,   height-1, 0,   width-1);
-    free_ui8matrix(Y, 0, 2*height-1, 0, 2*width-1);
-}
-// --------------------------------------------
-void image_duplication2(int argc, char *argv[])
-// --------------------------------------------
-{
-    uint8 x, **X, **Y;
-    int i, j, i0, i1, j0, j1;
-    int height, width;
-    char *src_filename;
-    char *dst_filename;
+    char * src_filename;
+    char * dst_filename;
     
     if (argc < 3) {
@@ -561,29 +551,77 @@
     X = LoadPGM_ui8matrix(src_filename, &i0, &i1, &j0, &j1);
     
-    height = i1-i0+1;
-    width  = j1-j0+1;
+    height = i1 - i0 + 1;
+    width  = j1 - j0 + 1;
     
     printf("width = %d height = %d\n", width, height);
     
-    Y = ui8matrix(0, 2*height-1, 0, 2*width-1);
+    Y = ui8matrix(0, 2 * height - 1, 0, 2 * width - 1);
+    
+    for (int i = 0; i <= height - 1; i++) {
+        for (int j = 0; j <= width - 1; j++) {
+            x = X[i][j];
+            Y[2 * i + 0][2 * j + 0] = x;
+            Y[2 * i + 0][2 * j + 1] = x;
+            Y[2 * i + 1][2 * j + 0] = x;
+            Y[2 * i + 1][2 * j + 1] = x;
+        }
+    }
+    SavePGM_ui8matrix(Y, 0, 2 * height - 1, 0, 2 * width - 1, dst_filename);
+    
+    free_ui8matrix(X, 0,     height - 1, 0,     width - 1);
+    free_ui8matrix(Y, 0, 2 * height - 1, 0, 2 * width - 1);
+}
+
+
+// ---------------------------------------------
+void image_duplication2(int argc, char * argv[])
+// ---------------------------------------------
+{
+    uint8 x, ** X, ** Y;
+    int i0, i1, j0, j1;
+    int height, width;
+    char * src_filename;
+    char * dst_filename;
+    
+    if (argc < 3) {
+        printf("too few arguments");
+        printf("%s src.pgm dst.pgm\n", argv[0]);
+        return;
+    }
+    
+    src_filename = argv[1];
+    dst_filename = argv[2];
+    
+    X = LoadPGM_ui8matrix(src_filename, &i0, &i1, &j0, &j1);
+    
+    height = i1 - i0 + 1;
+    width  = j1 - j0 + 1;
+    
+    printf("width = %d height = %d\n", width, height);
+    
+    Y = ui8matrix(0, 2 * height - 1, 0, 2 * width - 1);
     
     // horizontal duplication
-    for(i=0; i<=height-1; i++) {
-        for(j=0; j<=width-1; j++) {
+    for (int i = 0; i <= height - 1; i++) {
+        for (int j = 0; j <= width - 1; j++) {
             x = X[i][j];
-            Y[i][width+j] = x;
+            Y[i][width + j] = x;
         }
     }
     
     // vertical duplication
-    for(i=0; i<=height-1; i++) {
-        for(j=0; j<=2*width-1; j++) {
+    for (int i = 0; i <= height - 1; i++) {
+        for (int j = 0; j <= 2 * width - 1; j++) {
             x = X[i][j];
-            Y[height+i][j] = x;
-        }
-    }
-    SavePGM_ui8matrix(Y, 0, 2*height-1, 0, 2*width-1, dst_filename);
-    
-    free_ui8matrix(X, 0,   height-1, 0,   width-1);
-    free_ui8matrix(Y, 0, 2*height-1, 0, 2*width-1);
-}
+            Y[height + i][j] = x;
+        }
+    }
+    SavePGM_ui8matrix(Y, 0, 2 * height - 1, 0, 2 * width - 1, dst_filename);
+    
+    free_ui8matrix(X, 0,     height - 1, 0,     width - 1);
+    free_ui8matrix(Y, 0, 2 * height - 1, 0, 2 * width - 1);
+}
+
+
+
+
