[GRASS-SVN] r40189 - grass/branches/develbranch_6/lib/rst/interp_float

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Jan 2 09:09:01 EST 2010


Author: martinl
Date: 2010-01-02 09:09:01 -0500 (Sat, 02 Jan 2010)
New Revision: 40189

Modified:
   grass/branches/develbranch_6/lib/rst/interp_float/interp2d.c
   grass/branches/develbranch_6/lib/rst/interp_float/output2d.c
   grass/branches/develbranch_6/lib/rst/interp_float/segmen2d.c
   grass/branches/develbranch_6/lib/rst/interp_float/vinput2d.c
Log:
librst: use G_message() instead of fprintf()
	(merge r40186 from trunk)


Modified: grass/branches/develbranch_6/lib/rst/interp_float/interp2d.c
===================================================================
--- grass/branches/develbranch_6/lib/rst/interp_float/interp2d.c	2010-01-02 14:08:18 UTC (rev 40188)
+++ grass/branches/develbranch_6/lib/rst/interp_float/interp2d.c	2010-01-02 14:09:01 UTC (rev 40189)
@@ -27,6 +27,7 @@
 #include <math.h>
 #include <unistd.h>
 #include <grass/gis.h>
+#include <grass/glocale.h>
 #include <grass/bitmap.h>
 
 #include <grass/interpf.h>
@@ -115,13 +116,13 @@
 
     if (!w) {
 	if (!(w = (double *)G_malloc(sizeof(double) * (params->KMAX2 + 9)))) {
-	    fprintf(stderr, "Cannot allocate w\n");
+	    G_warning(_("Out of memory"));
 	    return -1;
 	}
     }
     if (!w2) {
 	if (!(w2 = (double *)G_malloc(sizeof(double) * (params->KMAX2 + 9)))) {
-	    fprintf(stderr, "Cannot allocate w2\n");
+	    G_warning(_("Out of memory"));
 	    return -1;
 	}
     }
@@ -208,22 +209,15 @@
 
 		    if (!once) {
 			once = 1;
-			fprintf(stderr, "WARNING:\n");
-			fprintf(stderr,
-				"Overshoot -- increase in tension suggested.\n");
-			fprintf(stderr, "Overshoot occures at (%d,%d) cell\n",
-				l, k);
-			fprintf(stderr,
-				"The z-value is %f,zmin is %f,zmax is %f\n",
-				zz, zmin, zmax);
+			G_warning(_("Overshoot - increase in tension suggested. "
+				    "Overshoot occures at (%d,%d) cell. "
+				    "Z-value %f, zmin %f, zmax %f."),
+				  l, k, zz, zmin, zmax);
 		    }
 		}
-
-
+		
 		params->az[l] = (FCELL) zz;
