[GRASS-SVN] r51570 - grass-addons/grass7/raster/r.stream.extract

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Apr 29 11:28:30 EDT 2012


Author: mmetz
Date: 2012-04-29 08:28:30 -0700 (Sun, 29 Apr 2012)
New Revision: 51570

Modified:
   grass-addons/grass7/raster/r.stream.extract/close.c
   grass-addons/grass7/raster/r.stream.extract/del_streams.c
   grass-addons/grass7/raster/r.stream.extract/do_astar.c
   grass-addons/grass7/raster/r.stream.extract/init_search.c
   grass-addons/grass7/raster/r.stream.extract/load.c
   grass-addons/grass7/raster/r.stream.extract/local_proto.h
   grass-addons/grass7/raster/r.stream.extract/main.c
   grass-addons/grass7/raster/r.stream.extract/streams.c
   grass-addons/grass7/raster/r.stream.extract/thin.c
Log:
sync to r.watershed

Modified: grass-addons/grass7/raster/r.stream.extract/close.c
===================================================================
--- grass-addons/grass7/raster/r.stream.extract/close.c	2012-04-29 12:06:36 UTC (rev 51569)
+++ grass-addons/grass7/raster/r.stream.extract/close.c	2012-04-29 15:28:30 UTC (rev 51570)
@@ -30,7 +30,7 @@
     double north_offset, west_offset, ns_res, ew_res;
     int next_cat;
 
-    G_message(_("Write vector map <%s>..."), stream_vect);
+    G_message(_("Writing vector map <%s>..."), stream_vect);
 
     if (0 > Vect_open_new(&Out, stream_vect, 0)) {
 	G_fatal_error(_("Unable to create vector map <%s>"), stream_vect);
@@ -153,7 +153,7 @@
     }
     G_percent(n_outlets, n_outlets, 1);	/* finish it */
 
-    G_message(_("Write vector attribute table"));
+    G_message(_("Writing vector attribute table"));
 
     /* Prepeare strings for use in db_* calls */
     db_init_string(&dbsql);
@@ -244,8 +244,8 @@
     stream_fd = dir_fd = -1;
     cell_buf1 = cell_buf2 = NULL;
 
