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

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jun 23 10:30:47 PDT 2018


Author: hcho
Date: 2018-06-23 10:30:47 -0700 (Sat, 23 Jun 2018)
New Revision: 72890

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
   grass-addons/grass7/raster/r.accumulate/raster.c
Log:
r.accumulate: Run grass_indent.sh

Modified: grass-addons/grass7/raster/r.accumulate/accumulate.c
===================================================================
--- grass-addons/grass7/raster/r.accumulate/accumulate.c	2018-06-23 17:26:36 UTC (rev 72889)
+++ grass-addons/grass7/raster/r.accumulate/accumulate.c	2018-06-23 17:30:47 UTC (rev 72890)
@@ -13,12 +13,12 @@
 
 double
 accumulate(CELL ** dir_buf, RASTER_MAP weight_buf, RASTER_MAP acc_buf,
-	   char **done, char neg, int row, int col)
+           char **done, char neg, int row, int col)
 {
     static int dir_checks[3][3][2] = {
-	{{SE, NW}, {S, N}, {SW, NE}},
-	{{E, W}, {0, 0}, {W, E}},
-	{{NE, SW}, {N, S}, {NW, SE}}
+        {{SE, NW}, {S, N}, {SW, NE}},
+        {{E, W}, {0, 0}, {W, E}},
+        {{NE, SW}, {N, S}, {NW, SE}}
     };
     int rows = weight_buf.rows, cols = weight_buf.cols;
     int i, j;
@@ -26,34 +26,34 @@
     double acc;
 
     if (done[row][col])
-	return fabs(get(acc_buf, row, col));
+        return fabs(get(acc_buf, row, col));
 
     if (weight_buf.map.v)
-	acc = get(weight_buf, row, col);
+        acc = get(weight_buf, row, col);
     else
-	acc = 1.0;
+        acc = 1.0;
 
     for (i = -1; i <= 1; i++) {
-	if (row + i < 0 || row + i >= rows) {
-	    incomplete = 1;
-	    continue;
-	}
-	for (j = -1; j <= 1; j++) {
-	    if (i == 0 && j == 0)
-		continue;
-	    if (col + j < 0 || col + j >= cols) {
-		incomplete = 1;
-		continue;
-	    }
-	    if (dir_buf[row + i][col + j] == dir_checks[i + 1][j + 1][0] &&
-		dir_buf[row][col] != dir_checks[i + 1][j + 1][1]) {
-		acc +=
-		    accumulate(dir_buf, weight_buf, acc_buf, done, neg,
-			       row + i, col + j);
-		if (done[row + i][col + j] == 2)
-		    incomplete = 1;
-	    }
-	}
+        if (row + i < 0 || row + i >= rows) {
+            incomplete = 1;
+            continue;
+        }
+        for (j = -1; j <= 1; j++) {
+            if (i == 0 && j == 0)
+                continue;
+            if (col + j < 0 || col + j >= cols) {
+                incomplete = 1;
+                continue;
+            }
+            if (dir_buf[row + i][col + j] == dir_checks[i + 1][j + 1][0] &&
+                dir_buf[row][col] != dir_checks[i + 1][j + 1][1]) {
+                acc +=
+                    accumulate(dir_buf, weight_buf, acc_buf, done, neg,
+                               row + i, col + j);
+                if (done[row + i][col + j] == 2)
+                    incomplete = 1;
+            }
+        }
     }
 
     set(acc_buf, row, col, neg && incomplete ? -acc : acc);

Modified: grass-addons/grass7/raster/r.accumulate/global.h
===================================================================
--- grass-addons/grass7/raster/r.accumulate/global.h	2018-06-23 17:26:36 UTC (rev 72889)
+++ grass-addons/grass7/raster/r.accumulate/global.h	2018-06-23 17:30:47 UTC (rev 72890)
@@ -6,10 +6,10 @@
     int rows, cols;
     union
     {
-	void **v;
-	CELL **c;
-	FCELL **f;
-	DCELL **d;
+        void **v;
+        CELL **c;
+        FCELL **f;
+        DCELL **d;
     } map;
 } RASTER_MAP;
 

