[GRASS-SVN] r40659 - grass/trunk/raster/r.watershed/ram
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Jan 26 04:00:23 EST 2010
Author: mmetz
Date: 2010-01-26 04:00:22 -0500 (Tue, 26 Jan 2010)
New Revision: 40659
Modified:
grass/trunk/raster/r.watershed/ram/init_vars.c
Log:
initialize alt, wat and asp together
Modified: grass/trunk/raster/r.watershed/ram/init_vars.c
===================================================================
--- grass/trunk/raster/r.watershed/ram/init_vars.c 2010-01-26 08:57:49 UTC (rev 40658)
+++ grass/trunk/raster/r.watershed/ram/init_vars.c 2010-01-26 09:00:22 UTC (rev 40659)
@@ -10,8 +10,8 @@
int init_vars(int argc, char *argv[])
{
int 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, ele_map_type;
size_t ele_size;
@@ -132,6 +132,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);
Rast_set_c_null_value(&alt_value, 1);
+ Rast_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[seg_idx] = alt_value;
+ wat[seg_idx] = wat_value;
+ asp[seg_idx] = 0;
if (er_flag) {
r_h[seg_idx] = 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 = Rast_allocate_c_buf();
if (run_flag) {
- /* ... with input map flow: amount of overland flow per cell */
fd = Rast_open_old(run_name, "");
for (r = 0; r < nrows; r++) {
Rast_get_c_row(fd, buf, r);
@@ -224,22 +230,6 @@
}
Rast_close(fd);
}
- else {
- /* ... with 1.0 */
- for (r = 0; r < nrows; r++) {
- for (c = 0; c < ncols; c++) {
- if (MASK_flag) {
- block_value = FLAG_GET(worked, r, c);
- if (!block_value)
- 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