Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc1.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc1.c	(revision 805)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc1.c	(revision 821)
@@ -29,6 +29,7 @@
 #include <stdlib.h>
 #include <malloc.h>
-#include <math.h> // fabs
+#include <stdint.h>
 
+#include "nrc_os_config.h"
 #include "mypredef.h"
 #include "nrtype.h"
@@ -38,516 +39,156 @@
 
 #include "nralloc1.h"
-#include "nrset1.h" // set 1
 
 
-long nr_end = NR_END;
 
-// ------------------------------------------------------------------
-// -- deprecated type (original NRC type, not enough typed vector) --
-// ------------------------------------------------------------------
-
-/* ---------------------------------------- */
-NRC_EXPORT(sint8*) si8vector(long nl, long nh)
-/* ---------------------------------------- */
-{
-    sint8 *v;
-    
-    v=(sint8 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(sint8)));
-    if (!v) nrerror("allocation failure in si8vector()");
-    return v-nl+NR_END;
-}
-/* ---------------------------------------- */
-NRC_EXPORT(uint8*) ui8vector(long nl, long nh)
-/* ---------------------------------------- */
-{
-    uint8 *v;
-    
-    v=(uint8 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(uint8)));
-    if (!v) nrerror("allocation failure in ui8vector()");
-    return v-nl+NR_END;
-}
-/* -------------------------------------------- */
-NRC_EXPORT(sint16*) si16vector(long nl, long nh)
-/* -------------------------------------------- */
-{
-    sint16 *v;
-    
-    v=(sint16 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(sint16)));
-    if (!v) nrerror("allocation failure in si16vector()");
-    return v-nl+NR_END;
-}
-/* -------------------------------------------- */
-NRC_EXPORT(uint16*) ui16vector(long nl, long nh)
-/* -------------------------------------------- */
-{
-    uint16 *v;
-    
-    v=(uint16 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(uint16)));
-    if (!v) nrerror("allocation failure in ui16vector()");
-    return v-nl+NR_END;
-}
-/* -------------------------------------------- */
-IMAGE_EXPORT(sint32*) si32vector(long nl, long nh)
-/* -------------------------------------------- */
-{
-    sint32 *v;
-    
-    v=(sint32 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(sint32)));
-    if (!v) nrerror("allocation failure in si32vector()");
-    if(!v) return NULL;
-    return v-nl+NR_END;
-}
-/* -------------------------------------------- */
-IMAGE_EXPORT(uint32*) ui32vector(long nl, long nh)
-/* -------------------------------------------- */
-{
-    uint32 *v;
-    
-    v=(uint32 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(uint32)));
-    if (!v) nrerror("allocation failure in ui32vector()");
-    if(!v) return NULL;
-    return v-nl+NR_END;
-}
-/* -------------------------------------------- */
-IMAGE_EXPORT(sint64*) si64vector(long nl, long nh)
-/* -------------------------------------------- */
-{
-    sint64 *v;
-    
-    v=(sint64 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(sint64)));
-    if (!v) nrerror("allocation failure in si64vector()");
-    return v-nl+NR_END;
-}
-/* -------------------------------------------- */
-IMAGE_EXPORT(uint64*) ui64vector(long nl, long nh)
-/* -------------------------------------------- */
-{
-    uint64 *v;
-    
-    v=(uint64 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(uint64)));
-    if (!v) nrerror("allocation failure in ui64vector()");
-    return v-nl+NR_END;
-}
-/* ------------------------------------------ */
-NRC_EXPORT(float32*) f32vector(long nl, long nh)
-/* ------------------------------------------ */
-{
-    float32 *v;
-    
-    v=(float32 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(float32)));
-    if (!v) nrerror("allocation failure in f32vector()");
-    if(!v) return NULL;
-    return v-nl+NR_END;
-}
-/* ------------------------------------------ */
-NRC_EXPORT(float64*) f64vector(long nl, long nh)
-/* ------------------------------------------ */
-{
-    float64 *v;
-    
-    v=(float64 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(float64)));
-    if (!v) nrerror("allocation failure in f64vector()");
-    if(!v) return NULL;
-    return v-nl+NR_END;
-}
-/* ------------------------------------------ */
-IMAGE_EXPORT(rgb8*) rgb8vector(long nl, long nh)
-/* ------------------------------------------ */
-{
-    rgb8 *v;
-    
-    v=(rgb8 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(rgb8)));
-    if (!v) nrerror("allocation failure in rgb8vector()");
-    return v-nl+NR_END;
-}
-/* -------------------------------------------- */
-IMAGE_EXPORT(rgbx8*) rgbx8vector(long nl, long nh)
-/* -------------------------------------------- */
-{
-    rgbx8 *v;
-    
-    v=(rgbx8 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(rgbx8)));
-    if (!v) nrerror("allocation failure in rgbx8vector()");
-    return v-nl+NR_END;
-}
-/* -------------------------------------------- */
-IMAGE_EXPORT(rgb32*) rgb32vector(long nl, long nh)
-/* -------------------------------------------- */
-{
-    rgb32 *v;
-    
-    v=(rgb32 *)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(rgb32)));
-    if (!v) nrerror("allocation failure in rgb32vector()");
-    return v-nl+NR_END;
+#undef type_vector
+#define type_vector(t)                                              \
+t * short_name(t,,vector)(int32_t nl, int32_t nh)                   \
+{                                                                   \
+    t * v;                                                          \
+    v = malloc((nh - nl + 1 + NR_END) * sizeof(t));                 \
+    if (v == NULL) {                                                \
+        nrerror("*** Error: allocation failure in %s\n", __func__); \
+    }                                                               \
+    return v - nl + NR_END;                                         \
 }
 
-/* ---------------------------------------- */
-IMAGE_EXPORT(void**) vvector(long nl, long nh)
-/* ---------------------------------------- */
-{
-    void **v;
-    
-    v=(void**)malloc((size_t) ((nh-nl+1+NR_END)*sizeof(void*)));
-    if (!v) nrerror("allocation failure in vvector()");
-    return v-nl+NR_END;
+type_vector(int8_t);
+type_vector(uint8_t);
+type_vector(int16_t);
+type_vector(uint16_t);
+type_vector(int32_t);
+type_vector(uint32_t);
+type_vector(int64_t);
+type_vector(uint64_t);
+type_vector(float);
+type_vector(double);
+type_vector(void_p);
+type_vector(rgb8);
+type_vector(rgbx8);
+type_vector(rgb32);
+
+
+
+#undef type_vector0
+#define type_vector0(t)                                             \
+t * short_name(t,,vector0)(int32_t nl, int32_t nh)                  \
+{                                                                   \
+    t * v;                                                          \
+    v = calloc((nh - nl + 1 + NR_END), sizeof(t));                  \
+    if (v == NULL) {                                                \
+        nrerror("*** Error: allocation failure in %s\n", __func__); \
+    }                                                               \
+    return v - nl + NR_END;                                         \
 }
-/*
- * ---------------
- * --- vector0 ---
- * ---------------
- */
 
-// do: allocate a vector and set it to 0
+type_vector0(int8_t);
+type_vector0(uint8_t);
+type_vector0(int16_t);
+type_vector0(uint16_t);
+type_vector0(int32_t);
+type_vector0(uint32_t);
+type_vector0(int64_t);
+type_vector0(uint64_t);
+type_vector0(float);
+type_vector0(double);
+type_vector0(void_p);
+type_vector0(rgb8);
+type_vector0(rgbx8);
+type_vector0(rgb32);
 
-// ----------------------
-// --- not deprecated ---
-// ----------------------
-/* ------------------------------------------- */
-IMAGE_EXPORT(sint8*) si8vector0(long nl, long nh)
-/* ------------------------------------------- */
-{
-    sint8 *v;
-    
-    v=(sint8 *)calloc((size_t) ((nh-nl+1+NR_END)), sizeof(sint8));
-    if (!v) nrerror("allocation failure in si8vector0()");
-    return v-nl+NR_END;
+
+#undef realloc_type_vector
+#define realloc_type_vector(t)                                      \
+t * short_name(t,realloc_,vector)(t * v, int32_t nl, int32_t nh)    \
+{                                                                   \
+    v += nl;                                                        \
+    v -= NR_END;                                                    \
+    v = realloc(v, (nh - nl + 1 + NR_END) * sizeof(t));             \
+    if (v == NULL) {                                                \
+        nrerror("*** Error: allocation failure in %s\n", __func__); \
+    }                                                               \
+    return v - nl + NR_END;                                         \
 }
-/* ------------------------------------------- */
-IMAGE_EXPORT(uint8*) ui8vector0(long nl, long nh)
-/* ------------------------------------------- */
-{
-    uint8 *v;
-    
-    v=(uint8 *)calloc((size_t) ((nh-nl+1+NR_END)), sizeof(uint8));
-    if (!v) nrerror("allocation failure in ui8vector0()");
-    return v-nl+NR_END;
+
+
+realloc_type_vector(int8_t);
+realloc_type_vector(uint8_t);
+realloc_type_vector(int16_t);
+realloc_type_vector(uint16_t);
+realloc_type_vector(int32_t);
+realloc_type_vector(uint32_t);
+realloc_type_vector(int64_t);
+realloc_type_vector(uint64_t);
+realloc_type_vector(float);
+realloc_type_vector(double);
+realloc_type_vector(void_p);
+realloc_type_vector(rgb8);
+realloc_type_vector(rgbx8);
+realloc_type_vector(rgb32);
+
+
+#undef free_type_vector
+#define free_type_vector(t)                               \
+void short_name(t,free_,vector)(t * v, long nl, long nh)  \
+{                                                         \
+    free((FREE_ARG) (v + nl - NR_END));                   \
 }
-/* -------------------------------------------- */
-IMAGE_EXPORT(int16*) si16vector0(long nl, long nh)
-/* -------------------------------------------- */
-{
-    sint16 *v;
-    
-    v=(sint16 *)calloc((size_t) ((nh-nl+1+NR_END)), sizeof(sint16));
-    if (!v) nrerror("allocation failure in si16vector0()");
-    return v-nl+NR_END;
+
+free_type_vector(int8_t);
+free_type_vector(uint8_t);
+free_type_vector(int16_t);
+free_type_vector(uint16_t);
+free_type_vector(int32_t);
+free_type_vector(uint32_t);
+free_type_vector(int64_t);
+free_type_vector(uint64_t);
+free_type_vector(float);
+free_type_vector(double);
+free_type_vector(void_p);
+free_type_vector(rgb8);
+free_type_vector(rgbx8);
+free_type_vector(rgb32);
+
+
+
+
+#if TARGET_OS == GIETVM
+#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 * v;                                                                      \
+    v = remote_malloc((nh - nl + 1 + NR_END) * sizeof(t), x, y);                \
+    if (v == NULL) {                                                            \
+        nrerror("*** Error: allocation failure in %s\n", __func__);             \
+    }                                                                           \
+    return v - nl + NR_END;                                                     \
 }
-/* --------------------------------------------- */
-IMAGE_EXPORT(uint16*) ui16vector0(long nl, long nh)
-/* --------------------------------------------- */
-{
-    uint16 *v;
-    
-    v=(uint16 *)calloc((size_t) ((nh-nl+1+NR_END)), sizeof(uint16));
-    if (!v) nrerror("allocation failure in ui16vector0()");
-    return v-nl+NR_END;
-}
-/* --------------------------------------------- */
-IMAGE_EXPORT(sint32*) si32vector0(long nl, long nh)
-/* --------------------------------------------- */
-/* allocate a sint32 vector with subscript range v[nl..nh] */
-{
-    sint32 *v;
-    
-    v=(sint32 *) calloc((size_t) (nh-nl+1+NR_END),sizeof(sint32));
-    if (!v) nrerror("allocation failure in si32vector0()");
-    return v-nl+NR_END;
-}
-/* --------------------------------------------- */
-IMAGE_EXPORT(uint32*) ui32vector0(long nl, long nh)
-/* --------------------------------------------- */
-/* allocate a uint32 vector with subscript range v[nl..nh] */
-{
-    uint32 *v;
-    
-    v=(uint32 *) calloc((size_t) (nh-nl+1+NR_END),sizeof(uint32));
-    if (!v) nrerror("allocation failure in ui32vector0()");
-    return v-nl+NR_END;
-}
-/* --------------------------------------------- */
-IMAGE_EXPORT(float32*) f32vector0(long nl, long nh)
-/* --------------------------------------------- */
-/* allocate a float32 vector with subscript range v[nl..nh] */
-{
-    float32 *v;
-    
-    v=(float32 *) calloc ( (size_t) (nh-nl+1+NR_END), sizeof(float32) );
-    if (!v) nrerror("allocation failure in f32vector0()");
-    if(!v) return NULL;
-    return v-nl+NR_END;
-}
-/* --------------------------------------------- */
-IMAGE_EXPORT(float64*) f64vector0(long nl, long nh)
-/* --------------------------------------------- */
-/* allocate a float vector with subscript range v[nl..nh] */
-{
-    float64 *v;
-    
-    v=(float64 *) calloc ( (size_t) (nh-nl+1+NR_END), sizeof(float64) );
-    if (!v) nrerror("allocation failure in f64vector0()");
-    if(!v) return NULL;
-    return v-nl+NR_END;
-}
-/* ------------------------------------------- */
-IMAGE_EXPORT(rgb8*) rgb8vector0(long nl, long nh)
-/* ------------------------------------------- */
-{
-    rgb8 *v;
-    
-    v=(rgb8 *)calloc((size_t) ((nh-nl+1+NR_END)), sizeof(rgb8));
-    if (!v) nrerror("allocation failure in rgb8vector0()");
-    return v-nl+NR_END;
-}
-/* --------------------------------------------- */
-IMAGE_EXPORT(rgbx8*) rgbx8vector0(long nl, long nh)
-/* --------------------------------------------- */
-{
-    rgbx8 *v;
-    
-    v=(rgbx8 *)calloc((size_t) ((nh-nl+1+NR_END)), sizeof(rgbx8));
-    if (!v) nrerror("allocation failure in rgbx8vector0()");
-    return v-nl+NR_END;
-}
-/* --------------------------------------------- */
-IMAGE_EXPORT(rgb32*) rgb32vector0(long nl, long nh)
-/* --------------------------------------------- */
-{
-    rgb32 *v;
-    
-    v=(rgb32 *)calloc((size_t) ((nh-nl+1+NR_END)), sizeof(rgb32));
-    if (!v) nrerror("allocation failure in rgb32vector0()");
-    return v-nl+NR_END;
-}
-/*
- * ----------------------
- * --- realloc_vector ---
- * ----------------------
- */
 
-/* ------------------------------------------------------------ */
-IMAGE_EXPORT(sint8*) realloc_si8vector(sint8 *v, long nl, long nh)
-/* ------------------------------------------------------------ */
-{
-    v += nl;
-    v -= NR_END;
-    v=(sint8 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(sint8)));
-    if (!v) nrerror("allocation failure in realloc_si8vector()");
-    
-    return v-nl+NR_END;
-}
-/* ------------------------------------------------------------ */
-IMAGE_EXPORT(uint8*) realloc_ui8vector(uint8 *v, long nl, long nh)
-/* ------------------------------------------------------------ */
-{
-    v += nl;
-    v -= NR_END;
-    v=(uint8 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(uint8)));
-    if (!v) nrerror("allocation failure in realloc_ui8vector()");
-    
-    return v-nl+NR_END;
-}
-/* --------------------------------------------------------------- */
-IMAGE_EXPORT(sint16*) realloc_si16vector(sint16 *v, long nl, long nh)
-/* --------------------------------------------------------------- */
-{
-    v += nl;
-    v -= NR_END;
-    v=(sint16 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(sint16)));
-    if (!v) nrerror("allocation failure in realloc_si16vector()");
-    
-    return v-nl+NR_END;
-}
-/* --------------------------------------------------------------- */
-IMAGE_EXPORT(uint16*) realloc_ui16vector(uint16 *v, long nl, long nh)
-/* --------------------------------------------------------------- */
-{
-    v += nl;
-    v -= NR_END;
-    v=(uint16 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(uint16)));
-    if (!v) nrerror("allocation failure in realloc_ui16vector()");
-    
-    return v-nl+NR_END;
-}
-/* --------------------------------------------------------------- */
-IMAGE_EXPORT(sint32*) realloc_si32vector(sint32 *v, long nl, long nh)
-/* --------------------------------------------------------------- */
-{
-    v += nl;
-    v -= NR_END;
-    v=(sint32 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(sint32)));
-    if (!v) nrerror("allocation failure in realloc_si32vector()");
-    
-    return v-nl+NR_END;
-}
-/* --------------------------------------------------------------- */
-IMAGE_EXPORT(uint32*) realloc_ui32vector(uint32 *v, long nl, long nh)
-/* --------------------------------------------------------------- */
-{
-    v += nl;
-    v -= NR_END;
-    v=(uint32 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(uint32)));
-    if (!v) nrerror("allocation failure in realloc_ui32vector()");
-    
-    return v-nl+NR_END;
-}
-/* --------------------------------------------------------------- */
-IMAGE_EXPORT(sint64*) realloc_si64vector(sint64 *v, long nl, long nh)
-/* --------------------------------------------------------------- */
-{
-    v += nl;
-    v -= NR_END;
-    v=(sint64 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(sint64)));
-    if (!v) nrerror("allocation failure in realloc_si64vector()");
-    
-    return v-nl+NR_END;
-}
-/* --------------------------------------------------------------- */
-IMAGE_EXPORT(uint64*) realloc_ui64vector(uint64 *v, long nl, long nh)
-/* --------------------------------------------------------------- */
-{
-    v += nl;
-    v -= NR_END;
-    v=(uint64 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(uint64)));
-    if (!v) nrerror("allocation failure in realloc_ui64vector()");
-    
-    return v-nl+NR_END;
-}
-/* ---------------------------------------------------------- */
-IMAGE_EXPORT(rgb8*) realloc_rgb8vector(rgb8 *v, long nl, long nh)
-/* ---------------------------------------------------------- */
-{
-    v += nl;
-    v -= NR_END;
-    v=(rgb8 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(rgb8)));
-    if (!v) nrerror("allocation failure in realloc_rgb8vector()");
-    
-    return v-nl+NR_END;
-}
-/* -------------------------------------------------------------- */
-IMAGE_EXPORT(rgbx8*) realloc_rgbx8vector(rgbx8 *v, long nl, long nh)
-/* -------------------------------------------------------------- */
-{
-    v += nl;
-    v -= NR_END;
-    v=(rgbx8 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(rgbx8)));
-    if (!v) nrerror("allocation failure in realloc_rgbx8vector()");
-    
-    return v-nl+NR_END;
-}
-/* -------------------------------------------------------------- */
-IMAGE_EXPORT(rgb32*) realloc_rgb32vector(rgb32 *v, long nl, long nh)
-/* -------------------------------------------------------------- */
-{
-    v += nl;
-    v -= NR_END;
-    v=(rgb32 *)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(rgb32)));
-    if (!v) nrerror("allocation failure in realloc_rgb32vector()");
-    
-    return v-nl+NR_END;
-}
-/* ---------------------------------------------------------- */
-IMAGE_EXPORT(void**) realloc_vvector(void **v, long nl, long nh)
-/* ---------------------------------------------------------- */
-/*
-* add n item to an void* vector with subscript range
-* fromv[nl..nh] to [nl..nh+n] */
-{
-    v += nl;
-    v -= NR_END;
-    v=(void**)realloc(v, (size_t) ((nh-nl+1+NR_END)*sizeof(void*)));
-    if (!v) nrerror("allocation failure in realloc vvector()");
-    
-    return v-nl+NR_END;
-}
-/*
- * -------------------
- * --- free_vector ---
- * -------------------
- */
+remote_type_vector(int8_t);
+remote_type_vector(uint8_t);
+remote_type_vector(int16_t);
+remote_type_vector(uint16_t);
+remote_type_vector(int32_t);
+remote_type_vector(uint32_t);
+remote_type_vector(int64_t);
+remote_type_vector(uint64_t);
+remote_type_vector(float);
+remote_type_vector(double);
+remote_type_vector(void_p);
+remote_type_vector(rgb8);
+remote_type_vector(rgbx8);
+remote_type_vector(rgb32);
 
-/* free a byte vector allocated with bvector() */
+#endif
 
-/* ------------------------------------------------------- */
-IMAGE_EXPORT(void) free_si8vector(sint8 *v, long nl, long nh)
-/* ------------------------------------------------------- */
-{
-    free((FREE_ARG) (v+nl-NR_END));
-}
-/* ------------------------------------------------------- */
-IMAGE_EXPORT(void) free_ui8vector(uint8 *v, long nl, long nh)
-/* ------------------------------------------------------- */
-{
-    free((FREE_ARG) (v+nl-NR_END));
-}
-/* --------------------------------------------------------- */
-IMAGE_EXPORT(void) free_si16vector(sint16 *v, long nl, long nh)
-/* --------------------------------------------------------- */
-{
-    free((FREE_ARG) (v+nl-NR_END));
-}
-/* ------------------------------------------------------- */
-IMAGE_EXPORT(void) free_ui16vector(uint16 *v, long nl, long nh)
-/* ------------------------------------------------------- */
-{
-    free((FREE_ARG) (v+nl-NR_END));
-}
-/* --------------------------------------------------------- */
-IMAGE_EXPORT(void) free_si32vector(sint32 *v, long nl, long nh)
-/* --------------------------------------------------------- */
-{
-    free((FREE_ARG) (v+nl-NR_END));
-}
-/* --------------------------------------------------------- */
-IMAGE_EXPORT(void) free_ui32vector(uint32 *v, long nl, long nh)
-/* --------------------------------------------------------- */
-{
-    free((FREE_ARG) (v+nl-NR_END));
-}
-/* --------------------------------------------------------- */
-IMAGE_EXPORT(void) free_si64vector(sint64 *v, long nl, long nh)
-/* --------------------------------------------------------- */
-{
-    free((FREE_ARG) (v+nl-NR_END));
-}
-/* --------------------------------------------------------- */
-IMAGE_EXPORT(void) free_ui64vector(uint64 *v, long nl, long nh)
-/* --------------------------------------------------------- */
-{
-    free((FREE_ARG) (v+nl-NR_END));
-}
-/* ---------------------------------------------------- */
-IMAGE_EXPORT(void) free_f32vector(float32 *v, long nl, long nh)
-/* ---------------------------------------------------- */
-{
-    free((FREE_ARG) (v+nl-NR_END));
-}
-/* ---------------------------------------------------- */
-IMAGE_EXPORT(void) free_f64vector(float64 *v, long nl, long nh)
-/* ---------------------------------------------------- */
-{
-    free((FREE_ARG) (v+nl-NR_END));
-}
-/* -------------------------------------------------------- */
-IMAGE_EXPORT(void) free_rgb8vector(rgb8 *v, long nl, long nh)
-/* -------------------------------------------------------- */
-{
-    free((FREE_ARG) (v+nl-NR_END));
-}
-/* --------------------------------------------------------- */
-IMAGE_EXPORT(void) free_rgbx8vector(rgbx8 *v, long nl, long nh)
-/* --------------------------------------------------------- */
-{
-    free((FREE_ARG) (v+nl-NR_END));
-}
-/* ------------------------------------------------------- */
-IMAGE_EXPORT(void) free_rgb32vector(rgb32 *v, long nl, long nh)
-/* ------------------------------------------------------- */
-{
-    free((FREE_ARG) (v+nl-NR_END));
-}
-/* ----------------------------------------------------- */
-IMAGE_EXPORT(void) free_vvector(void **v, long nl, long nh)
-/* ----------------------------------------------------- */
-{
-    free((FREE_ARG) (v+nl-NR_END));
-}
+// 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/nralloc2.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc2.c	(revision 805)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc2.c	(revision 821)
@@ -30,15 +30,14 @@
 #include <malloc.h>
 #include <math.h> // fabs
