~ubuntu-branches/ubuntu/vivid/grass/vivid-proposed

« back to all changes in this revision

Viewing changes to raster/r.random.surface/main.c

  • Committer: Package Import Robot
  • Author(s): Bas Couwenberg
  • Date: 2015-02-20 23:12:08 UTC
  • mfrom: (8.2.6 experimental)
  • Revision ID: package-import@ubuntu.com-20150220231208-1u6qvqm84v430b10
Tags: 7.0.0-1~exp1
* New upstream release.
* Update python-ctypes-ternary.patch to use if/else instead of and/or.
* Drop check4dev patch, rely on upstream check.
* Add build dependency on libpq-dev to grass-dev for libpq-fe.h.
* Drop patches applied upstream, refresh remaining patches.
* Update symlinks for images switched from jpg to png.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <stdlib.h>
25
25
#include <stdio.h>
26
26
#include <grass/gis.h>
 
27
#include <grass/raster.h>
27
28
#include <grass/glocale.h>
28
29
 
29
 
#define MAIN
30
30
#include "ransurf.h"
31
31
#include "local_proto.h"
32
 
#undef MAIN
 
32
 
 
33
BIGF BigF;
 
34
double **Surface, NS, EW, FilterSD, AllMaxDist, *Norm;
 
35
int MapCount, FDM, Rs, Cs, Theory;
 
36
CELL *CellBuffer;
 
37
FILTER *AllFilters, Filter;
 
38
CATINFO CatInfo;
 
39
int *Seeds, Seed, NumSeeds, Low, High, NumMaps, NumFilters, OutFD;
 
40
char Buf[240], **OutNames, *TheoryName, *Mapset;
 
41
 
 
42
struct Flag *Uniform;
 
43
struct Option *Distance, *Exponent, *Weight;
 
44
struct Option *Output;
 
45
struct Option *range_high_stuff;
 
46
struct Option *SeedStuff;
33
47
 
34
48
int main(int argc, char **argv)
35
49
{
36
50
    struct GModule *module;
 
51
 
37
52
    int DoMap, DoFilter, MapSeed;
38
 
    double ran1();
39
53
 
40
54
    G_gisinit(argv[0]);
41
55
 
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.");
46
62
 
47
 
    Init(argc, argv);
 
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";
 
70
 
 
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";
 
79
 
 
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";
 
87
 
 
88
    Weight = G_define_option();
 
89
    Weight->key = "flat";
 
90
    Weight->type = TYPE_DOUBLE;
 
91
    Weight->multiple = NO;
 
92
    Weight->required = NO;
 
93
    Weight->description =
 
94
        _("Distance filter remains flat before beginning exponent");
 
95
    Weight->answer = "0.0";
 
96
 
 
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]");
 
103
 
 
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";
 
110
 
 
111
    Uniform = G_define_flag();
 
112
    Uniform->key = 'u';
 
113
    Uniform->description = _("Uniformly distributed cell values");
 
114
 
 
115
    if (G_parser(argc, argv))
 
116
        exit(EXIT_FAILURE);
 
117
 
 
118
    Init();
 
119
 
48
120
    if (Uniform->answer)
49
121
        GenNorm();
 
122
 
50
123
    CalcSD();
 
124
 
51
125
    for (DoMap = 0; DoMap < NumMaps; DoMap++) {
52
 
        OutFD = G_open_cell_new(OutNames[DoMap]);
53
 
        if (OutFD < 0)
54
 
            G_fatal_error(_("Unable to open raster map <%s>"),
55
 
                          OutNames[DoMap]);
 
126
        OutFD = Rast_open_c_new(OutNames[DoMap]);
56
127
 
57
 
        G_message(_("Generating raster map <%s>..."),
58
 
                  OutNames[DoMap]);
 
128
        G_message(_("Generating raster map <%s>..."), OutNames[DoMap]);
59
129
 
60
130
        if (Seeds[DoMap] == SEED_MIN - 1)
61
131
            Seeds[DoMap] = (int)(ran1() * SEED_MAX);
65
135
 
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",
 
138
            G_debug(1,
 
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);
72
143
 
73
144
            MakeBigF();
74
145
            CalcSurface();
78
149
    }
79
150
 
80
151
    G_done_msg(" ");
81
 
    
 
152
 
82
153
    exit(EXIT_SUCCESS);
83
154
}