[GRASS-SVN] r67658 - in grass/trunk: include include/Make include/defs lib lib/calc raster/r.mapcalc

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jan 25 01:28:12 PST 2016


Author: glynn
Date: 2016-01-25 01:28:12 -0800 (Mon, 25 Jan 2016)
New Revision: 67658

Added:
   grass/trunk/include/calc.h
   grass/trunk/include/defs/calc.h
   grass/trunk/lib/calc/
   grass/trunk/lib/calc/Makefile
   grass/trunk/lib/calc/calc.c
   grass/trunk/lib/calc/check.c
   grass/trunk/lib/calc/function.c
   grass/trunk/lib/calc/xabs.c
   grass/trunk/lib/calc/xacos.c
   grass/trunk/lib/calc/xadd.c
   grass/trunk/lib/calc/xand.c
   grass/trunk/lib/calc/xand2.c
   grass/trunk/lib/calc/xasin.c
   grass/trunk/lib/calc/xatan.c
   grass/trunk/lib/calc/xbitand.c
   grass/trunk/lib/calc/xbitnot.c
   grass/trunk/lib/calc/xbitor.c
   grass/trunk/lib/calc/xbitxor.c
   grass/trunk/lib/calc/xcos.c
   grass/trunk/lib/calc/xdiv.c
   grass/trunk/lib/calc/xdouble.c
   grass/trunk/lib/calc/xeq.c
   grass/trunk/lib/calc/xeval.c
   grass/trunk/lib/calc/xexp.c
   grass/trunk/lib/calc/xfloat.c
   grass/trunk/lib/calc/xge.c
   grass/trunk/lib/calc/xgraph.c
   grass/trunk/lib/calc/xgt.c
   grass/trunk/lib/calc/xif.c
   grass/trunk/lib/calc/xint.c
   grass/trunk/lib/calc/xisnull.c
   grass/trunk/lib/calc/xle.c
   grass/trunk/lib/calc/xlog.c
   grass/trunk/lib/calc/xlt.c
   grass/trunk/lib/calc/xmax.c
   grass/trunk/lib/calc/xmedian.c
   grass/trunk/lib/calc/xmin.c
   grass/trunk/lib/calc/xmod.c
   grass/trunk/lib/calc/xmode.c
   grass/trunk/lib/calc/xmul.c
   grass/trunk/lib/calc/xne.c
   grass/trunk/lib/calc/xneg.c
   grass/trunk/lib/calc/xnmax.c
   grass/trunk/lib/calc/xnmedian.c
   grass/trunk/lib/calc/xnmin.c
   grass/trunk/lib/calc/xnmode.c
   grass/trunk/lib/calc/xnot.c
   grass/trunk/lib/calc/xnull.c
   grass/trunk/lib/calc/xor.c
   grass/trunk/lib/calc/xor2.c
   grass/trunk/lib/calc/xpow.c
   grass/trunk/lib/calc/xrand.c
   grass/trunk/lib/calc/xround.c
   grass/trunk/lib/calc/xshiftl.c
   grass/trunk/lib/calc/xshiftr.c
   grass/trunk/lib/calc/xshiftru.c
   grass/trunk/lib/calc/xsin.c
   grass/trunk/lib/calc/xsqrt.c
   grass/trunk/lib/calc/xsub.c
   grass/trunk/lib/calc/xtan.c
Removed:
   grass/trunk/raster/r.mapcalc/check.c
   grass/trunk/raster/r.mapcalc/xabs.c
   grass/trunk/raster/r.mapcalc/xacos.c
   grass/trunk/raster/r.mapcalc/xadd.c
   grass/trunk/raster/r.mapcalc/xand.c
   grass/trunk/raster/r.mapcalc/xand2.c
   grass/trunk/raster/r.mapcalc/xasin.c
   grass/trunk/raster/r.mapcalc/xatan.c
   grass/trunk/raster/r.mapcalc/xbitand.c
   grass/trunk/raster/r.mapcalc/xbitnot.c
   grass/trunk/raster/r.mapcalc/xbitor.c
   grass/trunk/raster/r.mapcalc/xbitxor.c
   grass/trunk/raster/r.mapcalc/xcos.c
   grass/trunk/raster/r.mapcalc/xdiv.c
   grass/trunk/raster/r.mapcalc/xdouble.c
   grass/trunk/raster/r.mapcalc/xeq.c
   grass/trunk/raster/r.mapcalc/xeval.c
   grass/trunk/raster/r.mapcalc/xexp.c
   grass/trunk/raster/r.mapcalc/xfloat.c
   grass/trunk/raster/r.mapcalc/xge.c
   grass/trunk/raster/r.mapcalc/xgraph.c
   grass/trunk/raster/r.mapcalc/xgt.c
   grass/trunk/raster/r.mapcalc/xif.c
   grass/trunk/raster/r.mapcalc/xint.c
   grass/trunk/raster/r.mapcalc/xisnull.c
   grass/trunk/raster/r.mapcalc/xle.c
   grass/trunk/raster/r.mapcalc/xlog.c
   grass/trunk/raster/r.mapcalc/xlt.c
   grass/trunk/raster/r.mapcalc/xmax.c
   grass/trunk/raster/r.mapcalc/xmedian.c
   grass/trunk/raster/r.mapcalc/xmin.c
   grass/trunk/raster/r.mapcalc/xmod.c
   grass/trunk/raster/r.mapcalc/xmode.c
   grass/trunk/raster/r.mapcalc/xmul.c
   grass/trunk/raster/r.mapcalc/xne.c
   grass/trunk/raster/r.mapcalc/xneg.c
   grass/trunk/raster/r.mapcalc/xnmax.c
   grass/trunk/raster/r.mapcalc/xnmedian.c
   grass/trunk/raster/r.mapcalc/xnmin.c
   grass/trunk/raster/r.mapcalc/xnmode.c
   grass/trunk/raster/r.mapcalc/xnot.c
   grass/trunk/raster/r.mapcalc/xnull.c
   grass/trunk/raster/r.mapcalc/xor.c
   grass/trunk/raster/r.mapcalc/xor2.c
   grass/trunk/raster/r.mapcalc/xpow.c
   grass/trunk/raster/r.mapcalc/xrand.c
   grass/trunk/raster/r.mapcalc/xround.c
   grass/trunk/raster/r.mapcalc/xshiftl.c
   grass/trunk/raster/r.mapcalc/xshiftr.c
   grass/trunk/raster/r.mapcalc/xshiftru.c
   grass/trunk/raster/r.mapcalc/xsin.c
   grass/trunk/raster/r.mapcalc/xsqrt.c
   grass/trunk/raster/r.mapcalc/xsub.c
   grass/trunk/raster/r.mapcalc/xtan.c
Modified:
   grass/trunk/include/Make/Grass.make
   grass/trunk/lib/Makefile
   grass/trunk/raster/r.mapcalc/Makefile
   grass/trunk/raster/r.mapcalc/evaluate.c
   grass/trunk/raster/r.mapcalc/expression.c
   grass/trunk/raster/r.mapcalc/expression.h
   grass/trunk/raster/r.mapcalc/func_proto.h
   grass/trunk/raster/r.mapcalc/function.c
   grass/trunk/raster/r.mapcalc/globals.h
   grass/trunk/raster/r.mapcalc/main.c
   grass/trunk/raster/r.mapcalc/map.c
   grass/trunk/raster/r.mapcalc/map3.c
Log:
Move vectorised functions from r.mapcalc into a separate library


Modified: grass/trunk/include/Make/Grass.make
===================================================================
--- grass/trunk/include/Make/Grass.make	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/include/Make/Grass.make	2016-01-25 09:28:12 UTC (rev 67658)
@@ -114,6 +114,7 @@
 	BTREE:btree \
 	BTREE2:btree2 \
 	CAIRODRIVER:cairodriver \
+	CALC:calc \
 	CDHC:cdhc \
 	CCMATH:ccmath \
 	CLUSTER:cluster \
@@ -183,6 +184,7 @@
 BITMAPDEPS       = $(LINKMLIB)
 BTREE2DEPS       = $(GISLIB)
 CAIRODRIVERDEPS  = $(DRIVERLIB) $(GISLIB) $(CAIROLIB) $(FCLIB) $(ICONVLIB)
+CALCDEPS         = $(RASTERLIB) $(GISLIB) $(MATHLIB)
 CDHCDEPS         = $(MATHLIB)
 CLUSTERDEPS      = $(IMAGERYLIB) $(RASTERLIB) $(GISLIB) $(MATHLIB)
 DBMIBASEDEPS     = $(GISLIB)

Added: grass/trunk/include/calc.h
===================================================================
--- grass/trunk/include/calc.h	                        (rev 0)
+++ grass/trunk/include/calc.h	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,45 @@
+
+#ifndef GRASS_CALC_H
+#define GRASS_CALC_H
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+
+typedef int func_t(int argc, const int *argt, void **args);
+typedef int args_t(int argc, int *argt);
+
+enum {
+    E_ARG_LO	= 1,
+    E_ARG_HI	= 2,
+    E_ARG_TYPE	= 3,
+    E_RES_TYPE	= 4,
+    E_INV_TYPE	= 5,
+    E_ARG_NUM	= 6,
+    E_WTF	= 99
+};
+
+typedef struct func_desc
+{
+    const char *name;
+    args_t *check_args;
+    func_t *func;
+} func_desc;
+
+#define IS_NULL_C(x) (Rast_is_c_null_value((x)))
+#define IS_NULL_F(x) (Rast_is_f_null_value((x)))
+#define IS_NULL_D(x) (Rast_is_d_null_value((x)))
+
+#define SET_NULL_C(x) (Rast_set_c_null_value((x),1))
+#define SET_NULL_F(x) (Rast_set_f_null_value((x),1))
+#define SET_NULL_D(x) (Rast_set_d_null_value((x),1))
+
+extern volatile int floating_point_exception;
+extern volatile int floating_point_exception_occurred;
+
+extern int columns;
+
+extern func_desc calc_func_descs[];
+
+#include <grass/defs/calc.h>
+
+#endif

Added: grass/trunk/include/defs/calc.h
===================================================================
--- grass/trunk/include/defs/calc.h	                        (rev 0)
+++ grass/trunk/include/defs/calc.h	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,107 @@
+
+#ifndef GRASS_CALCDEFS_H
+#define GRASS_CALCDEFS_H
+
+extern void calc_init(int);
+extern void pre_exec(void);
+extern void post_exec(void);
+
+extern func_t f_add;
+extern func_t f_sub;
+extern func_t f_mul;
+extern func_t f_div;
+extern func_t f_mod;
+extern func_t f_pow;
+extern args_t c_binop;
+
+extern func_t f_neg;
+extern func_t f_abs;
+extern args_t c_unop;
+
+extern func_t f_gt;
+extern func_t f_ge;
+extern func_t f_lt;
+extern func_t f_le;
+extern func_t f_eq;
+extern func_t f_ne;
+extern args_t c_cmpop;
+
+extern func_t f_and;
+extern func_t f_or;
+extern func_t f_and2;
+extern func_t f_or2;
+extern func_t f_bitand;
+extern func_t f_bitor;
+extern func_t f_bitxor;
+extern args_t c_logop;
+
+extern func_t f_shiftl;
+extern func_t f_shiftr;
+extern func_t f_shiftru;
+extern args_t c_shiftop;
+
+extern func_t f_not;
+extern func_t f_bitnot;
+extern args_t c_not;
+
+extern func_t f_sqrt;
+extern func_t f_sin;
+extern func_t f_cos;
+extern func_t f_tan;
+extern func_t f_acos;
+extern func_t f_asin;
+extern args_t c_double1;
+
+extern func_t f_exp;
+extern func_t f_log;
+extern func_t f_atan;
+extern args_t c_double12;
+
+extern func_t f_int;
+extern args_t c_int;
+
+extern func_t f_float;
+extern args_t c_float;
+
+extern func_t f_double;
+extern args_t c_double;
+
+extern func_t f_round;
+extern args_t c_round;
+
+extern func_t f_eval;
+extern args_t c_eval;
+
+extern func_t f_if;
+extern args_t c_if;
+
+extern func_t f_isnull;
+extern args_t c_isnull;
+
+extern func_t f_graph;
+extern func_t f_graph2;
+extern args_t c_graph;
+
+extern func_t f_min;
+extern func_t f_max;
+extern func_t f_nmin;
+extern func_t f_nmax;
+extern args_t c_varop;
+
+extern func_t f_median;
+extern func_t f_nmedian;
+extern args_t c_median;
+
+extern func_t f_mode;
+extern func_t f_nmode;
+extern args_t c_mode;
+
+extern func_t f_rand;
+extern args_t c_binop;
+
+extern func_t f_null;
+extern args_t c_int0;
+
+extern args_t c_double0;
+
+#endif

Modified: grass/trunk/lib/Makefile
===================================================================
--- grass/trunk/lib/Makefile	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/lib/Makefile	2016-01-25 09:28:12 UTC (rev 67658)
@@ -43,7 +43,8 @@
 	temporal \
 	python \
 	iostream \
-	manage
+	manage \
+	calc
 
 include $(MODULE_TOPDIR)/include/Make/Dir.make
 include $(MODULE_TOPDIR)/include/Make/Doxygen.make


Property changes on: grass/trunk/lib/calc
___________________________________________________________________
Added: svn:ignore
   + OBJ.*


Added: grass/trunk/lib/calc/Makefile
===================================================================
--- grass/trunk/lib/calc/Makefile	                        (rev 0)
+++ grass/trunk/lib/calc/Makefile	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,8 @@
+MODULE_TOPDIR = ../..
+
+
+LIB = CALC
+
+include $(MODULE_TOPDIR)/include/Make/Lib.make
+
+default: lib

Added: grass/trunk/lib/calc/calc.c
===================================================================
--- grass/trunk/lib/calc/calc.c	                        (rev 0)
+++ grass/trunk/lib/calc/calc.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,62 @@
+
+#include <unistd.h>
+#include <signal.h>
+
+#include <grass/calc.h>
+
+/****************************************************************************/
+
+volatile int floating_point_exception;
+volatile int floating_point_exception_occurred;
+
+int columns;
+
+/****************************************************************************/
+
+static RETSIGTYPE handle_fpe(int n)
+{
+    floating_point_exception = 1;
+    floating_point_exception_occurred = 1;
+}
+
+void pre_exec(void)
+{
+#ifndef __MINGW32__
+#ifdef SIGFPE
+    struct sigaction act;
+
+    act.sa_handler = &handle_fpe;
+    act.sa_flags = 0;
+    sigemptyset(&act.sa_mask);
+
+    sigaction(SIGFPE, &act, NULL);
+#endif
+#endif
+
+    floating_point_exception_occurred = 0;
+}
+
+void post_exec(void)
+{
+#ifndef __MINGW32__
+#ifdef SIGFPE
+    struct sigaction act;
+
+    act.sa_handler = SIG_DFL;
+    act.sa_flags = 0;
+    sigemptyset(&act.sa_mask);
+
+    sigaction(SIGFPE, &act, NULL);
+#endif
+#endif
+}
+
+/****************************************************************************/
+
+void calc_init(int cols)
+{
+    columns = cols;
+}
+
+/****************************************************************************/
+

Copied: grass/trunk/lib/calc/check.c (from rev 67656, grass/trunk/raster/r.mapcalc/check.c)
===================================================================
--- grass/trunk/lib/calc/check.c	                        (rev 0)
+++ grass/trunk/lib/calc/check.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,159 @@
+
+#include <grass/calc.h>
+
+int c_int0(int argc, int *argt)
+{
+    if (argc > 0)
+	return E_ARG_HI;
+
+    argt[0] = CELL_TYPE;
+
+    return 0;
+}
+
+int c_double0(int argc, int *argt)
+{
+    if (argc > 0)
+	return E_ARG_HI;
+
+    argt[0] = DCELL_TYPE;
+
+    return 0;
+}
+
+int c_double1(int argc, int *argt)
+{
+    if (argc < 1)
+	return E_ARG_LO;
+    if (argc > 1)
+	return E_ARG_HI;
+
+    argt[0] = DCELL_TYPE;
+    argt[1] = DCELL_TYPE;
+
+    return 0;
+}
+
+int c_double12(int argc, int *argt)
+{
+    if (argc < 1)
+	return E_ARG_LO;
+
+    if (argc > 2)
+	return E_ARG_HI;
+
+    argt[0] = DCELL_TYPE;
+    argt[1] = DCELL_TYPE;
+    if (argc == 2)
+	argt[2] = DCELL_TYPE;
+
+    return 0;
+}
+
+int c_unop(int argc, int *argt)
+{
+    if (argc < 1)
+	return E_ARG_LO;
+    if (argc > 1)
+	return E_ARG_HI;
+
+    argt[0] = argt[1];
+
+    return 0;
+}
+
+int c_binop(int argc, int *argt)
+{
+    if (argc < 2)
+	return E_ARG_LO;
+    if (argc > 2)
+	return E_ARG_HI;
+
+    argt[0] = CELL_TYPE;
+    if (argt[1] == FCELL_TYPE || argt[2] == FCELL_TYPE)
+	argt[0] = FCELL_TYPE;
+    if (argt[1] == DCELL_TYPE || argt[2] == DCELL_TYPE)
+	argt[0] = DCELL_TYPE;
+
+    argt[1] = argt[0];
+    argt[2] = argt[0];
+
+    return 0;
+}
+
+int c_varop(int argc, int *argt)
+{
+    int i;
+
+    if (argc < 1)
+	return E_ARG_LO;
+
+    argt[0] = CELL_TYPE;
+
+    for (i = 1; i <= argc; i++)
+	if (argt[i] == FCELL_TYPE)
+	    argt[0] = FCELL_TYPE;
+
+    for (i = 1; i <= argc; i++)
+	if (argt[i] == DCELL_TYPE)
+	    argt[0] = DCELL_TYPE;
+
+    for (i = 1; i <= argc; i++)
+	argt[i] = argt[0];
+
+    return 0;
+}
+
+int c_cmpop(int argc, int *argt)
+{
+    int arg_type;
+
+    if (argc < 2)
+	return E_ARG_LO;
+    if (argc > 2)
+	return E_ARG_HI;
+
+    argt[0] = CELL_TYPE;
+
+    arg_type = CELL_TYPE;
+    if (argt[1] == FCELL_TYPE || argt[2] == FCELL_TYPE)
+	arg_type = FCELL_TYPE;
+    if (argt[1] == DCELL_TYPE || argt[2] == DCELL_TYPE)
+	arg_type = DCELL_TYPE;
+
+    argt[1] = arg_type;
+    argt[2] = arg_type;
+
+    return 0;
+}
+
+int c_logop(int argc, int *argt)
+{
+    int i;
+
+    if (argc < 1)
+	return E_ARG_LO;
+
+    for (i = 1; i <= argc; i++)
+	if (argt[i] != CELL_TYPE)
+	    return E_ARG_TYPE;
+
+    argt[0] = CELL_TYPE;
+
+    return 0;
+}
+
+int c_shiftop(int argc, int *argt)
+{
+    if (argc < 2)
+	return E_ARG_LO;
+    if (argc > 2)
+	return E_ARG_HI;
+
+    if (argt[1] != CELL_TYPE || argt[2] != CELL_TYPE)
+	return E_ARG_TYPE;
+
+    argt[0] = CELL_TYPE;
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/function.c (from rev 67656, grass/trunk/raster/r.mapcalc/function.c)
===================================================================
--- grass/trunk/lib/calc/function.c	                        (rev 0)
+++ grass/trunk/lib/calc/function.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,79 @@
+
+#include <grass/calc.h>
+
+func_desc calc_func_descs[] = {
+    {"add", c_varop, f_add},
+    {"sub", c_binop, f_sub},
+    {"mul", c_varop, f_mul},
+    {"div", c_binop, f_div},
+    {"mod", c_binop, f_mod},
+    {"pow", c_binop, f_pow},
+
+    {"neg", c_unop, f_neg},
+    {"abs", c_unop, f_abs},
+
+    {"gt", c_cmpop, f_gt},
+    {"ge", c_cmpop, f_ge},
+    {"lt", c_cmpop, f_lt},
+    {"le", c_cmpop, f_le},
+    {"eq", c_cmpop, f_eq},
+    {"ne", c_cmpop, f_ne},
+
+    {"and", c_logop, f_and},
+    {"or", c_logop, f_or},
+
+    {"and2", c_logop, f_and2},
+    {"or2", c_logop, f_or2},
+
+    {"not", c_not, f_not},
+
+    {"bitand", c_logop, f_bitand},
+    {"bitor", c_logop, f_bitor},
+    {"xor", c_logop, f_bitxor},
+
+    {"shiftl", c_shiftop, f_shiftl},
+    {"shiftr", c_shiftop, f_shiftr},
+    {"shiftru", c_shiftop, f_shiftru},
+
+    {"bitnot", c_not, f_bitnot},
+
+    {"sqrt", c_double1, f_sqrt},
+    {"sin", c_double1, f_sin},
+    {"cos", c_double1, f_cos},
+    {"tan", c_double1, f_tan},
+    {"acos", c_double1, f_acos},
+    {"asin", c_double1, f_asin},
+
+    {"exp", c_double12, f_exp},
+    {"log", c_double12, f_log},
+    {"atan", c_double12, f_atan},
+
+    {"int", c_int, f_int},
+    {"float", c_float, f_float},
+    {"double", c_double, f_double},
+    {"round", c_round, f_round},
+
+    {"eval", c_eval, f_eval},
+    {"if", c_if, f_if},
+    {"isnull", c_isnull, f_isnull},
+
+    {"max", c_varop, f_max},
+    {"min", c_varop, f_min},
+    {"median", c_varop, f_median},
+    {"mode", c_varop, f_mode},
+
+    {"nmax", c_varop, f_nmax},
+    {"nmin", c_varop, f_nmin},
+    {"nmedian", c_varop, f_nmedian},
+    {"nmode", c_varop, f_nmode},
+
+    {"graph", c_graph, f_graph},
+    {"graph2", c_graph, f_graph2},
+
+    {"rand", c_binop, f_rand},
+
+    {"null", c_int0, f_null},
+
+    {NULL, NULL, NULL}
+};
+

Copied: grass/trunk/lib/calc/xabs.c (from rev 67656, grass/trunk/raster/r.mapcalc/xabs.c)
===================================================================
--- grass/trunk/lib/calc/xabs.c	                        (rev 0)
+++ grass/trunk/lib/calc/xabs.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,67 @@
+
+#include <math.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/**********************************************************************
+abs(x)
+
+   absolute value. if x is negative returns -x
+**********************************************************************/
+
+int f_abs(int argc, const int *argt, void **args)
+{
+    int i;
+
+    if (argc < 1)
+	return E_ARG_LO;
+    if (argc > 1)
+	return E_ARG_HI;
+
+    if (argt[0] != argt[1])
+	return E_RES_TYPE;
+
+    switch (argt[1]) {
+    case CELL_TYPE:
+	{
+	    CELL *res = args[0];
+	    CELL *arg1 = args[1];
+
+	    for (i = 0; i < columns; i++)
+		if (IS_NULL_C(&arg1[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg1[i] < 0 ? -arg1[i]
+			: arg1[i];
+	    return 0;
+	}
+    case FCELL_TYPE:
+	{
+	    FCELL *res = args[0];
+	    FCELL *arg1 = args[1];
+
+	    for (i = 0; i < columns; i++)
+		if (IS_NULL_F(&arg1[i]))
+		    SET_NULL_F(&res[i]);
+		else
+		    res[i] = (FCELL) fabs(arg1[i]);
+	    return 0;
+	}
+    case DCELL_TYPE:
+	{
+	    DCELL *res = args[0];
+	    DCELL *arg1 = args[1];
+
+	    for (i = 0; i < columns; i++)
+		if (IS_NULL_D(&arg1[i]))
+		    SET_NULL_D(&res[i]);
+		else
+		    res[i] = fabs(arg1[i]);
+	    return 0;
+	}
+    default:
+	return E_INV_TYPE;
+    }
+}

Copied: grass/trunk/lib/calc/xacos.c (from rev 67656, grass/trunk/raster/r.mapcalc/xacos.c)
===================================================================
--- grass/trunk/lib/calc/xacos.c	                        (rev 0)
+++ grass/trunk/lib/calc/xacos.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,48 @@
+
+#include <stdlib.h>
+#include <math.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/**********************************************************************
+acos(x)  [0 and PI]
+
+  if floating point exception occurs during the evaluation of acos(x)
+  the result is NULL
+
+  note: result is in degrees
+**********************************************************************/
+
+#define RADIANS_TO_DEGREES (180.0 / M_PI)
+
+int f_acos(int argc, const int *argt, void **args)
+{
+    DCELL *res = args[0];
+    DCELL *arg1 = args[1];
+    int i;
+
+    if (argc < 1)
+	return E_ARG_LO;
+    if (argc > 1)
+	return E_ARG_HI;
+
+    if (argt[0] != DCELL_TYPE)
+	return E_RES_TYPE;
+
+    if (argt[1] != DCELL_TYPE)
+	return E_ARG_TYPE;
+
+    for (i = 0; i < columns; i++)
+	if (IS_NULL_D(&arg1[i]))
+	    SET_NULL_D(&res[i]);
+	else {
+	    floating_point_exception = 0;
+	    res[i] = RADIANS_TO_DEGREES * acos(arg1[i]);
+	    if (floating_point_exception)
+		SET_NULL_D(&res[i]);
+	}
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/xadd.c (from rev 67656, grass/trunk/raster/r.mapcalc/xadd.c)
===================================================================
--- grass/trunk/lib/calc/xadd.c	                        (rev 0)
+++ grass/trunk/lib/calc/xadd.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,76 @@
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+add(a,b,c,...) = a + b + c + ...
+****************************************************************/
+
+int f_add(int argc, const int *argt, void **args)
+{
+    int i, j;
+
+    if (argc < 1)
+	return E_ARG_LO;
+
+    for (i = 1; i <= argc; i++)
+	if (argt[i] != argt[0])
+	    return E_ARG_TYPE;
+
+    switch (argt[0]) {
+    case CELL_TYPE:
+	{
+	    CELL *res = args[0];
+	    CELL **argz = (CELL **) args;
+
+	    for (i = 0; i < columns; i++) {
+		res[i] = 0;
+		for (j = 1; j <= argc; j++) {
+		    if (IS_NULL_C(&argz[j][i])) {
+			SET_NULL_C(&res[i]);
+			break;
+		    }
+		    res[i] += argz[j][i];
+		}
+	    }
+	    return 0;
+	}
+    case FCELL_TYPE:
+	{
+	    FCELL *res = args[0];
+	    FCELL **argz = (FCELL **) args;
+
+	    for (i = 0; i < columns; i++) {
+		res[i] = 0;
+		for (j = 1; j <= argc; j++) {
+		    if (IS_NULL_F(&argz[j][i])) {
+			SET_NULL_F(&res[i]);
+			break;
+		    }
+		    res[i] += argz[j][i];
+		}
+	    }
+	    return 0;
+	}
+    case DCELL_TYPE:
+	{
+	    DCELL *res = args[0];
+	    DCELL **argz = (DCELL **) args;
+
+	    for (i = 0; i < columns; i++) {
+		res[i] = 0;
+		for (j = 1; j <= argc; j++) {
+		    if (IS_NULL_D(&argz[j][i])) {
+			SET_NULL_D(&res[i]);
+			break;
+		    }
+		    res[i] += argz[j][i];
+		}
+	    }
+	    return 0;
+	}
+    default:
+	return E_INV_TYPE;
+    }
+}

Copied: grass/trunk/lib/calc/xand.c (from rev 67656, grass/trunk/raster/r.mapcalc/xand.c)
===================================================================
--- grass/trunk/lib/calc/xand.c	                        (rev 0)
+++ grass/trunk/lib/calc/xand.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,39 @@
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+and(a,b,c,...) = a && b && c && ...
+****************************************************************/
+
+int f_and(int argc, const int *argt, void **args)
+{
+    CELL *res = args[0];
+    CELL **argz = (CELL **) args;
+    int i, j;
+
+    if (argc < 1)
+	return E_ARG_LO;
+
+    if (argt[0] != CELL_TYPE)
+	return E_RES_TYPE;
+
+    for (i = 1; i <= argc; i++)
+	if (argt[i] != CELL_TYPE)
+	    return E_ARG_TYPE;
+
+    for (i = 0; i < columns; i++) {
+	res[i] = 1;
+	for (j = 1; j <= argc; j++) {
+	    if (IS_NULL_C(&argz[j][i])) {
+		SET_NULL_C(&res[i]);
+		break;
+	    }
+	    if (!argz[j][i])
+		res[i] = 0;
+	}
+    }
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/xand2.c (from rev 67656, grass/trunk/raster/r.mapcalc/xand2.c)
===================================================================
--- grass/trunk/lib/calc/xand2.c	                        (rev 0)
+++ grass/trunk/lib/calc/xand2.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,46 @@
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+and2(a,b,c,...) = a && b && c && ...
+
+Differs from and() in that the boolean axioms:
+
+	false && x == false
+	x && false == false
+
+hold even when x is null.
+****************************************************************/
+
+int f_and2(int argc, const int *argt, void **args)
+{
+    CELL *res = args[0];
+    CELL **argz = (CELL **) args;
+    int i, j;
+
+    if (argc < 1)
+	return E_ARG_LO;
+
+    if (argt[0] != CELL_TYPE)
+	return E_RES_TYPE;
+
+    for (i = 1; i <= argc; i++)
+	if (argt[i] != CELL_TYPE)
+	    return E_ARG_TYPE;
+
+    for (i = 0; i < columns; i++) {
+	res[i] = 1;
+	for (j = 1; j <= argc; j++) {
+	    if (!IS_NULL_C(&argz[j][i]) && !argz[j][i]) {
+		res[i] = 0;
+		break;
+	    }
+	    if (IS_NULL_C(&argz[j][i]))
+		SET_NULL_C(&res[i]);
+	}
+    }
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/xasin.c (from rev 67656, grass/trunk/raster/r.mapcalc/xasin.c)
===================================================================
--- grass/trunk/lib/calc/xasin.c	                        (rev 0)
+++ grass/trunk/lib/calc/xasin.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,48 @@
+
+#include <stdlib.h>
+#include <math.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/**********************************************************************
+asin(x)  range [-90,90]
+
+  if floating point exception occurs during the evaluation of asin(x)
+  the result is NULL
+
+  note: result is in degrees
+**********************************************************************/
+
+#define RADIANS_TO_DEGREES (180.0 / M_PI)
+
+int f_asin(int argc, const int *argt, void **args)
+{
+    DCELL *res = args[0];
+    DCELL *arg1 = args[1];
+    int i;
+
+    if (argc < 1)
+	return E_ARG_LO;
+    if (argc > 1)
+	return E_ARG_HI;
+
+    if (argt[0] != DCELL_TYPE)
+	return E_RES_TYPE;
+
+    if (argt[1] != DCELL_TYPE)
+	return E_ARG_TYPE;
+
+    for (i = 0; i < columns; i++)
+	if (IS_NULL_D(&arg1[i]))
+	    SET_NULL_D(&res[i]);
+	else {
+	    floating_point_exception = 0;
+	    res[i] = RADIANS_TO_DEGREES * asin(arg1[i]);
+	    if (floating_point_exception)
+		SET_NULL_D(&res[i]);
+	}
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/xatan.c (from rev 67656, grass/trunk/raster/r.mapcalc/xatan.c)
===================================================================
--- grass/trunk/lib/calc/xatan.c	                        (rev 0)
+++ grass/trunk/lib/calc/xatan.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,64 @@
+
+#include <stdlib.h>
+#include <math.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/**********************************************************************
+atan(x)     range [-90,90]
+atan(x,y) = atan(y/x) range[0,360]
+
+  if floating point exception occurs during the evaluation of atan(x)
+  the result is NULL
+
+  note: result is in degrees
+**********************************************************************/
+
+#define RADIANS_TO_DEGREES (180.0 / M_PI)
+
+int f_atan(int argc, const int *argt, void **args)
+{
+    DCELL *res = args[0];
+    DCELL *arg1 = args[1];
+    DCELL *arg2;
+    int i;
+
+    if (argc < 1)
+	return E_ARG_LO;
+    if (argc > 2)
+	return E_ARG_HI;
+
+    if (argt[0] != DCELL_TYPE)
+	return E_RES_TYPE;
+
+    if (argt[1] != DCELL_TYPE)
+	return E_ARG_TYPE;
+
+    if (argc > 1 && argt[2] != DCELL_TYPE)
+	return E_ARG_TYPE;
+
+    arg2 = (argc > 1) ? args[2] : NULL;
+
+    for (i = 0; i < columns; i++)
+	if (IS_NULL_D(&arg1[i]))
+	    SET_NULL_D(&res[i]);
+	else if (argc > 1 && IS_NULL_D(&arg2[i]))
+	    SET_NULL_D(&res[i]);
+
+	else {
+	    floating_point_exception = 0;
+	    if (argc == 1)
+		res[i] = RADIANS_TO_DEGREES * atan(arg1[i]);
+	    else {
+		res[i] = RADIANS_TO_DEGREES * atan2(arg2[i], arg1[i]);
+		if (res[i] < 0)
+		    res[i] += 360.0;
+	    }
+	    if (floating_point_exception)
+		SET_NULL_D(&res[i]);
+	}
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/xbitand.c (from rev 67656, grass/trunk/raster/r.mapcalc/xbitand.c)
===================================================================
--- grass/trunk/lib/calc/xbitand.c	                        (rev 0)
+++ grass/trunk/lib/calc/xbitand.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,38 @@
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+bitand(a,b,c,...) = a & b & c & ...
+****************************************************************/
+
+int f_bitand(int argc, const int *argt, void **args)
+{
+    CELL *res = args[0];
+    CELL **argz = (CELL **) args;
+    int i, j;
+
+    if (argc < 1)
+	return E_ARG_LO;
+
+    if (argt[0] != CELL_TYPE)
+	return E_RES_TYPE;
+
+    for (i = 1; i <= argc; i++)
+	if (argt[i] != CELL_TYPE)
+	    return E_ARG_TYPE;
+
+    for (i = 0; i < columns; i++) {
+	res[i] = ~0;
+	for (j = 1; j <= argc; j++) {
+	    if (IS_NULL_C(&argz[j][i])) {
+		SET_NULL_C(&res[i]);
+		break;
+	    }
+	    res[i] &= argz[j][i];
+	}
+    }
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/xbitnot.c (from rev 67656, grass/trunk/raster/r.mapcalc/xbitnot.c)
===================================================================
--- grass/trunk/lib/calc/xbitnot.c	                        (rev 0)
+++ grass/trunk/lib/calc/xbitnot.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,35 @@
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+bitnot(a) = ~a
+****************************************************************/
+
+int f_bitnot(int argc, const int *argt, void **args)
+{
+    CELL *res = args[0];
+    CELL *arg1 = args[1];
+    int i;
+
+    if (argc < 1)
+	return E_ARG_LO;
+    if (argc > 1)
+	return E_ARG_HI;
+
+    if (argt[1] != CELL_TYPE)
+	return E_ARG_TYPE;
+
+    if (argt[0] != CELL_TYPE)
+	return E_RES_TYPE;
+
+    for (i = 0; i < columns; i++) {
+	if (IS_NULL_C(&arg1[i]))
+	    SET_NULL_C(&res[i]);
+	else
+	    res[i] = ~arg1[i];
+    }
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/xbitor.c (from rev 67656, grass/trunk/raster/r.mapcalc/xbitor.c)
===================================================================
--- grass/trunk/lib/calc/xbitor.c	                        (rev 0)
+++ grass/trunk/lib/calc/xbitor.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,38 @@
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+bitor(a,b,c,...) = a | b | c | ...
+****************************************************************/
+
+int f_bitor(int argc, const int *argt, void **args)
+{
+    CELL *res = args[0];
+    CELL **argz = (CELL **) args;
+    int i, j;
+
+    if (argc < 1)
+	return E_ARG_LO;
+
+    if (argt[0] != CELL_TYPE)
+	return E_RES_TYPE;
+
+    for (i = 1; i <= argc; i++)
+	if (argt[i] != CELL_TYPE)
+	    return E_ARG_TYPE;
+
+    for (i = 0; i < columns; i++) {
+	res[i] = 0;
+	for (j = 1; j <= argc; j++) {
+	    if (IS_NULL_C(&argz[j][i])) {
+		SET_NULL_C(&res[i]);
+		break;
+	    }
+	    res[i] |= argz[j][i];
+	}
+    }
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/xbitxor.c (from rev 67656, grass/trunk/raster/r.mapcalc/xbitxor.c)
===================================================================
--- grass/trunk/lib/calc/xbitxor.c	                        (rev 0)
+++ grass/trunk/lib/calc/xbitxor.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,38 @@
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+bitxor(a,b,c,...) = a ^ b ^ c ^ ...
+****************************************************************/
+
+int f_bitxor(int argc, const int *argt, void **args)
+{
+    CELL *res = args[0];
+    CELL **argz = (CELL **) args;
+    int i, j;
+
+    if (argc < 1)
+	return E_ARG_LO;
+
+    if (argt[0] != CELL_TYPE)
+	return E_RES_TYPE;
+
+    for (i = 1; i <= argc; i++)
+	if (argt[i] != CELL_TYPE)
+	    return E_ARG_TYPE;
+
+    for (i = 0; i < columns; i++) {
+	res[i] = 0;
+	for (j = 1; j <= argc; j++) {
+	    if (IS_NULL_C(&argz[j][i])) {
+		SET_NULL_C(&res[i]);
+		break;
+	    }
+	    res[i] ^= argz[j][i];
+	}
+    }
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/xcos.c (from rev 67656, grass/trunk/raster/r.mapcalc/xcos.c)
===================================================================
--- grass/trunk/lib/calc/xcos.c	                        (rev 0)
+++ grass/trunk/lib/calc/xcos.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,47 @@
+
+#include <math.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/**********************************************************************
+cos(x) 
+
+  if floating point exception occurs during the evaluation of cos(x)
+  the result is NULL
+
+  note: x is in degrees.
+**********************************************************************/
+
+#define DEGREES_TO_RADIANS (M_PI / 180.0)
+
+int f_cos(int argc, const int *argt, void **args)
+{
+    DCELL *res = args[0];
+    DCELL *arg1 = args[1];
+    int i;
+
+    if (argc < 1)
+	return E_ARG_LO;
+    if (argc > 1)
+	return E_ARG_HI;
+
+    if (argt[0] != DCELL_TYPE)
+	return E_RES_TYPE;
+
+    if (argt[1] != DCELL_TYPE)
+	return E_ARG_TYPE;
+
+    for (i = 0; i < columns; i++)
+	if (IS_NULL_D(&arg1[i]))
+	    SET_NULL_D(&res[i]);
+	else {
+	    floating_point_exception = 0;
+	    res[i] = cos(arg1[i] * DEGREES_TO_RADIANS);
+	    if (floating_point_exception)
+		SET_NULL_D(&res[i]);
+	}
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/xdiv.c (from rev 67656, grass/trunk/raster/r.mapcalc/xdiv.c)
===================================================================
--- grass/trunk/lib/calc/xdiv.c	                        (rev 0)
+++ grass/trunk/lib/calc/xdiv.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,79 @@
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+div(a,b) = a / b
+****************************************************************/
+
+int f_div(int argc, const int *argt, void **args)
+{
+    int i;
+
+    if (argc < 2)
+	return E_ARG_LO;
+    if (argc > 2)
+	return E_ARG_HI;
+
+    if (argt[1] != argt[0] || argt[2] != argt[0])
+	return E_ARG_TYPE;
+
+    switch (argt[0]) {
+    case CELL_TYPE:
+	{
+	    CELL *res = args[0];
+	    CELL *arg1 = args[1];
+	    CELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]) ||
+		    arg2[i] == 0)
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg1[i] / arg2[i];
+	    }
+	    return 0;
+	}
+    case FCELL_TYPE:
+	{
+	    FCELL *res = args[0];
+	    FCELL *arg1 = args[1];
+	    FCELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]) ||
+		    arg2[i] == 0.0f)
+		    SET_NULL_F(&res[i]);
+		else {
+		    floating_point_exception = 0;
+		    res[i] = arg1[i] / arg2[i];
+		    if (floating_point_exception)
+			SET_NULL_F(&res[i]);
+		}
+	    }
+	    return 0;
+	}
+    case DCELL_TYPE:
+	{
+	    DCELL *res = args[0];
+	    DCELL *arg1 = args[1];
+	    DCELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]) ||
+		    arg2[i] == 0.0)
+		    SET_NULL_D(&res[i]);
+		else {
+		    floating_point_exception = 0;
+		    res[i] = arg1[i] / arg2[i];
+		    if (floating_point_exception)
+			SET_NULL_D(&res[i]);
+		}
+	    }
+	    return 0;
+	}
+    default:
+	return E_INV_TYPE;
+    }
+}

Copied: grass/trunk/lib/calc/xdouble.c (from rev 67656, grass/trunk/raster/r.mapcalc/xdouble.c)
===================================================================
--- grass/trunk/lib/calc/xdouble.c	                        (rev 0)
+++ grass/trunk/lib/calc/xdouble.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,76 @@
+
+#include <stdlib.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/**********************************************************************
+double(x)
+  converts x to double
+**********************************************************************/
+
+int f_double(int argc, const int *argt, void **args)
+{
+    DCELL *res = args[0];
+    int i;
+
+    if (argc < 1)
+	return E_ARG_LO;
+    if (argc > 1)
+	return E_ARG_HI;
+
+    if (argt[0] != DCELL_TYPE)
+	return E_RES_TYPE;
+
+    switch (argt[1]) {
+    case CELL_TYPE:
+	{
+	    CELL *arg1 = args[1];
+
+	    for (i = 0; i < columns; i++)
+		if (IS_NULL_C(&arg1[i]))
+		    SET_NULL_D(&res[i]);
+		else
+		    res[i] = (DCELL) arg1[i];
+	    return 0;
+	}
+    case FCELL_TYPE:
+	{
+	    FCELL *arg1 = args[1];
+
+	    for (i = 0; i < columns; i++)
+		if (IS_NULL_F(&arg1[i]))
+		    SET_NULL_D(&res[i]);
+		else
+		    res[i] = (DCELL) arg1[i];
+	    return 0;
+	}
+    case DCELL_TYPE:
+	{
+	    DCELL *arg1 = args[1];
+
+	    for (i = 0; i < columns; i++)
+		if (IS_NULL_D(&arg1[i]))
+		    SET_NULL_D(&res[i]);
+		else
+		    res[i] = (DCELL) arg1[i];
+	    return 0;
+	}
+    default:
+	return E_INV_TYPE;
+    }
+}
+
+int c_double(int argc, int *argt)
+{
+    if (argc < 1)
+	return E_ARG_LO;
+    if (argc > 1)
+	return E_ARG_HI;
+
+    argt[0] = DCELL_TYPE;
+    /*      argt[1] = argt[1];      */
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/xeq.c (from rev 67656, grass/trunk/raster/r.mapcalc/xeq.c)
===================================================================
--- grass/trunk/lib/calc/xeq.c	                        (rev 0)
+++ grass/trunk/lib/calc/xeq.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,70 @@
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+eq(a,b) = a == b
+****************************************************************/
+
+int f_eq(int argc, const int *argt, void **args)
+{
+    CELL *res = args[0];
+    int i;
+
+    if (argc < 2)
+	return E_ARG_LO;
+    if (argc > 2)
+	return E_ARG_HI;
+
+    if (argt[0] != CELL_TYPE)
+	return E_RES_TYPE;
+
+    for (i = 2; i <= argc; i++)
+	if (argt[i] != argt[1])
+	    return E_ARG_TYPE;
+
+    switch (argt[1]) {
+    case CELL_TYPE:
+	{
+	    CELL *arg1 = args[1];
+	    CELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg1[i] == arg2[i];
+	    }
+	    return 0;
+	}
+    case FCELL_TYPE:
+	{
+	    FCELL *arg1 = args[1];
+	    FCELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg1[i] == arg2[i];
+	    }
+	    return 0;
+	}
+    case DCELL_TYPE:
+	{
+	    DCELL *arg1 = args[1];
+	    DCELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg1[i] == arg2[i];
+	    }
+	    return 0;
+	}
+    default:
+	return E_INV_TYPE;
+    }
+}

