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