GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator 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 }
void G_set_d_null_value(DCELL *dcellVals, int numVals)
Definition: null_val.c:176
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 G_debug(int level, const char *msg,...)
Print debugging message.
Definition: gis/debug.c:51
void c_thresh(DCELL *result, DCELL *values, int n, const void *closure)
Definition: c_thresh.c:4
int n
Definition: dataquad.c:291