[GRASS-SVN] r57152 - grass-addons/grass7/raster/r.stream.extract

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jul 15 08:41:00 PDT 2013


Author: mmetz
Date: 2013-07-15 08:41:00 -0700 (Mon, 15 Jul 2013)
New Revision: 57152

Modified:
   grass-addons/grass7/raster/r.stream.extract/do_astar.c
   grass-addons/grass7/raster/r.stream.extract/dseg.c
   grass-addons/grass7/raster/r.stream.extract/streams.c
Log:
r.stream.extract: code clean-up, sync to r.watershed

Modified: grass-addons/grass7/raster/r.stream.extract/do_astar.c
===================================================================
--- grass-addons/grass7/raster/r.stream.extract/do_astar.c	2013-07-15 15:38:18 UTC (rev 57151)
+++ grass-addons/grass7/raster/r.stream.extract/do_astar.c	2013-07-15 15:41:00 UTC (rev 57152)
@@ -31,7 +31,7 @@
     double dx, dy, dist_to_nbr[8], ew_res, ns_res;
     double slope[8];
     struct Cell_head window;
-    int skip_me;
+    int skip_diag;
 
     count = 0;
 
@@ -79,7 +79,7 @@
 	    r_nbr = r + nextdr[ct_dir];
 	    c_nbr = c + nextdc[ct_dir];
 	    slope[ct_dir] = ele_nbr[ct_dir] = 0;
-	    skip_me = 0;
+	    skip_diag = 0;
 
 	    /* check that neighbour is within region */
 	    if (r_nbr < 0 || r_nbr >= nrows || c_nbr < 0 || c_nbr >= ncols)
@@ -102,19 +102,19 @@
 			if (slope[ct_dir] <
 			    get_slope(ele_nbr[nbr_ew[ct_dir]],
 				       ele_nbr[ct_dir], ew_res))
-			    skip_me = 1;
+			    skip_diag = 1;
 		    }
-		    if (!skip_me && slope[nbr_ns[ct_dir]] > 0) {
+		    if (!skip_diag && slope[nbr_ns[ct_dir]] > 0) {
 			/* slope to ns nbr > slope to center */
 			if (slope[ct_dir] <
 			    get_slope(ele_nbr[nbr_ns[ct_dir]],
 				       ele_nbr[ct_dir], ns_res))
-			    skip_me = 1;
+			    skip_diag = 1;
 		    }
 		}
 	    }
 
