GRASS 8 Programmer's Manual
8.6.0dev(2026)-5f4f7ad06c
Loading...
Searching...
No Matches
basic.c
Go to the documentation of this file.
1
#include <math.h>
2
3
#include <
grass/arraystats.h
>
4
#include <
grass/gis.h
>
5
6
/*provides basic univar stats */
7
void
AS_basic_stats
(
const
double
data[],
int
count,
struct
GASTATS
*stats)
8
{
9
int
i = 1;
10
double
sum = 0, sumsq = 0, sumabs = 0;
11
double
dev
= 0,
dev2
= 0;
12
13
stats->
count
=
count
;
14
stats->
min
= data[0];
15
stats->
max
= data[
count
- 1];
16
17
for
(i = 0; i <
count
; i++) {
18
sum += data[i];
19
sumabs +=
fabs
(data[i]);
20
sumsq += data[i] * data[i];
21
}
22
stats->
sum
= sum;
23
stats->
sumabs
= sumabs;
24
stats->
sumsq
= sumsq;
25
26
stats->
mean
= stats->
sum
/ stats->
count
;
27
stats->
meanabs
= stats->
sumabs
/ stats->
count
;
28
for
(i = 0; i <
count
; i++) {
29
dev2
=
dev2
+ (data[i] - stats->
mean
) * (data[i] - stats->
mean
);
30
dev
=
dev
+ (data[i] - stats->
mean
);
31
}
32
33
stats->
var
= (
dev2
- (
dev
*
dev
/ stats->
count
)) / stats->
count
;
34
stats->
stdev
=
sqrt
(stats->
var
);
35
36
return
;
37
}
38
39
void
AS_eqdrt
(
double
vectx
[],
double
vecty
[],
int
i1
,
int
i2
,
double
*a,
40
double
*
b
,
double
*c)
41
{
42
double
x1 =
vectx
[
i1
];
43
double
y1 =
vecty
[
i1
];
44
double
x2 =
vectx
[
i2
];
45
double
y2 =
vecty
[
i2
];
46
47
if
(
i1
== 0) {
48
x1 = 0.0;
49
y1 = 0.0;
50
}
51
else
{
52
x1 =
vectx
[
i1
];
53
y1 =
vecty
[
i1
];
54
}
55
56
*a = 0.0;
57
*
b
= 0.0;
58
*c = 0.0;
59
60
double
bn
= y1 - y2;
61
double
bd
= x1 - x2;
62
63
if
(
fabs
(
bd
) <
GRASS_EPSILON
) {
64
if
(
fabs
(
bn
) <
GRASS_EPSILON
) {
65
G_debug
(3,
"Points are equal\n"
);
66
}
67
else
{
68
*c = x1;
69
}
70
}
71
else
{
72
*
b
=
bn
/
bd
;
73
*a = y1 - *
b
* x1;
74
}
75
}
arraystats.h
AS_eqdrt
void AS_eqdrt(double vectx[], double vecty[], int i1, int i2, double *a, double *b, double *c)
Definition
basic.c:39
AS_basic_stats
void AS_basic_stats(const double data[], int count, struct GASTATS *stats)
Definition
basic.c:7
AMI_STREAM
Definition
ami_stream.h:153
G_debug
int G_debug(int, const char *,...) __attribute__((format(printf
gis.h
GRASS_EPSILON
#define GRASS_EPSILON
Definition
gis.h:178
count
int count
b
double b
Definition
r_raster.c:39
GASTATS
Definition
arraystats.h:11
GASTATS::sum
double sum
Definition
arraystats.h:15
GASTATS::mean
double mean
Definition
arraystats.h:18
GASTATS::sumabs
double sumabs
Definition
arraystats.h:17
GASTATS::max
double max
Definition
arraystats.h:14
GASTATS::meanabs
double meanabs
Definition
arraystats.h:19
GASTATS::stdev
double stdev
Definition
arraystats.h:21
GASTATS::var
double var
Definition
arraystats.h:20
GASTATS::min
double min
Definition
arraystats.h:13
GASTATS::count
double count
Definition
arraystats.h:12
GASTATS::sumsq
double sumsq
Definition
arraystats.h:16
lib
arraystats
basic.c
Generated on Sat Apr 4 2026 07:00:45 for GRASS 8 Programmer's Manual by
1.9.8