[GRASS-SVN] r45129 - grass/trunk/imagery/i.rectify

svn_grass at osgeo.org svn_grass at osgeo.org
Fri Jan 21 05:42:54 EST 2011


Author: mmetz
Date: 2011-01-21 02:42:54 -0800 (Fri, 21 Jan 2011)
New Revision: 45129

Modified:
   grass/trunk/imagery/i.rectify/exec.c
   grass/trunk/imagery/i.rectify/global.h
   grass/trunk/imagery/i.rectify/main.c
   grass/trunk/imagery/i.rectify/report.c
Log:
clean up report, check input answers, manually check for overwrite

Modified: grass/trunk/imagery/i.rectify/exec.c
===================================================================
--- grass/trunk/imagery/i.rectify/exec.c	2011-01-21 10:34:33 UTC (rev 45128)
+++ grass/trunk/imagery/i.rectify/exec.c	2011-01-21 10:42:54 UTC (rev 45129)
@@ -32,14 +32,14 @@
     struct Categories cats;
     struct History hist;
     int colr_ok, cats_ok;
-    long start_time, rectify_time, compress_time;
+    long start_time, rectify_time;
 
     Rast_set_output_window(&target_window);
+    G_message("-----------------------------------------------");
 
     /* rectify each file */
     for (n = 0; n < ref.nfiles; n++) {
-	if (ref_list[n] < 0) {
-	    /* continue; */
+	if (ref_list[n]) {
 	    name = ref.file[n].name;
 	    mapset = ref.file[n].mapset;
 
@@ -48,8 +48,6 @@
 		G_malloc(strlen(ref.file[n].name) + strlen(extension) + 1);
 	    strcpy(result, ref.file[n].name);
 	    strcat(result, extension);
-	    G_message(_("Rectified input raster map <%s> will be saved as <%s>"),
-		      name, result);
 
 	    select_current_env();
 
@@ -82,12 +80,10 @@
 
 		select_current_env();
 		time(&rectify_time);
-		compress_time = rectify_time;
-		report(name, mapset, result, rectify_time - start_time,
-		       compress_time - rectify_time, 1);
+		report(rectify_time - start_time, 1);
 	    }
 	    else
-		report(name, mapset, result, (long)0, (long)0, 0);
+		report((long)0, 0);
 
 	    G_free(result);
 	}

Modified: grass/trunk/imagery/i.rectify/global.h
===================================================================
--- grass/trunk/imagery/i.rectify/global.h	2011-01-21 10:34:33 UTC (rev 45128)
+++ grass/trunk/imagery/i.rectify/global.h	2011-01-21 10:42:54 UTC (rev 45129)
@@ -85,7 +85,7 @@
 #define CPTR(c,y,x) (&(*BLOCK((c),HI((y)),HI((x))))[LO((y))][LO((x))])
 
 /* report.c */
-int report(char *, char *, char *, long, long, int);
+int report(long, int);
 
 /* target.c */
 int get_target(char *);

Modified: grass/trunk/imagery/i.rectify/main.c
===================================================================
--- grass/trunk/imagery/i.rectify/main.c	2011-01-21 10:34:33 UTC (rev 45128)
+++ grass/trunk/imagery/i.rectify/main.c	2011-01-21 10:42:54 UTC (rev 45129)
@@ -80,7 +80,9 @@
     char *ipolname;		/* name of interpolation method */
     int method;
     int n, i, m, k = 0;
-    int got_file = 0;
+    int got_file = 0, target_overwrite = 0;
+    char *overstr;
+    struct Cell_head cellhd;
 
     struct Option *grp,         /* imagery group */
      *val,                      /* transformation order */
@@ -93,8 +95,6 @@
     struct Flag *c, *a;
     struct GModule *module;
 
-    struct Cell_head cellhd;
-
     setbuf(stdout, NULL);
     setbuf(stderr, NULL);
 
@@ -186,7 +186,7 @@
     if (!ifile->answers)
 	a->answer = 1;		/* force all */
 
-    /* Find out how files on command line */
+    /* Find out how many files on command line */
     if (!a->answer) {
 	for (m = 0; ifile->answers[m]; m++) {
 	    k = m;
@@ -219,25 +219,43 @@
 
     if (a->answer) {
 	for (n = 0; n < ref.nfiles; n++) {
-	    ref_list[n] = -1;
+	    ref_list[n] = 1;
 	}
     }
     else {
-	char xname[GNAME_MAX], xmapset[GMAPSET_MAX], *name;
+	char xname[GNAME_MAX], xmapset[GMAPSET_MAX], *name, *mapset;
+
+	for (n = 0; n < ref.nfiles; n++)
+		ref_list[n] = 0;
+
 	for (m = 0; m < k; m++) {
 	    got_file = 0;
-	    if (G_name_is_fully_qualified(ifile->answers[m], xname, xmapset))
+	    if (G_name_is_fully_qualified(ifile->answers[m], xname, xmapset)) {
 		name = xname;
-	    else
+		mapset = xmapset;
+	    }
+	    else {
 		name = ifile->answers[m];
+		mapset = 0;
+	    }
 
+	    got_file = 0;
 	    for (n = 0; n < ref.nfiles; n++) {
-		ref_list[n] = 1;
-		if (strcmp(name, ref.file[n].name) == 0) {
-		    got_file = 1;
-		    ref_list[n] = -1;
-		    break;
+		if (mapset) {
+		    if (strcmp(name, ref.file[n].name) == 0 &&
+		        strcmp(mapset, ref.file[n].mapset) == 0) {
+			got_file = 1;
+			ref_list[n] = 1;
+			break;
+		    }
 		}
+		else {
+		    if (strcmp(name, ref.file[n].name) == 0) {
+			got_file = 1;
+			ref_list[n] = 1;
+			break;
+		    }
+		}
 	    }
 	    if (got_file == 0)
 		err_exit(ifile->answers[m], group);
@@ -250,6 +268,39 @@
     /* get the target */
     get_target(group);
 
+    /* Check the GRASS_OVERWRITE environment variable */
+    if ((overstr = getenv("GRASS_OVERWRITE")))  /* OK ? */
+	target_overwrite = atoi(overstr);
+
+    if (!target_overwrite) {
+	/* check if output exists in target location/mapset */
+	char result[GNAME_MAX];
+	
+	select_target_env();
+	for (i = 0; i < ref.nfiles; i++) {
+	    if (!ref_list[i])
+		continue;
+
+	    strcpy(result, ref.file[i].name);
+	    strcat(result, extension);
+	    
+	    if (G_legal_filename(result) < 0)
+		G_fatal_error(_("Extension <%s> is illegal"), extension);
+		
+	    if (G_find_raster2(result, G_mapset())) {
+		G_warning(_("The following raster map already exists in"));
+		G_warning(_("target LOCATION %s, MAPSET %s:"),
+			  G_location(), G_mapset());
+		G_warning("<%s>", result);
+		G_fatal_error(_("Orthorectification cancelled."));
+	    }
+	}
+	
+	select_current_env();
+    }
+    else
+	G_debug(1, "Overwriting OK");
+
     /* do not use current region in target location */
     if (!c->answer) {
 	double res = -1;

Modified: grass/trunk/imagery/i.rectify/report.c
===================================================================
--- grass/trunk/imagery/i.rectify/report.c	2011-01-21 10:34:33 UTC (rev 45128)
+++ grass/trunk/imagery/i.rectify/report.c	2011-01-21 10:42:54 UTC (rev 45129)
@@ -1,8 +1,7 @@
 #include <grass/glocale.h>
 #include "global.h"
 
-int report(char *name, char *mapset, char *result,
-	   long rectify, long compress, int ok)
+int report(long rectify, int ok)
 {
     int minutes, hours;
     long seconds;
@@ -21,30 +20,14 @@
     G_verbose_message(_("%d rows, %d cols (%ld cells) completed in"),
 			target_window.rows, target_window.cols, ncells);
     if (hours)
-	G_verbose_message("%d:%02d:%02ld", hours, minutes, seconds % 60);
+	G_verbose_message(_("%d:%02d:%02ld hours"), hours, minutes, seconds % 60);
     else
-	G_verbose_message("%d:%02ld", minutes, seconds % 60);
+	G_verbose_message(_("%d:%02ld minutes"), minutes, seconds % 60);
     if (seconds)
 	G_verbose_message(_("%.1f cells per minute"),
 			  (60.0 * ncells) / ((double)seconds));
 		      
-    seconds = compress;
-
-    if (seconds <= 0) {
-	G_message("-----------------------------------------------");
-	return 1;
-    }
-
-    minutes = seconds / 60;
-    hours = minutes / 60;
-    minutes -= hours * 60;
-    G_verbose_message(_("data compression required an additional"));
-    if (hours)
-	G_verbose_message("%d:%02d:%02ld", hours, minutes, seconds % 60);
-    else
-	G_verbose_message("%d:%02ld\n", minutes, seconds % 60);
-
     G_message("-----------------------------------------------");
 
-    return 0;
+    return 1;
 }



More information about the grass-commit mailing list