[GRASS-SVN] r39838 - grass/trunk/vector/v.normal

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Nov 27 17:49:18 EST 2009


Author: martinl
Date: 2009-11-27 17:49:17 -0500 (Fri, 27 Nov 2009)
New Revision: 39838

Modified:
   grass/trunk/vector/v.normal/main.c
Log:
v.normal: q flag removed + i18n


Modified: grass/trunk/vector/v.normal/main.c
===================================================================
--- grass/trunk/vector/v.normal/main.c	2009-11-27 21:32:22 UTC (rev 39837)
+++ grass/trunk/vector/v.normal/main.c	2009-11-27 22:49:17 UTC (rev 39838)
@@ -1,25 +1,19 @@
 
-/*-
- * from s.normal - GRASS program for distributional testing.
- * Copyright (C) 1994-1995. James Darrell McCauley.
+
+/***************************************************************
  *
- * Author: James Darrell McCauley darrell at mccauley-usa.com
- * 	                          http://mccauley-usa.com/
+ * MODULE:       v.normal
+ * 
+ * AUTHOR(S):    James Darrell McCauley darrell at mccauley-usa.com
+ *               OGR support by Martin Landa <landa.martin gmail.com> (2009)
+ *               
+ * PURPOSE:      GRASS program for distributional testing (based on s.normal)
+ *               
+ * COPYRIGHT:    (C) 2001-2009 by the GRASS Development Team
  *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- *
+ *               This program is free software under the GNU General
+ *               Public License (>=v2).  Read the file COPYING that
+ *               comes with GRASS for details. 
  * Modification History:
  * <23 Jan 2001> - added field parameter, fixed reading of sites (MN)
  * <27 Aug 1994> - began coding. Adapted cdh.f from statlib (jdm)
@@ -30,10 +24,11 @@
  * <21 Jun 1995> - adapted to use new sites API (jdm)
  * <13 Sep 2000> - released under GPL
  *
- */
+ **************************************************************/
 
 #include <stdlib.h>
 #include <math.h>
+
 #include <grass/gis.h>
 #include <grass/dbmi.h>
 #include <grass/vector.h>