Copied: grass/trunk/lib/calc/xeval.c (from rev 67656, grass/trunk/raster/r.mapcalc/xeval.c)
===================================================================
--- grass/trunk/lib/calc/xeval.c	                        (rev 0)
+++ grass/trunk/lib/calc/xeval.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,73 @@
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/**********************************************************************
+eval(..,..,..,x) = x
+
+   return last argument
+**********************************************************************/
+
+int f_eval(int argc, const int *argt, void **args)
+{
+    int i;
+
+    if (argc < 1)
+	return E_ARG_LO;
+
+    if (argt[0] != argt[argc])
+	return E_RES_TYPE;
+
+    switch (argt[argc]) {
+    case CELL_TYPE:
+	{
+	    CELL *res = args[0];
+	    CELL *arg1 = args[argc];
+
+	    for (i = 0; i < columns; i++)
+		if (IS_NULL_C(&arg1[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg1[i];
+
+	    return 0;
+	}
+    case FCELL_TYPE:
+	{
+	    FCELL *res = args[0];
+	    FCELL *arg1 = args[argc];
+
+	    for (i = 0; i < columns; i++)
+		if (IS_NULL_F(&arg1[i]))
+		    SET_NULL_F(&res[i]);
+		else
+		    res[i] = arg1[i];
+	    return 0;
+	}
+    case DCELL_TYPE:
+	{
+	    DCELL *res = args[0];
+	    DCELL *arg1 = args[argc];
+
+	    for (i = 0; i < columns; i++)
+		if (IS_NULL_D(&arg1[i]))
+		    SET_NULL_D(&res[i]);
+		else
+		    res[i] = arg1[i];
+	    return 0;
+	}
+    default:
+	return E_INV_TYPE;
+    }
+}
+
+int c_eval(int argc, int *argt)
+{
+    if (argc < 1)
+	return E_ARG_LO;
+
+    argt[0] = argt[argc];
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/xexp.c (from rev 67656, grass/trunk/raster/r.mapcalc/xexp.c)
===================================================================
--- grass/trunk/lib/calc/xexp.c	                        (rev 0)
+++ grass/trunk/lib/calc/xexp.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,53 @@
+
+#include <math.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/**********************************************************************
+exp(x)   computes e raised to power x
+exp(x,y) computes x raised to power y
+
+  if floating point exception occurs during the evaluation of exp(x)
+  or exp(x,y) the result is NULL
+**********************************************************************/
+
+int f_exp(int argc, const int *argt, void **args)
+{
+    DCELL *res = args[0];
+    DCELL *arg1 = args[1];
+    DCELL *arg2;
+    int i;
+
+    if (argc < 1)
+	return E_ARG_LO;
+    if (argc > 2)
+	return E_ARG_HI;
+
+    if (argt[0] != DCELL_TYPE)
+	return E_RES_TYPE;
+
+    if (argt[1] != DCELL_TYPE)
+	return E_ARG_TYPE;
+
+    arg2 = (argc > 1) ? args[2] : NULL;
+
+    for (i = 0; i < columns; i++)
+	if (IS_NULL_D(&arg1[i]))
+	    SET_NULL_D(&res[i]);
+	else if (argc > 1 && IS_NULL_D(&arg2[i]))
+	    SET_NULL_D(&res[i]);
+	else if (argc > 1 && arg1[i] < 0 && arg2[i] != ceil(arg2[i]))
+	    SET_NULL_D(&res[i]);
+	else {
+	    floating_point_exception = 0;
+	    res[i] = (argc > 1)
+		? pow(arg1[i], arg2[i])
+		: exp(arg1[i]);
+	    if (floating_point_exception)
+		SET_NULL_D(&res[i]);
+	}
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/xfloat.c (from rev 67656, grass/trunk/raster/r.mapcalc/xfloat.c)
===================================================================
--- grass/trunk/lib/calc/xfloat.c	                        (rev 0)
+++ grass/trunk/lib/calc/xfloat.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,76 @@
+
+#include <stdlib.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/**********************************************************************
+float(x)
+  converts x to float
+**********************************************************************/
+
+int f_float(int argc, const int *argt, void **args)
+{
+    FCELL *res = args[0];
+    int i;
+
+    if (argc < 1)
+	return E_ARG_LO;
+    if (argc > 1)
+	return E_ARG_HI;
+
+    if (argt[0] != FCELL_TYPE)
+	return E_RES_TYPE;
+
+    switch (argt[1]) {
+    case CELL_TYPE:
+	{
+	    CELL *arg1 = args[1];
+
+	    for (i = 0; i < columns; i++)
+		if (IS_NULL_C(&arg1[i]))
+		    SET_NULL_F(&res[i]);
+		else
+		    res[i] = (FCELL) arg1[i];
+	    return 0;
+	}
+    case FCELL_TYPE:
+	{
+	    FCELL *arg1 = args[1];
+
+	    for (i = 0; i < columns; i++)
+		if (IS_NULL_F(&arg1[i]))
+		    SET_NULL_F(&res[i]);
+		else
+		    res[i] = (FCELL) arg1[i];
+	    return 0;
+	}
+    case DCELL_TYPE:
+	{
+	    DCELL *arg1 = args[1];
+
+	    for (i = 0; i < columns; i++)
+		if (IS_NULL_D(&arg1[i]))
+		    SET_NULL_F(&res[i]);
+		else
+		    res[i] = (FCELL) arg1[i];
+	    return 0;
+	}
+    default:
+	return E_INV_TYPE;
+    }
+}
+
+int c_float(int argc, int *argt)
+{
+    if (argc < 1)
+	return E_ARG_LO;
+    if (argc > 1)
+	return E_ARG_HI;
+
+    argt[0] = FCELL_TYPE;
+    /*      argt[1] = argt[1];      */
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/xge.c (from rev 67656, grass/trunk/raster/r.mapcalc/xge.c)
===================================================================
--- grass/trunk/lib/calc/xge.c	                        (rev 0)
+++ grass/trunk/lib/calc/xge.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,63 @@
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+ge(a,b) = a >= b
+****************************************************************/
+
+int f_ge(int argc, const int *argt, void **args)
+{
+    CELL *res = args[0];
+    int i;
+
+    if (argc < 2)
+	return E_ARG_LO;
+    if (argc > 2)
+	return E_ARG_HI;
+
+    switch (argt[1]) {
+    case CELL_TYPE:
+	{
+	    CELL *arg1 = args[1];
+	    CELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg1[i] >= arg2[i];
+	    }
+	    return 0;
+	}
+    case FCELL_TYPE:
+	{
+	    FCELL *arg1 = args[1];
+	    FCELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg1[i] >= arg2[i];
+	    }
+	    return 0;
+	}
+    case DCELL_TYPE:
+	{
+	    DCELL *arg1 = args[1];
+	    DCELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg1[i] >= arg2[i];
+	    }
+	    return 0;
+	}
+    default:
+	return E_INV_TYPE;
+    }
+}

Copied: grass/trunk/lib/calc/xgraph.c (from rev 67656, grass/trunk/raster/r.mapcalc/xgraph.c)
===================================================================
--- grass/trunk/lib/calc/xgraph.c	                        (rev 0)
+++ grass/trunk/lib/calc/xgraph.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,178 @@
+
+#include <stdlib.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+graph(x, x1,y1, x2,y2, ... xn,yn)  returns y value based on graph
+described by the x,y pairs.
+****************************************************************/
+
+int c_graph(int argc, int *argt)
+{
+    int i;
+
+    if (argc < 3)
+	return E_ARG_LO;
+
+    if (argc % 2 == 0)
+	return E_ARG_NUM;
+
+    for (i = 0; i <= argc; i++)
+	argt[i] = DCELL_TYPE;
+
+    return 0;
+}
+
+int f_graph(int argc, const int *argt, void **args)
+{
+    DCELL **argz = (DCELL **) args;
+    DCELL *res = argz[0];
+    int n = (argc - 1) / 2;
+    int i, j;
+
+    if (argc < 3)
+	return E_ARG_LO;
+
+    if (argc % 2 == 0)
+	return E_ARG_NUM;
+
+    if (argt[0] != DCELL_TYPE)
+	return E_RES_TYPE;
+
+    for (i = 1; i <= argc; i++)
+	if (argt[i] != DCELL_TYPE)
+	    return E_ARG_TYPE;
+
+    for (i = 0; i < columns; i++) {
+#define X(j) (argz[2 + 2 * (j) + 0][i])
+#define Y(j) (argz[2 + 2 * (j) + 1][i])
+#define x (argz[1][i])
+
+	if (IS_NULL_D(&x))
+	    goto null;
+
+	for (j = 0; j < n; j++)
+	    if (IS_NULL_D(&X(j)))
+		goto null;
+
+	for (j = 0; j < n - 1; j++)
+	    if (X(j + 1) <= X(j))
+		goto null;
+
+	if (x <= X(0)) {
+	    if (IS_NULL_D(&Y(0)))
+		goto null;
+	    res[i] = Y(0);
+	    continue;
+	}
+
+	if (x >= X(n - 1)) {
+	    if (IS_NULL_D(&Y(n - 1)))
+		goto null;
+	    res[i] = Y(n - 1);
+	    continue;
+	}
+
+	for (j = 0; j < n - 1; j++) {
+	    if (x > X(j + 1))
+		continue;
+
+	    if (IS_NULL_D(&Y(j)) || IS_NULL_D(&Y(j + 1)))
+		goto null;
+
+	    res[i] =
+		Y(j) + (x - X(j)) * (Y(j + 1) - Y(j)) / (X(j + 1) - X(j));
+
+	    break;
+	}
+#undef X
+#undef Y
+#undef x
+
+	continue;
+
+      null:
+	SET_NULL_D(&res[i]);
+    }
+
+    return 0;
+}
+
+int f_graph2(int argc, const int *argt, void **args)
+{
+    DCELL **argz = (DCELL **) args;
+    DCELL *res = argz[0];
+    int n = (argc - 1) / 2;
+    int i, j;
+
+    if (argc < 3)
+	return E_ARG_LO;
+
+    if (argc % 2 == 0)
+	return E_ARG_NUM;
+
+    if (argt[0] != DCELL_TYPE)
+	return E_RES_TYPE;
+
+    for (i = 1; i <= argc; i++)
+	if (argt[i] != DCELL_TYPE)
+	    return E_ARG_TYPE;
+
+    for (i = 0; i < columns; i++) {
+#define X(j) (argz[2 + (j) + 0][i])
+#define Y(j) (argz[2 + (j) + n][i])
+#define x (argz[1][i])
+
+	if (IS_NULL_D(&x))
+	    goto null;
+
+	for (j = 0; j < n; j++)
+	    if (IS_NULL_D(&X(j)))
+		goto null;
+
+	for (j = 0; j < n - 1; j++)
+	    if (X(j + 1) <= X(j))
+		goto null;
+
+	if (x <= X(0)) {
+	    if (IS_NULL_D(&Y(0)))
+		goto null;
+	    res[i] = Y(0);
+	    continue;
+	}
+
+	if (x >= X(n - 1)) {
+	    if (IS_NULL_D(&Y(n - 1)))
+		goto null;
+	    res[i] = Y(n - 1);
+	    continue;
+	}
+
+	for (j = 0; j < n - 1; j++) {
+	    if (x > X(j + 1))
+		continue;
+
+	    if (IS_NULL_D(&Y(j)) || IS_NULL_D(&Y(j + 1)))
+		goto null;
+
+	    res[i] =
+		Y(j) + (x - X(j)) * (Y(j + 1) - Y(j)) / (X(j + 1) - X(j));
+
+	    break;
+	}
+#undef X
+#undef Y
+#undef x
+
+	continue;
+
+      null:
+	SET_NULL_D(&res[i]);
+    }
+
+    return 0;
+}
+

Copied: grass/trunk/lib/calc/xgt.c (from rev 67656, grass/trunk/raster/r.mapcalc/xgt.c)
===================================================================
--- grass/trunk/lib/calc/xgt.c	                        (rev 0)
+++ grass/trunk/lib/calc/xgt.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,63 @@
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+gt(a,b) = a > b
+****************************************************************/
+
+int f_gt(int argc, const int *argt, void **args)
+{
+    CELL *res = args[0];
+    int i;
+
+    if (argc < 2)
+	return E_ARG_LO;
+    if (argc > 2)
+	return E_ARG_HI;
+
+    switch (argt[1]) {
+    case CELL_TYPE:
+	{
+	    CELL *arg1 = args[1];
+	    CELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg1[i] > arg2[i];
+	    }
+	    return 0;
+	}
+    case FCELL_TYPE:
+	{
+	    FCELL *arg1 = args[1];
+	    FCELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg1[i] > arg2[i];
+	    }
+	    return 0;
+	}
+    case DCELL_TYPE:
+	{
+	    DCELL *arg1 = args[1];
+	    DCELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg1[i] > arg2[i];
+	    }
+	    return 0;
+	}
+    default:
+	return E_INV_TYPE;
+    }
+}

