[GRASS5] PATCH: i.gensig
Markus Neteler
neteler at itc.it
Fri Jul 22 03:44:30 EDT 2005
Brad,
I did a quick inspection - looks good to me.
Markus
On Thu, Jul 21, 2005 at 02:23:05PM -0700, Brad Douglas wrote:
> I need to clean up some old cruft I had not already committed to
> generate a clean, uncluttered patch for the tempfile issues.
>
> Any objections to the attached patch? Just some benign updates to
> i.gensig to do with message output and localization.
>
>
> --
> Brad Douglas <rez at touchofmadness.com>
> ? imagery/i.gensig/OBJ.x86_64-unknown-linux-gnu
> Index: imagery/i.gensig/check.c
> ===================================================================
> RCS file: /grassrepository/grass6/imagery/i.gensig/check.c,v
> retrieving revision 2.0
> diff -u -r2.0 check.c
> --- imagery/i.gensig/check.c 9 Nov 2004 12:55:04 -0000 2.0
> +++ imagery/i.gensig/check.c 21 Jul 2005 21:18:31 -0000
> @@ -1,6 +1,9 @@
> #include "imagery.h"
> +#include "glocale.h"
> #include "signature.h"
> #include "local_proto.h"
> +
> +
> int
> check_signatures (struct Signature *S)
> {
> @@ -18,14 +21,14 @@
> if (!can_invert(temp.sig[0].var, S->nbands))
> {
> S->sig[i].status = -1;
> - fprintf (stderr, "Signature %d not invertible\n", i+1);
> + G_message(_("Signature [%d] not invertible,"), i+1);
> continue;
> }
> copy_covariances (temp.sig[0].var, S->sig[i].var, S->nbands);
> if (!eigen(temp.sig[0].var, lambda, S->nbands))
> {
> S->sig[i].status = -1;
> - fprintf (stderr, "Signature %d can't get eigen values\n", i+1);
> + G_message(_("Signature [%d] can't get eigen values."), i+1);
> continue;
> }
> for (j = 0; j < S->nbands; j++)
> @@ -33,7 +36,7 @@
> if (lambda[j] <= 0.0)
> {
> S->sig[i].status = -1;
> - fprintf (stderr, "Signature %d not positive definite\n", i+1);
> + G_message(_("Signature [%d] not positive definite."), i+1);
> break;
> }
> }
> Index: imagery/i.gensig/covariance.c
> ===================================================================
> RCS file: /grassrepository/grass6/imagery/i.gensig/covariance.c,v
> retrieving revision 2.1
> diff -u -r2.1 covariance.c
> --- imagery/i.gensig/covariance.c 13 Jul 2005 15:22:44 -0000 2.1
> +++ imagery/i.gensig/covariance.c 21 Jul 2005 21:18:31 -0000
> @@ -1,9 +1,11 @@
> #include <stdlib.h>
> #include "imagery.h"
> +#include "glocale.h"
> #include "signature.h"
> #include "files.h"
> #include "local_proto.h"
>
> +
> /* must be called after compute_means() */
> int compute_covariances (struct files *files, struct Signature *S)
> {
> @@ -21,7 +23,8 @@
> ncols = G_window_cols();
> class = (CELL *) G_calloc (ncols, sizeof(CELL));
>
> - fprintf (stderr, "Calculating class covariance matri%s ...", S->nsigs==1?"x":"ces");
> + G_message(_("Calculating class covariance matri%s ..."),
> + S->nsigs==1 ? "x" : "ces");
>
> for (row = 0; row < nrows; row++)
> {
> Index: imagery/i.gensig/get_train.c
> ===================================================================
> RCS file: /grassrepository/grass6/imagery/i.gensig/get_train.c,v
> retrieving revision 2.1
> diff -u -r2.1 get_train.c
> --- imagery/i.gensig/get_train.c 13 Jul 2005 15:22:44 -0000 2.1
> +++ imagery/i.gensig/get_train.c 21 Jul 2005 21:18:31 -0000
> @@ -1,8 +1,10 @@
> #include <stdlib.h>
> #include "imagery.h"
> +#include "glocale.h"
> #include "signature.h"
> #include "files.h"
>
> +
> int get_training_classes (struct files *files, struct Signature *S)
> {
> int fd;
> @@ -23,11 +25,12 @@
> /* determine the categories in the map */
> I_init_signatures (S, files->nbands);
> G_init_cell_stats (&cell_stats);
> - fprintf (stderr, "Finding training classes ...");
> + G_message(_("Finding training classes ..."));
> for (row = 0; row < nrows; row++)
> {
> G_percent (row, nrows, 2);
> - if (G_get_c_raster_row(fd, cell, row) < 0) exit(1);
> + if (G_get_c_raster_row(fd, cell, row) < 0)
> + G_fatal_error(_("Unable to read raster row."));
> G_update_cell_stats (cell, ncols, &cell_stats);
> }
> G_percent (row, nrows, 2);
> @@ -49,15 +52,11 @@
> n++;
> }
> else
> - fprintf (stderr,
> - "WARNING: Training class [%d] only has one cell - this class will be ignored\n", cat);
> + G_warning(_("Training class [%d] only has one cell - this class will be ignored"), cat);
> }
>
> if (n==0)
> - {
> - fprintf (stderr, "ERROR: training map has no classes\n");
> - exit(1);
> - }
> + G_fatal_error(_("Training map has no classes."));
>
> list = (CELL *) G_calloc (n, sizeof(CELL));
> n = 0;
> @@ -70,7 +69,7 @@
>
> files->ncats = n;
> files->training_cats = list;
> - fprintf (stderr, "%d class%s\n", files->ncats, files->ncats==1?"":"es" );
> + G_message(_("%d class%s"), files->ncats, files->ncats==1 ? "" : "es");
>
> return 0;
> }
> Index: imagery/i.gensig/main.c
> ===================================================================
> RCS file: /grassrepository/grass6/imagery/i.gensig/main.c,v
> retrieving revision 2.1
> diff -u -r2.1 main.c
> --- imagery/i.gensig/main.c 13 Jul 2005 15:22:44 -0000 2.1
> +++ imagery/i.gensig/main.c 21 Jul 2005 21:18:31 -0000
> @@ -1,23 +1,25 @@
> #include <stdlib.h>
> #include "imagery.h"
> +#include "glocale.h"
> #include "signature.h"
> #include "parms.h"
> #include "files.h"
> #include "local_proto.h"
>
> +
> int main (int argc, char *argv[])
> {
> struct parms parms; /* command line parms */
> struct files files; /* file descriptors, io, buffers */
> struct Signature S;
> - struct GModule *module;
> + struct GModule *module;
>
> G_gisinit (argv[0]);
>
> module = G_define_module();
> module->description =
> - "Generates statistics for i.maxlik "
> - "from raster map layer.";
> + _("Generates statistics for i.maxlik "
> + "from raster map layer.");
>
> parse (argc,argv, &parms);
> openfiles (&parms, &files);
> @@ -28,5 +30,6 @@
> compute_covariances (&files, &S);
> check_signatures (&S);
> write_sigfile (&parms, &S);
> +
> exit(0);
> }
> Index: imagery/i.gensig/means.c
> ===================================================================
> RCS file: /grassrepository/grass6/imagery/i.gensig/means.c,v
> retrieving revision 2.1
> diff -u -r2.1 means.c
> --- imagery/i.gensig/means.c 13 Jul 2005 15:22:44 -0000 2.1
> +++ imagery/i.gensig/means.c 21 Jul 2005 21:18:31 -0000
> @@ -1,9 +1,11 @@
> #include <stdlib.h>
> #include "imagery.h"
> +#include "glocale.h"
> #include "signature.h"
> #include "files.h"
> #include "local_proto.h"
>
> +
> int compute_means (struct files *files, struct Signature *S)
> {
> int n, n_nulls;
> @@ -19,7 +21,7 @@
> ncols = G_window_cols();
> class = (CELL *) G_calloc (ncols, sizeof(CELL));
>
> - fprintf (stderr, "Calculating class mean%s ...", S->nsigs==1?"":"s");
> + G_message(_("Calculating class mean%s ..."), S->nsigs==1 ? "" : "s");
>
> for (row = 0; row < nrows; row++)
> {
> Index: imagery/i.gensig/opencell.c
> ===================================================================
> RCS file: /grassrepository/grass6/imagery/i.gensig/opencell.c,v
> retrieving revision 2.1
> diff -u -r2.1 opencell.c
> --- imagery/i.gensig/opencell.c 13 Jul 2005 15:22:44 -0000 2.1
> +++ imagery/i.gensig/opencell.c 21 Jul 2005 21:18:31 -0000
> @@ -1,5 +1,7 @@
> #include <stdlib.h>
> #include "gis.h"
> +#include "glocale.h"
> +
>
> CELL *
> open_cell (char *name, char *mapset, int *fd)
> @@ -9,6 +11,5 @@
> if (*fd >= 0)
> return G_allocate_cell_buf();
>
> - fprintf (stderr, "ERROR: unable to open raster map [%s]\n", name);
> - exit(1);
> + G_fatal_error(_("Unable to open raster map [%s]."), name);
> }
> Index: imagery/i.gensig/openfiles.c
> ===================================================================
> RCS file: /grassrepository/grass6/imagery/i.gensig/openfiles.c,v
> retrieving revision 2.1
> diff -u -r2.1 openfiles.c
> --- imagery/i.gensig/openfiles.c 13 Jul 2005 15:22:44 -0000 2.1
> +++ imagery/i.gensig/openfiles.c 21 Jul 2005 21:18:31 -0000
> @@ -1,7 +1,10 @@
> #include <stdlib.h>
> #include "imagery.h"
> +#include "glocale.h"
> #include "parms.h"
> #include "files.h"
> +
> +
> int
> openfiles (struct parms *parms, struct files *files)
> {
> @@ -11,18 +14,12 @@
>
>
> if (!I_get_subgroup_ref (parms->group, parms->subgroup, &Ref))
> - {
> - fprintf (stderr,
> - "ERROR: unable to read REF file for subgroup [%s] in group [%s]\n",
> - parms->subgroup, parms->group);
> - exit(1);
> - }
> + G_fatal_error(_("Unable to read REF file for subgroup [%s] in group [%s]."),
> + parms->subgroup, parms->group);
> +
> if (Ref.nfiles <= 0)
> - {
> - fprintf (stderr, "ERROR: subgroup [%s] in group [%s] contains no files\n",
> - parms->subgroup, parms->group);
> - exit(1);
> - }
> + G_fatal_error(_("Subgroup [%s] in group [%s] contains no files."),
> + parms->subgroup, parms->group);
>
> /* allocate file descriptors, and array of io buffers */
> files->nbands = Ref.nfiles;
> Index: imagery/i.gensig/parse.c
> ===================================================================
> RCS file: /grassrepository/grass6/imagery/i.gensig/parse.c,v
> retrieving revision 2.1
> diff -u -r2.1 parse.c
> --- imagery/i.gensig/parse.c 13 Jul 2005 15:22:44 -0000 2.1
> +++ imagery/i.gensig/parse.c 21 Jul 2005 21:18:31 -0000
> @@ -1,7 +1,10 @@
> #include <stdlib.h>
> #include "gis.h"
> +#include "glocale.h"
> #include "imagery.h"
> #include "parms.h"
> +
> +
> int
> parse (int argc, char *argv[], struct parms *parms)
> {
> @@ -9,27 +12,27 @@
>
> trainingmap = G_define_option();
> trainingmap->key = "trainingmap";
> - trainingmap->description = "ground truth training map";
> + trainingmap->description = _("ground truth training map");
> trainingmap->required = YES;
> trainingmap->type = TYPE_STRING;
> trainingmap->gisprompt = "old,cell,raster";
>
> group = G_define_option();
> group->key = "group";
> - group->description = "imagery group";
> + group->description = _("imagery group");
> group->required = YES;
> group->type = TYPE_STRING;
> group->gisprompt = "old,group,group";
>
> subgroup = G_define_option();
> subgroup->key = "subgroup";
> - subgroup->description = "subgroup containing image files";
> + subgroup->description = _("subgroup containing image files");
> subgroup->required = YES;
> subgroup->type = TYPE_STRING;
>
> sigfile = G_define_option();
> sigfile->key = "signaturefile";
> - sigfile->description = "resultant signature file";
> + sigfile->description = _("resultant signature file");
> sigfile->required = YES;
> sigfile->type = TYPE_STRING;
>
> @@ -42,20 +45,13 @@
>
> /* check all the inputs */
> if(G_find_cell(parms->training_map, "") == NULL)
> - {
> - fprintf (stderr, "ERROR: training map [%s] not found\n", parms->training_map);
> - exit(1);
> - }
> + G_fatal_error(_("Training map [%s] not found."), parms->training_map);
> +
> if (!I_find_group(parms->group))
> - {
> - fprintf (stderr, "ERROR: group [%s] not found\n", parms->group);
> - exit(1);
> - }
> + G_fatal_error(_("Group [%s] not found."), parms->group);
> +
> if (!I_find_subgroup(parms->group, parms->subgroup))
> - {
> - fprintf (stderr, "ERROR: subgroup [%s] not found\n", parms->subgroup);
> - exit(1);
> - }
> + G_fatal_error(_("Subgroup [%s] not found."), parms->subgroup);
>
> return 0;
> }
> Index: imagery/i.gensig/print_sig.c
> ===================================================================
> RCS file: /grassrepository/grass6/imagery/i.gensig/print_sig.c,v
> retrieving revision 2.0
> diff -u -r2.0 print_sig.c
> --- imagery/i.gensig/print_sig.c 9 Nov 2004 12:56:10 -0000 2.0
> +++ imagery/i.gensig/print_sig.c 21 Jul 2005 21:18:31 -0000
> @@ -1,28 +1,28 @@
> #include "imagery.h"
> +#include "glocale.h"
> #include "signature.h"
>
> +
> int
> print_one_sig (struct Signature *S, int k)
> {
> struct One_Sig *s;
> int i,n;
> - FILE *fd;
> -
> - fd = stdout;
>
> s = &S->sig[k];
>
> - fprintf (fd, "#%s\n", s->desc);
> - fprintf (fd, "%d\n", s->npoints);
> + G_message(_("#%s"), s->desc);
> + G_message("%d", s->npoints);
> +
> for (i=0; i < S->nbands; i++)
> - fprintf(fd, "%lf ", s->mean[i]);
> - fprintf (fd, "\n");
> + G_message("%lf\n", s->mean[i]);
> +
> for (i=0; i < S->nbands; i++)
> {
> for (n=0; n < S->nbands; n++)
> - fprintf (fd, "%lf ", s->var[i][n]);
> - fprintf (fd, "\n");
> + G_message("%lf\n", s->var[i][n]);
> }
> +
> if (s->have_color)
> - fprintf (fd, "%f %f %f\n", s->r, s->g, s->b);
> + G_message("%f %f %f", s->r, s->g, s->b);
> }
> Index: imagery/i.gensig/write_sig.c
> ===================================================================
> RCS file: /grassrepository/grass6/imagery/i.gensig/write_sig.c,v
> retrieving revision 2.1
> diff -u -r2.1 write_sig.c
> --- imagery/i.gensig/write_sig.c 13 Jul 2005 15:22:44 -0000 2.1
> +++ imagery/i.gensig/write_sig.c 21 Jul 2005 21:18:31 -0000
> @@ -1,24 +1,23 @@
> #include <stdlib.h>
> #include "imagery.h"
> +#include "glocale.h"
> #include "signature.h"
> #include "parms.h"
>
> +
> int write_sigfile (struct parms *parms, struct Signature *S)
> {
> FILE *fd;
>
> fd = I_fopen_signature_file_new (parms->group, parms->subgroup, parms->sigfile);
> if (fd == NULL)
> - {
> - fprintf (stderr, "ERROR: unable to create signature file [%s] ", parms->sigfile);
> - fprintf (stderr, "for subgroup [%s] in group [%s]\n",
> - parms->subgroup, parms->group);
> - exit(1);
> - }
> - fprintf (stderr, "Writing signature file [%s] ...", parms->sigfile);
> - fflush (stderr);
> + G_fatal_error(_("Unable to create signature file [%s] for "
> + "subgroup [%s] in group [%s]."),
> + parms->sigfile, parms->subgroup, parms->group);
> +
> + G_message(_("Writing signature file [%s] ..."), parms->sigfile);
> I_write_signatures (fd, S);
> - fprintf (stderr, "\n");
> + G_message(_("Done."));
>
> return 0;
> }
--
Markus Neteler <neteler itc it> http://mpa.itc.it
ITC-irst - Centro per la Ricerca Scientifica e Tecnologica
MPBA - Predictive Models for Biol. & Environ. Data Analysis
Via Sommarive, 18 - 38050 Povo (Trento), Italy
More information about the grass-dev
mailing list