@@ -44,7 +39,7 @@
 
 int main(int argc, char **argv)
 {
-    int i, nsites, verbose, warn_once = 0;
+    int i, nsites, warn_once = 0;
     int all;
     long x, y;
     struct Cell_head window;
@@ -61,6 +56,7 @@
 
     struct Map_info Map;
     int line, nlines, npoints;
+    int field;
     struct line_pnts *Points;
     struct line_cats *Cats;
     struct bound_box box;
@@ -77,79 +73,63 @@
     module = G_define_module();
     G_add_keyword(_("vector"));
     G_add_keyword(_("statistics"));
-    module->description = _("Tests for normality for points.");
-    parm.input = G_define_option();
-    parm.input->key = "map";
-    parm.input->type = TYPE_STRING;
-    parm.input->required = YES;
-    parm.input->description = "point vector defining sample points";
-    parm.input->gisprompt = "old,vector,vector";
+    G_add_keyword(_("points"));
+    module->description = _("Tests for normality for vector points.");
 
+    parm.input = G_define_standard_option(G_OPT_V_MAP);
+
     parm.tests = G_define_option();
     parm.tests->key = "tests";
     parm.tests->key_desc = "range";
     parm.tests->type = TYPE_STRING;
     parm.tests->multiple = YES;
     parm.tests->required = YES;
-    parm.tests->description = "Lists of tests (1-15): e.g. 1,3-8,13";
+    parm.tests->label = _("Lists of tests (1-15)");
+    parm.tests->description = _("E.g. 1,3-8,13");
 
-    parm.dfield = G_define_option();
-    parm.dfield->key = "column";
-    parm.dfield->type = TYPE_STRING;
-    parm.dfield->multiple = NO;
+    parm.dfield = G_define_standard_option(G_OPT_DB_COLUMN);
     parm.dfield->required = YES;
-    parm.dfield->description = "Attribute column";
 
     flag.region = G_define_flag();
     flag.region->key = 'r';
-    flag.region->description = "Use only points in current region";
+    flag.region->description = _("Use only points in current region");
 
-    flag.q = G_define_flag();
-    flag.q->key = 'q';
-    flag.q->description = "Quiet";
-
     flag.l = G_define_flag();
     flag.l->key = 'l';
-    flag.l->description = "lognormal";
-
+    flag.l->description = _("Lognormality instead of normality");
+    
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
-
-    if (parm.tests->answer == NULL) {
-	G_usage();
-	exit(EXIT_FAILURE);
-    }
-
+    
     all = flag.region->answer ? 0 : 1;
-    verbose = flag.q->answer ? 0 : 1;
 
     /* Open input */
     Vect_set_open_level(2);
     Vect_open_old(&Map, parm.input->answer, "");
-
+    field = 1;
+    
     /* Read attributes */
-    Fi = Vect_get_field(&Map, 1);
+    Fi = Vect_get_field(&Map, field);
     if (Fi == NULL) {
-	G_fatal_error("Cannot read layer info");
+	G_fatal_error("Database connection not defined for layer %d", field);
     }
-
+    
     Driver = db_start_driver_open_database(Fi->driver, Fi->database);
     if (Driver == NULL)
 	G_fatal_error(_("Unable to open database <%s> by driver <%s>"),
 		      Fi->database, Fi->driver);
 
-    nrecords =
-	db_select_CatValArray(Driver, Fi->table, Fi->key, parm.dfield->answer,
-			      NULL, &cvarr);
+    nrecords = db_select_CatValArray(Driver, Fi->table, Fi->key, parm.dfield->answer,
+				     NULL, &cvarr);
     G_debug(1, "nrecords = %d", nrecords);
 
     ctype = cvarr.ctype;
     if (ctype != DB_C_TYPE_INT && ctype != DB_C_TYPE_DOUBLE)
-	G_fatal_error("Column type not supported");
+	G_fatal_error(_("Only numeric column type supported"));
 
     if (nrecords < 0)
 	G_fatal_error(_("Unable to select data from table"));
-    G_message(_("%d records selected from table"), nrecords);
+    G_verbose_message(_("%d records selected from table"), nrecords);
 
     db_close_database_shutdown_driver(Driver);
 
@@ -188,7 +168,7 @@
 	if (ctype == DB_C_TYPE_INT) {
 	    ret = db_CatValArray_get_value_int(&cvarr, cat, &cval);
 	    if (ret != DB_OK) {
-		G_warning("No record for cat = %d", cat);
+		G_warning(_("No record for cat %d"), cat);
 		continue;
 	    }
 	    dval = cval;
@@ -196,7 +176,7 @@
 	else if (ctype == DB_C_TYPE_DOUBLE) {
 	    ret = db_CatValArray_get_value_double(&cvarr, cat, &dval);
 	    if (ret != DB_OK) {
-		G_warning("No record for cat = %d", cat);
+		G_warning(_("No record for cat %d"), cat);
 		continue;
 	    }
 	}
@@ -206,24 +186,21 @@
 	nsites++;
     }
 
-    if (verbose)
-	fprintf(stdout, "Number of points: %d\n", nsites);
-
+    G_verbose_message(_("Number of points: %d"), nsites);
+    
     if (nsites <= 0)
-	G_fatal_error("No points found");
+	G_fatal_error(_("No points found"));
 
     if (nsites < 4)
-	fprintf(stdout,
-		"WARNING: I'm not so sure of myself for small samples\n");
-
+	G_warning(_("Too small sample"));
+    
     if (flag.l->answer) {
-	G_message(_("Doing log transformation"));
 	warn_once = 0;
 	for (i = 0; i < nsites; ++i) {
 	    if (z[i] > 1.0e-10)
 		z[i] = log10(z[i]);
 	    else if (!warn_once) {
-		G_warning("Negative or very small point values set to -10.0");
+		G_warning(_("Negative or very small point values set to -10.0"));
 		z[i] = -10.0;
 		warn_once = 1;
 	    }
@@ -240,104 +217,99 @@
 	while (x <= y)
 	    switch (x++) {
 	    case 1:		/* moments */
-		fprintf(stdout, "Moments \\sqrt{b_1} and b_2:");
+		fprintf(stdout, _("Moments \\sqrt{b_1} and b_2: "));
 		w = omnibus_moments(z, nsites);
 		fprintf(stdout, "%g %g\n", w[0], w[1]);
 		break;
 	    case 2:		/* geary */
-		fprintf(stdout, "Geary's a-statistic & an approx. normal: ");
+		fprintf(stdout, _("Geary's a-statistic & an approx. normal: "));
 		w = geary_test(z, nsites);
 		fprintf(stdout, "%g %g\n", w[0], w[1]);
 		break;
 	    case 3:		/* extreme deviates */
-		fprintf(stdout, "Extreme normal deviates: ");
+		fprintf(stdout, _("Extreme normal deviates: "));
 		w = extreme(z, nsites);
 		fprintf(stdout, "%g %g\n", w[0], w[1]);
 		break;
 	    case 4:		/* D'Agostino */
-		fprintf(stdout, "D'Agostino's D & an approx. normal: ");
+		fprintf(stdout, _("D'Agostino's D & an approx. normal: "));
 		w = dagostino_d(z, nsites);
 		fprintf(stdout, "%g %g\n", w[0], w[1]);
 		break;
 	    case 5:		/* Kuiper */
 		fprintf(stdout,
-			"Kuiper's V (regular & modified for normality): ");
+			_("Kuiper's V (regular & modified for normality): "));
 		w = kuipers_v(z, nsites);
 		fprintf(stdout, "%g %g\n", w[1], w[0]);
 		break;
 	    case 6:		/* Watson */
 		fprintf(stdout,
-			"Watson's U^2 (regular & modified for normality): ");
+			_("Watson's U^2 (regular & modified for normality): "));
 		w = watson_u2(z, nsites);
 		fprintf(stdout, "%g %g\n", w[1], w[0]);
 		break;
 	    case 7:		/* Durbin */
 		fprintf(stdout,
-			"Durbin's Exact Test (modified Kolmogorov): ");
+			_("Durbin's Exact Test (modified Kolmogorov): "));
 		w = durbins_exact(z, nsites);
 		fprintf(stdout, "%g\n", w[0]);
 		break;
 	    case 8:		/* Anderson-Darling */
 		fprintf(stdout,
-			"Anderson-Darling's A^2 (regular & modified for normality): ");
+			_("Anderson-Darling's A^2 (regular & modified for normality): "));
 		w = anderson_darling(z, nsites);
 		fprintf(stdout, "%g %g\n", w[1], w[0]);
 		break;
 	    case 9:		/* Cramer-Von Mises */
 		fprintf(stdout,
-			"Cramer-Von Mises W^2(regular & modified for normality): ");
+			_("Cramer-Von Mises W^2(regular & modified for normality): "));
 		w = cramer_von_mises(z, nsites);
 		fprintf(stdout, "%g %g\n", w[1], w[0]);
 		break;
 	    case 10:		/* Kolmogorov-Smirnov */
 		fprintf(stdout,
-			"Kolmogorov-Smirnov's D (regular & modified for normality): ");
+			_("Kolmogorov-Smirnov's D (regular & modified for normality): "));
 		w = kolmogorov_smirnov(z, nsites);
 		fprintf(stdout, "%g %g\n", w[1], w[0]);
 		break;
 	    case 11:		/* chi-square */
 		fprintf(stdout,
-			"Chi-Square stat (equal probability classes) and d.f.: ");
+			_("Chi-Square stat (equal probability classes) and d.f.: "));
 		w = chi_square(z, nsites);
 		fprintf(stdout, "%g %d\n", w[0], (int)w[1]);
 		break;
 	    case 12:		/* Shapiro-Wilk */
 		if (nsites > 50) {
-		    fprintf(stdout,
-			    "\nShapiro-Wilk's W cannot be used for n > 50\n");
+		    G_warning(_("Shapiro-Wilk's W cannot be used for n > 50"));
 		    if (nsites < 99)
-			fprintf(stdout, "Use Weisberg-Binghams's W''\n\n");
-		    else
-			fprintf(stdout, "\n");
+			G_message(_("Use Weisberg-Binghams's W''"));
 		}
 		else {
-		    fprintf(stdout, "Shapiro-Wilk W: ");
+		    fprintf(stdout, _("Shapiro-Wilk W: "));
 		    w = shapiro_wilk(z, nsites);
 		    fprintf(stdout, "%g\n", w[0]);
 		}
 		break;
 	    case 13:		/* Weisberg-Bingham */
 		if (nsites > 99 || nsites < 50)
