[GRASS-SVN] r34794 - in grass/branches/develbranch_6:
imagery/i.cluster lib/imagery
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Dec 8 06:44:30 EST 2008
Author: martinl
Date: 2008-12-08 06:44:30 -0500 (Mon, 08 Dec 2008)
New Revision: 34794
Modified:
grass/branches/develbranch_6/imagery/i.cluster/checkpt.c
grass/branches/develbranch_6/imagery/i.cluster/main.c
grass/branches/develbranch_6/imagery/i.cluster/open_files.c
grass/branches/develbranch_6/lib/imagery/sigfile.c
Log:
i.cluster: message standardization
more guisections
imagerylib: allow fully qualified group name + doxygenization (sigfice.c)
Modified: grass/branches/develbranch_6/imagery/i.cluster/checkpt.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.cluster/checkpt.c 2008-12-08 10:32:22 UTC (rev 34793)
+++ grass/branches/develbranch_6/imagery/i.cluster/checkpt.c 2008-12-08 11:44:30 UTC (rev 34794)
@@ -37,7 +37,7 @@
if (verbose) {
cur_time = time(NULL);
elapsed_time = cur_time - start_time;
- G_message(_("Iteration %d: %% Convergence: %.2f (%s elapsed, %s left)"),
+ G_message(_("Iteration %.2d: convergence %.2f%% (%s elapsed, %s left)"),
X->iteration, (double)X->percent_stable,
print_time(elapsed_time),
print_time(iters * elapsed_time / (X->iteration + 1) -
Modified: grass/branches/develbranch_6/imagery/i.cluster/main.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.cluster/main.c 2008-12-08 10:32:22 UTC (rev 34793)
+++ grass/branches/develbranch_6/imagery/i.cluster/main.c 2008-12-08 11:44:30 UTC (rev 34794)
@@ -11,7 +11,7 @@
* Glynn Clements <glynn gclements.plus.com>,
* Jan-Oliver Wagner <jan intevation.de>
* PURPOSE: builds pixel clusters based on multi-image pixel values
- * COPYRIGHT: (C) 1999-2006 by the GRASS Development Team
+ * COPYRIGHT: (C) 1999-2008 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
@@ -77,7 +77,7 @@
G_gisinit(argv[0]);
module = G_define_module();
- module->keywords = _("imagery");
+ module->keywords = _("imagery, classification, signatures");
module->label =
_("Generates spectral signatures for land cover "
"types in an image using a clustering algorithm.");
@@ -86,19 +86,17 @@
"to generate an unsupervised image classification.");
parm.group_name = G_define_standard_option(G_OPT_I_GROUP);
- parm.group_name->description =
- _("Group of imagery files to be clustered");
parm.subgroup_name = G_define_option();
parm.subgroup_name->key = "subgroup";
parm.subgroup_name->type = TYPE_STRING;
parm.subgroup_name->required = YES;
- parm.subgroup_name->description = _("Subgroup name in the above group");
+ parm.subgroup_name->description = _("Name of subgroup in the above group");
parm.out_sig = G_define_standard_option(G_OPT_F_OUTPUT);
parm.out_sig->key = "sigfile";
parm.out_sig->required = YES;
- parm.out_sig->description = _("File to contain result signatures");
+ parm.out_sig->description = _("Name for output file containing result signatures");
parm.class = G_define_option();
parm.class->key = "classes";
@@ -106,11 +104,12 @@
parm.class->options = "1-255";
parm.class->required = YES;
parm.class->description = _("Initial number of classes");
+ parm.class->guisection = _("Settings");
parm.seed_sig = G_define_standard_option(G_OPT_F_INPUT);
parm.seed_sig->key = "seed";
parm.seed_sig->required = NO;
- parm.seed_sig->description = _("File containing initial signatures");
+ parm.seed_sig->description = _("Name of file containing initial signatures");
parm.sample_interval = G_define_option();
parm.sample_interval->key = "sample";
@@ -119,6 +118,7 @@
parm.sample_interval->required = NO;
parm.sample_interval->description =
_("Sampling intervals (by row and col); default: ~10,000 pixels");
+ parm.sample_interval->guisection = _("Settings");
parm.iterations = G_define_option();
parm.iterations->key = "iterations";
@@ -126,6 +126,7 @@
parm.iterations->required = NO;
parm.iterations->description = _("Maximum number of iterations");
parm.iterations->answer = "30";
+ parm.iterations->guisection = _("Settings");
parm.convergence = G_define_option();
parm.convergence->key = "convergence";
@@ -134,6 +135,7 @@
parm.convergence->options = "0-100";
parm.convergence->description = _("Percent convergence");
parm.convergence->answer = "98.0";
+ parm.convergence->guisection = _("Settings");
parm.separation = G_define_option();
parm.separation->key = "separation";
@@ -141,6 +143,7 @@
parm.separation->required = NO;
parm.separation->description = _("Cluster separation");
parm.separation->answer = "0.0";
+ parm.separation->guisection = _("Settings");
parm.min_size = G_define_option();
parm.min_size->key = "min_size";
@@ -148,11 +151,12 @@
parm.min_size->required = NO;
parm.min_size->description = _("Minimum number of pixels in a class");
parm.min_size->answer = "17";
+ parm.min_size->guisection = _("Settings");
parm.report_file = G_define_standard_option(G_OPT_F_OUTPUT);
parm.report_file->key = "reportfile";
parm.report_file->required = NO;
- parm.report_file->description = _("Output file to contain final report");
+ parm.report_file->description = _("Name for output file containing final report");
flag.q = G_define_flag();
flag.q->key = 'q';
@@ -175,10 +179,8 @@
if (sscanf(parm.class->answer, "%d", &maxclass) != 1 || maxclass < 1
|| maxclass > 255) {
- G_warning(_("\n<%s> -- illegal number of initial classes"),
- parm.class->answer);
- G_usage();
- exit(EXIT_FAILURE);
+ G_fatal_error(_("Illegal number of initial classes (%s)"),
+ parm.class->answer);
}
insigfile = parm.seed_sig->answer;
@@ -188,10 +190,8 @@
(parm.sample_interval->answer, "%d,%d", &sample_rows,
&sample_cols) != 2 || sample_rows < 1 || sample_cols < 1 ||
sample_rows > nrows || sample_cols > ncols) {
- G_warning(_("\n<%s> -- illegal value(s) of sample intervals"),
- parm.sample_interval->answer);
- G_usage();
- exit(EXIT_FAILURE);
+ G_fatal_error(_("Illegal value(s) of sample intervals (%s)"),
+ parm.sample_interval->answer);
}
}
else {
@@ -204,32 +204,24 @@
}
if (sscanf(parm.iterations->answer, "%d", &iters) != 1 || iters < 1) {
- G_warning(_("\n<%s> -- illegal value of iterations"),
- parm.iterations->answer);
- G_usage();
- exit(EXIT_FAILURE);
+ G_fatal_error(_("Illegal value of iterations (%s>)"),
+ parm.iterations->answer);
}
if (sscanf(parm.convergence->answer, "%lf", &conv) != 1 || conv < 0.0 ||
conv > 100.0) {
- G_warning(_("\n<%s> -- illegal value of convergence"),
- parm.convergence->answer);
- G_usage();
- exit(EXIT_FAILURE);
+ G_fatal_error(_("Illegal value of convergence (%s)"),
+ parm.convergence->answer);
}
if (sscanf(parm.separation->answer, "%lf", &sep) != 1 || sep < 0.0) {
- G_warning(_("\n<%s> -- illegal value of separation"),
- parm.separation->answer);
- G_usage();
- exit(EXIT_FAILURE);
+ G_fatal_error(_("Illegal value of separation (%s)"),
+ parm.separation->answer);
}
if (sscanf(parm.min_size->answer, "%d", &mcs) != 1 || mcs < 2) {
- G_warning(_("\n<%s> -- illegal value of min_size"),
- parm.min_size->answer);
- G_usage();
- exit(EXIT_FAILURE);
+ G_fatal_error(_("Illegal value of min_size (%s)"),
+ parm.min_size->answer);
}
verbose = !flag.q->answer;
@@ -239,9 +231,8 @@
else
report = fopen(reportfile, "w");
if (report == NULL) {
- G_warning(_("Can't creat reportfile: "));
- perror(reportfile);
- exit(EXIT_FAILURE);
+ G_fatal_error(_("Unable to create report file <%s>"),
+ reportfile);
}
open_files();
@@ -291,33 +282,33 @@
I_cluster_begin(&C, ref.nfiles);
count = 0;
- if (verbose)
- G_message(_("Reading image ... "));
+ G_message(_("Reading raster maps..."));
for (row = sample_rows - 1; row < nrows; row += sample_rows) {
- if (verbose)
- G_percent(row, nrows, 2);
+ G_percent(row, nrows, 2);
for (n = 0; n < ref.nfiles; n++)
if (G_get_d_raster_row(cellfd[n], cell[n], row) < 0)
- exit(EXIT_FAILURE);
+ G_fatal_error(_("Unable to read raster map row %d"),
+ row);
for (col = sample_cols - 1; col < ncols; col += sample_cols) {
count++;
for (n = 0; n < ref.nfiles; n++)
x[n] = cell[n][col];
if (I_cluster_point(&C, x) < 0)
- G_fatal_error(_("Out of Memory. Please run again and choose a smaller sample size"));
+ G_fatal_error(_("Out of Memory. Please run again and choose a "
+ "smaller sample size."));
}
}
- if (verbose)
- G_percent(nrows, nrows, 2);
+ G_percent(nrows, nrows, 2);
+
fprintf(report, _("Sample size: %d points\n"), C.npoints);
fprintf(report, "\n");
if (count < 2)
G_fatal_error(_("Not enough sample points. Please run again and "
- "choose a larger sample size"));
+ "choose a larger sample size."));
if (C.npoints < 2)
G_fatal_error(_("Not enough non-zero sample data points. Check "
- "your current region (and mask)"));
+ "your current region (and mask)."));
for (n = 0; n < ref.nfiles; n++) {
G_free(cell[n]);
@@ -341,7 +332,7 @@
fclose(fd);
}
else {
- G_fatal_error(_("Could not write signature file <%s> for group "
+ G_fatal_error(_("Unable to create signature file <%s> for group "
"<%s>, subsgroup <%s>"), outsigfile, group, subgroup);
}
@@ -352,6 +343,9 @@
fprintf(report, _("\n######## CLUSTER END (%s) ########\n"), G_date());
fclose(report);
+ G_done_msg(_("File <%s> created."),
+ outsigfile);
+
exit(EXIT_SUCCESS);
}
Modified: grass/branches/develbranch_6/imagery/i.cluster/open_files.c
===================================================================
--- grass/branches/develbranch_6/imagery/i.cluster/open_files.c 2008-12-08 10:32:22 UTC (rev 34793)
+++ grass/branches/develbranch_6/imagery/i.cluster/open_files.c 2008-12-08 11:44:30 UTC (rev 34794)
@@ -14,11 +14,12 @@
G_strip(group);
if (!I_find_group(group))
- G_fatal_error(_("\n group <%s> not found"), group);
+ G_fatal_error(_("Group <%s> not found"), group);
G_strip(subgroup);
if (!I_find_subgroup(group, subgroup))
- G_fatal_error(_("subgroup <%s> not found"), subgroup);
+ G_fatal_error(_("Subgroup <%s> in group <%s> not found"),
+ subgroup, group);
I_free_group_ref(&ref);
I_get_subgroup_ref(group, subgroup, &ref);
@@ -34,14 +35,15 @@
}
}
if (missing)
- exit(1);
+ G_fatal_error(_("No raster maps found"));
+
if (ref.nfiles <= 1) {
if (ref.nfiles <= 0)
- G_warning(_("Subgroup [%s] doesn't have any files"), subgroup);
+ G_warning(_("Subgroup <%s> doesn't have any raster maps"),
+ subgroup);
else
- G_warning(_("Subgroup [%s] only has 1 file"), subgroup);
- G_fatal_error(_("The subgroup must have at least 2 files to run %s"),
- G_program_name());
+ G_warning(_("Subgroup <%s> only has 1 raster map"), subgroup);
+ G_fatal_error(_("Subgroup must have at least 2 raster maps"));
}
cell = (DCELL **) G_malloc(ref.nfiles * sizeof(DCELL *));
@@ -51,20 +53,21 @@
name = ref.file[n].name;
mapset = ref.file[n].mapset;
if ((cellfd[n] = G_open_cell_old(name, mapset)) < 0)
- G_fatal_error(_("Unable to proceed"));
+ G_fatal_error(_("Unable to open raster map <%s>"),
+ G_fully_qualified_name(name, mapset));
}
I_init_signatures(&in_sig, ref.nfiles);
if (insigfile) {
fd = I_fopen_signature_file_old(group, subgroup, insigfile);
if (fd == NULL)
- G_fatal_error(_("Can't open seed signature file <%s>"),
+ G_fatal_error(_("Unable to open seed signature file <%s>"),
insigfile);
n = I_read_signatures(fd, &in_sig);
fclose(fd);
if (n < 0)
- G_fatal_error(_("Can't read signature file <%s>"),
+ G_fatal_error(_("Unable to read signature file <%s>"),
insigfile);
if (in_sig.nsigs > 255)
Modified: grass/branches/develbranch_6/lib/imagery/sigfile.c
===================================================================
--- grass/branches/develbranch_6/lib/imagery/sigfile.c 2008-12-08 10:32:22 UTC (rev 34793)
+++ grass/branches/develbranch_6/lib/imagery/sigfile.c 2008-12-08 11:44:30 UTC (rev 34794)
@@ -1,38 +1,75 @@
+/**
+ \file sigfile.c
+
+ \brief Imagery Library - Signature file functions.
+
+ (C) 2001-2008 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 for details.
+
+ \author USA CERL
+*/
+
#include <string.h>
#include <grass/imagery.h>
+/**
+ \brief Create signature file
+
+ \param group group name
+ \param subgroup subgroup name in given group
+ \param name signature filename
+
+ \return pointer to FILE*
+ \return NULL on error
+*/
FILE *I_fopen_signature_file_new(const char *group,
const char *subgroup, const char *name)
{
- char element[GNAME_MAX * 2];
+ char element[GPATH_MAX];
+ char group_name[GNAME_MAX], group_mapset[GMAPSET_MAX];
FILE *fd;
+ if (!G__name_is_fully_qualified(group, group_name, group_mapset)) {
+ strcpy(group_name, group);
+ }
+
/* create sigset directory */
- sprintf(element, "%s/subgroup/%s/sig", group, subgroup);
+ sprintf(element, "%s/subgroup/%s/sig", group_name, subgroup);
G__make_mapset_element_misc("group", element);
sprintf(element, "subgroup/%s/sig/%s", subgroup, name);
- fd = G_fopen_new_misc("group", element, group);
- if (fd == NULL)
- G_warning
- ("unable to create signature file %s for subgroup %s of group %s",
- name, subgroup, group);
+ fd = G_fopen_new_misc("group", element, group_name);
+
return fd;
}
+/**
+ \brief Open signature file
+
+ \param group group name
+ \param subgroup subgroup name in given group
+ \param name signature filename
+
+ \return pointer to FILE*
+ \return NULL on error
+*/
FILE *I_fopen_signature_file_old(const char *group,
const char *subgroup, const char *name)
{
- char element[GNAME_MAX * 2];
+ char element[GPATH_MAX];
+ char group_name[GNAME_MAX], group_mapset[GMAPSET_MAX];
FILE *fd;
+ if (!G__name_is_fully_qualified(group, group_name, group_mapset)) {
+ strcpy(group_name, group);
+ }
+
sprintf(element, "subgroup/%s/sig/%s", subgroup, name);
- fd = G_fopen_old_misc("group", element, group, G_mapset());
- if (fd == NULL)
- G_warning
- ("unable to open signature file %s for subgroup %s of group [%s in %s]",
- name, subgroup, group, G_mapset());
+ fd = G_fopen_old_misc("group", element, group_name, G_mapset());
+
return fd;
}
More information about the grass-commit
mailing list