-		/*
-		 * fprintf(stderr,"%f ",zz);
-		 */
+		
 		if (cond1) {
 		    params->adx[l] = (FCELL) (-dx * tfsta2);
 		    params->ady[l] = (FCELL) (-dy * tfsta2);

Modified: grass/branches/develbranch_6/lib/rst/interp_float/output2d.c
===================================================================
--- grass/branches/develbranch_6/lib/rst/interp_float/output2d.c	2010-01-02 14:08:18 UTC (rev 40188)
+++ grass/branches/develbranch_6/lib/rst/interp_float/output2d.c	2010-01-02 14:09:01 UTC (rev 40189)
@@ -121,8 +121,8 @@
 
     ncols = cellhd->cols;
     if (ncols != params->nsizc) {
-	fprintf(stderr, "first change your cols number to nsizc! %d %d\n",
-		ncols, params->nsizc);
+	G_warning(_("First change your cols number to nsizc %d %d"),
+		  ncols, params->nsizc);
 	return -1;
     }
 
@@ -587,8 +587,7 @@
 	G_short_history(params->elev, type, &hist);
 
 	params->dmin = sqrt(params->dmin);
-	fprintf(stdout, "history initiated\n");
-	fflush(stdout);
+
 	/*
 	 * sprintf (hist.edhist[0], "tension=%f, smoothing=%f", params->fi *
 	 * dnorm / 1000., params->rsm);

Modified: grass/branches/develbranch_6/lib/rst/interp_float/segmen2d.c
===================================================================
--- grass/branches/develbranch_6/lib/rst/interp_float/segmen2d.c	2010-01-02 14:08:18 UTC (rev 40188)
+++ grass/branches/develbranch_6/lib/rst/interp_float/segmen2d.c	2010-01-02 14:09:01 UTC (rev 40189)
@@ -56,7 +56,6 @@
     /* find the size of the smallest segment once */
     if (first_time) {
 	smseg = smallest_segment(info->root, 4);
-	/*      fprintf(stderr, "smseg=%lf, first=%d,\n", smseg, first_time); */
 	first_time = 0;
     }
     ns_res = (((struct quaddata *)(info->root->data))->ymax -
@@ -109,10 +108,9 @@
 
 	while ((npt < MINPTS) || (npt > params->KMAX2)) {
 	    if (i >= 70) {
-		fprintf(stderr, "\n");
-		G_warning(_("taking too long to find points for interpolation--"
-			   "please change the region to area where your points are. "
-			   "Continuing calculations..."));
+		G_warning(_("Taking too long to find points for interpolation - "
+			    "please change the region to area where your points are. "
+			    "Continuing calculations..."));
 		break;
 	    }
 	    i++;
@@ -152,7 +150,7 @@
 	    data->n_points = 0;
 	    npt = MT_region_data(info, info->root, data, params->KMAX2, 4);
 	}
-	/* show before to catch 0% */
+	
 	if (totsegm != 0) {
 	    G_percent(cursegm, totsegm, 1);
 	}
@@ -174,19 +172,19 @@
 	    if (!
 		(matrix =
 		 G_alloc_matrix(params->KMAX2 + 1, params->KMAX2 + 1))) {
-		fprintf(stderr, "Cannot allocate memory for matrix\n");
+		G_warning(_("Out of memory"));
 		return -1;
 	    }
 	}
 	if (!indx) {
 	    if (!(indx = G_alloc_ivector(params->KMAX2 + 1))) {
-		fprintf(stderr, "Cannot allocate memory for indx\n");
+		G_warning(_("Out of memory"));
 		return -1;
 	    }
 	}
 	if (!b) {
 	    if (!(b = G_alloc_vector(params->KMAX2 + 3))) {
-		fprintf(stderr, "Cannot allocate memory for b\n");
+		G_warning(_("Out of memory"));
 		return -1;
 	    }
 	}
@@ -196,7 +194,7 @@
 		(point =
 		 (struct triple *)G_malloc(sizeof(struct triple) *
 					   data->n_points))) {
-		fprintf(stderr, "Cannot allocate memory for point\n");
+		G_warning(_("Out of memory"));
 		return -1;
 	    }
 	}
@@ -305,7 +303,8 @@
 	/* show after to catch 100% */
 	cursegm++;
 	if (totsegm < cursegm)
-	    fprintf(stderr, "%d %d\n", totsegm, cursegm);
+	    G_debug(1, "%d %d", totsegm, cursegm);
+	
 	if (totsegm != 0) {
 	    G_percent(cursegm, totsegm, 1);
 	}
@@ -314,8 +313,8 @@
 	   G_free_ivector(indx);
 	   G_free_vector(b);
 	 */
-	free(data->points);
-	free(data);
+	G_free(data->points);
+	G_free(data);
     }
     return 1;
 }
@@ -337,11 +336,9 @@
 	    if (first_time) {
 		minside = side;
 		first_time = 0;
-		/*          fprintf(stderr, "FIRST,side=%lf, minside=%lf,\n", side, minside); */
 	    }
 	    if (side < minside)
 		minside = side;
-	    /*        fprintf(stderr, "SEC side=%lf, minside=%lf,\n", side, minside); */
 	}
     }
     else {
@@ -349,6 +346,6 @@
 	    ((struct quaddata *)(tree->data))->x_orig;
 	return side;
     }
-    /*    fprintf(stderr, "OUT side=%lf, minside=%lf,\n", side, minside); */
+    
     return minside;
 }

