[GRASS-SVN] r40743 - in grass/trunk: include lib/raster raster/r.external raster/r.quant

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jan 29 16:38:44 EST 2010


Author: glynn
Date: 2010-01-29 16:38:43 -0500 (Fri, 29 Jan 2010)
New Revision: 40743

Modified:
   grass/trunk/include/rasterdefs.h
   grass/trunk/lib/raster/closecell.c
   grass/trunk/lib/raster/quant_rw.c
   grass/trunk/lib/raster/range.c
   grass/trunk/raster/r.external/main.c
   grass/trunk/raster/r.quant/main.c
Log:
Errors writing range, quant files generates error instead of returning status


Modified: grass/trunk/include/rasterdefs.h
===================================================================
--- grass/trunk/include/rasterdefs.h	2010-01-29 21:37:33 UTC (rev 40742)
+++ grass/trunk/include/rasterdefs.h	2010-01-29 21:38:43 UTC (rev 40743)
@@ -79,7 +79,7 @@
 
 /* cellstats_eq.c */
 int Rast_cell_stats_histo_eq(struct Cell_stats *, CELL, CELL, CELL, CELL, int,
-			  void (*)(CELL, CELL, CELL));
+			     void (*)(CELL, CELL, CELL));
 
 /* closecell.c */
 void Rast_close(int);
@@ -314,7 +314,7 @@
 			 unsigned char *);
 /* histo_eq.c */
 void Rast_histogram_eq(const struct Histogram *, unsigned char **,
-		    CELL *, CELL *);
+		       CELL *, CELL *);
 
 /* histogram.c */
 void Rast_init_histogram(struct Histogram *);
@@ -459,12 +459,12 @@
 int Rast__quant_export(const char *, const char *, const struct Quant *);
 
 /* quant_rw.c */
-int Rast_truncate_fp_map(const char *, const char *);
-int Rast_round_fp_map(const char *, const char *);
-int Rast_quantize_fp_map(const char *, const char *, CELL, CELL);
-int Rast_quantize_fp_map_range(const char *, const char *, DCELL, DCELL, CELL,
-			    CELL);
-int Rast_write_quant(const char *, const char *, const struct Quant *);
+void Rast_truncate_fp_map(const char *, const char *);
+void Rast_round_fp_map(const char *, const char *);
+void Rast_quantize_fp_map(const char *, const char *, CELL, CELL);
+void Rast_quantize_fp_map_range(const char *, const char *, DCELL, DCELL, CELL,
+				CELL);
+void Rast_write_quant(const char *, const char *, const struct Quant *);
 int Rast_read_quant(const char *, const char *, struct Quant *);
 
 /* range.c */
@@ -472,8 +472,8 @@
 void Rast_construct_default_range(struct Range *);
 int Rast_read_fp_range(const char *, const char *, struct FPRange *);
 int Rast_read_range(const char *, const char *, struct Range *);
-int Rast_write_range(const char *, const struct Range *);
-int Rast_write_fp_range(const char *, const struct FPRange *);
+void Rast_write_range(const char *, const struct Range *);
+void Rast_write_fp_range(const char *, const struct FPRange *);
 void Rast_update_range(CELL, struct Range *);
 void Rast_update_fp_range(DCELL, struct FPRange *);
 void Rast_row_update_range(const CELL *, int, struct Range *);

Modified: grass/trunk/lib/raster/closecell.c
===================================================================
--- grass/trunk/lib/raster/closecell.c	2010-01-29 21:37:33 UTC (rev 40742)
+++ grass/trunk/lib/raster/closecell.c	2010-01-29 21:38:43 UTC (rev 40743)
@@ -223,8 +223,7 @@
 	   }
 	 */
 	Rast_quant_round(&fcb->quant);