-	    if (!skip_me) {
+	    if (!skip_diag) {
 		if (is_in_list == 0) {
 		    ele_up = ele_nbr[ct_dir];
 		    af.asp = drain[r_nbr - r + 1][c_nbr - c + 1];

Modified: grass-addons/grass7/raster/r.stream.extract/dseg.c
===================================================================
--- grass-addons/grass7/raster/r.stream.extract/dseg.c	2013-07-15 15:38:18 UTC (rev 57151)
+++ grass-addons/grass7/raster/r.stream.extract/dseg.c	2013-07-15 15:41:00 UTC (rev 57152)
@@ -102,7 +102,7 @@
 
 int dseg_read_raster(DSEG *dseg, char *map_name, char *mapset)
 {
-    int row, nrows, ncols;
+    int row, nrows;
     int map_fd;
     DCELL *dbuffer;
 
@@ -111,7 +111,6 @@
 
     map_fd = Rast_open_old(map_name, mapset);
     nrows = Rast_window_rows();
-    ncols = Rast_window_cols();
     dbuffer = Rast_allocate_d_buf();
     for (row = 0; row < nrows; row++) {
 	Rast_get_d_row(map_fd, dbuffer, row);
@@ -136,12 +135,11 @@
 int dseg_write_cellfile(DSEG *dseg, char *map_name)
 {
     int map_fd;
-    int row, nrows, ncols;
+    int row, nrows;
     DCELL *dbuffer;
 
     map_fd = Rast_open_new(map_name, DCELL_TYPE);
     nrows = Rast_window_rows();
-    ncols = Rast_window_cols();
     dbuffer = Rast_allocate_d_buf();
     segment_flush(&(dseg->seg));
     for (row = 0; row < nrows; row++) {

Modified: grass-addons/grass7/raster/r.stream.extract/streams.c
===================================================================
--- grass-addons/grass7/raster/r.stream.extract/streams.c	2013-07-15 15:38:18 UTC (rev 57151)
+++ grass-addons/grass7/raster/r.stream.extract/streams.c	2013-07-15 15:41:00 UTC (rev 57152)
@@ -143,15 +143,15 @@
     int mfd_cells, astar_not_set;
     double *dist_to_nbr, *weight, sum_weight, max_weight;
     double dx, dy;
-    int r_nbr, c_nbr, r_max, c_max, ct_dir, np_side;
+    int r_nbr, c_nbr, ct_dir, np_side;
     int is_worked;
-    double max_acc, prop;
+    double prop;
     int edge;
     int asp_r[9] = { 0, -1, -1, -1, 0, 1, 1, 1, 0 };
     int asp_c[9] = { 0, 1, 0, -1, -1, -1, 0, 1, 1 };
     int nextdr[8] = { 1, -1, 0, 0, -1, 1, 1, -1 };
     int nextdc[8] = { 0, 0, -1, 1, 1, -1, 1, -1 };
-    GW_LARGE_INT workedon, killer, count;
+    GW_LARGE_INT workedon, killer;
     char *flag_nbr;
     POINT astarpoint;
     WAT_ALT wa;
@@ -182,7 +182,6 @@
     }
 
     /* distribute and accumulate */
-    count = 0;
     for (killer = 0; killer < n_points; killer++) {
 
 	G_percent(killer, n_points, 1);
@@ -205,9 +204,6 @@
 	    dc = c + asp_c[abs((int)af.asp)];
 	}
 
-	r_max = dr;
-	c_max = dc;
-
 	seg_get(&watalt, (char *)&wa, r, c);
 	value = wa.wat;
 
@@ -309,8 +305,6 @@
 	if (fabs(value) > d8cut)
 	    mfd_cells = 0;
 
-	max_acc = -1;
-
 	if (mfd_cells > 1) {
 	    prop = 0.0;
 	    for (ct_dir = 0; ct_dir < sides; ct_dir++) {
@@ -370,7 +364,7 @@
     CELL is_swale, ele_val, *ele_nbr;
     DCELL value, valued, *wat_nbr;
     struct Cell_head window;
-    int mfd_cells, stream_cells, swale_cells, astar_not_set;
+    int mfd_cells, stream_cells, swale_cells;
     double *dist_to_nbr;
     double dx, dy;
     int r_nbr, c_nbr, r_max, c_max, ct_dir, np_side, max_side;
@@ -387,7 +381,7 @@
      *  | 2 |   | 3 |
      *  | 5 | 0 | 6 |
      */
-    GW_LARGE_INT workedon, killer, count;
+    GW_LARGE_INT workedon, killer;
     int stream_no = 0, stream_node_step = 1000;
     double slope, diag;
     char *flag_nbr;
@@ -435,7 +429,6 @@
     workedon = 0;
 
     /* extract streams */
-    count = 0;
     for (killer =  0; killer < n_points; killer++) {
 	G_percent(killer, n_points, 1);
 	
@@ -505,7 +498,6 @@
 	mfd_cells = 0;
 	stream_cells = 0;
 	swale_cells = 0;
-	astar_not_set = 1;
 	ele_val = wa.ele;
 	edge = 0;
 	flat = 1;
@@ -562,10 +554,6 @@
 			    c_max = c_nbr;
 			    max_side = ct_dir;
 			}
-
-			if (dr == r_nbr && dc == c_nbr) {
-			    astar_not_set = 0;
-			}
 		    }
 		}
 		else if (ct_dir == np_side && !edge) {



More information about the grass-commit mailing list