GRASS GIS 8 Programmer's Manual 8.2.0(2022)-exported
xadd.c
Go to the documentation of this file.
1
2#include <grass/gis.h>
3#include <grass/raster.h>
4#include <grass/calc.h>
5
6/****************************************************************
7add(a,b,c,...) = a + b + c + ...
8****************************************************************/
9
10int f_add(int argc, const int *argt, void **args)
11{
12 int i, j;
13
14 if (argc < 1)
15 return E_ARG_LO;
16
17 for (i = 1; i <= argc; i++)
18 if (argt[i] != argt[0])
19 return E_ARG_TYPE;
20
21 switch (argt[0]) {
22 case CELL_TYPE:
23 {
24 CELL *res = args[0];
25 CELL **argz = (CELL **) args;
26
27 for (i = 0; i < columns; i++) {
28 res[i] = 0;
29 for (j = 1; j <= argc; j++) {
30 if (IS_NULL_C(&argz[j][i])) {
31 SET_NULL_C(&res[i]);
32 break;
33 }
34 res[i] += argz[j][i];
35 }
36 }
37 return 0;
38 }
39 case FCELL_TYPE:
40 {
41 FCELL *res = args[0];
42 FCELL **argz = (FCELL **) args;
43
44 for (i = 0; i < columns; i++) {
45 res[i] = 0;
46 for (j = 1; j <= argc; j++) {
47 if (IS_NULL_F(&argz[j][i])) {
48 SET_NULL_F(&res[i]);
49 break;
50 }
51 res[i] += argz[j][i];
52 }
53 }
54 return 0;
55 }
56 case DCELL_TYPE:
57 {
58 DCELL *res = args[0];
59 DCELL **argz = (DCELL **) args;
60
61 for (i = 0; i < columns; i++) {
62 res[i] = 0;
63 for (j = 1; j <= argc; j++) {
64 if (IS_NULL_D(&argz[j][i])) {
65 SET_NULL_D(&res[i]);
66 break;
67 }
68 res[i] += argz[j][i];
69 }
70 }
71 return 0;
72 }
73 default:
74 return E_INV_TYPE;
75 }
76}
int columns
Definition: calc.c:12
int f_add(int argc, const int *argt, void **args)
Definition: xadd.c:10