[GRASS-SVN] r34760 - grass/branches/develbranch_6/raster/r.surf.fractal

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Dec 6 17:39:44 EST 2008


Author: martinl
Date: 2008-12-06 17:39:43 -0500 (Sat, 06 Dec 2008)
New Revision: 34760

Removed:
   grass/branches/develbranch_6/raster/r.surf.fractal/open_files.c
Modified:
   grass/branches/develbranch_6/raster/r.surf.fractal/description.html
   grass/branches/develbranch_6/raster/r.surf.fractal/frac.h
   grass/branches/develbranch_6/raster/r.surf.fractal/interface.c
   grass/branches/develbranch_6/raster/r.surf.fractal/main.c
   grass/branches/develbranch_6/raster/r.surf.fractal/process.c
   grass/branches/develbranch_6/raster/r.surf.fractal/spec_syn.c
   grass/branches/develbranch_6/raster/r.surf.fractal/write_rast.c
Log:
r.surf.fractal: avoid segfault on G_malloc
		parameters key consolidated
		message standardization


Modified: grass/branches/develbranch_6/raster/r.surf.fractal/description.html
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.fractal/description.html	2008-12-06 20:35:57 UTC (rev 34759)
+++ grass/branches/develbranch_6/raster/r.surf.fractal/description.html	2008-12-06 22:39:43 UTC (rev 34760)
@@ -31,11 +31,11 @@
 <em><a href="v.surf.idw.html">v.surf.idw</a></em>,
 <em><a href="v.surf.rst.html">v.surf.rst</a></em>
 
+<h2>AUTHOR</h2>
 
-<address>
-<a href="MAILTO:jwo at le.ac.uk">jwo at le.ac.uk</a></address>
+Jo Wood,
+Midlands Regional Research Laboratory (ASSIST),
+University of Leicester
 
-<br><a href="http://www.geog.le.ac.uk/assist/index.html">ASSIST's home</a>
-
 <p>
 <i>Last changed: $Date$</i>

Modified: grass/branches/develbranch_6/raster/r.surf.fractal/frac.h
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.fractal/frac.h	2008-12-06 20:35:57 UTC (rev 34759)
+++ grass/branches/develbranch_6/raster/r.surf.fractal/frac.h	2008-12-06 22:39:43 UTC (rev 34760)
@@ -43,9 +43,6 @@
 /* interface.c */
 int interface(int, char *[]);
 
-/* open_files.c */
-int open_files(void);
-
 /* process.c */
 int process(void);
 int data_reset(double *[2], int);

Modified: grass/branches/develbranch_6/raster/r.surf.fractal/interface.c
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.fractal/interface.c	2008-12-06 20:35:57 UTC (rev 34759)
+++ grass/branches/develbranch_6/raster/r.surf.fractal/interface.c	2008-12-06 22:39:43 UTC (rev 34760)
@@ -33,7 +33,7 @@
     G_gisinit(argv[0]);		/* Link with GRASS interface.      */
 
     module = G_define_module();
-    module->keywords = _("raster");
+    module->keywords = _("raster, DEM, fractal");
     module->description =
 	_("Creates a fractal surface of a given fractal dimension.");
 
@@ -42,27 +42,17 @@
 
     /*---------------------------------------------------------------------*/
 
-    rast_out = G_define_option();
-    frac_dim = G_define_option();
-    num_images = G_define_option();
+    rast_out = G_define_standard_option(G_OPT_R_OUTPUT);
 
-    /* Each option needs a 'key' (short description),
-       a 'description` (a longer one),
-       a 'type' (eg intiger, or string),
-       and an indication whether manditory or not */
-
-    rast_out->key = "out";
-    rast_out->description = _("Name of fractal surface raster layer");
-    rast_out->type = TYPE_STRING;
-    rast_out->required = YES;
-
-    frac_dim->key = "d";
+    frac_dim = G_define_option();
+    frac_dim->key = "dimension";
     frac_dim->description = _("Fractal dimension of surface (2 < D < 3)");
     frac_dim->type = TYPE_DOUBLE;
     frac_dim->required = NO;
     frac_dim->answer = "2.05";
 
-    num_images->key = "n";
+    num_images = G_define_option();
+    num_images->key = "number";
     num_images->description = _("Number of intermediate images to produce");
     num_images->type = TYPE_INTEGER;
     num_images->required = NO;
@@ -76,7 +66,7 @@
     H = 3.0 - H;
     Steps = atoi(num_images->answer) + 1;
 
-    G_message(_("Steps=%d"), Steps);
+    G_debug(1, "Steps %d", Steps);
 
     /*--------------------------------------------------------------------*/
     /*                  CHECK OUTPUT RASTER FILE DOES NOT EXIST           */
