1 
2 /****************************************************************************
3  *
4  * MODULE:       r.describe
5  *
6  * AUTHOR(S):    Michael Shapiro - CERL
7  *
8  * PURPOSE:      Prints terse list of category values found in a raster
9  *               map layer.
10  *
11  * COPYRIGHT:    (C) 2006 by the GRASS Development Team
12  *
13  *               This program is free software under the GNU General Public
14  *               License (>=v2). Read the file COPYING that comes with GRASS
15  *               for details.
16  *
17  ***************************************************************************/
18 
19 #include <stdlib.h>
20 #include <string.h>
21 #include <stdio.h>
22 #include <grass/gis.h>
23 #include "local_proto.h"
24 #include <grass/glocale.h>
25 
26 
main(int argc,char * argv[])27 int main(int argc, char *argv[])
28 {
29     int as_int;
30     int compact;
31     int range;
32     int windowed;
33     int nsteps;
34     char *no_data_str;
35     struct GModule *module;
36     struct
37     {
38 	struct Flag *one;
39 	struct Flag *r;
40 	struct Flag *d;
41 	struct Flag *i;
42 	struct Flag *n;
43     } flag;
44     struct
45     {
46 	struct Option *map;
47 	struct Option *nv;
48 	struct Option *nsteps;
49     } option;
50 
51     G_gisinit(argv[0]);
52 
53     module = G_define_module();
54     G_add_keyword(_("raster"));
55     G_add_keyword(_("metadata"));
56     module->description =
57 	_("Prints terse list of category values found in a raster map layer.");
58 
59     /* define different options */
60     option.map = G_define_standard_option(G_OPT_R_MAP);
61 
62     option.nv = G_define_standard_option(G_OPT_M_NULL_VALUE);
63     option.nv->answer = "*";
64 
65     option.nsteps = G_define_option();
66     option.nsteps->key = "nsteps";
67     option.nsteps->type = TYPE_INTEGER;
68     option.nsteps->required = NO;
69     option.nsteps->multiple = NO;
70     option.nsteps->answer = "255";
71     option.nsteps->description = _("Number of quantization steps");
72 
73     /*define the different flags */
74 
75     flag.one = G_define_flag();
76     flag.one->key = '1';
77     flag.one->description = _("Print the output one value per line");
78 
79     flag.r = G_define_flag();
80     flag.r->key = 'r';
81     flag.r->description = _("Only print the range of the data");
82 
83     flag.n = G_define_flag();
84     flag.n->key = 'n';
85     flag.n->description = _("Suppress reporting of any NULLs");
86 
87     flag.d = G_define_flag();
88     flag.d->key = 'd';
89     flag.d->description = _("Use the current region");
90 
91     flag.i = G_define_flag();
92     flag.i->key = 'i';
93     flag.i->description = _("Read floating-point map as integer");
94 
95     if (0 > G_parser(argc, argv))
96 	exit(EXIT_FAILURE);
97 
98     compact = (!flag.one->answer);
99     range = flag.r->answer;
100     windowed = flag.d->answer;
101     as_int = flag.i->answer;
102     no_data_str = option.nv->answer;
103 
104     if (sscanf(option.nsteps->answer, "%d", &nsteps) != 1 || nsteps < 1)
105 	G_fatal_error(_("%s = %s -- must be greater than zero"),
106 		      option.nsteps->key, option.nsteps->answer);
107 
108     describe(option.map->answer, compact, no_data_str,
109 	     range, windowed, nsteps, as_int, flag.n->answer);
110 
111     return EXIT_SUCCESS;
112 }
113