[GRASS-SVN] r33984 - grass-addons/raster/r.viewshed
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Oct 22 17:55:02 EDT 2008
Author: neteler
Date: 2008-10-22 17:55:01 -0400 (Wed, 22 Oct 2008)
New Revision: 33984
Modified:
grass-addons/raster/r.viewshed/viewshed.cc
Log:
ltoma: bugfix for available memory detection
Modified: grass-addons/raster/r.viewshed/viewshed.cc
===================================================================
--- grass-addons/raster/r.viewshed/viewshed.cc 2008-10-22 17:28:21 UTC (rev 33983)
+++ grass-addons/raster/r.viewshed/viewshed.cc 2008-10-22 21:55:01 UTC (rev 33984)
@@ -8,7 +8,7 @@
* Ported to GRASS by William Richard -
* wkrichar at bowdoin.edu or willster3021 at gmail.com
*
- * Date: july 2008
+ * Date: oct 2008
*
* PURPOSE: To calculate the viewshed (the visible cells in the
* raster) for the given viewpoint (observer) location. The
@@ -44,17 +44,16 @@
#include "visibility.h"
#include "eventlist.h"
#include "statusstructure.h"
-
#ifdef __GRASS
#include "grass.h"
#endif
#define VIEWSHEDDEBUG if(0)
+#define INMEMORY_DEBUG if(0)
-
/* ------------------------------------------------------------ */
/* return the memory usage (in bytes) of viewshed */
long long get_viewshed_memory_usage(GridHeader* hd) {
@@ -63,7 +62,7 @@
assert(hd);
/* the output visibility grid */
long long totalcells = (long long)hd->nrows * (long long)hd->ncols;
- VIEWSHEDDEBUG {printf("rows=%d, cols=%d, total = %lld\n", hd->nrows, hd->ncols, totalcells);}
+ printf("rows=%d, cols=%d, total = %lld\n", hd->nrows, hd->ncols, totalcells);
long long gridMemUsage = totalcells * sizeof(float);
VIEWSHEDDEBUG {printf("grid usage=%lld\n", gridMemUsage);}
@@ -75,7 +74,7 @@
as the viewpoint */
long long dataMemUsage = (long long)(hd->ncols * sizeof(double));
- printf("get_viewshed_memory usage: size AEvent=%dB, nevents=%lld, \
+ printf("viewshed memory usage: size AEvent=%dB, nevents=%lld, \
total=%lld B (%d MB)\n",
(int)sizeof(AEvent), totalcells*3,
gridMemUsage + eventListMemUsage + dataMemUsage,
@@ -115,7 +114,7 @@
/* ------------------------------------------------------------ */
-static void print_event(StatusNode sn)
+static void print_statusnode(StatusNode sn)
{
printf("processing (row=%d, col=%d, elev=%f, dist=%f, grad=%f)",
sn.row, sn.col, sn.elev, sn.dist2vp, sn.gradient);
@@ -125,7 +124,10 @@
/* ------------------------------------------------------------ */
-/* allocates the eventlist array used by kreveled_in_memory */
+/* allocates the eventlist array used by kreveled_in_memory; it is
+ possible that the amount of memory required is more than that
+ supported by the platform; for e.g. on a 32-bt platform cannot
+ allocate more than 4GB. Try to detect this situation. */
AEvent*
allocate_eventlist(GridHeader* hd) {
@@ -135,14 +137,24 @@
totalsize *= sizeof(AEvent);
printf("total size of eventlist is %lld B (%d MB); ",
totalsize, (int)(totalsize>>20));
+
+ /* what's the size of size_t on this machine? */
+ int sizet_size;
+ sizet_size = (int) sizeof(size_t);
printf("size_t is %lu B\n", sizeof(size_t));
- /* checking whether allocating totalsize causes an overflow */
- long long maxsizet = ((long long)1<<(sizeof(size_t)*8)) -1;
- printf("max size_t is %lld\n", maxsizet);
- if (totalsize > maxsizet) {
- printf("running the program in-memory mode requires memory beyond the capability of the platform. Use external mode, or 64-bit platform.\n");
- exit(1);
+ if (sizet_size >= 8) {
+ printf("64-bit platform, great.\n");
+ } else {
+ /* this is the max value of size_t */
+ long long maxsizet = ((long long)1<<(sizeof(size_t)*8)) -1;
+ printf("max size_t is %lld\n", maxsizet);
+
+ /* checking whether allocating totalsize causes an overflow */
+ if (totalsize > maxsizet) {
+ printf("running the program in-memory mode requires memory beyond the capability of the platform. Use external mode, or 64-bit platform.\n");
+ exit(1);
+ }
}
printf("allocating..");
@@ -262,7 +274,7 @@
calculate_dist_n_gradient(&sn, vp);
VIEWSHEDDEBUG {
printf("inserting: ");
- print_event(sn);
+ print_statusnode(sn);
printf("\n");
}
/*insert sn into the status structure */
@@ -293,9 +305,10 @@
/*calculate Distance to VP and Gradient */
calculate_dist_n_gradient(&sn, vp);
- VIEWSHEDDEBUG {
- printf("next event: ");
- print_event(sn);
+ INMEMORY_DEBUG {
+ printf("event: ");
+ print_event(*e);
+ printf("sn.dist=%f, sn.gradient=%f\n", sn.dist2vp, sn.gradient);
}
switch (e->eventType) {
@@ -439,7 +452,7 @@
calculate_dist_n_gradient(&sn, vp);
VIEWSHEDDEBUG {
printf("inserting: ");
- print_event(sn);
+ print_statusnode(sn);
printf("\n");
}
/*insert sn into the status structure */
@@ -476,7 +489,7 @@
calculate_dist_n_gradient(&sn, vp);
VIEWSHEDDEBUG {
printf("next event: ");
- print_event(sn);
+ print_statusnode(sn);
}
switch (e->eventType) {
More information about the grass-commit
mailing list