[GRASS-SVN] r72940 - in grass/trunk: include/defs lib/calc raster/r.mapcalc
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Jul 1 14:03:44 PDT 2018
Author: mmetz
Date: 2018-07-01 14:03:44 -0700 (Sun, 01 Jul 2018)
New Revision: 72940
Added:
grass/trunk/lib/calc/xceil.c
grass/trunk/lib/calc/xfloor.c
Modified:
grass/trunk/include/defs/calc.h
grass/trunk/lib/calc/function.c
grass/trunk/raster/r.mapcalc/r.mapcalc.html
grass/trunk/raster/r.mapcalc/r3.mapcalc.html
Log:
r.mapcalc: +ceil, +floor (fixes #769)
Modified: grass/trunk/include/defs/calc.h
===================================================================
--- grass/trunk/include/defs/calc.h 2018-06-30 06:37:42 UTC (rev 72939)
+++ grass/trunk/include/defs/calc.h 2018-07-01 21:03:44 UTC (rev 72940)
@@ -16,6 +16,8 @@
extern func_t f_neg;
extern func_t f_abs;
+extern func_t f_ceil;
+extern func_t f_floor;
extern args_t c_unop;
extern func_t f_gt;
Modified: grass/trunk/lib/calc/function.c
===================================================================
--- grass/trunk/lib/calc/function.c 2018-06-30 06:37:42 UTC (rev 72939)
+++ grass/trunk/lib/calc/function.c 2018-07-01 21:03:44 UTC (rev 72940)
@@ -11,6 +11,8 @@
{"neg", c_unop, f_neg},
{"abs", c_unop, f_abs},
+ {"ceil", c_unop, f_ceil},
+ {"floor", c_unop, f_floor},
{"gt", c_cmpop, f_gt},
{"ge", c_cmpop, f_ge},
Copied: grass/trunk/lib/calc/xceil.c (from rev 72867, grass/trunk/lib/calc/xabs.c)
===================================================================
--- grass/trunk/lib/calc/xceil.c (rev 0)
+++ grass/trunk/lib/calc/xceil.c 2018-07-01 21:03:44 UTC (rev 72940)
@@ -0,0 +1,66 @@
+
+#include <math.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/**********************************************************************
+ceil(x)
+
+ the smallest integral value that is not less than x
+**********************************************************************/
+
+int f_ceil(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] = (FCELL) ceil(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] = ceil(arg1[i]);
+ return 0;
+ }
+ default:
+ return E_INV_TYPE;
+ }
+}
Copied: grass/trunk/lib/calc/xfloor.c (from rev 72867, grass/trunk/lib/calc/xabs.c)
===================================================================
--- grass/trunk/lib/calc/xfloor.c (rev 0)
+++ grass/trunk/lib/calc/xfloor.c 2018-07-01 21:03:44 UTC (rev 72940)
@@ -0,0 +1,66 @@
+
+#include <math.h>
+
+#include <grass/gis.h>
+#include <grass/raster.h>
+#include <grass/calc.h>
+
+/**********************************************************************
+floor(x)
+
+ the largest integral value that is not greater than x
+**********************************************************************/
+
+int f_floor(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] = (FCELL) floor(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] = floor(arg1[i]);
+ return 0;
+ }
+ default:
+ return E_INV_TYPE;
+ }
+}
Modified: grass/trunk/raster/r.mapcalc/r.mapcalc.html
===================================================================
--- grass/trunk/raster/r.mapcalc/r.mapcalc.html 2018-06-30 06:37:42 UTC (rev 72939)
+++ grass/trunk/raster/r.mapcalc/r.mapcalc.html 2018-07-01 21:03:44 UTC (rev 72940)
@@ -333,6 +333,7 @@
asin(x) inverse sine of x (result is in degrees) F
atan(x) inverse tangent of x (result is in degrees) F
atan(x,y) inverse tangent of y/x (result is in degrees) F
+ceil(x) the smallest integral value not less than x *
cos(x) cosine of x (x is in degrees) F
double(x) convert x to double-precision floating point F
eval([x,y,...,]z) evaluate values of listed expr, pass results to z
@@ -339,6 +340,7 @@
exp(x) exponential function of x F
exp(x,y) x to the power y F
float(x) convert x to single-precision floating point F
+floor(x) the largest integral value not greater than x *
graph(x,x1,y1[x2,y2..]) convert the x to a y based on points in a graph F
graph2(x,x1[,x2,..],y1[,y2..])
alternative form of graph() F
Modified: grass/trunk/raster/r.mapcalc/r3.mapcalc.html
===================================================================
--- grass/trunk/raster/r.mapcalc/r3.mapcalc.html 2018-06-30 06:37:42 UTC (rev 72939)
+++ grass/trunk/raster/r.mapcalc/r3.mapcalc.html 2018-07-01 21:03:44 UTC (rev 72940)
@@ -201,6 +201,7 @@
asin(x) inverse sine of x (result is in degrees) F
atan(x) inverse tangent of x (result is in degrees) F
atan(x,y) inverse tangent of y/x (result is in degrees) F
+ceil(x) the smallest integral value not less than x *
cos(x) cosine of x (x is in degrees) F
double(x) convert x to double-precision floating point F
eval([x,y,...,]z) evaluate values of listed expr, pass results to z
@@ -207,6 +208,7 @@
exp(x) exponential function of x F
exp(x,y) x to the power y F
float(x) convert x to single-precision floating point F
+floor(x) the largest integral value not greater than x *
graph(x,x1,y1[x2,y2..]) convert the x to a y based on points in a graph F
graph2(x,x1[,x2,..],y1[,y2..])
alternative form of graph() F
More information about the grass-commit
mailing list