Copied: grass/trunk/lib/calc/xif.c (from rev 67656, grass/trunk/raster/r.mapcalc/xif.c)
===================================================================
--- grass/trunk/lib/calc/xif.c	                        (rev 0)
+++ grass/trunk/lib/calc/xif.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,303 @@
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/********************************************************************
+ if(a)        1,0,1  1 if a is non zero, 0 otherwise
+ if(a,b)      b,0,b  b if a is non zero, 0 otherwise
+ if(a,b,c)    b,c,b  b if a is non zero, c otherwise
+ if(a,b,c,d)  d,c,b  b if a is positive, c if a is zero, d if a is negative
+********************************************************************/
+
+static int f_if_i(int argc, const int *argt, void **args)
+{
+    CELL *res = args[0];
+    DCELL *arg1 = args[1];
+    CELL *arg2 = (argc >= 2) ? args[2] : NULL;
+    CELL *arg3 = (argc >= 3) ? args[3] : NULL;
+    CELL *arg4 = (argc >= 4) ? args[4] : NULL;
+    int i;
+
+    switch (argc) {
+    case 0:
+	return E_ARG_LO;
+    case 1:
+	for (i = 0; i < columns; i++)
+	    if (IS_NULL_D(&arg1[i]))
+		SET_NULL_C(&res[i]);
+	    else
+		res[i] = arg1[i] != 0.0 ? 1 : 0;
+	break;
+    case 2:
+	for (i = 0; i < columns; i++)
+	    if (IS_NULL_D(&arg1[i]))
+		SET_NULL_C(&res[i]);
+	    else if (arg1[i] == 0.0)
+		res[i] = 0;
+	    else {
+		if (IS_NULL_C(&arg2[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg2[i];
+	    }
+	break;
+    case 3:
+	for (i = 0; i < columns; i++)
+	    if (IS_NULL_D(&arg1[i]))
+		SET_NULL_C(&res[i]);
+	    else if (arg1[i] == 0.0) {
+		if (IS_NULL_C(&arg3[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg3[i];
+	    }
+	    else {
+		if (IS_NULL_C(&arg2[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg2[i];
+	    }
+	break;
+    case 4:
+	for (i = 0; i < columns; i++)
+	    if (IS_NULL_D(&arg1[i]))
+		SET_NULL_C(&res[i]);
+	    else if (arg1[i] == 0.0) {
+		if (IS_NULL_C(&arg3[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg3[i];
+	    }
+	    else if (arg1[i] > 0.0) {
+		if (IS_NULL_C(&arg2[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg2[i];
+	    }
+	    else {		/* (arg1[i] < 0.0) */
+
+		if (IS_NULL_C(&arg4[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg4[i];
+	    }
+	break;
+    default:
+	return E_ARG_HI;
+    }
+
+    return 0;
+}
+
+static int f_if_f(int argc, const int *argt, void **args)
+{
+    FCELL *res = args[0];
+    DCELL *arg1 = args[1];
+    FCELL *arg2 = (argc >= 2) ? args[2] : NULL;
+    FCELL *arg3 = (argc >= 3) ? args[3] : NULL;
+    FCELL *arg4 = (argc >= 4) ? args[4] : NULL;
+    int i;
+
+    switch (argc) {
+    case 0:
+	return E_ARG_LO;
+    case 1:
+	return E_ARG_TYPE;
+    case 2:
+	for (i = 0; i < columns; i++)
+	    if (IS_NULL_D(&arg1[i]))
+		SET_NULL_F(&res[i]);
+	    else if (arg1[i] == 0.0)
+		res[i] = 0.0;
+	    else {
+		if (IS_NULL_F(&arg2[i]))
+		    SET_NULL_F(&res[i]);
+		else
+		    res[i] = arg2[i];
+	    }
+	break;
+    case 3:
+	for (i = 0; i < columns; i++)
+	    if (IS_NULL_D(&arg1[i]))
+		SET_NULL_F(&res[i]);
+	    else if (arg1[i] == 0.0) {
+		if (IS_NULL_F(&arg3[i]))
+		    SET_NULL_F(&res[i]);
+		else
+		    res[i] = arg3[i];
+	    }
+	    else {
+		if (IS_NULL_F(&arg2[i]))
+		    SET_NULL_F(&res[i]);
+		else
+		    res[i] = arg2[i];
+	    }
+	break;
+    case 4:
+	for (i = 0; i < columns; i++)
+	    if (IS_NULL_D(&arg1[i]))
+		SET_NULL_F(&res[i]);
+	    else if (arg1[i] == 0.0) {
+		if (IS_NULL_F(&arg3[i]))
+		    SET_NULL_F(&res[i]);
+		else
+		    res[i] = arg3[i];
+	    }
+	    else if (arg1[i] > 0.0) {
+		if (IS_NULL_F(&arg2[i]))
+		    SET_NULL_F(&res[i]);
+		else
+		    res[i] = arg2[i];
+	    }
+	    else {		/* (arg1[i] < 0.0) */
+
+		if (IS_NULL_F(&arg4[i]))
+		    SET_NULL_F(&res[i]);
+		else
+		    res[i] = arg4[i];
+	    }
+	break;
+    default:
+	return E_ARG_HI;
+    }
+
+    return 0;
+}
+
+static int f_if_d(int argc, const int *argt, void **args)
+{
+    DCELL *res = args[0];
+    DCELL *arg1 = args[1];
+    DCELL *arg2 = (argc >= 2) ? args[2] : NULL;
+    DCELL *arg3 = (argc >= 3) ? args[3] : NULL;
+    DCELL *arg4 = (argc >= 4) ? args[4] : NULL;
+    int i;
+
+    switch (argc) {
+    case 0:
+	return E_ARG_LO;
+    case 1:
+	return E_ARG_TYPE;
+    case 2:
+	for (i = 0; i < columns; i++)
+	    if (IS_NULL_D(&arg1[i]))
+		SET_NULL_D(&res[i]);
+	    else if (arg1[i] == 0.0)
+		res[i] = 0.0;
+	    else {
+		if (IS_NULL_D(&arg2[i]))
+		    SET_NULL_D(&res[i]);
+		else
+		    res[i] = arg2[i];
+	    }
+	break;
+    case 3:
+	for (i = 0; i < columns; i++)
+	    if (IS_NULL_D(&arg1[i]))
+		SET_NULL_D(&res[i]);
+	    else if (arg1[i] == 0.0) {
+		if (IS_NULL_D(&arg3[i]))
+		    SET_NULL_D(&res[i]);
+		else
+		    res[i] = arg3[i];
+	    }
+	    else {
+		if (IS_NULL_D(&arg2[i]))
+		    SET_NULL_D(&res[i]);
+		else
+		    res[i] = arg2[i];
+	    }
+	break;
+    case 4:
+	for (i = 0; i < columns; i++)
+	    if (IS_NULL_D(&arg1[i]))
+		SET_NULL_D(&res[i]);
+	    else if (arg1[i] == 0.0) {
+		if (IS_NULL_D(&arg3[i]))
+		    SET_NULL_D(&res[i]);
+		else
+		    res[i] = arg3[i];
+	    }
+	    else if (arg1[i] > 0.0) {
+		if (IS_NULL_D(&arg2[i]))
+		    SET_NULL_D(&res[i]);
+		else
+		    res[i] = arg2[i];
+	    }
+	    else {		/* (arg1[i] < 0.0) */
+
+		if (IS_NULL_D(&arg4[i]))
+		    SET_NULL_D(&res[i]);
+		else
+		    res[i] = arg4[i];
+	    }
+	break;
+    default:
+	return E_ARG_HI;
+    }
+
+    return 0;
+}
+
+int f_if(int argc, const int *argt, void **args)
+{
+    if (argc < 1)
+	return E_ARG_LO;
+    if (argc > 4)
+	return E_ARG_HI;
+
+    if (argt[1] != DCELL_TYPE)
+	return E_ARG_TYPE;
+    if (argc >= 2 && argt[2] != argt[0])
+	return E_ARG_TYPE;
+    if (argc >= 3 && argt[3] != argt[0])
+	return E_ARG_TYPE;
+    if (argc >= 4 && argt[4] != argt[0])
+	return E_ARG_TYPE;
+
+    switch (argt[0]) {
+    case CELL_TYPE:
+	return f_if_i(argc, argt, args);
+    case FCELL_TYPE:
+	return f_if_f(argc, argt, args);
+    case DCELL_TYPE:
+	return f_if_d(argc, argt, args);
+    default:
+	return E_INV_TYPE;
+    }
+}
+
+int c_if(int argc, int *argt)
+{
+    if (argc < 1)
+	return E_ARG_LO;
+    if (argc > 4)
+	return E_ARG_HI;
+
+    argt[0] = CELL_TYPE;
+
+    if (argc >= 2 && argt[2] == FCELL_TYPE)
+	argt[0] = FCELL_TYPE;
+    if (argc >= 3 && argt[3] == FCELL_TYPE)
+	argt[0] = FCELL_TYPE;
+    if (argc >= 4 && argt[4] == FCELL_TYPE)
+	argt[0] = FCELL_TYPE;
+
+    if (argc >= 2 && argt[2] == DCELL_TYPE)
+	argt[0] = DCELL_TYPE;
+    if (argc >= 3 && argt[3] == DCELL_TYPE)
+	argt[0] = DCELL_TYPE;
+    if (argc >= 4 && argt[4] == DCELL_TYPE)
+	argt[0] = DCELL_TYPE;
+
+    argt[1] = DCELL_TYPE;
+    if (argc >= 2)
+	argt[2] = argt[0];
+    if (argc >= 3)
+	argt[3] = argt[0];
+    if (argc >= 4)
+	argt[4] = argt[0];
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/xint.c (from rev 67656, grass/trunk/raster/r.mapcalc/xint.c)
===================================================================
--- grass/trunk/lib/calc/xint.c	                        (rev 0)
+++ grass/trunk/lib/calc/xint.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,76 @@
+
+#include <stdlib.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/**********************************************************************
+int(x)
+  converts x to int
+**********************************************************************/
+
+int f_int(int argc, const int *argt, void **args)
+{
+    CELL *res = args[0];
+    int i;
+
+    if (argc < 1)
+	return E_ARG_LO;
+    if (argc > 1)
+	return E_ARG_HI;
+
+    if (argt[0] != CELL_TYPE)
+	return E_RES_TYPE;
+
+    switch (argt[1]) {
+    case CELL_TYPE:
+	{
+	    CELL *arg1 = args[1];
+
+	    for (i = 0; i < columns; i++)
+		if (IS_NULL_C(&arg1[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = (CELL) arg1[i];
+	    return 0;
+	}
+    case FCELL_TYPE:
+	{
+	    FCELL *arg1 = args[1];
+
+	    for (i = 0; i < columns; i++)
+		if (IS_NULL_F(&arg1[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = (CELL) arg1[i];
+	    return 0;
+	}
+    case DCELL_TYPE:
+	{
+	    DCELL *arg1 = args[1];
+
+	    for (i = 0; i < columns; i++)
+		if (IS_NULL_D(&arg1[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = (CELL) arg1[i];
+	    return 0;
+	}
+    default:
+	return E_INV_TYPE;
+    }
+}
+
+int c_int(int argc, int *argt)
+{
+    if (argc < 1)
+	return E_ARG_LO;
+    if (argc > 1)
+	return E_ARG_HI;
+
+    argt[0] = CELL_TYPE;
+    /*      argt[1] = argt[1];      */
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/xisnull.c (from rev 67656, grass/trunk/raster/r.mapcalc/xisnull.c)
===================================================================
--- grass/trunk/lib/calc/xisnull.c	                        (rev 0)
+++ grass/trunk/lib/calc/xisnull.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,64 @@
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/**********************************************************************
+isnull(x)
+  return 1 if x is null, 0 otherwise
+**********************************************************************/
+
+int f_isnull(int argc, const int *argt, void **args)
+{
+    int *res = args[0];
+    int i;
+
+    if (argc < 1)
+	return E_ARG_LO;
+    if (argc > 1)
+	return E_ARG_HI;
+
+    if (argt[0] != CELL_TYPE)
+	return E_RES_TYPE;
+
+    switch (argt[1]) {
+    case CELL_TYPE:
+	{
+	    CELL *arg1 = args[1];
+
+	    for (i = 0; i < columns; i++)
+		res[i] = IS_NULL_C(&arg1[i]) ? 1 : 0;
+	    return 0;
+	}
+    case FCELL_TYPE:
+	{
+	    FCELL *arg1 = args[1];
+
+	    for (i = 0; i < columns; i++)
+		res[i] = IS_NULL_F(&arg1[i]) ? 1 : 0;
+	    return 0;
+	}
+    case DCELL_TYPE:
+	{
+	    DCELL *arg1 = args[1];
+
+	    for (i = 0; i < columns; i++)
+		res[i] = IS_NULL_D(&arg1[i]) ? 1 : 0;
+	    return 0;
+	}
+    default:
+	return E_INV_TYPE;
+    }
+}
+
+int c_isnull(int argc, int *argt)
+{
+    if (argc < 1)
+	return E_ARG_LO;
+    if (argc > 1)
+	return E_ARG_HI;
+
+    argt[0] = CELL_TYPE;
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/xle.c (from rev 67656, grass/trunk/raster/r.mapcalc/xle.c)
===================================================================
--- grass/trunk/lib/calc/xle.c	                        (rev 0)
+++ grass/trunk/lib/calc/xle.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,63 @@
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+le(a,b) = a <= b
+****************************************************************/
+
+int f_le(int argc, const int *argt, void **args)
+{
+    CELL *res = args[0];
+    int i;
+
+    if (argc < 2)
+	return E_ARG_LO;
+    if (argc > 2)
+	return E_ARG_HI;
+
+    switch (argt[1]) {
+    case CELL_TYPE:
+	{
+	    CELL *arg1 = args[1];
+	    CELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg1[i] <= arg2[i];
+	    }
+	    return 0;
+	}
+    case FCELL_TYPE:
+	{
+	    FCELL *arg1 = args[1];
+	    FCELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg1[i] <= arg2[i];
+	    }
+	    return 0;
+	}
+    case DCELL_TYPE:
+	{
+	    DCELL *arg1 = args[1];
+	    DCELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg1[i] <= arg2[i];
+	    }
+	    return 0;
+	}
+    default:
+	return E_INV_TYPE;
+    }
+}

Copied: grass/trunk/lib/calc/xlog.c (from rev 67656, grass/trunk/raster/r.mapcalc/xlog.c)
===================================================================
--- grass/trunk/lib/calc/xlog.c	                        (rev 0)
+++ grass/trunk/lib/calc/xlog.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,59 @@
+
+#include <math.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/**********************************************************************
+log(x) 
+log(x,b)
+
+  first form computes the natural log of x = ln(x)
+  second form computes log of x base b = ln(x)/ln(b)
+
+  if x is non-positive, or floating point exception occurs while
+  computing ln(x), the result is NULL
+
+  if b is non-positive, or 1.0, or floating point exception occurs while
+  computing ln(b), the result is NULL
+**********************************************************************/
+
+int f_log(int argc, const int *argt, void **args)
+{
+    DCELL *res = args[0];
+    DCELL *arg1 = args[1];
+    DCELL *arg2 = (argc >= 2) ? args[2] : (DCELL *) 0;
+    int i;
+
+    if (argc < 1)
+	return E_ARG_LO;
+
+    if (argc > 2)
+	return E_ARG_HI;
+
+    if (argt[0] != DCELL_TYPE)
+	return E_RES_TYPE;
+
+    if (argt[1] != DCELL_TYPE)
+	return E_ARG_TYPE;
+
+    if (argc > 1 && argt[2] != DCELL_TYPE)
+	return E_ARG_TYPE;
+
+    for (i = 0; i < columns; i++)
+	if (IS_NULL_D(&arg1[i]) || (arg1[i] <= 0.0))
+	    SET_NULL_D(&res[i]);
+	else if (argc > 1 && (IS_NULL_D(&arg2[i]) || (arg2[i] <= 0.0)))
+	    SET_NULL_D(&res[i]);
+	else {
+	    floating_point_exception = 0;
+	    res[i] = (argc > 1)
+		? log(arg1[i]) / log(arg2[i])
+		: log(arg1[i]);
+	    if (floating_point_exception)
+		SET_NULL_D(&res[i]);
+	}
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/xlt.c (from rev 67656, grass/trunk/raster/r.mapcalc/xlt.c)
===================================================================
--- grass/trunk/lib/calc/xlt.c	                        (rev 0)
+++ grass/trunk/lib/calc/xlt.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,63 @@
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+lt(a,b) = a < b
+****************************************************************/
+
+int f_lt(int argc, const int *argt, void **args)
+{
+    CELL *res = args[0];
+    int i;
+
+    if (argc < 2)
+	return E_ARG_LO;
+    if (argc > 2)
+	return E_ARG_HI;
+
+    switch (argt[1]) {
+    case CELL_TYPE:
+	{
+	    CELL *arg1 = args[1];
+	    CELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg1[i] < arg2[i];
+	    }
+	    return 0;
+	}
+    case FCELL_TYPE:
+	{
+	    FCELL *arg1 = args[1];
+	    FCELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg1[i] < arg2[i];
+	    }
+	    return 0;
+	}
+    case DCELL_TYPE:
+	{
+	    DCELL *arg1 = args[1];
+	    DCELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg1[i] < arg2[i];
+	    }
+	    return 0;
+	}
+    default:
+	return E_INV_TYPE;
+    }
+}

Copied: grass/trunk/lib/calc/xmax.c (from rev 67656, grass/trunk/raster/r.mapcalc/xmax.c)
===================================================================
--- grass/trunk/lib/calc/xmax.c	                        (rev 0)
+++ grass/trunk/lib/calc/xmax.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,98 @@
+
+#include <stdlib.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+max(x0,x1,...,xn) returns maximum value
+****************************************************************/
+
+int f_max(int argc, const int *argt, void **args)
+{
+    int i, j;
+
+    if (argc < 1)
+	return E_ARG_LO;
+
+    for (i = 1; i <= argc; i++)
+	if (argt[i] != argt[0])
+	    return E_ARG_TYPE;
+
+    switch (argt[0]) {
+    case CELL_TYPE:
+	{
+	    CELL *res = args[0];
+	    CELL **argz = (CELL **) args;
+
+	    for (i = 0; i < columns; i++) {
+		int nul = 0;
+		CELL max;
+
+		for (j = 1; j <= argc; j++)
+		    if (IS_NULL_C(&argz[j][i]))
+			nul = 1;
+		    else if (j == 1)
+			max = argz[j][i];
+		    else if (max < argz[j][i])
+			max = argz[j][i];
+		if (nul)
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = max;
+	    }
+	    return 0;
+	}
+    case FCELL_TYPE:
+	{
+	    FCELL *res = args[0];
+	    FCELL **argz = (FCELL **) args;
+
+	    for (i = 0; i < columns; i++) {
+		int nul = 0;
+		FCELL max;
+
+		for (j = 1; j <= argc; j++)
+		    if (IS_NULL_F(&argz[j][i]))
+			nul = 1;
+		    else if (j == 1)
+			max = argz[j][i];
+		    else if (max < argz[j][i])
+			max = argz[j][i];
+		if (nul)
+		    SET_NULL_F(&res[i]);
+		else
+		    res[i] = max;
+	    }
+
+	    return 0;
+	}
+    case DCELL_TYPE:
+	{
+	    DCELL *res = args[0];
+	    DCELL **argz = (DCELL **) args;
+
+	    for (i = 0; i < columns; i++) {
+		int nul = 0;
+		DCELL max;
+
+		for (j = 1; j <= argc; j++)
+		    if (IS_NULL_D(&argz[j][i]))
+			nul = 1;
+		    else if (j == 1)
+			max = argz[j][i];
+		    else if (max < argz[j][i])
+			max = argz[j][i];
+		if (nul)
+		    SET_NULL_D(&res[i]);
+		else
+		    res[i] = max;
+	    }
+
+	    return 0;
+	}
+    default:
+	return E_INV_TYPE;
+    }
+}

Copied: grass/trunk/lib/calc/xmedian.c (from rev 67656, grass/trunk/raster/r.mapcalc/xmedian.c)
===================================================================
--- grass/trunk/lib/calc/xmedian.c	                        (rev 0)
+++ grass/trunk/lib/calc/xmedian.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,153 @@
+
+#include <stdlib.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/**********************************************************************
+median(x1,x2,..,xn)
+   return median of arguments
+**********************************************************************/
+
+static int icmp(const void *aa, const void *bb)
+{
+    const CELL *a = aa;
+    const CELL *b = bb;
+
+    return *a - *b;
+}
+
+static int fcmp(const void *aa, const void *bb)
+{
+    const FCELL *a = aa;
+    const FCELL *b = bb;
+
+    if (*a < *b)
+	return -1;
+    if (*a > *b)
+	return 1;
+    return 0;
+}
+
+static int dcmp(const void *aa, const void *bb)
+{
+    const DCELL *a = aa;
+    const DCELL *b = bb;
+
+    if (*a < *b)
+	return -1;
+    if (*a > *b)
+	return 1;
+    return 0;
+}
+
+int f_median(int argc, const int *argt, void **args)
+{
+    static void *array;
+    static int alloc;
+    int size = argc * Rast_cell_size(argt[0]);
+    int i, j;
+
+    if (argc < 1)
+	return E_ARG_LO;
+
+    for (i = 1; i <= argc; i++)
+	if (argt[i] != argt[0])
+	    return E_ARG_TYPE;
+
+    if (size > alloc) {
+	alloc = size;
+	array = G_realloc(array, size);
+    }
+
+    switch (argt[0]) {
+    case CELL_TYPE:
+	{
+	    CELL *res = args[0];
+	    CELL **argv = (CELL **) &args[1];
+	    CELL *a = array;
+	    CELL *a1 = &a[(argc - 1) / 2];
+	    CELL *a2 = &a[argc / 2];
+
+	    for (i = 0; i < columns; i++) {
+		int nv = 0;
+
+		for (j = 0; j < argc && !nv; j++) {
+		    if (IS_NULL_C(&argv[j][i]))
+			nv = 1;
+		    else
+			a[j] = argv[j][i];
+		}
+
+		if (nv)
+		    SET_NULL_C(&res[i]);
+		else {
+		    qsort(a, argc, sizeof(CELL), icmp);
+		    res[i] = (*a1 + *a2) / 2;
+		}
+	    }
+
+	    return 0;
+	}
+    case FCELL_TYPE:
+	{
+	    FCELL *res = args[0];
+	    FCELL **argv = (FCELL **) &args[1];
+	    FCELL *a = array;
+	    FCELL *a1 = &a[(argc - 1) / 2];
+	    FCELL *a2 = &a[argc / 2];
+
+	    for (i = 0; i < columns; i++) {
+		int nv = 0;
+
+		for (j = 0; j < argc && !nv; j++) {
+		    if (IS_NULL_F(&argv[j][i]))
+			nv = 1;
+		    else
+			a[j] = argv[j][i];
+		}
+
+		if (nv)
+		    SET_NULL_F(&res[i]);
+		else {
+		    qsort(a, argc, sizeof(FCELL), fcmp);
+		    res[i] = (*a1 + *a2) / 2;
+		}
+	    }
+
+	    return 0;
+	}
+    case DCELL_TYPE:
+	{
+	    DCELL *res = args[0];
+	    DCELL **argv = (DCELL **) &args[1];
+	    DCELL *a = array;
+	    DCELL *a1 = &a[(argc - 1) / 2];
+	    DCELL *a2 = &a[argc / 2];
+
+	    for (i = 0; i < columns; i++) {
+		int nv = 0;
+
+		for (j = 0; j < argc && !nv; j++) {
+		    if (IS_NULL_D(&argv[j][i]))
+			nv = 1;
+		    else
+			a[j] = argv[j][i];
+		}
+
+		if (nv)
+		    SET_NULL_D(&res[i]);
+		else {
+		    qsort(a, argc, sizeof(DCELL), dcmp);
+		    res[i] = (*a1 + *a2) / 2;
+		}
+	    }
+
+	    return 0;
+	}
+    default:
+	return E_INV_TYPE;
+    }
+}

Copied: grass/trunk/lib/calc/xmin.c (from rev 67656, grass/trunk/raster/r.mapcalc/xmin.c)
===================================================================
--- grass/trunk/lib/calc/xmin.c	                        (rev 0)
+++ grass/trunk/lib/calc/xmin.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,98 @@
+
+#include <stdlib.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+min(x0,x1,...,xn) returns minimum value
+****************************************************************/
+
+int f_min(int argc, const int *argt, void **args)
+{
+    int i, j;
+
+    if (argc < 1)
+	return E_ARG_LO;
+
+    for (i = 1; i <= argc; i++)
+	if (argt[i] != argt[0])
+	    return E_ARG_TYPE;
+
+    switch (argt[0]) {
+    case CELL_TYPE:
+	{
+	    CELL *res = args[0];
+	    CELL **argz = (CELL **) args;
+
+	    for (i = 0; i < columns; i++) {
+		int nul = 0;
+		CELL min;
+
+		for (j = 1; j <= argc; j++)
+		    if (IS_NULL_C(&argz[j][i]))
+			nul = 1;
+		    else if (j == 1)
+			min = argz[j][i];
+		    else if (min > argz[j][i])
+			min = argz[j][i];
+		if (nul)
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = min;
+	    }
+	    return 0;
+	}
+    case FCELL_TYPE:
+	{
+	    FCELL *res = args[0];
+	    FCELL **argz = (FCELL **) args;
+
+	    for (i = 0; i < columns; i++) {
+		int nul = 0;
+		FCELL min;
+
+		for (j = 1; j <= argc; j++)
+		    if (IS_NULL_F(&argz[j][i]))
+			nul = 1;
+		    else if (j == 1)
+			min = argz[j][i];
+		    else if (min > argz[j][i])
+			min = argz[j][i];
+		if (nul)
+		    SET_NULL_F(&res[i]);
+		else
+		    res[i] = min;
+	    }
+
+	    return 0;
+	}
+    case DCELL_TYPE:
+	{
+	    DCELL *res = args[0];
+	    DCELL **argz = (DCELL **) args;
+
+	    for (i = 0; i < columns; i++) {
+		int nul = 0;
+		DCELL min;
+
+		for (j = 1; j <= argc; j++)
+		    if (IS_NULL_D(&argz[j][i]))
+			nul = 1;
+		    else if (j == 1)
+			min = argz[j][i];
+		    else if (min > argz[j][i])
+			min = argz[j][i];
+		if (nul)
+		    SET_NULL_D(&res[i]);
+		else
+		    res[i] = min;
+	    }
+
+	    return 0;
+	}
+    default:
+	return E_INV_TYPE;
+    }
+}

Copied: grass/trunk/lib/calc/xmod.c (from rev 67656, grass/trunk/raster/r.mapcalc/xmod.c)
===================================================================
--- grass/trunk/lib/calc/xmod.c	                        (rev 0)
+++ grass/trunk/lib/calc/xmod.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,78 @@
+
+#include <math.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+mod(a,b) = a % b
+****************************************************************/
+
+int f_mod(int argc, const int *argt, void **args)
+{
+    int i;
+
+    if (argc < 2)
+	return E_ARG_LO;
+    if (argc > 2)
+	return E_ARG_HI;
+
+    if (argt[1] != argt[0] || argt[2] != argt[0])
+	return E_ARG_TYPE;
+
+    switch (argt[0]) {
+    case CELL_TYPE:
+	{
+	    CELL *res = args[0];
+	    CELL *arg1 = args[1];
+	    CELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg1[i] % arg2[i];
+	    }
+	    return 0;
+	}
+    case FCELL_TYPE:
+	{
+	    FCELL *res = args[0];
+	    FCELL *arg1 = args[1];
+	    FCELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]))
+		    SET_NULL_F(&res[i]);
+		else {
+		    floating_point_exception = 0;
+		    res[i] = (FCELL) fmod(arg1[i], arg2[i]);
+		    if (floating_point_exception)
+			SET_NULL_F(&res[i]);
+		}
+	    }
+	    return 0;
+	}
+    case DCELL_TYPE:
+	{
+	    DCELL *res = args[0];
+	    DCELL *arg1 = args[1];
+	    DCELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]))
+		    SET_NULL_D(&res[i]);
+		else {
+		    floating_point_exception = 0;
+		    res[i] = (DCELL) fmod(arg1[i], arg2[i]);
+		    if (floating_point_exception)
+			SET_NULL_D(&res[i]);
+		}
+	    }
+	    return 0;
+	}
+    default:
+	return E_INV_TYPE;
+    }
+}

Copied: grass/trunk/lib/calc/xmode.c (from rev 67656, grass/trunk/raster/r.mapcalc/xmode.c)
===================================================================
--- grass/trunk/lib/calc/xmode.c	                        (rev 0)
+++ grass/trunk/lib/calc/xmode.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,142 @@
+
+#include <stdlib.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/**********************************************************************
+mode(x1,x2,..,xn)
+   return mode of arguments
+**********************************************************************/
+
+static int dcmp(const void *aa, const void *bb)
+{
+    const double *a = aa;
+    const double *b = bb;
+
+    if (*a < *b)
+	return -1;
+    if (*a > *b)
+	return 1;
+    return 0;
+}
+
+static double mode(double *value, int argc)
+{
+    double mode_v;
+    int mode_n = 0;
+    int i;
+
+    qsort(value, argc, sizeof(double), dcmp);
+
+    for (i = 0; i < argc;) {
+	int n = 1;
+	double v = value[i];
+
+	for (i++; i < argc; i++) {
+	    if (value[i] != v)
+		break;
+	    n++;
+	}
+
+	if (n < mode_n)
+	    continue;
+
+	mode_v = v;
+	mode_n = n;
+    }
+
+    return mode_v;
+}
+
+int f_mode(int argc, const int *argt, void **args)
+{
+    static double *value;
+    static int value_size;
+    int size = argc * sizeof(double);
+    int i, j;
+
+    if (argc < 1)
+	return E_ARG_LO;
+
+    for (i = 1; i <= argc; i++)
+	if (argt[i] != argt[0])
+	    return E_ARG_TYPE;
+
+    if (size > value_size) {
+	value_size = size;
+	value = G_realloc(value, value_size);
+    }
+
+    switch (argt[argc]) {
+    case CELL_TYPE:
+	{
+	    CELL *res = args[0];
+	    CELL **argv = (CELL **) & args[1];
+
+	    for (i = 0; i < columns; i++) {
+		int nv = 0;
+
+		for (j = 0; j < argc && !nv; j++) {
+		    if (IS_NULL_C(&argv[j][i]))
+			nv = 1;
+		    else
+			value[j] = (double)argv[j][i];
+		}
+
+		if (nv)
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = (CELL) mode(value, argc);
+	    }
+	    return 0;
+	}
+    case FCELL_TYPE:
+	{
+	    FCELL *res = args[0];
+	    FCELL **argv = (FCELL **) & args[1];
+
+	    for (i = 0; i < columns; i++) {
+		int nv = 0;
+
+		for (j = 0; j < argc && !nv; j++) {
+		    if (IS_NULL_F(&argv[j][i]))
+			nv = 1;
+		    else
+			value[j] = (double)argv[j][i];
+		}
+
+		if (nv)
+		    SET_NULL_F(&res[i]);
+		else
+		    res[i] = (FCELL) mode(value, argc);
+	    }
+	    return 0;
+	}
+    case DCELL_TYPE:
+	{
+	    DCELL *res = args[0];
+	    DCELL **argv = (DCELL **) & args[1];
+
+	    for (i = 0; i < columns; i++) {
+		int nv = 0;
+
+		for (j = 0; j < argc && !nv; j++) {
+		    if (IS_NULL_D(&argv[j][i]))
+			nv = 1;
+		    else
+			value[j] = (double)argv[j][i];
+		}
+
+		if (nv)
+		    SET_NULL_D(&res[i]);
+		else
+		    res[i] = (DCELL) mode(value, argc);
+	    }
+	    return 0;
+	}
+    default:
+	return E_INV_TYPE;
+    }
+}

Copied: grass/trunk/lib/calc/xmul.c (from rev 67656, grass/trunk/raster/r.mapcalc/xmul.c)
===================================================================
--- grass/trunk/lib/calc/xmul.c	                        (rev 0)
+++ grass/trunk/lib/calc/xmul.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,76 @@
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+mul(a,b) = a * b
+****************************************************************/
+
+int f_mul(int argc, const int *argt, void **args)
+{
+    int i, j;
+
+    if (argc < 1)
+	return E_ARG_LO;
+
+    for (i = 1; i <= argc; i++)
+	if (argt[i] != argt[0])
+	    return E_ARG_TYPE;
+
+    switch (argt[0]) {
+    case CELL_TYPE:
+	{
+	    CELL *res = args[0];
+	    CELL **argz = (CELL **) args;
+
+	    for (i = 0; i < columns; i++) {
+		res[i] = 1;
+		for (j = 1; j <= argc; j++) {
+		    if (IS_NULL_C(&argz[j][i])) {
+			SET_NULL_C(&res[i]);
+			break;
+		    }
+		    res[i] *= argz[j][i];
+		}
+	    }
+	    return 0;
+	}
+    case FCELL_TYPE:
+	{
+	    FCELL *res = args[0];
+	    FCELL **argz = (FCELL **) args;
+
+	    for (i = 0; i < columns; i++) {
+		res[i] = 1;
+		for (j = 1; j <= argc; j++) {
+		    if (IS_NULL_F(&argz[j][i])) {
+			SET_NULL_F(&res[i]);
+			break;
+		    }
+		    res[i] *= argz[j][i];
+		}
+	    }
+	    return 0;
+	}
+    case DCELL_TYPE:
+	{
+	    DCELL *res = args[0];
+	    DCELL **argz = (DCELL **) args;
+
+	    for (i = 0; i < columns; i++) {
+		res[i] = 1;
+		for (j = 1; j <= argc; j++) {
+		    if (IS_NULL_D(&argz[j][i])) {
+			SET_NULL_D(&res[i]);
+			break;
+		    }
+		    res[i] *= argz[j][i];
+		}
+	    }
+	    return 0;
+	}
+    default:
+	return E_INV_TYPE;
+    }
+}

Copied: grass/trunk/lib/calc/xne.c (from rev 67656, grass/trunk/raster/r.mapcalc/xne.c)
===================================================================
--- grass/trunk/lib/calc/xne.c	                        (rev 0)
+++ grass/trunk/lib/calc/xne.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,63 @@
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+ne(a,b) = a != b
+****************************************************************/
+
+int f_ne(int argc, const int *argt, void **args)
+{
+    CELL *res = args[0];
+    int i;
+
+    if (argc < 2)
+	return E_ARG_LO;
+    if (argc > 2)
+	return E_ARG_HI;
+
+    switch (argt[1]) {
+    case CELL_TYPE:
+	{
+	    CELL *arg1 = args[1];
+	    CELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg1[i] != arg2[i];
+	    }
+	    return 0;
+	}
+    case FCELL_TYPE:
+	{
+	    FCELL *arg1 = args[1];
+	    FCELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg1[i] != arg2[i];
+	    }
+	    return 0;
+	}
+    case DCELL_TYPE:
+	{
+	    DCELL *arg1 = args[1];
+	    DCELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg1[i] != arg2[i];
+	    }
+	    return 0;
+	}
+    default:
+	return E_INV_TYPE;
+    }
+}

Copied: grass/trunk/lib/calc/xneg.c (from rev 67656, grass/trunk/raster/r.mapcalc/xneg.c)
===================================================================
--- grass/trunk/lib/calc/xneg.c	                        (rev 0)
+++ grass/trunk/lib/calc/xneg.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,62 @@
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/**********************************************************************
+neg(x) = -x
+**********************************************************************/
+
+int f_neg(int argc, const int *argt, void **args)
+{
+    int i;
+
+    if (argc < 1)
+	return E_ARG_LO;
+    if (argc > 1)
+	return E_ARG_HI;
+
+    if (argt[0] != argt[1])
+	return E_RES_TYPE;
+
+    switch (argt[1]) {
+    case CELL_TYPE:
+	{
+	    CELL *res = args[0];
+	    CELL *arg1 = args[1];
+
+	    for (i = 0; i < columns; i++)
+		if (IS_NULL_C(&arg1[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = -arg1[i];
+	    return 0;
+	}
+    case FCELL_TYPE:
+	{
+	    FCELL *res = args[0];
+	    FCELL *arg1 = args[1];
+
+	    for (i = 0; i < columns; i++)
+		if (IS_NULL_F(&arg1[i]))
+		    SET_NULL_F(&res[i]);
+		else
+		    res[i] = -arg1[i];
+	    return 0;
+	}
+    case DCELL_TYPE:
+	{
+	    DCELL *res = args[0];
+	    DCELL *arg1 = args[1];
+
+	    for (i = 0; i < columns; i++)
+		if (IS_NULL_D(&arg1[i]))
+		    SET_NULL_D(&res[i]);
+		else
+		    res[i] = -arg1[i];
+	    return 0;
+	}
+    default:
+	return E_INV_TYPE;
+    }
+}

Copied: grass/trunk/lib/calc/xnmax.c (from rev 67656, grass/trunk/raster/r.mapcalc/xnmax.c)
===================================================================
--- grass/trunk/lib/calc/xnmax.c	                        (rev 0)
+++ grass/trunk/lib/calc/xnmax.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,98 @@
+
+#include <stdlib.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+max(x0,x1,...,xn) returns maximum value
+****************************************************************/
+
+int f_nmax(int argc, const int *argt, void **args)
+{
+    int i, j;
+
+    if (argc < 1)
+	return E_ARG_LO;
+
+    for (i = 1; i <= argc; i++)
+	if (argt[i] != argt[0])
+	    return E_ARG_TYPE;
+
+    switch (argt[0]) {
+    case CELL_TYPE:
+	{
+	    CELL *res = args[0];
+	    CELL **argz = (CELL **) args;
+
+	    for (i = 0; i < columns; i++) {
+		int nul = 1;
+		CELL max;
+
+		for (j = 1; j <= argc; j++)
+		    if (IS_NULL_C(&argz[j][i]))
+			continue;
+		    else if (nul)
+			max = argz[j][i], nul = 0;
+		    else if (max < argz[j][i])
+			max = argz[j][i], nul = 0;
+		if (nul)
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = max;
+	    }
+	    return 0;
+	}
+    case FCELL_TYPE:
+	{
+	    FCELL *res = args[0];
+	    FCELL **argz = (FCELL **) args;
+
+	    for (i = 0; i < columns; i++) {
+		int nul = 1;
+		FCELL max;
+
+		for (j = 1; j <= argc; j++)
+		    if (IS_NULL_F(&argz[j][i]))
+			continue;
+		    else if (nul)
+			max = argz[j][i], nul = 0;
+		    else if (max < argz[j][i])
+			max = argz[j][i], nul = 0;
+		if (nul)
+		    SET_NULL_F(&res[i]);
+		else
+		    res[i] = max;
+	    }
+
+	    return 0;
+	}
+    case DCELL_TYPE:
+	{
+	    DCELL *res = args[0];
+	    DCELL **argz = (DCELL **) args;
+
+	    for (i = 0; i < columns; i++) {
+		int nul = 1;
+		DCELL max;
+
+		for (j = 1; j <= argc; j++)
+		    if (IS_NULL_D(&argz[j][i]))
+			continue;
+		    else if (nul)
+			max = argz[j][i], nul = 0;
+		    else if (max < argz[j][i])
+			max = argz[j][i], nul = 0;
+		if (nul)
+		    SET_NULL_D(&res[i]);
+		else
+		    res[i] = max;
+	    }
+
+	    return 0;
+	}
+    default:
+	return E_INV_TYPE;
+    }
+}

Copied: grass/trunk/lib/calc/xnmedian.c (from rev 67656, grass/trunk/raster/r.mapcalc/xnmedian.c)
===================================================================
--- grass/trunk/lib/calc/xnmedian.c	                        (rev 0)
+++ grass/trunk/lib/calc/xnmedian.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,150 @@
+
+#include <stdlib.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/**********************************************************************
+median(x1,x2,..,xn)
+   return median of arguments
+**********************************************************************/
+
+static int icmp(const void *aa, const void *bb)
+{
+    const CELL *a = aa;
+    const CELL *b = bb;
+
+    return *a - *b;
+}
+
+static int fcmp(const void *aa, const void *bb)
+{
+    const FCELL *a = aa;
+    const FCELL *b = bb;
+
+    if (*a < *b)
+	return -1;
+    if (*a > *b)
+	return 1;
+    return 0;
+}
+
+static int dcmp(const void *aa, const void *bb)
+{
+    const DCELL *a = aa;
+    const DCELL *b = bb;
+
+    if (*a < *b)
+	return -1;
+    if (*a > *b)
+	return 1;
+    return 0;
+}
+
+int f_nmedian(int argc, const int *argt, void **args)
+{
+    static void *array;
+    static int alloc;
+    int size = argc * Rast_cell_size(argt[0]);
+    int i, j;
+
+    if (argc < 1)
+	return E_ARG_LO;
+
+    for (i = 1; i <= argc; i++)
+	if (argt[i] != argt[0])
+	    return E_ARG_TYPE;
+
+    if (size > alloc) {
+	alloc = size;
+	array = G_realloc(array, size);
+    }
+
+    switch (argt[0]) {
+    case CELL_TYPE:
+	{
+	    CELL *res = args[0];
+	    CELL **argv = (CELL **) &args[1];
+	    CELL *a = array;
+	    CELL *a1 = &a[(argc - 1) / 2];
+	    CELL *a2 = &a[argc / 2];
+
+	    for (i = 0; i < columns; i++) {
+		int n = 0;
+
+		for (j = 0; j < argc; j++) {
+		    if (IS_NULL_C(&argv[j][i]))
+			continue;
+		    a[n++] = argv[j][i];
+		}
+
+		if (!n)
+		    SET_NULL_C(&res[i]);
+		else {
+		    qsort(a, n, sizeof(CELL), icmp);
+		    res[i] = (*a1 + *a2) / 2;
+		}
+	    }
+
+	    return 0;
+	}
+    case FCELL_TYPE:
+	{
+	    FCELL *res = args[0];
+	    FCELL **argv = (FCELL **) &args[1];
+	    FCELL *a = array;
+	    FCELL *a1 = &a[(argc - 1) / 2];
+	    FCELL *a2 = &a[argc / 2];
+
+	    for (i = 0; i < columns; i++) {
+		int n = 0;
+
+		for (j = 0; j < argc; j++) {
+		    if (IS_NULL_F(&argv[j][i]))
+			continue;
+		    a[n++] = argv[j][i];
+		}
+
+		if (!n)
+		    SET_NULL_F(&res[i]);
+		else {
+		    qsort(a, n, sizeof(FCELL), fcmp);
+		    res[i] = (*a1 + *a2) / 2;
+		}
+	    }
+
+	    return 0;
+	}
+    case DCELL_TYPE:
+	{
+	    DCELL *res = args[0];
+	    DCELL **argv = (DCELL **) &args[1];
+	    DCELL *a = array;
+	    DCELL *a1 = &a[(argc - 1) / 2];
+	    DCELL *a2 = &a[argc / 2];
+
+	    for (i = 0; i < columns; i++) {
+		int n = 0;
+
+		for (j = 0; j < argc; j++) {
+		    if (IS_NULL_D(&argv[j][i]))
+			continue;
+		    a[n++] = argv[j][i];
+		}
+
+		if (!n)
+		    SET_NULL_D(&res[i]);
+		else {
+		    qsort(a, n, sizeof(DCELL), dcmp);
+		    res[i] = (*a1 + *a2) / 2;
+		}
+	    }
+
+	    return 0;
+	}
+    default:
+	return E_INV_TYPE;
+    }
+}

Copied: grass/trunk/lib/calc/xnmin.c (from rev 67656, grass/trunk/raster/r.mapcalc/xnmin.c)
===================================================================
--- grass/trunk/lib/calc/xnmin.c	                        (rev 0)
+++ grass/trunk/lib/calc/xnmin.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,98 @@
+
+#include <stdlib.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+min(x0,x1,...,xn) returns minimum value
+****************************************************************/
+
+int f_nmin(int argc, const int *argt, void **args)
+{
+    int i, j;
+
+    if (argc < 1)
+	return E_ARG_LO;
+
+    for (i = 1; i <= argc; i++)
+	if (argt[i] != argt[0])
+	    return E_ARG_TYPE;
+
+    switch (argt[0]) {
+    case CELL_TYPE:
+	{
+	    CELL *res = args[0];
+	    CELL **argz = (CELL **) args;
+
+	    for (i = 0; i < columns; i++) {
+		int nul = 1;
+		CELL min;
+
+		for (j = 1; j <= argc; j++)
+		    if (IS_NULL_C(&argz[j][i]))
+			continue;
+		    else if (nul)
+			min = argz[j][i], nul = 0;
+		    else if (min > argz[j][i])
+			min = argz[j][i], nul = 0;
+		if (nul)
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = min;
+	    }
+	    return 0;
+	}
+    case FCELL_TYPE:
+	{
+	    FCELL *res = args[0];
+	    FCELL **argz = (FCELL **) args;
+
+	    for (i = 0; i < columns; i++) {
+		int nul = 1;
+		FCELL min;
+
+		for (j = 1; j <= argc; j++)
+		    if (IS_NULL_F(&argz[j][i]))
+			continue;
+		    else if (nul)
+			min = argz[j][i], nul = 0;
+		    else if (min > argz[j][i])
+			min = argz[j][i], nul = 0;
+		if (nul)
+		    SET_NULL_F(&res[i]);
+		else
+		    res[i] = min;
+	    }
+
+	    return 0;
+	}
+    case DCELL_TYPE:
+	{
+	    DCELL *res = args[0];
+	    DCELL **argz = (DCELL **) args;
+
+	    for (i = 0; i < columns; i++) {
+		int nul = 1;
+		DCELL min;
+
+		for (j = 1; j <= argc; j++)
+		    if (IS_NULL_D(&argz[j][i]))
+			continue;
+		    else if (nul)
+			min = argz[j][i], nul = 0;
+		    else if (min > argz[j][i])
+			min = argz[j][i], nul = 0;
+		if (nul)
+		    SET_NULL_D(&res[i]);
+		else
+		    res[i] = min;
+	    }
+
+	    return 0;
+	}
+    default:
+	return E_INV_TYPE;
+    }
+}

Copied: grass/trunk/lib/calc/xnmode.c (from rev 67656, grass/trunk/raster/r.mapcalc/xnmode.c)
===================================================================
--- grass/trunk/lib/calc/xnmode.c	                        (rev 0)
+++ grass/trunk/lib/calc/xnmode.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,139 @@
+
+#include <stdlib.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/**********************************************************************
+mode(x1,x2,..,xn)
+   return mode of arguments
+**********************************************************************/
+
+static int dcmp(const void *aa, const void *bb)
+{
+    const double *a = aa;
+    const double *b = bb;
+
+    if (*a < *b)
+	return -1;
+    if (*a > *b)
+	return 1;
+    return 0;
+}
+
+static double mode(double *value, int argc)
+{
+    double mode_v;
+    int mode_n = 0;
+    int i;
+
+    qsort(value, argc, sizeof(double), dcmp);
+
+    for (i = 0; i < argc;) {
+	int n = 1;
+	double v = value[i];
+
+	for (i++; i < argc; i++) {
+	    if (value[i] != v)
+		break;
+	    n++;
+	}
+
+	if (n < mode_n)
+	    continue;
+
+	mode_v = v;
+	mode_n = n;
+    }
+
+    return mode_v;
+}
+
+int f_nmode(int argc, const int *argt, void **args)
+{
+    static double *value;
+    static int value_size;
+    int size = argc * sizeof(double);
+    int i, j;
+
+    if (argc < 1)
+	return E_ARG_LO;
+
+    for (i = 1; i <= argc; i++)
+	if (argt[i] != argt[0])
+	    return E_ARG_TYPE;
+
+    if (size > value_size) {
+	value_size = size;
+	value = G_realloc(value, value_size);
+    }
+
+    switch (argt[argc]) {
+    case CELL_TYPE:
+	{
+	    CELL *res = args[0];
+	    CELL **argv = (CELL **) & args[1];
+
+	    for (i = 0; i < columns; i++) {
+		int n = 0;
+
+		for (j = 0; j < argc; j++) {
+		    if (IS_NULL_C(&argv[j][i]))
+			continue;
+		    value[n++] = (double)argv[j][i];
+		}
+
+		if (!n)
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = (CELL) mode(value, n);
+	    }
+	    return 0;
+	}
+    case FCELL_TYPE:
+	{
+	    FCELL *res = args[0];
+	    FCELL **argv = (FCELL **) & args[1];
+
+	    for (i = 0; i < columns; i++) {
+		int n = 0;
+
+		for (j = 0; j < argc; j++) {
+		    if (IS_NULL_F(&argv[j][i]))
+			continue;
+		    value[n++] = (double)argv[j][i];
+		}
+
+		if (!n)
+		    SET_NULL_F(&res[i]);
+		else
+		    res[i] = (FCELL) mode(value, n);
+	    }
+	    return 0;
+	}
+    case DCELL_TYPE:
+	{
+	    DCELL *res = args[0];
+	    DCELL **argv = (DCELL **) & args[1];
+
+	    for (i = 0; i < columns; i++) {
+		int n = 0;
+
+		for (j = 0; j < argc; j++) {
+		    if (IS_NULL_D(&argv[j][i]))
+			continue;
+		    value[n++] = (double)argv[j][i];
+		}
+
+		if (!n)
+		    SET_NULL_D(&res[i]);
+		else
+		    res[i] = (DCELL) mode(value, n);
+	    }
+	    return 0;
+	}
+    default:
+	return E_INV_TYPE;
+    }
+}

Copied: grass/trunk/lib/calc/xnot.c (from rev 67656, grass/trunk/raster/r.mapcalc/xnot.c)
===================================================================
--- grass/trunk/lib/calc/xnot.c	                        (rev 0)
+++ grass/trunk/lib/calc/xnot.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,50 @@
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+not(a) = !a
+****************************************************************/
+
+int f_not(int argc, const int *argt, void **args)
+{
+    CELL *res = args[0];
+    CELL *arg1 = args[1];
+    int i;
+
+    if (argc < 1)
+	return E_ARG_LO;
+    if (argc > 1)
+	return E_ARG_HI;
+
+    if (argt[1] != CELL_TYPE)
+	return E_ARG_TYPE;
+
+    if (argt[0] != CELL_TYPE)
+	return E_RES_TYPE;
+
+    for (i = 0; i < columns; i++) {
+	if (IS_NULL_C(&arg1[i]))
+	    SET_NULL_C(&res[i]);
+	else
+	    res[i] = !arg1[i];
+    }
+
+    return 0;
+}
+
+int c_not(int argc, int *argt)
+{
+    if (argc < 1)
+	return E_ARG_LO;
+    if (argc > 1)
+	return E_ARG_HI;
+
+    if (argt[1] != CELL_TYPE)
+	return E_ARG_TYPE;
+
+    argt[0] = CELL_TYPE;
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/xnull.c (from rev 67656, grass/trunk/raster/r.mapcalc/xnull.c)
===================================================================
--- grass/trunk/lib/calc/xnull.c	                        (rev 0)
+++ grass/trunk/lib/calc/xnull.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,25 @@
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+null() null values
+****************************************************************/
+
+int f_null(int argc, const int *argt, void **args)
+{
+    CELL *res = args[0];
+    int i;
+
+    if (argc > 0)
+	return E_ARG_HI;
+
+    if (argt[0] != CELL_TYPE)
+	return E_RES_TYPE;
+
+    for (i = 0; i < columns; i++)
+	SET_NULL_C(&res[i]);
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/xor.c (from rev 67656, grass/trunk/raster/r.mapcalc/xor.c)
===================================================================
--- grass/trunk/lib/calc/xor.c	                        (rev 0)
+++ grass/trunk/lib/calc/xor.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,39 @@
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+or(a,b,c,...) = a || b || c || ...
+****************************************************************/
+
+int f_or(int argc, const int *argt, void **args)
+{
+    CELL *res = args[0];
+    int i, j;
+
+    if (argc < 1)
+	return E_ARG_LO;
+
+    if (argt[0] != CELL_TYPE)
+	return E_RES_TYPE;
+
+    for (i = 1; i <= argc; i++)
+	if (argt[i] != argt[0])
+	    return E_ARG_TYPE;
+
+    for (i = 0; i < columns; i++) {
+	res[i] = 0;
+	for (j = 1; j <= argc; j++) {
+	    CELL *arg = args[j];
+	    if (IS_NULL_C(&arg[i])) {
+		SET_NULL_C(&res[i]);
+		break;
+	    }
+	    if (arg[i])
+		res[i] = 1;
+	}
+    }
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/xor2.c (from rev 67656, grass/trunk/raster/r.mapcalc/xor2.c)
===================================================================
--- grass/trunk/lib/calc/xor2.c	                        (rev 0)
+++ grass/trunk/lib/calc/xor2.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,46 @@
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+or2(a,b,c,...) = a || b || c || ...
+
+Differs from or() in that the boolean axioms:
+
+	true || x == true
+	x || true == true
+
+hold even when x is null.
+****************************************************************/
+
+int f_or2(int argc, const int *argt, void **args)
+{
+    CELL *res = args[0];
+    int i, j;
+
+    if (argc < 1)
+	return E_ARG_LO;
+
+    if (argt[0] != CELL_TYPE)
+	return E_RES_TYPE;
+
+    for (i = 1; i <= argc; i++)
+	if (argt[i] != argt[0])
+	    return E_ARG_TYPE;
+
+    for (i = 0; i < columns; i++) {
+	res[i] = 0;
+	for (j = 1; j <= argc; j++) {
+	    CELL *arg = args[j];
+	    if (!IS_NULL_C(&arg[i]) && arg[i]) {
+		res[i] = 1;
+		break;
+	    }
+	    if (IS_NULL_C(&arg[i]))
+		SET_NULL_C(&res[i]);
+	}
+    }
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/xpow.c (from rev 67656, grass/trunk/raster/r.mapcalc/xpow.c)
===================================================================
--- grass/trunk/lib/calc/xpow.c	                        (rev 0)
+++ grass/trunk/lib/calc/xpow.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,96 @@
+
+#include <math.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+pow(a,b)
+   a raised to the power b
+****************************************************************/
+
+static int ipow(int x, int y)
+{
+    int res = 1;
+
+    while (y) {
+	if (y & 1)
+	    res *= x;
+	y >>= 1;
+	x *= x;
+    }
+    return res;
+}
+
+int f_pow(int argc, const int *argt, void **args)
+{
+    int i;
+
+    if (argc < 2)
+	return E_ARG_LO;
+    if (argc > 2)
+	return E_ARG_HI;
+
+    if (argt[1] != argt[0] || argt[2] != argt[0])
+	return E_ARG_TYPE;
+
+    switch (argt[0]) {
+    case CELL_TYPE:
+	{
+	    CELL *res = args[0];
+	    CELL *arg1 = args[1];
+	    CELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]) || arg2[i] < 0)
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = ipow(arg1[i], arg2[i]);
+	    }
+	    return 0;
+	}
+    case FCELL_TYPE:
+	{
+	    FCELL *res = args[0];
+	    FCELL *arg1 = args[1];
+	    FCELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]))
+		    SET_NULL_F(&res[i]);
+		else if (arg1[i] < 0 && arg2[i] != ceil(arg2[i]))
+		    SET_NULL_F(&res[i]);
+		else {
+		    floating_point_exception = 0;
+		    res[i] = pow(arg1[i], arg2[i]);
+		    if (floating_point_exception)
+			SET_NULL_F(&res[i]);
+		}
+	    }
+	    return 0;
+	}
+    case DCELL_TYPE:
+	{
+	    DCELL *res = args[0];
+	    DCELL *arg1 = args[1];
+	    DCELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]))
+		    SET_NULL_D(&res[i]);
+		else if (arg1[i] < 0 && arg2[i] != ceil(arg2[i]))
+		    SET_NULL_D(&res[i]);
+		else {
+		    floating_point_exception = 0;
+		    res[i] = pow(arg1[i], arg2[i]);
+		    if (floating_point_exception)
+			SET_NULL_D(&res[i]);
+		}
+	    }
+	    return 0;
+	}
+    default:
+	return E_INV_TYPE;
+    }
+}

Copied: grass/trunk/lib/calc/xrand.c (from rev 67656, grass/trunk/raster/r.mapcalc/xrand.c)
===================================================================
--- grass/trunk/lib/calc/xrand.c	                        (rev 0)
+++ grass/trunk/lib/calc/xrand.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,89 @@
+
+#include <stdlib.h>
+
+#include <grass/config.h>
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+rand(lo,hi) random values between a and b
+****************************************************************/
+
+int f_rand(int argc, const int *argt, void **args)
+{
+    int i;
+
+    if (argc < 2)
+	return E_ARG_LO;
+    if (argc > 2)
+	return E_ARG_HI;
+
+    switch (argt[0]) {
+    case CELL_TYPE:
+	{
+	    CELL *res = args[0];
+	    CELL *arg1 = args[1];
+	    CELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		unsigned int x = (unsigned int)G_mrand48();
+		int lo = arg1[i];
+		int hi = arg2[i];
+
+		if (lo > hi) {
+		    int tmp = lo;
+
+		    lo = hi;
+		    hi = tmp;
+		}
+		res[i] = (lo == hi) ? lo : lo + x % (unsigned int)(hi - lo);
+	    }
+	    return 0;
+	}
+    case FCELL_TYPE:
+	{
+	    FCELL *res = args[0];
+	    FCELL *arg1 = args[1];
+	    FCELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		double x = G_drand48();
+		FCELL lo = arg1[i];
+		FCELL hi = arg2[i];
+
+		if (lo > hi) {
+		    FCELL tmp = lo;
+
+		    lo = hi;
+		    hi = tmp;
+		}
+		res[i] = (FCELL) (lo + x * (hi - lo));
+	    }
+	    return 0;
+	}
+    case DCELL_TYPE:
+	{
+	    DCELL *res = args[0];
+	    DCELL *arg1 = args[1];
+	    DCELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		double x = G_drand48();
+		DCELL lo = arg1[i];
+		DCELL hi = arg2[i];
+
+		if (lo > hi) {
+		    DCELL tmp = lo;
+
+		    lo = hi;
+		    hi = tmp;
+		}
+		res[i] = lo + x * (hi - lo);
+	    }
+	    return 0;
+	}
+    default:
+	return E_INV_TYPE;
+    }
+}

Copied: grass/trunk/lib/calc/xround.c (from rev 67656, grass/trunk/raster/r.mapcalc/xround.c)
===================================================================
--- grass/trunk/lib/calc/xround.c	                        (rev 0)
+++ grass/trunk/lib/calc/xround.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,203 @@
+
+#include <limits.h>
+#include <math.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/**********************************************************************
+round(x, step, start)
+
+  rounds x to nearest value in the sequence
+    y[i] = i * step + start
+
+**********************************************************************/
+
+/* i_round(x) rounds x to nearest value, handles negative correctly */
+
+static double i_round(double x, double step, double start)
+{
+    x -= start;
+    x /= step;
+    x = floor(x + 0.5);
+    x *= step;
+    x += start;
+    return x;
+}
+
+/**********************************************************************/
+
+int f_round(int argc, const int *argt, void **args)
+{
+    const DCELL *arg1 = args[1];
+    int i;
+
+    if (argc < 1)
+	return E_ARG_LO;
+    if (argc > 3)
+	return E_ARG_HI;
+
+    if (argc == 1 && argt[0] != CELL_TYPE)
+	return E_RES_TYPE;
+    if (argt[1] != DCELL_TYPE)
+	return E_ARG_TYPE;
+    if (argc > 1 && argt[2] != DCELL_TYPE)
+	return E_ARG_TYPE;
+    if (argc > 2 && argt[3] != DCELL_TYPE)
+	return E_ARG_TYPE;
+
+    if (argc == 1) {
+	CELL *res = args[0];
+
+	for (i = 0; i < columns; i++) {
+	    if (IS_NULL_D(&arg1[i]))
+		SET_NULL_C(&res[i]);
+	    else {
+		DCELL x = i_round(arg1[i], 1.0, 0.0);
+		if (x > 2147483647.0 || x < -2147483647.0)
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = (CELL) x;
+	    }
+	}
+	return 0;
+    }
+    else if (argc == 2) {
+	const DCELL *arg2 = args[2];
+
+	switch (argt[0]) {
+        case CELL_TYPE:
+            {
+                CELL *res = args[0];
+    
+                for (i = 0; i < columns; i++) {
+                    if (IS_NULL_D(&arg1[i]))
+                        SET_NULL_C(&res[i]);
+                    else if (IS_NULL_D(&arg2[i]))
+                        SET_NULL_C(&res[i]);
+                    else {
+                        DCELL x = i_round(arg1[i], arg2[i], 0.0);
+                        if (x > 2147483647.0 || x < -2147483647.0)
+                            SET_NULL_C(&res[i]);
+                        else
+                            res[i] = (CELL) x;
+                    }
+                }
+                return 0;
+            }
+        case FCELL_TYPE:
+            {
+                FCELL *res = args[0];
+    
+                for (i = 0; i < columns; i++)
+                    if (IS_NULL_D(&arg1[i]))
+                        SET_NULL_F(&res[i]);
+                    else if (IS_NULL_D(&arg2[i]))
+                        SET_NULL_F(&res[i]);
+                    else
+                        res[i] = (FCELL) i_round(arg1[i], arg2[i], 0.0);
+                return 0;
+            }
+        case DCELL_TYPE:
+            {
+                DCELL *res = args[0];
+    
+                for (i = 0; i < columns; i++)
+                    if (IS_NULL_D(&arg1[i]))
+                        SET_NULL_D(&res[i]);
+                    else if (IS_NULL_D(&arg2[i]))
+                        SET_NULL_D(&res[i]);
+                    else
+                        res[i] = (DCELL) i_round(arg1[i], arg2[i], 0.0);
+                return 0;
+            }
+        default:
+            return E_INV_TYPE;
+        }
+    }
+    else if (argc == 3) {
+	const DCELL *arg2 = args[2];
+	const DCELL *arg3 = args[3];
+
+	switch (argt[0]) {
+        case CELL_TYPE:
+            {
+                CELL *res = args[0];
+    
+                for (i = 0; i < columns; i++) {
+                    if (IS_NULL_D(&arg1[i]))
+                        SET_NULL_C(&res[i]);
+                    else if (IS_NULL_D(&arg2[i]))
+                        SET_NULL_C(&res[i]);
+                    else if (IS_NULL_D(&arg3[i]))
+                        SET_NULL_C(&res[i]);
+                    else {
+                        DCELL x = i_round(arg1[i], arg2[i], arg3[i]);
+                        if (x > 2147483647.0 || x < -2147483647.0)
+                            SET_NULL_C(&res[i]);
+                        else
+                            res[i] = (CELL) x;
+                    }
+                }
+                return 0;
+            }
+        case FCELL_TYPE:
+            {
+                FCELL *res = args[0];
+    
+                for (i = 0; i < columns; i++)
+                    if (IS_NULL_D(&arg1[i]))
+                        SET_NULL_F(&res[i]);
+                    else if (IS_NULL_D(&arg2[i]))
+                        SET_NULL_F(&res[i]);
+                    else if (IS_NULL_D(&arg3[i]))
+                        SET_NULL_F(&res[i]);
+                    else
+                        res[i] = (FCELL) i_round(arg1[i], arg2[i], arg3[i]);
+                return 0;
+            }
+        case DCELL_TYPE:
+            {
+                DCELL *res = args[0];
+    
+                for (i = 0; i < columns; i++)
+                    if (IS_NULL_D(&arg1[i]))
+                        SET_NULL_D(&res[i]);
+                    else if (IS_NULL_D(&arg2[i]))
+                        SET_NULL_D(&res[i]);
+                    else if (IS_NULL_D(&arg3[i]))
+                        SET_NULL_D(&res[i]);
+                    else
+                        res[i] = (DCELL) i_round(arg1[i], arg2[i], arg3[i]);
+                return 0;
+            }
+        default:
+            return E_INV_TYPE;
+        }
+    }
+    else
+	return E_WTF;
+}
+
+int c_round(int argc, int *argt)
+{
+    if (argc < 1)
+	return E_ARG_LO;
+    if (argc > 3)
+	return E_ARG_HI;
+
+    argt[0] = CELL_TYPE;
+    if (argc > 1 && argt[0] < argt[2])
+	argt[0] = argt[2];
+    if (argc > 2 && argt[0] < argt[3])
+	argt[0] = argt[3];
+
+    argt[1] = DCELL_TYPE;
+    if (argc > 1)
+	argt[2] = DCELL_TYPE;
+    if (argc > 2)
+	argt[3] = DCELL_TYPE;
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/xshiftl.c (from rev 67656, grass/trunk/raster/r.mapcalc/xshiftl.c)
===================================================================
--- grass/trunk/lib/calc/xshiftl.c	                        (rev 0)
+++ grass/trunk/lib/calc/xshiftl.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,36 @@
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+shiftl(a,b) = a << b
+****************************************************************/
+
+int f_shiftl(int argc, const int *argt, void **args)
+{
+    CELL *res = args[0];
+    CELL *arg1 = args[1];
+    CELL *arg2 = args[2];
+    int i;
+
+    if (argc < 2)
+	return E_ARG_LO;
+    if (argc > 2)
+	return E_ARG_HI;
+
+    if (argt[1] != CELL_TYPE || argt[2] != CELL_TYPE)
+	return E_ARG_TYPE;
+
+    if (argt[0] != CELL_TYPE)
+	return E_RES_TYPE;
+
+    for (i = 0; i < columns; i++) {
+	if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]))
+	    SET_NULL_C(&res[i]);
+	else
+	    res[i] = arg1[i] << arg2[i];
+    }
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/xshiftr.c (from rev 67656, grass/trunk/raster/r.mapcalc/xshiftr.c)
===================================================================
--- grass/trunk/lib/calc/xshiftr.c	                        (rev 0)
+++ grass/trunk/lib/calc/xshiftr.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,36 @@
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+shiftr(a,b) = a >> b
+****************************************************************/
+
+int f_shiftr(int argc, const int *argt, void **args)
+{
+    CELL *res = args[0];
+    CELL *arg1 = args[1];
+    CELL *arg2 = args[2];
+    int i;
+
+    if (argc < 2)
+	return E_ARG_LO;
+    if (argc > 2)
+	return E_ARG_HI;
+
+    if (argt[1] != CELL_TYPE || argt[2] != CELL_TYPE)
+	return E_ARG_TYPE;
+
+    if (argt[0] != CELL_TYPE)
+	return E_RES_TYPE;
+
+    for (i = 0; i < columns; i++) {
+	if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]))
+	    SET_NULL_C(&res[i]);
+	else
+	    res[i] = arg1[i] >> arg2[i];
+    }
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/xshiftru.c (from rev 67656, grass/trunk/raster/r.mapcalc/xshiftru.c)
===================================================================
--- grass/trunk/lib/calc/xshiftru.c	                        (rev 0)
+++ grass/trunk/lib/calc/xshiftru.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,36 @@
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+shiftru(a,b) = (unsigned) a >> b
+****************************************************************/
+
+int f_shiftru(int argc, const int *argt, void **args)
+{
+    CELL *res = args[0];
+    CELL *arg1 = args[1];
+    CELL *arg2 = args[2];
+    int i;
+
+    if (argc < 2)
+	return E_ARG_LO;
+    if (argc > 2)
+	return E_ARG_HI;
+
+    if (argt[1] != CELL_TYPE || argt[2] != CELL_TYPE)
+	return E_ARG_TYPE;
+
+    if (argt[0] != CELL_TYPE)
+	return E_RES_TYPE;
+
+    for (i = 0; i < columns; i++) {
+	if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]))
+	    SET_NULL_C(&res[i]);
+	else
+	    res[i] = ((unsigned int)arg1[i]) >> arg2[i];
+    }
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/xsin.c (from rev 67656, grass/trunk/raster/r.mapcalc/xsin.c)
===================================================================
--- grass/trunk/lib/calc/xsin.c	                        (rev 0)
+++ grass/trunk/lib/calc/xsin.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,47 @@
+
+#include <math.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/**********************************************************************
+sin(x) 
+
+  if floating point exception occurs during the evaluation of sin(x)
+  the result is NULL
+
+  note: x is in degrees.
+**********************************************************************/
+
+#define DEGREES_TO_RADIANS (M_PI / 180.0)
+
+int f_sin(int argc, const int *argt, void **args)
+{
+    DCELL *res = args[0];
+    DCELL *arg1 = args[1];
+    int i;
+
+    if (argc < 1)
+	return E_ARG_LO;
+    if (argc > 1)
+	return E_ARG_HI;
+
+    if (argt[0] != DCELL_TYPE)
+	return E_RES_TYPE;
+
+    if (argt[1] != DCELL_TYPE)
+	return E_ARG_TYPE;
+
+    for (i = 0; i < columns; i++)
+	if (IS_NULL_D(&arg1[i]))
+	    SET_NULL_D(&res[i]);
+	else {
+	    floating_point_exception = 0;
+	    res[i] = sin(arg1[i] * DEGREES_TO_RADIANS);
+	    if (floating_point_exception)
+		SET_NULL_D(&res[i]);
+	}
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/xsqrt.c (from rev 67656, grass/trunk/raster/r.mapcalc/xsqrt.c)
===================================================================
--- grass/trunk/lib/calc/xsqrt.c	                        (rev 0)
+++ grass/trunk/lib/calc/xsqrt.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,43 @@
+
+#include <math.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/**********************************************************************
+sqrt(x) 
+
+  if floating point exception occurs during the evaluation of sqrt(x)
+  the result is NULL
+**********************************************************************/
+
+int f_sqrt(int argc, const int *argt, void **args)
+{
+    DCELL *res = args[0];
+    DCELL *arg1 = args[1];
+    int i;
+
+    if (argc < 1)
+	return E_ARG_LO;
+    if (argc > 1)
+	return E_ARG_HI;
+
+    if (argt[0] != DCELL_TYPE)
+	return E_RES_TYPE;
+
+    if (argt[1] != DCELL_TYPE)
+	return E_ARG_TYPE;
+
+    for (i = 0; i < columns; i++)
+	if (IS_NULL_D(&arg1[i]) || (arg1[i] < 0.0))
+	    SET_NULL_D(&res[i]);
+	else {
+	    floating_point_exception = 0;
+	    res[i] = sqrt(arg1[i]);
+	    if (floating_point_exception)
+		SET_NULL_D(&res[i]);
+	}
+
+    return 0;
+}

Copied: grass/trunk/lib/calc/xsub.c (from rev 67656, grass/trunk/raster/r.mapcalc/xsub.c)
===================================================================
--- grass/trunk/lib/calc/xsub.c	                        (rev 0)
+++ grass/trunk/lib/calc/xsub.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,68 @@
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/****************************************************************
+sub(a,b) = a - b
+****************************************************************/
+
+int f_sub(int argc, const int *argt, void **args)
+{
+    int i;
+
+    if (argc < 2)
+	return E_ARG_LO;
+    if (argc > 2)
+	return E_ARG_HI;
+
+    if (argt[1] != argt[0] || argt[2] != argt[0])
+	return E_ARG_TYPE;
+
+    switch (argt[0]) {
+    case CELL_TYPE:
+	{
+	    CELL *res = args[0];
+	    CELL *arg1 = args[1];
+	    CELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]))
+		    SET_NULL_C(&res[i]);
+		else
+		    res[i] = arg1[i] - arg2[i];
+	    }
+	    return 0;
+	}
+    case FCELL_TYPE:
+	{
+	    FCELL *res = args[0];
+	    FCELL *arg1 = args[1];
+	    FCELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]))
+		    SET_NULL_F(&res[i]);
+		else
+		    res[i] = arg1[i] - arg2[i];
+	    }
+	    return 0;
+	}
+    case DCELL_TYPE:
+	{
+	    DCELL *res = args[0];
+	    DCELL *arg1 = args[1];
+	    DCELL *arg2 = args[2];
+
+	    for (i = 0; i < columns; i++) {
+		if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]))
+		    SET_NULL_D(&res[i]);
+		else
+		    res[i] = arg1[i] - arg2[i];
+	    }
+	    return 0;
+	}
+    default:
+	return E_INV_TYPE;
+    }
+}

