~ubuntu-branches/ubuntu/wily/grass/wily

« back to all changes in this revision

Viewing changes to raster/r.basins.fill/main.c

Tags: 7.0.0~rc1+ds1-1~exp1
* New upstream release candidate.
* Repack upstream tarball, remove precompiled Python objects.
* Add upstream metadata.
* Update gbp.conf and Vcs-Git URL to use the experimental branch.
* Update watch file for GRASS 7.0.
* Drop build dependencies for Tcl/Tk, add build dependencies:
  python-numpy, libnetcdf-dev, netcdf-bin, libblas-dev, liblapack-dev
* Update Vcs-Browser URL to use cgit instead of gitweb.
* Update paths to use grass70.
* Add configure options: --with-netcdf, --with-blas, --with-lapack,
  remove --with-tcltk-includes.
* Update patches for GRASS 7.
* Update copyright file, changes:
  - Update copyright years
  - Group files by license
  - Remove unused license sections
* Add patches for various typos.
* Fix desktop file with patch instead of d/rules.
* Use minimal dh rules.
* Bump Standards-Version to 3.9.6, no changes.
* Use dpkg-maintscript-helper to replace directories with symlinks.
  (closes: #776349)
* Update my email to use @debian.org address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
8
8
 *
9
9
 * PURPOSE:      Generates a raster map layer showing watershed subbasins.
10
10
 *
11
 
 * COPYRIGHT:    (C) 2005 by the GRASS Development Team
 
11
 * COPYRIGHT:    (C) 2005, 2010 by the GRASS Development Team
12
12
 *
13
13
 *               This program is free software under the GNU General Public
14
14
 *               License (>=v2). Read the file COPYING that comes with GRASS
27
27
#include <string.h>
28
28
#include <stdio.h>
29
29
#include <grass/gis.h>
 
30
#include <grass/raster.h>
 
31
#include <grass/glocale.h>
 
32
 
30
33
#include "local_proto.h"
31
 
#include <grass/glocale.h>
32
 
 
33
34
 
34
35
#define NOMASK 1
35
36
 
38
39
{
39
40
    int partfd;
40
41
    int nrows, ncols;
41
 
    char drain_name[GNAME_MAX], *drain_mapset;
42
 
    char ridge_name[GNAME_MAX], *ridge_mapset;
43
 
    char part_name[GNAME_MAX], *part_mapset;
 
42
    const char *drain_name;
 
43
    const char *ridge_name;
 
44
    const char *part_name;
44
45
    CELL *drain, *ridge;
45
46
    struct Cell_head window;
46
47
    int row, col, npass, tpass;
47
48
    struct GModule *module;
48
 
    struct Option *opt1, *opt2, *opt3, *opt4;
 
49
    struct Option *num_opt, *drain_opt, *ridge_opt, *part_opt;
49
50
 
50
51
    G_gisinit(argv[0]);
51
52
 
52
53
    module = G_define_module();
53
 
    module->keywords = _("raster");
 
54
    G_add_keyword(_("raster"));
 
55
    G_add_keyword(_("hydrology"));
 
56
    G_add_keyword(_("watershed"));
54
57
    module->description =
55
 
        _("Generates a raster map layer showing " "watershed subbasins.");
56
 
 
57
 
    opt1 = G_define_option();
58
 
    opt1->key = "number";
59
 
    opt1->type = TYPE_INTEGER;
60
 
    opt1->required = YES;
61
 
    opt1->description = _("Number of passes through the dataset");
62
 
    opt1->gisprompt = "old,cell,raster";
63
 
 
64
 
    opt2 = G_define_option();
65
 
    opt2->key = "c_map";
66
 
    opt2->type = TYPE_STRING;
67
 
    opt2->required = YES;
68
 
    opt2->description = _("Coded stream network file name");
69
 
    opt2->gisprompt = "old,cell,raster";
70
 
 
71
 
    opt3 = G_define_option();
72
 
    opt3->key = "t_map";
73
 
    opt3->type = TYPE_STRING;
74
 
    opt3->required = YES;
75
 
    opt3->description = _("Thinned ridge network file name");
76
 
    opt3->gisprompt = "old,cell,raster";
77
 
 
78
 
    opt4 = G_define_option();
79
 
    opt4->key = "result";
80
 
    opt4->type = TYPE_STRING;
81
 
    opt4->required = YES;
82
 
    opt4->description = _("Name for the resultant watershed partition file");
83
 
    opt4->gisprompt = "new,cell,raster";
 
58
        _("Generates watershed subbasins raster map.");
 
59
 
 
60
    drain_opt = G_define_standard_option(G_OPT_R_INPUT);
 
61
    drain_opt->key = "cnetwork";
 
62
    drain_opt->description = _("Name of input coded stream network raster map");
 
63
 
 
64
    ridge_opt = G_define_standard_option(G_OPT_R_INPUT);
 
65
    ridge_opt->key = "tnetwork";
 
66
    ridge_opt->description = _("Name of input thinned ridge network raster map");
 
67
 
 
68
    part_opt = G_define_standard_option(G_OPT_R_OUTPUT);
 
69
    
 
70
    num_opt = G_define_option();
 
71
    num_opt->key = "number";
 
72
    num_opt->type = TYPE_INTEGER;
 
73
    num_opt->required = YES;
 
74
    num_opt->description = _("Number of passes through the dataset");
84
75
 
85
76
    if (G_parser(argc, argv))
86
77
        exit(EXIT_FAILURE);
87
78
 
88
 
    sscanf(opt1->answer, "%d", &tpass);
89
 
 
90
 
    strcpy(drain_name, opt2->answer);
91
 
    drain_mapset = G_find_cell2(drain_name, "");
92
 
    if (drain_mapset == NULL)
93
 
        G_fatal_error(_("Raster map <%s> not found"), opt2->answer);
94
 
 
95
 
    /* this isn't a nice thing to do. G_align_window() should be used first */
96
 
    G_get_cellhd(drain_name, drain_mapset, &window);
97
 
    G_set_window(&window);
98
 
 
99
 
    nrows = G_window_rows();
100
 
    ncols = G_window_cols();
101
 
 
102
 
    strcpy(ridge_name, opt3->answer);
103
 
    ridge_mapset = G_find_cell2(ridge_name, "");
104
 
    if (ridge_mapset == NULL)
105
 
        G_fatal_error(_("Raster map <%s> not found"), opt3->answer);
106
 
 
107
 
    strcpy(part_name, opt4->answer);
108
 
    part_mapset = G_find_cell2(part_name, "");
109
 
    if (part_mapset != NULL)
110
 
        G_fatal_error(_("Raster map <%s> already exists"), opt4->answer);
111
 
 
112
 
    drain = read_map(drain_name, drain_mapset, NOMASK, nrows, ncols);
113
 
    ridge = read_map(ridge_name, ridge_mapset, NOMASK, nrows, ncols);
114
 
 
115
 
    partfd = G_open_cell_new(part_name);
116
 
    if (partfd < 0)
117
 
        G_fatal_error(_("Unable to create raster map <%s>"), part_name);
 
79
    sscanf(num_opt->answer, "%d", &tpass);
 
80
 
 
81
    drain_name = drain_opt->answer;
 
82
 
 
83
    /* this isn't a nice thing to do. Rast_align_window() should be used first */
 
84
    Rast_get_cellhd(drain_name, "", &window);
 
85
    Rast_set_window(&window);
 
86
 
 
87
    nrows = Rast_window_rows();
 
88
    ncols = Rast_window_cols();
 
89
 
 
90
    ridge_name = ridge_opt->answer;
 
91
 
 
92
    part_name = part_opt->answer;
 
93
 
 
94
    drain = read_map(drain_name, NOMASK, nrows, ncols);
 
95
    ridge = read_map(ridge_name, NOMASK, nrows, ncols);
 
96
 
 
97
    partfd = Rast_open_c_new(part_name);
118
98
 
119
99
    /* run through file and set streams to zero at locations where ridges exist */
120
100
    for (row = 0; row < nrows; row++) {
161
141
 
162
142
    /* write out partitioned watershed map */
163
143
    for (row = 0; row < nrows; row++)
164
 
        G_put_raster_row(partfd, drain + (row * ncols), CELL_TYPE);
 
144
        Rast_put_row(partfd, drain + (row * ncols), CELL_TYPE);
165
145
 
166
146
    G_message(_("Creating support files for <%s>..."), part_name);
167
 
    G_close_cell(partfd);
 
147
    Rast_close(partfd);
168
148
 
169
149
    exit(EXIT_SUCCESS);
170
150
}