[GRASS-SVN] r40657 -
grass/branches/develbranch_6/raster/r.watershed/ram
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jan 26 03:56:28 EST 2010
Author: mmetz
Date: 2010-01-26 03:56:27 -0500 (Tue, 26 Jan 2010)
New Revision: 40657
Modified:
grass/branches/develbranch_6/raster/r.watershed/ram/init_vars.c
Log:
initialize alt, wat and asp together
Modified: grass/branches/develbranch_6/raster/r.watershed/ram/init_vars.c
===================================================================
--- grass/branches/develbranch_6/raster/r.watershed/ram/init_vars.c 2010-01-26 08:53:12 UTC (rev 40656)
+++ grass/branches/develbranch_6/raster/r.watershed/ram/init_vars.c 2010-01-26 08:56:27 UTC (rev 40657)
@@ -9,8 +9,8 @@
int init_vars(int argc, char *argv[])
{
SHORT r, c;
- CELL *buf, alt_value, wat_value, asp_value, block_value;
- DCELL dvalue;
+ CELL *buf, alt_value, asp_value, block_value;
+ DCELL dvalue, wat_value;
void *elebuf, *ptr;
int fd, index, ele_map_type;
size_t ele_size;
@@ -129,6 +129,12 @@
alt =
(CELL *) G_malloc(sizeof(CELL) * size_array(&alt_seg, nrows, ncols));
+ wat =
+ (DCELL *) G_malloc(sizeof(DCELL) *
+ size_array(&wat_seg, nrows, ncols));
+ asp =
+ (CELL *) G_malloc(size_array(&asp_seg, nrows, ncols) * sizeof(CELL));
+
if (er_flag) {
r_h =
(CELL *) G_malloc(sizeof(CELL) * size_array(&r_h_seg, nrows, ncols));
@@ -152,6 +158,7 @@
ele_scale = 1000; /* should be enough to do the trick */
/* read elevation input and mark NULL/masked cells */
+ /* intialize accumulation and drainage direction */
MASK_flag = 0;
do_points = nrows * ncols;
for (r = 0; r < nrows; r++) {
@@ -170,6 +177,7 @@
FLAG_SET(worked, r, c);
FLAG_SET(in_list, r, c);
G_set_c_null_value(&alt_value, 1);
+ G_set_d_null_value(&wat_value, 1);
do_points--;
}
else {
@@ -186,8 +194,11 @@
dvalue *= ele_scale;
alt_value = ele_round(dvalue);
}
+ wat_value = 1.0;
}
alt[index] = alt_value;
+ wat[index] = wat_value;
+ asp[index] = 0;
if (er_flag) {
r_h[index] = alt_value;
}
@@ -199,14 +210,9 @@
if (do_points < nrows * ncols)
MASK_flag = 1;
- /* initialize flow accumulation ... */
- wat =
- (DCELL *) G_malloc(sizeof(DCELL) *
- size_array(&wat_seg, nrows, ncols));
-
+ /* read flow accumulation from input map flow: amount of overland flow per cell */
buf = G_allocate_cell_buf();
if (run_flag) {
- /* ... with input map flow: amount of overland flow per cell */
fd = G_open_cell_old(run_name, "");
if (fd < 0) {
G_fatal_error(_("unable to open runoff map layer"));
@@ -227,22 +233,6 @@
}
G_close_cell(fd);
}
- else {
- /* ... with 1.0 */
- for (r = 0; r < nrows; r++) {
- for (c = 0; c < ncols; c++) {
- if (MASK_flag) {
- index = FLAG_GET(worked, r, c);
- if (!index)
- wat[SEG_INDEX(wat_seg, r, c)] = 1.0;
- }
- else
- wat[SEG_INDEX(wat_seg, r, c)] = 1.0;
- }
- }
- }
- asp =
- (CELL *) G_malloc(size_array(&asp_seg, nrows, ncols) * sizeof(CELL));
/* depression: drainage direction will be set to zero later */
if (pit_flag) {
More information about the grass-commit
mailing list