[GRASS-SVN] r51483 - grass/trunk/raster/r.watershed/seg

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Apr 22 13:12:18 EDT 2012


Author: mmetz
Date: 2012-04-22 10:12:18 -0700 (Sun, 22 Apr 2012)
New Revision: 51483

Modified:
   grass/trunk/raster/r.watershed/seg/Gwater.h
   grass/trunk/raster/r.watershed/seg/bseg_close.c
   grass/trunk/raster/r.watershed/seg/bseg_get.c
   grass/trunk/raster/r.watershed/seg/bseg_open.c
   grass/trunk/raster/r.watershed/seg/bseg_put.c
   grass/trunk/raster/r.watershed/seg/bseg_read.c
   grass/trunk/raster/r.watershed/seg/bseg_write.c
   grass/trunk/raster/r.watershed/seg/close_maps.c
   grass/trunk/raster/r.watershed/seg/close_maps2.c
   grass/trunk/raster/r.watershed/seg/cseg.h
   grass/trunk/raster/r.watershed/seg/cseg_close.c
   grass/trunk/raster/r.watershed/seg/cseg_get.c
   grass/trunk/raster/r.watershed/seg/cseg_open.c
   grass/trunk/raster/r.watershed/seg/cseg_put.c
   grass/trunk/raster/r.watershed/seg/cseg_read.c
   grass/trunk/raster/r.watershed/seg/cseg_write.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_astar.h
   grass/trunk/raster/r.watershed/seg/do_cum.c
   grass/trunk/raster/r.watershed/seg/dseg_close.c
   grass/trunk/raster/r.watershed/seg/dseg_get.c
   grass/trunk/raster/r.watershed/seg/dseg_open.c
   grass/trunk/raster/r.watershed/seg/dseg_put.c
   grass/trunk/raster/r.watershed/seg/dseg_read.c
   grass/trunk/raster/r.watershed/seg/dseg_write.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_close.c
   grass/trunk/raster/r.watershed/seg/sseg_get.c
   grass/trunk/raster/r.watershed/seg/sseg_open.c
   grass/trunk/raster/r.watershed/seg/sseg_put.c
Log:
r.watershed: support for more than 2 billion cells

Modified: grass/trunk/raster/r.watershed/seg/Gwater.h
===================================================================
--- grass/trunk/raster/r.watershed/seg/Gwater.h	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/Gwater.h	2012-04-22 17:12:18 UTC (rev 51483)
@@ -10,6 +10,9 @@
 #include <math.h>
 #include <grass/gis.h>
 #include <grass/raster.h>
+
+#define GW_LARGE_INT off_t
+
 #include "cseg.h"
 #include "flag.h"
 
@@ -49,7 +52,7 @@
 
 #define HEAP_PNT    struct heap_point
 HEAP_PNT {
-   int added;
+   GW_LARGE_INT added;
    CELL ele;
    POINT pnt;
 };
@@ -60,6 +63,12 @@
    DCELL wat;
 };
 
