main.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /****************************************************************************
  2. *
  3. * MODULE: d.colors
  4. * AUTHOR(S): Jim Westervelt (CERL) (original contributor)
  5. * Markus Neteler <neteler itc.it>,
  6. * Bernhard Reiter <bernhard intevation.de>,
  7. * Eric G. Miller <egm2 jps.net>,
  8. * Glynn Clements <glynn gclements.plus.com>,
  9. * Hamish Bowman <hamish_b yahoo.com>
  10. * PURPOSE: Enables the user to change color table of raster map layers
  11. * COPYRIGHT: (C) 1999-2007 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. #include <stdlib.h>
  19. #include <grass/gis.h>
  20. #include <grass/glocale.h>
  21. #include <grass/display.h>
  22. #include "colors.h"
  23. int main(int argc, char **argv)
  24. {
  25. char name[128] = "";
  26. struct Option *map;
  27. struct GModule *module;
  28. char *mapset;
  29. char buff[500];
  30. /* must run in a term window */
  31. G_putenv("GRASS_UI_TERM", "1");
  32. /* Initialize the GIS calls */
  33. G_gisinit(argv[0]);
  34. module = G_define_module();
  35. G_add_keyword(_("display"));
  36. G_add_keyword(_("color table"));
  37. G_add_keyword(_("raster"));
  38. module->description =
  39. "Allows the user to interactively change the color table "
  40. "of a raster map layer displayed on the graphics monitor.";
  41. map = G_define_option();
  42. map->key = "map";
  43. map->type = TYPE_STRING;
  44. if (*name)
  45. map->answer = name;
  46. if (*name)
  47. map->required = NO;
  48. else
  49. map->required = YES;
  50. map->gisprompt = "old,cell,raster";
  51. map->description = "Name of raster map";
  52. if (G_parser(argc, argv))
  53. exit(1);
  54. /* Make sure map is available */
  55. if (map->answer == NULL)
  56. exit(0);
  57. mapset = G_find_raster2(map->answer, "");
  58. if (mapset == NULL) {
  59. char msg[256];
  60. sprintf(msg, "Raster file [%s] not available", map->answer);
  61. G_fatal_error(msg);
  62. }
  63. if (Rast_map_is_fp(map->answer, mapset)) {
  64. sprintf(buff,
  65. "Raster file [%s] is floating point! \nd.colors only works with integer maps",
  66. map->answer);
  67. G_fatal_error(buff);
  68. }
  69. /* connect to the driver */
  70. if (R_open_driver() != 0)
  71. G_fatal_error("No graphics device selected");
  72. /* Read in the map region associated with graphics window */
  73. D_setup(0);
  74. get_map_info(map->answer, mapset);
  75. R_close_driver();
  76. exit(0);
  77. }