Debian Codegraph @

raster/r.surf.gauss/main.c

raw
1 /****************************************************************************
2 *
3 * MODULE: r.surf.gauss
4 * AUTHOR(S): Jo Wood, 19th October, 24th October 1991 (original contributor)
5 * Midlands Regional Research Laboratory (ASSIST)
6 * PURPOSE:
7 * COPYRIGHT: (C) 1999-2007 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 <stdlib.h>
16 #include <stdio.h>
17 #include <grass/gis.h>
18 #include <grass/gmath.h>
19 #include <grass/glocale.h>
20 #include "local_proto.h"
21
22 int main(int argc, char *argv[])
23 {
24
25 /****** INITIALISE ******/
26 double gauss_mean, gauss_sigma;
27 long seed_value;
28
29 struct GModule *module;
30 struct Option *out;
31 struct Option *mean;
32 struct Option *sigma;
33 struct Option *seed;
34
35 G_gisinit(argv[0]);
36
37 module = G_define_module();
38 G_add_keyword(_("raster"));
39 G_add_keyword(_("surface"));
40 G_add_keyword(_("random"));
41 module->label = _("Generates a raster map using gaussian "
42 "random number generator.");
43 module->description = _("Mean and standard deviation of gaussian deviates "
44 "can be expressed by the user.");
45
46 out = G_define_standard_option(G_OPT_R_OUTPUT);
47
48 mean = G_define_option();
49 mean->key = "mean";
50 mean->description = _("Distribution mean");
51 mean->type = TYPE_DOUBLE;
52 mean->answer = "0.0";
53
54 sigma = G_define_option();
55 sigma->key = "sigma";
56 sigma->description = _("Standard deviation");
57 sigma->type = TYPE_DOUBLE;
58 sigma->answer = "1.0";
59
60 seed = G_define_standard_option(G_OPT_M_SEED);
61
62 if (G_parser(argc, argv))
63 exit(EXIT_FAILURE);
64
65 /****** INITIALISE RANDOM NUMBER GENERATOR ******/
66 if (seed->answer) {
67 seed_value = atol(seed->answer);
68 G_srand48(seed_value);
69 G_verbose_message(_("Read random seed from %s option: %ld"), seed->key,
70 seed_value);
71 }
72 else {
73 /* default as it used to be */
74 seed_value = G_math_srand_auto();
75 G_verbose_message(_("Autogenerated random seed set to: %ld"),
76 seed_value);
77 }
78
79 sscanf(mean->answer, "%lf", &gauss_mean);
80 sscanf(sigma->answer, "%lf", &gauss_sigma);
81
82 gaussurf(out->answer, gauss_mean, gauss_sigma);
83
84 exit(EXIT_SUCCESS);
85 }