GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
xand2.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 and2(a,b,c,...) = a && b && c && ...
8 
9 Differs from and() in that the boolean axioms:
10 
11  false && x == false
12  x && false == false
13 
14 hold even when x is null.
15 ****************************************************************/
16 
17 int f_and2(int argc, const int *argt, void **args)
18 {
19  CELL *res = args[0];
20  CELL **argz = (CELL **) args;
21  int i, j;
22 
23  if (argc < 1)
24  return E_ARG_LO;
25 
26  if (argt[0] != CELL_TYPE)
27  return E_RES_TYPE;
28 
29  for (i = 1; i <= argc; i++)
30  if (argt[i] != CELL_TYPE)
31  return E_ARG_TYPE;
32 
33  for (i = 0; i < columns; i++) {
34  res[i] = 1;
35  for (j = 1; j <= argc; j++) {
36  if (!IS_NULL_C(&argz[j][i]) && !argz[j][i]) {
37  res[i] = 0;
38  break;
39  }
40  if (IS_NULL_C(&argz[j][i]))
41  SET_NULL_C(&res[i]);
42  }
43  }
44 
45  return 0;
46 }
#define CELL_TYPE
Definition: raster.h:11
#define SET_NULL_C(x)
Definition: calc.h:32
#define IS_NULL_C(x)
Definition: calc.h:28
int columns
Definition: calc.c:12
int f_and2(int argc, const int *argt, void **args)
Definition: xand2.c:17
Definition: calc.h:12
int CELL
Definition: gis.h:613