-// #include <memory.h> // memcpy
-
+
+#include "nrc_os_config.h"
 #include "mypredef.h"
 #include "nrtype.h"
+#include "nrtypex.h"
 #include "nrdef.h"
 #include "nrmacro.h"
 #include "nrkernel.h"
 
-#include "nralloc1.h"
 #include "nralloc2.h"
-//#include "nrarith.h"
 
 /*
@@ -47,1001 +46,210 @@
  * --------------
  */
-/* ------------------------------------------------ */
-float** matrix(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------ */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    float **m;
-    
-    /* allocate pointers to rows */
-    m=(float **) malloc((size_t)((nrow+NR_END)*sizeof(float*)));
-    if (!m) nrerror("allocation failure 1 in matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(float *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(float)));
-    if (!m[nrl]) nrerror("allocation failure 2 in matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* -------------------------------------------------------------- */
-IMAGE_EXPORT(byte**) bmatrix(long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    byte **m;
-    
-    /* allocate pointers to rows */
-    m=(byte **) malloc((size_t)((nrow+NR_END)*sizeof(byte*)));
-    if (!m) nrerror("allocation failure 1 in bmatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(byte *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(byte)));
-    if (!m[nrl]) nrerror("allocation failure 2 in bmatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}/* ---------------------------------------------------------------- */
-IMAGE_EXPORT(sint8**) si8matrix(long nrl, long nrh, long ncl, long nch)
-/* ----------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    sint8 **m;
-    
-    /* allocate pointers to rows */
-    m=(sint8 **) malloc((size_t)((nrow+NR_END)*sizeof(sint8*)));
-    if (!m) nrerror("allocation failure 1 in i8matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(sint8 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(sint8)));
-    if (!m[nrl]) nrerror("allocation failure 2 in i8matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ----------------------------------------------------------------- */
-IMAGE_EXPORT(uint8**) ui8matrix(long nrl, long nrh, long ncl, long nch)
-/* ----------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    uint8 **m;
-    
-    /* allocate pointers to rows */
-    m=(uint8 **) malloc((size_t)((nrow+NR_END)*sizeof(uint8*)));
-    if (!m) nrerror("allocation failure 1 in ui8matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(uint8 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(uint8)));
-    if (!m[nrl]) nrerror("allocation failure 2 in ui8matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ------------------------------------------------------------------- */
-IMAGE_EXPORT(sint16**) si16matrix(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    sint16 **m;
-    
-    /* allocate pointers to rows */
-    m=(sint16 **) malloc((size_t)((nrow+NR_END)*sizeof(sint16*)));
-    if (!m) nrerror("allocation failure 1 in si16matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(sint16 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(sint16)));
-    if (!m[nrl]) nrerror("allocation failure 2 in si16matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ------------------------------------------------------------------- */
-IMAGE_EXPORT(uint16**) ui16matrix(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    uint16 **m;
-    
-    /* allocate pointers to rows */
-    m=(uint16 **) malloc((size_t)((nrow+NR_END)*sizeof(uint16*)));
-    if (!m) nrerror("allocation failure 1 in ui16matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(uint16 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(uint16)));
-    if (!m[nrl]) nrerror("allocation failure 2 in ui16matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++)
-        m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ------------------------------------------------------------------- */
-IMAGE_EXPORT(sint32**) si32matrix(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------- */
-/* allocate a int32 matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    sint32 **m;
-    
-    /* allocate pointers to rows */
-    m=(sint32 **) malloc((size_t)((nrow+NR_END)*sizeof(sint32*)));
-    if (!m) nrerror("allocation failure 1 in si32matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(sint32 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(sint32)));
-    if (!m[nrl]) nrerror("allocation failure 2 in si32matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ------------------------------------------------------------------- */
-IMAGE_EXPORT(uint32**) ui32matrix(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------- */
-/* allocate a uint32 matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    uint32 **m;
-    
-    /* allocate pointers to rows */
-    m=(uint32 **) malloc((size_t)((nrow+NR_END)*sizeof(uint32*)));
-    if (!m) nrerror("allocation failure 1 in ui32matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(uint32 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(uint32)));
-    if (!m[nrl]) nrerror("allocation failure 2 in ui32matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++)
-        m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ------------------------------------------------------------------- */
-IMAGE_EXPORT(sint64**) si64matrix(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------- */
-/* allocate a int64 matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    sint64 **m;
-    
-    /* allocate pointers to rows */
-    m=(sint64 **) malloc((size_t)((nrow+NR_END)*sizeof(sint64*)));
-    if (!m) nrerror("allocation failure 1 in si64matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(sint64 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(sint64)));
-    if (!m[nrl]) nrerror("allocation failure 2 in si64matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ------------------------------------------------------------------- */
-IMAGE_EXPORT(uint64**) ui64matrix(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------- */
-/* allocate a int64 matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    uint64 **m;
-    
-    /* allocate pointers to rows */
-    m=(uint64 **) malloc((size_t)((nrow+NR_END)*sizeof(uint64*)));
-    if (!m) nrerror("allocation failure 1 in ui64matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(uint64 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(uint64)));
-    if (!m[nrl]) nrerror("allocation failure 2 in ui64matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ------------------------------------------------------------------- */
-IMAGE_EXPORT(float32**) f32matrix(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------- */
-/* allocate a float matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    float32 **m;
-    
-    /* allocate pointers to rows */
-    m=(float32 **) malloc((size_t)((nrow+NR_END)*sizeof(float32*)));
-    if (!m) nrerror("allocation failure 1 in f32matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(float32 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(float32)));
-    if (!m[nrl]) nrerror("allocation failure 2 in f32matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}/* ------------------------------------------------------------------- */
-IMAGE_EXPORT(float64**) f64matrix(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------- */
-
-/* allocate a float matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    float64 **m;
-    
-    /* allocate pointers to rows */
-    m=(float64 **) malloc((size_t)((nrow+NR_END)*sizeof(float64*)));
-    if (!m) nrerror("allocation failure 1 in f64matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(float64 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(float64)));
-    if (!m[nrl]) nrerror("allocation failure 2 in f64matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* --------------------------------------------------------------------- */
-IMAGE_EXPORT(complex32**) c32matrix(long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------- */
-/* allocate a complex32 matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    complex32 **m;
-    
-    /* allocate pointers to rows */
-    m=(complex32 **) malloc((size_t)((nrow+NR_END)*sizeof(complex32*)));
-    if (!m) nrerror("allocation failure 1 in c32matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(complex32 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(complex32)));
-    if (!m[nrl]) nrerror("allocation failure 2 in c32matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* --------------------------------------------------------------------- */
-IMAGE_EXPORT(complex64**) c64matrix(long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------- */
-/* allocate a complex32 matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    complex64 **m;
-    
-    /* allocate pointers to rows */
-    m=(complex64 **) malloc((size_t)((nrow+NR_END)*sizeof(complex64*)));
-    if (!m) nrerror("allocation failure 1 in c64matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(complex64 *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(complex64)));
-    if (!m[nrl]) nrerror("allocation failure 2 in c64matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ----------------------------------------------------------------- */
-IMAGE_EXPORT(rgb8**) rgb8matrix(long nrl, long nrh, long ncl, long nch)
-/* ----------------------------------------------------------------- */
-/* allocate a sint16  matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    rgb8 **m;
-    
-    /* allocate pointers to rows */
-    m=(rgb8**) malloc((size_t)((nrow+NR_END)*sizeof(rgb8*)));
-    if (!m) nrerror("allocation failure 1 in rgb8matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(rgb8*) malloc((size_t)((nrow*ncol+NR_END)*sizeof(rgb8)));
-    if (!m[nrl]) nrerror("allocation failure 2 in rgb8matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ------------------------------------------------------------------- */
-IMAGE_EXPORT(rgbx8**) rgbx8matrix(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------- */
-/* allocate a sint16  matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    rgbx8 **m;
-    
-    /* allocate pointers to rows */
-    m=(rgbx8**) malloc((size_t)((nrow+NR_END)*sizeof(rgbx8*)));
-    if (!m) nrerror("allocation failure 1 in rgbx8matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(rgbx8*) malloc((size_t)((nrow*ncol+NR_END)*sizeof(rgbx8)));
-    if (!m[nrl]) nrerror("allocation failure 2 in rgbx8matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ------------------------------------------------------------------- */
-IMAGE_EXPORT(rgb32**) rgb32matrix(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------- */
-/* allocate a sint16  matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    rgb32 **m;
-    
-    /* allocate pointers to rows */
-    m=(rgb32**) malloc((size_t)((nrow+NR_END)*sizeof(rgb32*)));
-    if (!m) nrerror("allocation failure 1 in rgb32matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(rgb32*) malloc((size_t)((nrow*ncol+NR_END)*sizeof(rgb32)));
-    if (!m[nrl]) nrerror("allocation failure 2 in rgb32matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* --------------------------------------------------------------------- */
-IMAGE_EXPORT(rgbx32**) rgbx32matrix(long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------- */
-/* allocate a sint16  matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    rgbx32 **m;
-    
-    /* allocate pointers to rows */
-    m=(rgbx32**) malloc((size_t)((nrow+NR_END)*sizeof(rgbx32*)));
-    if (!m) nrerror("allocation failure 1 in rgbx32matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(rgbx32*) malloc((size_t)((nrow*ncol+NR_END)*sizeof(rgbx32)));
-    if (!m[nrl]) nrerror("allocation failure 2 in rgbx32matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-
-/*
- * ---------------
- * --- matrix0 ---
- * ---------------
- */
-
-/* --------------------------------------------------------------- */
-IMAGE_EXPORT(byte**) bmatrix0(long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------- */
-/* allocate a byte matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    byte **m;
-    
-    /* allocate pointers to rows */
-    m=(byte **) malloc((size_t)((nrow+NR_END)*sizeof(byte*)));
-    if (!m) nrerror("allocation failure 1 in bmatrix0()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(byte *) calloc((size_t)(nrow*ncol+NR_END),sizeof(byte));
-    if (!m[nrl]) nrerror("allocation failure 2 in bmatrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ------------------------------------------------------------------ */
-IMAGE_EXPORT(sint8**) si8matrix0(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------ */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    sint8 **m;
-    
-    /* allocate pointers to rows */
-    m=(sint8 **) malloc((size_t)((nrow+NR_END)*sizeof(sint8*)));
-    if (!m) nrerror("allocation failure 1 in i8matrix0()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(sint8 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(sint8));
-    if (!m[nrl]) nrerror("allocation failure 2 in imatrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ------------------------------------------------------------------ */
-IMAGE_EXPORT(uint8**) ui8matrix0(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------ */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    uint8 **m;
-    
-    /* allocate pointers to rows */
-    m=(uint8 **) malloc((size_t)((nrow+NR_END)*sizeof(uint8*)));
-    if (!m) nrerror("allocation failure 1 in ui8matrix0()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(uint8 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(uint8));
-    if (!m[nrl]) nrerror("allocation failure 2 in ui8matrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* -------------------------------------------------------------------- */
-IMAGE_EXPORT(sint16**) si16matrix0(long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------- */
-/* allocate a sint16  matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    sint16 **m;
-    
-    /* allocate pointers to rows */
-    m=(sint16 **) malloc((size_t)((nrow+NR_END)*sizeof(sint16*)));
-    if (!m) nrerror("allocation failure 1 in si16matrix0()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(sint16 *) calloc(nrow*ncol, sizeof(int16));
-    if (!m[nrl]) nrerror("allocation failure 2 in si16matrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* -------------------------------------------------------------------- */
-IMAGE_EXPORT(uint16**) ui16matrix0(long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------- */
-/* allocate a sint16  matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    uint16 **m;
-    
-    /* allocate pointers to rows */
-    m=(uint16 **) malloc((size_t)((nrow+NR_END)*sizeof(uint16*)));
-    if (!m) nrerror("allocation failure 1 in ui16matrix0()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(uint16 *) calloc(nrow*ncol, sizeof(uint16));
-    if (!m[nrl]) nrerror("allocation failure 2 in ui16matrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* -------------------------------------------------------------------- */
-IMAGE_EXPORT(sint32**) si32matrix0(long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------- */
-/* allocate a int32 matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    sint32 **m;
-    
-    /* allocate pointers to rows */
-    m=(sint32 **) malloc((size_t)((nrow+NR_END)*sizeof(sint32*)));
-    if (!m) nrerror("allocation failure 1 in si32matrix0()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(sint32 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(sint32));
-    if (!m[nrl]) nrerror("allocation failure 2 in si32matrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* -------------------------------------------------------------------- */
-IMAGE_EXPORT(uint32**) ui32matrix0(long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------- */
-/* allocate a sint16  matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;  
-    uint32 **m;
-    /* allocate pointers to rows */
-    m=(uint32 **) malloc((size_t)((nrow+NR_END)*sizeof(uint32*)));
-    if (!m) nrerror("allocation failure 1 in ui32matrix0()");
-    m += NR_END;
-    m -= nrl;
-
-    /* allocate rows and set pointers to them */
-    m[nrl]=(uint32 *) calloc((size_t)(nrow*ncol+NR_END), sizeof(uint32));
-    if (!m[nrl]) nrerror("allocation failure 2 in ui32matrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    /* return pointer to array of pointers to rows */
-    return m;    
-}
-/* -------------------------------------------------------------------- */
-IMAGE_EXPORT(sint64**) si64matrix0(long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    sint64 **m;
-    
-    /* allocate pointers to rows */
-    m=(sint64 **) malloc((size_t)((nrow+NR_END)*sizeof(sint64*)));
-    if (!m) nrerror("allocation failure 1 in si64matrix0()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(sint64 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(sint64));
-    if (!m[nrl]) nrerror("allocation failure 2 in si64matrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* -------------------------------------------------------------------- */
-IMAGE_EXPORT(uint64**) ui64matrix0(long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    uint64 **m;
-    
-    /* allocate pointers to rows */
-    m=(uint64 **) malloc((size_t)((nrow+NR_END)*sizeof(uint64*)));
-    if (!m) nrerror("allocation failure 1 in i64matrix0()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(uint64 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(uint64));
-    if (!m[nrl]) nrerror("allocation failure 2 in i64matrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* -------------------------------------------------------------------- */
-IMAGE_EXPORT(float32**) f32matrix0(long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    float32 **m;
-    
-    /* allocate pointers to rows */
-    m=(float32 **) malloc((size_t)((nrow+NR_END)*sizeof(float32*)));
-    if (!m) nrerror("allocation failure 1 in f32matrix0()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(float32 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(float32));
-    if (!m[nrl]) nrerror("allocation failure 2 in f32matrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* -------------------------------------------------------------------- */
-IMAGE_EXPORT(float64**) f64matrix0(long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    float64 **m;
-    
-    /* allocate pointers to rows */
-    m=(float64 **) malloc((size_t)((nrow+NR_END)*sizeof(float64*)));
-    if (!m) nrerror("allocation failure 1 in f64matrix0()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(float64 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(float64));
-    if (!m[nrl]) nrerror("allocation failure 2 in f64matrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ---------------------------------------------------------------------- */
-IMAGE_EXPORT(complex32**) c32matrix0(long nrl, long nrh, long ncl, long nch)
-/* ---------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    complex32 **m;
-    
-    /* allocate pointers to rows */
-    m=(complex32 **) malloc((size_t)((nrow+NR_END)*sizeof(complex32*)));
-    if (!m) nrerror("allocation failure 1 in c32matrix0()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(complex32 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(complex32));
-    if (!m[nrl]) nrerror("allocation failure 2 in c32matrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ---------------------------------------------------------------------- */
-IMAGE_EXPORT(complex64**) c64matrix0(long nrl, long nrh, long ncl, long nch)
-/* ---------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    complex64 **m;
-    
-    /* allocate pointers to rows */
-    m=(complex64 **) malloc((size_t)((nrow+NR_END)*sizeof(complex64*)));
-    if (!m) nrerror("allocation failure 1 in c64matrix0()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(complex64 *) calloc((size_t)(nrow*ncol+NR_END),sizeof(complex64));
-    if (!m[nrl]) nrerror("allocation failure 2 in c64matrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ------------------------------------------------------------------ */
-IMAGE_EXPORT(rgb8**) rgb8matrix0(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------ */
-/* allocate a sint16  matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    rgb8 **m;
-    
-    /* allocate pointers to rows */
-    m=(rgb8**) malloc((size_t)((nrow+NR_END)*sizeof(rgb8*)));
-    if (!m) nrerror("allocation failure 1 in rgb8matrix0()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(rgb8*) calloc((size_t)(nrow*ncol+NR_END), sizeof(rgb8));
-    if (!m[nrl]) nrerror("allocation failure 2 in rgb8matrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* -------------------------------------------------------------------- */
-IMAGE_EXPORT(rgbx8**) rgbx8matrix0(long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------- */
-/* allocate a sint16  matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    rgbx8 **m;
-    
-    /* allocate pointers to rows */
-    m=(rgbx8**) malloc((size_t)((nrow+NR_END)*sizeof(rgbx8*)));
-    if (!m) nrerror("allocation failure 1 in rgbx8matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(rgbx8*) calloc((size_t)(nrow*ncol+NR_END), sizeof(rgbx8));
-    if (!m[nrl]) nrerror("allocation failure 2 in rgbx8matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* -------------------------------------------------------------------- */
-IMAGE_EXPORT(rgb32**) rgb32matrix0(long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------- */
-/* allocate a rgb32 matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    rgb32 **m;
-    
-    /* allocate pointers to rows */
-    m=(rgb32**) malloc((size_t)((nrow+NR_END)*sizeof(rgb32*)));
-    if (!m) nrerror("allocation failure 1 in rgb32matrix0()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(rgb32*) calloc((nrow*ncol+NR_END), sizeof(rgb32));
-    if (!m[nrl]) nrerror("allocation failure 2 in rgb32matrix0()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ---------------------------------------------------------------------- */
-IMAGE_EXPORT(rgbx32**) rgbx32matrix0(long nrl, long nrh, long ncl, long nch)
-/* ---------------------------------------------------------------------- */
-/* allocate a rgb32 matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    rgbx32 **m;
-    
-    /* allocate pointers to rows */
-    m=(rgbx32**) malloc((size_t)((nrow+NR_END)*sizeof(rgbx32*)));
-    if (!m) nrerror("allocation failure 1 in rgbx32matrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(rgbx32*) calloc((size_t)(nrow*ncol+NR_END), sizeof(rgbx32));
-    if (!m[nrl]) nrerror("allocation failure 2 in rgbx32matrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/*
- * -------------------
- * --- free_matrix ---
- * -------------------
- */ 
-
-/* ------------------------------------------------------------- */
-void free_matrix(float **m, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------- */
-/* free a float matrix allocated by matrix() */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* --------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_bmatrix(byte **m, long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* ------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) free_si8matrix(sint8 **m, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------ */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* ------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) free_ui8matrix(uint8 **m, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------ */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_si16matrix(sint16 **m, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------- */
-{  
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_ui16matrix(uint16 **m, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------- */
-{  
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_si32matrix(sint32 **m, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------- */
-{  
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_ui32matrix(uint32 **m, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------- */
-{  
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_si64matrix(sint64 **m, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------- */
-{  
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_ui64matrix(uint64 **m, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------- */
-{  
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_f32matrix(float32 **m, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_f64matrix(float64 **m, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_c32matrix(complex32 **m, long nrl, long nrh, long ncl, long nch)
-/* ---------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_c64matrix(complex64 **m, long nrl, long nrh, long ncl, long nch)
-/* ---------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* ------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) free_rgb8matrix(rgb8 **m, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------ */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_rgbx8matrix(rgbx8 **m, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* ------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) free_rgb32matrix(rgb32 **m, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------ */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_rgbx32matrix(rgbx32 **m, long nrl, long nrh, long ncl, long nch)
-/* ---------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
+
+
+#undef type_matrix
+#define type_matrix(t) \
+t ** short_name(t,,matrix)(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \
+{                                                                              \
+    int32_t nrow = nrh - nrl + 1;                                              \
+    int32_t ncol = nch - ncl + 1;                                              \
+    t ** m;                                                                    \
+    /* allocate pointers to row */                                             \
+    m = malloc((nrow + NR_END) * sizeof(t *));                                 \
+    if (m == NULL) {                                                           \
+        nrerror("*** Error: allocation failure in %s\n", __func__);            \
+    }                                                                          \
+    m += NR_END;                                                               \
+    m -= nrl;                                                                  \
+    /* allocate rows and set pointers to them */                               \
+    m[nrl] = malloc((nrow * ncol + NR_END) * sizeof(t));                       \
+    if (m[nrl] == NULL) {                                                      \
+        nrerror("*** Error: allocation failure in %s\n", __func__);            \
+    }                                                                          \
+    m[nrl] += NR_END;                                                          \
+    m[nrl] -= ncl;                                                             \
+    for (int32_t i = nrl + 1; i <= nrh; i++) {                                 \
+        m[i] = m[i - 1] + ncol;                                                \
+    }                                                                          \
+    /* return pointer to array of pointers to rows */                          \
+    return m;                                                                  \
+}
+
+
+type_matrix(int8_t);
+type_matrix(uint8_t);
+type_matrix(int16_t);
+type_matrix(uint16_t);
+type_matrix(int32_t);
+type_matrix(uint32_t);
+type_matrix(int64_t);
+type_matrix(uint64_t);
+type_matrix(float);
+type_matrix(double);
+type_matrix(void_p);
+type_matrix(rgb8);
+type_matrix(rgbx8);
+type_matrix(rgb32);
+type_matrix(rgbx32);
+type_matrix(complex32);
+type_matrix(complex64);
+type_matrix(si16Point);
+type_matrix(ui16Point);
+type_matrix(si32Point);
+type_matrix(ui32Point);
+type_matrix(f32Point);
+type_matrix(si16Triplet);
+type_matrix(ui16Triplet);
+type_matrix(si32Triplet);
+type_matrix(ui32Triplet);
+type_matrix(f32Triplet);
+
+
+
+
+#undef type_matrix0
+#define type_matrix0(t) \
+t ** short_name(t,,matrix0)(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \
+{                                                                               \
+    int32_t nrow = nrh - nrl + 1;                                               \
+    int32_t ncol = nch - ncl + 1;                                               \
+    t ** m;                                                                     \
+    /* allocate pointers to row */                                              \
+    m = malloc((nrow + NR_END) * sizeof(t *));                                  \
+    if (m == NULL) {                                                            \
+        nrerror("*** Error: allocation failure in %s\n", __func__);             \
+    }                                                                           \
+    m += NR_END;                                                                \
+    m -= nrl;                                                                   \
+    /* allocate rows and set pointers to them */                                \
+    m[nrl] = calloc((nrow * ncol + NR_END), sizeof(t));                         \
+    if (m[nrl] == NULL) {                                                       \
+        nrerror("*** Error: allocation failure in %s\n", __func__);             \
+    }                                                                           \
+    m[nrl] += NR_END;                                                           \
+    m[nrl] -= ncl;                                                              \
+    for (int32_t i = nrl + 1; i <= nrh; i++) {                                  \
+        m[i] = m[i - 1] + ncol;                                                 \
+    }                                                                           \
+    /* return pointer to array of pointers to rows */                           \
+    return m;                                                                   \
+}
+
+
+type_matrix0(int8_t);
+type_matrix0(uint8_t);
+type_matrix0(int16_t);
+type_matrix0(uint16_t);
+type_matrix0(int32_t);
+type_matrix0(uint32_t);
+type_matrix0(int64_t);
+type_matrix0(uint64_t);
+type_matrix0(float);
+type_matrix0(double);
+type_matrix0(void_p);
+type_matrix0(rgb8);
+type_matrix0(rgbx8);
+type_matrix0(rgb32);
+type_matrix0(rgbx32);
+type_matrix0(complex32);
+type_matrix0(complex64);
+
+
+#if TARGET_OS == GIETVM
+
+#undef remote_type_matrix
+#define remote_type_matrix(t) \
+t ** short_name(t,remote_,matrix)(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \
+{                                                                              \
+    int32_t nrow = nrh - nrl + 1;                                              \
+    int32_t ncol = nch - ncl + 1;                                              \
+    t ** m;                                                                    \
+    /* allocate pointers to row */                                             \
+    m = malloc((nrow + NR_END) * sizeof(t *));                                 \
+    if (m == NULL) {                                                           \
+        nrerror("*** Error: allocation failure in %s\n", __func__);            \
+    }                                                                          \
+    m += NR_END;                                                               \
+    m -= nrl;                                                                  \
+    /* allocate rows and set pointers to them */                               \
+    m[nrl] = malloc((nrow * ncol + NR_END) * sizeof(t));                       \
+    if (m[nrl] == NULL) {                                                      \
+        nrerror("*** Error: allocation failure in %s\n", __func__);            \
+    }                                                                          \
+    m[nrl] += NR_END;                                                          \
+    m[nrl] -= ncl;                                                             \
+    for (int32_t i = nrl + 1; i <= nrh; i++) {                                 \
+        m[i] = m[i - 1] + ncol;                                                \
+    }                                                                          \
+    /* return pointer to array of pointers to rows */                          \
+    return m;                                                                  \
+}
+
+
+remote_type_matrix(int8_t);
+remote_type_matrix(uint8_t);
+remote_type_matrix(int16_t);
+remote_type_matrix(uint16_t);
+remote_type_matrix(int32_t);
+remote_type_matrix(uint32_t);
+remote_type_matrix(int64_t);
+remote_type_matrix(uint64_t);
+remote_type_matrix(float);
+remote_type_matrix(double);
+remote_type_matrix(void_p);
+remote_type_matrix(rgb8);
+remote_type_matrix(rgbx8);
+remote_type_matrix(rgb32);
+remote_type_matrix(rgbx32);
+remote_type_matrix(complex32);
+remote_type_matrix(complex64);
+
+#endif
+
+
+#undef free_type_matrix
+#define free_type_matrix(t) \
+void short_name(t,free_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \
+{ \
+    free((FREE_ARG) (m[nrl] + ncl - NR_END)); \
+    free((FREE_ARG) (m + nrl - NR_END)); \
+}
+
+free_type_matrix(int8_t);
+free_type_matrix(uint8_t);
+free_type_matrix(int16_t);
+free_type_matrix(uint16_t);
+free_type_matrix(int32_t);
+free_type_matrix(uint32_t);
+free_type_matrix(int64_t);
+free_type_matrix(uint64_t);
+free_type_matrix(float);
+free_type_matrix(double);
+free_type_matrix(void_p);
+free_type_matrix(rgb8);
+free_type_matrix(rgbx8);
+free_type_matrix(rgb32);
+free_type_matrix(rgbx32);
+free_type_matrix(complex32);
+free_type_matrix(complex64);
+free_type_matrix(si16Point);
+free_type_matrix(ui16Point);
+free_type_matrix(si32Point);
+free_type_matrix(ui32Point);
+free_type_matrix(f32Point);
+free_type_matrix(si16Triplet);
+free_type_matrix(ui16Triplet);
+free_type_matrix(si32Triplet);
+free_type_matrix(ui32Triplet);
+free_type_matrix(f32Triplet);
+
+
+
+// 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/nralloc2x.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc2x.c	(revision 805)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc2x.c	(revision 821)
@@ -17,6 +17,6 @@
 #include <malloc.h>
 #include <math.h> // fabs
-// #include <memory.h> // memcpy
 
+#include "nrc_os_config.h"
 #include "mypredef.h"
 #include "nrtype.h"
@@ -25,516 +25,60 @@
 #include "nrkernel.h"
 
-#include "nralloc1.h"
-#include "nralloc2.h"
 #include "nralloc2x.h"
-//#include "nrarith.h"
 
-/* ----------------------------------------------------------------------- */
-IMAGE_EXPORT(si16Point**) si16Pmatrix(long nrl, long nrh, long ncl, long nch)
-/* ----------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    si16Point **m;
-    
-    /* allocate pointers to rows */
-    m=(si16Point **) malloc((size_t)((nrow+NR_END)*sizeof(si16Point*)));
-    if (!m) nrerror("allocation failure 1 in si16Pmatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(si16Point *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(si16Point)));
-    if (!m[nrl]) nrerror("allocation failure 2 in si16Pmatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ----------------------------------------------------------------------- */
-IMAGE_EXPORT(ui16Point**) ui16Pmatrix(long nrl, long nrh, long ncl, long nch)
-/* ----------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    ui16Point **m;
-    
-    /* allocate pointers to rows */
-    m=(ui16Point **) malloc((size_t)((nrow+NR_END)*sizeof(ui16Point*)));
-    if (!m) nrerror("allocation failure 1 in ui16Pmatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(ui16Point *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(ui16Point)));
-    if (!m[nrl]) nrerror("allocation failure 2 in ui16Pmatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ----------------------------------------------------------------------- */
-IMAGE_EXPORT(si32Point**) si32Pmatrix(long nrl, long nrh, long ncl, long nch)
-/* ----------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    si32Point **m;
-    
-    /* allocate pointers to rows */
-    m=(si32Point **) malloc((size_t)((nrow+NR_END)*sizeof(si32Point*)));
-    if (!m) nrerror("allocation failure 1 in si32Pmatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(si32Point *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(si32Point)));
-    if (!m[nrl]) nrerror("allocation failure 2 in si32Pmatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ----------------------------------------------------------------------- */
-IMAGE_EXPORT(ui32Point**) ui32Pmatrix(long nrl, long nrh, long ncl, long nch)
-/* ----------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    ui32Point **m;
-    
-    /* allocate pointers to rows */
-    m=(ui32Point **) malloc((size_t)((nrow+NR_END)*sizeof(ui32Point*)));
-    if (!m) nrerror("allocation failure 1 in ui32Pmatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(ui32Point *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(ui32Point)));
-    if (!m[nrl]) nrerror("allocation failure 2 in ui32Pmatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ---------------------------------------------------------------------- */
-IMAGE_EXPORT(f32Point**) f32Pmatrix(long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    f32Point **m;
-    
-    /* allocate pointers to rows */
-    m=(f32Point **) malloc((size_t)((nrow+NR_END)*sizeof(f32Point*)));
-    if (!m) nrerror("allocation failure 1 in f32Pmatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(f32Point *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(f32Point)));
-    if (!m[nrl]) nrerror("allocation failure 2 in f32Pmatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ------------------------------------------------------------------------- */
-IMAGE_EXPORT(si16Triplet**) si16Tmatrix(long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    si16Triplet **m;
-    
-    /* allocate pointers to rows */
-    m=(si16Triplet **) malloc((size_t)((nrow+NR_END)*sizeof(si16Triplet*)));
-    if (!m) nrerror("allocation failure 1 in si16Tmatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(si16Triplet *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(si16Triplet)));
-    if (!m[nrl]) nrerror("allocation failure 2 in si16Tmatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ----------------------------------------------------------------------- */
-IMAGE_EXPORT(ui16Triplet**) ui16Tmatrix(long nrl, long nrh, long ncl, long nch)
-/* ----------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    ui16Triplet **m;
-    
-    /* allocate pointers to rows */
-    m=(ui16Triplet **) malloc((size_t)((nrow+NR_END)*sizeof(ui16Triplet*)));
-    if (!m) nrerror("allocation failure 1 in ui16Tmatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(ui16Triplet *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(ui16Triplet)));
-    if (!m[nrl]) nrerror("allocation failure 2 in ui16Tmatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ----------------------------------------------------------------------- */
-IMAGE_EXPORT(si32Triplet**) si32Tmatrix(long nrl, long nrh, long ncl, long nch)
-/* ----------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    si32Triplet **m;
-    
-    /* allocate pointers to rows */
-    m=(si32Triplet**) malloc((size_t)((nrow+NR_END)*sizeof(si32Triplet*)));
-    if (!m) nrerror("allocation failure 1 in si32Tmatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(si32Triplet*) malloc((size_t)((nrow*ncol+NR_END)*sizeof(si32Triplet)));
-    if (!m[nrl]) nrerror("allocation failure 2 in si32Tmatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ----------------------------------------------------------------------- */
-IMAGE_EXPORT(ui32Triplet**) ui32Tmatrix(long nrl, long nrh, long ncl, long nch)
-/* ----------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    ui32Triplet **m;
-    
-    /* allocate pointers to rows */
-    m=(ui32Triplet **) malloc((size_t)((nrow+NR_END)*sizeof(ui32Triplet*)));
-    if (!m) nrerror("allocation failure 1 in ui32Tmatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(ui32Triplet *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(ui32Triplet)));
-    if (!m[nrl]) nrerror("allocation failure 2 in ui32Tmatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ---------------------------------------------------------------------- */
-IMAGE_EXPORT(f32Triplet**) f32Tmatrix(long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------- */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1;
-    f32Triplet **m;
-    
-    /* allocate pointers to rows */
-    m=(f32Triplet **) malloc((size_t)((nrow+NR_END)*sizeof(f32Triplet*)));
-    if (!m) nrerror("allocation failure 1 in f32Tmatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(f32Triplet *) malloc((size_t)((nrow*ncol+NR_END)*sizeof(f32Triplet)));
-    if (!m[nrl]) nrerror("allocation failure 2 in f32Tmatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) m[i]=m[i-1]+ncol;
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_si16Pmatrix(si16Point **m, long nrl, long nrh, long ncl, long nch)
-/* ---------------------------------------------------------------------------------- */
-/* free an si16Point matrix allocated by si16Pmatrix() */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_ui16Pmatrix(ui16Point **m, long nrl, long nrh, long ncl, long nch)
-/* ---------------------------------------------------------------------------------- */
-/* free an ui16Point matrix allocated by ui16Pmatrix() */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* ------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) free_si32Pmatrix(si32Point **m, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------------ */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* ------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) free_ui32Pmatrix(ui32Point **m, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------------ */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_f32Pmatrix(f32Point **m, long nrl, long nrh, long ncl, long nch)
-/* ---------------------------------------------------------------------------------- */
-/* free an f32Point matrix allocated by f32Pmatrix() */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_si16Tmatrix(si16Triplet **m, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------------- */
-/* free an si16Point matrix allocated by si16Pmatrix() */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_ui16Tmatrix(ui16Triplet **m, long nrl, long nrh, long ncl, long nch)
-/* ---------------------------------------------------------------------------------- */
-/* free an ui16Point matrix allocated by ui16Pmatrix() */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* ------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) free_si32Tmatrix(si32Triplet **m, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------------ */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_ui32Tmatrix(ui32Triplet **m, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
-/* ------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) free_f32Tmatrix(f32Triplet **m, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------------ */
-/* free an f32Point matrix allocated by f32Pmatrix() */
-{
-    free((FREE_ARG) (m[nrl]+ncl-NR_END));
-    free((FREE_ARG) (m+nrl-NR_END));
-}
 
 /* ----------------- */
 /* --- trimatrix --- */
 /* ----------------- */
-/* ---------------------------------------------------------------------------- */
-IMAGE_EXPORT(byte**) btrimatrix(long nrl, long nrh, long ncl, long nch, long step)
-/* ---------------------------------------------------------------------------- */
-/* allocate an byte triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1, n = nrow * ncol + (nrow * (nrow-1) * step) / 2;
-    // Attention, factorisation of n IS NOT PERMITTED : (nrow-1)step/2 is not even!!!
-    byte **m;
-    
-    /* allocate pointers to rows */
-    m=(byte **) malloc((size_t)((nrow+NR_END)*sizeof(byte*)));
-    if (!m) nrerror("allocation failure 1 in btrimatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(byte *) malloc((size_t)((n+NR_END)*sizeof(byte)));
-    if (!m[nrl]) nrerror("allocation failure 2 in btrimatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) { m[i]=m[i-1]+ncol; ncol += step; }
-    
-    /* return pointer to array of pointers to rows */
-    return m;
+
+
+#undef type_trimatrix
+#define type_trimatrix(t) \
+t ** short_name(t,,trimatrix)(int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int32_t step) \
+/* allocate an byte triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */               \
+{                                                                                               \
+    int32_t nrow = nrh - nrl + 1;                                                               \
+    int32_t ncol = nch - ncl + 1;                                                               \
+    int n = nrow * ncol + (nrow * (nrow - 1) * step) / 2;                                       \
+    /* Attention, factorisation of n IS NOT PERMITTED : (nrow - 1) step / 2 is not even!!! */   \
+    t ** m;                                                                                     \
+    /* allocate pointers to rows */                                                             \
+    m = malloc((nrow + NR_END) * sizeof(t *));                                                  \
+    if (m == NULL) {                                                                            \
+        nrerror("*** Error: allocation failure in %s\n", __func__);                             \
+    }                                                                                           \
+    m += NR_END;                                                                                \
+    m -= nrl;                                                                                   \
+    /* allocate rows and set pointers to them */                                                \
+    m[nrl] = malloc(((n + NR_END) * sizeof(t)));                                                \
+    if (m[nrl] == NULL) {                                                                       \
+        nrerror("*** Error: allocation failure in %s\n", __func__);                             \
+    }                                                                                           \
+    m[nrl] += NR_END;                                                                           \
+    m[nrl] -= ncl;                                                                              \
+    for (int32_t i = nrl + 1; i <= nrh;i++) {                                                   \
+        m[i] = m[i - 1] + ncol;                                                                 \
+        ncol += step;                                                                           \
+    }                                                                                           \
+    /* return pointer to array of pointers to rows */                                           \
+    return m;                                                                                   \
 }
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(sint16**) si16trimatrix(long nrl, long nrh, long ncl, long nch, long step)
-/* --------------------------------------------------------------------------------- */
-/* allocate an i16 triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1, n = nrow * ncol + (nrow * (nrow-1) * step) / 2;
-    // Attention, factorisation of n IS NOT PERMITTED : (nrow-1)step/2 is not even!!!
-    sint16 **m;
-    
-    /* allocate pointers to rows */
-    m=(sint16 **) malloc((size_t)((nrow+NR_END)*sizeof(sint16*)));
-    if (!m) nrerror("allocation failure 1 in i16trimatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(int16*) malloc((size_t)((n+NR_END)*sizeof(int16)));
-    if (!m[nrl]) nrerror("allocation failure 2 in i16trimatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) { m[i]=m[i-1]+ncol; ncol += step; }
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(uint16**) ui16trimatrix(long nrl, long nrh, long ncl, long nch, long step)
-/* --------------------------------------------------------------------------------- */
-/* allocate an i16 triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1, n = nrow * ncol + (nrow * (nrow-1) * step) / 2;
-    // Attention, factorisation of n IS NOT PERMITTED : (nrow-1)step/2 is not even!!!
-    uint16 **m;
-    
-    /* allocate pointers to rows */
-    m=(uint16 **) malloc((size_t)((nrow+NR_END)*sizeof(uint16*)));
-    if (!m) nrerror("allocation failure 1 in ui16trimatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(uint16*) malloc((size_t)((n+NR_END)*sizeof(uint16)));
-    if (!m[nrl]) nrerror("allocation failure 2 in i16trimatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) { m[i]=m[i-1]+ncol; ncol += step; }
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(sint32**) si32trimatrix(long nrl, long nrh, long ncl, long nch, long step)
-/* --------------------------------------------------------------------------------- */
-/* allocate an i32 triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1, n = nrow * ncol + (nrow * (nrow-1) * step) / 2;
-    // Attention, factorisation of n IS NOT PERMITTED : (nrow-1)step/2 is not even!!!
-    sint32 **m;
-    
-    /* allocate pointers to rows */
-    m=(sint32 **) malloc((size_t)((nrow+NR_END)*sizeof(sint32*)));
-    if (!m) nrerror("allocation failure 1 in si32trimatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(sint32*) malloc((size_t)((n+NR_END)*sizeof(sint32)));
-    if (!m[nrl]) nrerror("allocation failure 2 in si32trimatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) { m[i]=m[i-1]+ncol; ncol += step; }
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* -------------------------------------------------------------------------------- */
-IMAGE_EXPORT(uint32**) i32trimatrix(long nrl, long nrh, long ncl, long nch, long step)
-/* -------------------------------------------------------------------------------- */
-/* allocate an i32 triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1, n = nrow * ncol + (nrow * (nrow-1) * step) / 2;
-    // Attention, factorisation of n IS NOT PERMITTED : (nrow-1)step/2 is not even!!!
-    uint32 **m;
-    
-    /* allocate pointers to rows */
-    m=(uint32 **) malloc((size_t)((nrow+NR_END)*sizeof(uint32*)));
-    if (!m) nrerror("allocation failure 1 in ui32trimatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(uint32*) malloc((size_t)((n+NR_END)*sizeof(uint32)));
-    if (!m[nrl]) nrerror("allocation failure 2 in i32trimatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) { m[i]=m[i-1]+ncol; ncol += step; }
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(float32**) f32trimatrix(long nrl, long nrh, long ncl, long nch, long step)
-/* --------------------------------------------------------------------------------- */
-/* allocate an f32 triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1, n = nrow * ncol + (nrow * (nrow-1) * step) / 2;
-    // Attention, factorisation of n IS NOT PERMITTED : (nrow-1)step/2 is not even!!!
-    float32 **m;
-    
-    /* allocate pointers to rows */
-    m=(float32 **) malloc((size_t)((nrow+NR_END)*sizeof(float32*)));
-    if (!m) nrerror("allocation failure 1 in f32trimatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(float32*) malloc((size_t)((n+NR_END)*sizeof(float32)));
-    if (!m[nrl]) nrerror("allocation failure 2 in f32trimatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) { m[i]=m[i-1]+ncol; ncol += step; }
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(float64**) f64trimatrix(long nrl, long nrh, long ncl, long nch, long step)
-/* --------------------------------------------------------------------------------- */
-/* allocate an f64 triangle-matrix with subscript range m[nrl..nrh][ncl..nch] */
-{
-    long i, nrow=nrh-nrl+1,ncol=nch-ncl+1, n = nrow * ncol + (nrow * (nrow-1) * step) / 2;
-    // Attention, factorisation of n IS NOT PERMITTED : (nrow-1)step/2 is not even!!!
-    float64 **m;
-    
-    /* allocate pointers to rows */
-    m=(float64 **) malloc((size_t)((nrow+NR_END)*sizeof(float64*)));
-    if (!m) nrerror("allocation failure 1 in f64trimatrix()");
-    m += NR_END;
-    m -= nrl;
-    
-    
-    /* allocate rows and set pointers to them */
-    m[nrl]=(float64*) malloc((size_t)((n+NR_END)*sizeof(float64)));
-    if (!m[nrl]) nrerror("allocation failure 2 in f64trimatrix()");
-    m[nrl] += NR_END;
-    m[nrl] -= ncl;
-    
-    for(i=nrl+1;i<=nrh;i++) { m[i]=m[i-1]+ncol; ncol += step; }
-    
-    /* return pointer to array of pointers to rows */
-    return m;
-}
+
+
+type_trimatrix(int8_t);
+type_trimatrix(uint8_t);
+type_trimatrix(int16_t);
+type_trimatrix(uint16_t);
+type_trimatrix(int32_t);
+type_trimatrix(uint32_t);
+type_trimatrix(float);
+type_trimatrix(double);
+
+// Local Variables:
+// tab-width: 4
+// c-basic-offset: 4
+// c-file-offsets:((innamespace . 0)(inline-open . 0))
+// indent-tabs-mode: nil
+// End:
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
+
Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc3.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc3.c	(revision 805)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nralloc3.c	(revision 821)
@@ -31,6 +31,7 @@
 #include <string.h> // memcpy
 #include <math.h> // fabs
-// #include <memory.h> // memcpy
 
+
+#include "nrc_os_config.h"
 #include "mypredef.h"
 #include "nrtype.h"
@@ -39,7 +40,89 @@
 #include "nrkernel.h"
 
-#include "nralloc1.h"
 #include "nralloc3.h"
 
+
+#undef type_cube
+#define type_cube(t) \
+t *** short_name(t,,cube)(int32_t ndl, int32_t ndh, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \
+{                                                                                                       \
+    int32_t ndep = ndh - ndl + 1;                                                                       \
+    int32_t nrow = nrh - nrl + 1;                                                                       \
+    int32_t nrol = nch - ncl + 1;                                                                       \
+    t *** c;                                                                                            \
+    /* allocate pointers to pointers to rows */                                                         \
+    c = malloc((ndep + NR_END) * sizeof(t **));                                                         \
+    if (c == NULL) {                                                                                    \
+        nrerror("*** Error: allocation failure in %s\n", __func__);                                     \
+    }                                                                                                   \
+    c += NR_END;                                                                                        \
+    c -= ndl;                                                                                           \
+    /* allocate pointers to rows anc set pointers to them */                                            \
+    c[ndl] = malloc((ndep * nrow + NR_END) * sizeof(t *));                                              \
+    if (c[ndl] == NULL) {                                                                               \
+        nrerror("*** Error: allocation failure in %s\n", __func__);                                     \
+    }                                                                                                   \
+    c[ndl] += NR_END;                                                                                   \
+    c[ndl] -= nrl;                                                                                      \
+    /* allocate rows anc set pointers to them */                                                        \
+    c[ndl][nrl] = malloc((ndep * nrow * nrol + NR_END) * sizeof(t));                                    \
+    if (c[ndl][nrl]) {                                                                                  \
+        nrerror("*** Error: allocation failure in %s\n", __func__);                                     \
+    }                                                                                                   \
+    c[ndl][nrl] += NR_END;                                                                              \
+    c[ndl][nrl] -= ncl;                                                                                 \
+                                                                                                        \
+    for(int32_t j = nrl + 1; j <= nrh; j++) {                                                           \
+        c[ndl][j] = c[ndl][j - 1] + nrol;                                                               \
+    }                                                                                                   \
+    for(int32_t i = ndl + 1; i <= ndh; i++) {                                                           \
+        c[i] = c[i - 1] + nrow;                                                                         \
+        c[i][nrl] = c[i - 1][nrl] + nrow * nrol;                                                        \
+        for (int32_t j = nrl + 1; j <= nrh; j++) {                                                      \
+            c[i][j] = c[i][j - 1] + nrol;                                                               \
+        }                                                                                               \
+    }                                                                                                   \
+    /* return pointer to array of pointers to rows */                                                   \
+    return t;                                                                                           \
+}
+
+
+type_cube(int8_t);
+type_cube(uint8_t);
+type_cube(int16_t);
+type_cube(uint16_t);
+type_cube(int32_t);
+type_cube(uint32_t);
+type_cube(int64_t);
+type_cube(uint64_t);
+type_cube(float);
+type_cube(double);
+type_cube(rgb8);
+type_cube(rgbx8);
+
+#undef free_type_cube
+#define free_type_cube(t) \
+void short_name(t,free_,cube)(t *** c, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, int32_t ndl, int32_t ndh) \
+{                                                                                                        \
+    free((FREE_ARG) (c[nrl][ncl] + ndl - NR_END));                                                       \
+    free((FREE_ARG) (c[nrl] + ncl - NR_END));                                                            \
+    free((FREE_ARG) (c + nrl - NR_END));                                                                 \
+}
+
+free_type_cube(int8_t);
+free_type_cube(uint8_t);
+free_type_cube(int16_t);
+free_type_cube(uint16_t);
+free_type_cube(int32_t);
+free_type_cube(uint32_t);
+free_type_cube(int64_t);
+free_type_cube(uint64_t);
+free_type_cube(float);
+free_type_cube(double);
+free_type_cube(rgb8);
+free_type_cube(rgbx8);
+
+
+#if 0
 /* ----------------------------------------------------------------------- */
 double*** d3tensor(long nrl, long nrh, long ncl, long nch, long ndl, long ndh)
@@ -78,4 +161,6 @@
     return t;
 }
+
+
 /* ------------------------------------------------------------------------------ */
 void free_d3tensor(double ***t,long nrl,long nrh,long ncl,long nch,long ndl,long ndh)
@@ -87,425 +172,13 @@
     free((FREE_ARG) (t+nrl-NR_END));
 }
+#endif
 
-/* ------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(sint8***) si8cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------------ */
-{
-    long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1;
-    sint8 ***t;
-    
-    /* allocate pointers to pointers to rows */
-    t=(sint8***) malloc((size_t)((ndep+NR_END)*sizeof(sint8**)));
-    if (!t) nrerror("allocation failure 1 in si8cube()");
-    t += NR_END;
-    t -= ndl;
-    
-    /* allocate pointers to rows anc set pointers to them */
-    t[ndl]=(sint8**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(sint8*)));
-    if (!t[ndl]) nrerror("allocation failure 2 in si8cube()");
-    t[ndl] += NR_END;
-    t[ndl] -= nrl;
-    
-    /* allocate rows anc set pointers to them */
-    t[ndl][nrl]=(sint8*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(sint8)));
-    if (!t[ndl][nrl]) nrerror("allocation failure 3 in si8cube()");
-    t[ndl][nrl] += NR_END;
-    t[ndl][nrl] -= ncl;
-    
-    for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol;
-    for(i=ndl+1;i<=ndh;i++) {
-        t[i]=t[i-1]+nrow;
-        t[i][nrl]=t[i-1][nrl]+nrow*nrol;
-        for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol;
-    }
-    /* return pointer to array of pointers to rows */
-    return t;
-}
-/* ------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(uint8***) ui8cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------------ */
-{
-    long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1;
-    uint8 ***t;
-    
-    /* allocate pointers to pointers to rows */
-    t=(uint8***) malloc((size_t)((ndep+NR_END)*sizeof(uint8**)));
-    if (!t) nrerror("allocation failure 1 in ui8cube()");
-    t += NR_END;
-    t -= ndl;
-    
-    /* allocate pointers to rows anc set pointers to them */
-    t[ndl]=(uint8**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(uint8*)));
-    if (!t[ndl]) nrerror("allocation failure 2 in ui8cube()");
-    t[ndl] += NR_END;
-    t[ndl] -= nrl;
-    
-    /* allocate rows anc set pointers to them */
-    t[ndl][nrl]=(uint8*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(uint8)));
-    if (!t[ndl][nrl]) nrerror("allocation failure 3 in ui8cube()");
-    t[ndl][nrl] += NR_END;
-    t[ndl][nrl] -= ncl;
-    
-    for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol;
-    for(i=ndl+1;i<=ndh;i++) {
-        t[i]=t[i-1]+nrow;
-        t[i][nrl]=t[i-1][nrl]+nrow*nrol;
-        for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol;
-    }
-    /* return pointer to array of pointers to rows */
-    return t;
-}
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(sint16***) si16cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------------- */
-{
-    long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1;
-    sint16 ***t;
-    
-    /* allocate pointers to pointers to rows */
-    t=(sint16 ***) malloc((size_t)((ndep+NR_END)*sizeof(sint16**)));
-    if (!t) nrerror("allocation failure 1 in si16cube()");
-    t += NR_END;
-    t -= ndl;
-    
-    /* allocate pointers to rows anc set pointers to them */
-    t[ndl]=(sint16 **) malloc((size_t)((ndep*nrow+NR_END)*sizeof(sint16*)));
-    if (!t[ndl]) nrerror("allocation failure 2 in si16cube()");
-    t[ndl] += NR_END;
-    t[ndl] -= nrl;
-    
-    /* allocate rows anc set pointers to them */
-    t[ndl][nrl]=(sint16 *) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(sint16)));
-    if (!t[ndl][nrl]) nrerror("allocation failure 3 in si16cube()");
-    t[ndl][nrl] += NR_END;
-    t[ndl][nrl] -= ncl;
-    
-    for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol;
-    for(i=ndl+1;i<=ndh;i++) {
-        t[i]=t[i-1]+nrow;
-        t[i][nrl]=t[i-1][nrl]+nrow*nrol;
-        for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol;
-    }
-    /* return pointer to array of pointers to rows */
-    return t;
-}
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(uint16***) ui16cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------------- */
-{
-    long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1;
-    uint16 ***t;
-    
-    /* allocate pointers to pointers to rows */
-    t=(uint16***) malloc((size_t)((ndep+NR_END)*sizeof(uint16**)));
-    if (!t) nrerror("allocation failure 1 in ui16cube()");
-    t += NR_END;
-    t -= ndl;
-    
-    /* allocate pointers to rows anc set pointers to them */
-    t[ndl]=(uint16**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(uint16*)));
-    if (!t[ndl]) nrerror("allocation failure 2 in ui16cube()");
-    t[ndl] += NR_END;
-    t[ndl] -= nrl;
-    
-    /* allocate rows anc set pointers to them */
-    t[ndl][nrl]=(uint16*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(uint16)));
-    if (!t[ndl][nrl]) nrerror("allocation failure 3 in ui16cube()");
-    t[ndl][nrl] += NR_END;
-    t[ndl][nrl] -= ncl;
-    
-    for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol;
-    for(i=ndl+1;i<=ndh;i++) {
-        t[i]=t[i-1]+nrow;
-        t[i][nrl]=t[i-1][nrl]+nrow*nrol;
-        for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol;
-    }
-    /* return pointer to array of pointers to rows */
-    return t;
-}
-/* ------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(sint32***) si32cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------------ */
-{
-    long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1;
-    sint32 ***t;
-    
-    /* allocate pointers to pointers to rows */
-    t=(sint32***) malloc((size_t)((ndep+NR_END)*sizeof(sint32**)));
-    if (!t) nrerror("allocation failure 1 in si32cube()");
-    t += NR_END;
-    t -= ndl;
-    
-    /* allocate pointers to rows anc set pointers to them */
-    t[ndl]=(sint32**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(sint32*)));
-    if (!t[ndl]) nrerror("allocation failure 2 in si32cube()");
-    t[ndl] += NR_END;
-    t[ndl] -= nrl;
-    
-    /* allocate rows anc set pointers to them */
-    t[ndl][nrl]=(sint32*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(sint32)));
-    if (!t[ndl][nrl]) nrerror("allocation failure 3 in si32cube()");
-    t[ndl][nrl] += NR_END;
-    t[ndl][nrl] -= ncl;
-    
-    for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol;
-    for(i=ndl+1;i<=ndh;i++) {
-        t[i]=t[i-1]+nrow;
-        t[i][nrl]=t[i-1][nrl]+nrow*nrol;
-        for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol;
-    }
-    /* return pointer to array of pointers to rows */
-    return t;
-}
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(uint32***) ui32cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------------- */
-{
-    long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1;
-    uint32 ***t;
-    
-    /* allocate pointers to pointers to rows */
-    t=(uint32***) malloc((size_t)((ndep+NR_END)*sizeof(uint32**)));
-    if (!t) nrerror("allocation failure 1 in ui32cube()");
-    t += NR_END;
-    t -= ndl;
-    
-    /* allocate pointers to rows anc set pointers to them */
-    t[ndl]=(uint32**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(uint32*)));
-    if (!t[ndl]) nrerror("allocation failure 2 in ui32cube()");
-    t[ndl] += NR_END;
-    t[ndl] -= nrl;
-    
-    /* allocate rows anc set pointers to them */
-    t[ndl][nrl]=(uint32*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(uint32)));
-    if (!t[ndl][nrl]) nrerror("allocation failure 3 in ui32cube()");
-    t[ndl][nrl] += NR_END;
-    t[ndl][nrl] -= ncl;
-    
-    for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol;
-    for(i=ndl+1;i<=ndh;i++) {
-        t[i]=t[i-1]+nrow;
-        t[i][nrl]=t[i-1][nrl]+nrow*nrol;
-        for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol;
-    }
-    /* return pointer to array of pointers to rows */
-    return t;
-}
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(float32***) f32cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------------- */
-{
-    long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1;
-    float32 ***t;
-    
-    /* allocate pointers to pointers to rows */
-    t=(float32***) malloc((size_t)((ndep+NR_END)*sizeof(float32**)));
-    if (!t) nrerror("allocation failure 1 in f32cube()");
-    t += NR_END;
-    t -= ndl;
-    
-    /* allocate pointers to rows anc set pointers to them */
-    t[ndl]=(float32**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(float32*)));
-    if (!t[ndl]) nrerror("allocation failure 2 in f32cube()");
-    t[ndl] += NR_END;
-    t[ndl] -= nrl;
-    
-    /* allocate rows anc set pointers to them */
-    t[ndl][nrl]=(float32*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(float32)));
-    if (!t[ndl][nrl]) nrerror("allocation failure 3 in f32cube()");
-    t[ndl][nrl] += NR_END;
-    t[ndl][nrl] -= ncl;
-    
-    for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol;
-    for(i=ndl+1;i<=ndh;i++) {
-        t[i]=t[i-1]+nrow;
-        t[i][nrl]=t[i-1][nrl]+nrow*nrol;
-        for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol;
-    }
-    /* return pointer to array of pointers to rows */
-    return t;
-}
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(float64***) f64cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------------- */
-{
-    long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1;
-    float64 ***t;
-    
-    /* allocate pointers to pointers to rows */
-    t=(float64***) malloc((size_t)((ndep+NR_END)*sizeof(float64**)));
-    if (!t) nrerror("allocation failure 1 in f32cube()");
-    t += NR_END;
-    t -= ndl;
-    
-    /* allocate pointers to rows anc set pointers to them */
-    t[ndl]=(float64**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(float64*)));
-    if (!t[ndl]) nrerror("allocation failure 2 in f64cube()");
-    t[ndl] += NR_END;
-    t[ndl] -= nrl;
-    
-    /* allocate rows anc set pointers to them */
-    t[ndl][nrl]=(float64*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(float64)));
-    if (!t[ndl][nrl]) nrerror("allocation failure 3 in f64cube()");
-    t[ndl][nrl] += NR_END;
-    t[ndl][nrl] -= ncl;
-    
-    for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol;
-    for(i=ndl+1;i<=ndh;i++) {
-        t[i]=t[i-1]+nrow;
-        t[i][nrl]=t[i-1][nrl]+nrow*nrol;
-        for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol;
-    }
-    /* return pointer to array of pointers to rows */
-    return t;
-}
-/* ------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(rgb8***) rgb8cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------------ */
-/* allocate a rgb8 cube with range t[ndl..ndh][nrl..nrh][ncl..nch] */
-{
-    long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1;
-    rgb8 ***t;
-    
-    /* allocate pointers to pointers to rows */
-    t=(rgb8***) malloc((size_t)((ndep+NR_END)*sizeof(rgb8**)));
-    if (!t) nrerror("allocation failure 1 in rgb8cube()");
-    t += NR_END;
-    t -= ndl;
-    
-    /* allocate pointers to rows anc set pointers to them */
-    t[ndl]=(rgb8**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(rgb8*)));
-    if (!t[ndl]) nrerror("allocation failure 2 in rgb8cube()");
-    t[ndl] += NR_END;
-    t[ndl] -= nrl;
-    
-    /* allocate rows anc set pointers to them */
-    t[ndl][nrl]=(rgb8*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(rgb8)));
-    if (!t[ndl][nrl]) nrerror("allocation failure 3 in rgb8cube()");
-    t[ndl][nrl] += NR_END;
-    t[ndl][nrl] -= ncl;
-    
-    for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol;
-    for(i=ndl+1;i<=ndh;i++) {
-        t[i]=t[i-1]+nrow;
-        t[i][nrl]=t[i-1][nrl]+nrow*nrol;
-        for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol;
-    }
-    /* return pointer to array of pointers to rows */
-    return t;
-}
-/* -------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(rgbx8***) rgbx8cube(long ndl, long ndh, long nrl, long nrh, long ncl, long nch)
-/* -------------------------------------------------------------------------------------- */
-/* allocate a rgb8 cube with range t[ndl..ndh][nrl..nrh][ncl..nch] */
-{
-    long i,j,ndep=ndh-ndl+1,nrow=nrh-nrl+1,nrol=nch-ncl+1;
-    rgbx8 ***t;
-    
-    /* allocate pointers to pointers to rows */
-    t=(rgbx8***) malloc((size_t)((ndep+NR_END)*sizeof(rgbx8**)));
-    if (!t) nrerror("allocation failure 1 in rgbx8cube()");
-    t += NR_END;
-    t -= ndl;
-    
-    /* allocate pointers to rows anc set pointers to them */
-    t[ndl]=(rgbx8**) malloc((size_t)((ndep*nrow+NR_END)*sizeof(rgbx8*)));
-    if (!t[ndl]) nrerror("allocation failure 2 in rgbx8cube()");
-    t[ndl] += NR_END;
-    t[ndl] -= nrl;
-    
-    /* allocate rows anc set pointers to them */
-    t[ndl][nrl]=(rgbx8*) malloc((size_t)((ndep*nrow*nrol+NR_END)*sizeof(rgbx8)));
-    if (!t[ndl][nrl]) nrerror("allocation failure 3 in rgbx8cube()");
-    t[ndl][nrl] += NR_END;
-    t[ndl][nrl] -= ncl;
-    
-    for(j=nrl+1;j<=nrh;j++) t[ndl][j]=t[ndl][j-1]+nrol;
-    for(i=ndl+1;i<=ndh;i++) {
-        t[i]=t[i-1]+nrow;
-        t[i][nrl]=t[i-1][nrl]+nrow*nrol;
-        for(j=nrl+1;j<=nrh;j++) t[i][j]=t[i][j-1]+nrol;
-    }
-    /* return pointer to array of pointers to rows */
-    return t;
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_si8cube(sint8 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh)
-/* ------------------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END));
-    free((FREE_ARG) (c[nrl]+ncl-NR_END));
-    free((FREE_ARG) (c+nrl-NR_END));
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_ui8cube(uint8 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh)
-/* ------------------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END));
-    free((FREE_ARG) (c[nrl]+ncl-NR_END));
-    free((FREE_ARG) (c+nrl-NR_END));
-}
-/* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_si16cube(sint16 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh)
-/* --------------------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END));
-    free((FREE_ARG) (c[nrl]+ncl-NR_END));
-    free((FREE_ARG) (c+nrl-NR_END));
-}
-/* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_ui16cube(uint16 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh)
-/* --------------------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END));
-    free((FREE_ARG) (c[nrl]+ncl-NR_END));
-    free((FREE_ARG) (c+nrl-NR_END));
-}
-/* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_si32cube(sint32 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh)
-/* --------------------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END));
-    free((FREE_ARG) (c[nrl]+ncl-NR_END));
-    free((FREE_ARG) (c+nrl-NR_END));
-}
-/* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_ui32cube(uint32 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh)
-/* --------------------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END));
-    free((FREE_ARG) (c[nrl]+ncl-NR_END));
-    free((FREE_ARG) (c+nrl-NR_END));
-}
-/* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_f32cube(float32 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh)
-/* --------------------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END));
-    free((FREE_ARG) (c[nrl]+ncl-NR_END));
-    free((FREE_ARG) (c+nrl-NR_END));
-}
-/* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_f64cube(float64 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh)
-/* --------------------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END));
-    free((FREE_ARG) (c[nrl]+ncl-NR_END));
-    free((FREE_ARG) (c+nrl-NR_END));
-}
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_rgb8cube(rgb8 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh)
-/* ------------------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END));
-    free((FREE_ARG) (c[nrl]+ncl-NR_END));
-    free((FREE_ARG) (c+nrl-NR_END));
-}
-/* --------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) free_rgbx8cube(rgbx8 ***c,long nrl,long nrh,long ncl,long nch,long ndl,long ndh)
-/* --------------------------------------------------------------------------------------------- */
-{
-    free((FREE_ARG) (c[nrl][ncl]+ndl-NR_END));
-    free((FREE_ARG) (c[nrl]+ncl-NR_END));
-    free((FREE_ARG) (c+nrl-NR_END));
-}
+// 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/nrarith0.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrarith0.c	(revision 805)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrarith0.c	(revision 821)
@@ -22,4 +22,5 @@
 #include <math.h>
 
+#include "nrc_os_config.h"
 #include "mypredef.h"
 #include "nrtype.h"
@@ -30,12 +31,22 @@
 #include "nrarith0.h"
 
-ROUTINE(void)    i8swap(int8    *a, int8    *b) { int8    *t; t=a; a=b; b=t;}
-ROUTINE(void)   i16swap(int16   *a, int16   *b) { int16   *t; t=a; a=b; b=t;}
-ROUTINE(void)   i32swap(int32   *a, int32   *b) { int32   *t; t=a; a=b; b=t;}
-ROUTINE(void)   i64swap(int64   *a, int64   *b) { int64   *t; t=a; a=b; b=t;}
-ROUTINE(void)   f32swap(float32 *a, float32 *b) { float32 *t; t=a; a=b; b=t;}
-ROUTINE(void)   f64swap(float64 *a, float64 *b) { float64 *t; t=a; a=b; b=t;}
-ROUTINE(void)  rgb8swap(rgb8    *a, rgb8    *b) { rgb8    *t; t=a; a=b; b=t;}
-ROUTINE(void) rgbx8swap(rgbx8   *a, rgbx8   *b) { rgbx8   *t; t=a; a=b; b=t;}
+#undef type_swap
+#define type_swap(t)                   \
+void short_name(t,,swap)(t * a, t * b) \
+{                                      \
+    t c;                               \
+    c = *a;                            \
+    *a = *b;                           \
+    *b = c;                            \
+}
+
+type_swap(int8_t);
+type_swap(int16_t);
+type_swap(int32_t);
+type_swap(int64_t);
+type_swap(float);
+type_swap(double);
+type_swap(rgb8);
+type_swap(rgbx8);
 
 /* --------- */
@@ -43,39 +54,41 @@
 /* --------- */
 
-ROUTINE(float32)  f32min  (float32 x1, float32 x2)                                    {if (x1<x2)  return x1; else  return x2;}
-ROUTINE(float32)  f32min2 (float32 x1, float32 x2)                                     {if (x1<x2)  return x1; else  return x2;}
-ROUTINE(float32)  f32min3 (float32 x1, float32 x2, float32 x3)                         {return f32min2(f32min2(x1, x2), x3);}
-ROUTINE(float32)  f32min4 (float32 x1, float32 x2, float32 x3, float32 x4)             {return f32min2(f32min2(x1, x2), f32min2(x3, x4));}
-ROUTINE(float32)  f32min5 (float32 x1, float32 x2, float32 x3, float32 x4, float32 x5) {return f32min3(f32min2(x1, x2), f32min2(x3, x4), x5);}
-
-ROUTINE(float64)  f64min  (float64 x1, float64 x2)                                     {if (x1<x2)  return x1; else  return x2;}
-ROUTINE(float64)  f64min2 (float64 x1, float64 x2)                                     {if (x1<x2)  return x1; else  return x2;}
-ROUTINE(float64)  f64min3 (float64 x1, float64 x2, float64 x3)                         {return f64min2(f64min2(x1, x2), x3);}
-ROUTINE(float64)  f64min4 (float64 x1, float64 x2, float64 x3, float64 x4)             {return f64min2(f64min2(x1, x2), f64min2(x3, x4));}
-ROUTINE(float64)  f64min5 (float64 x1, float64 x2, float64 x3, float64 x4, float64 x5) {return f64min3(f64min2(x1, x2), f64min2(x3, x4), x5);}
-
-ROUTINE(uint8)  ui8min (uint8 x1, uint8 x2)                               {if (x1<x2)  return x1; else  return x2;}
-ROUTINE(uint8)  ui8min2(uint8 x1, uint8 x2)                               {if (x1<x2)  return x1; else  return x2;}
-ROUTINE(uint8)  ui8min3(uint8 x1, uint8 x2, uint8 x3)                     {return ui8min2(ui8min2(x1, x2), x3);}
-ROUTINE(uint8)  ui8min4(uint8 x1, uint8 x2, uint8 x3, uint8 x4)           {return ui8min2(ui8min2(x1, x2), ui8min2(x3, x4));}
-ROUTINE(uint8)  ui8min5(uint8 x1, uint8 x2, uint8 x3, uint8 x4, uint8 x5) {return ui8min3(ui8min2(x1, x2), ui8min2(x3, x4), x5);}
-
-ROUTINE(uint16) ui16min (uint16 x1, uint16 x2)                                  {if (x1<x2)  return x1; else  return x2;}
-ROUTINE(uint16) ui16min2(uint16 x1, uint16 x2)                                  {if (x1<x2)  return x1; else  return x2;}
-ROUTINE(uint16) ui16min3(uint16 x1, uint16 x2, uint16 x3)                       {return ui16min2(ui16min2(x1, x2), x3);}
-ROUTINE(uint16) ui16min4(uint16 x1, uint16 x2, uint16 x3, uint16 x4)            {return ui16min2(ui16min2(x1, x2), ui16min2(x3, x4));}
-ROUTINE(uint16) ui16min5(uint16 x1, uint16 x2, uint16 x3, uint16 x4, uint16 x5) {return ui16min3(ui16min2(x1, x2), ui16min2(x3, x4), x5);}
-
-ROUTINE(int32) ui32min (uint32 x1, uint32 x2)                                  {if (x1<x2)  return x1; else  return x2;}
-ROUTINE(int32) ui32min2(uint32 x1, uint32 x2)                                  {if (x1<x2)  return x1; else  return x2;}
-ROUTINE(int32) ui32min3(uint32 x1, uint32 x2, uint32 x3)                       {return ui32min2(ui32min2(x1, x2), x3);}
-ROUTINE(int32) ui32min4(uint32 x1, uint32 x2, uint32 x3, uint32 x4)            {return ui32min2(ui32min2(x1, x2), ui32min2(x3, x4));}
-ROUTINE(int32) ui32min5(uint32 x1, uint32 x2, uint32 x3, uint32 x4, uint32 x5) {return ui32min3(ui32min2(x1, x2), ui32min2(x3, x4), x5);}
-
-ROUTINE(rgb8) rgb8min (rgb8 x1, rgb8 x2)                            {rgb8 y; y.r = ui8min2(x1.r,x2.r);y.g=ui8min2(x1.g,x2.g);y.b=ui8min2(x1.b,x2.b);return y;}
-ROUTINE(rgb8) rgb8min2(rgb8 x1, rgb8 x2)                            {rgb8 y; y.r = ui8min2(x1.r,x2.r);y.g=ui8min2(x1.g,x2.g);y.b=ui8min2(x1.b,x2.b);return y;}
-ROUTINE(rgb8) rgb8min3(rgb8 x1, rgb8 x2, rgb8 x3)                   {return rgb8min2(rgb8min2(x1, x2), x3);}
-ROUTINE(rgb8) rgb8min4(rgb8 x1, rgb8 x2, rgb8 x3, rgb8 x4)          {return rgb8min2(rgb8min2(x1, x2), rgb8min2(x3,x4));}
-ROUTINE(rgb8) rgb8min5(rgb8 x1, rgb8 x2, rgb8 x3, rgb8 x4, rgb8 x5) {return rgb8min3(rgb8min2(x1, x2), rgb8min2(x3,x4), x5);}
+#undef type_min
+#define type_min(t)               \
+t short_name(t,,min)(t x1, t x2)  \
+{                                 \
+    return (x1 < x2) ? x1 : x2;   \
+}                                 \
+t short_name(t,,min2)(t x1, t x2) \
+{                                 \
+    return (x1 < x2) ? x1 : x2;   \
+}                                 \
+t short_name(t,,min3)(t x1, t x2, t x3)                          \
+{                                                                \
+    return short_name(t,,min2)(short_name(t,,min2)(x1, x2), x3); \
+}                                                                \
+t short_name(t,,min4)(t x1, t x2, t x3, t x4)                                                 \
+{                                                                                             \
+    return short_name(t,,min2)(short_name(t,,min2)(x1, x2), short_name(t,,min2)(x3, x4));     \
+}                                                                                             \
+t short_name(t,,min5)(t x1, t x2, t x3, t x4, t x5)                                           \
+{                                                                                             \
+    return short_name(t,,min3)(short_name(t,,min2)(x1, x2), short_name(t,,min2)(x3, x4), x5); \
+}
+
+type_min(float);
+type_min(double);
+type_min(int8_t);
+type_min(uint8_t);
+type_min(int16_t);
+type_min(uint16_t);
+type_min(int32_t);
+type_min(uint32_t);
+
+rgb8 rgb8min (rgb8 x1, rgb8 x2)                            {rgb8 y; y.r = ui8min2(x1.r,x2.r);y.g=ui8min2(x1.g,x2.g);y.b=ui8min2(x1.b,x2.b);return y;}
+rgb8 rgb8min2(rgb8 x1, rgb8 x2)                            {rgb8 y; y.r = ui8min2(x1.r,x2.r);y.g=ui8min2(x1.g,x2.g);y.b=ui8min2(x1.b,x2.b);return y;}
+rgb8 rgb8min3(rgb8 x1, rgb8 x2, rgb8 x3)                   {return rgb8min2(rgb8min2(x1, x2), x3);}
+rgb8 rgb8min4(rgb8 x1, rgb8 x2, rgb8 x3, rgb8 x4)          {return rgb8min2(rgb8min2(x1, x2), rgb8min2(x3,x4));}
+rgb8 rgb8min5(rgb8 x1, rgb8 x2, rgb8 x3, rgb8 x4, rgb8 x5) {return rgb8min3(rgb8min2(x1, x2), rgb8min2(x3,x4), x5);}
 
 /* --------- */
@@ -83,33 +96,35 @@
 /* --------- */
 
-ROUTINE(float32) f32max (float32 x1, float32 x2)                                     {if (x1>x2)  return x1; else  return x2;}
-ROUTINE(float32) f32max2(float32 x1, float32 x2)                                     {if (x1>x2)  return x1; else  return x2;}
-ROUTINE(float32) f32max3(float32 x1, float32 x2, float32 x3)                         {return f32max2(f32max2(x1, x2), x3);}
-ROUTINE(float32) f32max4(float32 x1, float32 x2, float32 x3, float32 x4)             {return f32max2(f32max2(x1, x2), f32max2(x3, x4));}
-ROUTINE(float32) f32max5(float32 x1, float32 x2, float32 x3, float32 x4, float32 x5) {return f32max3(f32max2(x1, x2), f32max2(x3, x4), x5);}
-
-ROUTINE(float64)  f64max  (float64 x1, float64 x2)                                     {if (x1>x2)  return x1; else  return x2;}
-ROUTINE(float64)  f64max2 (float64 x1, float64 x2)                                     {if (x1>x2)  return x1; else  return x2;}
-ROUTINE(float64)  f64max3 (float64 x1, float64 x2, float64 x3)                         {return f64max2(f64max2(x1, x2), x3);}
-ROUTINE(float64)  f64max4 (float64 x1, float64 x2, float64 x3, float64 x4)             {return f64max2(f64max2(x1, x2), f64max2(x3, x4));}
-ROUTINE(float64)  f64max5 (float64 x1, float64 x2, float64 x3, float64 x4, float64 x5) {return f64max3(f64max2(x1, x2), f64max2(x3, x4), x5);}
-
-ROUTINE(uint8) ui8max (uint8 x1, uint8 x2)                               {if (x1>x2)  return x1; else  return x2;}
-ROUTINE(uint8) ui8max2(uint8 x1, uint8 x2)                               {if (x1>x2)  return x1; else  return x2;}
-ROUTINE(uint8) ui8max3(uint8 x1, uint8 x2, uint8 x3)                     {return ui8max2(ui8max2(x1, x2), x3);}
-ROUTINE(uint8) ui8max4(uint8 x1, uint8 x2, uint8 x3, uint8 x4)           {return ui8max2(ui8max2(x1, x2), ui8max2(x3, x4));}
-ROUTINE(uint8) ui8max5(uint8 x1, uint8 x2, uint8 x3, uint8 x4, uint8 x5) {return ui8max3(ui8max2(x1, x2), ui8max2(x3, x4), x5);}
-
-ROUTINE(uint16) ui16max (uint16 x1, uint16 x2)                                  {if (x1>x2)  return x1; else  return x2;}
-ROUTINE(uint16) ui16max2(uint16 x1, uint16 x2)                                  {if (x1>x2)  return x1; else  return x2;}
-ROUTINE(uint16) ui16max3(uint16 x1, uint16 x2, uint16 x3)                       {return ui16max2(ui16max2(x1, x2), x3);}
-ROUTINE(uint16) ui16max4(uint16 x1, uint16 x2, uint16 x3, uint16 x4)            {return ui16max2(ui16max2(x1, x2), ui16max2(x3, x4));}
-ROUTINE(uint16) ui16max5(uint16 x1, uint16 x2, uint16 x3, uint16 x4, uint16 x5) {return ui16max3(ui16max2(x1, x2), ui16max2(x3, x4), x5);}
-
-ROUTINE(int32) ui32max (uint32 x1, uint32 x2)                                 {if (x1>x2) return x1; else  return x2;}
-ROUTINE(int32) ui32max2(uint32 x1, uint32 x2)                                 {if (x1>x2) return x1; else  return x2;}
-ROUTINE(int32) ui32max3(uint32 x1, uint32 x2, uint32 x3)                      {return ui32max2(ui32max2(x1, x2), x3);}
-ROUTINE(int32) ui32max4(uint32 x1, uint32 x2, uint32 x3, uint32 x4)           {return ui32max2(ui32max2(x1, x2), ui32max2(x3, x4));}
-ROUTINE(int32) ui32max5(uint32 x1, uint32 x2, uint32 x3, uint32 x4, int32 x5) {return ui32max3(ui32max2(x1, x2), ui32max2(x3, x4), x5);}
+#undef type_max
+#define type_max(t)               \
+t short_name(t,,max)(t x1, t x2)  \
+{                                 \
+    return (x1 > x2) ? x1 : x2;   \
+}                                 \
+t short_name(t,,max2)(t x1, t x2) \
+{                                 \
+    return (x1 > x2) ? x1 : x2;   \
+}                                 \
+t short_name(t,,max3)(t x1, t x2, t x3)                          \
+{                                                                \
+    return short_name(t,,max2)(short_name(t,,max2)(x1, x2), x3); \
+}                                                                \
+t short_name(t,,max4)(t x1, t x2, t x3, t x4)                                                 \
+{                                                                                             \
+    return short_name(t,,max2)(short_name(t,,max2)(x1, x2), short_name(t,,max2)(x3, x4));     \
+}                                                                                             \
+t short_name(t,,max5)(t x1, t x2, t x3, t x4, t x5)                                           \
+{                                                                                             \
+    return short_name(t,,max3)(short_name(t,,max2)(x1, x2), short_name(t,,max2)(x3, x4), x5); \
+}
+
+type_max(float);
+type_max(double);
+type_max(int8_t);
+type_max(uint8_t);
+type_max(int16_t);
+type_max(uint16_t);
+type_max(int32_t);
+type_max(uint32_t);
 
 ROUTINE(rgb8) rgb8max (rgb8 x1, rgb8 x2)                            {rgb8 y; y.r = ui8max2(x1.r,x2.r);y.g=ui8max2(x1.g,x2.g);y.b=ui8max2(x1.b,x2.b);return y;}
@@ -124,63 +139,79 @@
 
 /* ------------------------------- */
-ROUTINE(int32) i32bit(int32 x, int n)
+int32_t i32bit(int32_t x, int32_t n)
 /* ------------------------------- */
 {
-  return ((x>>n)&1);
-}
+    return ((x >> n) & 1);
+}
+
 /* --------------------------- */
-ROUTINE(int32) sym_int32(int32 x)
+int32_t sym_int32(int32_t x)
 /* --------------------------- */
 {
-  int i;
-  int32 y = 0;
-  for(i=0; i<31; i++) {
-    y = y | (x & 1);
-    x = x >> 1;
-  }
-  y = y | x;
-  return y;
+    int32_t y = 0;
+    for (int32_t i = 0; i < 31; i++) {
+        y = y | (x & 1);
+        x = x >> 1;
+    }
+    y = y | x;
+    return y;
 }
 
 
 /* ----------------------- */
-ROUTINE(int) ilog2(int x)
+int32_t ilog2(int32_t x)
 /* ----------------------- */
 {
-  int s = 0;
-  while(x) {
-    x >>= 1;
-    s++;
-  }
-  return s - 1;
-}
+    int32_t s = 0;
+    while (x) {
+        x >>= 1;
+        s++;
+    }
+    return s - 1;
+}
+
 /* ----------------------------- */
-ROUTINE(int) next_power2(int x)
+int32_t next_power2(int32_t x)
 /* ----------------------------- */
 {
-  int s = ilog2(x);
-  int n = 1 << s;
-  
-  if(x != n)
-    return n << 1;
-  else
-    return n;
-}
-/* ---------------------------- */
-ROUTINE(int) gcd(int u, int v)
-/* ---------------------------- */
-{
-  int r;
-  while(v) {
-    r = u % v;
-    u = v;
-    v = r;
-  }
-  return u;
-}
-/* ---------------------------- */
-ROUTINE(int) lcm(int u, int v)
-/* ---------------------------- */
-{
-  return (u*v)/gcd(u,v);
-}
+    int32_t s = ilog2(x);
+    int32_t n = 1 << s;
+
+    if (x != n) {
+        return n << 1;
+    }
+    else {
+        return n;
+    }
+}
+
+/* ---------------------------- */
+int32_t myGCD(int32_t u, int32_t v)
+/* ---------------------------- */
+{
+    int32_t r;
+    while (v != 0) {
+        r = u % v;
+        u = v;
+        v = r;
+    }
+    return u;
+}
+
+/* ---------------------------- */
+int32_t myLCM(int32_t u, int32_t v)
+/* ---------------------------- */
+{
+    return (u * v) / myGCD(u, v);
+}
+
+
+// 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/nrarith1.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrarith1.c	(revision 805)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrarith1.c	(revision 821)
@@ -20,6 +20,6 @@
 #include <malloc.h>
 #include <math.h> // fabs
-// #include <memory.h> // memcpy
-
+
+#include "nrc_os_config.h"
 #include "mypredef.h"
 #include "nrtype.h"
@@ -28,5 +28,4 @@
 #include "nrkernel.h"
 
-//#include "nralloc.h"
 #include "nrarith1.h"
 
@@ -37,92 +36,23 @@
  */
 
-/* -------------------------------------------------------- */
-IMAGE_EXPORT(sint32) sum_si8vector(sint8 *v, long nl, long nh)
-/* -------------------------------------------------------- */
-{
-	int i;
-    sint32 s = 0;
-	for(i=nl; i<=nh; i++) {
-		s += v[i];
-	}
-	return s;
-}
-/* -------------------------------------------------------- */
-IMAGE_EXPORT(uint32) sum_u8ivector(uint8 *v, long nl, long nh)
-/* -------------------------------------------------------- */
-{
-	int i;
-    uint32 s = 0;
-	for(i=nl; i<=nh; i++) {
-		s += v[i];
-	}
-	return s;
-}
-/* ---------------------------------------------------------- */
-IMAGE_EXPORT(sint32) sum_si16vector(sint16 *v, long nl, long nh)
-/* ---------------------------------------------------------- */
-{
-	int i;
-    sint32 s = 0;
-	for(i=nl; i<=nh; i++) {
-		s += v[i];
-	}
-	return s;
-}
-/* ---------------------------------------------------------- */
-IMAGE_EXPORT(uint32) sum_u16ivector(uint16 *v, long nl, long nh)
-/* ---------------------------------------------------------- */
-{
-	int i;
-    uint32 s = 0;
-	for(i=nl; i<=nh; i++) {
-		s += v[i];
-	}
-	return s;
-}
-/* ---------------------------------------------------------- */
-IMAGE_EXPORT(sint32) sum_si32vector(sint32 *v, long nl, long nh)
-/* ---------------------------------------------------------- */
-{
-	int i;
-    sint32 s = 0;
-	for(i=nl; i<=nh; i++) {
-		s += v[i];
-	}
-	return s;
-}
-/* ---------------------------------------------------------- */
-IMAGE_EXPORT(uint32) sum_u32ivector(uint32 *v, long nl, long nh)
-/* ---------------------------------------------------------- */
-{
-	int i;
-    uint32 s = 0;
-	for(i=nl; i<=nh; i++) {
-		s += v[i];
-	}
-	return s;
-}
-/* ----------------------------------------------------------- */
-IMAGE_EXPORT(float32) sum_f32vector(float32 *v, long nl, long nh)
-/* ----------------------------------------------------------- */
-{
-	int i;
-	float32 s = 0.0f;
-	for(i=nl; i<=nh; i++) {
-		s += v[i];
-	}
-	return s;
-}
-/* ----------------------------------------------------------- */
-IMAGE_EXPORT(float64) sum_f64vector(float64 *v, long nl, long nh)
-/* ----------------------------------------------------------- */
-{
-	int i;
-	float64 s = 0.0;
-	for(i=nl; i<=nh; i++) {
-		s += v[i];
-	}
-	return s;
-}
+#undef sum_type_vector
+#define sum_type_vector(t,r)                                     \
+r short_name(t,sum_,vector)(t * v, int32_t nl, int32_t nh)       \
+{                                                                \
+    r s = 0;                                                     \
+    for (int32_t i = nl; i <= nh; i++) {                         \
+        s += v[i];                                               \
+    }                                                            \
+    return s;                                                    \
+}
+
+sum_type_vector(int8_t, int32_t);
+sum_type_vector(uint8_t, uint32_t);
+sum_type_vector(int16_t, int32_t);
+sum_type_vector(uint16_t, uint32_t);
+sum_type_vector(int32_t, int32_t);
+sum_type_vector(uint32_t, uint32_t);
+sum_type_vector(float, float);
+sum_type_vector(double, double);
 
 /*
@@ -132,108 +62,27 @@
  */
 
-/* ------------------------------------------------------- */
-IMAGE_EXPORT(sint8) min_si8vector(sint8 *v, long nl, long nh)
-/* ------------------------------------------------------- */
-{
-	int i;
-	uint8  m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]<m) m = v[i];
-	}
-	return m;
-}
-/* ------------------------------------------------------- */
-IMAGE_EXPORT(uint8) min_ui8vector(uint8 *v, long nl, long nh)
-/* ------------------------------------------------------- */
-{
-	int i;
-	uint8  m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]<m) m = v[i];
-	}
-	return m;
-}
-/* ---------------------------------------------------------- */
-IMAGE_EXPORT(sint16) min_si16vector(sint16 *v, long nl, long nh)
-/* ---------------------------------------------------------- */
-{
-	int i;
-	int16 m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]<m) m = v[i];
-	}
-	return m;
-}
-/* ---------------------------------------------------------- */
-IMAGE_EXPORT(uint16) min_ui16vector(uint16 *v, long nl, long nh)
-/* ---------------------------------------------------------- */
-{
-	int i;
-	uint16 m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]<m) m = v[i];
-	}
-	return m;
-}
-/* ---------------------------------------------------------- */
-IMAGE_EXPORT(sint32) min_si32vector(sint32 *v, long nl, long nh)
-/* ---------------------------------------------------------- */
-{
-	int i;
-	int16 m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]<m) m = v[i];
-	}
-	return m;
-}
-/* ---------------------------------------------------------- */
-IMAGE_EXPORT(uint32) min_ui32vector(uint32 *v, long nl, long nh)
-/* ---------------------------------------------------------- */
-{
-	int i;
-	uint32 m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]<m) m = v[i];
-	}
-	return m;
-}
-/* ----------------------------------------------------------- */
-IMAGE_EXPORT(float32) min_f32vector(float32 *v, long nl, long nh)
-/* ----------------------------------------------------------- */
-{
-	int i;
-	float32 m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]<m) m = v[i];
-	}
-	return m;
-}
-/* ----------------------------------------------------------- */
-IMAGE_EXPORT(float64) min_f64vector(float64 *v, long nl, long nh)
-/* ----------------------------------------------------------- */
-{
-	int i;
-	float64 m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]<m) m = v[i];
-	}
-	return m;
-}
+#undef min_type_vector
+#define min_type_vector(t)                                 \
+t short_name(t,min_,vector)(t * v, int32_t nl, int32_t nh) \
+{                                                          \
+    t m = v[nl];                                           \
+    for (int32_t i = nl + 1; i <= nh; i++) {               \
+        if (v[i] < m) {                                    \
+            m = v[i];                                      \
+        }                                                  \
+    }                                                      \
+    return m;                                              \
+}
+
+
+min_type_vector(int8_t);
+min_type_vector(uint8_t);
+min_type_vector(int16_t);
+min_type_vector(uint16_t);
+min_type_vector(int32_t);
+min_type_vector(uint32_t);
+min_type_vector(float);
+min_type_vector(double);
+
 
 /*
@@ -243,108 +92,28 @@
  */
 
-/* ------------------------------------------------------- */
-IMAGE_EXPORT(sint8) max_si8vector(sint8 *v, long nl, long nh)
-/* ------------------------------------------------------- */
-{
-	int i;
-	sint8  m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) m = v[i];
-	}
-	return m;
-}
-/* ------------------------------------------------------- */
-IMAGE_EXPORT(uint8) max_ui8vector(uint8 *v, long nl, long nh)
-/* ------------------------------------------------------- */
-{
-	int i;
-	uint8  m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) m = v[i];
-	}
-	return m;
-}
-/* ---------------------------------------------------------- */
-IMAGE_EXPORT(sint16) max_si16vector(sint16 *v, long nl, long nh)
-/* ---------------------------------------------------------- */
-{
-	int i; 
-	sint16 m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) m = v[i];
-	}
-	return m;
-}
-/* ---------------------------------------------------------- */
-IMAGE_EXPORT(uint16) max_ui16vector(uint16 *v, long nl, long nh)
-/* ---------------------------------------------------------- */
-{
-	int i; 
-	uint16 m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) m = v[i];
-	}
-	return m;
-}
-/* ---------------------------------------------------------- */
-IMAGE_EXPORT(sint32) max_si32vector(sint32 *v, long nl, long nh)
-/* ---------------------------------------------------------- */
-{
-	int i;
-	sint32 m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) m = v[i];
-	}
-	return m;
-}
-/* ---------------------------------------------------------- */
-IMAGE_EXPORT(uint32) max_ui32vector(uint32 *v, long nl, long nh)
-/* ---------------------------------------------------------- */
-{
-	int i;
-	uint32 m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) m = v[i];
-	}
-	return m;
-}
-/* ----------------------------------------------------------- */
-IMAGE_EXPORT(float32) max_f32vector(float32 *v, long nl, long nh)
-/* ----------------------------------------------------------- */
-{
-	int i;
-	float32 m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) m = v[i];
-	}
-	return m;
-}
-/* ----------------------------------------------------------- */
-IMAGE_EXPORT(float64) max_f64vector(float64 *v, long nl, long nh)
-/* ----------------------------------------------------------- */
-{
-	int i;
-	float64 m;
-	
-	m = v[nl];
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) m = v[i];
-	}
-	return m;
-}
+#undef max_type_vector
+#define max_type_vector(t)                                 \
+t short_name(t,max_,vector)(t * v, int32_t nl, int32_t nh) \
+{                                                          \
+    t m = v[nl];                                           \
+    for (int32_t i = nl + 1; i <= nh; i++) {               \
+        if (v[i] > m) {                                    \
+            m = v[i];                                      \
+        }                                                  \
+    }                                                      \
+    return m;                                              \
+}
+
+
+max_type_vector(int8_t);
+max_type_vector(uint8_t);
+max_type_vector(int16_t);
+max_type_vector(uint16_t);
+max_type_vector(int32_t);
+max_type_vector(uint32_t);
+max_type_vector(float);
+max_type_vector(double);
+
+
 /*
  * ----------------------
@@ -353,116 +122,31 @@
  */
 
-/* --------------------------------------------------------------------- */
-IMAGE_EXPORT(sint8) min_si8vector_pos(sint8 *v, long nl, long nh, int *pos)
-/* --------------------------------------------------------------------- */
-{
-	int i;
-	sint8  m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	return m;
-}
-/* --------------------------------------------------------------------- */
-IMAGE_EXPORT(uint8) min_ui8vector_pos(uint8 *v, long nl, long nh, int *pos)
-/* --------------------------------------------------------------------- */
-{
-	int i;
-	uint8  m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	return m;
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(sint16) min_si16vector_pos(sint16 *v, long nl, long nh, int *pos)
-/* ------------------------------------------------------------------------ */
-{
-	int i;
-	sint16 m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	return m;
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(uint16) min_ui16vector_pos(uint16 *v, long nl, long nh, int *pos)
-/* ------------------------------------------------------------------------ */
-{
-	int i;
-	uint16 m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	return m;
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(sint32) min_si32vector_pos(sint32 *v, long nl, long nh, int *pos)
-/* ------------------------------------------------------------------------ */
-{
-	int i;
-	sint32 m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	return m;
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(uint32) min_ui32vector_pos(uint32 *v, long nl, long nh, int *pos)
-/* ------------------------------------------------------------------------ */
-{
-	int i;
-	uint32 m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	return m;
-}
-/* ------------------------------------------------------------------------- */
-IMAGE_EXPORT(float32) min_f32vector_pos(float32 *v, long nl, long nh, int *pos)
-/* ------------------------------------------------------------------------- */
-{
-	int i;
-	float32 m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	return m;
-}
-/* ------------------------------------------------------------------------- */
-IMAGE_EXPORT(float64) min_f64vector_pos(float64 *v, long nl, long nh, int *pos)
-/* ------------------------------------------------------------------------- */
-{
-	int i;
-	float64 m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	return m;
-}
+
+#undef min_type_vector_pos
+#define min_type_vector_pos(t)                                                \
+t short_name(t,min_,vector_pos)(t * v, int32_t nl, int32_t nh, int32_t * pos) \
+{                                                                             \
+    t m = v[nl];                                                              \
+    int32_t p = nl;                                                           \
+    for (int32_t i = nl + 1; i <= nh; i++) {                                  \
+        if (v[i] < m) {                                                       \
+            m = v[i];                                                         \
+            p = i;                                                            \
+        }                                                                     \
+    }                                                                         \
+    *pos = p;                                                                 \
+    return m;                                                                 \
+}
+
+
+min_type_vector_pos(int8_t);
+min_type_vector_pos(uint8_t);
+min_type_vector_pos(int16_t);
+min_type_vector_pos(uint16_t);
+min_type_vector_pos(int32_t);
+min_type_vector_pos(uint32_t);
+min_type_vector_pos(float);
+min_type_vector_pos(double);
+
 
 /*
@@ -472,279 +156,266 @@
  */
 
-/* --------------------------------------------------------------------- */
-IMAGE_EXPORT(sint8) max_si8vector_pos(sint8 *v, long nl, long nh, int *pos)
-/* --------------------------------------------------------------------- */
-{
-	int i;
-	sint8 m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	
-	return m;
-}
-/* --------------------------------------------------------------------- */
-IMAGE_EXPORT(uint8) max_ui8vector_pos(uint8 *v, long nl, long nh, int *pos)
-/* --------------------------------------------------------------------- */
-{
-	int i;
-	uint8 m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	
-	return m;
-}
+
+#undef max_type_vector_pos
+#define max_type_vector_pos(t)                                                \
+t short_name(t,max_,vector_pos)(t * v, int32_t nl, int32_t nh, int32_t * pos) \
+{                                                                             \
+    t m = v[nl];                                                              \
+    int32_t p = nl;                                                           \
+    for (int32_t i = nl + 1; i <= nh; i++) {                                  \
+        if (v[i] > m) {                                                       \
+            m = v[i];                                                         \
+            p = i;                                                            \
+        }                                                                     \
+    }                                                                         \
+    *pos = p;                                                                 \
+    return m;                                                                 \
+}
+
+
+max_type_vector_pos(int8_t);
+max_type_vector_pos(uint8_t);
+max_type_vector_pos(int16_t);
+max_type_vector_pos(uint16_t);
+max_type_vector_pos(int32_t);
+max_type_vector_pos(uint32_t);
+max_type_vector_pos(float);
+max_type_vector_pos(double);
+
+
+#undef add_type_vector
+#define add_type_vector(t) \
+void short_name(t,add_,vector)(t * S1, int32_t nl, int32_t nh, t * S2, t * D) \
+{                                                                             \
+    for (int32_t i = nl; i <= nh; i++) {                                      \
+        D[i] = S1[i] + S2[i];                                                 \
+    }                                                                         \
+}
+
+add_type_vector(int8_t);
+add_type_vector(uint8_t);
+add_type_vector(int16_t);
+add_type_vector(uint16_t);
+add_type_vector(int32_t);
+add_type_vector(uint32_t);
+add_type_vector(float);
+add_type_vector(double);
+
+
+#undef sub_type_vector
+#define sub_type_vector(t) \
+void short_name(t,sub_,vector)(t * S1, int32_t nl, int32_t nh, t * S2, t * D) \
+{                                                                             \
+    for (int32_t i = nl; i <= nh; i++) {                                      \
+        D[i] = S1[i] - S2[i];                                                 \
+    }                                                                         \
+}
+
+sub_type_vector(int8_t);
+sub_type_vector(uint8_t);
+sub_type_vector(int16_t);
+sub_type_vector(uint16_t);
+sub_type_vector(int32_t);
+sub_type_vector(uint32_t);
+sub_type_vector(float);
+sub_type_vector(double);
+
+
+#undef mulc_type_vector
+#define mulc_type_vector(t) \
+void short_name(t,mulc_,vector)(t * S, int32_t nl, int32_t nh, int32_t c, t * D)  \
+{                                                                                 \
+    for (int32_t i = nl; i <= nh; i++) {                                          \
+        D[i] = S[i] * c;                                                          \
+    }                                                                             \
+}
+
+mulc_type_vector(int8_t);
+mulc_type_vector(uint8_t);
+mulc_type_vector(int16_t);
+mulc_type_vector(uint16_t);
+mulc_type_vector(int32_t);
+mulc_type_vector(uint32_t);
+mulc_type_vector(float);
+mulc_type_vector(double);
+
+
+#undef divc_type_vector
+#define divc_type_vector(t) \
+void short_name(t,divc_,vector)(t * S, int32_t nl, int32_t nh, int32_t c, t * D)  \
+{                                                                                 \
+    for (int32_t i = nl; i <= nh; i++) {                                          \
+        D[i] = S[i] / c;                                                          \
+    }                                                                             \
+}
+
+divc_type_vector(int8_t);
+divc_type_vector(uint8_t);
+divc_type_vector(int16_t);
+divc_type_vector(uint16_t);
+divc_type_vector(int32_t);
+divc_type_vector(uint32_t);
+divc_type_vector(float);
+divc_type_vector(double);
+
+
+#undef cumulleft_type_vector
+#define cumulleft_type_vector(t) \
+void short_name(t,cumulleft_,vector)(t * S, int32_t nl, int32_t nh, int32_t * D) \
+{                                                                                \
+    for (int32_t i = nh - 1; i >= nl; i--) {                                     \
+        D[i] += S[i + 1];                                                        \
+    }                                                                            \
+}
+
+cumulleft_type_vector(int8_t);
+cumulleft_type_vector(uint8_t);
+cumulleft_type_vector(int16_t);
+cumulleft_type_vector(uint16_t);
+cumulleft_type_vector(int32_t);
+cumulleft_type_vector(uint32_t);
+cumulleft_type_vector(float);
+cumulleft_type_vector(double);
+
+
+#undef cumulright_type_vector
+#define cumulright_type_vector(t) \
+void short_name(t,cumulright_,vector)(t * S, int32_t nl, int32_t nh, int32_t * D) \
+{                                                                                 \
+    for (int32_t i = nl + 1; i <= nh; i++) {                                      \
+        D[i] += S[i - 1];                                                         \
+    }                                                                             \
+}
+
+cumulright_type_vector(int8_t);
+cumulright_type_vector(uint8_t);
+cumulright_type_vector(int16_t);
+cumulright_type_vector(uint16_t);
+cumulright_type_vector(int32_t);
+cumulright_type_vector(uint32_t);
+cumulright_type_vector(float);
+cumulright_type_vector(double);
+
+
+#undef mulfrac_type_vector
+#define mulfrac_type_vector(t) \
+void short_name(t,mulfrac_,vector)(t * S, int32_t nl, int32_t nh, int32_t a, int32_t b, t * D) \
+{                                                                                              \
+    for (int32_t i = nl; i <= nh; i++) {                                                       \
+        D[i] = (a * S[i]) / b;                                                                 \
+    }                                                                                          \
+}
+
+
+mulfrac_type_vector(int8_t);
+mulfrac_type_vector(uint8_t);
+mulfrac_type_vector(int16_t);
+mulfrac_type_vector(uint16_t);
+mulfrac_type_vector(int32_t);
+mulfrac_type_vector(uint32_t);
+mulfrac_type_vector(float);
+mulfrac_type_vector(double);
+
+
+/* --------------------------------------------------------------------- */
+void beta_sum_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, rgb32 * D)
+/* --------------------------------------------------------------------- */
+{
+    int32_t r, g, b;
+    int32_t s;
+    for (int32_t i = nl; i <= nh; i++) {
+        r = S[i].r;
+        g = S[i].g;
+        b = S[i].b;
+        s = r + g + b;
+        D[i].r = s;
+        D[i].g = s;
+        D[i].b = s;
+    }
+}
+
+/* ----------------------------------------------------------------------- */
+void beta_average_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, rgb32 * D)
+/* ----------------------------------------------------------------------- */
+{
+    int32_t r, g, b;
+    int32_t s;
+    for (int32_t i = nl; i <= nh; i++) {
+        r = S[i].r;
+        g = S[i].g;
+        b = S[i].b;
+        s = (r + g + b) / 3;
+        D[i].r = s;
+        D[i].g = s;
+        D[i].b = s;
+    }
+}
+
 /* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(sint16) max_si16vector_pos(sint16 *v, long nl, long nh, int *pos)
+void mulc_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, int32_t c, rgb32 * D)
 /* ------------------------------------------------------------------------ */
 {
-	int i; 
-	int16 m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	return m;
-}
-/* ----------------------------------------------------------------------- */
-IMAGE_EXPORT(uint16) max_ui16vector_pos(uint16 *v, long nl, long nh, int *pos)
-/* ----------------------------------------------------------------------- */
-{
-	int i; 
-	uint16 m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	
-	return m;
-}
-/* --------------------------------------------------------------------- */
-IMAGE_EXPORT(sint32) max_si32vector_pos(sint32 *v, long nl, long nh, int *pos)
-/* --------------------------------------------------------------------- */
-{
-	int i;
-	sint32 m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	
-	return m;
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(uint32) max_ui32vector_pos(uint32 *v, long nl, long nh, int *pos)
-/* ------------------------------------------------------------------------ */
-{
-	int i;
-	uint32 m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	
-	return m;
-}
-/* ----------------------------------------------------------------------- */
-IMAGE_EXPORT(float32) max_f32vector_pos(float32 *v, long nl, long nh, int *pos)
-/* ----------------------------------------------------------------------- */
-{
-	int i;
-	float32 m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	
-	return m;
-}
-/* ------------------------------------------------------------------------- */
-IMAGE_EXPORT(float64) max_f64vector_pos(float64 *v, long nl, long nh, int *pos)
-/* ------------------------------------------------------------------------- */
-{
-	int i;
-	float64 m = v[nl];
-	int  p = nl;
-	
-	for(i=nl+1; i<=nh; i++) {
-		if(v[i]>m) { m = v[i]; p = i;}
-	}
-	*pos = p;
-	
-	return m;
-}
-/* --------------------------------------------------------------------- */
-IMAGE_EXPORT(void) beta_sum_rgb32vector(rgb32 *S,long nl,long nh, rgb32 *D)
-/* --------------------------------------------------------------------- */
-{
-	long i;
-	int32 r, g, b, s;
-	for(i=nl; i<=nh; i++){
-		r = S[i].r;
-		g = S[i].g;
-		b = S[i].b;
-		s = r + g + b;
-		D[i].r = s;
-		D[i].g = s;
-		D[i].b = s;
-	}
-}
-/* ----------------------------------------------------------------------- */
-IMAGE_EXPORT(void) beta_average_rgb32vector(rgb32 *S,long nl,long nh, rgb32 *D)
-/* ----------------------------------------------------------------------- */
-{
-	long i;
-	int32 r, g, b, s;
-	for(i=nl; i<=nh; i++){
-		r = S[i].r;
-		g = S[i].g;
-		b = S[i].b;
-		s = (r + g + b) / 3;
-		D[i].r = s;
-		D[i].g = s;
-		D[i].b = s;
-	}
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) add_i32vector(int32 *S1,long nl,long nh, int32 *S2, int32 *D)
-/* ------------------------------------------------------------------------ */
-{
-	long i;
-	for(i=nl; i<=nh; i++) D[i] = S1[i] + S2[i];
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) sub_i32vector(int32 *S1,long nl,long nh, int32 *S2, int32 *D)
-/* ------------------------------------------------------------------------ */
-{
-	long i;
-	for(i=nl; i<=nh; i++) D[i] = S1[i] - S2[i];
-}
-/* ---------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulc_i32vector(int32 *S,long nl,long nh, int32 c, int32 *D)
-/* ---------------------------------------------------------------------- */
-{
-	long i;
-	for(i=nl; i<=nh; i++) D[i] = c * S[i];
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) mulc_rgb32vector(rgb32 *S,long nl,long nh, int32 c, rgb32 *D)
-/* ------------------------------------------------------------------------ */
-{
-	long i;
-	
-	for(i=nl; i<=nh; i++) {
-		D[i].r = c * S[i].r;
-		D[i].g = c * S[i].g;
-		D[i].b = c * S[i].b;
-	}
-}
-/* ------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) divc_i32vector(int32 *S,long nl,long nh, int32 c, int32 *D)
-/* ------------------------------------------------------------------------ */
-{
-	long i;
-	for(i=nl; i<=nh; i++) D[i] = S[i]  / c;
-}
-/* -------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) divc_rgb32vector(rgb32 *S,long nl,long nh, int32 c, rgb32 *D)
-/* -------------------------------------------------------------------------- */
-{
-	long i;
-	
-	for(i=nl; i<=nh; i++) {
-		D[i].r = S[i].r / c;
-		D[i].g = S[i].g / c;
-		D[i].b = S[i].b / c;
-	}
-}
-/* -------------------------------------------------------------------- */
-IMAGE_EXPORT(void) cumulleft_i32vector(int32 *S, long nl,long nh, int32 *D)
-/* -------------------------------------------------------------------- */
-{
-	// for histogram
-	long i;
-	
-	for(i=nh-1; i>=nl; i--) {
-		D[i] += S[i+1];
-	}
-}
-/* --------------------------------------------------------------------- */
-IMAGE_EXPORT(void) cumulleft_rgb32vector(rgb32 *S, long nl,long nh, rgb32 *D)
-/* --------------------------------------------------------------------- */
-{
-	// for histogram
-	long i;
-	
-	for(i=nh-1; i>=nl; i--) {
-		D[i].r += S[i+1].r;
-		D[i].g += S[i+1].g;
-		D[i].b += S[i+1].b;
-	}
-}
-/* -------------------------------------------------------------------- */
-IMAGE_EXPORT(void) cumulright_i32vector(int32 *S, long nl,long nh, int32 *D)
-/* -------------------------------------------------------------------- */
-{
-	// for histogram
-	long i;
-	
-	for(i=nl+1; i<=nh; i++) {
-		D[i] += S[i-1];
-	}
-}
-/* ---------------------------------------------------------------------- */
-IMAGE_EXPORT(void) cumulright_rgb32vector(rgb32 *S, long nl,long nh, rgb32 *D)
-/* ---------------------------------------------------------------------- */
-{
-	// for histogram
-	long i;
-	
-	for(i=nl+1; i<=nh; i++) {
-		D[i].r += S[i-1].r;
-		D[i].g += S[i-1].g;
-		D[i].b += S[i-1].b;
-	}
-}
-/* ----------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulfrac_i32vector(int32 *S, long nl,long nh, int32 a, int32 b, int32 *D)
-/* ----------------------------------------------------------------------------------- */
-{
-	long i;
-	
-	for(i=nl; i<=nh; i++) {
-		//D[i] = (a * S[i] + b) / b;
-		D[i] = (a * S[i]) / b;
-	}
-}
+    for (int32_t i = nl; i <= nh; i++) {
+        D[i].r = c * S[i].r;
+        D[i].g = c * S[i].g;
+        D[i].b = c * S[i].b;
+    }
+}
+
+/* --------------------------------------------------------------------- */
+void divc_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, int32_t c, rgb32 * D)
+/* --------------------------------------------------------------------- */
+{
+    for (int32_t i = nl; i <= nh; i++) {
+        D[i].r = S[i].r / c;
+        D[i].g = S[i].g / c;
+        D[i].b = S[i].b / c;
+    }
+}
+
+/* --------------------------------------------------------------------- */
+void cumulleft_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, rgb32 * D)
+/* --------------------------------------------------------------------- */
+{
+    // for histogram
+    for (int32_t i = nh - 1; i >= nl; i--) {
+        D[i].r += S[i + 1].r;
+        D[i].g += S[i + 1].g;
+        D[i].b += S[i + 1].b;
+    }
+}
+
+    
+/* --------------------------------------------------------------------- */
+void cumulright_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, rgb32 * D)
+/* --------------------------------------------------------------------- */
+{
+    // for histogram
+    for (int32_t i = nl + 1; i <= nh; i++) {
+        D[i].r += S[i - 1].r;
+        D[i].g += S[i - 1].g;
+        D[i].b += S[i - 1].b;
+    }
+}
+
+
 /* ------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulfrac_rgb32vector(rgb32 *S, long nl,long nh, int32 a, int32 b, rgb32 *D)
+void mulfrac_rgb32vector(rgb32 * S, int32_t nl, int32_t nh, int32_t a, int32_t b, rgb32 * D)
 /* ------------------------------------------------------------------------------------- */
 {
-	long i;
-	
-	for(i=nl; i<=nh; i++) {
-		//D[i].r = (a * S[i].r + b) / b;
-		//D[i].g = (a * S[i].g + b) / b;
-		//D[i].b = (a * S[i].b + b) / b;
-		D[i].r = (a * S[i].r) / b;
-		D[i].g = (a * S[i].g) / b;
-		D[i].b = (a * S[i].b) / b;
-	}
-}
+    for (int32_t i = nl; i <= nh; i++) {
+        D[i].r = (a * S[i].r) / b;
+        D[i].g = (a * S[i].g) / b;
+        D[i].b = (a * S[i].b) / b;
+    }
+}
+
+// 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/nrarith2.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrarith2.c	(revision 805)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrarith2.c	(revision 821)
@@ -17,6 +17,6 @@
 #include <malloc.h>
 #include <math.h> // fabs
-// #include <memory.h> // memcpy
-
+
+#include "nrc_os_config.h"
 #include "mypredef.h"
 #include "nrtype.h"
@@ -25,5 +25,4 @@
 #include "nrkernel.h"
 
-#include "nrarith1.h"
 #include "nrarith2.h"
 
@@ -32,144 +31,30 @@
 /* ------------------ */
 
-/* ----------------------------------------------------------------------------- */
-IMAGE_EXPORT(sint8) min_si8matrix(sint8 **m, long nrl, long nrh, long ncl, long nch)
-/* ----------------------------------------------------------------------------- */
-{
-	int i, j;
-	sint8 minimum = m[nrl][ncl];
-	    
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]<minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* ------------------------------------------------------------------------------ */
-IMAGE_EXPORT(uint8) min_ui8matrix(uint8 **m, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------ */
-{
-	int i, j;
-	uint8 minimum = m[nrl][ncl];
-	    
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]<minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(sint16) min_si16matrix(sint16 **m, long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------------------- */
-{
-	int i, j;
-	sint16 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]<minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(uint16) min_ui16matrix(uint16 **m, long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------------------- */
-{
-	int i, j;
-	uint16 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]<minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(sint32) min_si32matrix(sint32 **m, long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------------------- */
-{
-	int i, j;
-	sint32 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]<minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(uint32) min_ui32matrix(uint32 **m, long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------------------- */
-{
-	int i, j;
-	uint32 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]<minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(sint64) min_si64matrix(sint64 **m, long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------------------- */
-{
-	int i, j;
-	sint64 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]<minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(uint64) min_ui64matrix(uint64 **m, long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------------------- */
-{
-	int i, j;
-	uint64 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]<minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(float32) min_f32matrix(float32 **m, long nrl, long nrh, long ncl, long nch)
-/* ---------------------------------------------------------------------------------- */
-{
-	int i, j;
-	float32 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]<minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(float64) min_f64matrix(float64 **m, long nrl, long nrh, long ncl, long nch)
-/* ---------------------------------------------------------------------------------- */
-{
-	int i, j;
-	float64 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]<minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
+#undef min_type_matrix
+#define min_type_matrix(t) \
+t short_name(t,min_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \
+{                                                                                       \
+    t minimum = m[nrl][nrh];                                                            \
+    for (int32_t i = nrl; i <= nrh; i++) {                                              \
+        for (int32_t j = ncl; j <= nch; j++) {                                          \
+            if (m[i][j] < minimum) {                                                    \
+                minimum = m[i][j];                                                      \
+            }                                                                           \
+        }                                                                               \
+    }                                                                                   \
+    return minimum;                                                                     \
+}
+
+min_type_matrix(int8_t);
+min_type_matrix(uint8_t);
+min_type_matrix(int16_t);
+min_type_matrix(uint16_t);
+min_type_matrix(int32_t);
+min_type_matrix(uint32_t);
+min_type_matrix(int64_t);
+min_type_matrix(uint64_t);
+min_type_matrix(float);
+min_type_matrix(double);
+
 
 /* ------------------ */
@@ -177,157 +62,31 @@
 /* ------------------ */
 
-/* ----------------------------------------------------------------------------- */
-IMAGE_EXPORT(sint8) max_si8matrix(sint8 **m, long nrl, long nrh, long ncl, long nch)
-/* ----------------------------------------------------------------------------- */
-{
-	int i, j;
-	sint8 minimum = m[nrl][ncl];
-	    
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]>minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* ------------------------------------------------------------------------------ */
-IMAGE_EXPORT(uint8) max_ui8matrix(uint8 **m, long nrl, long nrh, long ncl, long nch)
-/* ------------------------------------------------------------------------------ */
-{
-	int i, j;
-	uint8 minimum = m[nrl][ncl];
-	    
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]>minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(sint16) max_si16matrix(sint16 **m, long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------------------- */
-{
-	int i, j;
-	sint16 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]>minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(uint16) max_ui16matrix(uint16 **m, long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------------------- */
-{
-	int i, j;
-	uint16 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]>minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(sint32) max_si32matrix(sint32 **m, long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------------------- */
-{
-	int i, j;
-	sint32 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]>minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(uint32) max_ui32matrix(uint32 **m, long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------------------- */
-{
-	int i, j;
-	uint32 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]>minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(sint64) max_si64matrix(sint64 **m, long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------------------- */
-{
-	int i, j;
-	sint64 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]>minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* --------------------------------------------------------------------------------- */
-IMAGE_EXPORT(uint64) max_ui64matrix(uint64 **m, long nrl, long nrh, long ncl, long nch)
-/* --------------------------------------------------------------------------------- */
-{
-	int i, j;
-	uint64 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]>minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(float32) max_f32matrix(float32 **m, long nrl, long nrh, long ncl, long nch)
-/* ---------------------------------------------------------------------------------- */
-{
-	int i, j;
-	float32 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]>minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-/* ---------------------------------------------------------------------------------- */
-IMAGE_EXPORT(float64) max_f64matrix(float64 **m, long nrl, long nrh, long ncl, long nch)
-/* ---------------------------------------------------------------------------------- */
-{
-	int i, j;
-	float64 minimum = m[nrl][ncl];
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			if(m[i][j]>minimum) minimum = m[i][j];
-		}
-	}
-	return minimum;
-}
-
-/* -------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) add_si8matrix(sint8 **X, long nrl,long nrh, long ncl, long nch, sint8 **Y, sint8 **Z)
-/* -------------------------------------------------------------------------------------------------- */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] + Y[i][j];
-		}
-	}
-}
+#undef max_type_matrix
+#define max_type_matrix(t) \
+t short_name(t,max_,matrix)(t ** m, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch) \
+{                                                                                       \
+    t maximum = m[nrl][nrh];                                                            \
+    for (int32_t i = nrl; i <= nrh; i++) {                                              \
+        for (int32_t j = ncl; j <= nch; j++) {                                          \
+            if (m[i][j] > maximum) {                                                    \
+                maximum = m[i][j];                                                      \
+            }                                                                           \
+        }                                                                               \
+    }                                                                                   \
+    return maximum;                                                                     \
+}
+
+max_type_matrix(int8_t);
+max_type_matrix(uint8_t);
+max_type_matrix(int16_t);
+max_type_matrix(uint16_t);
+max_type_matrix(int32_t);
+max_type_matrix(uint32_t);
+max_type_matrix(int64_t);
+max_type_matrix(uint64_t);
+max_type_matrix(float);
+max_type_matrix(double);
+
+
 
 /* ------------------ */
@@ -335,145 +94,50 @@
 /* ------------------ */
 
-/* -------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) add_ui8matrix(uint8 **X, long nrl,long nrh, long ncl, long nch, uint8 **Y, uint8 **Z)
-/* -------------------------------------------------------------------------------------------------- */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] + Y[i][j];
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) add_si16matrix(sint16 **X, long nrl,long nrh, long ncl, long nch, sint16 **Y, sint16 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] + Y[i][j];
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) add_ui16matrix(uint16 **X, long nrl,long nrh, long ncl, long nch, uint16 **Y, uint16 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] + Y[i][j];
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) add_si32matrix(sint32 **X, long nrl,long nrh, long ncl, long nch, sint32 **Y, sint32 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] + Y[i][j];
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) add_ui32matrix(uint32 **X, long nrl,long nrh, long ncl, long nch, uint32 **Y, uint32 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] + Y[i][j];
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) add_si64matrix(sint64 **X, long nrl,long nrh, long ncl, long nch, sint64 **Y, sint64 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] + Y[i][j];
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) add_ui64matrix(uint64 **X, long nrl,long nrh, long ncl, long nch, uint64 **Y, uint64 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] + Y[i][j];
-		}
-	}
-}
-/* -------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) add_f32matrix(float32 **X, long nrl,long nrh, long ncl, long nch, float32 **Y, float32 **Z)
-/* -------------------------------------------------------------------------------------------------------- */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] + Y[i][j];
-		}
-	}
-}
-/* -------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) add_f64matrix(float64 **X, long nrl,long nrh, long ncl, long nch, float64 **Y, float64 **Z)
-/* -------------------------------------------------------------------------------------------------------- */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] + Y[i][j];
-		}
-	}
-}
+
+#undef add_type_matrix
+#define add_type_matrix(t) \
+void short_name(t,add_,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++) {                                                                 \
+        for (int32_t j = ncl; j <= nch; j++) {                                                             \
+            Z[i][j] = X[i][j] + Y[i][j];                                                                   \
+        }                                                                                                  \
+    }                                                                                                      \
+}
+
+add_type_matrix(int8_t);
+add_type_matrix(uint8_t);
+add_type_matrix(int16_t);
+add_type_matrix(uint16_t);
+add_type_matrix(int32_t);
+add_type_matrix(uint32_t);
+add_type_matrix(int64_t);
+add_type_matrix(uint64_t);
+add_type_matrix(float);
+add_type_matrix(double);
+
+
 /* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) add_rgb8matrix(rgb8 **X, long nrl,long nrh,long ncl, long nch, rgb8 **Y, rgb8 **Z)
+void add_rgb8matrix(rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8 ** Y, rgb8 ** Z)
 /* ----------------------------------------------------------------------------------------------- */
 {
-	long i, j;
-	rgb8 x, y, z;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = Y[i][j];
-			//z = x + y;
-			RGB8_ADD(x,y,z);
-			Z[i][j] = z;
-		}
-	}
-}
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            //z = x + y;
+            RGB8_ADD(X[i][j], Y[i][j], Z[i][j]);
+        }
+    }
+}
+
 /* --------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) add_rgbx8matrix(rgbx8 **X, long nrl,long nrh,long ncl, long nch, rgbx8 **Y, rgbx8 **Z)
+void add_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 ** Y, rgbx8 ** Z)
 /* --------------------------------------------------------------------------------------------------- */
 {
-	long i, j;
-	rgbx8 x, y, z;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = Y[i][j];
-			//z = x + y;
-			RGBX8_ADD(x,y,z);
-			Z[i][j] = z;
-		}
-	}
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            //z = x + y;
+            RGBX8_ADD(X[i][j], Y[i][j], Z[i][j]);
+        }
+    }
 }
 
@@ -482,298 +146,102 @@
 /* -------------------- */
 
-/* ------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) addc_si8matrix(sint8 **X,long nrl,long nrh, long ncl, long nch, sint8 y, sint8 **Z)
-/* ------------------------------------------------------------------------------------------------ */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] + y;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) addc_ui8matrix(uint8 **X,long nrl,long nrh, long ncl, long nch, uint8 y, uint8 **Z)
-/* ------------------------------------------------------------------------------------------------ */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] + y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) addc_si16matrix(sint16 **X,long nrl,long nrh, long ncl, long nch, sint16 y, sint16 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] + y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) addc_ui16matrix(uint16 **X,long nrl,long nrh, long ncl, long nch, uint16 y, uint16 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] + y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) addc_si32matrix(sint32 **X,long nrl,long nrh, long ncl, long nch, sint32 y, sint32 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] + y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) addc_ui32matrix(uint32 **X,long nrl,long nrh, long ncl, long nch, uint32 y, uint32 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] + y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) addc_si64matrix(sint64 **X,long nrl,long nrh, long ncl, long nch, sint64 y, sint64 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] + y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) addc_ui64matrix(uint64 **X,long nrl,long nrh, long ncl, long nch, uint64 y, uint64 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] + y;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) addc_f32matrix(float32 **X,long nrl,long nrh, long ncl, long nch, float32 y, float32 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] + y;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) addc_f64matrix(float64 **X,long nrl,long nrh, long ncl, long nch, float64 y, float64 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] + y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) addc_rgb8matrix(rgb8 **X,long nrl,long nrh, long ncl, long nch, rgb8 y, rgb8 **Z)
-/* ---------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-    rgb8 x, z;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            x = X[i][j];
-            RGB8_ADD(x,y,z);
-            Z[i][j] = z;
-		}
-	}
-}
-/* -------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) addc_rgbx8matrix(rgbx8 **X,long nrl,long nrh, long ncl, long nch, rgbx8 y, rgbx8 **Z)
-/* -------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-    rgbx8 x, z;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            x = X[i][j];
-            RGBX8_ADD(x,y,z);
-            Z[i][j] = z;
-		}
-	}
-}
-/* ------------------ */
-/* --- Add Matrix --- */
-/* ------------------ */
-
-/* -------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) sub_ui8matrix(uint8 **X, long nrl,long nrh, long ncl, long nch, uint8 **Y, uint8 **Z)
-/* -------------------------------------------------------------------------------------------------- */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] - Y[i][j];
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) sub_si16matrix(sint16 **X, long nrl,long nrh, long ncl, long nch, sint16 **Y, sint16 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] - Y[i][j];
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) sub_ui16matrix(uint16 **X, long nrl,long nrh, long ncl, long nch, uint16 **Y, uint16 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] - Y[i][j];
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) sub_si32matrix(sint32 **X, long nrl,long nrh, long ncl, long nch, sint32 **Y, sint32 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] - Y[i][j];
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) sub_ui32matrix(uint32 **X, long nrl,long nrh, long ncl, long nch, uint32 **Y, uint32 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] - Y[i][j];
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) sub_si64matrix(sint64 **X, long nrl,long nrh, long ncl, long nch, sint64 **Y, sint64 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] - Y[i][j];
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) sub_ui64matrix(uint64 **X, long nrl,long nrh, long ncl, long nch, uint64 **Y, uint64 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] - Y[i][j];
-		}
-	}
-}
-/* -------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) sub_f32matrix(float32 **X, long nrl,long nrh, long ncl, long nch, float32 **Y, float32 **Z)
-/* -------------------------------------------------------------------------------------------------------- */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] - Y[i][j];
-		}
-	}
-}
-/* -------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) sub_f64matrix(float64 **X, long nrl,long nrh, long ncl, long nch, float64 **Y, float64 **Z)
-/* -------------------------------------------------------------------------------------------------------- */
-{
-	long i, j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			Z[i][j] = X[i][j] - Y[i][j];
-		}
-	}
-}
+#undef addc_type_matrix
+#define addc_type_matrix(t) \
+void short_name(t,addc_,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++) {                                                               \
+        for (int32_t j = ncl; j <= nch; j++) {                                                           \
+            Z[i][j] = X[i][j] + y;                                                                       \
+        }                                                                                                \
+    }                                                                                                    \
+}
+
+addc_type_matrix(int8_t);
+addc_type_matrix(uint8_t);
+addc_type_matrix(int16_t);
+addc_type_matrix(uint16_t);
+addc_type_matrix(int32_t);
+addc_type_matrix(uint32_t);
+addc_type_matrix(int64_t);
+addc_type_matrix(uint64_t);
+addc_type_matrix(float);
+addc_type_matrix(double);
+
+
+
+/* ---------------------------------------------------------------------------------------------- */
+void addc_rgb8matrix(rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8 y, rgb8 ** Z)
+/* ---------------------------------------------------------------------------------------------- */
+{
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            RGB8_ADD(X[i][j], y, Z[i][j]);
+        }
+    }
+}
+
+/* -------------------------------------------------------------------------------------------------- */
+void addc_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 y, rgbx8 ** Z)
+/* -------------------------------------------------------------------------------------------------- */
+{
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            RGBX8_ADD(X[i][j], y, Z[i][j]);
+        }
+    }
+}
+
+
+/* ------------------ */
+/* --- Sub Matrix --- */
+/* ------------------ */
+
+#undef sub_type_matrix
+#define sub_type_matrix(t) \
+void short_name(t,sub_,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++) {                                                                 \
+        for (int32_t j = ncl; j <= nch; j++) {                                                             \
+            Z[i][j] = X[i][j] - Y[i][j];                                                                   \
+        }                                                                                                  \
+    }                                                                                                      \
+}
+
+sub_type_matrix(int8_t);
+sub_type_matrix(uint8_t);
+sub_type_matrix(int16_t);
+sub_type_matrix(uint16_t);
+sub_type_matrix(int32_t);
+sub_type_matrix(uint32_t);
+sub_type_matrix(int64_t);
+sub_type_matrix(uint64_t);
+sub_type_matrix(float);
+sub_type_matrix(double);
+
+
 /* ----------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) sub_rgb8matrix(rgb8 **X, long nrl,long nrh,long ncl, long nch, rgb8 **Y, rgb8 **Z)
+void sub_rgb8matrix(rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8 ** Y, rgb8 ** Z)
 /* ----------------------------------------------------------------------------------------------- */
 {
-	long i, j;
-	rgb8 x, y, z;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = Y[i][j];
-			RGB8_SUB(x,y,z);
-			Z[i][j] = z;
-		}
-	}
-}
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            //z = x + y;
+            RGB8_SUB(X[i][j], Y[i][j], Z[i][j]);
+        }
+    }
+}
+
 /* --------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) sub_rgbx8matrix(rgbx8 **X, long nrl,long nrh,long ncl, long nch, rgbx8 **Y, rgbx8 **Z)
+void sub_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 ** Y, rgbx8 ** Z)
 /* --------------------------------------------------------------------------------------------------- */
 {
-	long i, j;
-	rgbx8 x, y, z;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = Y[i][j];
-			RGBX8_SUB(x,y,z);
-			Z[i][j] = z;
-		}
-	}
-}
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            //z = x + y;
+            RGBX8_SUB(X[i][j], Y[i][j], Z[i][j]);
+        }
+    }
+}
+
 
 /* -------------------- */
@@ -781,469 +249,164 @@
 /* -------------------- */
 
-/* ------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) subc_si8matrix(sint8 **X,long nrl,long nrh, long ncl, long nch, sint8 y, sint8 **Z)
-/* ------------------------------------------------------------------------------------------------ */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] - y;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) subc_ui8matrix(uint8 **X,long nrl,long nrh, long ncl, long nch, uint8 y, uint8 **Z)
-/* ------------------------------------------------------------------------------------------------ */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] - y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) subc_si16matrix(sint16 **X,long nrl,long nrh, long ncl, long nch, sint16 y, sint16 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] - y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) subc_ui16matrix(uint16 **X,long nrl,long nrh, long ncl, long nch, uint16 y, uint16 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] - y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) subc_si32matrix(sint32 **X,long nrl,long nrh, long ncl, long nch, sint32 y, sint32 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] - y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) subc_ui32matrix(uint32 **X,long nrl,long nrh, long ncl, long nch, uint32 y, uint32 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] - y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) subc_si64matrix(sint64 **X,long nrl,long nrh, long ncl, long nch, sint64 y, sint64 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] - y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) subc_ui64matrix(uint64 **X,long nrl,long nrh, long ncl, long nch, uint64 y, uint64 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] - y;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) subc_f32matrix(float32 **X,long nrl,long nrh, long ncl, long nch, float32 y, float32 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] - y;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) subc_f64matrix(float64 **X,long nrl,long nrh, long ncl, long nch, float64 y, float64 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] - y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) subc_rgb8matrix(rgb8 **X,long nrl,long nrh, long ncl, long nch, rgb8 y, rgb8 **Z)
-/* ---------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-    rgb8 x, z;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            x = X[i][j];
-            RGB8_SUB(x,y,z);
-            Z[i][j] = z;
-		}
-	}
-}
-/* -------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) subc_rgbx8matrix(rgbx8 **X,long nrl,long nrh, long ncl, long nch, rgbx8 y, rgbx8 **Z)
-/* -------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-    rgbx8 x, z;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            x = X[i][j];
-            RGBX8_SUB(x,y,z);
-            Z[i][j] = z;
-		}
-	}
-}
+#undef subc_type_matrix
+#define subc_type_matrix(t) \
+void short_name(t,subc_,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++) {                                                               \
+        for (int32_t j = ncl; j <= nch; j++) {                                                           \
+            Z[i][j] = X[i][j] - y;                                                                       \
+        }                                                                                                \
+    }                                                                                                    \
+}
+
+subc_type_matrix(int8_t);
+subc_type_matrix(uint8_t);
+subc_type_matrix(int16_t);
+subc_type_matrix(uint16_t);
+subc_type_matrix(int32_t);
+subc_type_matrix(uint32_t);
+subc_type_matrix(int64_t);
+subc_type_matrix(uint64_t);
+subc_type_matrix(float);
+subc_type_matrix(double);
+
+
+
+/* ---------------------------------------------------------------------------------------------- */
+void subc_rgb8matrix(rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8 y, rgb8 ** Z)
+/* ---------------------------------------------------------------------------------------------- */
+{
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            RGB8_SUB(X[i][j], y, Z[i][j]);
+        }
+    }
+}
+
+/* -------------------------------------------------------------------------------------------------- */
+void subc_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 y, rgbx8 ** Z)
+/* -------------------------------------------------------------------------------------------------- */
+{
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            RGBX8_SUB(X[i][j], y, Z[i][j]);
+        }
+    }
+}
+
+
 /* -------------------- */
 /* --- Mul constant --- */
 /* -------------------- */
 
-/* ------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) mulc_si8matrix(sint8 **X,long nrl,long nrh, long ncl, long nch, sint8 y, sint8 **Z)
-/* ------------------------------------------------------------------------------------------------ */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] * y;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) mulc_ui8matrix(uint8 **X,long nrl,long nrh, long ncl, long nch, uint8 y, uint8 **Z)
-/* ------------------------------------------------------------------------------------------------ */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] * y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulc_si16matrix(sint16 **X,long nrl,long nrh, long ncl, long nch, sint16 y, sint16 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] * y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulc_ui16matrix(uint16 **X,long nrl,long nrh, long ncl, long nch, uint16 y, uint16 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] * y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulc_si32matrix(sint32 **X,long nrl,long nrh, long ncl, long nch, sint32 y, sint32 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] * y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulc_ui32matrix(uint32 **X,long nrl,long nrh, long ncl, long nch, uint32 y, uint32 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] * y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulc_si64matrix(sint64 **X,long nrl,long nrh, long ncl, long nch, sint64 y, sint64 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] * y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulc_ui64matrix(uint64 **X,long nrl,long nrh, long ncl, long nch, uint64 y, uint64 **Z)
-/* ---------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] * y;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) mulc_f32matrix(float32 **X,long nrl,long nrh, long ncl, long nch, float32 y, float32 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] * y;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) mulc_f64matrix(float64 **X,long nrl,long nrh, long ncl, long nch, float64 y, float64 **Z)
-/* ------------------------------------------------------------------------------------------------------ */
-{
-	long i,j;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            Z[i][j] = X[i][j] * y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulc_rgb8matrix(rgb8 **X,long nrl,long nrh, long ncl, long nch, rgb8 y, rgb8 **Z)
-/* ---------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-    rgb8 x, z;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            x = X[i][j];
-            RGB8_MUL(x,y,z);
-            Z[i][j] = z;
-		}
-	}
-}
-/* -------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulc_rgbx8matrix(rgbx8 **X,long nrl,long nrh, long ncl, long nch, rgbx8 y, rgbx8 **Z)
-/* -------------------------------------------------------------------------------------------------- */
-{
-	long i,j;
-    rgbx8 x, z;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-            x = X[i][j];
-            RGBX8_MUL(x,y,z);
-            Z[i][j] = z;
-		}
-	}
-}
+#undef mulc_type_matrix
+#define mulc_type_matrix(t) \
+void short_name(t,mulc_,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++) {                                                               \
+        for (int32_t j = ncl; j <= nch; j++) {                                                           \
+            Z[i][j] = X[i][j] * y;                                                                       \
+        }                                                                                                \
+    }                                                                                                    \
+}
+
+mulc_type_matrix(int8_t);
+mulc_type_matrix(uint8_t);
+mulc_type_matrix(int16_t);
+mulc_type_matrix(uint16_t);
+mulc_type_matrix(int32_t);
+mulc_type_matrix(uint32_t);
+mulc_type_matrix(int64_t);
+mulc_type_matrix(uint64_t);
+mulc_type_matrix(float);
+mulc_type_matrix(double);
+
+
+
+/* ---------------------------------------------------------------------------------------------- */
+void mulc_rgb8matrix(rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb8 y, rgb8 ** Z)
+/* ---------------------------------------------------------------------------------------------- */
+{
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            RGB8_MUL(X[i][j], y, Z[i][j]);
+        }
+    }
+}
+
+/* -------------------------------------------------------------------------------------------------- */
+void mulc_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx8 y, rgbx8 ** Z)
+/* -------------------------------------------------------------------------------------------------- */
+{
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            RGBX8_MUL(X[i][j], y, Z[i][j]);
+        }
+    }
+}
+
+
 /* --------------- */
 /* --- MulFrac --- */
 /* --------------- */
 
