main.c 3.0 KB

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