[GRASS-SVN] r29520 - grass/trunk/imagery/i.group

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Dec 27 10:14:44 EST 2007


Author: martinl
Date: 2007-12-27 10:14:43 -0500 (Thu, 27 Dec 2007)
New Revision: 29520

Modified:
   grass/trunk/imagery/i.group/main.c
Log:
Allow to remove multiple raster maps from group/subgroup.
Message cleaning.


Modified: grass/trunk/imagery/i.group/main.c
===================================================================
--- grass/trunk/imagery/i.group/main.c	2007-12-27 14:34:04 UTC (rev 29519)
+++ grass/trunk/imagery/i.group/main.c	2007-12-27 15:14:43 UTC (rev 29520)
@@ -10,7 +10,7 @@
  *               Hamish Bowman <hamish_nospam yahoo.com>
  * PURPOSE:      collect raster map layers into an imagery group by assigning 
  *               them to user-named subgroups or other groups
- * COPYRIGHT:    (C) 2001-2006 by the GRASS Development Team
+ * COPYRIGHT:    (C) 2001-2007 by the GRASS Development Team
  *
  *               This program is free software under the GNU General Public
  *               License (>=v2). Read the file COPYING that comes with GRASS
@@ -51,11 +51,7 @@
 	_("Creates, edits, and lists groups and subgroups of imagery files.");
 
     /* Get Args */
-    grp = G_define_option();
-    grp->key = "group";
-    grp->type = TYPE_STRING;
-    grp->required = YES;
-    grp->gisprompt = "old,group,group";
+    grp = G_define_standard_option(G_OPT_I_GROUP);
     grp->description = _("Name of imagery group");
 
     sgrp = G_define_option();
@@ -64,13 +60,9 @@
     sgrp->required = NO;
     sgrp->description = _("Name of imagery sub-group");
 
-    rast = G_define_option();
-    rast->key = "input";
-    rast->type = TYPE_STRING;
-    rast->required = NO;   /* why is it NO? so the -list flag is easy. */
-    rast->multiple = YES;
-    rast->gisprompt = "old,cell,raster";
-    rast->description = _("Name of raster(s) to include in group");
+    rast = G_define_standard_option(G_OPT_R_INPUTS);
+    rast->required = NO;   /* -l flag */
+    rast->description = _("Name of raster map(s) to include in group");
 
     r = G_define_flag();
     r->key = 'r';
@@ -79,10 +71,12 @@
     l = G_define_flag();
     l->key = 'l';
     l->description = _("List files from specified (sub)group (fancy)");
+    l->guisection = _("Print");
 
     simple_flag = G_define_flag();
     simple_flag->key = 'g';
-    simple_flag->description = _("List files from specified (sub)group (simple)");
+    simple_flag->description = _("List files from specified (sub)group (shell script style)");
+    simple_flag->guisection = _("Print");
 
     if (G_parser(argc, argv))
 	exit(EXIT_FAILURE);
@@ -101,21 +95,23 @@
     }
     
     if (k < 1 && !l->answer)  /* remove if input is requirement */
-        G_fatal_error( _("No input map(s) specified.") );
-
+        G_fatal_error( _("No input raster map(s) specified") );
+    
     I_location_info(title, argv[0]);
 
     if (r->answer) {
 	/* Remove files from Group */
-	if (I_find_group(grp->answer) == 0)
-	    G_fatal_error(_("Specified group does not exist... Exiting."));
-
+	
+	if (I_find_group(grp->answer) == 0) {
+	    G_fatal_error(_("Specified group does not exist"));
+	}
+	
 	if (sgrp->answer) {
-	    G_message(_("Removing files from subgroup"));
+	    G_verbose_message(_("Removing raster maps from subgroup <%s>..."), sgrp->answer);
 	    remove_subgroup_files(grp->answer, sgrp->answer, rast->answers, k);
 	}
 	else {
-	    G_message(_("Removing files from group"));
+	    G_verbose_message(_("Removing raster maps from group <%s>..."), grp->answer);
 	    remove_group_files(grp->answer, rast->answers, k);
 	}
     }