@@ -95,7 +85,7 @@
     /*--------------------------------------------------------------------*/
 
     if ((H <= 0) || (H >= 1)) {
-	G_fatal_error(_("Fractal dimension of [%.2lf] must be between 2 and 3."),
+	G_fatal_error(_("Fractal dimension of %.2lf must be between 2 and 3."),
 		      3.0 - H);
     }
 

Modified: grass/branches/develbranch_6/raster/r.surf.fractal/main.c
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.fractal/main.c	2008-12-06 20:35:57 UTC (rev 34759)
+++ grass/branches/develbranch_6/raster/r.surf.fractal/main.c	2008-12-06 22:39:43 UTC (rev 34760)
@@ -4,7 +4,7 @@
  * MODULE:       r.surf.fractal
  * AUTHOR(S):    Jo Wood, 19th October, 1994
  * PURPOSE:      GRASS module to manipulate a raster map layer.
- * COPYRIGHT:    (C) 2005 by the GRASS Development Team
+ * COPYRIGHT:    (C) 2005-2008 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
@@ -14,6 +14,8 @@
 
 #define MAIN
 
+#include <grass/glocale.h>
+
 #include "frac.h"
 
 int main(int argc, char *argv[])
@@ -34,5 +36,7 @@
 
     process();
 
+    G_done_msg(_("Raster map <%s> created."), rast_out_name);
+    
     return EXIT_SUCCESS;
 }

Deleted: grass/branches/develbranch_6/raster/r.surf.fractal/open_files.c
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.fractal/open_files.c	2008-12-06 20:35:57 UTC (rev 34759)
+++ grass/branches/develbranch_6/raster/r.surf.fractal/open_files.c	2008-12-06 22:39:43 UTC (rev 34760)
@@ -1,28 +0,0 @@
-
-/*****************************************************************************/
-
-/***                                                                       ***/
-
-/***                             open_files()                              ***/
-
-/***           Opens input and output raster maps for r.example	   ***/
-
-/***                    Jo Wood, V1.0, 13th September, 1994                ***/
-
-/***                                                                       ***/
-
-/*****************************************************************************/
-
-#include <grass/glocale.h>
-#include "frac.h"
-
-int open_files(void)
-{
-    /* Open new file and set the output file descriptor. */
-
-    if ((fd_out = G_open_cell_new(rast_out_name)) < 0) {
-	G_fatal_error(_("ERROR: Problem opening output file."));
-    }
-
-    return 0;
-}

Modified: grass/branches/develbranch_6/raster/r.surf.fractal/process.c
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.fractal/process.c	2008-12-06 20:35:57 UTC (rev 34759)
+++ grass/branches/develbranch_6/raster/r.surf.fractal/process.c	2008-12-06 22:39:43 UTC (rev 34760)
@@ -13,8 +13,9 @@
 
 /***************************************************************************/
 
+#include <grass/gmath.h>
+#include <grass/glocale.h>
 #include "frac.h"
-#include <grass/gmath.h>
 
 int process(void)
 {
@@ -47,6 +48,10 @@
 
     /*------------------------------------------------------------------*/
 
+    if (nn * nn * sizeof(double) < 1)
+	G_fatal_error(_("Unable to allocate data buffer. "
+			"Check current region with g.region."));
+    
     data[0] = (double *)G_malloc(nn * nn * sizeof(double));
     data[1] = (double *)G_malloc(nn * nn * sizeof(double));
 

Modified: grass/branches/develbranch_6/raster/r.surf.fractal/spec_syn.c
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.fractal/spec_syn.c	2008-12-06 20:35:57 UTC (rev 34759)
+++ grass/branches/develbranch_6/raster/r.surf.fractal/spec_syn.c	2008-12-06 22:39:43 UTC (rev 34760)
@@ -58,7 +58,7 @@
     /* Calculate all the preliminary random coefficients. */
     /* ================================================== */
 
-    G_message(_("Preliminary surface calculations."));
+    G_message(_("Preliminary surface calculations..."));
     data_reset(data, nn);
 
     for (row = 0; row <= nn / 2; row++)
@@ -117,7 +117,7 @@
     /* ========================================================= */
 
     for (coeff = 0; coeff < Steps; coeff++) {
-	G_message(_("Calculating surface %d (of %d)"), coeff + 1, Steps);
+	G_message(_("Calculating surface %d (of %d)..."), coeff + 1, Steps);
 	data_reset(temp, nn);
 
 	for (row = 0; row <= (coeff + 1) * nn / (Steps * 2); row++)

Modified: grass/branches/develbranch_6/raster/r.surf.fractal/write_rast.c
===================================================================
--- grass/branches/develbranch_6/raster/r.surf.fractal/write_rast.c	2008-12-06 20:35:57 UTC (rev 34759)
+++ grass/branches/develbranch_6/raster/r.surf.fractal/write_rast.c	2008-12-06 22:39:43 UTC (rev 34760)
@@ -55,7 +55,8 @@
 	G_strcpy(file_name, rast_out_name);
 
     if ((fd_out = G_open_raster_new(file_name, DCELL_TYPE)) < 0) {
-	G_fatal_error(_("ERROR: Problem opening output file."));
+	G_fatal_error(_("Unable to create raster map <%s>"),
+		      file_name);
     }
 
     /*------------------------------------------------------------------*/



More information about the grass-commit mailing list