Modified: grass-addons/grass7/raster/r.accumulate/main.c
===================================================================
--- grass-addons/grass7/raster/r.accumulate/main.c	2018-06-23 17:26:36 UTC (rev 72889)
+++ grass-addons/grass7/raster/r.accumulate/main.c	2018-06-23 17:30:47 UTC (rev 72890)
@@ -32,11 +32,11 @@
     struct GModule *module;
     struct
     {
-	struct Option *dir, *format, *weight, *acc;
+        struct Option *dir, *format, *weight, *acc;
     } opt;
     struct
     {
-	struct Flag *neg;
+        struct Flag *neg;
     } flag;
     char *desc;
     char *dir_name, *weight_name, *acc_name;
@@ -57,7 +57,7 @@
     G_add_keyword(_("raster"));
     G_add_keyword(_("hydrology"));
     module->description =
-	_("Calculates weighted flow accumulation using a flow direction map.");
+        _("Calculates weighted flow accumulation using a flow direction map.");
 
     opt.dir = G_define_standard_option(G_OPT_R_INPUT);
     opt.dir->description = _("Name of input direction map");
@@ -70,9 +70,9 @@
     opt.format->options = "auto,degree,45degree";
     opt.format->answer = "auto";
     G_asprintf(&desc, "auto;%s;degree;%s;45degree;%s",
-	       _("auto-detect direction format"),
-	       _("degrees CCW from East"),
-	       _("degrees CCW from East divided by 45 (e.g. r.watershed directions)"));
+               _("auto-detect direction format"),
+               _("degrees CCW from East"),
+               _("degrees CCW from East divided by 45 (e.g. r.watershed directions)"));
     opt.format->descriptions = desc;
 
     opt.weight = G_define_standard_option(G_OPT_R_INPUT);
@@ -83,17 +83,17 @@
     opt.acc = G_define_standard_option(G_OPT_R_OUTPUT);
     opt.acc->type = TYPE_STRING;
     opt.acc->description =
-	_("Name for output weighted flow accumulation map");
+        _("Name for output weighted flow accumulation map");
 
     flag.neg = G_define_flag();
     flag.neg->key = 'n';
     flag.neg->label =
-	_("Use negative flow accumulation for likely underestimates");
+        _("Use negative flow accumulation for likely underestimates");
 
     G_option_exclusive(opt.weight, flag.neg, NULL);
 
     if (G_parser(argc, argv))
-	exit(EXIT_FAILURE);
+        exit(EXIT_FAILURE);
 
     dir_name = opt.dir->answer;
     weight_name = opt.weight->answer;
@@ -101,51 +101,51 @@
 
     dir_fd = Rast_open_old(dir_name, "");
     if (Rast_get_map_type(dir_fd) != CELL_TYPE)
-	G_fatal_error(_("Invalid directions map <%s>"), dir_name);
+        G_fatal_error(_("Invalid directions map <%s>"), dir_name);
 
     /* adapted from r.path */
     if (Rast_read_range(dir_name, "", &dir_range) < 0)
-	G_fatal_error(_("Unable to read range file"));
+        G_fatal_error(_("Unable to read range file"));
     Rast_get_range_min_max(&dir_range, &dir_min, &dir_max);
     if (dir_max <= 0)
