[GRASS-SVN] r44625 - grass/trunk/raster/r.watershed/seg
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri Dec 17 06:15:48 EST 2010
Author: mmetz
Date: 2010-12-17 03:15:48 -0800 (Fri, 17 Dec 2010)
New Revision: 44625
Modified:
grass/trunk/raster/r.watershed/seg/Gwater.h
grass/trunk/raster/r.watershed/seg/bseg_put.c
grass/trunk/raster/r.watershed/seg/close_maps.c
grass/trunk/raster/r.watershed/seg/cseg.h
grass/trunk/raster/r.watershed/seg/cseg_put.c
grass/trunk/raster/r.watershed/seg/def_basin.c
grass/trunk/raster/r.watershed/seg/do_astar.c
grass/trunk/raster/r.watershed/seg/do_cum.c
grass/trunk/raster/r.watershed/seg/dseg_put.c
grass/trunk/raster/r.watershed/seg/find_pour.c
grass/trunk/raster/r.watershed/seg/init_vars.c
grass/trunk/raster/r.watershed/seg/main.c
grass/trunk/raster/r.watershed/seg/no_stream.c
grass/trunk/raster/r.watershed/seg/over_cells.c
grass/trunk/raster/r.watershed/seg/sg_factor.c
grass/trunk/raster/r.watershed/seg/slope_len.c
grass/trunk/raster/r.watershed/seg/split_str.c
grass/trunk/raster/r.watershed/seg/sseg_get.c
grass/trunk/raster/r.watershed/seg/sseg_put.c
Log:
overhauled segment and memory handling
Modified: grass/trunk/raster/r.watershed/seg/Gwater.h
===================================================================
--- grass/trunk/raster/r.watershed/seg/Gwater.h 2010-12-17 11:14:48 UTC (rev 44624)
+++ grass/trunk/raster/r.watershed/seg/Gwater.h 2010-12-17 11:15:48 UTC (rev 44625)
@@ -44,9 +44,7 @@
#define POINT struct points
POINT {
- int r, c; /* , downr, downc */
- char asp; /* drainage direction */
- char guessed; /* accumulation will likely be an underestimate */
+ int r, c;
};
#define HEAP_PNT struct heap_point
@@ -80,16 +78,16 @@
extern double half_res, diag, max_length, dep_slope;
extern int bas_thres, tot_parts;
extern SSEG astar_pts;
-extern BSEG bitflags, s_b;
-extern CSEG dis, alt, asp, bas, haf, r_h, dep;
+extern BSEG bitflags, s_b, asp;
+extern CSEG dis, bas, haf, r_h, dep;
extern SSEG watalt;
extern DSEG slp, s_l, s_g, l_s, ril;
extern double segs_mb;
extern char zero, one;
extern double ril_value, d_zero, d_one;
extern int sides;
-extern int drain[3][3];
-extern int updrain[3][3];
+extern char drain[3][3];
+extern char updrain[3][3];
extern int nextdr[8];
extern int nextdc[8];
extern char ele_name[GNAME_MAX], pit_name[GNAME_MAX];
@@ -139,13 +137,7 @@
/* do_astar.c */
int do_astar(void);
-int add_pt(int, int, CELL, char, int);
-HEAP_PNT drop_pt(void);
-int sift_up(int, HEAP_PNT);
-int sift_up_mem(int, HEAP_PNT);
-int sift_down_disk(void);
-int fill_mem_heap(void);
-int cmp_pnt(HEAP_PNT *a, HEAP_PNT *b);
+int add_pt(int, int, CELL);
double get_slope(int, int, int, int, CELL, CELL);
/* do_cum.c */
Modified: grass/trunk/raster/r.watershed/seg/bseg_put.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/bseg_put.c 2010-12-17 11:14:48 UTC (rev 44624)
+++ grass/trunk/raster/r.watershed/seg/bseg_put.c 2010-12-17 11:15:48 UTC (rev 44625)
@@ -11,6 +11,14 @@
return 0;
}
+int bseg_put_row(BSEG * bseg, char *value, int row)
+{
+ if (segment_put_row(&(bseg->seg), value, row) < 0) {
+ G_warning("cseg_put(): could not write segment file");
+ return -1;
+ }
+ return 0;
+}
int bseg_put_old(BSEG * bseg, CELL * value, int row, int col)
{
Modified: grass/trunk/raster/r.watershed/seg/close_maps.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/close_maps.c 2010-12-17 11:14:48 UTC (rev 44624)
+++ grass/trunk/raster/r.watershed/seg/close_maps.c 2010-12-17 11:15:48 UTC (rev 44625)
@@ -12,15 +12,16 @@
DCELL min, max;
DCELL clr_min, clr_max;
DCELL sum, sum_sqr, stddev, lstddev, dvalue;
- WAT_ALT wa;
+ WAT_ALT *wabuf;
/* bseg_close(&swale); */
bseg_close(&bitflags);
- cseg_close(&alt);
if (wat_flag) {
G_message(_("Closing accumulation map"));
sum = sum_sqr = stddev = 0.0;
dbuf = Rast_allocate_d_buf();
+ wabuf = G_malloc(ncols * sizeof(WAT_ALT));
+ seg_flush(&watalt);
if (abs_acc) {
G_warning("Writing out only positive flow accumulation values.");
G_warning("Cells with a likely underestimate for flow accumulation can no longer be identified.");
@@ -31,10 +32,10 @@
for (r = 0; r < nrows; r++) {
G_percent(r, nrows, 1);
Rast_set_d_null_value(dbuf, ncols); /* reset row to all NULL */
+ seg_get_row(&watalt, (char *)wabuf, r);
for (c = 0; c < ncols; c++) {
/* dseg_get(&wat, &dvalue, r, c); */
- seg_get(&watalt, (char *)&wa, r, c);
- dvalue = wa.wat;
+ dvalue = wabuf[c].wat;
if (Rast_is_d_null_value(&dvalue) == 0 && dvalue) {
if (abs_acc) {
dvalue = fabs(dvalue);
@@ -52,6 +53,8 @@
G_percent(r, nrows, 1); /* finish it */
Rast_close(fd);
+ G_free(wabuf);
+ G_free(dbuf);
stddev = sqrt((sum_sqr - (sum + sum / do_points)) / (do_points - 1));
G_debug(1, "stddev: %f", stddev);
@@ -123,12 +126,12 @@
seg_close(&watalt);
if (asp_flag) {
G_message(_("Closing flow direction map"));
- cseg_write_cellfile(&asp, asp_name);
+ bseg_write_cellfile(&asp, asp_name);
Rast_init_colors(&colors);
Rast_make_grey_scale_colors(&colors, 1, 8);
Rast_write_colors(asp_name, this_mapset, &colors);
}
- cseg_close(&asp);
+ bseg_close(&asp);
if (ls_flag) {
G_message(_("Closing LS map"));
dseg_write_cellfile(&l_s, ls_name);
Modified: grass/trunk/raster/r.watershed/seg/cseg.h
===================================================================
--- grass/trunk/raster/r.watershed/seg/cseg.h 2010-12-17 11:14:48 UTC (rev 44624)
+++ grass/trunk/raster/r.watershed/seg/cseg.h 2010-12-17 11:15:48 UTC (rev 44625)
@@ -49,6 +49,7 @@
/* bseg_put.c */
int bseg_put(BSEG *, char *, int, int);
+int bseg_put_row(BSEG *, char *, int);
/* bseg_read.c */
int bseg_read_cell(BSEG *, char *, char *);
@@ -67,6 +68,7 @@
/* cseg_put.c */
int cseg_put(CSEG *, CELL *, int, int);
+int cseg_put_row(CSEG *, CELL *, int);
/* cseg_read.c */
int cseg_read_cell(CSEG *, char *, char *);
@@ -85,6 +87,7 @@
/* dseg_put.c */
int dseg_put(DSEG *, double *, int, int);
+int dseg_put_row(DSEG *, double *, int);
/* dseg_read.c */
int dseg_read_cell(DSEG *, char *, char *);
@@ -103,12 +106,15 @@
/* seg_put.c */
int seg_put(SSEG *, char *, int, int);
+int seg_put_row(SSEG *, char *, int);
/* sseg_close.c */
int seg_close(SSEG *);
/* sseg_get.c */
int seg_get(SSEG *, char *, int, int);
+int seg_get_row(SSEG *, char *, int);
+int seg_flush(SSEG *);
/* sseg_open.c */
int seg_open(SSEG *, int, int, int, int, int, int);
Modified: grass/trunk/raster/r.watershed/seg/cseg_put.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/cseg_put.c 2010-12-17 11:14:48 UTC (rev 44624)
+++ grass/trunk/raster/r.watershed/seg/cseg_put.c 2010-12-17 11:15:48 UTC (rev 44625)
@@ -10,3 +10,12 @@
}
return 0;
}
+
+int cseg_put_row(CSEG * cseg, CELL * value, int row)
+{
+ if (segment_put_row(&(cseg->seg), value, row) < 0) {
+ G_warning("cseg_put(): could not write segment file");
+ return -1;
+ }
+ return 0;
+}
Modified: grass/trunk/raster/r.watershed/seg/def_basin.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/def_basin.c 2010-12-17 11:14:48 UTC (rev 44624)
+++ grass/trunk/raster/r.watershed/seg/def_basin.c 2010-12-17 11:15:48 UTC (rev 44625)
@@ -5,8 +5,8 @@
CELL old_elev)
{
int r, rr, c, cc, ct, new_r[9], new_c[9];
- CELL downdir, direction, asp_value, value, new_elev;
- char cvalue;
+ CELL value, new_elev;
+ char downdir, direction, asp_value, cvalue;
int oldupdir, riteflag, leftflag, thisdir;
for (;;) {
@@ -15,10 +15,10 @@
for (r = row - 1, rr = 0; rr < 3; r++, rr++) {
for (c = col - 1, cc = 0; cc < 3; c++, cc++) {
if (r >= 0 && c >= 0 && r < nrows && c < ncols) {
- cseg_get(&asp, &value, r, c);
- if (value < -1)
- value = -value;
- if (value == drain[rr][cc]) {
+ bseg_get(&asp, &asp_value, r, c);
+ if (asp_value < -1)
+ asp_value = -asp_value;
+ if (asp_value == drain[rr][cc]) {
bseg_get(&bitflags, &cvalue, r, c);
if (FLAG_GET(cvalue, SWALEFLAG)) {
new_r[++ct] = r;
@@ -38,14 +38,14 @@
return (basin_num);
}
oldupdir = drain[row - new_r[1] + 1][col - new_c[1] + 1];
- cseg_get(&asp, &downdir, row, col);
+ bseg_get(&asp, &downdir, row, col);
if (downdir < 0)
downdir = -downdir;
riteflag = leftflag = 0;
for (r = row - 1, rr = 0; rr < 3; r++, rr++) {
for (c = col - 1, cc = 0; cc < 3; c++, cc++) {
if (r >= 0 && c >= 0 && r < nrows && c < ncols) {
- cseg_get(&asp, &direction, r, c);
+ bseg_get(&asp, &direction, r, c);
if (direction == drain[rr][cc]) {
thisdir = updrain[rr][cc];
switch (haf_basin_side
@@ -83,7 +83,7 @@
}
else { /* sides == 4 */
- cseg_get(&asp, &asp_value, row, col);
+ bseg_get(&asp, &asp_value, row, col);
if (asp_value < 0)
asp_value = -asp_value;
if (asp_value == 2 || asp_value == 6) {
Modified: grass/trunk/raster/r.watershed/seg/do_astar.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/do_astar.c 2010-12-17 11:14:48 UTC (rev 44624)
+++ grass/trunk/raster/r.watershed/seg/do_astar.c 2010-12-17 11:15:48 UTC (rev 44625)
@@ -3,14 +3,18 @@
#include "Gwater.h"
#include "do_astar.h"
+HEAP_PNT drop_pt(void);
+int sift_up(int, HEAP_PNT);
+int cmp_pnt(HEAP_PNT *a, HEAP_PNT *b);
double get_slope2(CELL, CELL, double);
int do_astar(void)
{
int doer, count;
int upr, upc, r = -1, c = -1, ct_dir;
- CELL alt_val, alt_nbr[8], alt_up;
- CELL asp_val;
+ CELL alt_val, alt_nbr[8];
+ WAT_ALT wa;
+ char asp_val;
char flag_value, is_in_list, is_worked;
HEAP_PNT heap_p;
@@ -78,8 +82,8 @@
skip_diag = 0;
/* avoid diagonal flow direction bias */
if (!is_worked) {
- cseg_get(&alt, &alt_up, upr, upc);
- alt_nbr[ct_dir] = alt_up;
+ seg_get(&watalt, (char *)&wa, upr, upc);
+ alt_nbr[ct_dir] = wa.ele;
slope[ct_dir] =
get_slope2(alt_val, alt_nbr[ct_dir],
dist_to_nbr[ct_dir]);
@@ -107,10 +111,11 @@
if (is_in_list == 0 && skip_diag == 0) {
/* set flow direction */
asp_val = drain[upr - r + 1][upc - c + 1];
- add_pt(upr, upc, alt_nbr[ct_dir], asp_val, 0);
- cseg_put(&asp, &asp_val, upr, upc);
+ add_pt(upr, upc, alt_nbr[ct_dir]);
+ bseg_put(&asp, &asp_val, upr, upc);
+ FLAG_SET(flag_value, INLISTFLAG);
+ bseg_put(&bitflags, &flag_value, upr, upc);
-
if (alt_nbr[ct_dir] < alt_val) {
if (ct_dir < 4)
count_edge_sink++;
@@ -128,25 +133,27 @@
else if (is_in_list && is_worked == 0 &&
FLAG_GET(flag_value, EDGEFLAG)) {
/* neighbour is edge in list, not yet worked */
- cseg_get(&asp, &asp_val, upr, upc);
+ bseg_get(&asp, &asp_val, upr, upc);
if (asp_val < 0) {
/* adjust flow direction for edge cell */
asp_val = drain[upr - r + 1][upc - c + 1];
- cseg_put(&asp, &asp_val, upr, upc);
- heap_p.pnt.guessed = 1;
+ bseg_put(&asp, &asp_val, upr, upc);
+ seg_get(&watalt, (char *)&wa, r, c);
+ if (wa.wat > 0) {
+ wa.wat = -wa.wat;
+ seg_put(&watalt, (char *)&wa, r, c);
+ }
+
}
}
}
}
/* add astar points to sorted list for flow accumulation */
- cseg_get(&asp, &asp_val, r, c);
- heap_p.pnt.asp = asp_val;
seg_put(&astar_pts, (char *)&heap_p.pnt, 0, doer);
doer--;
bseg_get(&bitflags, &flag_value, r, c);
FLAG_SET(flag_value, WORKEDFLAG);
bseg_put(&bitflags, &flag_value, r, c);
-
}
if (doer != -1)
G_fatal_error(_("bug in A* Search: doer %d heap size %d count %d"),
@@ -178,22 +185,10 @@
}
/* add point routine for min heap */
-int add_pt(int r, int c, CELL ele, char asp, int is_edge)
+int add_pt(int r, int c, CELL ele)
{
HEAP_PNT heap_p;
- char flag_value;
- bseg_get(&bitflags, &flag_value, r, c);
- if (is_edge) {
- FLAG_SET(flag_value, EDGEFLAG);
- heap_p.pnt.guessed = 1;
- }
- else {
- heap_p.pnt.guessed = 0;
- }
- FLAG_SET(flag_value, INLISTFLAG);
- bseg_put(&bitflags, &flag_value, r, c);
-
/* add point to next free position */
heap_size++;
@@ -202,7 +197,6 @@
heap_p.ele = ele;
heap_p.pnt.r = r;
heap_p.pnt.c = c;
- heap_p.pnt.asp = asp;
nxt_avail_pt++;
Modified: grass/trunk/raster/r.watershed/seg/do_cum.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/do_cum.c 2010-12-17 11:14:48 UTC (rev 44624)
+++ grass/trunk/raster/r.watershed/seg/do_cum.c 2010-12-17 11:15:48 UTC (rev 44625)
@@ -8,7 +8,7 @@
int do_cum(void)
{
int r, c, dr, dc;
- CELL asp_val, asp_val_down;
+ char asp_val, asp_val_down;
char is_swale, this_flag_value, flag_value;
DCELL value, valued;
POINT point;
@@ -28,7 +28,7 @@
seg_get(&astar_pts, (char *)&point, 0, killer);
r = point.r;
c = point.c;
- asp_val = point.asp;
+ bseg_get(&asp, &asp_val, r, c);
if (asp_val) {
dr = r + asp_r[ABS(asp_val)];
dc = c + asp_c[ABS(asp_val)];
@@ -67,10 +67,10 @@
seg_put(&watalt, (char *)&wadown, dr, dc);
/* update asp for depression */
if (is_swale && pit_flag) {
- cseg_get(&asp, &asp_val_down, dr, dc);
+ bseg_get(&asp, &asp_val_down, dr, dc);
if (asp_val > 0 && asp_val_down == 0) {
asp_val = -asp_val;
- cseg_put(&asp, &asp_val, r, c);
+ bseg_put(&asp, &asp_val, r, c);
}
}
if (is_swale || fabs(valued) >= threshold) {
@@ -80,7 +80,7 @@
is_swale = 1;
}
else {
- if (er_flag && !is_swale)
+ if (er_flag && !is_swale && !FLAG_GET(this_flag_value, RUSLEBLOCKFLAG))
slope_length(r, c, dr, dc);
}
}
@@ -128,7 +128,8 @@
double *dist_to_nbr, *weight, sum_weight, max_weight;
int r_nbr, c_nbr, r_max, c_max, ct_dir, np_side, max_side;
double dx, dy;
- CELL ele, *ele_nbr, asp_val, asp_val_down;
+ CELL ele, *ele_nbr;
+ char asp_val, asp_val_down;
double prop, max_acc;
int workedon, edge, is_swale, flat;
char *flag_nbr, this_flag_value, flag_value;
@@ -171,7 +172,7 @@
seg_get(&astar_pts, (char *)&point, 0, killer);
r = point.r;
c = point.c;
- asp_val = point.asp;
+ bseg_get(&asp, &asp_val, r, c);
if (asp_val) {
dr = r + asp_r[ABS(asp_val)];
dc = c + asp_c[ABS(asp_val)];
@@ -180,14 +181,8 @@
else
dr = dc = -1;
- seg_get(&watalt, (char *)&wa, r, c);
- value = wa.wat;
- if (point.guessed && value > 0) {
- value = -value;
- wa.wat = value;
- seg_put(&watalt, (char *)&wa, r, c);
- }
-
+ /* WORKEDFLAG has been set during A* Search
+ * reversed meaning here: 0 = done, 1 = not yet done */
bseg_get(&bitflags, &this_flag_value, r, c);
FLAG_UNSET(this_flag_value, WORKEDFLAG);
@@ -195,6 +190,9 @@
r_max = dr;
c_max = dc;
+ seg_get(&watalt, (char *)&wa, r, c);
+ value = wa.wat;
+
/* get weights */
max_weight = 0;
sum_weight = 0;
@@ -217,10 +215,6 @@
wat_nbr[ct_dir] = 0;
ele_nbr[ct_dir] = 0;
- /* WORKEDFLAG has been set during A* Search
- * reversed meaning here: 0 = done, 1 = not yet done */
- FLAG_UNSET(flag_nbr[ct_dir], WORKEDFLAG);
-
/* check if neighbour is within region */
if (r_nbr >= 0 && r_nbr < nrows && c_nbr >= 0 &&
c_nbr < ncols) {
@@ -282,8 +276,9 @@
is_swale = FLAG_GET(this_flag_value, SWALEFLAG);
if (is_swale && asp_val > 0) {
asp_val = -1 * drain[r - r_nbr + 1][c - c_nbr + 1];
- cseg_put(&asp, &asp_val, r, c);
+ bseg_put(&asp, &asp_val, r, c);
}
+ bseg_put(&bitflags, &this_flag_value, r, c);
continue;
}
@@ -355,7 +350,7 @@
/* adjust main drainage direction to A* path if possible */
/*if (fabs(wat_nbr[np_side]) >= max_acc) {
- max_acc = fabs(wat_nbr[ct_dir]);
+ max_acc = fabs(wat_nbr[np_side]);
r_max = dr;
c_max = dc;
} */
@@ -393,7 +388,7 @@
else
asp_val = drain[r - r_max + 1][c - c_max + 1];
- cseg_put(&asp, &asp_val, r, c);
+ bseg_put(&asp, &asp_val, r, c);
}
is_swale = FLAG_GET(this_flag_value, SWALEFLAG);
/* start new stream */
@@ -405,10 +400,10 @@
}
/* update asp for depression */
if (is_swale && pit_flag) {
- cseg_get(&asp, &asp_val_down, dr, dc);
+ bseg_get(&asp, &asp_val_down, dr, dc);
if (asp_val > 0 && asp_val_down == 0) {
asp_val = -asp_val;
- cseg_put(&asp, &asp_val, r, c);
+ bseg_put(&asp, &asp_val, r, c);
}
}
/* continue stream */
Modified: grass/trunk/raster/r.watershed/seg/dseg_put.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/dseg_put.c 2010-12-17 11:14:48 UTC (rev 44624)
+++ grass/trunk/raster/r.watershed/seg/dseg_put.c 2010-12-17 11:15:48 UTC (rev 44625)
@@ -10,3 +10,12 @@
}
return 0;
}
+
+int dseg_put_row(DSEG * dseg, double *value, int row)
+{
+ if (segment_put_row(&(dseg->seg), (DCELL *) value, row) < 0) {
+ G_warning("dseg_put(): could not write segment file");
+ return -1;
+ }
+ return 0;
+}
Modified: grass/trunk/raster/r.watershed/seg/find_pour.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/find_pour.c 2010-12-17 11:14:48 UTC (rev 44624)
+++ grass/trunk/raster/r.watershed/seg/find_pour.c 2010-12-17 11:15:48 UTC (rev 44625)
@@ -4,7 +4,9 @@
{
int row, col;
double easting, northing, stream_length;
- CELL old_elev, basin_num, value;
+ CELL old_elev, basin_num;
+ char aspect;
+ WAT_ALT wa;
char is_swale;
ocs_alloced = 2 * bas_thres;
@@ -16,10 +18,10 @@
G_percent(row, nrows, 1);
northing = window.north - (row + .5) * window.ns_res;
for (col = 0; col < ncols; col++) {
- cseg_get(&asp, &value, row, col);
+ bseg_get(&asp, &aspect, row, col);
bseg_get(&bitflags, &is_swale, row, col);
is_swale = FLAG_GET(is_swale, SWALEFLAG);
- if (value < 0 && is_swale > 0) {
+ if (aspect < 0 && is_swale > 0) {
basin_num += 2;
if (arm_flag) {
easting = window.west + (col + .5) * window.ew_res;
@@ -34,7 +36,8 @@
else {
stream_length = 0.0;
}
- cseg_get(&alt, &old_elev, row, col);
+ seg_get(&watalt, (char *) &wa, row, col);
+ old_elev = wa.ele;
}
basin_num =
def_basin(row, col, basin_num, stream_length, old_elev);
Modified: grass/trunk/raster/r.watershed/seg/init_vars.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/init_vars.c 2010-12-17 11:14:48 UTC (rev 44624)
+++ grass/trunk/raster/r.watershed/seg/init_vars.c 2010-12-17 11:15:48 UTC (rev 44625)
@@ -12,19 +12,20 @@
int r, c;
int ele_fd, fd, wat_fd;
int seg_rows, seg_cols, num_cseg_total, num_open_segs, num_open_array_segs;
+ double memory_divisor, heap_mem, seg_factor;
/* int page_block, num_cseg; */
int max_bytes;
- CELL *buf, alt_value, asp_value, block_value;
- char worked_value, flag_value;
+ CELL *buf, alt_value, *alt_value_buf, block_value;
+ char asp_value;
+ char worked_value, flag_value, *flag_value_buf;
DCELL wat_value;
DCELL dvalue;
- WAT_ALT wa;
+ WAT_ALT wa, *wabuf;
char MASK_flag;
void *elebuf, *ptr, *watbuf, *watptr;
int ele_map_type, wat_map_type;
size_t ele_size, wat_size;
- CELL cellone = 1;
int ct_dir, r_nbr, c_nbr;
G_gisinit(argv[0]);
@@ -145,23 +146,52 @@
if (sides == 4)
diag *= 0.5;
- /* segment parameters: one size fits all. Fine tune? */
/* Segment rows and cols: 64 */
- /* 1 segment open for all data structures used in A* Search: 0.18 MB */
- /* is really 0.22 MB but search heap holds max 5% of all points
- * i.e. we will probably never need all open segments for search heap
- */
seg_rows = SROW;
seg_cols = SCOL;
+ /* seg_factor * <size in bytes> = segment size in KB */
+ seg_factor = seg_rows * seg_rows / 1024.;
if (segs_mb < 3.0) {
- segs_mb = 300;
+ segs_mb = 3;
G_warning(_("Maximum memory to be used was smaller than 3 MB,"
- " set to default = 300 MB."));
+ " set to 3 MB."));
}
- num_open_segs = segs_mb / 0.18;
+ /* balance segment files */
+ /* elevation + accumulation: * 2 */
+ memory_divisor = seg_factor * 8 * 2;
+ /* aspect: as is */
+ memory_divisor += seg_factor;
+ /* flags: * 4 */
+ memory_divisor += seg_factor * 4;
+ /* astar_points: / 16 */
+ /* ideally only a few but large segments */
+ memory_divisor += seg_factor * sizeof(POINT) / 16.;
+ /* heap points: / 5 */
+ memory_divisor += seg_factor * sizeof(HEAP_PNT) / 5.;
+ /* RUSLE */
+ if (er_flag) {
+ /* r_h */
+ memory_divisor += seg_factor * 4.;
+ /* s_l */
+ memory_divisor += seg_factor * 8.;
+ /* s_g */
+ if (sg_flag)
+ memory_divisor += seg_factor * 8.;
+ /* l_s */
+ if (ls_flag)
+ memory_divisor += seg_factor * 8.;
+ /* ril */
+ if (ril_flag)
+ memory_divisor += seg_factor * 8.;
+ }
+
+ /* KB -> MB */
+ memory_divisor /= 1024.;
+ num_open_segs = segs_mb / memory_divisor;
+ heap_mem = num_open_segs * seg_factor * sizeof(HEAP_PNT) / (5. * 1024.);
G_debug(1, "segs MB: %.0f", segs_mb);
G_debug(1, "region rows: %d", nrows);
@@ -184,11 +214,11 @@
num_open_segs = num_cseg_total;
G_debug(1, " open segments after adjusting:\t%d", num_open_segs);
- if (num_cseg_total * 0.18 < 1024.0)
- G_verbose_message(_("Will need up to %.2f MB of disk space"), num_cseg_total * 0.18);
+ if (num_cseg_total * memory_divisor < 1024.0)
+ G_verbose_message(_("Will need up to %.2f MB of disk space"), num_cseg_total * memory_divisor);
else
- G_verbose_message(_("Will need up to %.2f GB (%.2f MB) of disk space"),
- (num_cseg_total * 0.18) / 1024.0, num_cseg_total * 0.18);
+ G_verbose_message(_("Will need up to %.2f GB (%.0f MB) of disk space"),
+ (num_cseg_total * memory_divisor) / 1024.0, num_cseg_total * memory_divisor);
if (er_flag) {
cseg_open(&r_h, seg_rows, seg_cols, num_open_segs);
@@ -197,11 +227,10 @@
/* read elevation input and mark NULL/masked cells */
- /* scattered access: alt, watalt, listflag, asp */
- cseg_open(&alt, seg_rows, seg_cols, num_open_segs);
- seg_open(&watalt, nrows, ncols, seg_rows, seg_cols, num_open_segs, sizeof(WAT_ALT));
- bseg_open(&bitflags, seg_rows, seg_cols, num_open_segs);
- cseg_open(&asp, seg_rows, seg_cols, num_open_segs);
+ /* scattered access: alt, watalt, bitflags, asp */
+ seg_open(&watalt, nrows, ncols, seg_rows, seg_cols, num_open_segs * 2, sizeof(WAT_ALT));
+ bseg_open(&bitflags, seg_rows, seg_cols, num_open_segs * 4);
+ bseg_open(&asp, seg_rows, seg_cols, num_open_segs);
/* open elevation input */
ele_fd = Rast_open_old(ele_name, "");
@@ -225,6 +254,9 @@
watbuf = watptr = NULL;
wat_fd = wat_size = wat_map_type = -1;
}
+ wabuf = G_malloc(ncols * sizeof(WAT_ALT));
+ flag_value_buf = G_malloc(ncols * sizeof(char));
+ alt_value_buf = Rast_allocate_buf(CELL_TYPE);
/* read elevation input and mark NULL/masked cells */
G_message("SECTION 1a: Mark masked and NULL cells");
@@ -242,13 +274,13 @@
for (c = 0; c < ncols; c++) {
- flag_value = 0;
+ flag_value_buf[c] = 0;
/* check for masked and NULL cells */
if (Rast_is_null_value(ptr, ele_map_type)) {
- FLAG_SET(flag_value, NULLFLAG);
- FLAG_SET(flag_value, INLISTFLAG);
- FLAG_SET(flag_value, WORKEDFLAG);
+ FLAG_SET(flag_value_buf[c], NULLFLAG);
+ FLAG_SET(flag_value_buf[c], INLISTFLAG);
+ FLAG_SET(flag_value_buf[c], WORKEDFLAG);
Rast_set_c_null_value(&alt_value, 1);
/* flow accumulation */
Rast_set_d_null_value(&wat_value, 1);
@@ -291,26 +323,26 @@
}
}
- cseg_put(&alt, &alt_value, r, c);
- wa.wat = wat_value;
- wa.ele = alt_value;
- seg_put(&watalt, (char *)&wa, r, c);
-
- if (flag_value)
- bseg_put(&bitflags, &flag_value, r, c);
-
- if (er_flag) {
- cseg_put(&r_h, &alt_value, r, c);
- }
+ wabuf[c].wat = wat_value;
+ wabuf[c].ele = alt_value;
+ alt_value_buf[c] = alt_value;
ptr = G_incr_void_ptr(ptr, ele_size);
if (run_flag) {
watptr = G_incr_void_ptr(watptr, wat_size);
}
}
+ seg_put_row(&watalt, (char *) wabuf, r);
+
+ bseg_put_row(&bitflags, flag_value_buf, r);
+
+ if (er_flag) {
+ cseg_put_row(&r_h, alt_value_buf, r);
+ }
}
G_percent(nrows, nrows, 1); /* finish it */
Rast_close(ele_fd);
- G_free(elebuf);
+ G_free(wabuf);
+ G_free(flag_value_buf);
if (run_flag) {
Rast_close(wat_fd);
@@ -321,15 +353,18 @@
/* depression: drainage direction will be set to zero later */
if (pit_flag) {
+ CELL cval;
+ char charone = 1;
+
fd = Rast_open_old(pit_name, "");
buf = Rast_allocate_c_buf();
for (r = 0; r < nrows; r++) {
G_percent(r, nrows, 1);
Rast_get_c_row(fd, buf, r);
for (c = 0; c < ncols; c++) {
- asp_value = buf[c];
- if (!Rast_is_c_null_value(&asp_value) && asp_value) {
- cseg_put(&asp, &cellone, r, c);
+ cval = buf[c];
+ if (!Rast_is_c_null_value(&cval) && cval) {
+ bseg_put(&asp, &charone, r, c);
bseg_get(&bitflags, &flag_value, r, c);
FLAG_SET(flag_value, PITFLAG);
bseg_put(&bitflags, &flag_value, r, c);
@@ -370,7 +405,7 @@
/* dseg_open(&slp, SROW, SCOL, num_open_segs); */
- dseg_open(&s_l, seg_rows, seg_cols, num_open_segs);
+ dseg_open(&s_l, seg_rows, seg_cols, num_open_segs);
if (sg_flag)
dseg_open(&s_g, 1, seg_rows * seg_cols, num_open_segs);
if (ls_flag)
@@ -378,49 +413,39 @@
}
G_debug(1, "open segments for A* points");
- /* rounded down power of 2 */
- seg_cols = (int) (pow(2, (int)(log(num_open_segs / 8.0) / log(2) + 0.1)) + 0.1);
- if (seg_cols < 2)
- seg_cols = 2;
- num_open_array_segs = num_open_segs / seg_cols;
- if (num_open_array_segs == 0)
- num_open_array_segs = 1;
- /* n cols in segment */
- seg_cols *= seg_rows * seg_rows;
- /* n segments in row */
+ /* columns per segment */
+ seg_cols = seg_rows * seg_rows;
num_cseg_total = do_points / seg_cols;
if (do_points % seg_cols > 0)
num_cseg_total++;
/* no need to have more segments open than exist */
+ num_open_array_segs = num_open_segs / 16.;
if (num_open_array_segs > num_cseg_total)
num_open_array_segs = num_cseg_total;
-
- if (num_open_array_segs > 4)
- num_open_array_segs = 4;
+ if (num_open_array_segs < 1)
+ num_open_array_segs = 1;
seg_open(&astar_pts, 1, do_points, 1, seg_cols, num_open_array_segs,
sizeof(POINT));
/* one-based d-ary search_heap with astar_pts */
G_debug(1, "open segments for A* search heap");
- /* rounded down power of 2 */
- seg_cols = (int) (pow(2, (int)(log(num_open_segs / 8.0) / log(2) + 0.1)) + 0.1);
- if (seg_cols < 2)
- seg_cols = 2;
- num_open_array_segs = num_open_segs / seg_cols;
- if (num_open_array_segs == 0)
- num_open_array_segs = 1;
- /* n cols in segment */
- seg_cols *= seg_rows * seg_rows;
- /* n segments in row */
- num_cseg_total = (do_points + 1) / seg_cols;
- if ((do_points + 1) % seg_cols > 0)
+ G_debug(1, "heap memory %.2f MB", heap_mem);
+ /* columns per segment */
+ /* larger is faster */
+ seg_cols = seg_rows * seg_rows * seg_rows;
+ num_cseg_total = do_points / seg_cols;
+ if (do_points % seg_cols > 0)
num_cseg_total++;
/* no need to have more segments open than exist */
+ num_open_array_segs = (2 << 20) * heap_mem / (seg_cols * sizeof(HEAP_PNT));
if (num_open_array_segs > num_cseg_total)
num_open_array_segs = num_cseg_total;
+ if (num_open_array_segs < 2)
+ num_open_array_segs = 2;
- G_debug(1, "A* search heap open segments %d, target 8", num_open_array_segs);
+ G_debug(1, "A* search heap open segments %d, total %d",
+ num_open_array_segs, num_cseg_total);
/* the search heap will not hold more than 5% of all points at any given time ? */
/* chances are good that the heap will fit into one large segment */
seg_open(&search_heap, 1, do_points + 1, 1, seg_cols,
@@ -441,7 +466,7 @@
if (!FLAG_GET(flag_value, NULLFLAG)) {
if (er_flag)
dseg_put(&s_l, &half_res, r, c);
- cseg_get(&asp, &asp_value, r, c);
+ bseg_get(&asp, &asp_value, r, c);
if (r == 0 || c == 0 || r == nrows - 1 ||
c == ncols - 1 || asp_value != 0) {
/* dseg_get(&wat, &wat_value, r, c); */
@@ -471,11 +496,14 @@
asp_value = -6;
else if (c == ncols - 1)
asp_value = -8;
- if (-1 == cseg_put(&asp, &asp_value, r, c))
+ if (-1 == bseg_put(&asp, &asp_value, r, c))
exit(EXIT_FAILURE);
/* cseg_get(&alt, &alt_value, r, c); */
alt_value = wa.ele;
- add_pt(r, c, alt_value, asp_value, 1);
+ add_pt(r, c, alt_value);
+ FLAG_SET(flag_value, INLISTFLAG);
+ FLAG_SET(flag_value, EDGEFLAG);
+ bseg_put(&bitflags, &flag_value, r, c);
}
else {
seg_get(&watalt, (char *)&wa, r, c);
@@ -487,8 +515,11 @@
bseg_get(&bitflags, &worked_value, r_nbr, c_nbr);
if (FLAG_GET(worked_value, NULLFLAG)) {
asp_value = -1 * drain[r - r_nbr + 1][c - c_nbr + 1];
- add_pt(r, c, wa.ele, asp_value, 1);
- cseg_put(&asp, &asp_value, r, c);
+ add_pt(r, c, wa.ele);
+ FLAG_SET(flag_value, INLISTFLAG);
+ FLAG_SET(flag_value, EDGEFLAG);
+ bseg_put(&bitflags, &flag_value, r, c);
+ bseg_put(&asp, &asp_value, r, c);
wat_value = wa.wat;
if (wat_value > 0) {
wa.wat = -wat_value;
@@ -509,7 +540,7 @@
/* bseg_put(&worked, &zero, r, c); */
if (er_flag)
dseg_put(&s_l, &half_res, r, c);
- cseg_get(&asp, &asp_value, r, c);
+ bseg_get(&asp, &asp_value, r, c);
if (r == 0 || c == 0 || r == nrows - 1 ||
c == ncols - 1 || asp_value != 0) {
seg_get(&watalt, (char *)&wa, r, c);
@@ -536,10 +567,14 @@
asp_value = -6;
else if (c == ncols - 1)
asp_value = -8;
- if (-1 == cseg_put(&asp, &asp_value, r, c))
+ if (-1 == bseg_put(&asp, &asp_value, r, c))
exit(EXIT_FAILURE);
/* cseg_get(&alt, &alt_value, r, c); */
- add_pt(r, c, wa.ele, asp_value, 1);
+ add_pt(r, c, wa.ele);
+ bseg_get(&bitflags, &flag_value, r, c);
+ FLAG_SET(flag_value, INLISTFLAG);
+ FLAG_SET(flag_value, EDGEFLAG);
+ bseg_put(&bitflags, &flag_value, r, c);
}
}
}
Modified: grass/trunk/raster/r.watershed/seg/main.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/main.c 2010-12-17 11:14:48 UTC (rev 44624)
+++ grass/trunk/raster/r.watershed/seg/main.c 2010-12-17 11:15:48 UTC (rev 44625)
@@ -36,16 +36,16 @@
double half_res, diag, max_length, dep_slope;
int bas_thres, tot_parts;
SSEG astar_pts;
-BSEG bitflags, s_b;
-CSEG dis, alt, asp, bas, haf, r_h, dep;
+BSEG bitflags, s_b, asp;
+CSEG dis, alt, bas, haf, r_h, dep;
SSEG watalt;
DSEG slp, s_l, s_g, l_s, ril;
double segs_mb;
char zero, one;
double ril_value, d_zero, d_one;
int sides;
-int drain[3][3] = { {7, 6, 5}, {8, 0, 4}, {1, 2, 3} };
-int updrain[3][3] = { {3, 2, 1}, {4, 0, 8}, {5, 6, 7} };
+char drain[3][3] = { {7, 6, 5}, {8, 0, 4}, {1, 2, 3} };
+char updrain[3][3] = { {3, 2, 1}, {4, 0, 8}, {5, 6, 7} };
int nextdr[8] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int nextdc[8] = { 0, 0, -1, 1, 1, -1, 1, -1 };
char ele_name[GNAME_MAX], pit_name[GNAME_MAX];
@@ -94,7 +94,7 @@
if (arm_flag) {
fp = fopen(arm_name, "w");
}
- num_open_segs = segs_mb / 0.2;
+ num_open_segs = segs_mb / 0.4;
if (num_open_segs > (ncols / SCOL + 1) * (nrows / SROW + 1)) {
num_open_segs = (ncols / SCOL + 1) * (nrows / SROW + 1);
}
Modified: grass/trunk/raster/r.watershed/seg/no_stream.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/no_stream.c 2010-12-17 11:14:48 UTC (rev 44624)
+++ grass/trunk/raster/r.watershed/seg/no_stream.c 2010-12-17 11:15:48 UTC (rev 44625)
@@ -6,7 +6,8 @@
{
int r, rr, c, cc, uprow = 0, upcol = 0;
double slope;
- CELL downdir, asp_value, hih_ele, new_ele, aspect, value;
+ CELL hih_ele, new_ele, value;
+ char downdir, asp_value, aspect;
DCELL dvalue, max_drain; /* flow acc is now DCELL */
int updir, riteflag, leftflag, thisdir;
WAT_ALT wa;
@@ -18,7 +19,7 @@
for (c = col - 1, cc = 0; c <= col + 1; c++, cc++) {
if (r >= 0 && c >= 0 && r < nrows && c < ncols) {
- cseg_get(&asp, &aspect, r, c);
+ bseg_get(&asp, &aspect, r, c);
if (aspect == drain[rr][cc]) {
seg_get(&watalt, (char *)&wa, r, c);
dvalue = wa.wat;
@@ -35,7 +36,7 @@
}
if (max_drain > -1) {
updir = drain[row - uprow + 1][col - upcol + 1];
- cseg_get(&asp, &downdir, row, col);
+ bseg_get(&asp, &downdir, row, col);
if (downdir < 0)
downdir = -downdir;
if (arm_flag) {
@@ -49,7 +50,7 @@
}
else { /* sides == 4 */
- cseg_get(&asp, &asp_value, uprow, upcol);
+ bseg_get(&asp, &asp_value, uprow, upcol);
if (downdir == 2 || downdir == 6) {
if (asp_value == 2 || asp_value == 6)
stream_length += window.ns_res;
@@ -69,7 +70,7 @@
for (r = row - 1, rr = 0; rr < 3; r++, rr++) {
for (c = col - 1, cc = 0; cc < 3; c++, cc++) {
if (r >= 0 && c >= 0 && r < nrows && c < ncols) {
- cseg_get(&asp, &aspect, r, c);
+ bseg_get(&asp, &aspect, r, c);
if (aspect == drain[rr][cc]) {
thisdir = updrain[rr][cc];
switch (haf_basin_side(updir,
@@ -101,7 +102,8 @@
}
else {
if (arm_flag) {
- cseg_get(&alt, &hih_ele, row, col);
+ seg_get(&watalt, (char *) &wa, row, col);
+ hih_ele = wa.ele;
slope = (hih_ele - old_elev) / stream_length;
if (slope < MIN_SLOPE)
slope = MIN_SLOPE;
Modified: grass/trunk/raster/r.watershed/seg/over_cells.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/over_cells.c 2010-12-17 11:14:48 UTC (rev 44624)
+++ grass/trunk/raster/r.watershed/seg/over_cells.c 2010-12-17 11:15:48 UTC (rev 44625)
@@ -5,7 +5,8 @@
overland_cells_recursive(int row, int col, CELL basin_num, CELL haf_num, CELL * hih_ele)
{
int r, rr, c, cc;
- CELL new_ele, new_max_ele, value;
+ CELL new_ele, new_max_ele;
+ char aspect;
cseg_put(&bas, &basin_num, row, col);
cseg_put(&haf, &haf_num, row, col);
@@ -13,8 +14,8 @@
for (r = row - 1, rr = 0; r <= row + 1; r++, rr++) {
for (c = col - 1, cc = 0; c <= col + 1; c++, cc++) {
if (r >= 0 && c >= 0 && r < nrows && c < ncols) {
- cseg_get(&asp, &value, r, c);
- if (value == drain[rr][cc]) {
+ bseg_get(&asp, &aspect, r, c);
+ if (aspect == drain[rr][cc]) {
overland_cells(r, c, basin_num, haf_num, &new_ele);
}
}
@@ -39,7 +40,7 @@
overland_cells(int row, int col, CELL basin_num, CELL haf_num, CELL * hih_ele)
{
int r, rr, c, cc, next_r, next_c;
- CELL value;
+ char aspect;
int top = 0;
/* put root on stack */
@@ -59,8 +60,8 @@
for (r = next_r - 1, rr = 0; r <= next_r + 1; r++, rr++) {
for (c = next_c - 1, cc = 0; c <= next_c + 1; c++, cc++) {
if (r >= 0 && c >= 0 && r < nrows && c < ncols) {
- cseg_get(&asp, &value, r, c);
- if (value == drain[rr][cc]) {
+ bseg_get(&asp, &aspect, r, c);
+ if (aspect == drain[rr][cc]) {
if (top >= ocs_alloced) {
ocs_alloced += bas_thres;
ocs = (OC_STACK *)G_realloc(ocs, ocs_alloced * sizeof(OC_STACK));
Modified: grass/trunk/raster/r.watershed/seg/sg_factor.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/sg_factor.c 2010-12-17 11:14:48 UTC (rev 44624)
+++ grass/trunk/raster/r.watershed/seg/sg_factor.c 2010-12-17 11:15:48 UTC (rev 44625)
@@ -6,9 +6,10 @@
int sg_factor(void)
{
int r, c;
- CELL downer, low_elev, hih_elev;
+ CELL low_elev, hih_elev;
double height, length, S, sin_theta;
char flag_value;
+ WAT_ALT wa;
G_message(_("SECTION 5: RUSLE LS and/or S factor determination."));
for (r = nrows - 1; r >= 0; r--) {
@@ -18,10 +19,10 @@
if (FLAG_GET(flag_value, NULLFLAG))
continue;
- cseg_get(&alt, &low_elev, r, c);
+ seg_get(&watalt, (char *) &wa, r, c);
+ low_elev = wa.ele;
cseg_get(&r_h, &hih_elev, r, c);
dseg_get(&s_l, &length, r, c);
- cseg_get(&asp, &downer, r, c);
height = 1.0 * (hih_elev - low_elev) / ele_scale;
if (length > max_length) {
height *= max_length / length;
Modified: grass/trunk/raster/r.watershed/seg/slope_len.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/slope_len.c 2010-12-17 11:14:48 UTC (rev 44624)
+++ grass/trunk/raster/r.watershed/seg/slope_len.c 2010-12-17 11:15:48 UTC (rev 44625)
@@ -2,8 +2,10 @@
int slope_length(int r, int c, int dr, int dc)
{
- CELL top_alt, bot_alt, asp_value, ridge;
+ CELL top_alt, bot_alt, ridge;
+ char asp_value;
double res, top_ls, bot_ls;
+ WAT_ALT wa;
if (sides == 8) {
if (r == dr)
@@ -15,7 +17,7 @@
}
else { /* sides == 4 */
- cseg_get(&asp, &asp_value, dr, dc);
+ bseg_get(&asp, &asp_value, dr, dc);
if (r == dr) {
if (asp_value == 2 || asp_value == 6)
res = window.ns_res;
@@ -36,8 +38,10 @@
else
top_ls += res;
dseg_put(&s_l, &top_ls, r, c);
- cseg_get(&alt, &top_alt, r, c);
- cseg_get(&alt, &bot_alt, dr, dc);
+ seg_get(&watalt, (char *) &wa, r, c);
+ top_alt = wa.ele;
+ seg_get(&watalt, (char *) &wa, dr, dc);
+ bot_alt = wa.ele;
if (top_alt > bot_alt) {
dseg_get(&s_l, &bot_ls, dr, dc);
if (top_ls > bot_ls) {
Modified: grass/trunk/raster/r.watershed/seg/split_str.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/split_str.c 2010-12-17 11:14:48 UTC (rev 44624)
+++ grass/trunk/raster/r.watershed/seg/split_str.c 2010-12-17 11:15:48 UTC (rev 44625)
@@ -4,7 +4,9 @@
split_stream(int row, int col, int new_r[], int new_c[], int ct,
CELL basin_num, double stream_length, CELL old_elev)
{
- CELL downdir, old_basin, new_elev, aspect;
+ CELL old_basin, new_elev;
+ char downdir, aspect;
+ WAT_ALT wa;
double slope, easting, northing;
int doit, ctr, updir, splitdir[9];
int thisdir, leftflag, riteflag;
@@ -15,14 +17,14 @@
for (ctr = 1; ctr <= ct; ctr++)
splitdir[ctr] = drain[row - new_r[ctr] + 1][col - new_c[ctr] + 1];
updir = splitdir[1];
- cseg_get(&asp, &downdir, row, col);
+ bseg_get(&asp, &downdir, row, col);
if (downdir < 0)
downdir = -downdir;
riteflag = leftflag = 0;
for (r = row - 1, rr = 0; rr < 3; r++, rr++) {
for (c = col - 1, cc = 0; cc < 3; c++, cc++) {
if (r >= 0 && c >= 0 && r < nrows && c < ncols) {
- cseg_get(&asp, &aspect, r, c);
+ bseg_get(&asp, &aspect, r, c);
if (aspect == drain[rr][cc]) {
doit = 1;
thisdir = updrain[rr][cc];
@@ -61,7 +63,8 @@
}
old_basin = basin_num;
if (arm_flag) {
- cseg_get(&alt, &new_elev, row, col);
+ seg_get(&watalt, (char *) &wa, row, col);
+ new_elev = wa.ele;
if ((slope = (new_elev - old_elev) / stream_length) < MIN_SLOPE)
slope = MIN_SLOPE;
fprintf(fp, " %f %f\n", slope, stream_length);
Modified: grass/trunk/raster/r.watershed/seg/sseg_get.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/sseg_get.c 2010-12-17 11:14:48 UTC (rev 44624)
+++ grass/trunk/raster/r.watershed/seg/sseg_get.c 2010-12-17 11:15:48 UTC (rev 44625)
@@ -4,9 +4,24 @@
int seg_get(SSEG * sseg, char *value, int row, int col)
{
- if (segment_get(&(sseg->seg), (CELL *) value, row, col) < 0) {
+ if (segment_get(&(sseg->seg), value, row, col) < 0) {
G_warning("seg_get(): could not read segment file");
return -1;
}
return 0;
}
+
+int seg_get_row(SSEG * sseg, char *value, int row)
+{
+ if (segment_get_row(&(sseg->seg), value, row) < 0) {
+ G_warning("seg_get(): could not read segment file");
+ return -1;
+ }
+ return 0;
+}
+
+int seg_flush(SSEG * sseg)
+{
+ segment_flush(&(sseg->seg));
+ return 0;
+}
Modified: grass/trunk/raster/r.watershed/seg/sseg_put.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/sseg_put.c 2010-12-17 11:14:48 UTC (rev 44624)
+++ grass/trunk/raster/r.watershed/seg/sseg_put.c 2010-12-17 11:15:48 UTC (rev 44625)
@@ -4,9 +4,18 @@
int seg_put(SSEG * sseg, char *value, int row, int col)
{
- if (segment_put(&(sseg->seg), (CELL *) value, row, col) < 0) {
+ if (segment_put(&(sseg->seg), value, row, col) < 0) {
G_warning("seg_put(): could not write segment file");
return -1;
}
return 0;
}
+
+int seg_put_row(SSEG * sseg, char *value, int row)
+{
+ if (segment_put_row(&(sseg->seg), value, row) < 0) {
+ G_warning("seg_put(): could not write segment file");
+ return -1;
+ }
+ return 0;
+}
More information about the grass-commit
mailing list