GRASS GIS 8 Programmer's Manual
8.5.0dev(2024)-38f5cf43d1
xnmax.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
max(x0,x1,...,xn) returns maximum value
9
****************************************************************/
10
11
int
f_nmax
(
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 = 1;
29
CELL
max
;
30
31
for
(j = 1; j <= argc; j++)
32
if
(
IS_NULL_C
(&argz[j][i]))
33
continue
;
34
else
if
(nul)
35
max
= argz[j][i], nul = 0;
36
else
if
(
max
< argz[j][i])
37
max
= argz[j][i], nul = 0;
38
if
(nul)
39
SET_NULL_C
(&res[i]);
40
else
41
res[i] =
max
;
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 = 1;
51
FCELL
max
;
52
53
for
(j = 1; j <= argc; j++)
54
if
(
IS_NULL_F
(&argz[j][i]))
55
continue
;
56
else
if
(nul)
57
max
= argz[j][i], nul = 0;
58
else
if
(
max
< argz[j][i])
59
max
= argz[j][i], nul = 0;
60
if
(nul)
61
SET_NULL_F
(&res[i]);
62
else
63
res[i] =
max
;
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 = 1;
74
DCELL
max
;
75
76
for
(j = 1; j <= argc; j++)
77
if
(
IS_NULL_D
(&argz[j][i]))
78
continue
;
79
else
if
(nul)
80
max
= argz[j][i], nul = 0;
81
else
if
(
max
< argz[j][i])
82
max
= argz[j][i], nul = 0;
83
if
(nul)
84
SET_NULL_D
(&res[i]);
85
else
86
res[i] =
max
;
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
max
#define max(x, y)
Definition:
draw2.c:30
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_nmax
int f_nmax(int argc, const int *argt, void **args)
Definition:
xnmax.c:11
lib
calc
xnmax.c
Generated on Mon Nov 25 2024 07:38:49 for GRASS GIS 8 Programmer's Manual by
1.9.1