[GRASS-SVN] r64288 - in grass/branches/releasebranch_7_0/raster: r.cost r.walk

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jan 23 11:39:26 PST 2015


Author: mmetz
Date: 2015-01-23 11:39:26 -0800 (Fri, 23 Jan 2015)
New Revision: 64288

Modified:
   grass/branches/releasebranch_7_0/raster/r.cost/cost.h
   grass/branches/releasebranch_7_0/raster/r.cost/main.c
   grass/branches/releasebranch_7_0/raster/r.cost/r.cost.html
   grass/branches/releasebranch_7_0/raster/r.cost/stash.h
   grass/branches/releasebranch_7_0/raster/r.walk/main.c
   grass/branches/releasebranch_7_0/raster/r.walk/r.walk.html
   grass/branches/releasebranch_7_0/raster/r.walk/stash.h
Log:
r.cost, r.walk: change percent_memory to memory (in MB)

Modified: grass/branches/releasebranch_7_0/raster/r.cost/cost.h
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.cost/cost.h	2015-01-23 19:38:50 UTC (rev 64287)
+++ grass/branches/releasebranch_7_0/raster/r.cost/cost.h	2015-01-23 19:39:26 UTC (rev 64288)
@@ -1,26 +1,4 @@
 
-/****************************************************************************
- *
- * MODULE:       r.cost
- *
- * AUTHOR(S):    Antony Awaida - IESL - M.I.T.
- *               James Westervelt - CERL
- *               Pierre de Mouveaux <pmx audiovu com>
- *               Eric G. Miller <egm2 jps net>
- *
- * PURPOSE:      Outputs a raster map layer showing the cumulative cost
- *               of moving between different geographic locations on an
- *               input raster map layer whose cell category values
- *               represent cost.
- *
- * COPYRIGHT:    (C) 2006 by the GRASS Development Team
- *
- *               This program is free software under the GNU General Public
- *               License (>=v2). Read the file COPYING that comes with GRASS
- *               for details.
- *
- ***************************************************************************/
-
 /***************************************************************/
 /*                                                             */
 /*        cost.h    in   ~/src/Gcost                           */

Modified: grass/branches/releasebranch_7_0/raster/r.cost/main.c
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.cost/main.c	2015-01-23 19:38:50 UTC (rev 64287)
+++ grass/branches/releasebranch_7_0/raster/r.cost/main.c	2015-01-23 19:39:26 UTC (rev 64288)
@@ -18,7 +18,7 @@
  *               input raster map layer whose cell category values 
  *               represent cost.
  *
- * COPYRIGHT:    (C) 2006-2009 by the GRASS Development Team
+ * COPYRIGHT:    (C) 2006-2015 by the GRASS Development Team
  *
  *               This program is free software under the GNU General Public
  *               License (>=v2). Read the file COPYING that comes with GRASS
@@ -132,7 +132,7 @@
     struct History history;
     double peak = 0.0;
     int dsize, nearest_size;
-    double disk_mb, mem_mb;
+    double disk_mb, mem_mb, pq_mb;
 
     G_gisinit(argv[0]);
 
@@ -219,14 +219,13 @@
     opt6->guisection = _("NULL cells");
 
     opt10 = G_define_option();
-    opt10->key = "percent_memory";
+    opt10->key = "memory";
     opt10->type = TYPE_INTEGER;
     opt10->key_desc = "value";
     opt10->required = NO;
     opt10->multiple = NO;
-    opt10->answer = "40";
-    opt10->options = "0-100";
-    opt10->description = _("Percent of map to keep in memory");
+    opt10->answer = "300";
+    opt10->description = _("Maximum memory to be used in MB");
 
     flag2 = G_define_flag();
     flag2->key = 'k';
@@ -309,9 +308,8 @@
     if (sscanf(opt5->answer, "%d", &maxcost) != 1 || maxcost < 0)
 	G_fatal_error(_("Inappropriate maximum cost: %d"), maxcost);
 
