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