GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
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 /****************************************************************
7 add(a,b,c,...) = a + b + c + ...
8 ****************************************************************/
9 
10 int 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 }
#define CELL_TYPE
Definition: raster.h:11
#define SET_NULL_C(x)
Definition: calc.h:32
double DCELL
Definition: gis.h:614
#define IS_NULL_F(x)
Definition: calc.h:29
#define IS_NULL_C(x)
Definition: calc.h:28
int columns
Definition: calc.c:12
#define DCELL_TYPE
Definition: raster.h:13
int f_add(int argc, const int *argt, void **args)
Definition: xadd.c:10
Definition: calc.h:12
float FCELL
Definition: gis.h:615
#define IS_NULL_D(x)
Definition: calc.h:30
int CELL
Definition: gis.h:613
#define FCELL_TYPE
Definition: raster.h:12
#define SET_NULL_F(x)
Definition: calc.h:33
#define SET_NULL_D(x)
Definition: calc.h:34