[GRASS-SVN] r50172 - grass/branches/develbranch_6/vector/v.distance

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jan 13 21:07:56 EST 2012


Author: hamish
Date: 2012-01-13 18:07:56 -0800 (Fri, 13 Jan 2012)
New Revision: 50172

Modified:
   grass/branches/develbranch_6/vector/v.distance/main.c
Log:
cleanup matrix option descriptions; make variable name less generic;
for clarity use boolean macros where appropriate. (merge from trunk)


Modified: grass/branches/develbranch_6/vector/v.distance/main.c
===================================================================
--- grass/branches/develbranch_6/vector/v.distance/main.c	2012-01-14 01:51:22 UTC (rev 50171)
+++ grass/branches/develbranch_6/vector/v.distance/main.c	2012-01-14 02:07:56 UTC (rev 50172)
@@ -71,8 +71,8 @@
 int main(int argc, char *argv[])
 {
     int i, j, k;
-    int print_as_matrix;	/* only for all */
-    int all;			/* calculate from each to each within the threshold */
+    int print_as_matrix;	/* only for do_all=TRUE */
+    int do_all;			/* calculate from each to each within the threshold */
     char *mapset;
     struct GModule *module;
     struct Option *from_opt, *to_opt, *from_type_opt, *to_type_opt,
@@ -86,7 +86,7 @@
     struct line_pnts *FPoints, *TPoints;
     struct line_cats *FCats, *TCats;
     NEAR *Near, *near;
-    int anear;			/* allocated space, used only for all */
+    int anear;			/* allocated space, used only for do_all */
     UPLOAD *Upload;		/* zero terminated */
     int ftype, fcat, tcat, count;
     int nfrom, nto, nfcats, fline, tline, tseg, tarea, area, isle, nisles;
@@ -104,8 +104,8 @@
     dbCatValArray cvarr;
     dbColumn *column;
 
-    all = 0;
-    print_as_matrix = 0;
+    do_all = FALSE;
+    print_as_matrix = FALSE;
     column = NULL;
 
     G_gisinit(argv[0]);
@@ -211,7 +211,7 @@
     table_opt = G_define_standard_option(G_OPT_TABLE);
     table_opt->gisprompt = "new_dbtable,dbtable,dbtable";
     table_opt->description =
-	_("Name of table created for output when the distance to all flag is used");
+	_("Name of table created when the 'distance to all' flag is used");
 
     print_flag = G_define_flag();
     print_flag->key = 'p';
@@ -224,7 +224,9 @@
     all_flag->key = 'a';
     all_flag->label =
 	_("Calculate distances to all features within the threshold");
-    all_flag->description = _("The output is written to stdout but may be uploaded " "to a new table created by this module. " "From categories are may be multiple.");	/* huh? */
+    all_flag->description =
+	_("Output is written to stdout but may be uploaded to a new table "
+	  "created by this module; multiple 'upload' options may be used.");
 
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
@@ -239,7 +241,7 @@
     min = atof(min_opt->answer);
 
     if (all_flag->answer)
-	all = 1;
+	do_all = TRUE;
 
     /* Read upload and column options */
     /* count */
@@ -247,8 +249,8 @@
     while (upload_opt->answers[i])
 	i++;
     if (strcmp(from_opt->answer, to_opt->answer) == 0 &&
-	all && !table_opt->answer && i == 1)
-	print_as_matrix = 1;
+	do_all && !table_opt->answer && i == 1)
+	print_as_matrix = TRUE;
 
     /* alloc */
     Upload = (UPLOAD *) G_calloc(i + 1, sizeof(UPLOAD));