-	if (Rast_write_quant(fcb->name, fcb->mapset, &fcb->quant) < 0)
-	    G_warning(_("unable to write quant file!"));
+	Rast_write_quant(fcb->name, fcb->mapset, &fcb->quant);
     }
     else {
 	/* remove cell_misc/name/f_quant */

Modified: grass/trunk/lib/raster/quant_rw.c
===================================================================
--- grass/trunk/lib/raster/quant_rw.c	2010-01-29 21:37:33 UTC (rev 40742)
+++ grass/trunk/lib/raster/quant_rw.c	2010-01-29 21:38:43 UTC (rev 40743)
@@ -27,22 +27,15 @@
 
    \param name map name
    \param mapset mapset name
-
-   \return -1 on error
-   \return 1 on success
  */
-int Rast_truncate_fp_map(const char *name, const char *mapset)
+void Rast_truncate_fp_map(const char *name, const char *mapset)
 {
     struct Quant quant;
 
     Rast_quant_init(&quant);
     Rast_quant_truncate(&quant);
     /* quantize the map */
-    if (Rast_write_quant(name, mapset, &quant) < 0) {
-	G_warning(_("Unable to write quant rules for raster map <%s>"), name);
-	return -1;
-    }
-    return 1;
+    Rast_write_quant(name, mapset, &quant);
 }
 
 /*!
@@ -54,22 +47,15 @@
 
    \param name map name
    \param mapset mapset name
-
-   \return -1 on error
-   \return 1 on success
  */
-int Rast_round_fp_map(const char *name, const char *mapset)
+void Rast_round_fp_map(const char *name, const char *mapset)
 {
     struct Quant quant;
 
     Rast_quant_init(&quant);
     Rast_quant_round(&quant);
     /* round the map */
-    if (Rast_write_quant(name, mapset, &quant) < 0) {
-	G_warning(_("Unable to write quant rules for raster map <%s>"), name);
-	return -1;
-    }
-    return 1;
+    Rast_write_quant(name, mapset, &quant);
 }
 
 /*!
@@ -91,28 +77,21 @@
  * \param mapset mapset name
  * \param cmin minimum value
  * \param cmax maximum value
- *
- * \return -1 on error
- * \return 1 on success
  */
-int Rast_quantize_fp_map(const char *name, const char *mapset,
-			 CELL min, CELL max)
+void Rast_quantize_fp_map(const char *name, const char *mapset,
+			  CELL min, CELL max)
 {
     DCELL d_min, d_max;
     struct FPRange fp_range;
 
-    if (Rast_read_fp_range(name, mapset, &fp_range) < 0) {
-	G_warning(_("Unable to read fp range for raster map <%s>"),
-		  G_fully_qualified_name(name, mapset));
-	return -1;
-    }
+    if (Rast_read_fp_range(name, mapset, &fp_range) < 0)
+	G_fatal_error(_("Unable to read fp range for raster map <%s>"),
+		      G_fully_qualified_name(name, mapset));
     Rast_get_fp_range_min_max(&fp_range, &d_min, &d_max);
-    if (Rast_is_d_null_value(&d_min) || Rast_is_d_null_value(&d_max)) {
-	G_warning(_("Raster map <%s> is empty"),
-		  G_fully_qualified_name(name, mapset));
-	return -1;
-    }
-    return Rast_quantize_fp_map_range(name, mapset, d_min, d_max, min, max);
+    if (Rast_is_d_null_value(&d_min) || Rast_is_d_null_value(&d_max))
+	G_fatal_error(_("Raster map <%s> is empty"),
+		      G_fully_qualified_name(name, mapset));
+    Rast_quantize_fp_map_range(name, mapset, d_min, d_max, min, max);
 }
 
 /*!
@@ -141,23 +120,16 @@
  * \param d_max maximum fp value
  * \param min minimum value
  * \param max maximum value
- *
- * \return -1 on error
- * \return 1 on success
  */
-int Rast_quantize_fp_map_range(const char *name, const char *mapset,
-			       DCELL d_min, DCELL d_max, CELL min, CELL max)
+void Rast_quantize_fp_map_range(const char *name, const char *mapset,
+				DCELL d_min, DCELL d_max, CELL min, CELL max)
 {
     struct Quant quant;
 
     Rast_quant_init(&quant);
     Rast_quant_add_rule(&quant, d_min, d_max, min, max);
     /* quantize the map */
-    if (Rast_write_quant(name, mapset, &quant) < 0) {
-	G_warning(_("Unable to write quant rules for raster map <%s>"), name);
-	return -1;
-    }
-    return 1;
+    Rast_write_quant(name, mapset, &quant);
 }
 
 /*!
@@ -174,12 +146,9 @@
  * \param name map name
  * \param mapset mapset name
  * \param quant pointer to Quant structure which hold quant rules info
- * 
- * \return -1 on error
- * \return 1 on success
  */
-int Rast_write_quant(const char *name, const char *mapset,
-		     const struct Quant *quant)
+void Rast_write_quant(const char *name, const char *mapset,
+		      const struct Quant *quant)
 {
     CELL cell_min, cell_max;
     DCELL d_min, d_max;
@@ -187,18 +156,14 @@
     if (Rast_map_type(name, mapset) == CELL_TYPE) {
 	G_warning(_("Unable to write quant rules: raster map <%s> is integer"),
 		  name);
-	return -1;
+	return;
     }
 
     Rast_quant_get_limits(quant, &d_min, &d_max, &cell_min, &cell_max);
 
     /* first actually write the rules */
-    if (Rast__quant_export(name, mapset, quant) < 0) {
-	G_warning(_("Unable to write quant rules for raster map <%s>"), name);
-	return -1;
-    }
-
-    return 1;
+    if (Rast__quant_export(name, mapset, quant) < 0)
+	G_fatal_error(_("Unable to write quant rules for raster map <%s>"), name);
 }
 
 /*!

Modified: grass/trunk/lib/raster/range.c
===================================================================
--- grass/trunk/lib/raster/range.c	2010-01-29 21:37:33 UTC (rev 40742)
+++ grass/trunk/lib/raster/range.c	2010-01-29 21:38:43 UTC (rev 40743)
@@ -257,37 +257,27 @@
  *
  * \param name map name
  * \param range pointer to Range structure which holds range info
- *
- * \return -1 on error (or raster map is floating-point)
- * \return 0 on success
  */
-int Rast_write_range(const char *name, const struct Range *range)
+void Rast_write_range(const char *name, const struct Range *range)
 {
-    FILE *fd;
+    FILE *fp;
 
     if (Rast_map_type(name, G_mapset()) != CELL_TYPE) {
 	G_remove_misc("cell_misc", "range", name);	/* remove the old file with this name */
-	G_warning(_("Unable to write range file for <%s>"), name);
-	return -1;
+	G_fatal_error(_("Unable to write range file for <%s>"), name);
     }
 
-    fd = G_fopen_new_misc("cell_misc", "range", name);
-    if (!fd) {
+    fp = G_fopen_new_misc("cell_misc", "range", name);
+    if (!fp) {
 	G_remove_misc("cell_misc", "range", name);	/* remove the old file with this name */
-	G_warning(_("Unable to write range file for <%s>"), name);
-	return -1;
+	G_fatal_error(_("Unable to write range file for <%s>"), name);
     }
 
-    /* if range hasn't been updated */
-    if (range->first_time) {
-	fclose(fd);
-	return 0;
-    }
+    /* if range has been updated */
+    if (!range->first_time)
+	fprintf(fp, "%ld %ld\n", (long)range->min, (long)range->max);
 
-    fprintf(fd, "%ld %ld\n", (long)range->min, (long)range->max);
-    fclose(fd);
-
-    return 0;
+    fclose(fp);
 }
 
 /*!
@@ -299,11 +289,8 @@
  *
  * \param name map name
  * \param range pointer to FPRange which holds fp range info
- *
- * \return 0 on success
- * \return -1 on error
  */
-int Rast_write_fp_range(const char *name, const struct FPRange *range)
+void Rast_write_fp_range(const char *name, const struct FPRange *range)
 {
     int fd;
     char xdr_buf[100];
@@ -312,14 +299,13 @@
     fd = G_open_new_misc("cell_misc", "f_range", name);
     if (fd < 0) {
 	G_remove_misc("cell_misc", "f_range", name);
-	G_warning(_("Unable to write range file for <%s>"), name);
-	return -1;
+	G_fatal_error(_("Unable to write range file for <%s>"), name);
     }
 
     /* if range hasn't been updated, write empty file meaning Nulls */
     if (range->first_time) {
 	close(fd);
-	return 0;
+	return;
     }
 
     xdrmem_create(&xdr_str, xdr_buf, (u_int) XDR_DOUBLE_NBYTES * 2,
@@ -327,20 +313,16 @@
 
     if (!xdr_double(&xdr_str, (double *)&(range->min))) {
 	G_remove_misc("cell_misc", "f_range", name);
-	G_warning(_("Unable to write range file for <%s>"), name);
-	return -1;
+	G_fatal_error(_("Unable to write range file for <%s>"), name);
     }
 
     if (!xdr_double(&xdr_str, (double *)&(range->max))) {
 	G_remove_misc("cell_misc", "f_range", name);
-	G_warning(_("Unable to write range file for <%s>"), name);
-	return -1;
+	G_fatal_error(_("Unable to write range file for <%s>"), name);
     }
 
     write(fd, xdr_buf, XDR_DOUBLE_NBYTES * 2);
     close(fd);
-
-    return 0;
 }
 
 /*!

Modified: grass/trunk/raster/r.external/main.c
===================================================================
--- grass/trunk/raster/r.external/main.c	2010-01-29 21:37:33 UTC (rev 40742)
+++ grass/trunk/raster/r.external/main.c	2010-01-29 21:38:43 UTC (rev 40743)
@@ -453,8 +453,7 @@
     Rast_quant_init(&quant);
     Rast_quant_round(&quant);
 
-    if (Rast_write_quant(output, G_mapset(), &quant) < 0)
-	G_warning(_("Unable to write quant file"));
+    Rast_write_quant(output, G_mapset(), &quant);
 }
 
 static void create_map(const char *input, int band, const char *output,

Modified: grass/trunk/raster/r.quant/main.c
===================================================================
--- grass/trunk/raster/r.quant/main.c	2010-01-29 21:37:33 UTC (rev 40742)
+++ grass/trunk/raster/r.quant/main.c	2010-01-29 21:38:43 UTC (rev 40743)
@@ -179,10 +179,8 @@
     }				/* use rules */
 
     for (i = 0; i < noi; i++) {
-	if (Rast_write_quant(name[i], G_mapset(), &quant_struct) < 0)
-	    G_message(_("Quant table not changed for %s"), name[i]);
-	else
-	    G_message(_("New quant table created for %s"), name[i]);
+	Rast_write_quant(name[i], G_mapset(), &quant_struct);
+	G_message(_("New quant table created for %s"), name[i]);
     }
 
     exit(EXIT_SUCCESS);



More information about the grass-commit mailing list