Modified: grass/branches/develbranch_6/lib/rst/interp_float/vinput2d.c
===================================================================
--- grass/branches/develbranch_6/lib/rst/interp_float/vinput2d.c	2010-01-02 14:08:18 UTC (rev 40188)
+++ grass/branches/develbranch_6/lib/rst/interp_float/vinput2d.c	2010-01-02 14:09:01 UTC (rev 40189)
@@ -70,10 +70,10 @@
     Cats = Vect_new_cats_struct();
 
     if (field == 0 && !Vect_is_3d(Map))
-	G_fatal_error(_("Vector is not 3D"));
+	G_fatal_error(_("Vector map <%s> is not 3D"), Vect_get_full_name(Map));
 
     if (field > 0 && zcol != NULL) {	/* open db driver */
-	G_message(_("Loading data from attribute table ..."));
+	G_verbose_message(_("Loading data from attribute table ..."));
 	Fi = Vect_get_field(Map, field);
 	if (Fi == NULL)
 	    G_fatal_error(_("Database connection not defined for layer %d"),
@@ -91,10 +91,10 @@
 	zctype = db_column_Ctype(driver, Fi->table, zcol);
 	G_debug(3, " zcol C type = %d", zctype);
 	if (zctype == -1)
-	    G_fatal_error(_("Cannot find z column <%s> (please verify name, e.g. with v.info)"),
+	    G_fatal_error(_("Column <%s> not found"),
 			  zcol);
 	if (zctype != DB_C_TYPE_INT && zctype != DB_C_TYPE_DOUBLE)
-	    G_fatal_error(_("Column type of z column is not supported (must be integer or double)"));
+	    G_fatal_error(_("Data type of column <%s> must be numeric"), zcol);
 
 	db_CatValArray_init(&zarray);
 	G_debug(3, "RST SQL WHERE: %s", params->wheresql);
@@ -105,11 +105,9 @@
 	    sctype = db_column_Ctype(driver, Fi->table, scol);
 	    G_debug(3, " scol C type = %d", sctype);
 	    if (sctype == -1)
-		G_fatal_error(_("Cannot read column type of smooth column"));
-	    if (sctype == DB_C_TYPE_DATETIME)
-		G_fatal_error(_("Column type of smooth column (datetime) is not supported"));
+		G_fatal_error(_("Column <%s> not found"), scol);
 	    if (sctype != DB_C_TYPE_INT && sctype != DB_C_TYPE_DOUBLE)
-		G_fatal_error(_("Column type of s column is not supported (must be integer or double)"));
+		G_fatal_error(_("Data type of column <%s> must be numeric"), scol);
 
 	    db_CatValArray_init(&sarray);
 	    db_select_CatValArray(driver, Fi->table, Fi->key, scol,
@@ -120,14 +118,14 @@
     }
 
     /* Lines without nodes */
-    G_message(_("Reading lines from vector map ... "));
+    G_message(_("Reading features from vector map ..."));
     sm = 0;
     line = 1;
     while ((ltype = Vect_read_next_line(Map, Points, Cats)) != -2) {
 
 	if (!(ltype & (GV_POINT | GV_LINE | GV_BOUNDARY)))
 	    continue;
-
+	
 	if (field > 0) {	/* use cat or attribute */
 	    Vect_cat_get(Cats, field, &cat);
 
@@ -170,8 +168,7 @@
 							    &sm);
 		    }
 		    if (sm < 0.0)
-			G_fatal_error
-			    ("Negative value of smoothing detected: sm must be >= 0");
+			G_fatal_error(_("Negative value of smoothing detected: sm must be >= 0"));
 		}
 		G_debug(5, "  z = %f sm = %f", z, sm);
 	    }
@@ -233,11 +230,11 @@
     }
 
     /* Process all nodes */
-    G_message(_("Reading nodes from vector map ... "));
+    G_message(_("Reading nodes from vector map ..."));
     nnodes = Vect_get_num_nodes(Map);
     for (k1 = 1; k1 <= nnodes; k1++) {
 	G_debug(5, "  node %d", k1);
-	G_percent(k1, nnodes - 1, 1);
+	G_percent(k1, nnodes, 1);
 	Vect_get_node_coor(Map, k1, &x1, &y1, &z);
 
 	/* TODO: check more lines ? */
@@ -288,8 +285,7 @@
 							    &sm);
 		    }
 		    if (sm < 0.0)