@@ -123,6 +119,12 @@
         if (l->answer) {
             struct Ref ref;
 
+	    /* List raster maps */
+	    
+	    if (I_find_group(grp->answer) == 0) {
+		G_fatal_error(_("Specified group does not exist"));
+	    }
+
 	    if (sgrp->answer) {
 		/* list subgroup files */
 	 	I_get_subgroup_ref(grp->answer, sgrp->answer, &ref);
@@ -141,25 +143,27 @@
             }
 	}
 	else {
-		/* Create or update Group REF */
-		if (I_find_group(grp->answer) == 0)
-		    G_message(_("group [%s] - does not yet exist. Creating..."), grp->answer);
-
-		if (sgrp->answer) {
-		    G_message(_("Adding files to group [%s]"), grp->answer);
-		    add_or_update_group(grp->answer, rast->answers, k);
-
-		    G_message(_("Adding files to subgroup [%s]"), sgrp->answer);
-		    add_or_update_subgroup(grp->answer, sgrp->answer, rast->answers, k);
-		}
-		else {
-		    G_message(_("Adding files to group [%s]"), grp->answer);
-		    add_or_update_group(grp->answer, rast->answers, k);
-		}
+	    /* Create or update Group REF */
+	    if (I_find_group(grp->answer) == 0)
+		G_verbose_message(_("Group <%s> does not yet exist. Creating..."), grp->answer);
+	    
+	    if (sgrp->answer) {
+		G_verbose_message(_("Adding raster maps to group <%s>..."), grp->answer);
+		add_or_update_group(grp->answer, rast->answers, k);
+		
+		G_verbose_message(_("Adding raster maps to subgroup <%s>..."), sgrp->answer);
+		add_or_update_subgroup(grp->answer, sgrp->answer, rast->answers, k);
+	    }
+	    else {
+		G_verbose_message(_("Adding raster maps to group <%s>..."), grp->answer);
+		add_or_update_group(grp->answer, rast->answers, k);
+	    }
 	}
     }
+    
+    G_done_msg(" ");
 
-    return 0;
+    return EXIT_SUCCESS;
 }
 
 
@@ -176,13 +180,13 @@
 	if ((mapset = G_find_cell(rasters[m], "")) == NULL)
 	    G_fatal_error(_("Raster map <%s> not found"), rasters[m]);
 
-	G_message(_("Adding raster map [%s]"), rasters[m]);
+	G_message(_("Adding raster map <%s> to group"), G_fully_qualified_name(rasters[m], mapset));
 
 	/* Go through existing files to check for duplicates */
 	for (n = 0; n < ref.nfiles; n++) {
 	    if (strcmp(rasters[m], ref.file[n].name) == 0) {
-		G_message(_("Raster map [%s] exists in group."), rasters[m]);
-		G_message(_("Skipping [%s]..."), rasters[m]);
+		G_message(_("Raster map <%s> exists in group. Skipping..."),
+			  G_fully_qualified_name(rasters[m], mapset));
 		skip = 1;
 		continue;
 	    }
@@ -192,9 +196,8 @@
 	    I_add_file_to_group_ref(rasters[m], mapset, &ref);
     }
 
-    G_message(_("Writing group REF"));
+    G_debug(1, "writing group REF");
     I_put_group_ref(group, &ref);
-    G_message(_("Done."));
 
     return 0;
 }
@@ -212,15 +215,17 @@
     for (m = 0; m < k; m++) {
 	skip = 0;
 	if ((mapset = G_find_cell(rasters[m], "")) == NULL)
-	    G_fatal_error(_("Raster map <%s> not found"), rasters[m]);
+	    G_fatal_error(_("Raster map <%s> not found"),
+			  G_fully_qualified_name(rasters[m], mapset));
 
-	G_message(_("Adding raster map [%s]"), rasters[m]);
+	G_message(_("Adding raster map <%s> to subgroup"),
+		  G_fully_qualified_name(rasters[m], mapset));
 
 	/* Go through existing files to check for duplicates */
 	for (n = 0; n < ref.nfiles; n++) {
 	    if (strcmp(rasters[m], ref.file[n].name) == 0) {
-		G_message(_("Raster map [%s] exists in group."), rasters[m]);
-		G_message(_("Skipping [%s]..."), rasters[m]);
+		G_message(_("Raster map <%s> exists in subgroup. Skipping..."),
+			  G_fully_qualified_name(rasters[m], mapset));
 		skip = 1;
 		continue;
 	    }
@@ -229,9 +234,8 @@
 	    I_add_file_to_group_ref(rasters[m], mapset, &ref);
     }
 
-    G_message(_("Writing subgroup REF"));
+    G_debug(1, "writing subgroup REF");
     I_put_subgroup_ref(group, subgroup, &ref);
-    G_message(_("Done."));
 
     return 0;
 }
@@ -249,41 +253,49 @@
     I_get_group_ref(group, &ref_tmp);
     I_init_group_ref(&ref);
 
