GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
c_ave.c
Go to the documentation of this file.
1 #include <grass/gis.h>
2 
3 void c_ave(DCELL * result, DCELL * values, int n, const void *closure)
4 {
5  DCELL sum;
6  int count;
7  int i;
8 
9  sum = 0.0;
10  count = 0;
11 
12  for (i = 0; i < n; i++) {
13  if (G_is_d_null_value(&values[i]))
14  continue;
15 
16  sum += values[i];
17  count++;
18  }
19 
20  if (count == 0)
21  G_set_d_null_value(result, 1);
22  else
23  *result = sum / count;
24 }
25 
26 void w_ave(DCELL * result, DCELL(*values)[2], int n, const void *closure)
27 {
28  DCELL sum;
29  DCELL count;
30  int i;
31 
32  sum = 0.0;
33  count = 0.0;
34 
35  for (i = 0; i < n; i++) {
36  if (G_is_d_null_value(&values[i][0]))
37  continue;
38 
39  sum += values[i][0] * values[i][1];
40  count += values[i][1];
41  }
42 
43  if (count == 0)
44  G_set_d_null_value(result, 1);
45  else
46  *result = sum / count;
47 }
void G_set_d_null_value(DCELL *dcellVals, int numVals)
Definition: null_val.c:176
void w_ave(DCELL *result, DCELL(*values)[2], int n, const void *closure)
Definition: c_ave.c:26
int count
void c_ave(DCELL *result, DCELL *values, int n, const void *closure)
Definition: c_ave.c:3
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