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;
50
51
G_gisinit(argv[0]);
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.");
57
opt1 = G_define_option();
59
opt1->type = TYPE_INTEGER;
61
opt1->description = _("Number of passes through the dataset");
62
opt1->gisprompt = "old,cell,raster";
64
opt2 = G_define_option();
66
opt2->type = TYPE_STRING;
68
opt2->description = _("Coded stream network file name");
69
opt2->gisprompt = "old,cell,raster";
71
opt3 = G_define_option();
73
opt3->type = TYPE_STRING;
75
opt3->description = _("Thinned ridge network file name");
76
opt3->gisprompt = "old,cell,raster";
78
opt4 = G_define_option();
80
opt4->type = TYPE_STRING;
82
opt4->description = _("Name for the resultant watershed partition file");
83
opt4->gisprompt = "new,cell,raster";
58
_("Generates watershed subbasins raster map.");
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");
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");
68
part_opt = G_define_standard_option(G_OPT_R_OUTPUT);
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");
85
76
if (G_parser(argc, argv))
86
77
exit(EXIT_FAILURE);
88
sscanf(opt1->answer, "%d", &tpass);
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);
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);
99
nrows = G_window_rows();
100
ncols = G_window_cols();
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);
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);
112
drain = read_map(drain_name, drain_mapset, NOMASK, nrows, ncols);
113
ridge = read_map(ridge_name, ridge_mapset, NOMASK, nrows, ncols);
115
partfd = G_open_cell_new(part_name);
117
G_fatal_error(_("Unable to create raster map <%s>"), part_name);
79
sscanf(num_opt->answer, "%d", &tpass);
81
drain_name = drain_opt->answer;
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);
87
nrows = Rast_window_rows();
88
ncols = Rast_window_cols();
90
ridge_name = ridge_opt->answer;
92
part_name = part_opt->answer;
94
drain = read_map(drain_name, NOMASK, nrows, ncols);
95
ridge = read_map(ridge_name, NOMASK, nrows, ncols);
97
partfd = Rast_open_c_new(part_name);
119
99
/* run through file and set streams to zero at locations where ridges exist */
120
100
for (row = 0; row < nrows; row++) {