-// Y=(a*X)/b
-
-/* -------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulfrac_si8matrix(sint8 **X, long nrl, long nrh, long ncl, long nch, int32 a, int32 b, sint8 **Y)
-/* -------------------------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	int32 x, y;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = (a * x) / b;
-            Y[i][j] = (sint8) y;
-		}
-	}
-}
-/* -------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulfrac_ui8matrix(uint8 **X, long nrl, long nrh, long ncl, long nch, int32 a, int32 b, uint8 **Y)
-/* -------------------------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	int32 x, y;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = (a * x) / b;
-			Y[i][j] = (uint8) y;
-		}
-	}
-}
+// Y = (a * X) / b
+
+#undef mulfrac_type_matrix
+#define mulfrac_type_matrix(t) \
+void short_name(t,mulfrac_,matrix)(t ** X, int32_t nrl, int32_t nrh, \
+        int32_t ncl, int32_t nch, int32_t a, int32_t b, t ** Y)      \
+{                                                                    \
+    for (int32_t i = nrl; i <= nrh; i++) {                           \
+        for (int32_t j = ncl; j <= nch; j++) {                       \
+            Y[i][j] = (t) ((a * X[i][j]) / b);                       \
+        }                                                            \
+    }                                                                \
+}
+
+mulfrac_type_matrix(int8_t);
+mulfrac_type_matrix(uint8_t);
+mulfrac_type_matrix(int16_t);
+mulfrac_type_matrix(uint16_t);
+mulfrac_type_matrix(int32_t);
+mulfrac_type_matrix(uint32_t);
+mulfrac_type_matrix(int64_t);
+mulfrac_type_matrix(uint64_t);
+mulfrac_type_matrix(float);
+mulfrac_type_matrix(double);
+
+
+/* ------------------------------------------------------------------------------------------------------------ */
+void mulfrac_rgb8matrix(rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb32 a, rgb32 b, rgb8 ** Y)
+/* ------------------------------------------------------------------------------------------------------------ */
+{
+    rgb32 y32;
+    rgb8 x8, y8;
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            x8 = X[i][j];
+            RGB8_MULFRAC(x8, a, b, y32);
+            RGB32CAST8(y32, y8);
+            Y[i][j] = y8;
+        }
+    }
+}
+
 /* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulfrac_si16matrix(sint16 **X, long nrl, long nrh, long ncl, long nch, int32 a, int32 b, sint16 **Y)
+void mulfrac_rgb8xmatrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx32 a, rgbx32 b, rgbx8 ** Y)
 /* ----------------------------------------------------------------------------------------------------------------- */
 {
-	int i, j;
-	int32 x, y;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = (a * x) / b;
-            Y[i][j] = (sint16) y;
-		}
-	}
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulfrac_ui16matrix(uint16 **X, long nrl, long nrh, long ncl, long nch, int32 a, int32 b, uint16 **Y)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	int32 x, y;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = (a * x) / b;
-			Y[i][j] = (uint16) y;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) mulfrac_si32matrix(sint32 **X, long nrl, long nrh, long ncl, long nch, int32  a, int32 b, sint32 **Y)
-/* ------------------------------------------------------------------------------------------------------------------ */
-{
-	int i, j;
-	int32 x, y;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = (a * x) / b;
-            Y[i][j] = (sint16) y;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) mulfrac_ui32matrix(uint32 **X, long nrl, long nrh, long ncl, long nch, int32  a, int32 b, uint32 **Y)
-/* ------------------------------------------------------------------------------------------------------------------ */
-{
-	int i, j;
-	int32 x, y;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = (a * x) / b;
-			Y[i][j] = (uint16) y;
-		}
-	}
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulfrac_si64matrix(sint64 **X, long nrl, long nrh, long ncl, long nch, int32 a, int32 b, sint64 **Y)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	sint64 x, y;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = (a * x) / b;
-            Y[i][j] = (sint64) y;
-		}
-	}
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulfrac_ui64matrix(uint64 **X, long nrl, long nrh, long ncl, long nch, int32 a, int32 b, uint64 **Y)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	uint64 x, y;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = (a * x) / b;
-			Y[i][j] = (uint64) y;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) mulfrac_rgb8matrix(rgb8 **X, long nrl,long nrh, long ncl, long nch, rgb32 a, rgb32 b, rgb8 **Y)
-/* ------------------------------------------------------------------------------------------------------------ */
-{
-	int i, j;
-	rgb32 y32;
-	rgb8 x8, y8;
-
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x8 = X[i][j];
-			RGB8_MULFRAC(x8,a,b,y32);
-			RGB32CAST8(y32,y8);
-			Y[i][j] = y8;
-		}
-	}
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulfrac_rgb8xmatrix(rgbx8 **X, long nrl,long nrh, long ncl, long nch, rgbx32 a, rgbx32 b, rgbx8 **Y)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	rgbx32 y32;
-	rgbx8 x8, y8;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x8 = X[i][j];
-			RGBX8_MULFRAC(x8,a,b,y32);
-			RGBX32CAST8(y32,y8);
-			Y[i][j] = y8;
-		}
-	}
-}
+    rgbx32 y32;
+    rgbx8 x8, y8;
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            x8 = X[i][j];
+            RGBX8_MULFRAC(x8, a, b, y32);
+            RGBX32CAST8(y32, y8);
+            Y[i][j] = y8;
+        }
+    }
+}
+
 
 /* ---------------- */