Copied: grass/trunk/lib/calc/xtan.c (from rev 67656, grass/trunk/raster/r.mapcalc/xtan.c)
===================================================================
--- grass/trunk/lib/calc/xtan.c	                        (rev 0)
+++ grass/trunk/lib/calc/xtan.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -0,0 +1,48 @@
+
+#include <stdlib.h>
+#include <math.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/**********************************************************************
+tan(x) 
+
+  if floating point exception occurs during the evaluation of tan(x)
+  the result is NULL
+
+  note: x is in degrees.
+**********************************************************************/
+
+#define DEGREES_TO_RADIANS (M_PI / 180.0)
+
+int f_tan(int argc, const int *argt, void **args)
+{
+    DCELL *res = args[0];
+    DCELL *arg1 = args[1];
+    int i;
+
+    if (argc < 1)
+	return E_ARG_LO;
+    if (argc > 1)
+	return E_ARG_HI;
+
+    if (argt[0] != DCELL_TYPE)
+	return E_RES_TYPE;
+
+    if (argt[1] != DCELL_TYPE)
+	return E_ARG_TYPE;
+
+    for (i = 0; i < columns; i++)
+	if (IS_NULL_D(&arg1[i]))
+	    SET_NULL_D(&res[i]);
+	else {
+	    floating_point_exception = 0;
+	    res[i] = tan(arg1[i] * DEGREES_TO_RADIANS);
+	    if (floating_point_exception)
+		SET_NULL_D(&res[i]);
+	}
+
+    return 0;
+}