@@ -351,7 +353,7 @@
     driver = NULL;
     if (!print_flag->answer) {
 
-	if (!all) {
+	if (!do_all) {
 	    Fi = Vect_get_field(&From, from_field);
 	    if (Fi == NULL)
 		G_fatal_error(_("Database connection not defined for layer %d"),
@@ -411,7 +413,7 @@
 	}
 
 	/* Check column types */
-	if (!print_flag->answer && !all) {
+	if (!print_flag->answer && !do_all) {
 	    char *fcname = NULL;
 	    int fctype, tctype;
 
@@ -453,8 +455,8 @@
     /* Allocate space ( may be more than needed (duplicate cats and elements without cats) ) */
     nfrom = Vect_get_num_lines(&From);
     nto = Vect_get_num_lines(&To);
-    if (all) {
-	/* Attention with space for all, it can easily run out of memory */
+    if (do_all) {
+	/* Be careful with do_all, it can easily run out of memory */
 	anear = 2 * nfrom;
 	Near = (NEAR *) G_calloc(anear, sizeof(NEAR));
     }
@@ -463,7 +465,7 @@
     }
 
     /* Read all cats from 'from' */
-    if (!all) {
+    if (!do_all) {
 	nfcats = 0;
 	for (i = 1; i <= nfrom; i++) {
 	    ftype = Vect_read_line(&From, NULL, FCats, i);
@@ -500,7 +502,7 @@
     /* Go through all lines in 'from' and find nearest in 'to' for each */
     /* Note: as from_type is restricted to GV_POINTS (for now) everything is simple */
 
-    count = 0;			/* count of distances in 'all' mode */
+    count = 0;			/* count of distances in 'do_all' mode */
     /* Find nearest lines */
     if (to_type & (GV_POINTS | GV_LINES)) {
 	struct line_pnts *LLPoints;
@@ -523,7 +525,7 @@
 		continue;
 
 	    Vect_cat_get(FCats, from_field, &fcat);
-	    if (fcat < 0 && !all)
+	    if (fcat < 0 && !do_all)
 		continue;
 
 	    box.E = FPoints->x[0] + max;
@@ -573,7 +575,7 @@
 		G_debug(4, "  tmp_dist = %f tmp_tcat = %d", tmp_dist,
 			tmp_tcat);
 
-		if (all) {
+		if (do_all) {
 		    if (anear <= count) {
 			anear += 10 + nfrom / 10;
 			Near = (NEAR *) G_realloc(Near, anear * sizeof(NEAR));
@@ -610,7 +612,7 @@
 	    }
 
 	    G_debug(4, "  dist = %f", dist);
-	    if (!all && tline > 0) {
+	    if (!do_all && tline > 0) {
 		/* find near by cat */
 		near =
 		    (NEAR *) bsearch((void *)&fcat, Near, nfcats,
@@ -650,7 +652,7 @@
 		continue;
 
 	    Vect_cat_get(FCats, from_field, &fcat);
-	    if (fcat < 0 && !all)
+	    if (fcat < 0 && !do_all)
 		continue;
 
 	    /* select areas by box */
@@ -722,7 +724,7 @@
 		G_debug(4, "  tmp_dist = %f tmp_tcat = %d", tmp_dist,
 			tmp_tcat);
 
-		if (all) {
+		if (do_all) {
 		    if (anear <= count) {
 			anear += 10 + nfrom / 10;
 			Near = (NEAR *) G_realloc(Near, anear * sizeof(NEAR));
@@ -751,7 +753,7 @@
 		}
 	    }
 
-	    if (!all && tarea > 0) {
+	    if (!do_all && tarea > 0) {
 		/* find near by cat */
 		near =
 		    (NEAR *) bsearch((void *)&fcat, Near, nfcats,
@@ -787,7 +789,7 @@
 	}
 	fprintf(stdout, "\n");
     }
-    else if (all && table_opt->answer) {	/* create new table */
+    else if (do_all && table_opt->answer) {	/* create new table */
 	db_set_string(&stmt, "create table ");
 	db_append_string(&stmt, table_opt->answer);
 	db_append_string(&stmt, " (from_cat integer");
@@ -826,7 +828,7 @@
 			  table_opt->answer);
 
     }
-    else if (!all) {		/* read existing cats from table */
+    else if (!do_all) {		/* read existing cats from table */
 	ncatexist =
 	    db_select_int(driver, Fi->table, Fi->key, NULL, &catexist);
 	G_debug(1, "%d cats selected from the table", ncatexist);
@@ -834,7 +836,7 @@
     update_ok = update_err = update_exist = update_notexist = update_dupl =
 	update_notfound = 0;
 
-    if (!all) {
+    if (!do_all) {
 	count = nfcats;
     }
     else if (print_as_matrix) {
@@ -888,7 +890,7 @@
 	    db_CatValArray_get_value(&cvarr, Near[i].to_cat, &catval);
 	}
 
-	if (print_flag->answer || (all && !table_opt->answer)) {	/* print only */
+	if (print_flag->answer || (do_all && !table_opt->answer)) {	/* print only */
 	    /*
 	       input and output is the same &&
 	       calculate distances &&
@@ -918,7 +920,7 @@
 		fprintf(stdout, "\n");
 	    }
 	}
-	else if (all) {		/* insert new record */
+	else if (do_all) {		/* insert new record */
 	    sprintf(buf1, "insert into %s values ( %d ", table_opt->answer,
 		    Near[i].from_cat);
 	    db_set_string(&stmt, buf1);
@@ -1114,13 +1116,13 @@
 	db_free_string(&stmt);
 
 	/* print stats */
-	if (all && table_opt->answer) {
+	if (do_all && table_opt->answer) {
 	    G_message(_("%d distances calculated"), count);
 	    G_message(_("%d records inserted"), update_ok);
 	    if (update_err > 0)
 		G_message(_("%d insert errors"), update_err);
 	}
-	else if (!all) {
+	else if (!do_all) {
 	    if (nfcats > 0)
 		G_message(_("%d categories read from the map"), nfcats);
 	    if (ncatexist > 0)



More information about the grass-commit mailing list