GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
xmax.c
Go to the documentation of this file.
1 
2 #include <stdlib.h>
3 
4 #include <grass/gis.h>
5 #include <grass/raster.h>
6 #include <grass/calc.h>
7 
8 /****************************************************************
9 max(x0,x1,...,xn) returns maximum value
10 ****************************************************************/
11 
12 int f_max(int argc, const int *argt, void **args)
13 {
14  int i, j;
15 
16  if (argc < 1)
17  return E_ARG_LO;
18 
19  for (i = 1; i <= argc; i++)
20  if (argt[i] != argt[0])
21  return E_ARG_TYPE;
22 
23  switch (argt[0]) {
24  case CELL_TYPE:
25  {
26  CELL *res = args[0];
27  CELL **argz = (CELL **) args;
28 
29  for (i = 0; i < columns; i++) {
30  int nul = 0;
31  CELL max;
32 
33  for (j = 1; j <= argc; j++)
34  if (IS_NULL_C(&argz[j][i]))
35  nul = 1;
36  else if (j == 1)
37  max = argz[j][i];
38  else if (max < argz[j][i])
39  max = argz[j][i];
40  if (nul)
41  SET_NULL_C(&res[i]);
42  else
43  res[i] = max;
44  }
45  return 0;
46  }
47  case FCELL_TYPE:
48  {
49  FCELL *res = args[0];
50  FCELL **argz = (FCELL **) args;
51 
52  for (i = 0; i < columns; i++) {
53  int nul = 0;
54  FCELL max;
55 
56  for (j = 1; j <= argc; j++)
57  if (IS_NULL_F(&argz[j][i]))
58  nul = 1;
59  else if (j == 1)
60  max = argz[j][i];
61  else if (max < argz[j][i])
62  max = argz[j][i];
63  if (nul)
64  SET_NULL_F(&res[i]);
65  else
66  res[i] = max;
67  }
68 
69  return 0;
70  }
71  case DCELL_TYPE:
72  {
73  DCELL *res = args[0];
74  DCELL **argz = (DCELL **) args;
75 
76  for (i = 0; i < columns; i++) {
77  int nul = 0;
78  DCELL max;
79 
80  for (j = 1; j <= argc; j++)
81  if (IS_NULL_D(&argz[j][i]))
82  nul = 1;
83  else if (j == 1)
84  max = argz[j][i];
85  else if (max < argz[j][i])
86  max = argz[j][i];
87  if (nul)
88  SET_NULL_D(&res[i]);
89  else
90  res[i] = max;
91  }
92 
93  return 0;
94  }
95  default:
96  return E_INV_TYPE;
97  }
98 }
#define CELL_TYPE
Definition: raster.h:11
int f_max(int argc, const int *argt, void **args)
Definition: xmax.c:12
#define SET_NULL_C(x)
Definition: calc.h:32
double DCELL
Definition: gis.h:603
#define IS_NULL_F(x)
Definition: calc.h:29
#define max(x, y)
Definition: draw2.c:32
#define IS_NULL_C(x)
Definition: calc.h:28
int columns
Definition: calc.c:12
#define DCELL_TYPE
Definition: raster.h:13
Definition: calc.h:12
float FCELL
Definition: gis.h:604
#define IS_NULL_D(x)
Definition: calc.h:30
int CELL
Definition: gis.h:602
#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