2
/****************************************************************************
6
* AUTHOR(S): Glynn Clements
8
* PURPOSE: Allows export of the color table for a raster map.
10
* COPYRIGHT: (C) 2008, 2010-2011 Glynn Clements and the GRASS Development Team
12
* This program is free software under the GNU General
13
* Public License (>=v2). Read the file COPYING that
14
* comes with GRASS for details.
16
***************************************************************************/
20
#include <grass/gis.h>
21
#include <grass/raster.h>
22
#include <grass/glocale.h>
24
/* Run in raster mode */
25
int main(int argc, char **argv)
27
struct GModule *module;
30
struct Option *map, *file;
44
module = G_define_module();
45
G_add_keyword(_("raster"));
46
G_add_keyword(_("color table"));
47
G_add_keyword(_("export"));
49
_("Exports the color table associated with a raster map.");
51
opt.map = G_define_standard_option(G_OPT_R_MAP);
53
opt.file = G_define_standard_option(G_OPT_F_OUTPUT);
54
opt.file->key = "rules";
55
opt.file->label = _("Path to output rules file");
56
opt.file->description = _("If not given write to standard output");
57
opt.file->required = NO;
59
flag.p = G_define_flag();
61
flag.p->description = _("Output values as percentages");
63
if (G_parser(argc, argv))
66
file = opt.file->answer;
68
if (Rast_read_colors(opt.map->answer, "", &colors) < 0)
69
G_fatal_error(_("Unable to read color table for raster map <%s>"),
72
Rast_read_fp_range(opt.map->answer, "", &range);
74
if (!file || strcmp(file, "-") == 0)
77
fp = fopen(file, "w");
79
G_fatal_error(_("Unable to open output file <%s>"), file);
82
Rast_print_colors(&colors, range.min, range.max, fp,
83
flag.p->answer ? 1 : 0);