[GRASS-SVN] r42270 - grass-addons/raster/r.stream.stats

svn_grass at osgeo.org svn_grass at osgeo.org
Mon May 17 11:17:31 EDT 2010


Author: jarekj71
Date: 2010-05-17 11:17:31 -0400 (Mon, 17 May 2010)
New Revision: 42270

Modified:
   grass-addons/raster/r.stream.stats/global.h
   grass-addons/raster/r.stream.stats/stats.c
Log:
fixed overflow error and wrong values for Horton's coefs

Modified: grass-addons/raster/r.stream.stats/global.h
===================================================================
--- grass-addons/raster/r.stream.stats/global.h	2010-05-17 14:40:19 UTC (rev 42269)
+++ grass-addons/raster/r.stream.stats/global.h	2010-05-17 15:17:31 UTC (rev 42270)
@@ -76,7 +76,7 @@
 
 /* stats */
 int init_streams (void);
-int fill_basin (int r,int c);
+double fill_basin (int r,int c);
 int calculate_basins (void);
 int stats(void);
 int fifo_insert (POINT point);
@@ -97,7 +97,7 @@
 GLOBAL char *out_file;
 GLOBAL int hack; /* flags */
 
-GLOBAL float total_basins;
+GLOBAL double total_basins;
 
 
 GLOBAL CELL **dirs, **streams; /* matrix with input data*/

Modified: grass-addons/raster/r.stream.stats/stats.c
===================================================================
--- grass-addons/raster/r.stream.stats/stats.c	2010-05-17 14:40:19 UTC (rev 42269)
+++ grass-addons/raster/r.stream.stats/stats.c	2010-05-17 15:17:31 UTC (rev 42270)
@@ -177,13 +177,13 @@
 }
 
 
-int fill_basin(int r, int c)
+double fill_basin(int r, int c)
 {
     int nextr[9] = { 0, -1, -1, -1, 0, 1, 1, 1, 0 };
     int nextc[9] = { 0, 1, 0, -1, -1, -1, 0, 1, 1 };
 
     int i, j;
-    float area;
+    double area;
     POINT n_cell;
 
     tail = 0;
@@ -210,7 +210,6 @@
 	c = n_cell.c;
 
     }
-
     return area;
 }
 
@@ -377,16 +376,24 @@
 
 	ord_stats[i - 1].bifur_ratio =
 	    ord_stats[i - 1].stream_num / (float)ord_stats[i].stream_num;
-	ord_stats[i - 1].length_ratio =
-	    ord_stats[i - 1].avg_length / ord_stats[i].avg_length;
-	ord_stats[i - 1].area_ratio =
-	    ord_stats[i - 1].avg_area / ord_stats[i].avg_area;
+	
+	ord_stats[i-1].length_ratio =
+	    (i==1) ? 0 :
+	    ord_stats[i].avg_length / ord_stats[i-1].avg_length;
+	
+	ord_stats[i].area_ratio =
+			(i==1) ? 0 :
+	    ord_stats[i].avg_area / ord_stats[i-1].avg_area;
+	
 	ord_stats[i - 1].slope_ratio =
 	    ord_stats[i - 1].avg_slope / ord_stats[i].avg_slope;
+	
 	ord_stats[i - 1].gradient_ratio =
 	    ord_stats[i - 1].avg_gradient / ord_stats[i].avg_gradient;
+	
 	ord_stats[i].stream_frequency =
 	    ord_stats[i].stream_num / ord_stats[i].sum_area;
+	
 	ord_stats[i].drainage_density =
 	    ord_stats[i].sum_length / ord_stats[i].sum_area;
 
@@ -456,4 +463,5 @@
     stats_total.drainage_density =
 	stats_total.sum_length / stats_total.sum_area;
 
+return 0;
 }



More information about the grass-commit mailing list