@@ -1251,128 +414,67 @@
 /* ---------------- */
 
-// m3 = (a*m1)>>s
-
-/* -------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulshift_si8matrix(sint8 **X, long nrl, long nrh,long ncl, long nch, int32 a, int32 s, sint8 **Y)
-/* -------------------------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	int32 x, y;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = (a * x) >> s;
-			Y[i][j] = (sint8) y;
-		}
-	}
-}
-/* --------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulshift_ui8matrix(uint8 **X, long nrl,long nrh,long ncl, long nch, int32  a, int32  s, uint8 **Y)
-/* --------------------------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	int32 x, y;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = (a * x) >> s;
-			Y[i][j] = (uint8) y;
-		}
-	}
-}
+// m3 = (a * m1) >> s
+
+#undef mulshift_type_matrix
+#define mulshift_type_matrix(t) \
+void short_name(t,mulshift_,matrix)(t ** X, int32_t nrl, int32_t nrh, \
+        int32_t ncl, int32_t nch, int32_t a, int32_t s, t ** Y)      \
+{                                                                    \
+    for (int32_t i = nrl; i <= nrh; i++) {                           \
+        for (int32_t j = ncl; j <= nch; j++) {                       \
+            Y[i][j] = (t) ((a * X[i][j]) >> s);                      \
+        }                                                            \
+    }                                                                \
+}
+
+mulshift_type_matrix(int8_t);
+mulshift_type_matrix(uint8_t);
+mulshift_type_matrix(int16_t);
+mulshift_type_matrix(uint16_t);
+mulshift_type_matrix(int32_t);
+mulshift_type_matrix(uint32_t);
+mulshift_type_matrix(int64_t);
+mulshift_type_matrix(uint64_t);
+
+
+/* ---------------------------------------------------------------------------------------------------------------- */
+void mulshift_rgb8matrix(rgb8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgb32  a, rgb32  s, rgb8 ** Y)
+/* ---------------------------------------------------------------------------------------------------------------- */
+{
+    rgb32 y32;
+    rgb8 x8, y8;
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            x8 = X[i][j];
+            RGB8_MULSHIFT(x8, a, s, y32);
+            RGB32CAST8(y32, y8);
+            Y[i][j] = y8;
+        }
+    }
+}
+
 /* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulshift_si16matrix(sint16 **X, long nrl, long nrh,long ncl, long nch, int32 a, int32 s, sint16 **Y)
+void mulshift_rgbx8matrix(rgbx8 ** X, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, rgbx32 a, rgbx32 s, rgbx8 ** Y)
 /* ----------------------------------------------------------------------------------------------------------------- */
 {
-	int i, j;
-	int32 x, y;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = (a * x) >> s;
-			Y[i][j] = (sint16) y;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) mulshift_ui16matrix(uint16 **X, long nrl,long nrh,long ncl, long nch, int32  a, int32  s, uint16 **Y)
-/* ------------------------------------------------------------------------------------------------------------------ */
-{
-	int i, j;
-	int32 x, y;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = (a * x) >> s;
-			Y[i][j] = (uint16) y;
-		}
-	}
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulshift_si32matrix(sint32 **X, long nrl, long nrh,long ncl, long nch, int32 a, int32 s, sint32 **Y)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	int32 x, y;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = (a * x) >> s;
-			Y[i][j] = (sint32) y;
-		}
-	}
-}
-/* ------------------------------------------------------------------------------------------------------------------ */
-IMAGE_EXPORT(void) mulshift_ui32matrix(uint32 **X, long nrl,long nrh,long ncl, long nch, int32  a, int32  s, uint32 **Y)
-/* ------------------------------------------------------------------------------------------------------------------ */
-{
-	int i, j;
-	int32 x, y;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x = X[i][j];
-			y = (a * x) >> s;
-			Y[i][j] = (uint32) y;
-		}
-	}
-}
-/* ---------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulshift_rgb8matrix(rgb8 **X, long nrl,long nrh,long ncl, long nch, rgb32  a, rgb32  s, rgb8 **Y)
-/* ---------------------------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	rgb32 y32;
-	rgb8 x8, y8;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x8 = X[i][j];
-			RGB8_MULSHIFT(x8,a,s,y32);
-			RGB32CAST8(y32,y8);
-			Y[i][j] = y8;
-		}
-	}
-}
-/* ----------------------------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) mulshift_rgbx8matrix(rgbx8 **X, long nrl,long nrh,long ncl, long nch, rgbx32 a, rgbx32 s, rgbx8 **Y)
-/* ----------------------------------------------------------------------------------------------------------------- */
-{
-	int i, j;
-	rgbx32 y32;
-	rgbx8 x8, y8;
-	
-	for(i=nrl; i<=nrh; i++) {
-		for(j=ncl; j<=nch; j++) {
-			x8 = X[i][j];
-			RGBX8_MULSHIFT(x8,a,s,y32);
-			RGBX32CAST8(y32,y8);
-			Y[i][j] = y8;
-		}
-	}
-}
+    rgbx32 y32;
+    rgbx8 x8, y8;
+    for (int32_t i = nrl; i <= nrh; i++) {
+        for (int32_t j = ncl; j <= nch; j++) {
+            x8 = X[i][j];
+            RGBX8_MULSHIFT(x8, a, s, y32);
+            RGBX32CAST8(y32, y8);
+            Y[i][j] = y8;
+        }
+    }
+}
+
+// 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/nrarith2x.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrarith2x.c	(revision 805)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrarith2x.c	(revision 821)
@@ -17,6 +17,6 @@
 #include <malloc.h>
 #include <math.h> // fabs
