GRASS Programmer's Manual  6.4.3(2013)-r
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Macros Pages
c_thresh.c
Go to the documentation of this file.
1 #include <grass/gis.h>
2 #include <math.h>
3 
4 void c_thresh(DCELL * result, DCELL * values, int n, const void *closure)
5 {
6  DCELL thresh, threshx;
7  double tval = *(const double *)closure;
8  double epsilon = GRASS_EPSILON;
9  int i;
10 
11  G_set_d_null_value(&thresh, 1);
12  G_set_d_null_value(&threshx, 1);
13 
14  for (i = 0; i < n; i++) {
15  /* already found */
16  if (! G_is_d_null_value(&threshx))
17  continue;
18 
19  if (G_is_d_null_value(&values[i]))
20  continue;
21 
22  G_debug(2, "values[%d] %f, tval %f", i, values[i], tval);
23  /* for GDD */
24  epsilon = 10.;
25  if (fabs(tval - values[i]) < epsilon ) {
26  thresh = values[i];
27  threshx = i + 1;
28  G_debug(2, "values[%d] %f, thresh %f, threshx %f, diff %f", i, values[i], thresh, threshx, tval - values[i]);
29  }
30  }
31 
32  if (G_is_d_null_value(&threshx))
33  G_set_d_null_value(result, 1);
34  else
35  *result = threshx;
36 }