-    if (sscanf(opt10->answer, "%d", &maxmem) != 1 || maxmem < 0 ||
-	maxmem > 100)
-	G_fatal_error(_("Inappropriate percent memory: %d"), maxmem);
+    if (sscanf(opt10->answer, "%d", &maxmem) != 1 || maxmem <= 0)
+	G_fatal_error(_("Inappropriate amount of memory: %d"), maxmem);
 
     if ((opt6->answer == NULL) ||
 	(sscanf(opt6->answer, "%lf", &null_cost) != 1)) {
@@ -379,31 +377,35 @@
     else
 	srows = scols = SEGCOLSIZE;
 
-    if (maxmem == 100) {
-	srows = scols = 256;
-    }
-
     /* calculate total number of segments */
     nseg = ((nrows + srows - 1) / srows) * ((ncols + scols - 1) / scols);
-    if (maxmem > 0)
-	segments_in_memory = (maxmem * nseg) / 100;
-    /* maxmem = 0 */
-    else
-	segments_in_memory = 4 * (nrows / srows + ncols / scols + 2);
 
-    if (segments_in_memory == 0)
-	segments_in_memory = 1;
-
-    /* report disk space and memory requirements */
+    /* calculate disk space and memory requirements */
+    /* (nrows + ncols) * 8. * 20.0 / 1048576. for Dijkstra search */
+    pq_mb = ((double)nrows + ncols) * 8. * 20.0 / 1048576.;
+    G_debug(0, "pq MB: %g", pq_mb);
+    maxmem -= pq_mb;
+    if (maxmem < 10)
+	maxmem = 10;
     if (dir == TRUE) {
 	disk_mb = (double) nrows * ncols * 28. / 1048576.;
-	mem_mb  = (double) srows * scols * 28. / 1048576. * segments_in_memory;
-	mem_mb += nrows * ncols * 0.05 * 20. / 1048576.;    /* for Dijkstra search */
+	segments_in_memory = maxmem / 
+	                     ((double) srows * scols * (28. / 1048576.));
+	if (segments_in_memory < 4)
+	    segments_in_memory = 4;
+	if (segments_in_memory > nseg)
+	    segments_in_memory = nseg;
+	mem_mb = (double) srows * scols * (28. / 1048576.) * segments_in_memory;
     }
     else {
 	disk_mb = (double) nrows * ncols * 24. / 1048576.;
-	mem_mb  = (double) srows * scols * 24. / 1048576. * segments_in_memory;
-	mem_mb += nrows * ncols * 0.05 * 20. / 1048576.;    /* for Dijkstra search */
+	segments_in_memory = maxmem / 
+	                     ((double) srows * scols * (24. / 1048576.));
+	if (segments_in_memory < 4)
+	    segments_in_memory = 4;
+	if (segments_in_memory > nseg)
+	    segments_in_memory = nseg;
+	mem_mb = (double) srows * scols * (24. / 1048576.) * segments_in_memory;
     }
 
     if (flag5->answer) {
@@ -411,6 +413,9 @@
         fprintf(stdout, "\n");
 	fprintf(stdout, _("Will need at least %.2f MB of memory"), mem_mb);
         fprintf(stdout, "\n");
+	fprintf(stdout, _("%d of %d segments are kept in memory"),
+	                segments_in_memory, nseg);
+        fprintf(stdout, "\n");
 	Rast_close(cost_fd);
 	exit(EXIT_SUCCESS);
     }
@@ -418,6 +423,8 @@
     G_verbose_message("--------------------------------------------");
     G_verbose_message(_("Will need at least %.2f MB of disk space"), disk_mb);
     G_verbose_message(_("Will need at least %.2f MB of memory"), mem_mb);
+    G_verbose_message(_("%d of %d segments are kept in memory"),
+	              segments_in_memory, nseg);
     G_verbose_message("--------------------------------------------");
 
     /* Create segmented format files for cost layer and output layer */

Modified: grass/branches/releasebranch_7_0/raster/r.cost/r.cost.html
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.cost/r.cost.html	2015-01-23 19:38:50 UTC (rev 64287)
+++ grass/branches/releasebranch_7_0/raster/r.cost/r.cost.html	2015-01-23 19:39:26 UTC (rev 64288)
@@ -140,16 +140,16 @@
 at each node in the tree for efficiently holding cells with identical
 cumulative costs.
 <p>
-<em>r.cost</em>, like most all GRASS raster programs, is also made to be run on
-maps larger that can fit in available computer memory. As the
-algorithm works through the dynamic list of cells it can move almost
-randomly around the entire area. <em>r.cost</em> divides the entire area
-into a number of pieces and swaps these pieces in and out of memory (to
-and from disk) as needed. This provides a virtual memory approach
-optimally designed for 2-D raster maps.
-The amount of map to hold in memory at one time can be controlled with the
-<b>percent_memory</b> option. For large maps this value will have to be set
-to a lower value.
+<em>r.cost</em>, like most all GRASS raster programs, is also made to 
+be run on maps larger that can fit in available computer memory. As the 
+algorithm works through the dynamic list of cells it can move almost 
+randomly around the entire area. <em>r.cost</em> divides the entire 
+area into a number of pieces and swaps these pieces in and out of 
+memory (to and from disk) as needed. This provides a virtual memory 
+approach optimally designed for 2-D raster maps. The amount of memory 
+to be used by <em>r.cost</em> can be controlled with the <b>memory</b> 
+option, default is 300 MB. For systems with less memory this value will 
+have to be set to a lower value.
 
 
 <h2>EXAMPLES</h2>

Modified: grass/branches/releasebranch_7_0/raster/r.cost/stash.h
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.cost/stash.h	2015-01-23 19:38:50 UTC (rev 64287)
+++ grass/branches/releasebranch_7_0/raster/r.cost/stash.h	2015-01-23 19:39:26 UTC (rev 64288)
@@ -1,26 +1,15 @@
 
-/****************************************************************************
- *
- * MODULE:       r.cost
- *
- * AUTHOR(S):    Antony Awaida - IESL - M.I.T.
- *               James Westervelt - CERL
- *               Pierre de Mouveaux <pmx audiovu com>
- *               Eric G. Miller <egm2 jps net>
- *
- * PURPOSE:      Outputs a raster map layer showing the cumulative cost
- *               of moving between different geographic locations on an
- *               input raster map layer whose cell category values
- *               represent cost.
- *
- * COPYRIGHT:    (C) 2006-2009 by the GRASS Development Team
- *
- *               This program is free software under the GNU General Public
- *               License (>=v2). Read the file COPYING that comes with GRASS
- *               for details.
- *
- ***************************************************************************/
+/***************************************************************/
+/*                                                             */
+/*       stash.h     in    ~/src/Gcost                         */
+/*                                                             */
+/*       This header file declares the global variables and    */
+/*       the structures that are to be used for command        */
+/*       line processing.                                      */
+/*                                                             */
 
+/***************************************************************/
+
 #ifndef __STASH_H__
 #define __STASH_H__
 

Modified: grass/branches/releasebranch_7_0/raster/r.walk/main.c
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.walk/main.c	2015-01-23 19:38:50 UTC (rev 64287)
+++ grass/branches/releasebranch_7_0/raster/r.walk/main.c	2015-01-23 19:39:26 UTC (rev 64288)
@@ -30,7 +30,7 @@
  *               Updated for GRASS 7
  *                 Markus Metz
  * PURPOSE:      anisotropic movements on cost surfaces
- * COPYRIGHT:    (C) 1999-2014 by the GRASS Development Team
+ * COPYRIGHT:    (C) 1999-2015 by the GRASS Development Team
  *
  *               This program is free software under the GNU General Public
  *               License (>=v2). Read the file COPYING that comes with GRASS
@@ -167,7 +167,7 @@
     struct History history;
     double peak = 0.0;
     int dtm_dsize, cost_dsize;
-    double disk_mb, mem_mb;
+    double disk_mb, mem_mb, pq_mb;
 
     /* Definition for dimension and region check */
     struct Cell_head dtm_cellhd, cost_cellhd;
@@ -259,9 +259,8 @@
     opt10->key_desc = "value";
     opt10->required = NO;
     opt10->multiple = NO;
-    opt10->answer = "40";
-    opt10->options = "0-100";
-    opt10->description = _("Percent of map to keep in memory");
+    opt10->answer = "300";
+    opt10->description = _("Maximum memory to be used in MB");
 
     opt15 = G_define_option();
     opt15->key = "walk_coeff";
@@ -369,9 +368,8 @@
     if (sscanf(opt5->answer, "%d", &maxcost) != 1 || maxcost < 0)
 	G_fatal_error(_("Inappropriate maximum cost: %d"), maxcost);
 
-    if (sscanf(opt10->answer, "%d", &maxmem) != 1 || maxmem < 0 ||
-	maxmem > 100)
-	G_fatal_error(_("Inappropriate percent memory: %d"), maxmem);
+    if (sscanf(opt10->answer, "%d", &maxmem) != 1 || maxmem <= 0)
+	G_fatal_error(_("Inappropriate amount of memory: %d"), maxmem);
 
     /* Getting walking energy formula parameters */
     if ((par_number =
@@ -492,31 +490,35 @@
     else
 	srows = scols = SEGCOLSIZE;
 
-    if (maxmem == 100) {
-	srows = scols = 256;
-    }
-
     /* calculate total number of segments */
     nseg = ((nrows + srows - 1) / srows) * ((ncols + scols - 1) / scols);
-    if (maxmem > 0)
-	segments_in_memory = (maxmem * nseg) / 100;
-    /* maxmem = 0 */
-    else
-	segments_in_memory = 4 * (nrows / srows + ncols / scols + 2);
 
-    if (segments_in_memory == 0)
-	segments_in_memory = 1;
-
-    /* report disk space and memory requirements */
-    if (dir == 1) {
+    /* calculate disk space and memory requirements */
+    /* (nrows + ncols) * 8. * 20.0 / 1048576. for Dijkstra search */
+    pq_mb = ((double)nrows + ncols) * 8. * 20.0 / 1048576.;
+    G_debug(0, "pq MB: %g", pq_mb);
+    maxmem -= pq_mb;
+    if (maxmem < 10)
+	maxmem = 10;
+    if (dir == TRUE) {
 	disk_mb = (double) nrows * ncols * 28. / 1048576.;
-	mem_mb  = (double) srows * scols * 28. / 1048576. * segments_in_memory;
-	mem_mb += nrows * ncols * 0.05 * 20. / 1048576.;    /* for Dijkstra search */
+	segments_in_memory = maxmem / 
+	                     ((double) srows * scols * (28. / 1048576.));
+	if (segments_in_memory < 4)
+	    segments_in_memory = 4;
+	if (segments_in_memory > nseg)
+	    segments_in_memory = nseg;
+	mem_mb = (double) srows * scols * (28. / 1048576.) * segments_in_memory;
     }
     else {
 	disk_mb = (double) nrows * ncols * 24. / 1048576.;
-	mem_mb  = (double) srows * scols * 24. / 1048576. * segments_in_memory;
-	mem_mb += nrows * ncols * 0.05 * 20. / 1048576.;    /* for Dijkstra search */
+	segments_in_memory = maxmem / 
+	                     ((double) srows * scols * (24. / 1048576.));
+	if (segments_in_memory < 4)
+	    segments_in_memory = 4;
+	if (segments_in_memory > nseg)
+	    segments_in_memory = nseg;
+	mem_mb = (double) srows * scols * (24. / 1048576.) * segments_in_memory;
     }
 
     if (flag5->answer) {
@@ -524,6 +526,9 @@
         fprintf(stdout, "\n");
 	fprintf(stdout, _("Will need at least %.2f MB of memory"), mem_mb);
         fprintf(stdout, "\n");
+	fprintf(stdout, _("%d of %d segments are kept in memory"),
+	                segments_in_memory, nseg);
+        fprintf(stdout, "\n");
 	Rast_close(cost_fd);
 	Rast_close(dtm_fd);
 	exit(EXIT_SUCCESS);
@@ -532,6 +537,8 @@
     G_verbose_message("--------------------------------------------");
     G_verbose_message(_("Will need at least %.2f MB of disk space"), disk_mb);
     G_verbose_message(_("Will need at least %.2f MB of memory"), mem_mb);
+    G_verbose_message(_("%d of %d segments are kept in memory"),
+	              segments_in_memory, nseg);
     G_verbose_message("--------------------------------------------");
 
     /* Create segmented format files for cost layer and output layer */

Modified: grass/branches/releasebranch_7_0/raster/r.walk/r.walk.html
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.walk/r.walk.html	2015-01-23 19:38:50 UTC (rev 64287)
+++ grass/branches/releasebranch_7_0/raster/r.walk/r.walk.html	2015-01-23 19:39:26 UTC (rev 64288)
@@ -110,6 +110,17 @@
 running <em><a href="r.drain.html">r.drain</a></em> to ensure the path
 is computed according to the proper movement directions.
 
+<p>
+<em>r.walk</em>, like most all GRASS raster programs, is also made to 
+be run on maps larger that can fit in available computer memory. As the 
+algorithm works through the dynamic list of cells it can move almost 
+randomly around the entire area. <em>r.walk</em> divides the entire 
+area into a number of pieces and swaps these pieces in and out of 
+memory (to and from disk) as needed. This provides a virtual memory 
+approach optimally designed for 2-D raster maps. The amount of memory 
+to be used by <em>r.walk</em> can be controlled with the <b>memory</b> 
+option, default is 300 MB. For systems with less memory this value will 
+have to be set to a lower value.
 
 <h2>REFERENCES</h2>
 

Modified: grass/branches/releasebranch_7_0/raster/r.walk/stash.h
===================================================================
--- grass/branches/releasebranch_7_0/raster/r.walk/stash.h	2015-01-23 19:38:50 UTC (rev 64287)
+++ grass/branches/releasebranch_7_0/raster/r.walk/stash.h	2015-01-23 19:39:26 UTC (rev 64288)
@@ -14,6 +14,7 @@
 #define __STASH_H__
 
 #include <stdio.h>
+
 #define      CUM_COST_LAYER        1
 #define      COST_LAYER            2
 #define      START_PT              3
@@ -32,4 +33,4 @@
 int process_answers(char **, struct start_pt **, struct start_pt **);
 int time_to_stop(int, int);
 
-#endif
+#endif /* __STASH_H__ */



More information about the grass-commit mailing list