Browse Source

Errors writing range, quant files generates error instead of returning status

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@40743 15284696-431f-4ddb-bdfa-cd5b030d7da7
Glynn Clements 15 years ago
parent
commit
827f5b43b3
6 changed files with 50 additions and 107 deletions
  1. 10 10
      include/rasterdefs.h
  2. 1 2
      lib/raster/closecell.c
  3. 21 56
      lib/raster/quant_rw.c
  4. 15 33
      lib/raster/range.c
  5. 1 2
      raster/r.external/main.c
  6. 2 4
      raster/r.quant/main.c

+ 10 - 10
include/rasterdefs.h

@@ -79,7 +79,7 @@ char *Rast_get_cell_title(const char *, const char *);
 
 
 /* cellstats_eq.c */
 /* cellstats_eq.c */
 int Rast_cell_stats_histo_eq(struct Cell_stats *, CELL, CELL, CELL, CELL, int,
 int Rast_cell_stats_histo_eq(struct Cell_stats *, CELL, CELL, CELL, CELL, int,
-			  void (*)(CELL, CELL, CELL));
+			     void (*)(CELL, CELL, CELL));
 
 
 /* closecell.c */
 /* closecell.c */
 void Rast_close(int);
 void Rast_close(int);
@@ -314,7 +314,7 @@ void Rast_get_row_colors(int, int, struct Colors *,
 			 unsigned char *);
 			 unsigned char *);
 /* histo_eq.c */
 /* histo_eq.c */
 void Rast_histogram_eq(const struct Histogram *, unsigned char **,
 void Rast_histogram_eq(const struct Histogram *, unsigned char **,
-		    CELL *, CELL *);
+		       CELL *, CELL *);
 
 
 /* histogram.c */
 /* histogram.c */
 void Rast_init_histogram(struct Histogram *);
 void Rast_init_histogram(struct Histogram *);
@@ -459,12 +459,12 @@ int Rast__quant_import(const char *, const char *, struct Quant *);
 int Rast__quant_export(const char *, const char *, const struct Quant *);
 int Rast__quant_export(const char *, const char *, const struct Quant *);
 
 
 /* quant_rw.c */
 /* 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 *);
 int Rast_read_quant(const char *, const char *, struct Quant *);
 
 
 /* range.c */
 /* range.c */
@@ -472,8 +472,8 @@ void Rast__remove_fp_range(const char *);
 void Rast_construct_default_range(struct Range *);
 void Rast_construct_default_range(struct Range *);
 int Rast_read_fp_range(const char *, const char *, struct FPRange *);
 int Rast_read_fp_range(const char *, const char *, struct FPRange *);
 int Rast_read_range(const char *, const char *, struct Range *);
 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_range(CELL, struct Range *);
 void Rast_update_fp_range(DCELL, struct FPRange *);
 void Rast_update_fp_range(DCELL, struct FPRange *);
 void Rast_row_update_range(const CELL *, int, struct Range *);
 void Rast_row_update_range(const CELL *, int, struct Range *);

+ 1 - 2
lib/raster/closecell.c

