[GRASS-SVN] r71295 - grass/branches/releasebranch_7_2/raster/r.random

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jul 22 05:20:36 PDT 2017


Author: annakrat
Date: 2017-07-22 05:20:36 -0700 (Sat, 22 Jul 2017)
New Revision: 71295

Modified:
   grass/branches/releasebranch_7_2/raster/r.random/count.c
   grass/branches/releasebranch_7_2/raster/r.random/local_proto.h
   grass/branches/releasebranch_7_2/raster/r.random/main.c
   grass/branches/releasebranch_7_2/raster/r.random/random.c
   grass/branches/releasebranch_7_2/raster/r.random/support.c
Log:
r.random: use long long when available (merge from trunk, r71074, r71075)

Modified: grass/branches/releasebranch_7_2/raster/r.random/count.c
===================================================================
--- grass/branches/releasebranch_7_2/raster/r.random/count.c	2017-07-22 11:59:19 UTC (rev 71294)
+++ grass/branches/releasebranch_7_2/raster/r.random/count.c	2017-07-22 12:20:36 UTC (rev 71295)
@@ -55,12 +55,12 @@
     nrows = Rast_window_rows();
     ncols = Rast_window_cols();
 
-    theState->nCells = (long) nrows * ncols;
+    theState->nCells = (gcell_count) nrows * ncols;
     theState->nNulls = 0;
     set_min(NULL, 0, &theState->min);
     set_max(NULL, 0, &theState->max);
     if (theState->docover == 1) {
-	theState->cnCells = nrows * ncols;
+	theState->cnCells = (gcell_count) nrows * ncols;
 	theState->cnNulls = 0;
 	set_min(NULL, 0, &theState->cmin);
 	set_max(NULL, 0, &theState->cmax);

Modified: grass/branches/releasebranch_7_2/raster/r.random/local_proto.h
===================================================================
--- grass/branches/releasebranch_7_2/raster/r.random/local_proto.h	2017-07-22 11:59:19 UTC (rev 71294)
+++ grass/branches/releasebranch_7_2/raster/r.random/local_proto.h	2017-07-22 12:20:36 UTC (rev 71295)
@@ -22,12 +22,18 @@
 
 /* End from Huidae Cho */
 
+#ifdef HAVE_LONG_LONG_INT
+typedef unsigned long long gcell_count;
+#else
+typedef unsigned long gcell_count;
+#endif
+
 /* Put all the state infomation into a struct */
 struct rr_state
 {
     char *inraster, *inrcover, *outraster, *outvector;
     int use_nulls, docover, fd_old, fd_cold, fd_new;
-    long nCells, nNulls, nRand, cnCells, cnNulls;
+    gcell_count nCells, nNulls, nRand, cnCells, cnNulls;
     struct RASTER_MAP_PTR nulls, cnulls, buf, cover, min, max, cmin, cmax;
     FILE *fsites;
     int z_geometry;

Modified: grass/branches/releasebranch_7_2/raster/r.random/main.c
===================================================================
--- grass/branches/releasebranch_7_2/raster/r.random/main.c	2017-07-22 11:59:19 UTC (rev 71294)
+++ grass/branches/releasebranch_7_2/raster/r.random/main.c	2017-07-22 12:20:36 UTC (rev 71295)
@@ -31,8 +31,8 @@
 {
     short percent;
     double percentage;
-    long targets;
-    long count;
+    gcell_count targets;
+    gcell_count count;
     struct rr_state myState;
 
     struct GModule *module;
@@ -121,13 +121,21 @@
     get_stats(&myState);
 
     if (flag.info->answer) {
+#ifdef HAVE_LONG_LONG_INT
 	G_message("Raster:      %s\n"
 		  "Cover:       %s\n"
-		  "Cell Count:  %d\n"
-		  "Null Cells:  %d\n\n",
+		  "Cell Count:  %llu\n"
+		  "Null Cells:  %llu\n\n",
 		  myState.inraster, myState.inrcover,
-		  (int)myState.nCells, (int)myState.nNulls);
-
+		  myState.nCells, myState.nNulls);
+#else
+	G_message("Raster:      %s\n"
+		  "Cover:       %s\n"
+		  "Cell Count:  %lu\n"
+		  "Null Cells:  %lu\n\n",
+		  myState.inraster, myState.inrcover,
+		  myState.nCells, myState.nNulls);
+#endif
 	exit(EXIT_SUCCESS);
     }
 
@@ -145,7 +153,11 @@
 	}
     }
     else {
-	if (sscanf(parm.npoints->answer, "%ld", &targets) != 1
+#ifdef HAVE_LONG_LONG_INT
+	if (sscanf(parm.npoints->answer, "%llu", &targets) != 1
+#else
+	if (sscanf(parm.npoints->answer, "%lu", &targets) != 1
+#endif
 	    || targets <= 0) {
 	    G_fatal_error(_("<%s=%s> invalid number of points"),
 			  parm.npoints->key, parm.npoints->answer);
@@ -156,15 +168,24 @@
 	myState.nCells - myState.nNulls;
 
     if (percent)
-	myState.nRand = (int)(count * percentage / 100.0 + .5);
+	myState.nRand = (gcell_count)(count * percentage / 100.0 + .5);
     else {
 	if (targets > count) {
+#ifdef HAVE_LONG_LONG_INT
 	    if (myState.use_nulls)
-		G_fatal_error(_("There aren't [%ld] cells in the current region"),
+		G_fatal_error(_("There aren't [%llu] cells in the current region"),
 			      targets);
 	    else
-		G_fatal_error(_("There aren't [%ld] non-NULL cells in the current region"),
+		G_fatal_error(_("There aren't [%llu] non-NULL cells in the current region"),
 			      targets);
+#else
+	    if (myState.use_nulls)
+		G_fatal_error(_("There aren't [%lu] cells in the current region"),
+			      targets);
+	    else
+		G_fatal_error(_("There aren't [%lu] non-NULL cells in the current region"),
+			      targets);
+#endif
 	}
 
 	if (targets <= 0)

Modified: grass/branches/releasebranch_7_2/raster/r.random/random.c
===================================================================
--- grass/branches/releasebranch_7_2/raster/r.random/random.c	2017-07-22 11:59:19 UTC (rev 71294)
+++ grass/branches/releasebranch_7_2/raster/r.random/random.c	2017-07-22 12:20:36 UTC (rev 71295)
@@ -16,8 +16,8 @@
 
 int execute_random(struct rr_state *theState)
 {
-    long nt;
-    long nc;
+    gcell_count nt;
+    gcell_count nc;
     struct Cell_head window;
     int nrows, ncols, row, col;
     int infd, cinfd, outfd;
@@ -240,8 +240,13 @@
     }
 
     if (nt > 0)
-	G_warning(_("Only [%ld] random points created"),
+#ifdef HAVE_LONG_LONG_INT
+	G_warning(_("Only [%llu] random points created"),
 		  theState->nRand - nt);
+#else
+	G_warning(_("Only [%lu] random points created"),
+		  theState->nRand - nt);
+#endif
 
     /* close files */
     Rast_close(infd);

Modified: grass/branches/releasebranch_7_2/raster/r.random/support.c
===================================================================
--- grass/branches/releasebranch_7_2/raster/r.random/support.c	2017-07-22 11:59:19 UTC (rev 71294)
+++ grass/branches/releasebranch_7_2/raster/r.random/support.c	2017-07-22 12:20:36 UTC (rev 71295)
@@ -48,7 +48,11 @@
 	else
 	    Rast_format_history(
 		&hist, HIST_DATSRC_2,
-		"%ld random points on the base map <%s>",
+#ifdef HAVE_LONG_LONG_INT
+		"%llu random points on the base map <%s>",
+#else
+		"%lu random points on the base map <%s>",
+#endif
 		theState->nRand, theState->inraster);
 
 	Rast_command_history(&hist);



More information about the grass-commit mailing list