GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
c_skew.c
Go to the documentation of this file.
1 #include <math.h>
2 #include <grass/gis.h>
3 
4 void c_skew(DCELL * result, DCELL * values, int n, const void *closure)
5 {
6  DCELL sum, ave, sumsq, sumcb, sdev;
7  int count;
8  int i;
9 
10  sum = 0.0;
11  count = 0;
12 
13  for (i = 0; i < n; i++) {
14  if (G_is_d_null_value(&values[i]))
15  continue;
16 
17  sum += values[i];
18  count++;
19  }
20 
21  if (count == 0) {
22  G_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 (G_is_d_null_value(&values[i]))
34  continue;
35 
36  d = values[i] - ave;
37  sumsq += d * d;
38  sumcb += d * d * d;
39  }
40 
41  sdev = sqrt(sumsq / count);
42 
43  *result = sumcb / (count * sdev * sdev * sdev);
44 }
45 
46 void w_skew(DCELL * result, DCELL(*values)[2], int n, const void *closure)
47 {
48  DCELL sum, ave, sumsq, sumcb, sdev;
49  int count;
50  int i;
51 
52  sum = 0.0;
53  count = 0;
54 
55  for (i = 0; i < n; i++) {
56  if (G_is_d_null_value(&values[i][0]))
57  continue;
58 
59  sum += values[i][0] * values[i][1];
60  count += values[i][1];
61  }
62 
63  if (count == 0) {
64  G_set_d_null_value(result, 1);
65  return;
66  }
67 
68  ave = sum / count;
69 
70  sumsq = 0;
71 
72  for (i = 0; i < n; i++) {
73  DCELL d;
74 
75  if (G_is_d_null_value(&values[i][0]))
76  continue;
77 
78  d = values[i][0] - ave;
79  sumsq += d * d * values[i][1];
80  sumcb += d * d * d * values[i][1];
81  }
82 
83  sdev = sqrt(sumsq / count);
84 
85  *result = sumcb / (count * sdev * sdev * sdev);
86 }
void w_skew(DCELL *result, DCELL(*values)[2], int n, const void *closure)
Definition: c_skew.c:46
void G_set_d_null_value(DCELL *dcellVals, int numVals)
Definition: null_val.c:176
int count
void c_skew(DCELL *result, DCELL *values, int n, const void *closure)
Definition: c_skew.c:4
int G_is_d_null_value(const DCELL *dcellVal)
Returns 1 if dcell is NULL, 0 otherwise. This will test if the value dcell is a NaN. Same test as in G_is_f_null_value().
Definition: null_val.c:306
int n
Definition: dataquad.c:291