-	G_fatal_error(_("Invalid directions map <%s>"), dir_name);
+        G_fatal_error(_("Invalid directions map <%s>"), dir_name);
 
     dir_format = DIR_UNKNOWN;
     if (strcmp(opt.format->answer, "degree") == 0) {
-	if (dir_max > 360)
-	    G_fatal_error(_("Directional degrees can not be > 360"));
-	dir_format = DIR_DEG;
+        if (dir_max > 360)
+            G_fatal_error(_("Directional degrees can not be > 360"));
+        dir_format = DIR_DEG;
     }
     else if (strcmp(opt.format->answer, "45degree") == 0) {
-	if (dir_max > 8)
-	    G_fatal_error(_("Directional degrees divided by 45 can not be > 8"));
-	dir_format = DIR_DEG45;
+        if (dir_max > 8)
+            G_fatal_error(_("Directional degrees divided by 45 can not be > 8"));
+        dir_format = DIR_DEG45;
     }
     else if (strcmp(opt.format->answer, "auto") == 0) {
-	if (dir_max <= 8) {
-	    dir_format = DIR_DEG45;
-	    G_important_message(_("Input direction format assumed to be degrees CCW from East divided by 45"));
-	}
-	else if (dir_max <= 360) {
-	    dir_format = DIR_DEG;
-	    G_important_message(_("Input direction format assumed to be degrees CCW from East"));
-	}
-	else
-	    G_fatal_error(_("Unable to detect format of input direction map <%s>"),
-			  dir_name);
+        if (dir_max <= 8) {
+            dir_format = DIR_DEG45;
+            G_important_message(_("Input direction format assumed to be degrees CCW from East divided by 45"));
+        }
+        else if (dir_max <= 360) {
+            dir_format = DIR_DEG;
+            G_important_message(_("Input direction format assumed to be degrees CCW from East"));
+        }
+        else
+            G_fatal_error(_("Unable to detect format of input direction map <%s>"),
+                          dir_name);
     }
     if (dir_format == DIR_UNKNOWN)
-	G_fatal_error(_("Invalid directions format '%s'"),
-		      opt.format->answer);
+        G_fatal_error(_("Invalid directions format '%s'"),
+                      opt.format->answer);
     /* end of r.path */
 
     if (weight_name) {
-	weight_fd = Rast_open_old(weight_name, "");
-	weight_buf.type = Rast_get_map_type(weight_fd);
+        weight_fd = Rast_open_old(weight_name, "");
+        weight_buf.type = Rast_get_map_type(weight_fd);
     }
     else {
-	weight_fd = -1;
-	weight_buf.type = CELL_TYPE;
+        weight_fd = -1;
+        weight_buf.type = CELL_TYPE;
     }
 
     acc_buf.type = weight_buf.type;
@@ -159,64 +159,64 @@
     done = G_malloc(rows * sizeof(char *));
     dir_buf = G_malloc(rows * sizeof(CELL *));
     for (row = 0; row < rows; row++) {
-	done[row] = G_calloc(cols, 1);
-	dir_buf[row] = Rast_allocate_c_buf();
-	Rast_get_c_row(dir_fd, dir_buf[row], row);
-	if (dir_format == DIR_DEG45) {
-	    for (col = 0; col < cols; col++)
-		dir_buf[row][col] *= 45;
-	}
+        done[row] = G_calloc(cols, 1);
+        dir_buf[row] = Rast_allocate_c_buf();
+        Rast_get_c_row(dir_fd, dir_buf[row], row);
+        if (dir_format == DIR_DEG45) {
+            for (col = 0; col < cols; col++)
+                dir_buf[row][col] *= 45;
+        }
     }
 
     if (weight_fd >= 0) {
-	weight_buf.map.v = (void **)G_malloc(rows * sizeof(void *));
-	for (row = 0; row < rows; row++) {
-	    weight_buf.map.v[row] =
-		(void *)Rast_allocate_buf(weight_buf.type);
-	    Rast_get_row(weight_fd, weight_buf.map.v[row], row,
-			 weight_buf.type);
-	}
+        weight_buf.map.v = (void **)G_malloc(rows * sizeof(void *));
+        for (row = 0; row < rows; row++) {
+            weight_buf.map.v[row] =
+                (void *)Rast_allocate_buf(weight_buf.type);
+            Rast_get_row(weight_fd, weight_buf.map.v[row], row,
+                         weight_buf.type);
+        }
     }
     else