-    G_message(_("Write raster %s"),
-              (stream_rast != NULL) + (dir_rast != NULL) > 1 ? "maps" : "map");
+    G_message(_("Writing raster %s"),
+              (stream_rast != NULL) + (dir_rast != NULL) > 1 ? _("maps") : _("map"));
 
     /* write requested output rasters */
     if (stream_rast) {

Modified: grass-addons/grass7/raster/r.stream.extract/del_streams.c
===================================================================
--- grass-addons/grass7/raster/r.stream.extract/del_streams.c	2012-04-29 12:06:36 UTC (rev 51569)
+++ grass-addons/grass7/raster/r.stream.extract/del_streams.c	2012-04-29 15:28:30 UTC (rev 51570)
@@ -127,7 +127,7 @@
     int other_trib, tmp_trib;
     int slength;
 
-    G_message(_("Delete stream segments shorter than %d cells..."), min_length);
+    G_message(_("Deleting stream segments shorter than %d cells..."), min_length);
 
     /* TODO: proceed from stream heads to outlets
      *       -> use depth first post order traversal */

Modified: grass-addons/grass7/raster/r.stream.extract/do_astar.c
===================================================================
--- grass-addons/grass7/raster/r.stream.extract/do_astar.c	2012-04-29 12:06:36 UTC (rev 51569)
+++ grass-addons/grass7/raster/r.stream.extract/do_astar.c	2012-04-29 15:28:30 UTC (rev 51570)
@@ -4,17 +4,17 @@
 #include <grass/glocale.h>
 #include "local_proto.h"
 
-#define GET_PARENT(c) ((unsigned int)(((c) - 2) >> 2) + 1)
-#define GET_CHILD(p) ((unsigned int)((p) << 2) - 2)
+#define GET_PARENT(c) ((((c) - 2) >> 3) + 1)
+#define GET_CHILD(p) (((p) << 3) - 6)
 
 HEAP_PNT heap_drop(void);
-int sift_up(unsigned int, HEAP_PNT);
+int sift_up(GW_LARGE_INT, HEAP_PNT);
 double get_slope(CELL, CELL, double);
 
 int do_astar(void)
 {
     int r, c, r_nbr, c_nbr, ct_dir;
-    unsigned int first_cum, count;
+    GW_LARGE_INT first_cum, count;
     int nextdr[8] = { 1, -1, 0, 0, -1, 1, 1, -1 };
     int nextdc[8] = { 0, 0, -1, 1, 1, -1, 1, -1 };
     CELL ele_val, ele_up, ele_nbr[8];
@@ -60,12 +60,12 @@
     while (heap_size > 0) {
 	G_percent(count++, n_points, 1);
 	if (count > n_points)
-	    G_fatal_error(_("BUG in A* Search: %d surplus points"),
+	    G_fatal_error(_("BUG in A* Search: %lld surplus points"),
 	                  heap_size);
 
 	if (heap_size > n_points)
 	    G_fatal_error
-		(_("BUG in A* Search: too many points in heap %d, should be %d"),
+		(_("BUG in A* Search: too many points in heap %lld, should be %lld"),
 		 heap_size, n_points);
 
 	heap_p = heap_drop();
@@ -174,9 +174,9 @@
     return 0;
 }
 
-int sift_up(unsigned int start, HEAP_PNT child_p)
+int sift_up(GW_LARGE_INT start, HEAP_PNT child_p)
 {
-    unsigned int parent, child;
+    GW_LARGE_INT parent, child;
     HEAP_PNT heap_p;
 
     child = start;
@@ -205,7 +205,7 @@
  * add item to heap
  * returns heap_size
  */
-unsigned int heap_add(int r, int c, CELL ele)
+GW_LARGE_INT heap_add(int r, int c, CELL ele)
 {
     HEAP_PNT heap_p;
     
@@ -232,8 +232,8 @@
  */
 HEAP_PNT heap_drop(void)
 {
-    unsigned int child, childr, parent;
-    int i;
+    GW_LARGE_INT child, childr, parent;
+    GW_LARGE_INT i;
     HEAP_PNT child_p, childr_p, last_p, root_p;
 
     seg_get(&search_heap, (char *)&last_p, 0, heap_size);
@@ -251,7 +251,7 @@
 
 	if (child < heap_size) {
 	    childr = child + 1;
-	    i = child + 4;
+	    i = child + 8;
 	    while (childr < heap_size && childr < i) {
 		seg_get(&search_heap, (char *)&childr_p, 0, childr);
 		if (heap_cmp(&childr_p, &child_p)) {

Modified: grass-addons/grass7/raster/r.stream.extract/init_search.c
===================================================================
--- grass-addons/grass7/raster/r.stream.extract/init_search.c	2012-04-29 12:06:36 UTC (rev 51569)
+++ grass-addons/grass7/raster/r.stream.extract/init_search.c	2012-04-29 15:28:30 UTC (rev 51570)
@@ -11,7 +11,7 @@
     char flag_value, flag_value_nbr, is_null;
     WAT_ALT wa;
     char asp_value;
-    unsigned int n_depr_cells = 0;
+    GW_LARGE_INT n_depr_cells = 0;
 
     nxt_avail_pt = heap_size = 0;
 
@@ -21,7 +21,7 @@
     else
 	depr_buf = NULL;
 
-    G_message(_("Initialize A* Search..."));
+    G_message(_("Initializing A* Search..."));
     for (r = 0; r < nrows; r++) {
 	G_percent(r, nrows, 2);
 
@@ -114,9 +114,9 @@
 	G_free(depr_buf);
     }
 
-    G_debug(1, "%d edge cells", heap_size - n_depr_cells);
+    G_debug(1, "%lld edge cells", heap_size - n_depr_cells);
     if (n_depr_cells)
-	G_debug(1, "%d cells in depressions", n_depr_cells);
+	G_debug(1, "%lld cells in depressions", n_depr_cells);
 
     return 1;
 }

Modified: grass-addons/grass7/raster/r.stream.extract/load.c
===================================================================
--- grass-addons/grass7/raster/r.stream.extract/load.c	2012-04-29 12:06:36 UTC (rev 51569)
+++ grass-addons/grass7/raster/r.stream.extract/load.c	2012-04-29 15:28:30 UTC (rev 51570)
@@ -29,9 +29,9 @@
     char *flag_value_buf, *aspect;
 
     if (acc_fd < 0)
-	G_message(_("Load elevation map..."));
+	G_message(_("Loading elevation map..."));
     else
-	G_message(_("Load input maps..."));
+	G_message(_("Loading input maps..."));
 
     n_search_points = n_points = 0;
 
@@ -85,16 +85,16 @@
 
 	    /* check for masked and NULL cells */
 	    if (Rast_is_null_value(ptr, ele_map_type)) {
-		if (acc_fd >= 0) {
-		    if (!Rast_is_null_value(acc_ptr, acc_map_type))
-			G_fatal_error(_("Accumulation map does not match elevation map!"));
-		}
 		FLAG_SET(flag_value_buf[c], NULLFLAG);
 		FLAG_SET(flag_value_buf[c], INLISTFLAG);
 		FLAG_SET(flag_value_buf[c], WORKEDFLAG);
 		FLAG_SET(flag_value_buf[c], WORKED2FLAG);
 		Rast_set_c_null_value(&ele_value, 1);
 		/* flow accumulation */
+		if (acc_fd >= 0) {
+		    if (!Rast_is_null_value(acc_ptr, acc_map_type))
+			G_fatal_error(_("Elevation map is NULL but accumulation map is not NULL!"));
+		}
 		Rast_set_d_null_value(&acc_value, 1);
 	    }
 	    else {
@@ -118,7 +118,7 @@
 		else {
 		    if (Rast_is_null_value(acc_ptr, acc_map_type)) {
 			/* can this be ok after weighing ? */
-			G_fatal_error(_("Accumulation map does not match elevation map!"));
+			G_fatal_error(_("Accumulation map is NULL but elevation map is not NULL!"));
 		    }
 
 		    switch (acc_map_type) {
@@ -162,7 +162,7 @@
 	G_free(acc_buf);
     }
     
-    G_debug(1, "%d non-NULL cells", n_points);
+    G_debug(1, "%lld non-NULL cells", n_points);
 
     return n_points;
 }

Modified: grass-addons/grass7/raster/r.stream.extract/local_proto.h
===================================================================
--- grass-addons/grass7/raster/r.stream.extract/local_proto.h	2012-04-29 12:06:36 UTC (rev 51569)
+++ grass-addons/grass7/raster/r.stream.extract/local_proto.h	2012-04-29 15:28:30 UTC (rev 51570)
@@ -6,6 +6,8 @@
 #include "flag.h"
 #include "seg.h"
 
+#define GW_LARGE_INT off_t
+
 #define INDEX(r, c) ((r) * ncols + (c))
 #define MAXDEPTH 1000     /* maximum supported tree depth of stream network */
 
@@ -16,7 +18,7 @@
 
 #define HEAP_PNT    struct heap_point
 HEAP_PNT {
-   unsigned int added;
+   GW_LARGE_INT added;
    CELL ele;
    POINT pnt;
 };
@@ -27,14 +29,7 @@
    DCELL wat;
 };
 
-/* global variables */
-#ifdef MAIN
-#       define GLOBAL
-#else
-#       define GLOBAL extern
-#endif
-
-GLOBAL struct snode
+struct snode
 {
     int r, c;
     int id;
@@ -42,26 +37,28 @@
     int n_trib_total;     /* number of all upstream stream segments */
     int n_alloc;          /* n allocated tributaries */
     int *trib;
-} *stream_node;
+};
 
-GLOBAL int nrows, ncols;
-GLOBAL unsigned int n_search_points, n_points, nxt_avail_pt;
-GLOBAL unsigned int heap_size;
-GLOBAL unsigned int n_stream_nodes, n_alloc_nodes;
-GLOBAL POINT *outlets;
-GLOBAL unsigned int n_outlets, n_alloc_outlets;
-GLOBAL char drain[3][3];
-GLOBAL char sides;
-GLOBAL int c_fac;
-GLOBAL int ele_scale;
-GLOBAL int have_depressions;
+/* extern variables */
+extern struct snode *stream_node;
+extern int nrows, ncols;
+extern GW_LARGE_INT n_search_points, n_points, nxt_avail_pt;
+extern GW_LARGE_INT heap_size;
+extern unsigned int n_stream_nodes, n_alloc_nodes;
+extern POINT *outlets;
+extern unsigned int n_outlets, n_alloc_outlets;
+extern char drain[3][3];
+extern char sides;
+extern int c_fac;
+extern int ele_scale;
+extern int have_depressions;
 
-GLOBAL SSEG search_heap;
-GLOBAL SSEG astar_pts;
-GLOBAL BSEG bitflags;
-GLOBAL SSEG watalt;
-GLOBAL BSEG asp;
-GLOBAL CSEG stream;
+extern SSEG search_heap;
+extern SSEG astar_pts;
+extern BSEG bitflags;
+extern SSEG watalt;
+extern BSEG asp;
+extern CSEG stream;
 
 /* load.c */
 int load_maps(int, int);
@@ -71,7 +68,7 @@
 
 /* do_astar.c */
 int do_astar(void);
-unsigned int heap_add(int, int, CELL);
+GW_LARGE_INT heap_add(int, int, CELL);
 
 /* streams.c */
 int do_accum(double);

Modified: grass-addons/grass7/raster/r.stream.extract/main.c
===================================================================
--- grass-addons/grass7/raster/r.stream.extract/main.c	2012-04-29 12:06:36 UTC (rev 51569)
+++ grass-addons/grass7/raster/r.stream.extract/main.c	2012-04-29 15:28:30 UTC (rev 51570)
@@ -19,13 +19,13 @@
 #include <math.h>
 #include <grass/raster.h>
 #include <grass/glocale.h>
-#define MAIN
 #include "local_proto.h"
 
 /* global variables */
+struct snode *stream_node;
 int nrows, ncols;
-unsigned int n_search_points, n_points, nxt_avail_pt;
-unsigned int heap_size;
+GW_LARGE_INT n_search_points, n_points, nxt_avail_pt;
+GW_LARGE_INT heap_size;
 unsigned int n_stream_nodes, n_alloc_nodes;
 POINT *outlets;
 unsigned int n_outlets, n_alloc_outlets;
@@ -280,19 +280,7 @@
     /* segment structures */
     seg_rows = seg_cols = 64;
     seg2kb = seg_rows * seg_cols / 1024.;
-    /* elevation + accumulation: 12 byte -> 48 KB / segment
-     * aspect: 1 byte -> 4 KB / segment
-     * stream: 4 byte -> 16 KB / segment
-     * flag: 1 byte -> 4 KB / segment
-     * 
-     * Total MB / segment so far: 0.07
-     * 
-     * astar_points: 8 byte -> 32 KB / segment
-     * heap_points: 16 byte -> 64 KB / segment
-     * 
-     * Total MB / segment: 0.16
-     */
-    
+
     /* balance segment files */
     /* elevation + accumulation: * 2 */
     memory_divisor = sizeof(WAT_ALT) * 2;
@@ -333,7 +321,7 @@
 	heap_mem = num_open_segs * seg2kb * sizeof(HEAP_PNT) /
 	           (4. * 1024.);
     }
-    G_verbose_message(_("%.2f of data are kept in memory"),
+    G_verbose_message(_("%.2f%% of data are kept in memory"),
                       100. * num_open_segs / num_seg_total);
     disk_space *= num_seg_total;
     if (disk_space < 1024.0)
@@ -343,7 +331,7 @@
 	           disk_space / 1024.0, disk_space);
 
     /* open segment files */
-    G_verbose_message(_("Create temporary files..."));
+    G_verbose_message(_("Creating temporary files..."));
     seg_open(&watalt, nrows, ncols, seg_rows, seg_cols, num_open_segs * 2,
         sizeof(WAT_ALT), 1);
     if (num_open_segs * 2 > num_seg_total)

Modified: grass-addons/grass7/raster/r.stream.extract/streams.c
===================================================================
--- grass-addons/grass7/raster/r.stream.extract/streams.c	2012-04-29 12:06:36 UTC (rev 51569)
+++ grass-addons/grass7/raster/r.stream.extract/streams.c	2012-04-29 15:28:30 UTC (rev 51570)
@@ -159,7 +159,7 @@
     POINT astarpoint;
     WAT_ALT wa;
 
-    G_message(_("Calculate flow accumulation..."));
+    G_message(_("Calculating flow accumulation..."));
 
     /* distances to neighbours */
     dist_to_nbr = (double *)G_malloc(sides * sizeof(double));
@@ -391,14 +391,14 @@
      *  | 2 |   | 3 |
      *  | 5 | 0 | 6 |
      */
-    unsigned int workedon, killer, count;
+    GW_LARGE_INT workedon, killer, count;
     int stream_no = 0, stream_node_step = 1000;
     double slope, diag;
     char *flag_nbr, this_flag_value;
     POINT astarpoint;
     WAT_ALT wa;
 
-    G_message(_("Extract streams..."));
+    G_message(_("Extracting streams..."));
 
     /* init stream nodes */
     n_alloc_nodes = stream_node_step;
@@ -714,7 +714,7 @@
     }
     G_percent(1, 1, 2);
     if (workedon)
-	G_warning(_("MFD: A * path already processed when setting drainage direction: %d of %d cells"),
+	G_warning(_("MFD: A * path already processed when setting drainage direction: %lld of %lld cells"),
 		  workedon, n_points);
 
     G_free(dist_to_nbr);

Modified: grass-addons/grass7/raster/r.stream.extract/thin.c
===================================================================
--- grass-addons/grass7/raster/r.stream.extract/thin.c	2012-04-29 12:06:36 UTC (rev 51569)
+++ grass-addons/grass7/raster/r.stream.extract/thin.c	2012-04-29 15:28:30 UTC (rev 51570)
@@ -80,7 +80,7 @@
     int n_trib_total;
     int n_thinned = 0;
 
-    G_message(_("Thin stream segments..."));
+    G_message(_("Thinning stream segments..."));
 
     nodestack = (struct sstack *)G_malloc(stack_step * sizeof(struct sstack));
 



More information about the grass-commit mailing list