GRASS Programmer's Manual
6.4.2(2012)
|
00001 #include <grass/gis.h> 00002 #include <math.h> 00003 00004 void c_thresh(DCELL * result, DCELL * values, int n, const void *closure) 00005 { 00006 DCELL thresh, threshx; 00007 double tval = *(const double *)closure; 00008 double epsilon = GRASS_EPSILON; 00009 int i; 00010 00011 G_set_d_null_value(&thresh, 1); 00012 G_set_d_null_value(&threshx, 1); 00013 00014 for (i = 0; i < n; i++) { 00015 /* already found */ 00016 if (! G_is_d_null_value(&threshx)) 00017 continue; 00018 00019 if (G_is_d_null_value(&values[i])) 00020 continue; 00021 00022 G_debug(2, "values[%d] %f, tval %f", i, values[i], tval); 00023 /* for GDD */ 00024 epsilon = 10.; 00025 if (fabs(tval - values[i]) < epsilon ) { 00026 thresh = values[i]; 00027 threshx = i + 1; 00028 G_debug(2, "values[%d] %f, thresh %f, threshx %f, diff %f", i, values[i], thresh, threshx, tval - values[i]); 00029 } 00030 } 00031 00032 if (G_is_d_null_value(&threshx)) 00033 G_set_d_null_value(result, 1); 00034 else 00035 *result = threshx; 00036 }