GRASS 8 Programmer's Manual
8.6.0dev(2026)-ddeab64dbf
Loading...
Searching...
No Matches
c_thresh.c
Go to the documentation of this file.
1
#include <math.h>
2
3
#include <
grass/gis.h
>
4
#include <
grass/raster.h
>
5
6
void
c_thresh
(
DCELL
*result,
DCELL
*values,
int
n,
const
void
*closure)
7
{
8
DCELL
thresh
,
threshx
;
9
double
tval
= *(
const
double
*)closure;
10
double
epsilon =
GRASS_EPSILON
;
11
int
i;
12
13
Rast_set_d_null_value
(&
thresh
, 1);
14
Rast_set_d_null_value
(&
threshx
, 1);
15
16
for
(i = 0; i < n; i++) {
17
/* already found */
18
if
(!
Rast_is_d_null_value
(&
threshx
))
19
continue
;
20
21
if
(
Rast_is_d_null_value
(&values[i]))
22
continue
;
23
24
G_debug
(2,
"values[%d] %f, tval %f"
, i, values[i],
tval
);
25
/* for GDD */
26
epsilon = 10.;
27
if
(
fabs
(
tval
- values[i]) < epsilon) {
28
thresh
= values[i];
29
threshx
= i + 1;
30
G_debug
(2,
"values[%d] %f, thresh %f, threshx %f, diff %f"
, i,
31
values[i],
thresh
,
threshx
,
tval
- values[i]);
32
}
33
}
34
35
if
(
Rast_is_d_null_value
(&
threshx
))
36
Rast_set_d_null_value
(result, 1);
37
else
38
*result =
threshx
;
39
}
AMI_STREAM
Definition
ami_stream.h:153
G_debug
int G_debug(int, const char *,...) __attribute__((format(printf
Rast_set_d_null_value
void Rast_set_d_null_value(DCELL *, int)
To set a number of DCELL raster values to NULL.
Definition
null_val.c:153
Rast_is_d_null_value
#define Rast_is_d_null_value(dcellVal)
Definition
defs/raster.h:417
c_thresh
stat_func c_thresh
gis.h
GRASS_EPSILON
#define GRASS_EPSILON
Definition
gis.h:178
DCELL
double DCELL
Definition
gis.h:635
raster.h
lib
stats
c_thresh.c
Generated on Sun Apr 5 2026 06:59:59 for GRASS 8 Programmer's Manual by
1.9.8