-		    fprintf(stdout,
-			    "\nWeisberg-Bingham's W'' cannot be used for n < 50 or n > 99\n\n");
+		    G_warning(_("Weisberg-Bingham's W'' cannot be used for n < 50 or n > 99"));
 		else {
-		    fprintf(stdout, "Weisberg-Bingham's W'': ");
+		    fprintf(stdout, _("Weisberg-Bingham's W'': "));
 		    w = weisberg_bingham(z, nsites);
 		    fprintf(stdout, "%g\n", w[0]);
 		}
 		break;
 	    case 14:		/* Royston */
 		if (nsites > 2000)
-		    fprintf(stdout,
-			    "\nRoyston only extended Shapiro-Wilk's W up to n = 2000\n\n");
+		    G_warning(_("Royston only extended Shapiro-Wilk's W up to n = 2000"));
 		else {
-		    fprintf(stdout, "Shapiro-Wilk W'': ");
+		    fprintf(stdout, _("Shapiro-Wilk W'': "));
 		    w = royston(z, nsites);
 		    fprintf(stdout, "%g\n", w[0]);
 		}
 		break;
 	    case 15:		/* Kotz */
-		fprintf(stdout, "Kotz' T'_f (Lognormality vs. Normality): ");
+		fprintf(stdout, _("Kotz' T'_f (Lognormality vs. Normality): "));
 		w = kotz_families(z, nsites);
 		fprintf(stdout, "%g\n", w[0]);
 		break;



More information about the grass-commit mailing list