@@ -223,8 +223,7 @@ static void write_support_files(int fd)
 	   }
 	   }
 	 */
 	 */
 	Rast_quant_round(&fcb->quant);
 	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 {
     else {
 	/* remove cell_misc/name/f_quant */
 	/* remove cell_misc/name/f_quant */

+ 21 - 56
lib/raster/quant_rw.c

@@ -27,22 +27,15 @@
 
 
    \param name map name
    \param name map name
    \param mapset mapset 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;
     struct Quant quant;
 
 
     Rast_quant_init(&quant);
     Rast_quant_init(&quant);
     Rast_quant_truncate(&quant);
     Rast_quant_truncate(&quant);
     /* quantize the map */
     /* 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 @@ int Rast_truncate_fp_map(const char *name, const char *mapset)
 
 
    \param name map name
    \param name map name
    \param mapset mapset 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;
     struct Quant quant;
 
 
     Rast_quant_init(&quant);
     Rast_quant_init(&quant);
     Rast_quant_round(&quant);
     Rast_quant_round(&quant);
     /* round the map */
     /* 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 @@ int Rast_round_fp_map(const char *name, const char *mapset)
  * \param mapset mapset name
  * \param mapset mapset name
  * \param cmin minimum value
  * \param cmin minimum value
  * \param cmax maximum 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;
     DCELL d_min, d_max;
     struct FPRange fp_range;
     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);
     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 @@ int Rast_quantize_fp_map(const char *name, const char *mapset,
  * \param d_max maximum fp value
  * \param d_max maximum fp value
  * \param min minimum value
  * \param min minimum value
  * \param max maximum 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;
     struct Quant quant;
 
 
     Rast_quant_init(&quant);
     Rast_quant_init(&quant);
     Rast_quant_add_rule(&quant, d_min, d_max, min, max);
     Rast_quant_add_rule(&quant, d_min, d_max, min, max);
     /* quantize the map */
     /* 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 @@ int Rast_quantize_fp_map_range(const char *name, const char *mapset,
  * \param name map name
  * \param name map name
  * \param mapset mapset name
  * \param mapset mapset name
  * \param quant pointer to Quant structure which hold quant rules info
  * \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;
     CELL cell_min, cell_max;
     DCELL d_min, d_max;
     DCELL d_min, d_max;
@@ -187,18 +156,14 @@ int Rast_write_quant(const char *name, const char *mapset,
     if (Rast_map_type(name, mapset) == CELL_TYPE) {
     if (Rast_map_type(name, mapset) == CELL_TYPE) {
 	G_warning(_("Unable to write quant rules: raster map <%s> is integer"),
 	G_warning(_("Unable to write quant rules: raster map <%s> is integer"),
 		  name);
 		  name);
-	return -1;
+	return;
     }
     }
 
 
     Rast_quant_get_limits(quant, &d_min, &d_max, &cell_min, &cell_max);
     Rast_quant_get_limits(quant, &d_min, &d_max, &cell_min, &cell_max);
 
 
     /* first actually write the rules */
     /* 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);
 }
 }
 
 
 /*!
 /*!

+ 15 - 33
lib/raster/range.c

@@ -257,37 +257,27 @@ int Rast_read_range(const char *name, const char *mapset, struct Range *range)
  *
  *
  * \param name map name
  * \param name map name
  * \param range pointer to Range structure which holds range info
  * \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) {
     if (Rast_map_type(name, G_mapset()) != CELL_TYPE) {
 	G_remove_misc("cell_misc", "range", name);	/* remove the old file with this name */
 	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_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;
-    }
-
-    /* if range hasn't been updated */
-    if (range->first_time) {
-	fclose(fd);
-	return 0;
+	G_fatal_error(_("Unable to write range file for <%s>"), name);
     }
     }
 
 
-    fprintf(fd, "%ld %ld\n", (long)range->min, (long)range->max);
-    fclose(fd);
+    /* if range has been updated */
+    if (!range->first_time)
+	fprintf(fp, "%ld %ld\n", (long)range->min, (long)range->max);
 
 
-    return 0;
+    fclose(fp);
 }
 }
 
 
 /*!
 /*!
@@ -299,11 +289,8 @@ int Rast_write_range(const char *name, const struct Range *range)
  *
  *
  * \param name map name
  * \param name map name
  * \param range pointer to FPRange which holds fp range info
  * \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;
     int fd;
     char xdr_buf[100];
     char xdr_buf[100];
@@ -312,14 +299,13 @@ int Rast_write_fp_range(const char *name, const struct FPRange *range)
     fd = G_open_new_misc("cell_misc", "f_range", name);
     fd = G_open_new_misc("cell_misc", "f_range", name);
     if (fd < 0) {
     if (fd < 0) {
 	G_remove_misc("cell_misc", "f_range", name);
 	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 hasn't been updated, write empty file meaning Nulls */
     if (range->first_time) {
     if (range->first_time) {
 	close(fd);
 	close(fd);
-	return 0;
+	return;
     }
     }
 
 
     xdrmem_create(&xdr_str, xdr_buf, (u_int) XDR_DOUBLE_NBYTES * 2,
     xdrmem_create(&xdr_str, xdr_buf, (u_int) XDR_DOUBLE_NBYTES * 2,
@@ -327,20 +313,16 @@ int Rast_write_fp_range(const char *name, const struct FPRange *range)
 
 
     if (!xdr_double(&xdr_str, (double *)&(range->min))) {
     if (!xdr_double(&xdr_str, (double *)&(range->min))) {
 	G_remove_misc("cell_misc", "f_range", name);
 	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))) {
     if (!xdr_double(&xdr_str, (double *)&(range->max))) {
 	G_remove_misc("cell_misc", "f_range", name);
 	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);
     write(fd, xdr_buf, XDR_DOUBLE_NBYTES * 2);
     close(fd);
     close(fd);
-
-    return 0;
 }
 }
 
 
 /*!
 /*!

+ 1 - 2
raster/r.external/main.c

@@ -453,8 +453,7 @@ static void write_fp_quant(const char *output)
     Rast_quant_init(&quant);
     Rast_quant_init(&quant);
     Rast_quant_round(&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,
 static void create_map(const char *input, int band, const char *output,

+ 2 - 4
raster/r.quant/main.c

@@ -179,10 +179,8 @@ int main(int argc, char *argv[])
     }				/* use rules */
     }				/* use rules */
 
 
     for (i = 0; i < noi; i++) {
     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);
     exit(EXIT_SUCCESS);