GRASS 8 Programmer's Manual
8.6.0dev(2026)-f6f2c534ea
Loading...
Searching...
No Matches
c_var.c
Go to the documentation of this file.
1
#include <
grass/gis.h
>
2
#include <
grass/raster.h
>
3
4
void
c_var
(
DCELL
*result,
DCELL
*values,
int
n,
const
void
*closure
UNUSED
)
5
{
6
DCELL
sum,
ave
, sumsq;
7
int
count
;
8
int
i;
9
10
sum = 0.0;
11
count
= 0;
12
13
for
(i = 0; i < n; i++) {
14
if
(
Rast_is_d_null_value
(&values[i]))
15
continue
;
16
17
sum += values[i];
18
count
++;
19
}
20
21
if
(
count
== 0) {
22
Rast_set_d_null_value
(result, 1);
23
return
;
24
}
25
26
ave
= sum /
count
;
27
28
sumsq = 0;
29
30
for
(i = 0; i < n; i++) {
31
DCELL
d;
32
33
if
(
Rast_is_d_null_value
(&values[i]))
34
continue
;
35
36
d = values[i] -
ave
;
37
sumsq += d * d;
38
}
39
40
*result = sumsq /
count
;
41
}
42
43
void
w_var
(
DCELL
*result,
DCELL
(*values)[2],
int
n,
const
void
*closure
UNUSED
)
44
{
45
DCELL
sum,
ave
, sumsq;
46
DCELL
count
;
47
int
i;
48
49
sum = 0.0;
50
count
= 0;
51
52
for
(i = 0; i < n; i++) {
53
if
(
Rast_is_d_null_value
(&values[i][0]))
54
continue
;
55
56
sum += values[i][0] * values[i][1];
57
count
+= values[i][1];
58
}
59
60
if
(
count
== 0) {
61
Rast_set_d_null_value
(result, 1);
62
return
;
63
}
64
65
ave
= sum /
count
;
66
67
sumsq = 0;
68
69
for
(i = 0; i < n; i++) {
70
DCELL
d;
71
72
if
(
Rast_is_d_null_value
(&values[i][0]))
73
continue
;
74
75
d = values[i][0] -
ave
;
76
sumsq += d * d * values[i][1];
77
}
78
79
*result = sumsq /
count
;
80
}
AMI_STREAM
Definition
ami_stream.h:153
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
w_var
stat_func_w w_var
c_var
stat_func c_var
gis.h
DCELL
double DCELL
Definition
gis.h:635
UNUSED
#define UNUSED
A macro for an attribute, if attached to a variable, indicating that the variable is not used.
Definition
gis.h:46
count
int count
raster.h
lib
stats
c_var.c
Generated on Sun Apr 12 2026 06:59:17 for GRASS 8 Programmer's Manual by
1.9.8