24
24
#include <stdlib.h>
26
26
#include <grass/gis.h>
27
#include <grass/raster.h>
27
28
#include <grass/glocale.h>
30
30
#include "ransurf.h"
31
31
#include "local_proto.h"
34
double **Surface, NS, EW, FilterSD, AllMaxDist, *Norm;
35
int MapCount, FDM, Rs, Cs, Theory;
37
FILTER *AllFilters, Filter;
39
int *Seeds, Seed, NumSeeds, Low, High, NumMaps, NumFilters, OutFD;
40
char Buf[240], **OutNames, *TheoryName, *Mapset;
43
struct Option *Distance, *Exponent, *Weight;
44
struct Option *Output;
45
struct Option *range_high_stuff;
46
struct Option *SeedStuff;
34
48
int main(int argc, char **argv)
36
50
struct GModule *module;
37
52
int DoMap, DoFilter, MapSeed;
40
54
G_gisinit(argv[0]);
42
56
module = G_define_module();
43
module->keywords = _("raster, random, surface");
57
G_add_keyword(_("raster"));
58
G_add_keyword(_("surface"));
59
G_add_keyword(_("random"));
44
60
module->description =
45
61
_("Generates random surface(s) with spatial dependence.");
63
Output = G_define_option();
64
Output->key = "output";
65
Output->type = TYPE_STRING;
66
Output->required = YES;
67
Output->multiple = YES;
68
Output->description = _("Name for output raster map(s)");
69
Output->gisprompt = "new,cell,raster";
71
Distance = G_define_option();
72
Distance->key = "distance";
73
Distance->type = TYPE_DOUBLE;
74
Distance->required = NO;
75
Distance->multiple = NO;
76
Distance->description =
77
_("Maximum distance of spatial correlation (value >= 0.0)");
78
Distance->answer = "0.0";
80
Exponent = G_define_option();
81
Exponent->key = "exponent";
82
Exponent->type = TYPE_DOUBLE;
83
Exponent->multiple = NO;
84
Exponent->required = NO;
85
Exponent->description = _("Distance decay exponent (value > 0.0)");
86
Exponent->answer = "1.0";
88
Weight = G_define_option();
90
Weight->type = TYPE_DOUBLE;
91
Weight->multiple = NO;
92
Weight->required = NO;
94
_("Distance filter remains flat before beginning exponent");
95
Weight->answer = "0.0";
97
SeedStuff = G_define_option();
98
SeedStuff->key = "seed";
99
SeedStuff->type = TYPE_INTEGER;
100
SeedStuff->required = NO;
101
SeedStuff->description =
102
_("Random seed (SEED_MIN >= value >= SEED_MAX), default [random]");
104
range_high_stuff = G_define_option();
105
range_high_stuff->key = "high";
106
range_high_stuff->type = TYPE_INTEGER;
107
range_high_stuff->required = NO;
108
range_high_stuff->description = _("Maximum cell value of distribution");
109
range_high_stuff->answer = "255";
111
Uniform = G_define_flag();
113
Uniform->description = _("Uniformly distributed cell values");
115
if (G_parser(argc, argv))
48
120
if (Uniform->answer)
51
125
for (DoMap = 0; DoMap < NumMaps; DoMap++) {
52
OutFD = G_open_cell_new(OutNames[DoMap]);
54
G_fatal_error(_("Unable to open raster map <%s>"),
126
OutFD = Rast_open_c_new(OutNames[DoMap]);
57
G_message(_("Generating raster map <%s>..."),
128
G_message(_("Generating raster map <%s>..."), OutNames[DoMap]);
60
130
if (Seeds[DoMap] == SEED_MIN - 1)
61
131
Seeds[DoMap] = (int)(ran1() * SEED_MAX);
66
136
for (DoFilter = 0; DoFilter < NumFilters; DoFilter++) {
67
137
CopyFilter(&Filter, AllFilters[DoFilter]);
68
G_debug(1, "Starting filter #%d, distance: %.*lf, exponent: %.*lf, flat: %.*lf",
139
"Starting filter #%d, distance: %.*lf, exponent: %.*lf, flat: %.*lf",
69
140
DoFilter, Digits(2.0 * Filter.MaxDist, 6),
70
2.0 * Filter.MaxDist, Digits(1.0 / Filter.Exp, 6),
71
1.0 / Filter.Exp, Digits(Filter.Mult, 6), Filter.Mult);
141
2.0 * Filter.MaxDist, Digits(1.0 / Filter.Exp, 6),
142
1.0 / Filter.Exp, Digits(Filter.Mult, 6), Filter.Mult);