[GRASS-SVN] r39723 - grass/trunk/raster/r.watershed/ram

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Nov 14 06:08:42 EST 2009


Author: mmetz
Date: 2009-11-14 06:08:42 -0500 (Sat, 14 Nov 2009)
New Revision: 39723

Modified:
   grass/trunk/raster/r.watershed/ram/def_basin.c
   grass/trunk/raster/r.watershed/ram/find_pour.c
   grass/trunk/raster/r.watershed/ram/no_stream.c
   grass/trunk/raster/r.watershed/ram/over_cells.c
   grass/trunk/raster/r.watershed/ram/split_str.c
Log:
fix for interactive mode

Modified: grass/trunk/raster/r.watershed/ram/def_basin.c
===================================================================
--- grass/trunk/raster/r.watershed/ram/def_basin.c	2009-11-14 11:07:45 UTC (rev 39722)
+++ grass/trunk/raster/r.watershed/ram/def_basin.c	2009-11-14 11:08:42 UTC (rev 39723)
@@ -9,10 +9,7 @@
 
     for (;;) {
 	bas[SEG_INDEX(bas_seg, row, col)] = basin_num;
-	asp_value = asp[SEG_INDEX(asp_seg, row, col)];
 	FLAG_SET(swale, row, col);
-	if (asp_value < 0)
-	    asp_value = -asp_value;
 	ct = 0;
 	for (r = row - 1, rr = 0; rr < 3; r++, rr++) {
 	    for (c = col - 1, cc = 0; cc < 3; c++, cc++) {
@@ -81,6 +78,10 @@
 	}
 	else {			/* sides == 4 */
 
+	    asp_value = asp[SEG_INDEX(asp_seg, row, col)];
+	    if (asp_value < 0)
+		asp_value = -asp_value;
+
 	    if (asp_value == 2 || asp_value == 6) {
 		if (new_r[1] != row)
 		    stream_length += window.ns_res;

Modified: grass/trunk/raster/r.watershed/ram/find_pour.c
===================================================================
--- grass/trunk/raster/r.watershed/ram/find_pour.c	2009-11-14 11:07:45 UTC (rev 39722)
+++ grass/trunk/raster/r.watershed/ram/find_pour.c	2009-11-14 11:08:42 UTC (rev 39723)
@@ -7,6 +7,7 @@
     CELL old_elev, basin_num;
 
     basin_num = 0;
+    stream_length = old_elev = 0;
     for (row = 0; row < nrows; row++) {
 	G_percent(row, nrows, 1);
 	northing = window.north - (row + .5) * window.ns_res;
@@ -18,17 +19,17 @@
 		    easting = window.west + (col + .5) * window.ew_res;
 		    fprintf(fp, "%5d drains into %5d at %3d %3d %.3f %.3f",
 			    (int)basin_num, 0, row, col, easting, northing);
+		    if (col == 0 || col == ncols - 1) {
+			stream_length = .5 * window.ew_res;
+		    }
+		    else if (row == 0 || row == nrows - 1) {
+			stream_length = .5 * window.ns_res;
+		    }
+		    else {
+			stream_length = 0.0;
+		    }
+		    old_elev = alt[SEG_INDEX(alt_seg, row, col)];
 		}
-		if (col == 0 || col == ncols - 1) {
-		    stream_length = .5 * window.ew_res;
-		}
-		else if (row == 0 || row == nrows - 1) {
-		    stream_length = .5 * window.ns_res;
-		}
-		else {
-		    stream_length = 0.0;
-		}
-		old_elev = alt[SEG_INDEX(alt_seg, row, col)];
 		basin_num =
 		    def_basin(row, col, basin_num, stream_length, old_elev);
 	    }

Modified: grass/trunk/raster/r.watershed/ram/no_stream.c
===================================================================
--- grass/trunk/raster/r.watershed/ram/no_stream.c	2009-11-14 11:07:45 UTC (rev 39722)
+++ grass/trunk/raster/r.watershed/ram/no_stream.c	2009-11-14 11:08:42 UTC (rev 39723)
@@ -19,7 +19,7 @@
 			dvalue = wat[SEG_INDEX(wat_seg, r, c)];
 			if (dvalue < 0)
 			    dvalue = -dvalue;
-			if ((dvalue - max_drain) > 5E-8f) {	/* floating point comparison problem workaround */
+			if (dvalue > max_drain) {
 			    uprow = r;
 			    upcol = c;
 			    max_drain = dvalue;

Modified: grass/trunk/raster/r.watershed/ram/over_cells.c
===================================================================
--- grass/trunk/raster/r.watershed/ram/over_cells.c	2009-11-14 11:07:45 UTC (rev 39722)
+++ grass/trunk/raster/r.watershed/ram/over_cells.c	2009-11-14 11:08:42 UTC (rev 39723)
@@ -15,25 +15,21 @@
 	    if (r >= 0 && c >= 0 && r < nrows && c < ncols) {
 		value = asp[SEG_INDEX(asp_seg, r, c)];
 		if (value == drain[rr][cc]) {
-		    if (r != row && c != col) {
-			overland_cells(r, c, basin_num, haf_num, &new_ele);
-		    }
-		    else if (r != row) {
-			overland_cells(r, c, basin_num, haf_num, &new_ele);
-		    }
-		    else {
-			overland_cells(r, c, basin_num, haf_num, &new_ele);
-		    }
+		    overland_cells(r, c, basin_num, haf_num, &new_ele);
 		}
 	    }
 	}
     }
-    if (new_max_ele == BIGNEG) {
-	*hih_ele = alt[SEG_INDEX(alt_seg, row, col)];
+    /*
+    if (arm_flag) {
+	if (new_max_ele == BIGNEG) {
+	    *hih_ele = alt[SEG_INDEX(alt_seg, row, col)];
+	}
+	else {
+	    *hih_ele = new_max_ele;
+	}
     }
-    else {
-	*hih_ele = new_max_ele;
-    }
+    */
 
     return 0;
 }

Modified: grass/trunk/raster/r.watershed/ram/split_str.c
===================================================================
--- grass/trunk/raster/r.watershed/ram/split_str.c	2009-11-14 11:07:45 UTC (rev 39722)
+++ grass/trunk/raster/r.watershed/ram/split_str.c	2009-11-14 11:08:42 UTC (rev 39723)
@@ -10,6 +10,8 @@
     SHORT thisdir, leftflag, riteflag;
     int r, c, rr, cc;
 
+    new_elev = 0;
+
     for (ctr = 1; ctr <= ct; ctr++)
 	splitdir[ctr] = drain[row - new_r[ctr] + 1][col - new_c[ctr] + 1];
     updir = splitdir[1];
@@ -57,16 +59,17 @@
 	haf[SEG_INDEX(haf_seg, row, col)] = basin_num;
     }
     old_basin = basin_num;
-    new_elev = alt[SEG_INDEX(alt_seg, row, col)];
-    if ((slope = (new_elev - old_elev) / stream_length) < MIN_SLOPE)
-	slope = MIN_SLOPE;
-    if (arm_flag)
+    if (arm_flag) {
+	new_elev = alt[SEG_INDEX(alt_seg, row, col)];
+	if ((slope = (new_elev - old_elev) / stream_length) < MIN_SLOPE)
+	    slope = MIN_SLOPE;
 	fprintf(fp, " %f %f\n", slope, stream_length);
+    }
     for (r = 1; r <= ct; r++) {
 	basin_num += 2;
-	easting = window.west + (new_c[r] + .5) * window.ew_res;
-	northing = window.north - (new_r[r] + .5) * window.ns_res;
 	if (arm_flag) {
+	    easting = window.west + (new_c[r] + .5) * window.ew_res;
+	    northing = window.north - (new_r[r] + .5) * window.ns_res;
 	    fprintf(fp, "%5d drains into %5d at %3d %3d %.3f %.3f",
 		    (int)basin_num, old_basin, new_r[r], new_c[r], easting,
 		    northing);



More information about the grass-commit mailing list