[GRASS-SVN] r72902 - grass-addons/grass7/raster/r.accumulate

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Jun 25 06:05:06 PDT 2018


Author: hcho
Date: 2018-06-25 06:05:06 -0700 (Mon, 25 Jun 2018)
New Revision: 72902

Modified:
   grass-addons/grass7/raster/r.accumulate/accumulate.c
   grass-addons/grass7/raster/r.accumulate/global.h
   grass-addons/grass7/raster/r.accumulate/main.c
Log:
r.accumulate: minor refactoring

Modified: grass-addons/grass7/raster/r.accumulate/accumulate.c
===================================================================
--- grass-addons/grass7/raster/r.accumulate/accumulate.c	2018-06-25 09:33:26 UTC (rev 72901)
+++ grass-addons/grass7/raster/r.accumulate/accumulate.c	2018-06-25 13:05:06 UTC (rev 72902)
@@ -1,10 +1,26 @@
 #include "global.h"
 
-double accumulate(struct cell_map *dir_buf, struct raster_map *weight_buf,
-                  struct raster_map *accum_buf, char **done, char neg,
-                  int row, int col)
+static double trace_up(struct cell_map *, struct raster_map *,
+                       struct raster_map *, char **, char, int, int);
+
+void accumulate(struct cell_map *dir_buf, struct raster_map *weight_buf,
+                struct raster_map *accum_buf, char **done, char neg)
 {
     int rows = dir_buf->rows, cols = dir_buf->cols;
+    int row, col;
+
+    for (row = 0; row < rows; row++) {
+        for (col = 0; col < cols; col++)
+            trace_up(dir_buf, weight_buf, accum_buf, done, neg, row, col);
+    }
+}
+
+static double trace_up(struct cell_map *dir_buf,
+                       struct raster_map *weight_buf,
+                       struct raster_map *accum_buf, char **done, char neg,
+                       int row, int col)
+{
+    int rows = dir_buf->rows, cols = dir_buf->cols;
     int i, j;
     char incomplete = 0;
     double accum;
@@ -53,12 +69,12 @@
              * loop), trace and recursively accumulate upstream cells */
             if (dir_buf->c[row + i][col + j] == dir_checks[i + 1][j + 1][0] &&
                 dir_buf->c[row][col] != dir_checks[i + 1][j + 1][1]) {
-                /* for negative accumulation, accumulate() always returns a
+                /* for negative accumulation, trace_up() always returns a
                  * positive value, so accum is always positive (cell count);
                  * otherwise, accum is weighted accumulation */
                 accum +=
-                    accumulate(dir_buf, weight_buf, accum_buf, done, neg,
-                               row + i, col + j);
+                    trace_up(dir_buf, weight_buf, accum_buf, done, neg,
+                             row + i, col + j);
 
                 /* if the neighbor cell is incomplete, the current cell also
                  * becomes incomplete */

Modified: grass-addons/grass7/raster/r.accumulate/global.h
===================================================================
--- grass-addons/grass7/raster/r.accumulate/global.h	2018-06-25 09:33:26 UTC (rev 72901)
+++ grass-addons/grass7/raster/r.accumulate/global.h	2018-06-25 13:05:06 UTC (rev 72902)
@@ -65,8 +65,8 @@
 void add_point(struct point_list *, double, double);
 
 /* accumulate.c */
-double accumulate(struct cell_map *, struct raster_map *, struct raster_map *,
-                  char **, char, int, int);
+void accumulate(struct cell_map *, struct raster_map *, struct raster_map *,
+                char **, char);
 
 /* delineate_streams.c */
 void delineate_streams(struct Map_info *, double, struct cell_map *,

Modified: grass-addons/grass7/raster/r.accumulate/main.c
===================================================================
--- grass-addons/grass7/raster/r.accumulate/main.c	2018-06-25 09:33:26 UTC (rev 72901)
+++ grass-addons/grass7/raster/r.accumulate/main.c	2018-06-25 13:05:06 UTC (rev 72902)
@@ -220,11 +220,7 @@
     accum_fd = accum_name ? Rast_open_new(accum_name, accum_buf.type) : -1;
 
     /* accumulate flows */
-    for (row = 0; row < rows; row++) {
-        for (col = 0; col < cols; col++)
-            accumulate(&dir_buf, &weight_buf, &accum_buf, done, neg, row,
-                       col);
-    }
+    accumulate(&dir_buf, &weight_buf, &accum_buf, done, neg);
 
     /* write out buffer to the accumulatoin map */
     if (accum_fd >= 0) {



More information about the grass-commit mailing list