GRASS GIS 7 Programmer's Manual  7.5.svn(2017)-r71942
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
c_skew.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_skew(DCELL * result, DCELL * values, int n, const void *closure)
7 {
8  DCELL sum, ave, sumsq, sumcb, sdev;
9  int count;
10  int i;
11 
12  sum = 0.0;
13  count = 0;
14 
15  for (i = 0; i < n; i++) {
16  if (Rast_is_d_null_value(&values[i]))
17  continue;
18 
19  sum += values[i];
20  count++;
21  }
22 
23  if (count == 0) {
24  Rast_set_d_null_value(result, 1);
25  return;
26  }
27 
28  ave = sum / count;
29 
30  sumsq = 0;
31 
32  for (i = 0; i < n; i++) {
33  DCELL d;
34 
35  if (Rast_is_d_null_value(&values[i]))
36  continue;
37 
38  d = values[i] - ave;
39  sumsq += d * d;
40  sumcb += d * d * d;
41  }
42 
43  sdev = sqrt(sumsq / count);
44 
45  *result = sumcb / (count * sdev * sdev * sdev);
46 }
47 
48 void w_skew(DCELL * result, DCELL(*values)[2], int n, const void *closure)
49 {
50  DCELL sum, ave, sumsq, sumcb, sdev;
51  int count;
52  int i;
53 
54  sum = 0.0;
55  count = 0;
56 
57  for (i = 0; i < n; i++) {
58  if (Rast_is_d_null_value(&values[i][0]))
59  continue;
60 
61  sum += values[i][0] * values[i][1];
62  count += values[i][1];
63  }
64 
65  if (count == 0) {
66  Rast_set_d_null_value(result, 1);
67  return;
68  }
69 
70  ave = sum / count;
71 
72  sumsq = 0;
73 
74  for (i = 0; i < n; i++) {
75  DCELL d;
76 
77  if (Rast_is_d_null_value(&values[i][0]))
78  continue;
79 
80  d = values[i][0] - ave;
81  sumsq += d * d * values[i][1];
82  sumcb += d * d * d * values[i][1];
83  }
84 
85  sdev = sqrt(sumsq / count);
86 
87  *result = sumcb / (count * sdev * sdev * sdev);
88 }
void w_skew(DCELL *result, DCELL(*values)[2], int n, const void *closure)
Definition: c_skew.c:48
double DCELL
Definition: gis.h:581
int count
void c_skew(DCELL *result, DCELL *values, int n, const void *closure)
Definition: c_skew.c:6
void Rast_set_d_null_value(DCELL *dcellVals, int numVals)
To set a number of DCELL raster values to NULL.
Definition: null_val.c:155
int Rast_is_d_null_value(const DCELL *dcellVal)
To check if a DCELL raster value is set to NULL.
Definition: null_val.c:261