-    /* Parse through supplied rasters */
-    for (m = 0; m < k; m++) {
+ 
+    /* Go through existing files to check for duplicates */
+    for (m = 0; m < ref_tmp.nfiles; m++) {
 	skip = 0;
-	strcpy(tmp_name, rasters[m]);
-	mapset = G_mapset();
+	/* Parse through supplied rasters */
+	for (n = 0; n < k; n++) {
+	    strcpy(tmp_name, rasters[n]);
+	    mapset = G_mapset();
 
-	/* Parse out mapset */
-	if (G__name_is_fully_qualified(rasters[m], xname, xmapset)) {
-	    strcpy(tmp_name, xname);
-	    strcpy(mapset, xmapset);
-	}
+	    /* Parse out mapset */
+	    if (G__name_is_fully_qualified(rasters[n], xname, xmapset)) {
+		strcpy(tmp_name, xname);
+		strcpy(mapset, xmapset);
+	    }
 
-	/* Go through existing files to check for duplicates */
-	for (n = 0; n < ref_tmp.nfiles; n++) {
-	    if ((strcmp(tmp_name, ref_tmp.file[n].name) == 0) &&
-		(strcmp(mapset, ref_tmp.file[n].mapset) == 0)) {
-		G_message(_("Found file <%s@%s> in group."), tmp_name, mapset);
+	    if ((strcmp(tmp_name, ref_tmp.file[m].name) == 0) &&
+		(strcmp(mapset, ref_tmp.file[m].mapset) == 0)) {
+		G_message(_("Removing raster map <%s> from group"),
+			  G_fully_qualified_name(tmp_name, mapset));
+		skip = 1;
+		break;
 	    }
-	    else {
-		I_add_file_to_group_ref(ref_tmp.file[n].name,
-					ref_tmp.file[n].mapset, &ref);
-	    }
 	}
+	
+	if (skip == 0) {
+	    I_add_file_to_group_ref(ref_tmp.file[m].name,
+				    ref_tmp.file[m].mapset, &ref);
+	}
     }
 
-    G_message(_("Writing group REF"));
+    G_debug(1, "writing group REF");
     I_put_group_ref(group, &ref);
-    G_message(_("Done."));
 
+    if (ref.nfiles == ref_tmp.nfiles) {
+	G_warning(_("No raster map removed"));
+    }
+
     return 0;
 }
 
 
 static int remove_subgroup_files(char group[INAME_LEN],
-			  char subgroup[INAME_LEN], char **rasters, int k)
+				 char subgroup[INAME_LEN], char **rasters, int k)
 {
     int m, n, skip;
     struct Ref ref;
@@ -295,35 +307,42 @@
     I_get_subgroup_ref(group, subgroup, &ref_tmp);
     I_init_group_ref(&ref);
 
-    /* Parse through supplied rasters */
-    for (m = 0; m < k; m++) {
+    /* Go through existing files to check for duplicates */
+    for (m = 0; m < ref_tmp.nfiles; m++) {
 	skip = 0;
-	strcpy(tmp_name, rasters[m]);
-	mapset = G_mapset();
+	/* Parse through supplied rasters */
+	for (n = 0; n < k; n++) {
+	    strcpy(tmp_name, rasters[n]);
+	    mapset = G_mapset();
 
-	/* Parse out mapset */
-	if (G__name_is_fully_qualified(rasters[m], xname, xmapset)) {
-	    strcpy(tmp_name, xname);
-	    strcpy(mapset, xmapset);
-	}
+	    /* Parse out mapset */
+	    if (G__name_is_fully_qualified(rasters[n], xname, xmapset)) {
+		strcpy(tmp_name, xname);
+		strcpy(mapset, xmapset);
+	    }
 
-	/* Go through existing files to check for duplicates */
-	for (n = 0; n < ref_tmp.nfiles; n++) {
-	    if ((strcmp(tmp_name, ref_tmp.file[n].name) == 0) &&
-		(strcmp(mapset, ref_tmp.file[n].mapset) == 0)) {
-		G_message(_("Found file <%s@%s> in subgroup."), tmp_name, mapset);
+	    if ((strcmp(tmp_name, ref_tmp.file[m].name) == 0) &&
+		(strcmp(mapset, ref_tmp.file[m].mapset) == 0)) {
+		G_message(_("Removing raster map <%s> from subgroup"),
+			  G_fully_qualified_name(tmp_name, mapset));
+		skip = 1;
+		break;
 	    }
-	    else {
-		I_add_file_to_group_ref(ref_tmp.file[n].name,
-					ref_tmp.file[n].mapset, &ref);
-	    }
 	}
+	
+	if (skip == 0) {
+	    I_add_file_to_group_ref(ref_tmp.file[m].name,
+				    ref_tmp.file[m].mapset, &ref);
+	}
     }
 
-    G_message(_("Writing subgroup REF"));
+    G_debug(1, "writing subgroup REF");
     I_put_subgroup_ref(group, subgroup, &ref);
-    G_message(_("Done."));
 
+    if (ref.nfiles == ref_tmp.nfiles) {
+	G_warning(_("No raster map removed"));
+    }
+
     return 0;
 }
 



More information about the grass-commit mailing list