104
91
infd = G_malloc(nfiles * sizeof(int));
105
92
statf = G_malloc(nfiles * sizeof(struct Cell_stats));
93
cellhd = G_malloc(nfiles * sizeof(struct Cell_head));
107
95
for (i = 0; i < nfiles; i++) {
108
96
const char *name = names[i];
109
const char *mapset = G_find_cell2(name, "");
112
if (mapset == NULL) {
113
G_warning(_("Raster map <%s> not found"), name);
121
fd = G_open_cell_old(name, mapset);
99
fd = Rast_open_old(name, "");
129
map_type = G_get_raster_map_type(fd);
103
map_type = Rast_get_map_type(fd);
130
104
if (map_type == FCELL_TYPE && out_type == CELL_TYPE)
131
105
out_type = FCELL_TYPE;
132
106
else if (map_type == DCELL_TYPE)
133
107
out_type = DCELL_TYPE;
135
G_init_cell_stats(&statf[i]);
109
Rast_init_cell_stats(&statf[i]);
111
Rast_get_cellhd(name, "", &cellhd[i]);
139
G_fatal_error(_("One or more input raster maps not found"));
141
114
rname = opt2->answer;
142
outfd = G_open_raster_new(new_name = rname, out_type);
144
G_fatal_error(_("Unable to create raster map <%s>"), new_name);
146
presult = G_allocate_raster_buf(out_type);
147
patch = G_allocate_raster_buf(out_type);
149
nrows = G_window_rows();
150
ncols = G_window_cols();
115
outfd = Rast_open_new(new_name = rname, out_type);
117
presult = Rast_allocate_buf(out_type);
118
patch = Rast_allocate_buf(out_type);
120
Rast_get_window(&window);
121
nrows = Rast_window_rows();
122
ncols = Rast_window_cols();
152
124
G_verbose_message(_("Percent complete..."));
153
125
for (row = 0; row < nrows; row++) {
126
double north_edge, south_edge;
154
128
G_percent(row, nrows, 2);
155
if (G_get_raster_row(infd[0], presult, row, out_type) < 0)
156
G_fatal_error(_("Unable to read raster map <%s> row %d"),
129
Rast_get_row(infd[0], presult, row, out_type);
131
north_edge = Rast_row_to_northing(row, &window);
132
south_edge = north_edge - window.ns_res;
159
134
if (out_type == CELL_TYPE)
160
G_update_cell_stats((CELL *) presult, ncols, &statf[0]);
135
Rast_update_cell_stats((CELL *) presult, ncols, &statf[0]);
161
136
for (i = 1; i < nfiles; i++) {
162
if (G_get_raster_row(infd[i], patch, row, out_type) < 0)
163
G_fatal_error(_("Unable to read raster map <%s> row %d"),
137
/* check if raster i overlaps with the current row */
138
if (south_edge >= cellhd[i].north ||
139
north_edge <= cellhd[i].south ||
140
window.west >= cellhd[i].east ||
141
window.east <= cellhd[i].west)
144
Rast_get_row(infd[i], patch, row, out_type);
166
(presult, patch, &statf[i], ncols, out_type, ZEROFLAG))
146
(presult, patch, &statf[i], ncols, out_type, use_zero))
169
G_put_raster_row(outfd, presult, out_type);
149
Rast_put_row(outfd, presult, out_type);
171
151
G_percent(row, nrows, 2);
175
155
for (i = 0; i < nfiles; i++)
176
G_close_cell(infd[i]);
178
158
* build the new cats and colors. do this before closing the new
179
159
* file, in case the new file is one of the patching files as well.
181
G_message(_("Creating support files for raster map <%s>"), new_name);
161
G_verbose_message(_("Creating support files for raster map <%s>..."), new_name);
182
162
support(names, statf, nfiles, &cats, &cats_ok, &colr, &colr_ok, out_type);
184
164
/* now close (and create) the result */
187
G_write_cats(new_name, &cats);
167
Rast_write_cats(new_name, &cats);
189
G_write_colors(new_name, G_mapset(), &colr);
169
Rast_write_colors(new_name, G_mapset(), &colr);
191
G_short_history(new_name, "raster", &history);
192
G_command_history(&history);
193
G_write_history(new_name, &history);
171
Rast_short_history(new_name, "raster", &history);
172
Rast_command_history(&history);
173
Rast_write_history(new_name, &history);
195
175
exit(EXIT_SUCCESS);