GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
xor2.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 or2(a,b,c,...) = a || b || c || ...
8 
9 Differs from or() in that the boolean axioms:
10 
11  true || x == true
12  x || true == true
13 
14 hold even when x is null.
15 ****************************************************************/
16 
17 int f_or2(int argc, const int *argt, void **args)
18 {
19  CELL *res = args[0];
20  int i, j;
21 
22  if (argc < 1)
23  return E_ARG_LO;
24 
25  if (argt[0] != CELL_TYPE)
26  return E_RES_TYPE;
27 
28  for (i = 1; i <= argc; i++)
29  if (argt[i] != argt[0])
30  return E_ARG_TYPE;
31 
32  for (i = 0; i < columns; i++) {
33  res[i] = 0;
34  for (j = 1; j <= argc; j++) {
35  CELL *arg = args[j];
36  if (!IS_NULL_C(&arg[i]) && arg[i]) {
37  res[i] = 1;
38  break;
39  }
40  if (IS_NULL_C(&arg[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_or2(int argc, const int *argt, void **args)
Definition: xor2.c:17
Definition: calc.h:12
int CELL
Definition: gis.h:602