main.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /****************************************************************************
  2. *
  3. * MODULE: r.surf.fractal
  4. * AUTHOR(S): Jo Wood, 19th October, 1994
  5. * PURPOSE: GRASS module to manipulate a raster map layer.
  6. * COPYRIGHT: (C) 2005-2008 by the GRASS Development Team
  7. *
  8. * This program is free software under the GNU General Public
  9. * License (>=v2). Read the file COPYING that comes with GRASS
  10. * for details.
  11. *
  12. *****************************************************************************/
  13. #include <grass/glocale.h>
  14. #include "frac.h"
  15. const char
  16. *rast_out_name, /* Name of the raster output file. */
  17. *mapset_out;
  18. int
  19. fd_out, /* File descriptor of output raster */
  20. Steps; /* Number of intermediate images. */
  21. double H; /* Hausdorff-Besickovitch dimension. */
  22. int main(int argc, char *argv[])
  23. {
  24. struct GModule *module;
  25. struct Option *rast_out; /* Structure for output raster */
  26. struct Option *frac_dim; /* Fractal dimension of surface. */
  27. struct Option *num_images; /* Number of images to produce. */
  28. G_gisinit(argv[0]); /* Link with GRASS interface. */
  29. module = G_define_module();
  30. G_add_keyword(_("raster"));
  31. G_add_keyword(_("surface"));
  32. G_add_keyword(_("fractal"));
  33. module->description =
  34. _("Creates a fractal surface of a given fractal dimension.");
  35. rast_out = G_define_standard_option(G_OPT_R_OUTPUT);
  36. frac_dim = G_define_option();
  37. frac_dim->key = "dimension";
  38. frac_dim->description = _("Fractal dimension of surface (2 < D < 3)");
  39. frac_dim->type = TYPE_DOUBLE;
  40. frac_dim->required = NO;
  41. frac_dim->answer = "2.05";
  42. num_images = G_define_option();
  43. num_images->key = "number";
  44. num_images->description = _("Number of intermediate images to produce");
  45. num_images->type = TYPE_INTEGER;
  46. num_images->required = NO;
  47. num_images->answer = "0";
  48. if (G_parser(argc, argv)) /* Performs the prompting for */
  49. exit(EXIT_FAILURE); /* keyboard input. */
  50. rast_out_name = rast_out->answer;
  51. sscanf(frac_dim->answer, "%lf", &H);
  52. H = 3.0 - H;
  53. Steps = atoi(num_images->answer) + 1;
  54. G_debug(1, "Steps %d", Steps);
  55. mapset_out = G_mapset(); /* Set output to current mapset. */
  56. /*--------------------------------------------------------------------*/
  57. /* CHECK FRACTAL DIMENSION IS WITHIN LIMITS */
  58. /*--------------------------------------------------------------------*/
  59. if ((H <= 0) || (H >= 1)) {
  60. G_fatal_error(_("Fractal dimension of %.2lf must be between 2 and 3."),
  61. 3.0 - H);
  62. }
  63. process();
  64. G_done_msg(_("Raster map <%s> created."), rast_out_name);
  65. return EXIT_SUCCESS;
  66. }