-// #include <memory.h> // memcpy
 
+#include "nrc_os_config.h"
 #include "mypredef.h"
 #include "nrtype.h"
@@ -25,84 +25,101 @@
 #include "nrkernel.h"
 
-/* ------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) addcnz_bmatrix(byte **src,long nrl,long nrh,long ncl, long nch, byte  cte, byte **dst)
-/* ------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	byte *Xi, *Yi;
-	
-	for(i=nrl; i<=nrh; i++) {
-		Xi = src[i];
-		Yi = dst[i];
-		for(j=ncl; j<=nch; j++) {
-			if(Xi[j])
-				Yi[j] = Xi[j] + cte;
-			else
-				Yi[j] = Xi[j];
-		}
-	}
+
+#undef addcnz_type_matrix
+#define addcnz_type_matrix(t) \
+void short_name(t,addcnz_,matrix)(t ** src, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t cte, t ** dst) \
+{                                              \
+	t * Xi;                                    \
+    t * Yi;                                    \
+	for (int32_t i = nrl; i <= nrh; i++) {     \
+		Xi = src[i];                           \
+		Yi = dst[i];                           \
+		for (int32_t j = ncl; j <= nch; j++) { \
+			if (Xi[j] != 0) {                  \
+				Yi[j] = Xi[j] + cte;           \
+            }                                  \
+			else {                             \
+				Yi[j] = Xi[j];                 \
+            }                                  \
+		}                                      \
+	}                                          \
 }
-/* ----------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) addandc_bmatrix(byte **src,long nrl,long nrh,long ncl, long nch, byte  cte, byte **dst)
-/* ----------------------------------------------------------------------------------- */
-{
-	long i,j;
-	byte *Xi, *Yi;
-	
-	for(i=nrl; i<=nrh; i++) {
-		Xi = src[i];
-		Yi = dst[i];
-		for(j=ncl; j<=nch; j++) {
-			if(Xi[j])
-				Yi[j] = Xi[j] + cte;
-			else
-				Yi[j] = Xi[i];
-		}
-	}
+
+addcnz_type_matrix(int8_t);
+addcnz_type_matrix(uint8_t);
+addcnz_type_matrix(int16_t);
+addcnz_type_matrix(uint16_t);
+addcnz_type_matrix(int32_t);
+addcnz_type_matrix(uint32_t);
+addcnz_type_matrix(int64_t);
+addcnz_type_matrix(uint64_t);
+addcnz_type_matrix(float);
+addcnz_type_matrix(double);
+
+
+#undef addandc_type_matrix
+#define addandc_type_matrix(t) \
+void short_name(t,addandc_,matrix)(t ** src, int32_t nrl, int32_t nrh, int32_t ncl, int32_t nch, t cte, t ** dst) \
+{                                              \
+	t * Xi;                                    \
+    t * Yi;                                    \
+	for (int32_t i = nrl; i <= nrh; i++) {     \
+		Xi = src[i];                           \
+		Yi = dst[i];                           \
+		for (int32_t j = ncl; j <= nch; j++) { \
+			if (Xi[j] != 0) {                  \
+                Yi[j] = Xi[j] + cte;           \
+            }                                  \
+		}                                      \
+	}                                          \
 }
-/* ---------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) addandc_si16matrix(sint16 **src,long nrl,long nrh,long ncl, long nch, short cte, sint16 **dst)
-/* ---------------------------------------------------------------------------------------- */
-{
-	long i,j;
-	sint16 *Xi, *Yi;
-	
-	for(i=nrl; i<=nrh; i++) {
-		Xi = src[i];
-		Yi = dst[i];
-		for(j=ncl; j<=nch; j++) {
-			if(Xi[j]) Yi[j] = Xi[j] + cte;
-		}
-	}
+
+addandc_type_matrix(int8_t);
+addandc_type_matrix(uint8_t);
+addandc_type_matrix(int16_t);
+addandc_type_matrix(uint16_t);
+addandc_type_matrix(int32_t);
+addandc_type_matrix(uint32_t);
+addandc_type_matrix(int64_t);
+addandc_type_matrix(uint64_t);
+addandc_type_matrix(float);
+addandc_type_matrix(double);
+
+
+#undef sum_type_matrix
+#define sum_type_matrix(t,rt) \
+rt short_name(t,sum_,matrix)(t ** m, int32_t nrl, int32_t nrh,int32_t ncl, int32_t nch) \
+{                                              \
+	rt s = 0;                                  \
+	t * Xi;                                    \
+	for (int32_t i = nrl; i <= nrh; i++) {     \
+		Xi = m[i];                             \
+		for (int32_t j = ncl; j <= nch; j++) { \
+			s += Xi[j];                        \
+		}                                      \
+    }                                          \
+    return s;                                  \
 }
-/* ------------------------------------------------------------------------------------------- */
-IMAGE_EXPORT(void) addandc_ui16matrix(uint16 **src,long nrl,long nrh,long ncl, long nch, short cte, uint16 **dst)
-/* ------------------------------------------------------------------------------------------ */
-{
-	long i,j;
-	uint16 *Xi, *Yi;
-	
-	for(i=nrl; i<=nrh; i++) {
-		Xi = src[i];
-		Yi = dst[i];
-		for(j=ncl; j<=nch; j++) {
-			if(Xi[j]) Yi[j] = Xi[j] + cte;
-		}
-	}
-}
-/* ----------------------------------------------------------- */
-IMAGE_EXPORT(int) count_bmatrix(byte **m, long nrl,long nrh,long ncl, long nch)
-/* ----------------------------------------------------------- */
-{
-	long i, j;
-	int s = 0;
-	byte *Xi;
-	
-	for(i=nrl; i<=nrh; i++) {
-		Xi = m[i];
-		for(j=ncl; j<=nch; j++) {
-			s += Xi[j];
-		}
-    }
-    return s;
-}
+
+
+sum_type_matrix(int8_t, int32_t);
+sum_type_matrix(uint8_t, uint32_t);
+sum_type_matrix(int16_t, int32_t);
+sum_type_matrix(uint16_t, uint32_t);
+sum_type_matrix(int32_t, int64_t);
+sum_type_matrix(uint32_t, uint64_t);
+sum_type_matrix(int64_t, int64_t);
+sum_type_matrix(uint64_t, uint64_t);
+sum_type_matrix(float, float);
+sum_type_matrix(double, 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 805)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrio2.c	(revision 821)
@@ -1001,9 +1001,11 @@
     char buffer[80];
     int i;
+    (void) gris;
     
     // open file
     fd = open(filename, O_RDONLY);
     if (fd < 0) {
-        printf("*** Error: Can't open file %s in %s.\n", filename, __func__);
+        printf("\n*** Error: Can't open file %s in %s.\n", filename, __func__);
+        exit(1);
     }
     
@@ -1046,7 +1048,9 @@
     int i;
     
+    //fd = open(filename, O_WRONLY | O_TRUNC | O_CREAT);
     fd = open(filename, O_TRUNC | O_CREAT);
     if (fd < 0) {
-        printf("*** Error: Impossible to open file %s in %s\n", filename, __func__);
+        printf("\n*** Error: Impossible to open file %s in %s\n", filename, __func__);
+        return;
     }
     
Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nrkernel.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrkernel.c	(revision 805)
+++ 	(revision )
@@ -1,181 +1,0 @@
-// ------------------
-// --- nrkernel.c ---
-// ------------------
-
-/*
- * Copyright (c) 2000-2014, Lionel Lacassagne, All rights reserved
- * Univ Paris Sud XI, CNRS
- *
- * Distributed under the Boost Software License, Version 1.0
- * see accompanying file LICENSE.txt or copy it at
- * http://www.boost.org/LICENSE_1_0.txt
- */
-
-/* 
-* 2002/06/11 ajout des fonctions endline
-*/
-#include <stdio.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <math.h> // fabs
-
-#include "nrc_os_config.h"
-#include "mypredef.h"
-#include "nrtype.h"
-#include "nrdef.h"
-#include "nrmacro.h"
-#include "nrkernel.h"
-
-/* ------------------------- */
-void nrerror0(char error_text[])
-/* ------------------------- */
-/* Numerical Recipes standard error handler */
-{
-    printf("Numerical Recipes run-time error...\n");
-    printf("%s\n",error_text);
-    giet_pthread_exit("...now exiting to system...\n");
-}
-/* ------------------------- */
-void nrerror1(char *format, ...)
-/* ------------------------- */
-/* global error handler */
-{
-	/*va_list pa;
-	int n;
-	char *s, c;
-	float f;
-
-    printf("NRC nrerror: ");
-	va_start(pa, format);
-
-	while (*format != '\0') {
-		if ( *format == '%' ) {
-			switch (*++format) {
-				case '%' : putchar('%'); break;
-				case 'c' :
-					c = va_arg(pa, int); // 'char' is promoted to 'int' when passed through '...'
-					putchar(c);
-					break;
-				case 'd' :
-					n = va_arg(pa, int);
-					printf("%d", n); 
-					break;
-				case 'f' : // affichage d'un float
-					f = (float) va_arg(pa, double);    // 'float' is promoted to 'double' when passed through '...'
-					printf("%f", f); 
-					break;
-				case 's' :
-					s = va_arg(pa, char*);
-					for ( ; *s != '\0'; s++ ) 
-						putchar(*s);
-					break;
-			}
-		}
-		else 
-			putchar( *format);
-		format++;
-	}   
-	va_end(pa);
-	putchar('\n');
-	exit(-1);
-     */
-}
-/* ------------------------- */
-void nrerror(char error_text[])
-/* ------------------------- */
-/* Numerical Recipes standard error handler */
-{
-    nrerror0(error_text);
-}
-// --------------------------
-void Error(char *format, ...)
-// --------------------------
-{
-    giet_pthread_exit("NRC 'Error' with variable length args is currently unavailable\nuse nrerror until 'include <stdarg.h>' issue will be addressed\n");
-    
-	/*va_list pa;
-	int n;
-	char *s, c;
-	float f;
-
-    printf("NRC Error: ");
-	va_start(pa, format);
-
-	while (*format != '\0') {
-		if ( *format == '%' ) {
-			switch (*++format) {
-				case '%' : putchar('%'); break;
-				case 'c' :
-					c = va_arg(pa, int); // 'char' is promoted to 'int' when passed through '...'
-					putchar(c);
-					break;
-				case 'd' :
-					n = va_arg(pa, int);
-					printf("%d", n); 
-					break;
-				case 'f' : // affichage d'un float
-					f = (float) va_arg(pa, double);    // 'float' is promoted to 'double' when passed through '...'
-					printf("%f", f); 
-					break;
-				case 's' :
-					s = va_arg(pa, char*);
-					for ( ; *s != '\0'; s++ ) 
-						putchar(*s);
-					break;
-			}
-		}
-		else 
-			putchar( *format);
-		format++;
-	}   
-	va_end(pa);
-	putchar('\n');
-	exit(-1);
-     */
-}
-// ----------------------------
-void Warning(char *format, ...)
-// ----------------------------
-{
-    giet_pthread_exit("NRC 'Warning' with variable length args is currently unavailable\nuse nrerror until 'include <stdarg.h>' issue will be addressed");
-    
-	/*
-     va_list pa;
-	int n;
-	char *s, c;
-	float f;
-
-	va_start(pa, format);
-
-	while (*format != '\0') {
-		if ( *format == '%' ) {
-			switch (*++format) {
-				case '%' : putchar('%'); break;
-				case 'c' :
-					c = va_arg(pa, int); // 'char' is promoted to 'int' when passed through '...'
-					putchar(c);
-					break;
-				case 'd' :
-					n = va_arg(pa, int);
-					printf("%d", n); 
-					break;
-				case 'f' : // affichage d'un float
-					f = (float) va_arg(pa, double);    // 'float' is promoted to 'double' when passed through '...'
-					printf("%f", f); 
-					break;
-				case 's' :
-					s = va_arg(pa, char*);
-					for ( ; *s != '\0'; s++ ) 
-						putchar(*s);
-					break;
-			}
-		}
-		else 
-			putchar( *format);
-		format++;
-	}   
-	va_end(pa);
-	putchar('\n');
-	//exit(-1);
-     */
-}
Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nrlut.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrlut.c	(revision 805)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrlut.c	(revision 821)
@@ -304,4 +304,5 @@
 	rgb8 *Si;
 	int r, b, g;
+    (void) Si;
 	
 	//FUNCTION_NAME("Histogram_rgbmatrix");
Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nrmem1x.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrmem1x.c	(revision 805)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrmem1x.c	(revision 821)
@@ -11,4 +11,5 @@
 #include <stdio.h>
 #include <stddef.h>
+#include <string.h>
 
 #include "mypredef.h"
Index: soft/giet_vm/applications/rosenfeld/nrc2/src/nrwrap2.c
===================================================================
--- soft/giet_vm/applications/rosenfeld/nrc2/src/nrwrap2.c	(revision 805)
+++ soft/giet_vm/applications/rosenfeld/nrc2/src/nrwrap2.c	(revision 821)
@@ -21,4 +21,5 @@
 #include <math.h> // fabs
 
+#include "nrc_os_config.h"
 #include "mypredef.h"
 #include "nrtype.h"