-	weight_buf.map.v = NULL;
+        weight_buf.map.v = NULL;
     weight_buf.rows = rows;
     weight_buf.cols = cols;
 
     acc_buf.map.v = (void **)G_malloc(rows * sizeof(void *));
     for (row = 0; row < rows; row++)
-	acc_buf.map.v[row] = (void *)Rast_allocate_buf(acc_buf.type);
+        acc_buf.map.v[row] = (void *)Rast_allocate_buf(acc_buf.type);
     acc_buf.rows = rows;
     acc_buf.cols = cols;
 
     for (row = 0; row < rows; row++) {
-	for (col = 0; col < cols; col++)
-	    accumulate(dir_buf, weight_buf, acc_buf, done, neg, row, col);
+        for (col = 0; col < cols; col++)
+            accumulate(dir_buf, weight_buf, acc_buf, done, neg, row, col);
     }
 
     for (row = 0; row < rows; row++)
-	Rast_put_row(acc_fd, acc_buf.map.v[row], acc_buf.type);
+        Rast_put_row(acc_fd, acc_buf.map.v[row], acc_buf.type);
 
     G_free(done);
     for (row = 0; row < rows; row++) {
-	G_free(dir_buf[row]);
-	if (weight_fd >= 0)
-	    G_free(weight_buf.map.v[row]);
-	G_free(acc_buf.map.v[row]);
+        G_free(dir_buf[row]);
+        if (weight_fd >= 0)
+            G_free(weight_buf.map.v[row]);
+        G_free(acc_buf.map.v[row]);
     }
     G_free(dir_buf);
     if (weight_fd >= 0)
-	G_free(weight_buf.map.v);
+        G_free(weight_buf.map.v);
     G_free(acc_buf.map.v);
 
     Rast_close(dir_fd);
     if (weight_fd >= 0)
-	Rast_close(weight_fd);
+        Rast_close(weight_fd);
     Rast_close(acc_fd);
 
     Rast_put_cell_title(acc_name,
-			weight_name ? "Weighted flow accumulation" :
-			(neg ? "Flow accumulation with likely underestimates"
-			 : "Flow accumulation"));
+                        weight_name ? "Weighted flow accumulation" :
+                        (neg ? "Flow accumulation with likely underestimates"
+                         : "Flow accumulation"));
     Rast_short_history(acc_name, "raster", &hist);
     Rast_command_history(&hist);
     Rast_write_history(acc_name, &hist);

Modified: grass-addons/grass7/raster/r.accumulate/raster.c
===================================================================
--- grass-addons/grass7/raster/r.accumulate/raster.c	2018-06-23 17:26:36 UTC (rev 72889)
+++ grass-addons/grass7/raster/r.accumulate/raster.c	2018-06-23 17:30:47 UTC (rev 72890)
@@ -5,14 +5,14 @@
 {
     switch (buf.type) {
     case CELL_TYPE:
-	buf.map.c[row][col] = (CELL) value;
-	break;
+        buf.map.c[row][col] = (CELL) value;
+        break;
     case FCELL_TYPE:
-	buf.map.f[row][col] = (FCELL) value;
-	break;
+        buf.map.f[row][col] = (FCELL) value;
+        break;
     case DCELL_TYPE:
-	buf.map.d[row][col] = (DCELL) value;
-	break;
+        buf.map.d[row][col] = (DCELL) value;
+        break;
     }
 
     return;
@@ -24,14 +24,14 @@
 
     switch (buf.type) {
     case CELL_TYPE:
-	value = (double)buf.map.c[row][col];
-	break;
+        value = (double)buf.map.c[row][col];
+        break;
     case FCELL_TYPE:
-	value = (double)buf.map.f[row][col];
-	break;
+        value = (double)buf.map.f[row][col];
+        break;
     case DCELL_TYPE:
-	value = buf.map.d[row][col];
-	break;
+        value = buf.map.d[row][col];
+        break;
     }
 
     return value;



More information about the grass-commit mailing list