Modified: grass/trunk/raster/r.mapcalc/Makefile
===================================================================
--- grass/trunk/raster/r.mapcalc/Makefile	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/Makefile	2016-01-25 09:28:12 UTC (rev 67658)
@@ -12,8 +12,8 @@
 include $(MODULE_TOPDIR)/include/Make/Multi.make
 
 EXTRA_CFLAGS = $(READLINEINCPATH) $(PTHREADINCPATH)
-LIBES2 =           $(GISLIB) $(RASTERLIB) $(BTREELIB) $(READLINELIBPATH) $(READLINELIB) $(HISTORYLIB) $(PTHREADLIBPATH) $(PTHREADLIB)
-LIBES3 = $(RASTER3DLIB) $(GISLIB) $(RASTERLIB) $(BTREELIB) $(READLINELIBPATH) $(READLINELIB) $(HISTORYLIB) $(PTHREADLIBPATH) $(PTHREADLIB)
+LIBES2 = $(CALCLIB) $(GISLIB) $(RASTERLIB) $(BTREELIB) $(READLINELIBPATH) $(READLINELIB) $(HISTORYLIB) $(PTHREADLIBPATH) $(PTHREADLIB)
+LIBES3 = $(CALCLIB) $(RASTER3DLIB) $(GISLIB) $(RASTERLIB) $(BTREELIB) $(READLINELIBPATH) $(READLINELIB) $(HISTORYLIB) $(PTHREADLIBPATH) $(PTHREADLIB)
 
 default: multi
 

Deleted: grass/trunk/raster/r.mapcalc/check.c
===================================================================
--- grass/trunk/raster/r.mapcalc/check.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/check.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,160 +0,0 @@
-
-#include "mapcalc.h"
-#include "func_proto.h"
-
-int c_int0(int argc, int *argt)
-{
-    if (argc > 0)
-	return E_ARG_HI;
-
-    argt[0] = CELL_TYPE;
-
-    return 0;
-}
-
-int c_double0(int argc, int *argt)
-{
-    if (argc > 0)
-	return E_ARG_HI;
-
-    argt[0] = DCELL_TYPE;
-
-    return 0;
-}
-
-int c_double1(int argc, int *argt)
-{
-    if (argc < 1)
-	return E_ARG_LO;
-    if (argc > 1)
-	return E_ARG_HI;
-
-    argt[0] = DCELL_TYPE;
-    argt[1] = DCELL_TYPE;
-
-    return 0;
-}
-
-int c_double12(int argc, int *argt)
-{
-    if (argc < 1)
-	return E_ARG_LO;
-
-    if (argc > 2)
-	return E_ARG_HI;
-
-    argt[0] = DCELL_TYPE;
-    argt[1] = DCELL_TYPE;
-    if (argc == 2)
-	argt[2] = DCELL_TYPE;
-
-    return 0;
-}
-
-int c_unop(int argc, int *argt)
-{
-    if (argc < 1)
-	return E_ARG_LO;
-    if (argc > 1)
-	return E_ARG_HI;
-
-    argt[0] = argt[1];
-
-    return 0;
-}
-
-int c_binop(int argc, int *argt)
-{
-    if (argc < 2)
-	return E_ARG_LO;
-    if (argc > 2)
-	return E_ARG_HI;
-
-    argt[0] = CELL_TYPE;
-    if (argt[1] == FCELL_TYPE || argt[2] == FCELL_TYPE)
-	argt[0] = FCELL_TYPE;
-    if (argt[1] == DCELL_TYPE || argt[2] == DCELL_TYPE)
-	argt[0] = DCELL_TYPE;
-
-    argt[1] = argt[0];
-    argt[2] = argt[0];
-
-    return 0;
-}
-
-int c_varop(int argc, int *argt)
-{
-    int i;
-
-    if (argc < 1)
-	return E_ARG_LO;
-
-    argt[0] = CELL_TYPE;
-
-    for (i = 1; i <= argc; i++)
-	if (argt[i] == FCELL_TYPE)
-	    argt[0] = FCELL_TYPE;
-
-    for (i = 1; i <= argc; i++)
-	if (argt[i] == DCELL_TYPE)
-	    argt[0] = DCELL_TYPE;
-
-    for (i = 1; i <= argc; i++)
-	argt[i] = argt[0];
-
-    return 0;
-}
-
-int c_cmpop(int argc, int *argt)
-{
-    int arg_type;
-
-    if (argc < 2)
-	return E_ARG_LO;
-    if (argc > 2)
-	return E_ARG_HI;
-
-    argt[0] = CELL_TYPE;
-
-    arg_type = CELL_TYPE;
-    if (argt[1] == FCELL_TYPE || argt[2] == FCELL_TYPE)
-	arg_type = FCELL_TYPE;
-    if (argt[1] == DCELL_TYPE || argt[2] == DCELL_TYPE)
-	arg_type = DCELL_TYPE;
-
-    argt[1] = arg_type;
-    argt[2] = arg_type;
-
-    return 0;
-}
-
-int c_logop(int argc, int *argt)
-{
-    int i;
-
-    if (argc < 1)
-	return E_ARG_LO;
-
-    for (i = 1; i <= argc; i++)
-	if (argt[i] != CELL_TYPE)
-	    return E_ARG_TYPE;
-
-    argt[0] = CELL_TYPE;
-
-    return 0;
-}
-
-int c_shiftop(int argc, int *argt)
-{
-    if (argc < 2)
-	return E_ARG_LO;
-    if (argc > 2)
-	return E_ARG_HI;
-
-    if (argt[1] != CELL_TYPE || argt[2] != CELL_TYPE)
-	return E_ARG_TYPE;
-
-    argt[0] = CELL_TYPE;
-
-    return 0;
-}

Modified: grass/trunk/raster/r.mapcalc/evaluate.c
===================================================================
--- grass/trunk/raster/r.mapcalc/evaluate.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/evaluate.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -13,7 +13,7 @@
 /****************************************************************************/
 
 int current_depth, current_row;
-int depths, rows, columns;
+int depths, rows;
 
 /****************************************************************************/
 

Modified: grass/trunk/raster/r.mapcalc/expression.c
===================================================================
--- grass/trunk/raster/r.mapcalc/expression.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/expression.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -19,10 +19,14 @@
 {
     int i;
 
-    for (i = 0; func_descs[i].name; i++) {
-	if (strcmp(name, func_descs[i].name) == 0)
-	    return &func_descs[i];
+    for (i = 0; local_func_descs[i].name; i++) {
+	if (strcmp(name, local_func_descs[i].name) == 0)
+	    return &local_func_descs[i];
     }
+    for (i = 0; calc_func_descs[i].name; i++) {
+	if (strcmp(name, calc_func_descs[i].name) == 0)
+	    return &calc_func_descs[i];
+    }
     return NULL;
 }
 

Modified: grass/trunk/raster/r.mapcalc/expression.h
===================================================================
--- grass/trunk/raster/r.mapcalc/expression.h	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/expression.h	2016-01-25 09:28:12 UTC (rev 67658)
@@ -2,19 +2,10 @@
 #ifndef __EXPRESSION_H_
 #define __EXPRESSION_H_
 
+#include <grass/calc.h>
+
 struct expr_list;
 
-typedef int func_t(int argc, const int *argt, void **args);
-typedef int args_t(int argc, int *argt);
-
-#define E_ARG_LO	1
-#define E_ARG_HI	2
-#define E_ARG_TYPE	3
-#define E_RES_TYPE	4
-#define E_INV_TYPE	5
-#define E_ARG_NUM	6
-#define E_WTF		99
-
 typedef enum expr_t
 {
     expr_type_constant,
@@ -85,13 +76,6 @@
     struct expr_list *next;
 } expr_list;
 
-typedef struct func_desc
-{
-    const char *name;
-    args_t *check_args;
-    func_t *func;
-} func_desc;
-
 extern int list_length(expr_list * l);
 extern void define_variable(expression * e);
 extern char *composite(const char *name, const char *mapset);
@@ -110,14 +94,6 @@
 extern expression *function(const char *name, expr_list * args);
 extern expression *binding(const char *var, expression * val);
 
-extern func_desc func_descs[];
+extern func_desc local_func_descs[];
 
-#define IS_NULL_C(x) (Rast_is_c_null_value((x)))
-#define IS_NULL_F(x) (Rast_is_f_null_value((x)))
-#define IS_NULL_D(x) (Rast_is_d_null_value((x)))
-
-#define SET_NULL_C(x) (Rast_set_c_null_value((x),1))
-#define SET_NULL_F(x) (Rast_set_f_null_value((x),1))
-#define SET_NULL_D(x) (Rast_set_d_null_value((x),1))
-
 #endif /* __EXPRESSION_H_ */

Modified: grass/trunk/raster/r.mapcalc/func_proto.h
===================================================================
--- grass/trunk/raster/r.mapcalc/func_proto.h	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/func_proto.h	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,104 +1,9 @@
 
 #include "expression.h"
 
-extern func_t f_add;
-extern func_t f_sub;
-extern func_t f_mul;
-extern func_t f_div;
-extern func_t f_mod;
-extern func_t f_pow;
-extern args_t c_binop;
-
-extern func_t f_neg;
-extern func_t f_abs;
-extern args_t c_unop;
-
-extern func_t f_gt;
-extern func_t f_ge;
-extern func_t f_lt;
-extern func_t f_le;
-extern func_t f_eq;
-extern func_t f_ne;
-extern args_t c_cmpop;
-
-extern func_t f_and;
-extern func_t f_or;
-extern func_t f_and2;
-extern func_t f_or2;
-extern func_t f_bitand;
-extern func_t f_bitor;
-extern func_t f_bitxor;
-extern args_t c_logop;
-
-extern func_t f_shiftl;
-extern func_t f_shiftr;
-extern func_t f_shiftru;
-extern args_t c_shiftop;
-
-extern func_t f_not;
-extern func_t f_bitnot;
-extern args_t c_not;
-
-extern func_t f_sqrt;
-extern func_t f_sin;
-extern func_t f_cos;
-extern func_t f_tan;
-extern func_t f_acos;
-extern func_t f_asin;
-extern args_t c_double1;
-
-extern func_t f_exp;
-extern func_t f_log;
-extern func_t f_atan;
-extern args_t c_double12;
-
-extern func_t f_int;
-extern args_t c_int;
-
-extern func_t f_float;
-extern args_t c_float;
-
-extern func_t f_double;
-extern args_t c_double;
-
-extern func_t f_round;
-extern args_t c_round;
-
-extern func_t f_eval;
-extern args_t c_eval;
-
-extern func_t f_if;
-extern args_t c_if;
-
-extern func_t f_isnull;
-extern args_t c_isnull;
-
-extern func_t f_graph;
-extern func_t f_graph2;
-extern args_t c_graph;
-
-extern func_t f_min;
-extern func_t f_max;
-extern func_t f_nmin;
-extern func_t f_nmax;
-extern args_t c_varop;
-
-extern func_t f_median;
-extern func_t f_nmedian;
-extern args_t c_median;
-
-extern func_t f_mode;
-extern func_t f_nmode;
-extern args_t c_mode;
-
-extern func_t f_rand;
-extern args_t c_binop;
-
-extern func_t f_null;
 extern func_t f_col;
 extern func_t f_row;
 extern func_t f_depth;
-extern args_t c_int0;
 
 extern func_t f_x;
 extern func_t f_y;
@@ -106,4 +11,3 @@
 extern func_t f_ewres;
 extern func_t f_nsres;
 extern func_t f_tbres;
-extern args_t c_double0;

Modified: grass/trunk/raster/r.mapcalc/function.c
===================================================================
--- grass/trunk/raster/r.mapcalc/function.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/function.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -7,79 +7,7 @@
 #include "expression.h"
 #include "func_proto.h"
 
-func_desc func_descs[] = {
-    {"add", c_varop, f_add},
-    {"sub", c_binop, f_sub},
-    {"mul", c_varop, f_mul},
-    {"div", c_binop, f_div},
-    {"mod", c_binop, f_mod},
-    {"pow", c_binop, f_pow},
-
-    {"neg", c_unop, f_neg},
-    {"abs", c_unop, f_abs},
-
-    {"gt", c_cmpop, f_gt},
-    {"ge", c_cmpop, f_ge},
-    {"lt", c_cmpop, f_lt},
-    {"le", c_cmpop, f_le},
-    {"eq", c_cmpop, f_eq},
-    {"ne", c_cmpop, f_ne},
-
-    {"and", c_logop, f_and},
-    {"or", c_logop, f_or},
-
-    {"and2", c_logop, f_and2},
-    {"or2", c_logop, f_or2},
-
-    {"not", c_not, f_not},
-
-    {"bitand", c_logop, f_bitand},
-    {"bitor", c_logop, f_bitor},
-    {"xor", c_logop, f_bitxor},
-
-    {"shiftl", c_shiftop, f_shiftl},
-    {"shiftr", c_shiftop, f_shiftr},
-    {"shiftru", c_shiftop, f_shiftru},
-
-    {"bitnot", c_not, f_bitnot},
-
-    {"sqrt", c_double1, f_sqrt},
-    {"sin", c_double1, f_sin},
-    {"cos", c_double1, f_cos},
-    {"tan", c_double1, f_tan},
-    {"acos", c_double1, f_acos},
-    {"asin", c_double1, f_asin},
-
-    {"exp", c_double12, f_exp},
-    {"log", c_double12, f_log},
-    {"atan", c_double12, f_atan},
-
-    {"int", c_int, f_int},
-    {"float", c_float, f_float},
-    {"double", c_double, f_double},
-    {"round", c_round, f_round},
-
-    {"eval", c_eval, f_eval},
-    {"if", c_if, f_if},
-    {"isnull", c_isnull, f_isnull},
-
-    {"max", c_varop, f_max},
-    {"min", c_varop, f_min},
-    {"median", c_varop, f_median},
-    {"mode", c_varop, f_mode},
-
-    {"nmax", c_varop, f_nmax},
-    {"nmin", c_varop, f_nmin},
-    {"nmedian", c_varop, f_nmedian},
-    {"nmode", c_varop, f_nmode},
-
-    {"graph", c_graph, f_graph},
-    {"graph2", c_graph, f_graph2},
-
-    {"rand", c_binop, f_rand},
-
-    {"null", c_int0, f_null},
-
+func_desc local_func_descs[] = {
     {"col", c_int0, f_col},
     {"row", c_int0, f_row},
     {"depth", c_int0, f_depth},
@@ -87,9 +15,11 @@
     {"x", c_double0, f_x},
     {"y", c_double0, f_y},
     {"z", c_double0, f_z},
+
     {"ewres", c_double0, f_ewres},
     {"nsres", c_double0, f_nsres},
     {"tbres", c_double0, f_tbres},
+
     {NULL, NULL, NULL}
 };
 
@@ -98,7 +28,9 @@
     int i;
 
     fprintf(stderr, _("Known functions:"));
-    for (i = 0; func_descs[i].name; i++)
-	fprintf(stderr, "%c%-10s", i % 7 ? ' ' : '\n', func_descs[i].name);
+    for (i = 0; calc_func_descs[i].name; i++)
+	fprintf(stderr, "%c%-10s", i % 7 ? ' ' : '\n', calc_func_descs[i].name);
+    for (i = 0; local_func_descs[i].name; i++)
+	fprintf(stderr, "%c%-10s", i % 7 ? ' ' : '\n', local_func_descs[i].name);
     fprintf(stderr, "\n");
 }

Modified: grass/trunk/raster/r.mapcalc/globals.h
===================================================================
--- grass/trunk/raster/r.mapcalc/globals.h	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/globals.h	2016-01-25 09:28:12 UTC (rev 67658)
@@ -2,14 +2,11 @@
 #ifndef __GLOBALS_H_
 #define __GLOBALS_H_
 
-extern volatile int floating_point_exception;
-extern volatile int floating_point_exception_occurred;
-extern int overflow_occurred;
 extern int overwrite_flag;
 extern long seed_value;
 extern long seeded;
 
 extern int current_depth, current_row;
-extern int depths, rows, columns;
+extern int depths, rows;
 
 #endif /* __GLOBALS_H_ */

Modified: grass/trunk/raster/r.mapcalc/main.c
===================================================================
--- grass/trunk/raster/r.mapcalc/main.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/main.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -14,7 +14,6 @@
  *****************************************************************************/
 
 #include <unistd.h>
-#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -25,12 +24,8 @@
 
 /****************************************************************************/
 
-int overflow_occurred;
 int overwrite_flag;
 
-volatile int floating_point_exception;
-volatile int floating_point_exception_occurred;
-
 long seed_value;
 long seeded;
 
@@ -40,47 +35,6 @@
 
 /****************************************************************************/
 
-static RETSIGTYPE handle_fpe(int n)
-{
-    floating_point_exception = 1;
-    floating_point_exception_occurred = 1;
-}
-
-static void pre_exec(void)
-{
-#ifndef __MINGW32__
-#ifdef SIGFPE
-    struct sigaction act;
-
-    act.sa_handler = &handle_fpe;
-    act.sa_flags = 0;
-    sigemptyset(&act.sa_mask);
-
-    sigaction(SIGFPE, &act, NULL);
-#endif
-#endif
-
-    floating_point_exception_occurred = 0;
-    overflow_occurred = 0;
-}
-
-static void post_exec(void)
-{
-#ifndef __MINGW32__
-#ifdef SIGFPE
-    struct sigaction act;
-
-    act.sa_handler = SIG_DFL;
-    act.sa_flags = 0;
-    sigemptyset(&act.sa_mask);
-
-    sigaction(SIGFPE, &act, NULL);
-#endif
-#endif
-}
-
-/****************************************************************************/
-
 static expr_list *parse_file(const char *filename)
 {
     expr_list *res;
@@ -206,11 +160,6 @@
 	all_ok = 0;
     }
 
-    if (overflow_occurred) {
-	G_warning(_("Overflow occurred in the calculation"));
-	all_ok = 0;
-    }
-
     return all_ok ? EXIT_SUCCESS : EXIT_FAILURE;
 }
 

Modified: grass/trunk/raster/r.mapcalc/map.c
===================================================================
--- grass/trunk/raster/r.mapcalc/map.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/map.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -14,6 +14,7 @@
 #include <grass/raster.h>
 #include <grass/btree.h>
 #include <grass/glocale.h>
+#include <grass/calc.h>
 
 #include "mapcalc.h"
 #include "globals.h"
@@ -29,6 +30,7 @@
 
     rows = Rast_window_rows();
     columns = Rast_window_cols();
+    calc_init(columns);
     depths = 1;
 }
 

Modified: grass/trunk/raster/r.mapcalc/map3.c
===================================================================
--- grass/trunk/raster/r.mapcalc/map3.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/map3.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -10,6 +10,7 @@
 #include <grass/raster3d.h>
 #include <grass/btree.h>
 #include <grass/glocale.h>
+#include <grass/calc.h>
 
 #include "mapcalc.h"
 #include "globals.h"
@@ -27,6 +28,7 @@
     rows = current_region3.rows;
     columns = current_region3.cols;
     depths = current_region3.depths;
+    calc_init(columns);
 }
 
 /****************************************************************************/

