GRASS GIS 7 Programmer's Manual  7.9.dev(2021)-e5379bbd7
xnmin.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 min(x0,x1,...,xn) returns minimum value
10 ****************************************************************/
11 
12 int f_nmin(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 = 1;
31  CELL min;
32 
33  for (j = 1; j <= argc; j++)
34  if (IS_NULL_C(&argz[j][i]))
35  continue;
36  else if (nul)
37  min = argz[j][i], nul = 0;
38  else if (min > argz[j][i])
39  min = argz[j][i], nul = 0;
40  if (nul)
41  SET_NULL_C(&res[i]);
42  else
43  res[i] = min;
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 = 1;
54  FCELL min;
55 
56  for (j = 1; j <= argc; j++)
57  if (IS_NULL_F(&argz[j][i]))
58  continue;
59  else if (nul)
60  min = argz[j][i], nul = 0;
61  else if (min > argz[j][i])
62  min = argz[j][i], nul = 0;
63  if (nul)
64  SET_NULL_F(&res[i]);
65  else
66  res[i] = min;
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 = 1;
78  DCELL min;
79 
80  for (j = 1; j <= argc; j++)
81  if (IS_NULL_D(&argz[j][i]))
82  continue;
83  else if (nul)
84  min = argz[j][i], nul = 0;
85  else if (min > argz[j][i])
86  min = argz[j][i], nul = 0;
87  if (nul)
88  SET_NULL_D(&res[i]);
89  else
90  res[i] = min;
91  }
92 
93  return 0;
94  }
95  default:
96  return E_INV_TYPE;
97  }
98 }
#define CELL_TYPE
Definition: raster.h:11
#define SET_NULL_C(x)
Definition: calc.h:32
#define min(x, y)
Definition: draw2.c:31
double DCELL
Definition: gis.h:603
#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_nmin(int argc, const int *argt, void **args)
Definition: xnmin.c:12
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