GRASS 8 Programmer's Manual
8.6.0dev(2026)-1d1e47ad9d
Loading...
Searching...
No Matches
c_sum.c
Go to the documentation of this file.
1
#include <
grass/gis.h
>
2
#include <
grass/raster.h
>
3
4
void
c_sum
(
DCELL
*result,
DCELL
*values,
int
n,
const
void
*closure
UNUSED
)
5
{
6
DCELL
sum;
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
else
24
*result = sum;
25
}
26
27
void
w_sum
(
DCELL
*result,
DCELL
(*values)[2],
int
n,
const
void
*closure
UNUSED
)
28
{
29
DCELL
sum;
30
DCELL
count
;
31
int
i;
32
33
sum = 0.0;
34
count
= 0.0;
35
36
for
(i = 0; i < n; i++) {
37
if
(
Rast_is_d_null_value
(&values[i][0]))
38
continue
;
39
40
sum += values[i][0] * values[i][1];
41
count
+= values[i][1];
42
}
43
44
if
(
count
== 0)
45
Rast_set_d_null_value
(result, 1);
46
else
47
*result = sum;
48
}
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_sum
stat_func c_sum
w_sum
stat_func_w w_sum
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_sum.c
Generated on Fri Apr 3 2026 06:59:56 for GRASS 8 Programmer's Manual by
1.9.8