Deleted: grass/trunk/raster/r.mapcalc/xabs.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xabs.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xabs.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,69 +0,0 @@
-
-#include <math.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/**********************************************************************
-abs(x)
-
-   absolute value. if x is negative returns -x
-**********************************************************************/
-
-int f_abs(int argc, const int *argt, void **args)
-{
-    int i;
-
-    if (argc < 1)
-	return E_ARG_LO;
-    if (argc > 1)
-	return E_ARG_HI;
-
-    if (argt[0] != argt[1])
-	return E_RES_TYPE;
-
-    switch (argt[1]) {
-    case CELL_TYPE:
-	{
-	    CELL *res = args[0];
-	    CELL *arg1 = args[1];
-
-	    for (i = 0; i < columns; i++)
-		if (IS_NULL_C(&arg1[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg1[i] < 0 ? -arg1[i]
-			: arg1[i];
-	    return 0;
-	}
-    case FCELL_TYPE:
-	{
-	    FCELL *res = args[0];
-	    FCELL *arg1 = args[1];
-
-	    for (i = 0; i < columns; i++)
-		if (IS_NULL_F(&arg1[i]))
-		    SET_NULL_F(&res[i]);
-		else
-		    res[i] = (FCELL) fabs(arg1[i]);
-	    return 0;
-	}
-    case DCELL_TYPE:
-	{
-	    DCELL *res = args[0];
-	    DCELL *arg1 = args[1];
-
-	    for (i = 0; i < columns; i++)
-		if (IS_NULL_D(&arg1[i]))
-		    SET_NULL_D(&res[i]);
-		else
-		    res[i] = fabs(arg1[i]);
-	    return 0;
-	}
-    default:
-	return E_INV_TYPE;
-    }
-}

Deleted: grass/trunk/raster/r.mapcalc/xacos.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xacos.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xacos.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,50 +0,0 @@
-
-#include <stdlib.h>
-#include <math.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/**********************************************************************
-acos(x)  [0 and PI]
-
-  if floating point exception occurs during the evaluation of acos(x)
-  the result is NULL
-
-  note: result is in degrees
-**********************************************************************/
-
-#define RADIANS_TO_DEGREES (180.0 / M_PI)
-
-int f_acos(int argc, const int *argt, void **args)
-{
-    DCELL *res = args[0];
-    DCELL *arg1 = args[1];
-    int i;
-
-    if (argc < 1)
-	return E_ARG_LO;
-    if (argc > 1)
-	return E_ARG_HI;
-
-    if (argt[0] != DCELL_TYPE)
-	return E_RES_TYPE;
-
-    if (argt[1] != DCELL_TYPE)
-	return E_ARG_TYPE;
-
-    for (i = 0; i < columns; i++)
-	if (IS_NULL_D(&arg1[i]))
-	    SET_NULL_D(&res[i]);
-	else {
-	    floating_point_exception = 0;
-	    res[i] = RADIANS_TO_DEGREES * acos(arg1[i]);
-	    if (floating_point_exception)
-		SET_NULL_D(&res[i]);
-	}
-
-    return 0;
-}

Deleted: grass/trunk/raster/r.mapcalc/xadd.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xadd.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xadd.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,78 +0,0 @@
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-add(a,b,c,...) = a + b + c + ...
-****************************************************************/
-
-int f_add(int argc, const int *argt, void **args)
-{
-    int i, j;
-
-    if (argc < 1)
-	return E_ARG_LO;
-
-    for (i = 1; i <= argc; i++)
-	if (argt[i] != argt[0])
-	    return E_ARG_TYPE;
-
-    switch (argt[0]) {
-    case CELL_TYPE:
-	{
-	    CELL *res = args[0];
-	    CELL **argz = (CELL **) args;
-
-	    for (i = 0; i < columns; i++) {
-		res[i] = 0;
-		for (j = 1; j <= argc; j++) {
-		    if (IS_NULL_C(&argz[j][i])) {
-			SET_NULL_C(&res[i]);
-			break;
-		    }
-		    res[i] += argz[j][i];
-		}
-	    }
-	    return 0;
-	}
-    case FCELL_TYPE:
-	{
-	    FCELL *res = args[0];
-	    FCELL **argz = (FCELL **) args;
-
-	    for (i = 0; i < columns; i++) {
-		res[i] = 0;
-		for (j = 1; j <= argc; j++) {
-		    if (IS_NULL_F(&argz[j][i])) {
-			SET_NULL_F(&res[i]);
-			break;
-		    }
-		    res[i] += argz[j][i];
-		}
-	    }
-	    return 0;
-	}
-    case DCELL_TYPE:
-	{
-	    DCELL *res = args[0];
-	    DCELL **argz = (DCELL **) args;
-
-	    for (i = 0; i < columns; i++) {
-		res[i] = 0;
-		for (j = 1; j <= argc; j++) {
-		    if (IS_NULL_D(&argz[j][i])) {
-			SET_NULL_D(&res[i]);
-			break;
-		    }
-		    res[i] += argz[j][i];
-		}
-	    }
-	    return 0;
-	}
-    default:
-	return E_INV_TYPE;
-    }
-}

Deleted: grass/trunk/raster/r.mapcalc/xand.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xand.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xand.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,41 +0,0 @@
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-and(a,b,c,...) = a && b && c && ...
-****************************************************************/
-
-int f_and(int argc, const int *argt, void **args)
-{
-    CELL *res = args[0];
-    CELL **argz = (CELL **) args;
-    int i, j;
-
-    if (argc < 1)
-	return E_ARG_LO;
-
-    if (argt[0] != CELL_TYPE)
-	return E_RES_TYPE;
-
-    for (i = 1; i <= argc; i++)
-	if (argt[i] != CELL_TYPE)
-	    return E_ARG_TYPE;
-
-    for (i = 0; i < columns; i++) {
-	res[i] = 1;
-	for (j = 1; j <= argc; j++) {
-	    if (IS_NULL_C(&argz[j][i])) {
-		SET_NULL_C(&res[i]);
-		break;
-	    }
-	    if (!argz[j][i])
-		res[i] = 0;
-	}
-    }
-
-    return 0;
-}

Deleted: grass/trunk/raster/r.mapcalc/xand2.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xand2.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xand2.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,48 +0,0 @@
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-and2(a,b,c,...) = a && b && c && ...
-
-Differs from and() in that the boolean axioms:
-
-	false && x == false
-	x && false == false
-
-hold even when x is null.
-****************************************************************/
-
-int f_and2(int argc, const int *argt, void **args)
-{
-    CELL *res = args[0];
-    CELL **argz = (CELL **) args;
-    int i, j;
-
-    if (argc < 1)
-	return E_ARG_LO;
-
-    if (argt[0] != CELL_TYPE)
-	return E_RES_TYPE;
-
-    for (i = 1; i <= argc; i++)
-	if (argt[i] != CELL_TYPE)
-	    return E_ARG_TYPE;
-
-    for (i = 0; i < columns; i++) {
-	res[i] = 1;
-	for (j = 1; j <= argc; j++) {
-	    if (!IS_NULL_C(&argz[j][i]) && !argz[j][i]) {
-		res[i] = 0;
-		break;
-	    }
-	    if (IS_NULL_C(&argz[j][i]))
-		SET_NULL_C(&res[i]);
-	}
-    }
-
-    return 0;
-}

Deleted: grass/trunk/raster/r.mapcalc/xasin.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xasin.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xasin.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,50 +0,0 @@
-
-#include <stdlib.h>
-#include <math.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/**********************************************************************
-asin(x)  range [-90,90]
-
-  if floating point exception occurs during the evaluation of asin(x)
-  the result is NULL
-
-  note: result is in degrees
-**********************************************************************/
-
-#define RADIANS_TO_DEGREES (180.0 / M_PI)
-
-int f_asin(int argc, const int *argt, void **args)
-{
-    DCELL *res = args[0];
-    DCELL *arg1 = args[1];
-    int i;
-
-    if (argc < 1)
-	return E_ARG_LO;
-    if (argc > 1)
-	return E_ARG_HI;
-
-    if (argt[0] != DCELL_TYPE)
-	return E_RES_TYPE;
-
-    if (argt[1] != DCELL_TYPE)
-	return E_ARG_TYPE;
-
-    for (i = 0; i < columns; i++)
-	if (IS_NULL_D(&arg1[i]))
-	    SET_NULL_D(&res[i]);
-	else {
-	    floating_point_exception = 0;
-	    res[i] = RADIANS_TO_DEGREES * asin(arg1[i]);
-	    if (floating_point_exception)
-		SET_NULL_D(&res[i]);
-	}
-
-    return 0;
-}

Deleted: grass/trunk/raster/r.mapcalc/xatan.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xatan.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xatan.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,66 +0,0 @@
-
-#include <stdlib.h>
-#include <math.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/**********************************************************************
-atan(x)     range [-90,90]
-atan(x,y) = atan(y/x) range[0,360]
-
-  if floating point exception occurs during the evaluation of atan(x)
-  the result is NULL
-
-  note: result is in degrees
-**********************************************************************/
-
-#define RADIANS_TO_DEGREES (180.0 / M_PI)
-
-int f_atan(int argc, const int *argt, void **args)
-{
-    DCELL *res = args[0];
-    DCELL *arg1 = args[1];
-    DCELL *arg2;
-    int i;
-
-    if (argc < 1)
-	return E_ARG_LO;
-    if (argc > 2)
-	return E_ARG_HI;
-
-    if (argt[0] != DCELL_TYPE)
-	return E_RES_TYPE;
-
-    if (argt[1] != DCELL_TYPE)
-	return E_ARG_TYPE;
-
-    if (argc > 1 && argt[2] != DCELL_TYPE)
-	return E_ARG_TYPE;
-
-    arg2 = (argc > 1) ? args[2] : NULL;
-
-    for (i = 0; i < columns; i++)
-	if (IS_NULL_D(&arg1[i]))
-	    SET_NULL_D(&res[i]);
-	else if (argc > 1 && IS_NULL_D(&arg2[i]))
-	    SET_NULL_D(&res[i]);
-
-	else {
-	    floating_point_exception = 0;
-	    if (argc == 1)
-		res[i] = RADIANS_TO_DEGREES * atan(arg1[i]);
-	    else {
-		res[i] = RADIANS_TO_DEGREES * atan2(arg2[i], arg1[i]);
-		if (res[i] < 0)
-		    res[i] += 360.0;
-	    }
-	    if (floating_point_exception)
-		SET_NULL_D(&res[i]);
-	}
-
-    return 0;
-}

Deleted: grass/trunk/raster/r.mapcalc/xbitand.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xbitand.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xbitand.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,40 +0,0 @@
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-bitand(a,b,c,...) = a & b & c & ...
-****************************************************************/
-
-int f_bitand(int argc, const int *argt, void **args)
-{
-    CELL *res = args[0];
-    CELL **argz = (CELL **) args;
-    int i, j;
-
-    if (argc < 1)
-	return E_ARG_LO;
-
-    if (argt[0] != CELL_TYPE)
-	return E_RES_TYPE;
-
-    for (i = 1; i <= argc; i++)
-	if (argt[i] != CELL_TYPE)
-	    return E_ARG_TYPE;
-
-    for (i = 0; i < columns; i++) {
-	res[i] = ~0;
-	for (j = 1; j <= argc; j++) {
-	    if (IS_NULL_C(&argz[j][i])) {
-		SET_NULL_C(&res[i]);
-		break;
-	    }
-	    res[i] &= argz[j][i];
-	}
-    }
-
-    return 0;
-}

Deleted: grass/trunk/raster/r.mapcalc/xbitnot.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xbitnot.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xbitnot.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,37 +0,0 @@
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-bitnot(a) = ~a
-****************************************************************/
-
-int f_bitnot(int argc, const int *argt, void **args)
-{
-    CELL *res = args[0];
-    CELL *arg1 = args[1];
-    int i;
-
-    if (argc < 1)
-	return E_ARG_LO;
-    if (argc > 1)
-	return E_ARG_HI;
-
-    if (argt[1] != CELL_TYPE)
-	return E_ARG_TYPE;
-
-    if (argt[0] != CELL_TYPE)
-	return E_RES_TYPE;
-
-    for (i = 0; i < columns; i++) {
-	if (IS_NULL_C(&arg1[i]))
-	    SET_NULL_C(&res[i]);
-	else
-	    res[i] = ~arg1[i];
-    }
-
-    return 0;
-}

Deleted: grass/trunk/raster/r.mapcalc/xbitor.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xbitor.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xbitor.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,40 +0,0 @@
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-bitor(a,b,c,...) = a | b | c | ...
-****************************************************************/
-
-int f_bitor(int argc, const int *argt, void **args)
-{
-    CELL *res = args[0];
-    CELL **argz = (CELL **) args;
-    int i, j;
-
-    if (argc < 1)
-	return E_ARG_LO;
-
-    if (argt[0] != CELL_TYPE)
-	return E_RES_TYPE;
-
-    for (i = 1; i <= argc; i++)
-	if (argt[i] != CELL_TYPE)
-	    return E_ARG_TYPE;
-
-    for (i = 0; i < columns; i++) {
-	res[i] = 0;
-	for (j = 1; j <= argc; j++) {
-	    if (IS_NULL_C(&argz[j][i])) {
-		SET_NULL_C(&res[i]);
-		break;
-	    }
-	    res[i] |= argz[j][i];
-	}
-    }
-
-    return 0;
-}

Deleted: grass/trunk/raster/r.mapcalc/xbitxor.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xbitxor.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xbitxor.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,40 +0,0 @@
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-bitxor(a,b,c,...) = a ^ b ^ c ^ ...
-****************************************************************/
-
-int f_bitxor(int argc, const int *argt, void **args)
-{
-    CELL *res = args[0];
-    CELL **argz = (CELL **) args;
-    int i, j;
-
-    if (argc < 1)
-	return E_ARG_LO;
-
-    if (argt[0] != CELL_TYPE)
-	return E_RES_TYPE;
-
-    for (i = 1; i <= argc; i++)
-	if (argt[i] != CELL_TYPE)
-	    return E_ARG_TYPE;
-
-    for (i = 0; i < columns; i++) {
-	res[i] = 0;
-	for (j = 1; j <= argc; j++) {
-	    if (IS_NULL_C(&argz[j][i])) {
-		SET_NULL_C(&res[i]);
-		break;
-	    }
-	    res[i] ^= argz[j][i];
-	}
-    }
-
-    return 0;
-}

Deleted: grass/trunk/raster/r.mapcalc/xcos.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xcos.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xcos.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,49 +0,0 @@
-
-#include <math.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/**********************************************************************
-cos(x) 
-
-  if floating point exception occurs during the evaluation of cos(x)
-  the result is NULL
-
-  note: x is in degrees.
-**********************************************************************/
-
-#define DEGREES_TO_RADIANS (M_PI / 180.0)
-
-int f_cos(int argc, const int *argt, void **args)
-{
-    DCELL *res = args[0];
-    DCELL *arg1 = args[1];
-    int i;
-
-    if (argc < 1)
-	return E_ARG_LO;
-    if (argc > 1)
-	return E_ARG_HI;
-
-    if (argt[0] != DCELL_TYPE)
-	return E_RES_TYPE;
-
-    if (argt[1] != DCELL_TYPE)
-	return E_ARG_TYPE;
-
-    for (i = 0; i < columns; i++)
-	if (IS_NULL_D(&arg1[i]))
-	    SET_NULL_D(&res[i]);
-	else {
-	    floating_point_exception = 0;
-	    res[i] = cos(arg1[i] * DEGREES_TO_RADIANS);
-	    if (floating_point_exception)
-		SET_NULL_D(&res[i]);
-	}
-
-    return 0;
-}

Deleted: grass/trunk/raster/r.mapcalc/xdiv.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xdiv.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xdiv.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,81 +0,0 @@
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-div(a,b) = a / b
-****************************************************************/
-
-int f_div(int argc, const int *argt, void **args)
-{
-    int i;
-
-    if (argc < 2)
-	return E_ARG_LO;
-    if (argc > 2)
-	return E_ARG_HI;
-
-    if (argt[1] != argt[0] || argt[2] != argt[0])
-	return E_ARG_TYPE;
-
-    switch (argt[0]) {
-    case CELL_TYPE:
-	{
-	    CELL *res = args[0];
-	    CELL *arg1 = args[1];
-	    CELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]) ||
-		    arg2[i] == 0)
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg1[i] / arg2[i];
-	    }
-	    return 0;
-	}
-    case FCELL_TYPE:
-	{
-	    FCELL *res = args[0];
-	    FCELL *arg1 = args[1];
-	    FCELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]) ||
-		    arg2[i] == 0.0f)
-		    SET_NULL_F(&res[i]);
-		else {
-		    floating_point_exception = 0;
-		    res[i] = arg1[i] / arg2[i];
-		    if (floating_point_exception)
-			SET_NULL_F(&res[i]);
-		}
-	    }
-	    return 0;
-	}
-    case DCELL_TYPE:
-	{
-	    DCELL *res = args[0];
-	    DCELL *arg1 = args[1];
-	    DCELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]) ||
-		    arg2[i] == 0.0)
-		    SET_NULL_D(&res[i]);
-		else {
-		    floating_point_exception = 0;
-		    res[i] = arg1[i] / arg2[i];
-		    if (floating_point_exception)
-			SET_NULL_D(&res[i]);
-		}
-	    }
-	    return 0;
-	}
-    default:
-	return E_INV_TYPE;
-    }
-}

Deleted: grass/trunk/raster/r.mapcalc/xdouble.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xdouble.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xdouble.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,78 +0,0 @@
-
-#include <stdlib.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/**********************************************************************
-double(x)
-  converts x to double
-**********************************************************************/
-
-int f_double(int argc, const int *argt, void **args)
-{
-    DCELL *res = args[0];
-    int i;
-
-    if (argc < 1)
-	return E_ARG_LO;
-    if (argc > 1)
-	return E_ARG_HI;
-
-    if (argt[0] != DCELL_TYPE)
-	return E_RES_TYPE;
-
-    switch (argt[1]) {
-    case CELL_TYPE:
-	{
-	    CELL *arg1 = args[1];
-
-	    for (i = 0; i < columns; i++)
-		if (IS_NULL_C(&arg1[i]))
-		    SET_NULL_D(&res[i]);
-		else
-		    res[i] = (DCELL) arg1[i];
-	    return 0;
-	}
-    case FCELL_TYPE:
-	{
-	    FCELL *arg1 = args[1];
-
-	    for (i = 0; i < columns; i++)
-		if (IS_NULL_F(&arg1[i]))
-		    SET_NULL_D(&res[i]);
-		else
-		    res[i] = (DCELL) arg1[i];
-	    return 0;
-	}
-    case DCELL_TYPE:
-	{
-	    DCELL *arg1 = args[1];
-
-	    for (i = 0; i < columns; i++)
-		if (IS_NULL_D(&arg1[i]))
-		    SET_NULL_D(&res[i]);
-		else
-		    res[i] = (DCELL) arg1[i];
-	    return 0;
-	}
-    default:
-	return E_INV_TYPE;
-    }
-}
-
-int c_double(int argc, int *argt)
-{
-    if (argc < 1)
-	return E_ARG_LO;
-    if (argc > 1)
-	return E_ARG_HI;
-
-    argt[0] = DCELL_TYPE;
-    /*      argt[1] = argt[1];      */
-
-    return 0;
-}

Deleted: grass/trunk/raster/r.mapcalc/xeq.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xeq.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xeq.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,72 +0,0 @@
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-eq(a,b) = a == b
-****************************************************************/
-
-int f_eq(int argc, const int *argt, void **args)
-{
-    CELL *res = args[0];
-    int i;
-
-    if (argc < 2)
-	return E_ARG_LO;
-    if (argc > 2)
-	return E_ARG_HI;
-
-    if (argt[0] != CELL_TYPE)
-	return E_RES_TYPE;
-
-    for (i = 2; i <= argc; i++)
-	if (argt[i] != argt[1])
-	    return E_ARG_TYPE;
-
-    switch (argt[1]) {
-    case CELL_TYPE:
-	{
-	    CELL *arg1 = args[1];
-	    CELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg1[i] == arg2[i];
-	    }
-	    return 0;
-	}
-    case FCELL_TYPE:
-	{
-	    FCELL *arg1 = args[1];
-	    FCELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg1[i] == arg2[i];
-	    }
-	    return 0;
-	}
-    case DCELL_TYPE:
-	{
-	    DCELL *arg1 = args[1];
-	    DCELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg1[i] == arg2[i];
-	    }
-	    return 0;
-	}
-    default:
-	return E_INV_TYPE;
-    }
-}

Deleted: grass/trunk/raster/r.mapcalc/xeval.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xeval.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xeval.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,75 +0,0 @@
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/**********************************************************************
-eval(..,..,..,x) = x
-
-   return last argument
-**********************************************************************/
-
-int f_eval(int argc, const int *argt, void **args)
-{
-    int i;
-
-    if (argc < 1)
-	return E_ARG_LO;
-
-    if (argt[0] != argt[argc])
-	return E_RES_TYPE;
-
-    switch (argt[argc]) {
-    case CELL_TYPE:
-	{
-	    CELL *res = args[0];
-	    CELL *arg1 = args[argc];
-
-	    for (i = 0; i < columns; i++)
-		if (IS_NULL_C(&arg1[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg1[i];
-
-	    return 0;
-	}
-    case FCELL_TYPE:
-	{
-	    FCELL *res = args[0];
-	    FCELL *arg1 = args[argc];
-
-	    for (i = 0; i < columns; i++)
-		if (IS_NULL_F(&arg1[i]))
-		    SET_NULL_F(&res[i]);
-		else
-		    res[i] = arg1[i];
-	    return 0;
-	}
-    case DCELL_TYPE:
-	{
-	    DCELL *res = args[0];
-	    DCELL *arg1 = args[argc];
-
-	    for (i = 0; i < columns; i++)
-		if (IS_NULL_D(&arg1[i]))
-		    SET_NULL_D(&res[i]);
-		else
-		    res[i] = arg1[i];
-	    return 0;
-	}
-    default:
-	return E_INV_TYPE;
-    }
-}
-
-int c_eval(int argc, int *argt)
-{
-    if (argc < 1)
-	return E_ARG_LO;
-
-    argt[0] = argt[argc];
-
-    return 0;
-}

Deleted: grass/trunk/raster/r.mapcalc/xexp.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xexp.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xexp.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,55 +0,0 @@
-
-#include <math.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/**********************************************************************
-exp(x)   computes e raised to power x
-exp(x,y) computes x raised to power y
-
-  if floating point exception occurs during the evaluation of exp(x)
-  or exp(x,y) the result is NULL
-**********************************************************************/
-
-int f_exp(int argc, const int *argt, void **args)
-{
-    DCELL *res = args[0];
-    DCELL *arg1 = args[1];
-    DCELL *arg2;
-    int i;
-
-    if (argc < 1)
-	return E_ARG_LO;
-    if (argc > 2)
-	return E_ARG_HI;
-
-    if (argt[0] != DCELL_TYPE)
-	return E_RES_TYPE;
-
-    if (argt[1] != DCELL_TYPE)
-	return E_ARG_TYPE;
-
-    arg2 = (argc > 1) ? args[2] : NULL;
-
-    for (i = 0; i < columns; i++)
-	if (IS_NULL_D(&arg1[i]))
-	    SET_NULL_D(&res[i]);
-	else if (argc > 1 && IS_NULL_D(&arg2[i]))
-	    SET_NULL_D(&res[i]);
-	else if (argc > 1 && arg1[i] < 0 && arg2[i] != ceil(arg2[i]))
-	    SET_NULL_D(&res[i]);
-	else {
-	    floating_point_exception = 0;
-	    res[i] = (argc > 1)
-		? pow(arg1[i], arg2[i])
-		: exp(arg1[i]);
-	    if (floating_point_exception)
-		SET_NULL_D(&res[i]);
-	}
-
-    return 0;
-}

Deleted: grass/trunk/raster/r.mapcalc/xfloat.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xfloat.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xfloat.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,78 +0,0 @@
-
-#include <stdlib.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/**********************************************************************
-float(x)
-  converts x to float
-**********************************************************************/
-
-int f_float(int argc, const int *argt, void **args)
-{
-    FCELL *res = args[0];
-    int i;
-
-    if (argc < 1)
-	return E_ARG_LO;
-    if (argc > 1)
-	return E_ARG_HI;
-
-    if (argt[0] != FCELL_TYPE)
-	return E_RES_TYPE;
-
-    switch (argt[1]) {
-    case CELL_TYPE:
-	{
-	    CELL *arg1 = args[1];
-
-	    for (i = 0; i < columns; i++)
-		if (IS_NULL_C(&arg1[i]))
-		    SET_NULL_F(&res[i]);
-		else
-		    res[i] = (FCELL) arg1[i];
-	    return 0;
-	}
-    case FCELL_TYPE:
-	{
-	    FCELL *arg1 = args[1];
-
-	    for (i = 0; i < columns; i++)
-		if (IS_NULL_F(&arg1[i]))
-		    SET_NULL_F(&res[i]);
-		else
-		    res[i] = (FCELL) arg1[i];
-	    return 0;
-	}
-    case DCELL_TYPE:
-	{
-	    DCELL *arg1 = args[1];
-
-	    for (i = 0; i < columns; i++)
-		if (IS_NULL_D(&arg1[i]))
-		    SET_NULL_F(&res[i]);
-		else
-		    res[i] = (FCELL) arg1[i];
-	    return 0;
-	}
-    default:
-	return E_INV_TYPE;
-    }
-}
-
-int c_float(int argc, int *argt)
-{
-    if (argc < 1)
-	return E_ARG_LO;
-    if (argc > 1)
-	return E_ARG_HI;
-
-    argt[0] = FCELL_TYPE;
-    /*      argt[1] = argt[1];      */
-
-    return 0;
-}

Deleted: grass/trunk/raster/r.mapcalc/xge.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xge.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xge.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,65 +0,0 @@
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-ge(a,b) = a >= b
-****************************************************************/
-
-int f_ge(int argc, const int *argt, void **args)
-{
-    CELL *res = args[0];
-    int i;
-
-    if (argc < 2)
-	return E_ARG_LO;
-    if (argc > 2)
-	return E_ARG_HI;
-
-    switch (argt[1]) {
-    case CELL_TYPE:
-	{
-	    CELL *arg1 = args[1];
-	    CELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg1[i] >= arg2[i];
-	    }
-	    return 0;
-	}
-    case FCELL_TYPE:
-	{
-	    FCELL *arg1 = args[1];
-	    FCELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg1[i] >= arg2[i];
-	    }
-	    return 0;
-	}
-    case DCELL_TYPE:
-	{
-	    DCELL *arg1 = args[1];
-	    DCELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg1[i] >= arg2[i];
-	    }
-	    return 0;
-	}
-    default:
-	return E_INV_TYPE;
-    }
-}

Deleted: grass/trunk/raster/r.mapcalc/xgraph.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xgraph.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xgraph.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,180 +0,0 @@
-
-#include <stdlib.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-graph(x, x1,y1, x2,y2, ... xn,yn)  returns y value based on graph
-described by the x,y pairs.
-****************************************************************/
-
-int c_graph(int argc, int *argt)
-{
-    int i;
-
-    if (argc < 3)
-	return E_ARG_LO;
-
-    if (argc % 2 == 0)
-	return E_ARG_NUM;
-
-    for (i = 0; i <= argc; i++)
-	argt[i] = DCELL_TYPE;
-
-    return 0;
-}
-
-int f_graph(int argc, const int *argt, void **args)
-{
-    DCELL **argz = (DCELL **) args;
-    DCELL *res = argz[0];
-    int n = (argc - 1) / 2;
-    int i, j;
-
-    if (argc < 3)
-	return E_ARG_LO;
-
-    if (argc % 2 == 0)
-	return E_ARG_NUM;
-
-    if (argt[0] != DCELL_TYPE)
-	return E_RES_TYPE;
-
-    for (i = 1; i <= argc; i++)
-	if (argt[i] != DCELL_TYPE)
-	    return E_ARG_TYPE;
-
-    for (i = 0; i < columns; i++) {
-#define X(j) (argz[2 + 2 * (j) + 0][i])
-#define Y(j) (argz[2 + 2 * (j) + 1][i])
-#define x (argz[1][i])
-
-	if (IS_NULL_D(&x))
-	    goto null;
-
-	for (j = 0; j < n; j++)
-	    if (IS_NULL_D(&X(j)))
-		goto null;
-
-	for (j = 0; j < n - 1; j++)
-	    if (X(j + 1) <= X(j))
-		goto null;
-
-	if (x <= X(0)) {
-	    if (IS_NULL_D(&Y(0)))
-		goto null;
-	    res[i] = Y(0);
-	    continue;
-	}
-
-	if (x >= X(n - 1)) {
-	    if (IS_NULL_D(&Y(n - 1)))
-		goto null;
-	    res[i] = Y(n - 1);
-	    continue;
-	}
-
-	for (j = 0; j < n - 1; j++) {
-	    if (x > X(j + 1))
-		continue;
-
-	    if (IS_NULL_D(&Y(j)) || IS_NULL_D(&Y(j + 1)))
-		goto null;
-
-	    res[i] =
-		Y(j) + (x - X(j)) * (Y(j + 1) - Y(j)) / (X(j + 1) - X(j));
-
-	    break;
-	}
-#undef X
-#undef Y
-#undef x
-
-	continue;
-
-      null:
-	SET_NULL_D(&res[i]);
-    }
-
-    return 0;
-}
-
-int f_graph2(int argc, const int *argt, void **args)
-{
-    DCELL **argz = (DCELL **) args;
-    DCELL *res = argz[0];
-    int n = (argc - 1) / 2;
-    int i, j;
-
-    if (argc < 3)
-	return E_ARG_LO;
-
-    if (argc % 2 == 0)
-	return E_ARG_NUM;
-
-    if (argt[0] != DCELL_TYPE)
-	return E_RES_TYPE;
-
-    for (i = 1; i <= argc; i++)
-	if (argt[i] != DCELL_TYPE)
-	    return E_ARG_TYPE;
-
-    for (i = 0; i < columns; i++) {
-#define X(j) (argz[2 + (j) + 0][i])
-#define Y(j) (argz[2 + (j) + n][i])
-#define x (argz[1][i])
-
-	if (IS_NULL_D(&x))
-	    goto null;
-
-	for (j = 0; j < n; j++)
-	    if (IS_NULL_D(&X(j)))
-		goto null;
-
-	for (j = 0; j < n - 1; j++)
-	    if (X(j + 1) <= X(j))
-		goto null;
-
-	if (x <= X(0)) {
-	    if (IS_NULL_D(&Y(0)))
-		goto null;
-	    res[i] = Y(0);
-	    continue;
-	}
-
-	if (x >= X(n - 1)) {
-	    if (IS_NULL_D(&Y(n - 1)))
-		goto null;
-	    res[i] = Y(n - 1);
-	    continue;
-	}
-
-	for (j = 0; j < n - 1; j++) {
-	    if (x > X(j + 1))
-		continue;
-
-	    if (IS_NULL_D(&Y(j)) || IS_NULL_D(&Y(j + 1)))
-		goto null;
-
-	    res[i] =
-		Y(j) + (x - X(j)) * (Y(j + 1) - Y(j)) / (X(j + 1) - X(j));
-
-	    break;
-	}
-#undef X
-#undef Y
-#undef x
-
-	continue;
-
-      null:
-	SET_NULL_D(&res[i]);
-    }
-
-    return 0;
-}
-

Deleted: grass/trunk/raster/r.mapcalc/xgt.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xgt.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xgt.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,65 +0,0 @@
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-gt(a,b) = a > b
-****************************************************************/
-
-int f_gt(int argc, const int *argt, void **args)
-{
-    CELL *res = args[0];
-    int i;
-
-    if (argc < 2)
-	return E_ARG_LO;
-    if (argc > 2)
-	return E_ARG_HI;
-
-    switch (argt[1]) {
-    case CELL_TYPE:
-	{
-	    CELL *arg1 = args[1];
-	    CELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg1[i] > arg2[i];
-	    }
-	    return 0;
-	}
-    case FCELL_TYPE:
-	{
-	    FCELL *arg1 = args[1];
-	    FCELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg1[i] > arg2[i];
-	    }
-	    return 0;
-	}
-    case DCELL_TYPE:
-	{
-	    DCELL *arg1 = args[1];
-	    DCELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg1[i] > arg2[i];
-	    }
-	    return 0;
-	}
-    default:
-	return E_INV_TYPE;
-    }
-}