-			G_fatal_error
-			    ("Negative value of smoothing detected: sm must be >= 0");
+			G_fatal_error(_("Negative value of smoothing detected: sm must be >= 0"));
 		}
 		G_debug(5, "  z = %f sm = %f", z, sm);
 	    }
@@ -298,7 +294,7 @@
 	process_point(x1, y1, z, sm, info, params->zmult, xmin, xmax, ymin,
 		      ymax, zmin, zmax, &npoint, &OUTRANGE, &k);
     }
-
+    
     if (field > 0 && zcol != NULL)
 	db_CatValArray_free(&zarray);
     if (scol != NULL) {
@@ -315,7 +311,7 @@
 
 	if (!once) {
 	    once = 1;
-	    G_warning(_("strip exists with insufficient data"));
+	    G_warning(_("Strip exists with insufficient data"));
 	}
     }
 
@@ -328,12 +324,11 @@
 
     /* G_read_vector_timestamp(name,mapset,ts); */
 
-    fprintf(stderr, "\n");
     if (OUTRANGE > 0)
-	G_warning(_("there are points outside specified 2D/3D region--ignored %d points"),
+	G_warning(_("There are points outside specified 2D/3D region - %d points ignored"),
 		  OUTRANGE);
     if (npoint > 0)
-	G_warning(_("ignoring %d points -- too dense"), npoint);
+	G_important_message(_("Ignoring %d points (too dense)"), npoint);
     npoint = k - npoint - OUTRANGE;
     if (npoint < params->kmin) {
 	if (npoint != 0) {
@@ -342,16 +337,14 @@
 	    params->kmin = npoint;
 	}
 	else {
-	    fprintf(stderr, "ERROR2: zero points in the given region!\n");
+	    G_warning(_("Zero points in the given region"));
 	    return -1;
 	}
     }
     if (npoint > params->KMAX2 && params->kmin <= params->kmax) {
-	fprintf(stderr,
-		"ERROR: segmentation parameters set to invalid values: npmin= %d, segmax= %d \n",
-		params->kmin, params->kmax);
-	fprintf(stderr,
-		"for smooth connection of segments, npmin > segmax (see manual) \n");
+	G_warning(_("Segmentation parameters set to invalid values: npmin= %d, segmax= %d "
+		    "for smooth connection of segments, npmin > segmax (see manual)"),
+		  params->kmin, params->kmax);
 	return -1;
     }
     if (npoint < params->KMAX2 && params->kmax != params->KMAX2)
@@ -359,12 +352,11 @@
 		    "segmentation is necessary, to run the program faster set "
 		    "segmax=%d (see manual)"), params->KMAX2, params->KMAX2);
 
-    fprintf(stdout, "\n");
-    fprintf(stdout, "The number of points from vector map is %d\n", k);
-    fprintf(stdout, "The number of points outside of 2D/3D region %d\n",
-	    OUTRANGE);
-    fprintf(stdout, "The number of points being used is %d\n", npoint);
-    fflush(stdout);
+    G_message(_("Number of points from vector map %d"), k);
+    G_verbose_message(_("Number of points outside of 2D/3D region %d"),
+	      OUTRANGE);
+    G_message(_("Number of points being used %d"), npoint);
+    
     *n_points = npoint;
     return (totsegm);
 }
@@ -396,13 +388,13 @@
 
     if (!((c1 >= 0) && (c2 >= 0) && (c3 >= 0) && (c4 >= 0))) {
 	if (!(*OUTRANGE)) {
-	    G_warning(_("some points outside of region -- will ignore..."));
+	    G_warning(_("Some points outside of region (ignored)"));
 	}
 	(*OUTRANGE)++;
     }
     else {
 	if (!(point = quad_point_new(x, y, z, sm))) {
-	    fprintf(stderr, "cannot allocate memory for point\n");
+	    G_warning(_("Unable to allocate memory"));
 	    return -1;
 	}
 	a = MT_insert(point, info, info->root, 4);
@@ -410,7 +402,7 @@
 	    (*npoint)++;
 	}
 	if (a < 0) {
-	    fprintf(stderr, "cannot insert %f,%f,%f a = %d\n", x, y, z, a);
+	    G_warning(_("Unable to insert %f,%f,%f a = %d"), x, y, z, a);
 	    return -1;
 	}
 	free(point);



More information about the grass-commit mailing list