[GRASS-SVN] r71853 - in grass-addons/grass7/raster: r.stream.basins r.stream.channel r.stream.distance r.stream.order r.stream.segment r.stream.stats
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Nov 27 07:12:43 PST 2017
Author: mmetz
Date: 2017-11-27 07:12:43 -0800 (Mon, 27 Nov 2017)
New Revision: 71853
Modified:
grass-addons/grass7/raster/r.stream.basins/main.c
grass-addons/grass7/raster/r.stream.channel/main.c
grass-addons/grass7/raster/r.stream.distance/main.c
grass-addons/grass7/raster/r.stream.order/main.c
grass-addons/grass7/raster/r.stream.segment/main.c
grass-addons/grass7/raster/r.stream.stats/main.c
Log:
r.stream.*: automatically use memory swap version if not all data can be kept in memory
Modified: grass-addons/grass7/raster/r.stream.basins/main.c
===================================================================
--- grass-addons/grass7/raster/r.stream.basins/main.c 2017-11-26 23:17:33 UTC (rev 71852)
+++ grass-addons/grass7/raster/r.stream.basins/main.c 2017-11-27 15:12:43 UTC (rev 71853)
@@ -38,6 +38,8 @@
int b_test = 0; /* test which option has been chosen: like chmod */
int segmentation, zerofill, lasts, cats;
+ int number_of_segs, number_of_segs_total;
+ double seg_size;
int i, outlets_num = 0;
int max_number_of_streams;
struct Range range;
@@ -139,6 +141,25 @@
nrows = Rast_window_rows();
ncols = Rast_window_cols();
+ number_of_segs = atoi(opt_swapsize->answer);
+ if (number_of_segs < 3)
+ number_of_segs = 3;
+
+ /* segment size in MB */
+ seg_size = sizeof(CELL) * 2.0 * SROWS * SCOLS / (1 << 20);
+
+ number_of_segs = (int)(number_of_segs / seg_size);
+
+ number_of_segs_total = (nrows / SROWS + nrows % SROWS) *
+ (ncols / SCOLS + ncols % SCOLS);
+
+ if (!segmentation) {
+ /* force use of the segment version
+ * if not all segments can be kept in memory */
+ if (number_of_segs_total > number_of_segs)
+ segmentation = 1;
+ }
+
/* ALL IN RAM VERSION */
if (!segmentation) {
MAP map_dirs, map_streams, map_basins;
@@ -199,19 +220,9 @@
else {
SEG map_dirs, map_streams, map_basins;
SEGMENT *streams = NULL, *dirs, *basins;
- int number_of_segs;
- double seg_size;
G_message(_("Memory swap calculation (may take some time)..."));
- number_of_segs = atoi(opt_swapsize->answer);
- if (number_of_segs < 3)
- number_of_segs = 3;
-
- /* segment size in MB */
- seg_size = sizeof(CELL) * 2.0 * SROWS * SCOLS / (1 << 20);
-
- number_of_segs = (int)(number_of_segs / seg_size);
if (number_of_segs < 10)
number_of_segs = 10;
Modified: grass-addons/grass7/raster/r.stream.channel/main.c
===================================================================
--- grass-addons/grass7/raster/r.stream.channel/main.c 2017-11-26 23:17:33 UTC (rev 71852)
+++ grass-addons/grass7/raster/r.stream.channel/main.c 2017-11-27 15:12:43 UTC (rev 71853)
@@ -44,9 +44,10 @@
*flag_local, *flag_cells, *flag_downstream;
char *method_name[] = { "UPSTREAM", "DOWNSTREAM" };
- int number_of_segs;
+ int number_of_segs, number_of_segs_total;
int number_of_streams;
int segmentation, downstream, local, cells; /*flags */
+ double seg_size;
/* initialize GIS environment */
G_gisinit(argv[0]);
@@ -145,7 +146,26 @@
G_get_window(&window);
G_begin_distance_calculations();
+ number_of_segs = atoi(opt_swapsize->answer);
+ if (number_of_segs < 3)
+ number_of_segs = 3;
+
+ /* segment size in MB */
+ seg_size = (sizeof(CELL) * 2.0 + sizeof(FCELL)) * SROWS * SCOLS / (1 << 20);
+
+ number_of_segs = (int)(number_of_segs / seg_size);
+
+ number_of_segs_total = (nrows / SROWS + nrows % SROWS) *
+ (ncols / SCOLS + ncols % SCOLS);
+
if (!segmentation) {
+ /* force use of the segment version
+ * if not all segments can be kept in memory */
+ if (number_of_segs_total > number_of_segs)
+ segmentation = 1;
+ }
+
+ if (!segmentation) {
MAP map_dirs, map_streams, map_elevation, map_output, map_identifier;
CELL **streams, **dirs, **identifier = NULL;
FCELL **elevation;
@@ -235,21 +255,12 @@
SEG map_dirs, map_streams, map_elevation, map_output, map_identifier;
SEGMENT *streams, *dirs, *elevation, *output, *identifier;
DCELL nullval;
- double seg_size;
G_message(_("Calculating segments in direction <%s> (may take some time)..."),
method_name[downstream]);
Rast_set_d_null_value(&nullval, 1);
- number_of_segs = atoi(opt_swapsize->answer);
- if (number_of_segs < 3)
- number_of_segs = 3;
-
- /* segment size in MB */
- seg_size = (sizeof(CELL) * 2.0 + sizeof(FCELL)) * SROWS * SCOLS / (1 << 20);
-
- number_of_segs = (int)(number_of_segs / seg_size);
if (number_of_segs < 10)
number_of_segs = 10;
Modified: grass-addons/grass7/raster/r.stream.distance/main.c
===================================================================
--- grass-addons/grass7/raster/r.stream.distance/main.c 2017-11-26 23:17:33 UTC (rev 71852)
+++ grass-addons/grass7/raster/r.stream.distance/main.c 2017-11-27 15:12:43 UTC (rev 71853)
@@ -37,10 +37,11 @@
struct Flag *flag_outs, *flag_sub, *flag_near, *flag_segmentation;
char *method_name[] = { "UPSTREAM", "DOWNSTREAM" };
int method;
- int number_of_segs;
+ int number_of_segs, number_of_segs_total;
int outlets_num;
int number_of_streams;
int outs, subs, near, segmentation; /*flags */
+ double seg_size;
int j;
G_gisinit(argv[0]);
@@ -142,7 +143,31 @@
fifo_max = 4 * (nrows + ncols);
fifo_points = (POINT *) G_malloc((fifo_max + 1) * sizeof(POINT));
+ number_of_segs = atoi(opt_swapsize->answer);
+ if (number_of_segs < 3)
+ number_of_segs = 3;
+
+ /* segment size in MB */
+ if (method == UPSTREAM && in_elev_opt->answer) {
+ seg_size = (sizeof(CELL) * 2.0 + sizeof(DCELL) * 2.0) * SROWS * SCOLS / (1 << 20);
+ }
+ else {
+ seg_size = (sizeof(CELL) * 2.0 + sizeof(DCELL) * 1.0) * SROWS * SCOLS / (1 << 20);
+ }
+
+ number_of_segs = (int)(number_of_segs / seg_size);
+
+ number_of_segs_total = (nrows / SROWS + nrows % SROWS) *
+ (ncols / SCOLS + ncols % SCOLS);
+
if (!segmentation) {
+ /* force use of the segment version
+ * if not all segments can be kept in memory */
+ if (number_of_segs_total > number_of_segs)
+ segmentation = 1;
+ }
+
+ if (!segmentation) {
MAP map_dirs, map_streams, map_distance, map_elevation,
map_tmp_elevation;
CELL **streams, **dirs;
@@ -231,26 +256,12 @@
SEGMENT *elevation = NULL;
SEGMENT *tmp_elevation = NULL;
DCELL nullval;
- double seg_size;
G_message(_("Calculating segments in direction <%s> (may take some time)..."),
method_name[method]);
Rast_set_d_null_value(&nullval, 1);
- number_of_segs = atoi(opt_swapsize->answer);
- if (number_of_segs < 3)
- number_of_segs = 3;
-
- /* segment size in MB */
- if (method == UPSTREAM && in_elev_opt->answer) {
- seg_size = (sizeof(CELL) * 2.0 + sizeof(DCELL) * 2.0) * SROWS * SCOLS / (1 << 20);
- }
- else {
- seg_size = (sizeof(CELL) * 2.0 + sizeof(DCELL) * 1.0) * SROWS * SCOLS / (1 << 20);
- }
-
- number_of_segs = (int)(number_of_segs / seg_size);
if (number_of_segs < 10)
number_of_segs = 10;
Modified: grass-addons/grass7/raster/r.stream.order/main.c
===================================================================
--- grass-addons/grass7/raster/r.stream.order/main.c 2017-11-26 23:17:33 UTC (rev 71852)
+++ grass-addons/grass7/raster/r.stream.order/main.c 2017-11-27 15:12:43 UTC (rev 71853)
@@ -58,8 +58,9 @@
int output_num = 0;
int segmentation, zerofill;
+ double seg_size;
int i; /* iteration vars */
- int number_of_segs;
+ int number_of_segs, number_of_segs_total;
int number_of_streams;
char *in_streams = NULL, *in_dirs = NULL, *in_elev = NULL, *in_accum =
NULL;
@@ -161,6 +162,25 @@
nrows = Rast_window_rows();
ncols = Rast_window_cols();
+ number_of_segs = atoi(opt_swapsize->answer);
+ if (number_of_segs < 3)
+ number_of_segs = 3;
+
+ /* segment size in MB */
+ seg_size = sizeof(CELL) * 2.0 * SROWS * SCOLS / (1 << 20);
+
+ number_of_segs = (int)(number_of_segs / seg_size);
+
+ number_of_segs_total = (nrows / SROWS + nrows % SROWS) *
+ (ncols / SCOLS + ncols % SCOLS);
+
+ if (!segmentation) {
+ /* force use of the segment version
+ * if not all segments can be kept in memory */
+ if (number_of_segs_total > number_of_segs)
+ segmentation = 1;
+ }
+
/* ALL IN RAM VERSION */
if (!segmentation) {
MAP map_streams, map_dirs;
@@ -219,18 +239,9 @@
else {
SEG map_streams, map_dirs;
SEGMENT *streams, *dirs;
- double seg_size;
G_message(_("Memory swap calculation (may take some time)..."));
- number_of_segs = atoi(opt_swapsize->answer);
- if (number_of_segs < 3)
- number_of_segs = 3;
-
- /* segment size in MB */
- seg_size = sizeof(CELL) * 2.0 * SROWS * SCOLS / (1 << 20);
-
- number_of_segs = (int)(number_of_segs / seg_size);
if (number_of_segs < 10)
number_of_segs = 10;
Modified: grass-addons/grass7/raster/r.stream.segment/main.c
===================================================================
--- grass-addons/grass7/raster/r.stream.segment/main.c 2017-11-26 23:17:33 UTC (rev 71852)
+++ grass-addons/grass7/raster/r.stream.segment/main.c 2017-11-27 15:12:43 UTC (rev 71853)
@@ -44,6 +44,8 @@
int i;
int seg_length, seg_skip;
int radians, segmentation; /* flags */
+ int number_of_segs, number_of_segs_total;
+ double seg_size;
double seg_treshold;
int number_of_streams, ordered;
@@ -139,7 +141,26 @@
Rast_get_window(&window);
G_begin_distance_calculations();
+ number_of_segs = atoi(opt_swapsize->answer);
+ if (number_of_segs < 3)
+ number_of_segs = 3;
+
+ /* segment size in MB */
+ seg_size = (sizeof(CELL) * 2.0 + sizeof(FCELL)) * SROWS * SCOLS / (1 << 20);
+
+ number_of_segs = (int)(number_of_segs / seg_size);
+
+ number_of_segs_total = (nrows / SROWS + nrows % SROWS) *
+ (ncols / SCOLS + ncols % SCOLS);
+
if (!segmentation) {
+ /* force use of the segment version
+ * if not all segments can be kept in memory */
+ if (number_of_segs_total > number_of_segs)
+ segmentation = 1;
+ }
+
+ if (!segmentation) {
MAP map_dirs, map_streams, map_elevation, map_unique_streams;
CELL **streams, **dirs, **unique_streams = NULL;
FCELL **elevation;
@@ -186,21 +207,11 @@
SEGMENT *streams, *dirs, *unique_streams = NULL;
SEGMENT *elevation;
DCELL nullval;
- int number_of_segs;
- double seg_size;
G_message(_("Memory swap calculation (may take some time)..."));
Rast_set_d_null_value(&nullval, 1);
- number_of_segs = atoi(opt_swapsize->answer);
- if (number_of_segs < 3)
- number_of_segs = 3;
-
- /* segment size in MB */
- seg_size = (sizeof(CELL) * 2.0 + sizeof(FCELL)) * SROWS * SCOLS / (1 << 20);
-
- number_of_segs = (int)(number_of_segs / seg_size);
if (number_of_segs < 10)
number_of_segs = 10;
Modified: grass-addons/grass7/raster/r.stream.stats/main.c
===================================================================
--- grass-addons/grass7/raster/r.stream.stats/main.c 2017-11-26 23:17:33 UTC (rev 71852)
+++ grass-addons/grass7/raster/r.stream.stats/main.c 2017-11-27 15:12:43 UTC (rev 71853)
@@ -39,9 +39,10 @@
*flag_catchment_total, *flag_orders_summary;
char *filename;
- int number_of_segs;
+ int number_of_segs, number_of_segs_total;
int order_max;
int segmentation, catchment_total, orders_summary; /*flags */
+ double seg_size;
/* initialize GIS environment */
G_gisinit(argv[0]);
@@ -109,7 +110,26 @@
nrows = Rast_window_rows();
ncols = Rast_window_cols();
+ number_of_segs = atoi(opt_swapsize->answer);
+ if (number_of_segs < 3)
+ number_of_segs = 3;
+
+ /* segment size in MB */
+ seg_size = (sizeof(CELL) * 2.0 + sizeof(FCELL)) * SROWS * SCOLS / (1 << 20);
+
+ number_of_segs = (int)(number_of_segs / seg_size);
+
+ number_of_segs_total = (nrows / SROWS + nrows % SROWS) *
+ (ncols / SCOLS + ncols % SCOLS);
+
if (!segmentation) {
+ /* force use of the segment version
+ * if not all segments can be kept in memory */
+ if (number_of_segs_total > number_of_segs)
+ segmentation = 1;
+ }
+
+ if (!segmentation) {
MAP map_dirs, map_streams, map_elevation;
CELL **streams, **dirs;
FCELL **elevation;
@@ -155,20 +175,11 @@
SEG map_dirs, map_streams, map_elevation;
SEGMENT *streams, *dirs, *elevation;
DCELL nullval;
- double seg_size;
G_message(_("Memory swap calculation (may take some time)..."));
Rast_set_d_null_value(&nullval, 1);
- number_of_segs = atoi(opt_swapsize->answer);
- if (number_of_segs < 3)
- number_of_segs = 3;
-
- /* segment size in MB */
- seg_size = (sizeof(CELL) * 2.0 + sizeof(FCELL)) * SROWS * SCOLS / (1 << 20);
-
- number_of_segs = (int)(number_of_segs / seg_size);
if (number_of_segs < 10)
number_of_segs = 10;
More information about the grass-commit
mailing list