Deleted: grass/trunk/raster/r.mapcalc/xif.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xif.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xif.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,305 +0,0 @@
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/********************************************************************
- if(a)        1,0,1  1 if a is non zero, 0 otherwise
- if(a,b)      b,0,b  b if a is non zero, 0 otherwise
- if(a,b,c)    b,c,b  b if a is non zero, c otherwise
- if(a,b,c,d)  d,c,b  b if a is positive, c if a is zero, d if a is negative
-********************************************************************/
-
-static int f_if_i(int argc, const int *argt, void **args)
-{
-    CELL *res = args[0];
-    DCELL *arg1 = args[1];
-    CELL *arg2 = (argc >= 2) ? args[2] : NULL;
-    CELL *arg3 = (argc >= 3) ? args[3] : NULL;
-    CELL *arg4 = (argc >= 4) ? args[4] : NULL;
-    int i;
-
-    switch (argc) {
-    case 0:
-	return E_ARG_LO;
-    case 1:
-	for (i = 0; i < columns; i++)
-	    if (IS_NULL_D(&arg1[i]))
-		SET_NULL_C(&res[i]);
-	    else
-		res[i] = arg1[i] != 0.0 ? 1 : 0;
-	break;
-    case 2:
-	for (i = 0; i < columns; i++)
-	    if (IS_NULL_D(&arg1[i]))
-		SET_NULL_C(&res[i]);
-	    else if (arg1[i] == 0.0)
-		res[i] = 0;
-	    else {
-		if (IS_NULL_C(&arg2[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg2[i];
-	    }
-	break;
-    case 3:
-	for (i = 0; i < columns; i++)
-	    if (IS_NULL_D(&arg1[i]))
-		SET_NULL_C(&res[i]);
-	    else if (arg1[i] == 0.0) {
-		if (IS_NULL_C(&arg3[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg3[i];
-	    }
-	    else {
-		if (IS_NULL_C(&arg2[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg2[i];
-	    }
-	break;
-    case 4:
-	for (i = 0; i < columns; i++)
-	    if (IS_NULL_D(&arg1[i]))
-		SET_NULL_C(&res[i]);
-	    else if (arg1[i] == 0.0) {
-		if (IS_NULL_C(&arg3[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg3[i];
-	    }
-	    else if (arg1[i] > 0.0) {
-		if (IS_NULL_C(&arg2[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg2[i];
-	    }
-	    else {		/* (arg1[i] < 0.0) */
-
-		if (IS_NULL_C(&arg4[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg4[i];
-	    }
-	break;
-    default:
-	return E_ARG_HI;
-    }
-
-    return 0;
-}
-
-static int f_if_f(int argc, const int *argt, void **args)
-{
-    FCELL *res = args[0];
-    DCELL *arg1 = args[1];
-    FCELL *arg2 = (argc >= 2) ? args[2] : NULL;
-    FCELL *arg3 = (argc >= 3) ? args[3] : NULL;
-    FCELL *arg4 = (argc >= 4) ? args[4] : NULL;
-    int i;
-
-    switch (argc) {
-    case 0:
-	return E_ARG_LO;
-    case 1:
-	return E_ARG_TYPE;
-    case 2:
-	for (i = 0; i < columns; i++)
-	    if (IS_NULL_D(&arg1[i]))
-		SET_NULL_F(&res[i]);
-	    else if (arg1[i] == 0.0)
-		res[i] = 0.0;
-	    else {
-		if (IS_NULL_F(&arg2[i]))
-		    SET_NULL_F(&res[i]);
-		else
-		    res[i] = arg2[i];
-	    }
-	break;
-    case 3:
-	for (i = 0; i < columns; i++)
-	    if (IS_NULL_D(&arg1[i]))
-		SET_NULL_F(&res[i]);
-	    else if (arg1[i] == 0.0) {
-		if (IS_NULL_F(&arg3[i]))
-		    SET_NULL_F(&res[i]);
-		else
-		    res[i] = arg3[i];
-	    }
-	    else {
-		if (IS_NULL_F(&arg2[i]))
-		    SET_NULL_F(&res[i]);
-		else
-		    res[i] = arg2[i];
-	    }
-	break;
-    case 4:
-	for (i = 0; i < columns; i++)
-	    if (IS_NULL_D(&arg1[i]))
-		SET_NULL_F(&res[i]);
-	    else if (arg1[i] == 0.0) {
-		if (IS_NULL_F(&arg3[i]))
-		    SET_NULL_F(&res[i]);
-		else
-		    res[i] = arg3[i];
-	    }
-	    else if (arg1[i] > 0.0) {
-		if (IS_NULL_F(&arg2[i]))
-		    SET_NULL_F(&res[i]);
-		else
-		    res[i] = arg2[i];
-	    }
-	    else {		/* (arg1[i] < 0.0) */
-
-		if (IS_NULL_F(&arg4[i]))
-		    SET_NULL_F(&res[i]);
-		else
-		    res[i] = arg4[i];
-	    }
-	break;
-    default:
-	return E_ARG_HI;
-    }
-
-    return 0;
-}
-
-static int f_if_d(int argc, const int *argt, void **args)
-{
-    DCELL *res = args[0];
-    DCELL *arg1 = args[1];
-    DCELL *arg2 = (argc >= 2) ? args[2] : NULL;
-    DCELL *arg3 = (argc >= 3) ? args[3] : NULL;
-    DCELL *arg4 = (argc >= 4) ? args[4] : NULL;
-    int i;
-
-    switch (argc) {
-    case 0:
-	return E_ARG_LO;
-    case 1:
-	return E_ARG_TYPE;
-    case 2:
-	for (i = 0; i < columns; i++)
-	    if (IS_NULL_D(&arg1[i]))
-		SET_NULL_D(&res[i]);
-	    else if (arg1[i] == 0.0)
-		res[i] = 0.0;
-	    else {
-		if (IS_NULL_D(&arg2[i]))
-		    SET_NULL_D(&res[i]);
-		else
-		    res[i] = arg2[i];
-	    }
-	break;
-    case 3:
-	for (i = 0; i < columns; i++)
-	    if (IS_NULL_D(&arg1[i]))
-		SET_NULL_D(&res[i]);
-	    else if (arg1[i] == 0.0) {
-		if (IS_NULL_D(&arg3[i]))
-		    SET_NULL_D(&res[i]);
-		else
-		    res[i] = arg3[i];
-	    }
-	    else {
-		if (IS_NULL_D(&arg2[i]))
-		    SET_NULL_D(&res[i]);
-		else
-		    res[i] = arg2[i];
-	    }
-	break;
-    case 4:
-	for (i = 0; i < columns; i++)
-	    if (IS_NULL_D(&arg1[i]))
-		SET_NULL_D(&res[i]);
-	    else if (arg1[i] == 0.0) {
-		if (IS_NULL_D(&arg3[i]))
-		    SET_NULL_D(&res[i]);
-		else
-		    res[i] = arg3[i];
-	    }
-	    else if (arg1[i] > 0.0) {
-		if (IS_NULL_D(&arg2[i]))
-		    SET_NULL_D(&res[i]);
-		else
-		    res[i] = arg2[i];
-	    }
-	    else {		/* (arg1[i] < 0.0) */
-
-		if (IS_NULL_D(&arg4[i]))
-		    SET_NULL_D(&res[i]);
-		else
-		    res[i] = arg4[i];
-	    }
-	break;
-    default:
-	return E_ARG_HI;
-    }
-
-    return 0;
-}
-
-int f_if(int argc, const int *argt, void **args)
-{
-    if (argc < 1)
-	return E_ARG_LO;
-    if (argc > 4)
-	return E_ARG_HI;
-
-    if (argt[1] != DCELL_TYPE)
-	return E_ARG_TYPE;
-    if (argc >= 2 && argt[2] != argt[0])
-	return E_ARG_TYPE;
-    if (argc >= 3 && argt[3] != argt[0])
-	return E_ARG_TYPE;
-    if (argc >= 4 && argt[4] != argt[0])
-	return E_ARG_TYPE;
-
-    switch (argt[0]) {
-    case CELL_TYPE:
-	return f_if_i(argc, argt, args);
-    case FCELL_TYPE:
-	return f_if_f(argc, argt, args);
-    case DCELL_TYPE:
-	return f_if_d(argc, argt, args);
-    default:
-	return E_INV_TYPE;
-    }
-}
-
-int c_if(int argc, int *argt)
-{
-    if (argc < 1)
-	return E_ARG_LO;
-    if (argc > 4)
-	return E_ARG_HI;
-
-    argt[0] = CELL_TYPE;
-
-    if (argc >= 2 && argt[2] == FCELL_TYPE)
-	argt[0] = FCELL_TYPE;
-    if (argc >= 3 && argt[3] == FCELL_TYPE)
-	argt[0] = FCELL_TYPE;
-    if (argc >= 4 && argt[4] == FCELL_TYPE)
-	argt[0] = FCELL_TYPE;
-
-    if (argc >= 2 && argt[2] == DCELL_TYPE)
-	argt[0] = DCELL_TYPE;
-    if (argc >= 3 && argt[3] == DCELL_TYPE)
-	argt[0] = DCELL_TYPE;
-    if (argc >= 4 && argt[4] == DCELL_TYPE)
-	argt[0] = DCELL_TYPE;
-
-    argt[1] = DCELL_TYPE;
-    if (argc >= 2)
-	argt[2] = argt[0];
-    if (argc >= 3)
-	argt[3] = argt[0];
-    if (argc >= 4)
-	argt[4] = argt[0];
-
-    return 0;
-}

Deleted: grass/trunk/raster/r.mapcalc/xint.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xint.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xint.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,78 +0,0 @@
-
-#include <stdlib.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/**********************************************************************
-int(x)
-  converts x to int
-**********************************************************************/
-
-int f_int(int argc, const int *argt, void **args)
-{
-    CELL *res = args[0];
-    int i;
-
-    if (argc < 1)
-	return E_ARG_LO;
-    if (argc > 1)
-	return E_ARG_HI;
-
-    if (argt[0] != CELL_TYPE)
-	return E_RES_TYPE;
-
-    switch (argt[1]) {
-    case CELL_TYPE:
-	{
-	    CELL *arg1 = args[1];
-
-	    for (i = 0; i < columns; i++)
-		if (IS_NULL_C(&arg1[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = (CELL) arg1[i];
-	    return 0;
-	}
-    case FCELL_TYPE:
-	{
-	    FCELL *arg1 = args[1];
-
-	    for (i = 0; i < columns; i++)
-		if (IS_NULL_F(&arg1[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = (CELL) arg1[i];
-	    return 0;
-	}
-    case DCELL_TYPE:
-	{
-	    DCELL *arg1 = args[1];
-
-	    for (i = 0; i < columns; i++)
-		if (IS_NULL_D(&arg1[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = (CELL) arg1[i];
-	    return 0;
-	}
-    default:
-	return E_INV_TYPE;
-    }
-}
-
-int c_int(int argc, int *argt)
-{
-    if (argc < 1)
-	return E_ARG_LO;
-    if (argc > 1)
-	return E_ARG_HI;
-
-    argt[0] = CELL_TYPE;
-    /*      argt[1] = argt[1];      */
-
-    return 0;
-}

Deleted: grass/trunk/raster/r.mapcalc/xisnull.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xisnull.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xisnull.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,66 +0,0 @@
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/**********************************************************************
-isnull(x)
-  return 1 if x is null, 0 otherwise
-**********************************************************************/
-
-int f_isnull(int argc, const int *argt, void **args)
-{
-    int *res = args[0];
-    int i;
-
-    if (argc < 1)
-	return E_ARG_LO;
-    if (argc > 1)
-	return E_ARG_HI;
-
-    if (argt[0] != CELL_TYPE)
-	return E_RES_TYPE;
-
-    switch (argt[1]) {
-    case CELL_TYPE:
-	{
-	    CELL *arg1 = args[1];
-
-	    for (i = 0; i < columns; i++)
-		res[i] = IS_NULL_C(&arg1[i]) ? 1 : 0;
-	    return 0;
-	}
-    case FCELL_TYPE:
-	{
-	    FCELL *arg1 = args[1];
-
-	    for (i = 0; i < columns; i++)
-		res[i] = IS_NULL_F(&arg1[i]) ? 1 : 0;
-	    return 0;
-	}
-    case DCELL_TYPE:
-	{
-	    DCELL *arg1 = args[1];
-
-	    for (i = 0; i < columns; i++)
-		res[i] = IS_NULL_D(&arg1[i]) ? 1 : 0;
-	    return 0;
-	}
-    default:
-	return E_INV_TYPE;
-    }
-}
-
-int c_isnull(int argc, int *argt)
-{
-    if (argc < 1)
-	return E_ARG_LO;
-    if (argc > 1)
-	return E_ARG_HI;
-
-    argt[0] = CELL_TYPE;
-
-    return 0;
-}

Deleted: grass/trunk/raster/r.mapcalc/xle.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xle.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xle.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,65 +0,0 @@
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-le(a,b) = a <= b
-****************************************************************/
-
-int f_le(int argc, const int *argt, void **args)
-{
-    CELL *res = args[0];
-    int i;
-
-    if (argc < 2)
-	return E_ARG_LO;
-    if (argc > 2)
-	return E_ARG_HI;
-
-    switch (argt[1]) {
-    case CELL_TYPE:
-	{
-	    CELL *arg1 = args[1];
-	    CELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg1[i] <= arg2[i];
-	    }
-	    return 0;
-	}
-    case FCELL_TYPE:
-	{
-	    FCELL *arg1 = args[1];
-	    FCELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg1[i] <= arg2[i];
-	    }
-	    return 0;
-	}
-    case DCELL_TYPE:
-	{
-	    DCELL *arg1 = args[1];
-	    DCELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg1[i] <= arg2[i];
-	    }
-	    return 0;
-	}
-    default:
-	return E_INV_TYPE;
-    }
-}

Deleted: grass/trunk/raster/r.mapcalc/xlog.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xlog.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xlog.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,61 +0,0 @@
-
-#include <math.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/**********************************************************************
-log(x) 
-log(x,b)
-
-  first form computes the natural log of x = ln(x)
-  second form computes log of x base b = ln(x)/ln(b)
-
-  if x is non-positive, or floating point exception occurs while
-  computing ln(x), the result is NULL
-
-  if b is non-positive, or 1.0, or floating point exception occurs while
-  computing ln(b), the result is NULL
-**********************************************************************/
-
-int f_log(int argc, const int *argt, void **args)
-{
-    DCELL *res = args[0];
-    DCELL *arg1 = args[1];
-    DCELL *arg2 = (argc >= 2) ? args[2] : (DCELL *) 0;
-    int i;
-
-    if (argc < 1)
-	return E_ARG_LO;
-
-    if (argc > 2)
-	return E_ARG_HI;
-
-    if (argt[0] != DCELL_TYPE)
-	return E_RES_TYPE;
-
-    if (argt[1] != DCELL_TYPE)
-	return E_ARG_TYPE;
-
-    if (argc > 1 && argt[2] != DCELL_TYPE)
-	return E_ARG_TYPE;
-
-    for (i = 0; i < columns; i++)
-	if (IS_NULL_D(&arg1[i]) || (arg1[i] <= 0.0))
-	    SET_NULL_D(&res[i]);
-	else if (argc > 1 && (IS_NULL_D(&arg2[i]) || (arg2[i] <= 0.0)))
-	    SET_NULL_D(&res[i]);
-	else {
-	    floating_point_exception = 0;
-	    res[i] = (argc > 1)
-		? log(arg1[i]) / log(arg2[i])
-		: log(arg1[i]);
-	    if (floating_point_exception)
-		SET_NULL_D(&res[i]);
-	}
-
-    return 0;
-}

Deleted: grass/trunk/raster/r.mapcalc/xlt.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xlt.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xlt.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,65 +0,0 @@
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-lt(a,b) = a < b
-****************************************************************/
-
-int f_lt(int argc, const int *argt, void **args)
-{
-    CELL *res = args[0];
-    int i;
-
-    if (argc < 2)
-	return E_ARG_LO;
-    if (argc > 2)
-	return E_ARG_HI;
-
-    switch (argt[1]) {
-    case CELL_TYPE:
-	{
-	    CELL *arg1 = args[1];
-	    CELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg1[i] < arg2[i];
-	    }
-	    return 0;
-	}
-    case FCELL_TYPE:
-	{
-	    FCELL *arg1 = args[1];
-	    FCELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg1[i] < arg2[i];
-	    }
-	    return 0;
-	}
-    case DCELL_TYPE:
-	{
-	    DCELL *arg1 = args[1];
-	    DCELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg1[i] < arg2[i];
-	    }
-	    return 0;
-	}
-    default:
-	return E_INV_TYPE;
-    }
-}

Deleted: grass/trunk/raster/r.mapcalc/xmax.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xmax.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xmax.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,100 +0,0 @@
-
-#include <stdlib.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-max(x0,x1,...,xn) returns maximum value
-****************************************************************/
-
-int f_max(int argc, const int *argt, void **args)
-{
-    int i, j;
-
-    if (argc < 1)
-	return E_ARG_LO;
-
-    for (i = 1; i <= argc; i++)
-	if (argt[i] != argt[0])
-	    return E_ARG_TYPE;
-
-    switch (argt[0]) {
-    case CELL_TYPE:
-	{
-	    CELL *res = args[0];
-	    CELL **argz = (CELL **) args;
-
-	    for (i = 0; i < columns; i++) {
-		int nul = 0;
-		CELL max;
-
-		for (j = 1; j <= argc; j++)
-		    if (IS_NULL_C(&argz[j][i]))
-			nul = 1;
-		    else if (j == 1)
-			max = argz[j][i];
-		    else if (max < argz[j][i])
-			max = argz[j][i];
-		if (nul)
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = max;
-	    }
-	    return 0;
-	}
-    case FCELL_TYPE:
-	{
-	    FCELL *res = args[0];
-	    FCELL **argz = (FCELL **) args;
-
-	    for (i = 0; i < columns; i++) {
-		int nul = 0;
-		FCELL max;
-
-		for (j = 1; j <= argc; j++)
-		    if (IS_NULL_F(&argz[j][i]))
-			nul = 1;
-		    else if (j == 1)
-			max = argz[j][i];
-		    else if (max < argz[j][i])
-			max = argz[j][i];
-		if (nul)
-		    SET_NULL_F(&res[i]);
-		else
-		    res[i] = max;
-	    }
-
-	    return 0;
-	}
-    case DCELL_TYPE:
-	{
-	    DCELL *res = args[0];
-	    DCELL **argz = (DCELL **) args;
-
-	    for (i = 0; i < columns; i++) {
-		int nul = 0;
-		DCELL max;
-
-		for (j = 1; j <= argc; j++)
-		    if (IS_NULL_D(&argz[j][i]))
-			nul = 1;
-		    else if (j == 1)
-			max = argz[j][i];
-		    else if (max < argz[j][i])
-			max = argz[j][i];
-		if (nul)
-		    SET_NULL_D(&res[i]);
-		else
-		    res[i] = max;
-	    }
-
-	    return 0;
-	}
-    default:
-	return E_INV_TYPE;
-    }
-}

Deleted: grass/trunk/raster/r.mapcalc/xmedian.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xmedian.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xmedian.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,155 +0,0 @@
-
-#include <stdlib.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/**********************************************************************
-median(x1,x2,..,xn)
-   return median of arguments
-**********************************************************************/
-
-static int icmp(const void *aa, const void *bb)
-{
-    const CELL *a = aa;
-    const CELL *b = bb;
-
-    return *a - *b;
-}
-
-static int fcmp(const void *aa, const void *bb)
-{
-    const FCELL *a = aa;
-    const FCELL *b = bb;
-
-    if (*a < *b)
-	return -1;
-    if (*a > *b)
-	return 1;
-    return 0;
-}
-
-static int dcmp(const void *aa, const void *bb)
-{
-    const DCELL *a = aa;
-    const DCELL *b = bb;
-
-    if (*a < *b)
-	return -1;
-    if (*a > *b)
-	return 1;
-    return 0;
-}
-
-int f_median(int argc, const int *argt, void **args)
-{
-    static void *array;
-    static int alloc;
-    int size = argc * Rast_cell_size(argt[0]);
-    int i, j;
-
-    if (argc < 1)
-	return E_ARG_LO;
-
-    for (i = 1; i <= argc; i++)
-	if (argt[i] != argt[0])
-	    return E_ARG_TYPE;
-
-    if (size > alloc) {
-	alloc = size;
-	array = G_realloc(array, size);
-    }
-
-    switch (argt[0]) {
-    case CELL_TYPE:
-	{
-	    CELL *res = args[0];
-	    CELL **argv = (CELL **) &args[1];
-	    CELL *a = array;
-	    CELL *a1 = &a[(argc - 1) / 2];
-	    CELL *a2 = &a[argc / 2];
-
-	    for (i = 0; i < columns; i++) {
-		int nv = 0;
-
-		for (j = 0; j < argc && !nv; j++) {
-		    if (IS_NULL_C(&argv[j][i]))
-			nv = 1;
-		    else
-			a[j] = argv[j][i];
-		}
-
-		if (nv)
-		    SET_NULL_C(&res[i]);
-		else {
-		    qsort(a, argc, sizeof(CELL), icmp);
-		    res[i] = (*a1 + *a2) / 2;
-		}
-	    }
-
-	    return 0;
-	}
-    case FCELL_TYPE:
-	{
-	    FCELL *res = args[0];
-	    FCELL **argv = (FCELL **) &args[1];
-	    FCELL *a = array;
-	    FCELL *a1 = &a[(argc - 1) / 2];
-	    FCELL *a2 = &a[argc / 2];
-
-	    for (i = 0; i < columns; i++) {
-		int nv = 0;
-
-		for (j = 0; j < argc && !nv; j++) {
-		    if (IS_NULL_F(&argv[j][i]))
-			nv = 1;
-		    else
-			a[j] = argv[j][i];
-		}
-
-		if (nv)
-		    SET_NULL_F(&res[i]);
-		else {
-		    qsort(a, argc, sizeof(FCELL), fcmp);
-		    res[i] = (*a1 + *a2) / 2;
-		}
-	    }
-
-	    return 0;
-	}
-    case DCELL_TYPE:
-	{
-	    DCELL *res = args[0];
-	    DCELL **argv = (DCELL **) &args[1];
-	    DCELL *a = array;
-	    DCELL *a1 = &a[(argc - 1) / 2];
-	    DCELL *a2 = &a[argc / 2];
-
-	    for (i = 0; i < columns; i++) {
-		int nv = 0;
-
-		for (j = 0; j < argc && !nv; j++) {
-		    if (IS_NULL_D(&argv[j][i]))
-			nv = 1;
-		    else
-			a[j] = argv[j][i];
-		}
-
-		if (nv)
-		    SET_NULL_D(&res[i]);
-		else {
-		    qsort(a, argc, sizeof(DCELL), dcmp);
-		    res[i] = (*a1 + *a2) / 2;
-		}
-	    }
-
-	    return 0;
-	}
-    default:
-	return E_INV_TYPE;
-    }
-}

Deleted: grass/trunk/raster/r.mapcalc/xmin.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xmin.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xmin.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,100 +0,0 @@
-
-#include <stdlib.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-min(x0,x1,...,xn) returns minimum value
-****************************************************************/
-
-int f_min(int argc, const int *argt, void **args)
-{
-    int i, j;
-
-    if (argc < 1)
-	return E_ARG_LO;
-
-    for (i = 1; i <= argc; i++)
-	if (argt[i] != argt[0])
-	    return E_ARG_TYPE;
-
-    switch (argt[0]) {
-    case CELL_TYPE:
-	{
-	    CELL *res = args[0];
-	    CELL **argz = (CELL **) args;
-
-	    for (i = 0; i < columns; i++) {
-		int nul = 0;
-		CELL min;
-
-		for (j = 1; j <= argc; j++)
-		    if (IS_NULL_C(&argz[j][i]))
-			nul = 1;
-		    else if (j == 1)
-			min = argz[j][i];
-		    else if (min > argz[j][i])
-			min = argz[j][i];
-		if (nul)
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = min;
-	    }
-	    return 0;
-	}
-    case FCELL_TYPE:
-	{
-	    FCELL *res = args[0];
-	    FCELL **argz = (FCELL **) args;
-
-	    for (i = 0; i < columns; i++) {
-		int nul = 0;
-		FCELL min;
-
-		for (j = 1; j <= argc; j++)
-		    if (IS_NULL_F(&argz[j][i]))
-			nul = 1;
-		    else if (j == 1)
-			min = argz[j][i];
-		    else if (min > argz[j][i])
-			min = argz[j][i];
-		if (nul)
-		    SET_NULL_F(&res[i]);
-		else
-		    res[i] = min;
-	    }
-
-	    return 0;
-	}
-    case DCELL_TYPE:
-	{
-	    DCELL *res = args[0];
-	    DCELL **argz = (DCELL **) args;
-
-	    for (i = 0; i < columns; i++) {
-		int nul = 0;
-		DCELL min;
-
-		for (j = 1; j <= argc; j++)
-		    if (IS_NULL_D(&argz[j][i]))
-			nul = 1;
-		    else if (j == 1)
-			min = argz[j][i];
-		    else if (min > argz[j][i])
-			min = argz[j][i];
-		if (nul)
-		    SET_NULL_D(&res[i]);
-		else
-		    res[i] = min;
-	    }
-
-	    return 0;
-	}
-    default:
-	return E_INV_TYPE;
-    }
-}

Deleted: grass/trunk/raster/r.mapcalc/xmod.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xmod.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xmod.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,80 +0,0 @@
-
-#include <math.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-mod(a,b) = a % b
-****************************************************************/
-
-int f_mod(int argc, const int *argt, void **args)
-{
-    int i;
-
-    if (argc < 2)
-	return E_ARG_LO;
-    if (argc > 2)
-	return E_ARG_HI;
-
-    if (argt[1] != argt[0] || argt[2] != argt[0])
-	return E_ARG_TYPE;
-
-    switch (argt[0]) {
-    case CELL_TYPE:
-	{
-	    CELL *res = args[0];
-	    CELL *arg1 = args[1];
-	    CELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg1[i] % arg2[i];
-	    }
-	    return 0;
-	}
-    case FCELL_TYPE:
-	{
-	    FCELL *res = args[0];
-	    FCELL *arg1 = args[1];
-	    FCELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]))
-		    SET_NULL_F(&res[i]);
-		else {
-		    floating_point_exception = 0;
-		    res[i] = (FCELL) fmod(arg1[i], arg2[i]);
-		    if (floating_point_exception)
-			SET_NULL_F(&res[i]);
-		}
-	    }
-	    return 0;
-	}
-    case DCELL_TYPE:
-	{
-	    DCELL *res = args[0];
-	    DCELL *arg1 = args[1];
-	    DCELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]))
-		    SET_NULL_D(&res[i]);
-		else {
-		    floating_point_exception = 0;
-		    res[i] = (DCELL) fmod(arg1[i], arg2[i]);
-		    if (floating_point_exception)
-			SET_NULL_D(&res[i]);
-		}
-	    }
-	    return 0;
-	}
-    default:
-	return E_INV_TYPE;
-    }
-}

Deleted: grass/trunk/raster/r.mapcalc/xmode.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xmode.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xmode.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,144 +0,0 @@
-
-#include <stdlib.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/**********************************************************************
-mode(x1,x2,..,xn)
-   return mode of arguments
-**********************************************************************/
-
-static int dcmp(const void *aa, const void *bb)
-{
-    const double *a = aa;
-    const double *b = bb;
-
-    if (*a < *b)
-	return -1;
-    if (*a > *b)
-	return 1;
-    return 0;
-}
-
-static double mode(double *value, int argc)
-{
-    double mode_v;
-    int mode_n = 0;
-    int i;
-
-    qsort(value, argc, sizeof(double), dcmp);
-
-    for (i = 0; i < argc;) {
-	int n = 1;
-	double v = value[i];
-
-	for (i++; i < argc; i++) {
-	    if (value[i] != v)
-		break;
-	    n++;
-	}
-
-	if (n < mode_n)
-	    continue;
-
-	mode_v = v;
-	mode_n = n;
-    }
-
-    return mode_v;
-}
-
-int f_mode(int argc, const int *argt, void **args)
-{
-    static double *value;
-    static int value_size;
-    int size = argc * sizeof(double);
-    int i, j;
-
-    if (argc < 1)
-	return E_ARG_LO;
-
-    for (i = 1; i <= argc; i++)
-	if (argt[i] != argt[0])
-	    return E_ARG_TYPE;
-
-    if (size > value_size) {
-	value_size = size;
-	value = G_realloc(value, value_size);
-    }
-
-    switch (argt[argc]) {
-    case CELL_TYPE:
-	{
-	    CELL *res = args[0];
-	    CELL **argv = (CELL **) & args[1];
-
-	    for (i = 0; i < columns; i++) {
-		int nv = 0;
-
-		for (j = 0; j < argc && !nv; j++) {
-		    if (IS_NULL_C(&argv[j][i]))
-			nv = 1;
-		    else
-			value[j] = (double)argv[j][i];
-		}
-
-		if (nv)
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = (CELL) mode(value, argc);
-	    }
-	    return 0;
-	}
-    case FCELL_TYPE:
-	{
-	    FCELL *res = args[0];
-	    FCELL **argv = (FCELL **) & args[1];
-
-	    for (i = 0; i < columns; i++) {
-		int nv = 0;
-
-		for (j = 0; j < argc && !nv; j++) {
-		    if (IS_NULL_F(&argv[j][i]))
-			nv = 1;
-		    else
-			value[j] = (double)argv[j][i];
-		}
-
-		if (nv)
-		    SET_NULL_F(&res[i]);
-		else
-		    res[i] = (FCELL) mode(value, argc);
-	    }
-	    return 0;
-	}
-    case DCELL_TYPE:
-	{
-	    DCELL *res = args[0];
-	    DCELL **argv = (DCELL **) & args[1];
-
-	    for (i = 0; i < columns; i++) {
-		int nv = 0;
-
-		for (j = 0; j < argc && !nv; j++) {
-		    if (IS_NULL_D(&argv[j][i]))
-			nv = 1;
-		    else
-			value[j] = (double)argv[j][i];
-		}
-
-		if (nv)
-		    SET_NULL_D(&res[i]);
-		else
-		    res[i] = (DCELL) mode(value, argc);
-	    }
-	    return 0;
-	}
-    default:
-	return E_INV_TYPE;
-    }
-}

Deleted: grass/trunk/raster/r.mapcalc/xmul.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xmul.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xmul.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,78 +0,0 @@
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-mul(a,b) = a * b
-****************************************************************/
-
-int f_mul(int argc, const int *argt, void **args)
-{
-    int i, j;
-
-    if (argc < 1)
-	return E_ARG_LO;
-
-    for (i = 1; i <= argc; i++)
-	if (argt[i] != argt[0])
-	    return E_ARG_TYPE;
-
-    switch (argt[0]) {
-    case CELL_TYPE:
-	{
-	    CELL *res = args[0];
-	    CELL **argz = (CELL **) args;
-
-	    for (i = 0; i < columns; i++) {
-		res[i] = 1;
-		for (j = 1; j <= argc; j++) {
-		    if (IS_NULL_C(&argz[j][i])) {
-			SET_NULL_C(&res[i]);
-			break;
-		    }
-		    res[i] *= argz[j][i];
-		}
-	    }
-	    return 0;
-	}
-    case FCELL_TYPE:
-	{
-	    FCELL *res = args[0];
-	    FCELL **argz = (FCELL **) args;
-
-	    for (i = 0; i < columns; i++) {
-		res[i] = 1;
-		for (j = 1; j <= argc; j++) {
-		    if (IS_NULL_F(&argz[j][i])) {
-			SET_NULL_F(&res[i]);
-			break;
-		    }
-		    res[i] *= argz[j][i];
-		}
-	    }
-	    return 0;
-	}
-    case DCELL_TYPE:
-	{
-	    DCELL *res = args[0];
-	    DCELL **argz = (DCELL **) args;
-
-	    for (i = 0; i < columns; i++) {
-		res[i] = 1;
-		for (j = 1; j <= argc; j++) {
-		    if (IS_NULL_D(&argz[j][i])) {
-			SET_NULL_D(&res[i]);
-			break;
-		    }
-		    res[i] *= argz[j][i];
-		}
-	    }
-	    return 0;
-	}
-    default:
-	return E_INV_TYPE;
-    }
-}

Deleted: grass/trunk/raster/r.mapcalc/xne.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xne.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xne.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,65 +0,0 @@
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-ne(a,b) = a != b
-****************************************************************/
-
-int f_ne(int argc, const int *argt, void **args)
-{
-    CELL *res = args[0];
-    int i;
-
-    if (argc < 2)
-	return E_ARG_LO;
-    if (argc > 2)
-	return E_ARG_HI;
-
-    switch (argt[1]) {
-    case CELL_TYPE:
-	{
-	    CELL *arg1 = args[1];
-	    CELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg1[i] != arg2[i];
-	    }
-	    return 0;
-	}
-    case FCELL_TYPE:
-	{
-	    FCELL *arg1 = args[1];
-	    FCELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg1[i] != arg2[i];
-	    }
-	    return 0;
-	}
-    case DCELL_TYPE:
-	{
-	    DCELL *arg1 = args[1];
-	    DCELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg1[i] != arg2[i];
-	    }
-	    return 0;
-	}
-    default:
-	return E_INV_TYPE;
-    }
-}

Deleted: grass/trunk/raster/r.mapcalc/xneg.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xneg.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xneg.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,64 +0,0 @@
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/**********************************************************************
-neg(x) = -x
-**********************************************************************/
-
-int f_neg(int argc, const int *argt, void **args)
-{
-    int i;
-
-    if (argc < 1)
-	return E_ARG_LO;
-    if (argc > 1)
-	return E_ARG_HI;
-
-    if (argt[0] != argt[1])
-	return E_RES_TYPE;
-
-    switch (argt[1]) {
-    case CELL_TYPE:
-	{
-	    CELL *res = args[0];
-	    CELL *arg1 = args[1];
-
-	    for (i = 0; i < columns; i++)
-		if (IS_NULL_C(&arg1[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = -arg1[i];
-	    return 0;
-	}
-    case FCELL_TYPE:
-	{
-	    FCELL *res = args[0];
-	    FCELL *arg1 = args[1];
-
-	    for (i = 0; i < columns; i++)
-		if (IS_NULL_F(&arg1[i]))
-		    SET_NULL_F(&res[i]);
-		else
-		    res[i] = -arg1[i];
-	    return 0;
-	}
-    case DCELL_TYPE:
-	{
-	    DCELL *res = args[0];
-	    DCELL *arg1 = args[1];
-
-	    for (i = 0; i < columns; i++)
-		if (IS_NULL_D(&arg1[i]))
-		    SET_NULL_D(&res[i]);
-		else
-		    res[i] = -arg1[i];
-	    return 0;
-	}
-    default:
-	return E_INV_TYPE;
-    }
-}

Deleted: grass/trunk/raster/r.mapcalc/xnmax.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xnmax.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xnmax.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,100 +0,0 @@
-
-#include <stdlib.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-max(x0,x1,...,xn) returns maximum value
-****************************************************************/
-
-int f_nmax(int argc, const int *argt, void **args)
-{
-    int i, j;
-
-    if (argc < 1)
-	return E_ARG_LO;
-
-    for (i = 1; i <= argc; i++)
-	if (argt[i] != argt[0])
-	    return E_ARG_TYPE;
-
-    switch (argt[0]) {
-    case CELL_TYPE:
-	{
-	    CELL *res = args[0];
-	    CELL **argz = (CELL **) args;
-
-	    for (i = 0; i < columns; i++) {
-		int nul = 1;
-		CELL max;
-
-		for (j = 1; j <= argc; j++)
-		    if (IS_NULL_C(&argz[j][i]))
-			continue;
-		    else if (nul)
-			max = argz[j][i], nul = 0;
-		    else if (max < argz[j][i])
-			max = argz[j][i], nul = 0;
-		if (nul)
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = max;
-	    }
-	    return 0;
-	}
-    case FCELL_TYPE:
-	{
-	    FCELL *res = args[0];
-	    FCELL **argz = (FCELL **) args;
-
-	    for (i = 0; i < columns; i++) {
-		int nul = 1;
-		FCELL max;
-
-		for (j = 1; j <= argc; j++)
-		    if (IS_NULL_F(&argz[j][i]))
-			continue;
-		    else if (nul)
-			max = argz[j][i], nul = 0;
-		    else if (max < argz[j][i])
-			max = argz[j][i], nul = 0;
-		if (nul)
-		    SET_NULL_F(&res[i]);
-		else
-		    res[i] = max;
-	    }
-
-	    return 0;
-	}
-    case DCELL_TYPE:
-	{
-	    DCELL *res = args[0];
-	    DCELL **argz = (DCELL **) args;
-
-	    for (i = 0; i < columns; i++) {
-		int nul = 1;
-		DCELL max;
-
-		for (j = 1; j <= argc; j++)
-		    if (IS_NULL_D(&argz[j][i]))
-			continue;
-		    else if (nul)
-			max = argz[j][i], nul = 0;
-		    else if (max < argz[j][i])
-			max = argz[j][i], nul = 0;
-		if (nul)
-		    SET_NULL_D(&res[i]);
-		else
-		    res[i] = max;
-	    }
-
-	    return 0;
-	}
-    default:
-	return E_INV_TYPE;
-    }
-}

Deleted: grass/trunk/raster/r.mapcalc/xnmedian.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xnmedian.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xnmedian.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,152 +0,0 @@
-
-#include <stdlib.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/**********************************************************************
-median(x1,x2,..,xn)
-   return median of arguments
-**********************************************************************/
-
-static int icmp(const void *aa, const void *bb)
-{
-    const CELL *a = aa;
-    const CELL *b = bb;
-
-    return *a - *b;
-}
-
-static int fcmp(const void *aa, const void *bb)
-{
-    const FCELL *a = aa;
-    const FCELL *b = bb;
-
-    if (*a < *b)
-	return -1;
-    if (*a > *b)
-	return 1;
-    return 0;
-}
-
-static int dcmp(const void *aa, const void *bb)
-{
-    const DCELL *a = aa;
-    const DCELL *b = bb;
-
-    if (*a < *b)
-	return -1;
-    if (*a > *b)
-	return 1;
-    return 0;
-}
-
-int f_nmedian(int argc, const int *argt, void **args)
-{
-    static void *array;
-    static int alloc;
-    int size = argc * Rast_cell_size(argt[0]);
-    int i, j;
-
-    if (argc < 1)
-	return E_ARG_LO;
-
-    for (i = 1; i <= argc; i++)
-	if (argt[i] != argt[0])
-	    return E_ARG_TYPE;
-
-    if (size > alloc) {
-	alloc = size;
-	array = G_realloc(array, size);
-    }
-
-    switch (argt[0]) {
-    case CELL_TYPE:
-	{
-	    CELL *res = args[0];
-	    CELL **argv = (CELL **) &args[1];
-	    CELL *a = array;
-	    CELL *a1 = &a[(argc - 1) / 2];
-	    CELL *a2 = &a[argc / 2];
-
-	    for (i = 0; i < columns; i++) {
-		int n = 0;
-
-		for (j = 0; j < argc; j++) {
-		    if (IS_NULL_C(&argv[j][i]))
-			continue;
-		    a[n++] = argv[j][i];
-		}
-
-		if (!n)
-		    SET_NULL_C(&res[i]);
-		else {
-		    qsort(a, n, sizeof(CELL), icmp);
-		    res[i] = (*a1 + *a2) / 2;
-		}
-	    }
-
-	    return 0;
-	}
-    case FCELL_TYPE:
-	{
-	    FCELL *res = args[0];
-	    FCELL **argv = (FCELL **) &args[1];
-	    FCELL *a = array;
-	    FCELL *a1 = &a[(argc - 1) / 2];
-	    FCELL *a2 = &a[argc / 2];
-
-	    for (i = 0; i < columns; i++) {
-		int n = 0;
-
-		for (j = 0; j < argc; j++) {
-		    if (IS_NULL_F(&argv[j][i]))
-			continue;
-		    a[n++] = argv[j][i];
-		}
-
-		if (!n)
-		    SET_NULL_F(&res[i]);
-		else {
-		    qsort(a, n, sizeof(FCELL), fcmp);
-		    res[i] = (*a1 + *a2) / 2;
-		}
-	    }
-
-	    return 0;
-	}
-    case DCELL_TYPE:
-	{
-	    DCELL *res = args[0];
-	    DCELL **argv = (DCELL **) &args[1];
-	    DCELL *a = array;
-	    DCELL *a1 = &a[(argc - 1) / 2];
-	    DCELL *a2 = &a[argc / 2];
-
-	    for (i = 0; i < columns; i++) {
-		int n = 0;
-
-		for (j = 0; j < argc; j++) {
-		    if (IS_NULL_D(&argv[j][i]))
-			continue;
-		    a[n++] = argv[j][i];
-		}
-
-		if (!n)
-		    SET_NULL_D(&res[i]);
-		else {
-		    qsort(a, n, sizeof(DCELL), dcmp);
-		    res[i] = (*a1 + *a2) / 2;
-		}
-	    }
-
-	    return 0;
-	}
-    default:
-	return E_INV_TYPE;
-    }
-}

Deleted: grass/trunk/raster/r.mapcalc/xnmin.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xnmin.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xnmin.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,100 +0,0 @@
-
-#include <stdlib.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-min(x0,x1,...,xn) returns minimum value
-****************************************************************/
-
-int f_nmin(int argc, const int *argt, void **args)
-{
-    int i, j;
-
-    if (argc < 1)
-	return E_ARG_LO;
-
-    for (i = 1; i <= argc; i++)
-	if (argt[i] != argt[0])
-	    return E_ARG_TYPE;
-
-    switch (argt[0]) {
-    case CELL_TYPE:
-	{
-	    CELL *res = args[0];
-	    CELL **argz = (CELL **) args;
-
-	    for (i = 0; i < columns; i++) {
-		int nul = 1;
-		CELL min;
-
-		for (j = 1; j <= argc; j++)
-		    if (IS_NULL_C(&argz[j][i]))
-			continue;
-		    else if (nul)
-			min = argz[j][i], nul = 0;
-		    else if (min > argz[j][i])
-			min = argz[j][i], nul = 0;
-		if (nul)
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = min;
-	    }
-	    return 0;
-	}
-    case FCELL_TYPE:
-	{
-	    FCELL *res = args[0];
-	    FCELL **argz = (FCELL **) args;
-
-	    for (i = 0; i < columns; i++) {
-		int nul = 1;
-		FCELL min;
-
-		for (j = 1; j <= argc; j++)
-		    if (IS_NULL_F(&argz[j][i]))
-			continue;
-		    else if (nul)
-			min = argz[j][i], nul = 0;
-		    else if (min > argz[j][i])
-			min = argz[j][i], nul = 0;
-		if (nul)
-		    SET_NULL_F(&res[i]);
-		else
-		    res[i] = min;
-	    }
-
-	    return 0;
-	}
-    case DCELL_TYPE:
-	{
-	    DCELL *res = args[0];
-	    DCELL **argz = (DCELL **) args;
-
-	    for (i = 0; i < columns; i++) {
-		int nul = 1;
-		DCELL min;
-
-		for (j = 1; j <= argc; j++)
-		    if (IS_NULL_D(&argz[j][i]))
-			continue;
-		    else if (nul)
-			min = argz[j][i], nul = 0;
-		    else if (min > argz[j][i])
-			min = argz[j][i], nul = 0;
-		if (nul)
-		    SET_NULL_D(&res[i]);
-		else
-		    res[i] = min;
-	    }
-
-	    return 0;
-	}
-    default:
-	return E_INV_TYPE;
-    }
-}

Deleted: grass/trunk/raster/r.mapcalc/xnmode.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xnmode.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xnmode.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,141 +0,0 @@
-
-#include <stdlib.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/**********************************************************************
-mode(x1,x2,..,xn)
-   return mode of arguments
-**********************************************************************/
-
-static int dcmp(const void *aa, const void *bb)
-{
-    const double *a = aa;
-    const double *b = bb;
-
-    if (*a < *b)
-	return -1;
-    if (*a > *b)
-	return 1;
-    return 0;
-}
-
-static double mode(double *value, int argc)
-{
-    double mode_v;
-    int mode_n = 0;
-    int i;
-
-    qsort(value, argc, sizeof(double), dcmp);
-
-    for (i = 0; i < argc;) {
-	int n = 1;
-	double v = value[i];
-
-	for (i++; i < argc; i++) {
-	    if (value[i] != v)
-		break;
-	    n++;
-	}
-
-	if (n < mode_n)
-	    continue;
-
-	mode_v = v;
-	mode_n = n;
-    }
-
-    return mode_v;
-}
-
-int f_nmode(int argc, const int *argt, void **args)
-{
-    static double *value;
-    static int value_size;
-    int size = argc * sizeof(double);
-    int i, j;
-
-    if (argc < 1)
-	return E_ARG_LO;
-
-    for (i = 1; i <= argc; i++)
-	if (argt[i] != argt[0])
-	    return E_ARG_TYPE;
-
-    if (size > value_size) {
-	value_size = size;
-	value = G_realloc(value, value_size);
-    }
-
-    switch (argt[argc]) {
-    case CELL_TYPE:
-	{
-	    CELL *res = args[0];
-	    CELL **argv = (CELL **) & args[1];
-
-	    for (i = 0; i < columns; i++) {
-		int n = 0;
-
-		for (j = 0; j < argc; j++) {
-		    if (IS_NULL_C(&argv[j][i]))
-			continue;
-		    value[n++] = (double)argv[j][i];
-		}
-
-		if (!n)
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = (CELL) mode(value, n);
-	    }
-	    return 0;
-	}
-    case FCELL_TYPE:
-	{
-	    FCELL *res = args[0];
-	    FCELL **argv = (FCELL **) & args[1];
-
-	    for (i = 0; i < columns; i++) {
-		int n = 0;
-
-		for (j = 0; j < argc; j++) {
-		    if (IS_NULL_F(&argv[j][i]))
-			continue;
-		    value[n++] = (double)argv[j][i];
-		}
-
-		if (!n)
-		    SET_NULL_F(&res[i]);
-		else
-		    res[i] = (FCELL) mode(value, n);
-	    }
-	    return 0;
-	}
-    case DCELL_TYPE:
-	{
-	    DCELL *res = args[0];
-	    DCELL **argv = (DCELL **) & args[1];
-
-	    for (i = 0; i < columns; i++) {
-		int n = 0;
-
-		for (j = 0; j < argc; j++) {
-		    if (IS_NULL_D(&argv[j][i]))
-			continue;
-		    value[n++] = (double)argv[j][i];
-		}
-
-		if (!n)
-		    SET_NULL_D(&res[i]);
-		else
-		    res[i] = (DCELL) mode(value, n);
-	    }
-	    return 0;
-	}
-    default:
-	return E_INV_TYPE;
-    }
-}

Deleted: grass/trunk/raster/r.mapcalc/xnot.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xnot.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xnot.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,52 +0,0 @@
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-not(a) = !a
-****************************************************************/
-
-int f_not(int argc, const int *argt, void **args)
-{
-    CELL *res = args[0];
-    CELL *arg1 = args[1];
-    int i;
-
-    if (argc < 1)
-	return E_ARG_LO;
-    if (argc > 1)
-	return E_ARG_HI;
-
-    if (argt[1] != CELL_TYPE)
-	return E_ARG_TYPE;
-
-    if (argt[0] != CELL_TYPE)
-	return E_RES_TYPE;
-
-    for (i = 0; i < columns; i++) {
-	if (IS_NULL_C(&arg1[i]))
-	    SET_NULL_C(&res[i]);
-	else
-	    res[i] = !arg1[i];
-    }
-
-    return 0;
-}
-
-int c_not(int argc, int *argt)
-{
-    if (argc < 1)
-	return E_ARG_LO;
-    if (argc > 1)
-	return E_ARG_HI;
-
-    if (argt[1] != CELL_TYPE)
-	return E_ARG_TYPE;
-
-    argt[0] = CELL_TYPE;
-
-    return 0;
-}

Deleted: grass/trunk/raster/r.mapcalc/xnull.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xnull.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xnull.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,27 +0,0 @@
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-null() null values
-****************************************************************/
-
-int f_null(int argc, const int *argt, void **args)
-{
-    CELL *res = args[0];
-    int i;
-
-    if (argc > 0)
-	return E_ARG_HI;
-
-    if (argt[0] != CELL_TYPE)
-	return E_RES_TYPE;
-
-    for (i = 0; i < columns; i++)
-	SET_NULL_C(&res[i]);
-
-    return 0;
-}

Deleted: grass/trunk/raster/r.mapcalc/xor.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xor.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xor.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,41 +0,0 @@
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-or(a,b,c,...) = a || b || c || ...
-****************************************************************/
-
-int f_or(int argc, const int *argt, void **args)
-{
-    CELL *res = args[0];
-    int i, j;
-
-    if (argc < 1)
-	return E_ARG_LO;
-
-    if (argt[0] != CELL_TYPE)
-	return E_RES_TYPE;
-
-    for (i = 1; i <= argc; i++)
-	if (argt[i] != argt[0])
-	    return E_ARG_TYPE;
-
-    for (i = 0; i < columns; i++) {
-	res[i] = 0;
-	for (j = 1; j <= argc; j++) {
-	    CELL *arg = args[j];
-	    if (IS_NULL_C(&arg[i])) {
-		SET_NULL_C(&res[i]);
-		break;
-	    }
-	    if (arg[i])
-		res[i] = 1;
-	}
-    }
-
-    return 0;
-}

Deleted: grass/trunk/raster/r.mapcalc/xor2.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xor2.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xor2.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,48 +0,0 @@
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-or2(a,b,c,...) = a || b || c || ...
-
-Differs from or() in that the boolean axioms:
-
-	true || x == true
-	x || true == true
-
-hold even when x is null.
-****************************************************************/
-
-int f_or2(int argc, const int *argt, void **args)
-{
-    CELL *res = args[0];
-    int i, j;
-
-    if (argc < 1)
-	return E_ARG_LO;
-
-    if (argt[0] != CELL_TYPE)
-	return E_RES_TYPE;
-
-    for (i = 1; i <= argc; i++)
-	if (argt[i] != argt[0])
-	    return E_ARG_TYPE;
-
-    for (i = 0; i < columns; i++) {
-	res[i] = 0;
-	for (j = 1; j <= argc; j++) {
-	    CELL *arg = args[j];
-	    if (!IS_NULL_C(&arg[i]) && arg[i]) {
-		res[i] = 1;
-		break;
-	    }
-	    if (IS_NULL_C(&arg[i]))
-		SET_NULL_C(&res[i]);
-	}
-    }
-
-    return 0;
-}

Deleted: grass/trunk/raster/r.mapcalc/xpow.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xpow.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xpow.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,98 +0,0 @@
-
-#include <math.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-pow(a,b)
-   a raised to the power b
-****************************************************************/
-
-static int ipow(int x, int y)
-{
-    int res = 1;
-
-    while (y) {
-	if (y & 1)
-	    res *= x;
-	y >>= 1;
-	x *= x;
-    }
-    return res;
-}
-
-int f_pow(int argc, const int *argt, void **args)
-{
-    int i;
-
-    if (argc < 2)
-	return E_ARG_LO;
-    if (argc > 2)
-	return E_ARG_HI;
-
-    if (argt[1] != argt[0] || argt[2] != argt[0])
-	return E_ARG_TYPE;
-
-    switch (argt[0]) {
-    case CELL_TYPE:
-	{
-	    CELL *res = args[0];
-	    CELL *arg1 = args[1];
-	    CELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]) || arg2[i] < 0)
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = ipow(arg1[i], arg2[i]);
-	    }
-	    return 0;
-	}
-    case FCELL_TYPE:
-	{
-	    FCELL *res = args[0];
-	    FCELL *arg1 = args[1];
-	    FCELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]))
-		    SET_NULL_F(&res[i]);
-		else if (arg1[i] < 0 && arg2[i] != ceil(arg2[i]))
-		    SET_NULL_F(&res[i]);
-		else {
-		    floating_point_exception = 0;
-		    res[i] = pow(arg1[i], arg2[i]);
-		    if (floating_point_exception)
-			SET_NULL_F(&res[i]);
-		}
-	    }
-	    return 0;
-	}
-    case DCELL_TYPE:
-	{
-	    DCELL *res = args[0];
-	    DCELL *arg1 = args[1];
-	    DCELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]))
-		    SET_NULL_D(&res[i]);
-		else if (arg1[i] < 0 && arg2[i] != ceil(arg2[i]))
-		    SET_NULL_D(&res[i]);
-		else {
-		    floating_point_exception = 0;
-		    res[i] = pow(arg1[i], arg2[i]);
-		    if (floating_point_exception)
-			SET_NULL_D(&res[i]);
-		}
-	    }
-	    return 0;
-	}
-    default:
-	return E_INV_TYPE;
-    }
-}

