GRASS GIS 8 Programmer's Manual
8.2.2dev(2023)-3d2c704037
xmin.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_min
(
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
min
;
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
min = argz[j][i];
38
else
if
(min > argz[j][i])
39
min = argz[j][i];
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 = 0;
54
FCELL
min
;
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
min = argz[j][i];
61
else
if
(min > argz[j][i])
62
min = argz[j][i];
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 = 0;
78
DCELL
min
;
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
min = argz[j][i];
85
else
if
(min > argz[j][i])
86
min = argz[j][i];
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
}
CELL_TYPE
#define CELL_TYPE
Definition:
raster.h:11
SET_NULL_C
#define SET_NULL_C(x)
Definition:
calc.h:32
min
#define min(x, y)
Definition:
draw2.c:31
DCELL
double DCELL
Definition:
gis.h:614
IS_NULL_F
#define IS_NULL_F(x)
Definition:
calc.h:29
E_ARG_TYPE
Definition:
calc.h:14
IS_NULL_C
#define IS_NULL_C(x)
Definition:
calc.h:28
columns
int columns
Definition:
calc.c:12
raster.h
gis.h
DCELL_TYPE
#define DCELL_TYPE
Definition:
raster.h:13
f_min
int f_min(int argc, const int *argt, void **args)
Definition:
xmin.c:12
E_ARG_LO
Definition:
calc.h:12
FCELL
float FCELL
Definition:
gis.h:615
IS_NULL_D
#define IS_NULL_D(x)
Definition:
calc.h:30
CELL
int CELL
Definition:
gis.h:613
E_INV_TYPE
Definition:
calc.h:16
FCELL_TYPE
#define FCELL_TYPE
Definition:
raster.h:12
SET_NULL_F
#define SET_NULL_F(x)
Definition:
calc.h:33
SET_NULL_D
#define SET_NULL_D(x)
Definition:
calc.h:34
calc.h
lib
calc
xmin.c
Generated on Tue Feb 14 2023 05:56:02 for GRASS GIS 8 Programmer's Manual by
1.8.13