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