raster3d_main.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /****************************************************************************
  2. *
  3. * MODULE: r3.colors.out
  4. *
  5. * AUTHOR(S): Glynn Clements
  6. *
  7. * PURPOSE: Allows export of the color table for a 3D raster map.
  8. *
  9. * COPYRIGHT: (C) 2008, 2010-2011 Glynn Clements and the GRASS Development Team
  10. *
  11. * This program is free software under the GNU General
  12. * Public License (>=v2). Read the file COPYING that
  13. * comes with GRASS for details.
  14. *
  15. ***************************************************************************/
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <grass/gis.h>
  19. #include <grass/raster.h>
  20. #include <grass/raster3d.h>
  21. #include <grass/glocale.h>
  22. /* Run in raster3d mode */
  23. int main(int argc, char **argv)
  24. {
  25. struct GModule *module;
  26. struct
  27. {
  28. struct Option *map, *file;
  29. } opt;
  30. struct
  31. {
  32. struct Flag *p;
  33. } flag;
  34. const char *file;
  35. FILE * fp;
  36. struct Colors colors;
  37. struct FPRange range;
  38. G_gisinit(argv[0]);
  39. module = G_define_module();
  40. G_add_keyword(_("raster3d"));
  41. G_add_keyword(_("color table"));
  42. G_add_keyword(_("export"));
  43. module->description =
  44. _("Exports the color table associated with a 3D raster map.");
  45. opt.map = G_define_standard_option(G_OPT_R3_MAP);
  46. opt.file = G_define_standard_option(G_OPT_F_OUTPUT);
  47. opt.file->key = "rules";
  48. opt.file->label = _("Path to output rules file");
  49. opt.file->description = _("If not given write to standard output");
  50. opt.file->required = NO;
  51. flag.p = G_define_flag();
  52. flag.p->key = 'p';
  53. flag.p->description = _("Output values as percentages");
  54. if (G_parser(argc, argv))
  55. exit(EXIT_FAILURE);
  56. file = opt.file->answer;
  57. if (Rast3d_read_colors(opt.map->answer, "", &colors) < 0)
  58. G_fatal_error(_("Unable to read color table for raster3d map <%s>"),
  59. opt.map->answer);
  60. Rast3d_read_range(opt.map->answer, "", &range);
  61. if (!file || strcmp(file, "-") == 0)
  62. fp = stdout;
  63. else {
  64. fp = fopen(file, "w");
  65. if (!fp)
  66. G_fatal_error(_("Unable to open output file <%s>"), file);
  67. }
  68. Rast_print_colors(&colors, range.min, range.max, fp,
  69. flag.p->answer ? 1 : 0);
  70. exit(EXIT_SUCCESS);
  71. }