+#define ASP_FLAG    struct aspect_flag
+ASP_FLAG {
+   char asp;
+   char flag;
+};
+
 #define OC_STACK struct overland_cells_stack
 OC_STACK {
     int row, col;
@@ -69,18 +78,18 @@
 
 extern int mfd, c_fac, abs_acc, ele_scale;
 extern SSEG search_heap;
-extern int heap_size;
-extern int first_astar, first_cum, nxt_avail_pt, total_cells, do_points;
+extern int nrows, ncols;
+extern GW_LARGE_INT heap_size;
+extern GW_LARGE_INT first_astar, first_cum, nxt_avail_pt, total_cells, do_points;
 extern CELL n_basins;
 extern OC_STACK *ocs;
 extern int ocs_alloced;
-extern int nrows, ncols;
 extern double half_res, diag, max_length, dep_slope;
 extern int bas_thres, tot_parts;
 extern SSEG astar_pts;
-extern BSEG bitflags, s_b, asp;
+extern BSEG s_b;
 extern CSEG dis, bas, haf, r_h, dep;
-extern SSEG watalt;
+extern SSEG watalt, aspflag;
 extern DSEG slp, s_l, s_g, l_s, ril;
 extern double segs_mb;
 extern char zero, one;

Modified: grass/trunk/raster/r.watershed/seg/bseg_close.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/bseg_close.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/bseg_close.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -1,6 +1,6 @@
 #include <grass/gis.h>
 #include <unistd.h>
-#include "cseg.h"
+#include "Gwater.h"
 
 int bseg_close(BSEG * bseg)
 {

Modified: grass/trunk/raster/r.watershed/seg/bseg_get.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/bseg_get.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/bseg_get.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -1,8 +1,8 @@
 #include <grass/gis.h>
 #include <grass/segment.h>
-#include "cseg.h"
+#include "Gwater.h"
 
-int bseg_get(BSEG * bseg, char *value, int row, int col)
+int bseg_get(BSEG * bseg, char *value, GW_LARGE_INT row, GW_LARGE_INT col)
 {
     if (segment_get(&(bseg->seg), value, row, col) < 0) {
 	G_warning("cseg_get(): could not read segment file");

Modified: grass/trunk/raster/r.watershed/seg/bseg_open.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/bseg_open.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/bseg_open.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -2,7 +2,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <grass/segment.h>
-#include "cseg.h"
+#include "Gwater.h"
 
 
 int bseg_open(BSEG * bseg, int srows, int scols, int nsegs_in_memory)

Modified: grass/trunk/raster/r.watershed/seg/bseg_put.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/bseg_put.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/bseg_put.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -1,8 +1,8 @@
 #include <grass/gis.h>
 #include <grass/segment.h>
-#include "cseg.h"
+#include "Gwater.h"
 
-int bseg_put(BSEG * bseg, char *value, int row, int col)
+int bseg_put(BSEG * bseg, char *value, GW_LARGE_INT row, GW_LARGE_INT col)
 {
     if (segment_put(&(bseg->seg), value, row, col) < 0) {
 	G_warning("cseg_put(): could not write segment file");
@@ -11,7 +11,7 @@
     return 0;
 }
 
-int bseg_put_row(BSEG * bseg, char *value, int row)
+int bseg_put_row(BSEG * bseg, char *value, GW_LARGE_INT row)
 {
     if (segment_put_row(&(bseg->seg), value, row) < 0) {
 	G_warning("cseg_put(): could not write segment file");

Modified: grass/trunk/raster/r.watershed/seg/bseg_read.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/bseg_read.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/bseg_read.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -1,7 +1,7 @@
 #include <grass/gis.h>
 #include <grass/raster.h>
 #include <unistd.h>
-#include "cseg.h"
+#include "Gwater.h"
 
 int bseg_read_cell(BSEG * bseg, char *map_name, char *mapset)
 {

Modified: grass/trunk/raster/r.watershed/seg/bseg_write.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/bseg_write.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/bseg_write.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -1,6 +1,6 @@
 #include <grass/gis.h>
 #include <grass/raster.h>
-#include "cseg.h"
+#include "Gwater.h"
 
 int bseg_write_cellfile(BSEG * bseg, char *map_name)
 {

Modified: grass/trunk/raster/r.watershed/seg/close_maps.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/close_maps.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/close_maps.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -7,15 +7,15 @@
     struct Colors colors;
     int r, c;
     DCELL *dbuf = NULL;
+    CELL *cbuf = NULL;
     int fd;
     struct FPRange accRange;
     DCELL min, max;
     DCELL clr_min, clr_max;
     DCELL sum, sum_sqr, stddev, lstddev, dvalue;
     WAT_ALT *wabuf;
+    ASP_FLAG *afbuf;
 
-    /* bseg_close(&swale); */
-    bseg_close(&bitflags);
     if (wat_flag) {
 	G_message(_("Closing accumulation map"));
 	sum = sum_sqr = stddev = 0.0;
@@ -126,12 +126,28 @@
     seg_close(&watalt);
     if (asp_flag) {
 	G_message(_("Closing flow direction map"));
-	bseg_write_cellfile(&asp, asp_name);
+	cbuf = Rast_allocate_c_buf();
+	afbuf = G_malloc(ncols * sizeof(ASP_FLAG));
+	seg_flush(&aspflag);
+
+	fd = Rast_open_new(wat_name, DCELL_TYPE);
+
+	for (r = 0; r < nrows; r++) {
+	    G_percent(r, nrows, 1);
+	    Rast_set_c_null_value(cbuf, ncols);	/* reset row to all NULL */
+	    seg_get_row(&aspflag, (char *)afbuf, r);
+	    for (c = 0; c < ncols; c++) {
+		if (!FLAG_GET(afbuf[c].flag, NULLFLAG)) {
+		    cbuf[c] = afbuf[c].asp;
+		}
+	    }
+	    Rast_put_row(fd, cbuf, CELL_TYPE);
+	}
 	Rast_init_colors(&colors);
 	Rast_make_grey_scale_colors(&colors, 1, 8);
 	Rast_write_colors(asp_name, this_mapset, &colors);
     }
-    bseg_close(&asp);
+    seg_close(&aspflag);
     if (ls_flag) {
 	G_message(_("Closing LS map"));
 	dseg_write_cellfile(&l_s, ls_name);

Modified: grass/trunk/raster/r.watershed/seg/close_maps2.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/close_maps2.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/close_maps2.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -9,9 +9,8 @@
     int incr, max, red, green, blue, rd, gr, bl, flag;
     int c, r, map_fd;
     CELL *cellrow;
-    /* CELL value; */
-    char cvalue;
     CSEG *theseg;
+    ASP_FLAG af;
 
     if (seg_flag || bas_flag || haf_flag) {
 	if (seg_flag)
@@ -93,8 +92,8 @@
 	    for (c = 0; c < ncols; c++) {
 		/* bseg_get(&swale, &cvalue, r, c); */
 		/* if (cvalue) */
-		bseg_get(&bitflags, &cvalue, r, c);
-		if (FLAG_GET(cvalue, SWALEFLAG))
+		seg_get(&aspflag, (char *)&af, r, c);
+		if (FLAG_GET(af.flag, SWALEFLAG))
 		    cseg_get(&bas, &(cellrow[c]), r, c);
 	    }
 	    Rast_put_row(map_fd, cellrow, CELL_TYPE);

Modified: grass/trunk/raster/r.watershed/seg/cseg.h
===================================================================
--- grass/trunk/raster/r.watershed/seg/cseg.h	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/cseg.h	2012-04-22 17:12:18 UTC (rev 51483)
@@ -42,14 +42,14 @@
 int bseg_close(BSEG *);
 
 /* bseg_get.c */
-int bseg_get(BSEG *, char *, int, int);
+int bseg_get(BSEG *, char *, GW_LARGE_INT, GW_LARGE_INT);
 
 /* bseg_open.c */
 int bseg_open(BSEG *, int, int, int);
 
 /* bseg_put.c */
-int bseg_put(BSEG *, char *, int, int);
-int bseg_put_row(BSEG *, char *, int);
+int bseg_put(BSEG *, char *, GW_LARGE_INT, GW_LARGE_INT);
+int bseg_put_row(BSEG *, char *, GW_LARGE_INT);
 
 /* bseg_read.c */
 int bseg_read_cell(BSEG *, char *, char *);
@@ -61,14 +61,14 @@
 int cseg_close(CSEG *);
 
 /* cseg_get.c */
-int cseg_get(CSEG *, CELL *, int, int);
+int cseg_get(CSEG *, CELL *, GW_LARGE_INT, GW_LARGE_INT);
 
 /* cseg_open.c */
 int cseg_open(CSEG *, int, int, int);
 
 /* cseg_put.c */
-int cseg_put(CSEG *, CELL *, int, int);
-int cseg_put_row(CSEG *, CELL *, int);
+int cseg_put(CSEG *, CELL *, GW_LARGE_INT, GW_LARGE_INT);
+int cseg_put_row(CSEG *, CELL *, GW_LARGE_INT);
 
 /* cseg_read.c */
 int cseg_read_cell(CSEG *, char *, char *);
@@ -80,14 +80,14 @@
 int dseg_close(DSEG *);
 
 /* dseg_get.c */
-int dseg_get(DSEG *, double *, int, int);
+int dseg_get(DSEG *, double *, GW_LARGE_INT, GW_LARGE_INT);
 
 /* dseg_open.c */
 int dseg_open(DSEG *, int, int, int);
 
 /* dseg_put.c */
-int dseg_put(DSEG *, double *, int, int);
-int dseg_put_row(DSEG *, double *, int);
+int dseg_put(DSEG *, double *, GW_LARGE_INT, GW_LARGE_INT);
+int dseg_put_row(DSEG *, double *, GW_LARGE_INT);
 
 /* dseg_read.c */
 int dseg_read_cell(DSEG *, char *, char *);
@@ -95,32 +95,20 @@
 /* dseg_write.c */
 int dseg_write_cellfile(DSEG *, char *);
 
-/* seg_close.c */
-int seg_close(SSEG *);
-
-/* seg_get.c */
-int seg_get(SSEG *, char *, int, int);
-
-/* seg_open.c */
-int seg_open(SSEG *, int, int, int, int, int, int);
-
-/* 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_get(SSEG *, char *, GW_LARGE_INT, GW_LARGE_INT);
+int seg_get_row(SSEG *, char *, GW_LARGE_INT);
 int seg_flush(SSEG *);
 
 /* sseg_open.c */
-int seg_open(SSEG *, int, int, int, int, int, int);
+int seg_open(SSEG *, GW_LARGE_INT, GW_LARGE_INT, int, int, int, int);
 
 /* sseg_put.c */
-int seg_put(SSEG *, char *, int, int);
+int seg_put(SSEG *, char *, GW_LARGE_INT, GW_LARGE_INT);
+int seg_put_row(SSEG * sseg, char *value, GW_LARGE_INT);
 
 
 #endif /* __CSEG_H__ */

Modified: grass/trunk/raster/r.watershed/seg/cseg_close.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/cseg_close.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/cseg_close.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -1,7 +1,7 @@
 #include <grass/gis.h>
 #include <unistd.h>
 #include <grass/segment.h>
-#include "cseg.h"
+#include "Gwater.h"
 
 int cseg_close(CSEG * cseg)
 {

Modified: grass/trunk/raster/r.watershed/seg/cseg_get.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/cseg_get.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/cseg_get.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -1,8 +1,8 @@
 #include <grass/gis.h>
 #include <grass/segment.h>
-#include "cseg.h"
+#include "Gwater.h"
 
-int cseg_get(CSEG * cseg, CELL * value, int row, int col)
+int cseg_get(CSEG * cseg, CELL * value, GW_LARGE_INT row, GW_LARGE_INT col)
 {
     if (segment_get(&(cseg->seg), value, row, col) < 0) {
 	G_warning("cseg_get(): could not read segment file");

Modified: grass/trunk/raster/r.watershed/seg/cseg_open.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/cseg_open.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/cseg_open.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -1,7 +1,7 @@
 #include <grass/gis.h>
 #include <unistd.h>
 #include <fcntl.h>
-#include "cseg.h"
+#include "Gwater.h"
 
 
 int cseg_open(CSEG * cseg, int srows, int scols, int nsegs_in_memory)

Modified: grass/trunk/raster/r.watershed/seg/cseg_put.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/cseg_put.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/cseg_put.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -1,8 +1,8 @@
 #include <grass/gis.h>
 #include <grass/segment.h>
-#include "cseg.h"
+#include "Gwater.h"
 
-int cseg_put(CSEG * cseg, CELL * value, int row, int col)
+int cseg_put(CSEG * cseg, CELL * value, GW_LARGE_INT row, GW_LARGE_INT col)
 {
     if (segment_put(&(cseg->seg), value, row, col) < 0) {
 	G_warning("cseg_put(): could not write segment file");
@@ -11,7 +11,7 @@
     return 0;
 }
 
-int cseg_put_row(CSEG * cseg, CELL * value, int row)
+int cseg_put_row(CSEG * cseg, CELL * value, GW_LARGE_INT row)
 {
     if (segment_put_row(&(cseg->seg), value, row) < 0) {
 	G_warning("cseg_put(): could not write segment file");

Modified: grass/trunk/raster/r.watershed/seg/cseg_read.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/cseg_read.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/cseg_read.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -1,13 +1,13 @@
 #include <grass/gis.h>
 #include <grass/raster.h>
 #include <grass/segment.h>
-#include "cseg.h"
+#include "Gwater.h"
 
 static char *me = "cseg_read_cell";
 
 int cseg_read_cell(CSEG * cseg, char *map_name, char *mapset)
 {
-    int row, nrows;
+    GW_LARGE_INT row, nrows;
     int map_fd;
     CELL *buffer;
 

Modified: grass/trunk/raster/r.watershed/seg/cseg_write.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/cseg_write.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/cseg_write.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -1,12 +1,12 @@
 #include <grass/gis.h>
 #include <grass/raster.h>
 #include <grass/segment.h>
-#include "cseg.h"
+#include "Gwater.h"
 
 int cseg_write_cellfile(CSEG * cseg, char *map_name)
 {
     int map_fd;
-    int row, nrows;
+    GW_LARGE_INT row, nrows;
     CELL *buffer;
 
     map_fd = Rast_open_c_new(map_name);

Modified: grass/trunk/raster/r.watershed/seg/def_basin.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/def_basin.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/def_basin.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -6,8 +6,9 @@
 {
     int r, rr, c, cc, ct, new_r[9], new_c[9];
     CELL value, new_elev;
-    char downdir, direction, asp_value, cvalue;
+    char downdir, direction, asp_value;
     int oldupdir, riteflag, leftflag, thisdir;
+    ASP_FLAG af;
 
     for (;;) {
 	cseg_put(&bas, &basin_num, row, col);
@@ -17,12 +18,12 @@
 		if (r >= 0 && c >= 0 && r < nrows && c < ncols) {
 		    if (r == row && c == col)
 			continue;
-		    bseg_get(&asp, &asp_value, r, c);
+		    seg_get(&aspflag, (char *)&af, r, c);
+		    asp_value = af.asp;
 		    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)) {
+			if (FLAG_GET(af.flag, SWALEFLAG)) {
 			    new_r[++ct] = r;
 			    new_c[ct] = c;
 			}
@@ -40,7 +41,8 @@
 	    return (basin_num);
 	}
 	oldupdir = drain[row - new_r[1] + 1][col - new_c[1] + 1];
-	bseg_get(&asp, &downdir, row, col);
+	seg_get(&aspflag, (char *)&af, row, col);
+	downdir = af.asp;
 	if (downdir < 0)
 	    downdir = -downdir;
 	riteflag = leftflag = 0;
@@ -49,7 +51,8 @@
 		if (r >= 0 && c >= 0 && r < nrows && c < ncols) {
 		    if (r == row && c == col)
 			continue;
-		    bseg_get(&asp, &direction, r, c);
+		    seg_get(&aspflag, (char *)&af, r, c);
+		    direction = af.asp;
 		    if (direction == drain[rr][cc]) {
 			thisdir = updrain[rr][cc];
 			switch (haf_basin_side
@@ -87,7 +90,8 @@
 	    }
 	    else {			/* sides == 4 */
 
-		bseg_get(&asp, &asp_value, row, col);
+		seg_get(&aspflag, (char *)&af, row, col);
+		asp_value = af.asp;
 		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	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/do_astar.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -4,18 +4,18 @@
 #include "do_astar.h"
 
 HEAP_PNT drop_pt(void);
-int sift_up(int, HEAP_PNT);
+int sift_up(GW_LARGE_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;
+    GW_LARGE_INT doer, count;
     int upr, upc, r = -1, c = -1, ct_dir;
     CELL alt_val, alt_nbr[8];
     WAT_ALT wa;
-    char asp_val;
-    char flag_value, is_in_list, is_worked;
+    ASP_FLAG af;
+    char is_in_list, is_worked;
     HEAP_PNT heap_p;
 
     /* sides
@@ -28,7 +28,6 @@
     double dx, dy, dist_to_nbr[8], ew_res, ns_res;
     double slope[8];
     int skip_diag;
-    int count_edge = 0, count_diag = 0, count_edge_sink = 0, count_diag_sink = 0;
 
     G_message(_("SECTION 2: A* Search."));
 
@@ -50,7 +49,7 @@
     if (heap_size == 0)
 	G_fatal_error(_("No seeds for A* Search"));
 
-    G_debug(1, "heap size %d, points %d", heap_size, do_points);
+    G_debug(1, "heap size %"PRI_OFF_T", points %"PRI_OFF_T, heap_size, do_points);
 
     count = 0;
 
@@ -64,7 +63,7 @@
 
 	r = heap_p.pnt.r;
 	c = heap_p.pnt.c;
-	G_debug(3, "heap size %d, r %d, c %d", heap_size, r, c);
+	G_debug(3, "heap size %"PRI_OFF_T", r %d, c %d", heap_size, r, c);
 
 	alt_val = heap_p.ele;
 
@@ -76,9 +75,9 @@
 	    slope[ct_dir] = alt_nbr[ct_dir] = 0;
 	    /* check if upr, upc are within region */
 	    if (upr >= 0 && upr < nrows && upc >= 0 && upc < ncols) {
-		bseg_get(&bitflags, &flag_value, upr, upc);
-		is_in_list = FLAG_GET(flag_value, INLISTFLAG);
-		is_worked = FLAG_GET(flag_value, WORKEDFLAG);
+		seg_get(&aspflag, (char *)&af, upr, upc);
+		is_in_list = FLAG_GET(af.flag, INLISTFLAG);
+		is_worked = FLAG_GET(af.flag, WORKEDFLAG);
 		skip_diag = 0;
 		/* avoid diagonal flow direction bias */
 		if (!is_worked) {
@@ -110,34 +109,18 @@
 		/* add neighbour as new point if not in the list */
 		if (is_in_list == 0 && skip_diag == 0) {
 		    /* set flow direction */
-		    asp_val = drain[upr - r + 1][upc - c + 1];
+		    af.asp = drain[upr - r + 1][upc - c + 1];
 		    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++;
-			else
-			    count_diag_sink++;
-		    }
-		    /* includes flat areas */
-		    else {
-			if (ct_dir < 4)
-			    count_edge++;
-			else
-			    count_diag++;
-		    }
+		    FLAG_SET(af.flag, INLISTFLAG);
+		    seg_put(&aspflag, (char *)&af, upr, upc);
 		}
 		else if (is_in_list && is_worked == 0 &&
-			 FLAG_GET(flag_value, EDGEFLAG)) {
+			 FLAG_GET(af.flag, EDGEFLAG)) {
 		    /* neighbour is edge in list, not yet worked */
-		    bseg_get(&asp, &asp_val, upr, upc);
-		    if (asp_val < 0) {
+		    if (af.asp < 0) {
 			/* adjust flow direction for edge cell */
-			asp_val = drain[upr - r + 1][upc - c + 1];
-			bseg_put(&asp, &asp_val, upr, upc);
+			af.asp = drain[upr - r + 1][upc - c + 1];
+			seg_put(&aspflag, (char *)&af, upr, upc);
 			seg_get(&watalt, (char *)&wa, r, c);
 			if (wa.wat > 0) {
 			    wa.wat = -wa.wat;
@@ -145,9 +128,9 @@
 			}
 		    }
 		    /* neighbour is inside real depression, not yet worked */
-		    else if (asp_val == 0) {
-			asp_val = drain[upr - r + 1][upc - c + 1];
-			bseg_put(&asp, &asp_val, upr, upc);
+		    else if (af.asp == 0) {
+			af.asp = drain[upr - r + 1][upc - c + 1];
+			seg_put(&aspflag, (char *)&af, upr, upc);
 		    }
 		}
 	    }
@@ -155,23 +138,18 @@
 	/* add astar points to sorted list for flow accumulation */
 	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);
+	seg_get(&aspflag, (char *)&af, r, c);
+	FLAG_SET(af.flag, WORKEDFLAG);
+	seg_put(&aspflag, (char *)&af, r, c);
     }
     if (doer != -1)
-	G_fatal_error(_("bug in A* Search: doer %d heap size %d count %d"),
+	G_fatal_error(_("bug in A* Search: doer %"PRI_OFF_T" heap size %"PRI_OFF_T" count %"PRI_OFF_T),
 		      doer, heap_size, count);
 
     seg_close(&search_heap);
 
     G_percent(count, do_points, 1);	/* finish it */
 
-    G_debug(1, "edge direction: %d (%.2f%%)", count_edge, (double) 100. * count_edge / (count_edge + count_diag));
-    G_debug(1, "diag direction: %d (%.2f%%)", count_diag, (double) 100. * count_diag / (count_edge + count_diag));
-    G_debug(1, "edge out of depression: %d (%.2f%%)", count_edge_sink, (double) 100. * count_edge_sink / (count_edge_sink + count_diag_sink));
-    G_debug(1, "diag out of depression: %d (%.2f%%)", count_diag_sink, (double) 100. * count_diag_sink / (count_edge_sink + count_diag_sink));
-
     return 0;
 }
 
@@ -258,9 +236,9 @@
 }
 
 /* standard sift-up routine for d-ary min heap */
-int sift_up(int start, HEAP_PNT child_p)
+int sift_up(GW_LARGE_INT start, HEAP_PNT child_p)
 {
-    int parent, child;
+    GW_LARGE_INT parent, child;
     HEAP_PNT heap_p;
 
     child = start;

Modified: grass/trunk/raster/r.watershed/seg/do_astar.h
===================================================================
--- grass/trunk/raster/r.watershed/seg/do_astar.h	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/do_astar.h	2012-04-22 17:12:18 UTC (rev 51483)
@@ -1,8 +1,8 @@
 #ifndef __DO_ASTAR_H__
 #define __DO_ASTAR_H__
 
-#define GET_PARENT(c) ((int) ((((c) - 2) >> 2) + 1))
-#define GET_CHILD(p) ((int) (((p) << 2) - 2))
+#define GET_PARENT(c) (((((GW_LARGE_INT) (c) - 2) >> 2) + 1))
+#define GET_CHILD(p) ((((GW_LARGE_INT) (p) << 2) - 2))
 
 /*
 #define GET_PARENT(c) ((int) (((c) - 2) / 3 + 1))

Modified: grass/trunk/raster/r.watershed/seg/do_cum.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/do_cum.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/do_cum.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -8,14 +8,15 @@
 int do_cum(void)
 {
     int r, c, dr, dc;
-    char asp_val, asp_val_down;
-    char is_swale, this_flag_value, flag_value;
+    char is_swale;
     DCELL value, valued;
     POINT point;
-    int killer, threshold;
+    GW_LARGE_INT killer;
+    int threshold;
     int asp_r[9] = { 0, -1, -1, -1, 0, 1, 1, 1, 0 };
     int asp_c[9] = { 0, 1, 0, -1, -1, -1, 0, 1, 1 };
     WAT_ALT wa, wadown;
+    ASP_FLAG af, afdown;
 
     G_message(_("SECTION 3: Accumulating Surface Flow with SFD."));
 
@@ -28,26 +29,25 @@
 	seg_get(&astar_pts, (char *)&point, 0, killer);
 	r = point.r;
 	c = point.c;
-	bseg_get(&asp, &asp_val, r, c);
-	if (asp_val) {
-	    dr = r + asp_r[ABS(asp_val)];
-	    dc = c + asp_c[ABS(asp_val)];
+	seg_get(&aspflag, (char *)&af, r, c);
+	if (af.asp) {
+	    dr = r + asp_r[ABS(af.asp)];
+	    dc = c + asp_c[ABS(af.asp)];
 	}
 	/* skip user-defined depressions */
 	else
 	    dr = dc = -1;
 
-	bseg_get(&bitflags, &this_flag_value, r, c);
-	FLAG_UNSET(this_flag_value, WORKEDFLAG);
+	FLAG_UNSET(af.flag, WORKEDFLAG);
 
 	if (dr >= 0 && dr < nrows && dc >= 0 && dc < ncols) {
 	    /* TODO: do not distribute flow along edges, this causes artifacts */
 	    seg_get(&watalt, (char *)&wa, r, c);
 	    value = wa.wat;
-	    is_swale = FLAG_GET(this_flag_value, SWALEFLAG);
+	    is_swale = FLAG_GET(af.flag, SWALEFLAG);
 	    if (fabs(value) >= threshold && !is_swale) {
 		is_swale = 1;
-		FLAG_SET(this_flag_value, SWALEFLAG);
+		FLAG_SET(af.flag, SWALEFLAG);
 	    }
 	    seg_get(&watalt, (char *)&wadown, dr, dc);
 	    valued = wadown.wat;
@@ -67,17 +67,17 @@
 	    seg_put(&watalt, (char *)&wadown, dr, dc);
 	    /* update asp for depression */
 	    if (is_swale || fabs(valued) >= threshold) {
-		bseg_get(&bitflags, &flag_value, dr, dc);
-		FLAG_SET(flag_value, SWALEFLAG);
-		bseg_put(&bitflags, &flag_value, dr, dc);
+		seg_get(&aspflag, (char *)&afdown, dr, dc);
+		FLAG_SET(afdown.flag, SWALEFLAG);
+		seg_put(&aspflag, (char *)&afdown, dr, dc);
 		is_swale = 1;
 	    }
 	    else {
-		if (er_flag && !is_swale && !FLAG_GET(this_flag_value, RUSLEBLOCKFLAG))
+		if (er_flag && !is_swale && !FLAG_GET(afdown.flag, RUSLEBLOCKFLAG))
 		    slope_length(r, c, dr, dc);
 	    }
 	}
-	bseg_put(&bitflags, &this_flag_value, r, c);
+	seg_put(&aspflag, (char *)&af, r, c);
     }
     G_percent(do_points, do_points, 1);	/* finish it */
 
@@ -114,7 +114,9 @@
     DCELL value, valued, *wat_nbr;
     POINT point;
     WAT_ALT wa;
-    int killer, threshold;
+    ASP_FLAG af, afdown;
+    GW_LARGE_INT killer;
+    int threshold;
 
     /* MFD */
     int mfd_cells, stream_cells, swale_cells, astar_not_set, is_null;
@@ -122,10 +124,9 @@
     int r_nbr, c_nbr, r_max, c_max, ct_dir, np_side, max_side;
     double dx, dy;
     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;
+    char *flag_nbr;
     int asp_r[9] = { 0, -1, -1, -1, 0, 1, 1, 1, 0 };
     int asp_c[9] = { 0, 1, 0, -1, -1, -1, 0, 1, 1 };
 
@@ -165,10 +166,10 @@
 	seg_get(&astar_pts, (char *)&point, 0, killer);
 	r = point.r;
 	c = point.c;
-	bseg_get(&asp, &asp_val, r, c);
-	if (asp_val) {
-	    dr = r + asp_r[ABS(asp_val)];
-	    dc = c + asp_c[ABS(asp_val)];
+	seg_get(&aspflag, (char *)&af, r, c);
+	if (af.asp) {
+	    dr = r + asp_r[ABS(af.asp)];
+	    dc = c + asp_c[ABS(af.asp)];
 	}
 	/* skip user-defined depressions */
 	else
@@ -176,8 +177,7 @@
 
 	/* 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);
+	FLAG_UNSET(af.flag, WORKEDFLAG);
 	
 	if (dr >= 0 && dr < nrows && dc >= 0 && dc < ncols) {
 	    r_max = dr;
@@ -207,6 +207,7 @@
 
 		wat_nbr[ct_dir] = 0;
 		ele_nbr[ct_dir] = 0;
+		flag_nbr[ct_dir] = 0;
 
 		/* check if neighbour is within region */
 		if (r_nbr >= 0 && r_nbr < nrows && c_nbr >= 0 &&
@@ -215,7 +216,8 @@
 		    if (dr == r_nbr && dc == c_nbr)
 			np_side = ct_dir;
 
-		    bseg_get(&bitflags, &flag_nbr[ct_dir], r_nbr, c_nbr);
+		    seg_get(&aspflag, (char *)&afdown, r_nbr, c_nbr);
+		    flag_nbr[ct_dir] = afdown.flag;
 		    seg_get(&watalt, (char *)&wa, r_nbr, c_nbr);
 		    wat_nbr[ct_dir] = wa.wat;
 		    ele_nbr[ct_dir] = wa.ele;
@@ -266,12 +268,11 @@
 	    }
 	    /* do not continue streams along edges, this causes artifacts */
 	    if (edge) {
-		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];
-		    bseg_put(&asp, &asp_val, r, c);
+		is_swale = FLAG_GET(af.flag, SWALEFLAG);
+		if (is_swale && af.asp > 0) {
+		    af.asp = -1 * drain[r - r_nbr + 1][c - c_nbr + 1];
 		}
-		bseg_put(&bitflags, &this_flag_value, r, c);
+		seg_put(&aspflag, (char *)&af, r, c);
 		continue;
 	    }
 
@@ -327,7 +328,7 @@
 			    seg_put(&watalt, (char *)&wa, r_nbr, c_nbr);
 
 			    /* get main drainage direction */
-			    if (ABS(wat_nbr[ct_dir]) >= max_acc) {
+			    if (fabs(wat_nbr[ct_dir]) >= max_acc) {
 				max_acc = ABS(wat_nbr[ct_dir]);
 				r_max = r_nbr;
 				c_max = c_nbr;
@@ -348,7 +349,7 @@
 		    c_max = dc;
 		} */
 
-		if (ABS(prop - 1.0) > 5E-6f) {
+		if (fabs(prop - 1.0) > 5E-6f) {
 		    G_warning(_("MFD: cumulative proportion of flow distribution not 1.0 but %f"),
 			      prop);
 		}
@@ -375,39 +376,36 @@
 
 	    /* update asp */
 	    if (dr != r_max || dc != c_max) {
-		if (asp_val < 0) {
-		    asp_val = -1 * drain[r - r_max + 1][c - c_max + 1];
+		if (af.asp < 0) {
+		    af.asp = -1 * drain[r - r_max + 1][c - c_max + 1];
 		}
 		else
-		    asp_val = drain[r - r_max + 1][c - c_max + 1];
-		    
-		bseg_put(&asp, &asp_val, r, c);
+		    af.asp = drain[r - r_max + 1][c - c_max + 1];
 	    }
-	    is_swale = FLAG_GET(this_flag_value, SWALEFLAG);
+	    is_swale = FLAG_GET(af.flag, SWALEFLAG);
 	    /* start new stream */
-	    value = ABS(value) + 0.5;
-	    if (!is_swale && (int)value >= threshold && stream_cells < 1 &&
+	    if (!is_swale && fabs(value) >= threshold && stream_cells < 1 &&
 		swale_cells < 1 && !flat) {
-		FLAG_SET(this_flag_value, SWALEFLAG);
+		FLAG_SET(af.flag, SWALEFLAG);
 		is_swale = 1;
 	    }
 	    /* continue stream */
 	    if (is_swale) {
-		flag_value = flag_nbr[max_side];
-		FLAG_SET(flag_value, SWALEFLAG);
-		bseg_put(&bitflags, &flag_value, r_max, c_max);
+		seg_get(&aspflag, (char *)&afdown, r_max, c_max);
+		FLAG_SET(afdown.flag, SWALEFLAG);
+		seg_put(&aspflag, (char *)&afdown, r_max, c_max);
 	    }
 	    else {
-		if (er_flag && !is_swale && !FLAG_GET(this_flag_value, RUSLEBLOCKFLAG))
+		if (er_flag && !is_swale && !FLAG_GET(af.flag, RUSLEBLOCKFLAG))
 		    slope_length(r, c, r_max, c_max);
 	    }
 	}
-	bseg_put(&bitflags, &this_flag_value, r, c);
+	seg_put(&aspflag, (char *)&af, r, c);
     }
     G_percent(do_points, do_points, 1);	/* finish it */
     
     if (workedon)
-	G_warning(_("MFD: A * path already processed when distributing flow: %d of %d cells"),
+	G_warning(_("MFD: A * path already processed when distributing flow: %d of %"PRI_OFF_T" cells"),
 		  workedon, do_points);
 
     seg_close(&astar_pts);

Modified: grass/trunk/raster/r.watershed/seg/dseg_close.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/dseg_close.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/dseg_close.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -1,6 +1,6 @@
 #include <grass/gis.h>
 #include <unistd.h>
-#include "cseg.h"
+#include "Gwater.h"
 
 int dseg_close(DSEG * dseg)
 {

Modified: grass/trunk/raster/r.watershed/seg/dseg_get.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/dseg_get.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/dseg_get.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -1,8 +1,8 @@
 #include <grass/gis.h>
 #include <grass/segment.h>
-#include "cseg.h"
+#include "Gwater.h"
 
-int dseg_get(DSEG * dseg, double *value, int row, int col)
+int dseg_get(DSEG * dseg, double *value, GW_LARGE_INT row, GW_LARGE_INT col)
 {
     if (segment_get(&(dseg->seg), (DCELL *) value, row, col) < 0) {
 	G_warning("dseg_get(): could not read segment file");

Modified: grass/trunk/raster/r.watershed/seg/dseg_open.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/dseg_open.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/dseg_open.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -2,7 +2,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <grass/segment.h>
-#include "cseg.h"
+#include "Gwater.h"
 
 
 int dseg_open(DSEG * dseg, int srows, int scols, int nsegs_in_memory)

Modified: grass/trunk/raster/r.watershed/seg/dseg_put.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/dseg_put.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/dseg_put.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -1,8 +1,8 @@
 #include <grass/gis.h>
 #include <grass/segment.h>
-#include "cseg.h"
+#include "Gwater.h"
 
-int dseg_put(DSEG * dseg, double *value, int row, int col)
+int dseg_put(DSEG * dseg, double *value, GW_LARGE_INT row, GW_LARGE_INT col)
 {
     if (segment_put(&(dseg->seg), (DCELL *) value, row, col) < 0) {
 	G_warning("dseg_put(): could not write segment file");
@@ -11,7 +11,7 @@
     return 0;
 }
 
-int dseg_put_row(DSEG * dseg, double *value, int row)
+int dseg_put_row(DSEG * dseg, double *value, GW_LARGE_INT row)
 {
     if (segment_put_row(&(dseg->seg), (DCELL *) value, row) < 0) {
 	G_warning("dseg_put(): could not write segment file");

Modified: grass/trunk/raster/r.watershed/seg/dseg_read.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/dseg_read.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/dseg_read.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -1,13 +1,13 @@
 #include <grass/gis.h>
 #include <grass/raster.h>
 #include <grass/segment.h>
-#include "cseg.h"
+#include "Gwater.h"
 
 static char *me = "dseg_read_cell";
 
 int dseg_read_cell(DSEG * dseg, char *map_name, char *mapset)
 {
-    int row, nrows, ncols;
+    GW_LARGE_INT row, nrows, ncols;
     int map_fd;
     double *dbuffer;
 

Modified: grass/trunk/raster/r.watershed/seg/dseg_write.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/dseg_write.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/dseg_write.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -1,12 +1,12 @@
 #include <grass/gis.h>
 #include <grass/raster.h>
 #include <grass/segment.h>
-#include "cseg.h"
+#include "Gwater.h"
 
 int dseg_write_cellfile(DSEG * dseg, char *map_name)
 {
     int map_fd;
-    int row, nrows, ncols;
+    GW_LARGE_INT row, nrows, ncols;
     double *dbuffer;
 
     map_fd = Rast_open_new(map_name, DCELL_TYPE);

Modified: grass/trunk/raster/r.watershed/seg/find_pour.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/find_pour.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/find_pour.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -5,8 +5,8 @@
     int row, col;
     double easting, northing, stream_length;
     CELL old_elev, basin_num, no_basin, curr_basin;
-    char aspect;
     WAT_ALT wa;
+    ASP_FLAG af;
     char is_swale;
 
     ocs_alloced = 2 * bas_thres;
@@ -19,16 +19,15 @@
 	G_percent(row, nrows, 1);
 	northing = window.north - (row + .5) * window.ns_res;
 	for (col = 0; col < ncols; col++) {
-	    bseg_get(&asp, &aspect, row, col);
-	    bseg_get(&bitflags, &is_swale, row, col);
+	    seg_get(&aspflag, (char *)&af, row, col);
 	    cseg_get(&bas, &curr_basin, row, col);
 	    if (curr_basin == 0)
 		cseg_put(&bas, &no_basin, row, col);
 	    cseg_get(&haf, &curr_basin, row, col);
 	    if (curr_basin == 0)
 		cseg_put(&haf, &no_basin, row, col);
-	    is_swale = FLAG_GET(is_swale, SWALEFLAG);
-	    if (aspect <= 0 && is_swale > 0) {
+	    is_swale = FLAG_GET(af.flag, SWALEFLAG);
+	    if (af.asp <= 0 && is_swale > 0) {
 		basin_num += 2;
 		if (arm_flag) {
 		    easting = window.west + (col + .5) * window.ew_res;

Modified: grass/trunk/raster/r.watershed/seg/init_vars.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/init_vars.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/init_vars.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -10,18 +10,18 @@
 int init_vars(int argc, char *argv[])
 {
     int r, c;
-    int ele_fd, fd, wat_fd;
+    int ele_fd, wat_fd, fd = -1;
     int seg_rows, seg_cols, num_cseg_total, num_open_segs, num_open_array_segs;
     double memory_divisor, heap_mem, seg_factor, disk_space;
 
     /* int page_block, num_cseg; */
     int max_bytes;
     CELL *buf, alt_value, *alt_value_buf, block_value;
-    char asp_value, *asp_buf;
-    char worked_value, flag_value, *flag_value_buf;
+    char asp_value;
     DCELL wat_value;
     DCELL dvalue;
     WAT_ALT wa, *wabuf;
+    ASP_FLAG af, af_nbr, *afbuf;
     char MASK_flag;
     void *elebuf, *ptr, *watbuf, *watptr;
     int ele_map_type, wat_map_type;
@@ -163,12 +163,9 @@
     /* elevation + accumulation: * 2 */
     memory_divisor = sizeof(WAT_ALT) * 2;
     disk_space = sizeof(WAT_ALT);
-    /* aspect: as is */
-    memory_divisor += 1;
-    disk_space += 1;
-    /* flags: * 4 */
-    memory_divisor += 4;
-    disk_space += 1;
+    /* aspect and flags: * 4 */
+    memory_divisor += sizeof(ASP_FLAG) * 4;
+    disk_space += sizeof(ASP_FLAG);
     /* astar_points: / 16 */
     /* ideally only a few but large segments */
     memory_divisor += sizeof(POINT) / 16.;
@@ -244,8 +241,7 @@
 
     /* 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);
+    seg_open(&aspflag, nrows, ncols, seg_rows, seg_cols, num_open_segs * 4, sizeof(ASP_FLAG));
 
     /* open elevation input */
     ele_fd = Rast_open_old(ele_name, "");
@@ -253,7 +249,7 @@
     ele_map_type = Rast_get_map_type(ele_fd);
     ele_size = Rast_cell_size(ele_map_type);
     elebuf = Rast_allocate_buf(ele_map_type);
-    asp_buf = G_malloc(ncols * sizeof(char));
+    afbuf = G_malloc(ncols * sizeof(ASP_FLAG));
 
     if (ele_map_type == FCELL_TYPE || ele_map_type == DCELL_TYPE)
 	ele_scale = 1000; 	/* should be enough to do the trick */
@@ -271,13 +267,13 @@
 	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("New version");
     G_message("SECTION 1a: Mark masked and NULL cells");
     MASK_flag = 0;
-    do_points = nrows * ncols;
+    do_points = (GW_LARGE_INT) nrows * ncols;
     for (r = 0; r < nrows; r++) {
 	G_percent(r, nrows, 1);
 	Rast_get_row(ele_fd, elebuf, r, ele_map_type);
@@ -290,14 +286,14 @@
 	
 	for (c = 0; c < ncols; c++) {
 
-	    flag_value_buf[c] = 0;
-	    asp_buf[c] = 0;
+	    afbuf[c].flag = 0;
+	    afbuf[c].asp = 0;
 
 	    /* check for masked and NULL cells */
 	    if (Rast_is_null_value(ptr, ele_map_type)) {
-		FLAG_SET(flag_value_buf[c], NULLFLAG);
-		FLAG_SET(flag_value_buf[c], INLISTFLAG);
-		FLAG_SET(flag_value_buf[c], WORKEDFLAG);
+		FLAG_SET(afbuf[c].flag, NULLFLAG);
+		FLAG_SET(afbuf[c].flag, INLISTFLAG);
+		FLAG_SET(afbuf[c].flag, WORKEDFLAG);
 		Rast_set_c_null_value(&alt_value, 1);
 		/* flow accumulation */
 		Rast_set_d_null_value(&wat_value, 1);
@@ -338,7 +334,6 @@
 		else {
 		    wat_value = 1;
 		}
-
 	    }
 	    wabuf[c].wat = wat_value;
 	    wabuf[c].ele = alt_value;
@@ -349,8 +344,7 @@
 	    }
 	}
 	seg_put_row(&watalt, (char *) wabuf, r);
-	bseg_put_row(&bitflags, flag_value_buf, r);
-	bseg_put_row(&asp, asp_buf, r);
+	seg_put_row(&aspflag, (char *)afbuf, r);
 	
 	if (er_flag) {
 	    cseg_put_row(&r_h, alt_value_buf, r);
@@ -359,8 +353,7 @@
     G_percent(nrows, nrows, 1);    /* finish it */
     Rast_close(ele_fd);
     G_free(wabuf);
-    G_free(flag_value_buf);
-    G_free(asp_buf);
+    G_free(afbuf);
     
     if (run_flag) {
 	Rast_close(wat_fd);
@@ -380,9 +373,9 @@
 		for (c = 0; c < ncols; c++) {
 		    block_value = buf[c];
 		    if (!Rast_is_c_null_value(&block_value) && block_value) {
-			bseg_get(&bitflags, &flag_value, r, c);
-			FLAG_SET(flag_value, RUSLEBLOCKFLAG);
-			bseg_put(&bitflags, &flag_value, r, c);
+			seg_get(&aspflag, (char *)&af, r, c);
+			FLAG_SET(af.flag, RUSLEBLOCKFLAG);
+			seg_put(&aspflag, (char *)&af, r, c);
 		    }
 		}
 	    }
@@ -462,11 +455,11 @@
 	if (pit_flag)
 	    Rast_get_c_row(fd, buf, r);
 	for (c = 0; c < ncols; c++) {
-	    bseg_get(&bitflags, &flag_value, r, c);
-	    if (!FLAG_GET(flag_value, NULLFLAG)) {
+	    seg_get(&aspflag, (char *)&af, r, c);
+	    if (!FLAG_GET(af.flag, NULLFLAG)) {
 		if (er_flag)
 		    dseg_put(&s_l, &half_res, r, c);
-		bseg_get(&asp, &asp_value, r, c);
+		asp_value = af.asp;
 		if (r == 0 || c == 0 || r == nrows - 1 ||
 		    c == ncols - 1) {
 		    /* dseg_get(&wat, &wat_value, r, c); */
@@ -486,14 +479,13 @@
 			asp_value = -6;
 		    else if (c == ncols - 1)
 			asp_value = -8;
-		    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);
-		    FLAG_SET(flag_value, INLISTFLAG);
-		    FLAG_SET(flag_value, EDGEFLAG);
-		    bseg_put(&bitflags, &flag_value, r, c);
+		    FLAG_SET(af.flag, INLISTFLAG);
+		    FLAG_SET(af.flag, EDGEFLAG);
+		    af.asp = asp_value;
+		    seg_put(&aspflag, (char *)&af, r, c);
 		}
 		else {
 		    seg_get(&watalt, (char *)&wa, r, c);
@@ -502,14 +494,13 @@
 			r_nbr = r + nextdr[ct_dir];
 			c_nbr = c + nextdc[ct_dir];
 
-			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];
+			seg_get(&aspflag, (char *)&af_nbr, r_nbr, c_nbr);
+			if (FLAG_GET(af_nbr.flag, NULLFLAG)) {
+			    af.asp = -1 * drain[r - r_nbr + 1][c - c_nbr + 1];
 			    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);
+			    FLAG_SET(af.flag, INLISTFLAG);
+			    FLAG_SET(af.flag, EDGEFLAG);
+			    seg_put(&aspflag, (char *)&af, r, c);
 			    wat_value = wa.wat;
 			    if (wat_value > 0) {
 				wa.wat = -wat_value;
@@ -526,9 +517,9 @@
 			seg_get(&watalt, (char *)&wa, 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);
+			FLAG_SET(af.flag, INLISTFLAG);
+			FLAG_SET(af.flag, EDGEFLAG);
+			seg_put(&aspflag, (char *)&af, r, c);
 			wat_value = wa.wat;
 			if (wat_value > 0) {
 			    wa.wat = -wat_value;

Modified: grass/trunk/raster/r.watershed/seg/main.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/main.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/main.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -27,18 +27,18 @@
 
 int mfd, c_fac, abs_acc, ele_scale;
 SSEG search_heap;
-int heap_size;
-int first_astar, first_cum, nxt_avail_pt, total_cells, do_points;
+int nrows, ncols;
+GW_LARGE_INT heap_size;
+GW_LARGE_INT first_astar, first_cum, nxt_avail_pt, total_cells, do_points;
 CELL n_basins;
 OC_STACK *ocs;
 int ocs_alloced;
-int nrows, ncols;
 double half_res, diag, max_length, dep_slope;
 int bas_thres, tot_parts;
 SSEG astar_pts;
-BSEG bitflags, s_b, asp;
+BSEG s_b;
 CSEG dis, alt, bas, haf, r_h, dep;
-SSEG watalt;
+SSEG watalt, aspflag;
 DSEG slp, s_l, s_g, l_s, ril;
 double segs_mb;
 char zero, one;

Modified: grass/trunk/raster/r.watershed/seg/no_stream.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/no_stream.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/no_stream.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -11,6 +11,7 @@
     DCELL dvalue, max_drain;	/* flow acc is now DCELL */
     int updir, riteflag, leftflag, thisdir;
     WAT_ALT wa;
+    ASP_FLAG af;
 
     while (1) {
 	cseg_put(&bas, &basin_num, row, col);
@@ -19,7 +20,8 @@
 	    for (c = col - 1, cc = 0; c <= col + 1; c++, cc++) {
 		if (r >= 0 && c >= 0 && r < nrows && c < ncols) {
 
-		    bseg_get(&asp, &aspect, r, c);
+		    seg_get(&aspflag, (char *)&af, r, c);
+		    aspect = af.asp;
 		    if (aspect == drain[rr][cc]) {
 			seg_get(&watalt, (char *)&wa, r, c);
 			dvalue = wa.wat;
@@ -36,7 +38,8 @@
 	}
 	if (max_drain > -1) {
 	    updir = drain[row - uprow + 1][col - upcol + 1];
-	    bseg_get(&asp, &downdir, row, col);
+	    seg_get(&aspflag, (char *)&af, row, col);
+	    downdir = af.asp;
 	    if (downdir < 0)
 		downdir = -downdir;
 	    if (arm_flag) {
@@ -49,8 +52,8 @@
 			stream_length += window.ew_res;
 		}
 		else {		/* sides == 4 */
-
-		    bseg_get(&asp, &asp_value, uprow, upcol);
+		    seg_get(&aspflag, (char *)&af, uprow, upcol);
+		    asp_value = af.asp;
 		    if (downdir == 2 || downdir == 6) {
 			if (asp_value == 2 || asp_value == 6)
 			    stream_length += window.ns_res;
@@ -70,7 +73,8 @@
 	    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) {
-			bseg_get(&asp, &aspect, r, c);
+			seg_get(&aspflag, (char *)&af, r, c);
+			aspect = af.asp;
 			if (aspect == drain[rr][cc]) {
 			    thisdir = updrain[rr][cc];
 			    switch (haf_basin_side(updir,

Modified: grass/trunk/raster/r.watershed/seg/over_cells.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/over_cells.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/over_cells.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -7,6 +7,7 @@
     int r, rr, c, cc;
     CELL new_ele, new_max_ele;
     char aspect;
+    ASP_FLAG af;
 
     cseg_put(&bas, &basin_num, row, col);
     cseg_put(&haf, &haf_num, row, col);
@@ -16,7 +17,8 @@
 	    if (r >= 0 && c >= 0 && r < nrows && c < ncols) {
 		if (r == row && c == col)
 		    continue;
-		bseg_get(&asp, &aspect, r, c);
+		seg_get(&aspflag, (char *)&af, r, c);
+		aspect = af.asp;
 		if (aspect == drain[rr][cc]) {
 		    overland_cells(r, c, basin_num, haf_num, &new_ele);
 		}
@@ -44,6 +46,7 @@
     int r, rr, c, cc, next_r, next_c;
     char aspect;
     int top = 0;
+    ASP_FLAG af;
 
     /* put root on stack */
     ocs[top].row = row;
@@ -64,7 +67,8 @@
 		if (r >= 0 && c >= 0 && r < nrows && c < ncols) {
 		    if (r == row && c == col)
 			continue;
-		    bseg_get(&asp, &aspect, r, c);
+		    seg_get(&aspflag, (char *)&af, r, c);
+		    aspect = af.asp;
 		    if (aspect == drain[rr][cc]) {
 			if (top >= ocs_alloced) {
 			    ocs_alloced += bas_thres;

Modified: grass/trunk/raster/r.watershed/seg/sg_factor.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/sg_factor.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/sg_factor.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -8,15 +8,15 @@
     int r, c;
     CELL low_elev, hih_elev;
     double height, length, S, sin_theta;
-    char flag_value;
     WAT_ALT wa;
+    ASP_FLAG af;
 
     G_message(_("SECTION 5: RUSLE LS and/or S factor determination."));
     for (r = nrows - 1; r >= 0; r--) {
 	G_percent(nrows - r, nrows, 3);
 	for (c = ncols - 1; c >= 0; c--) {
-	    bseg_get(&bitflags, &flag_value, r, c);
-	    if (FLAG_GET(flag_value, NULLFLAG))
+	    seg_get(&aspflag, (char *)&af, r, c);
+	    if (FLAG_GET(af.flag, NULLFLAG))
 		continue;
 	    
 	    seg_get(&watalt, (char *) &wa, r, c);

Modified: grass/trunk/raster/r.watershed/seg/slope_len.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/slope_len.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/slope_len.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -6,6 +6,7 @@
     char asp_value;
     double res, top_ls, bot_ls;
     WAT_ALT wa;
+    ASP_FLAG af;
 
     if (sides == 8) {
 	if (r == dr)
@@ -17,7 +18,8 @@
     }
     else {			/* sides == 4 */
 
-	bseg_get(&asp, &asp_value, dr, dc);
+	seg_get(&aspflag, (char *)&af, dr, dc);
+	asp_value = af.asp;
 	if (r == dr) {
 	    if (asp_value == 2 || asp_value == 6)
 		res = window.ns_res;

Modified: grass/trunk/raster/r.watershed/seg/split_str.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/split_str.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/split_str.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -7,6 +7,7 @@
     CELL old_basin, new_elev;
     char downdir, aspect;
     WAT_ALT wa;
+    ASP_FLAG af;
     double slope, easting, northing;
     int doit, ctr, updir, splitdir[9];
     int thisdir, leftflag, riteflag;
@@ -17,7 +18,8 @@
     for (ctr = 1; ctr <= ct; ctr++)
 	splitdir[ctr] = drain[row - new_r[ctr] + 1][col - new_c[ctr] + 1];
     updir = splitdir[1];
-    bseg_get(&asp, &downdir, row, col);
+    seg_get(&aspflag, (char *)&af, row, col);
+    downdir = af.asp;
     if (downdir < 0)
 	downdir = -downdir;
     riteflag = leftflag = 0;
@@ -26,7 +28,8 @@
 	    if (r >= 0 && c >= 0 && r < nrows && c < ncols) {
 		if (r == row && c == col)
 		    continue;
-		bseg_get(&asp, &aspect, r, c);
+		seg_get(&aspflag, (char *)&af, r, c);
+		aspect = af.asp;
 		if (aspect == drain[rr][cc]) {
 		    doit = 1;
 		    thisdir = updrain[rr][cc];

Modified: grass/trunk/raster/r.watershed/seg/sseg_close.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/sseg_close.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/sseg_close.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -1,7 +1,7 @@
 #include <grass/gis.h>
 #include <unistd.h>
 #include <grass/segment.h>
-#include "cseg.h"
+#include "Gwater.h"
 
 int seg_close(SSEG * sseg)
 {

Modified: grass/trunk/raster/r.watershed/seg/sseg_get.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/sseg_get.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/sseg_get.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -1,8 +1,8 @@
 #include <grass/gis.h>
 #include <grass/segment.h>
-#include "cseg.h"
+#include "Gwater.h"
 
-int seg_get(SSEG * sseg, char *value, int row, int col)
+int seg_get(SSEG * sseg, char *value, GW_LARGE_INT row, GW_LARGE_INT col)
 {
     if (segment_get(&(sseg->seg), value, row, col) < 0) {
 	G_warning("seg_get(): could not read segment file");
@@ -11,7 +11,7 @@
     return 0;
 }
 
-int seg_get_row(SSEG * sseg, char *value, int row)
+int seg_get_row(SSEG * sseg, char *value, GW_LARGE_INT row)
 {
     if (segment_get_row(&(sseg->seg), value, row) < 0) {
 	G_warning("seg_get(): could not read segment file");

Modified: grass/trunk/raster/r.watershed/seg/sseg_open.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/sseg_open.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/sseg_open.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -2,10 +2,10 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <grass/segment.h>
-#include "cseg.h"
+#include "Gwater.h"
 
 int
-seg_open(SSEG * sseg, int nrows, int ncols, int row_in_seg, int col_in_seg,
+seg_open(SSEG * sseg, GW_LARGE_INT nrows, GW_LARGE_INT ncols, int row_in_seg, int col_in_seg,
 	 int nsegs_in_memory, int size_struct)
 {
     char *filename;

Modified: grass/trunk/raster/r.watershed/seg/sseg_put.c
===================================================================
--- grass/trunk/raster/r.watershed/seg/sseg_put.c	2012-04-22 17:11:23 UTC (rev 51482)
+++ grass/trunk/raster/r.watershed/seg/sseg_put.c	2012-04-22 17:12:18 UTC (rev 51483)
@@ -1,8 +1,8 @@
 #include <grass/gis.h>
 #include <grass/segment.h>
-#include "cseg.h"
+#include "Gwater.h"
 
-int seg_put(SSEG * sseg, char *value, int row, int col)
+int seg_put(SSEG * sseg, char *value, GW_LARGE_INT row, GW_LARGE_INT col)
 {
     if (segment_put(&(sseg->seg), value, row, col) < 0) {
 	G_warning("seg_put(): could not write segment file");
@@ -11,7 +11,7 @@
     return 0;
 }
 
-int seg_put_row(SSEG * sseg, char *value, int row)
+int seg_put_row(SSEG * sseg, char *value, GW_LARGE_INT row)
 {
     if (segment_put_row(&(sseg->seg), value, row) < 0) {
 	G_warning("seg_put(): could not write segment file");



More information about the grass-commit mailing list