Deleted: grass/trunk/raster/r.mapcalc/xrand.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xrand.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xrand.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,91 +0,0 @@
-
-#include <stdlib.h>
-
-#include <grass/config.h>
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-rand(lo,hi) random values between a and b
-****************************************************************/
-
-int f_rand(int argc, const int *argt, void **args)
-{
-    int i;
-
-    if (argc < 2)
-	return E_ARG_LO;
-    if (argc > 2)
-	return E_ARG_HI;
-
-    switch (argt[0]) {
-    case CELL_TYPE:
-	{
-	    CELL *res = args[0];
-	    CELL *arg1 = args[1];
-	    CELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		unsigned int x = (unsigned int)G_mrand48();
-		int lo = arg1[i];
-		int hi = arg2[i];
-
-		if (lo > hi) {
-		    int tmp = lo;
-
-		    lo = hi;
-		    hi = tmp;
-		}
-		res[i] = (lo == hi) ? lo : lo + x % (unsigned int)(hi - lo);
-	    }
-	    return 0;
-	}
-    case FCELL_TYPE:
-	{
-	    FCELL *res = args[0];
-	    FCELL *arg1 = args[1];
-	    FCELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		double x = G_drand48();
-		FCELL lo = arg1[i];
-		FCELL hi = arg2[i];
-
-		if (lo > hi) {
-		    FCELL tmp = lo;
-
-		    lo = hi;
-		    hi = tmp;
-		}
-		res[i] = (FCELL) (lo + x * (hi - lo));
-	    }
-	    return 0;
-	}
-    case DCELL_TYPE:
-	{
-	    DCELL *res = args[0];
-	    DCELL *arg1 = args[1];
-	    DCELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		double x = G_drand48();
-		DCELL lo = arg1[i];
-		DCELL hi = arg2[i];
-
-		if (lo > hi) {
-		    DCELL tmp = lo;
-
-		    lo = hi;
-		    hi = tmp;
-		}
-		res[i] = lo + x * (hi - lo);
-	    }
-	    return 0;
-	}
-    default:
-	return E_INV_TYPE;
-    }
-}

Deleted: grass/trunk/raster/r.mapcalc/xround.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xround.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xround.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,205 +0,0 @@
-
-#include <limits.h>
-#include <math.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/**********************************************************************
-round(x, step, start)
-
-  rounds x to nearest value in the sequence
-    y[i] = i * step + start
-
-**********************************************************************/
-
-/* i_round(x) rounds x to nearest value, handles negative correctly */
-
-static double i_round(double x, double step, double start)
-{
-    x -= start;
-    x /= step;
-    x = floor(x + 0.5);
-    x *= step;
-    x += start;
-    return x;
-}
-
-/**********************************************************************/
-
-int f_round(int argc, const int *argt, void **args)
-{
-    const DCELL *arg1 = args[1];
-    int i;
-
-    if (argc < 1)
-	return E_ARG_LO;
-    if (argc > 3)
-	return E_ARG_HI;
-
-    if (argc == 1 && argt[0] != CELL_TYPE)
-	return E_RES_TYPE;
-    if (argt[1] != DCELL_TYPE)
-	return E_ARG_TYPE;
-    if (argc > 1 && argt[2] != DCELL_TYPE)
-	return E_ARG_TYPE;
-    if (argc > 2 && argt[3] != DCELL_TYPE)
-	return E_ARG_TYPE;
-
-    if (argc == 1) {
-	CELL *res = args[0];
-
-	for (i = 0; i < columns; i++) {
-	    if (IS_NULL_D(&arg1[i]))
-		SET_NULL_C(&res[i]);
-	    else {
-		DCELL x = i_round(arg1[i], 1.0, 0.0);
-		if (x > 2147483647.0 || x < -2147483647.0)
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = (CELL) x;
-	    }
-	}
-	return 0;
-    }
-    else if (argc == 2) {
-	const DCELL *arg2 = args[2];
-
-	switch (argt[0]) {
-        case CELL_TYPE:
-            {
-                CELL *res = args[0];
-    
-                for (i = 0; i < columns; i++) {
-                    if (IS_NULL_D(&arg1[i]))
-                        SET_NULL_C(&res[i]);
-                    else if (IS_NULL_D(&arg2[i]))
-                        SET_NULL_C(&res[i]);
-                    else {
-                        DCELL x = i_round(arg1[i], arg2[i], 0.0);
-                        if (x > 2147483647.0 || x < -2147483647.0)
-                            SET_NULL_C(&res[i]);
-                        else
-                            res[i] = (CELL) x;
-                    }
-                }
-                return 0;
-            }
-        case FCELL_TYPE:
-            {
-                FCELL *res = args[0];
-    
-                for (i = 0; i < columns; i++)
-                    if (IS_NULL_D(&arg1[i]))
-                        SET_NULL_F(&res[i]);
-                    else if (IS_NULL_D(&arg2[i]))
-                        SET_NULL_F(&res[i]);
-                    else
-                        res[i] = (FCELL) i_round(arg1[i], arg2[i], 0.0);
-                return 0;
-            }
-        case DCELL_TYPE:
-            {
-                DCELL *res = args[0];
-    
-                for (i = 0; i < columns; i++)
-                    if (IS_NULL_D(&arg1[i]))
-                        SET_NULL_D(&res[i]);
-                    else if (IS_NULL_D(&arg2[i]))
-                        SET_NULL_D(&res[i]);
-                    else
-                        res[i] = (DCELL) i_round(arg1[i], arg2[i], 0.0);
-                return 0;
-            }
-        default:
-            return E_INV_TYPE;
-        }
-    }
-    else if (argc == 3) {
-	const DCELL *arg2 = args[2];
-	const DCELL *arg3 = args[3];
-
-	switch (argt[0]) {
-        case CELL_TYPE:
-            {
-                CELL *res = args[0];
-    
-                for (i = 0; i < columns; i++) {
-                    if (IS_NULL_D(&arg1[i]))
-                        SET_NULL_C(&res[i]);
-                    else if (IS_NULL_D(&arg2[i]))
-                        SET_NULL_C(&res[i]);
-                    else if (IS_NULL_D(&arg3[i]))
-                        SET_NULL_C(&res[i]);
-                    else {
-                        DCELL x = i_round(arg1[i], arg2[i], arg3[i]);
-                        if (x > 2147483647.0 || x < -2147483647.0)
-                            SET_NULL_C(&res[i]);
-                        else
-                            res[i] = (CELL) x;
-                    }
-                }
-                return 0;
-            }
-        case FCELL_TYPE:
-            {
-                FCELL *res = args[0];
-    
-                for (i = 0; i < columns; i++)
-                    if (IS_NULL_D(&arg1[i]))
-                        SET_NULL_F(&res[i]);
-                    else if (IS_NULL_D(&arg2[i]))
-                        SET_NULL_F(&res[i]);
-                    else if (IS_NULL_D(&arg3[i]))
-                        SET_NULL_F(&res[i]);
-                    else
-                        res[i] = (FCELL) i_round(arg1[i], arg2[i], arg3[i]);
-                return 0;
-            }
-        case DCELL_TYPE:
-            {
-                DCELL *res = args[0];
-    
-                for (i = 0; i < columns; i++)
-                    if (IS_NULL_D(&arg1[i]))
-                        SET_NULL_D(&res[i]);
-                    else if (IS_NULL_D(&arg2[i]))
-                        SET_NULL_D(&res[i]);
-                    else if (IS_NULL_D(&arg3[i]))
-                        SET_NULL_D(&res[i]);
-                    else
-                        res[i] = (DCELL) i_round(arg1[i], arg2[i], arg3[i]);
-                return 0;
-            }
-        default:
-            return E_INV_TYPE;
-        }
-    }
-    else
-	return E_WTF;
-}
-
-int c_round(int argc, int *argt)
-{
-    if (argc < 1)
-	return E_ARG_LO;
-    if (argc > 3)
-	return E_ARG_HI;
-
-    argt[0] = CELL_TYPE;
-    if (argc > 1 && argt[0] < argt[2])
-	argt[0] = argt[2];
-    if (argc > 2 && argt[0] < argt[3])
-	argt[0] = argt[3];
-
-    argt[1] = DCELL_TYPE;
-    if (argc > 1)
-	argt[2] = DCELL_TYPE;
-    if (argc > 2)
-	argt[3] = DCELL_TYPE;
-
-    return 0;
-}

Deleted: grass/trunk/raster/r.mapcalc/xshiftl.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xshiftl.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xshiftl.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,38 +0,0 @@
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-shiftl(a,b) = a << b
-****************************************************************/
-
-int f_shiftl(int argc, const int *argt, void **args)
-{
-    CELL *res = args[0];
-    CELL *arg1 = args[1];
-    CELL *arg2 = args[2];
-    int i;
-
-    if (argc < 2)
-	return E_ARG_LO;
-    if (argc > 2)
-	return E_ARG_HI;
-
-    if (argt[1] != CELL_TYPE || argt[2] != CELL_TYPE)
-	return E_ARG_TYPE;
-
-    if (argt[0] != CELL_TYPE)
-	return E_RES_TYPE;
-
-    for (i = 0; i < columns; i++) {
-	if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]))
-	    SET_NULL_C(&res[i]);
-	else
-	    res[i] = arg1[i] << arg2[i];
-    }
-
-    return 0;
-}

Deleted: grass/trunk/raster/r.mapcalc/xshiftr.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xshiftr.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xshiftr.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,38 +0,0 @@
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-shiftr(a,b) = a >> b
-****************************************************************/
-
-int f_shiftr(int argc, const int *argt, void **args)
-{
-    CELL *res = args[0];
-    CELL *arg1 = args[1];
-    CELL *arg2 = args[2];
-    int i;
-
-    if (argc < 2)
-	return E_ARG_LO;
-    if (argc > 2)
-	return E_ARG_HI;
-
-    if (argt[1] != CELL_TYPE || argt[2] != CELL_TYPE)
-	return E_ARG_TYPE;
-
-    if (argt[0] != CELL_TYPE)
-	return E_RES_TYPE;
-
-    for (i = 0; i < columns; i++) {
-	if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]))
-	    SET_NULL_C(&res[i]);
-	else
-	    res[i] = arg1[i] >> arg2[i];
-    }
-
-    return 0;
-}

Deleted: grass/trunk/raster/r.mapcalc/xshiftru.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xshiftru.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xshiftru.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,38 +0,0 @@
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-shiftru(a,b) = (unsigned) a >> b
-****************************************************************/
-
-int f_shiftru(int argc, const int *argt, void **args)
-{
-    CELL *res = args[0];
-    CELL *arg1 = args[1];
-    CELL *arg2 = args[2];
-    int i;
-
-    if (argc < 2)
-	return E_ARG_LO;
-    if (argc > 2)
-	return E_ARG_HI;
-
-    if (argt[1] != CELL_TYPE || argt[2] != CELL_TYPE)
-	return E_ARG_TYPE;
-
-    if (argt[0] != CELL_TYPE)
-	return E_RES_TYPE;
-
-    for (i = 0; i < columns; i++) {
-	if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]))
-	    SET_NULL_C(&res[i]);
-	else
-	    res[i] = ((unsigned int)arg1[i]) >> arg2[i];
-    }
-
-    return 0;
-}

Deleted: grass/trunk/raster/r.mapcalc/xsin.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xsin.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xsin.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,49 +0,0 @@
-
-#include <math.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/**********************************************************************
-sin(x) 
-
-  if floating point exception occurs during the evaluation of sin(x)
-  the result is NULL
-
-  note: x is in degrees.
-**********************************************************************/
-
-#define DEGREES_TO_RADIANS (M_PI / 180.0)
-
-int f_sin(int argc, const int *argt, void **args)
-{
-    DCELL *res = args[0];
-    DCELL *arg1 = args[1];
-    int i;
-
-    if (argc < 1)
-	return E_ARG_LO;
-    if (argc > 1)
-	return E_ARG_HI;
-
-    if (argt[0] != DCELL_TYPE)
-	return E_RES_TYPE;
-
-    if (argt[1] != DCELL_TYPE)
-	return E_ARG_TYPE;
-
-    for (i = 0; i < columns; i++)
-	if (IS_NULL_D(&arg1[i]))
-	    SET_NULL_D(&res[i]);
-	else {
-	    floating_point_exception = 0;
-	    res[i] = sin(arg1[i] * DEGREES_TO_RADIANS);
-	    if (floating_point_exception)
-		SET_NULL_D(&res[i]);
-	}
-
-    return 0;
-}

Deleted: grass/trunk/raster/r.mapcalc/xsqrt.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xsqrt.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xsqrt.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,45 +0,0 @@
-
-#include <math.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/**********************************************************************
-sqrt(x) 
-
-  if floating point exception occurs during the evaluation of sqrt(x)
-  the result is NULL
-**********************************************************************/
-
-int f_sqrt(int argc, const int *argt, void **args)
-{
-    DCELL *res = args[0];
-    DCELL *arg1 = args[1];
-    int i;
-
-    if (argc < 1)
-	return E_ARG_LO;
-    if (argc > 1)
-	return E_ARG_HI;
-
-    if (argt[0] != DCELL_TYPE)
-	return E_RES_TYPE;
-
-    if (argt[1] != DCELL_TYPE)
-	return E_ARG_TYPE;
-
-    for (i = 0; i < columns; i++)
-	if (IS_NULL_D(&arg1[i]) || (arg1[i] < 0.0))
-	    SET_NULL_D(&res[i]);
-	else {
-	    floating_point_exception = 0;
-	    res[i] = sqrt(arg1[i]);
-	    if (floating_point_exception)
-		SET_NULL_D(&res[i]);
-	}
-
-    return 0;
-}

Deleted: grass/trunk/raster/r.mapcalc/xsub.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xsub.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xsub.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,70 +0,0 @@
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/****************************************************************
-sub(a,b) = a - b
-****************************************************************/
-
-int f_sub(int argc, const int *argt, void **args)
-{
-    int i;
-
-    if (argc < 2)
-	return E_ARG_LO;
-    if (argc > 2)
-	return E_ARG_HI;
-
-    if (argt[1] != argt[0] || argt[2] != argt[0])
-	return E_ARG_TYPE;
-
-    switch (argt[0]) {
-    case CELL_TYPE:
-	{
-	    CELL *res = args[0];
-	    CELL *arg1 = args[1];
-	    CELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_C(&arg1[i]) || IS_NULL_C(&arg2[i]))
-		    SET_NULL_C(&res[i]);
-		else
-		    res[i] = arg1[i] - arg2[i];
-	    }
-	    return 0;
-	}
-    case FCELL_TYPE:
-	{
-	    FCELL *res = args[0];
-	    FCELL *arg1 = args[1];
-	    FCELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]))
-		    SET_NULL_F(&res[i]);
-		else
-		    res[i] = arg1[i] - arg2[i];
-	    }
-	    return 0;
-	}
-    case DCELL_TYPE:
-	{
-	    DCELL *res = args[0];
-	    DCELL *arg1 = args[1];
-	    DCELL *arg2 = args[2];
-
-	    for (i = 0; i < columns; i++) {
-		if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]))
-		    SET_NULL_D(&res[i]);
-		else
-		    res[i] = arg1[i] - arg2[i];
-	    }
-	    return 0;
-	}
-    default:
-	return E_INV_TYPE;
-    }
-}

Deleted: grass/trunk/raster/r.mapcalc/xtan.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xtan.c	2016-01-25 09:27:55 UTC (rev 67657)
+++ grass/trunk/raster/r.mapcalc/xtan.c	2016-01-25 09:28:12 UTC (rev 67658)
@@ -1,50 +0,0 @@
-
-#include <stdlib.h>
-#include <math.h>
-
-#include <grass/gis.h>
-#include <grass/raster.h>
-#include "globals.h"
-#include "expression.h"
-#include "func_proto.h"
-
-/**********************************************************************
-tan(x) 
-
-  if floating point exception occurs during the evaluation of tan(x)
-  the result is NULL
-
-  note: x is in degrees.
-**********************************************************************/
-
-#define DEGREES_TO_RADIANS (M_PI / 180.0)
-
-int f_tan(int argc, const int *argt, void **args)
-{
-    DCELL *res = args[0];
-    DCELL *arg1 = args[1];
-    int i;
-
-    if (argc < 1)
-	return E_ARG_LO;
-    if (argc > 1)
-	return E_ARG_HI;
-
-    if (argt[0] != DCELL_TYPE)
-	return E_RES_TYPE;
-
-    if (argt[1] != DCELL_TYPE)
-	return E_ARG_TYPE;
-
-    for (i = 0; i < columns; i++)
-	if (IS_NULL_D(&arg1[i]))
-	    SET_NULL_D(&res[i]);
-	else {
-	    floating_point_exception = 0;
-	    res[i] = tan(arg1[i] * DEGREES_TO_RADIANS);
-	    if (floating_point_exception)
-		SET_NULL_D(&res[i]);
-	}
-
-    return 0;
-}



More information about the grass-commit mailing list