[GRASS-SVN] r71992 - grass/trunk/raster/r.fill.dir

svn_grass at osgeo.org svn_grass at osgeo.org
Thu Dec 28 13:27:36 PST 2017


Author: mmetz
Date: 2017-12-28 13:27:36 -0800 (Thu, 28 Dec 2017)
New Revision: 71992

Modified:
   grass/trunk/raster/r.fill.dir/filldir.c
   grass/trunk/raster/r.fill.dir/main.c
   grass/trunk/raster/r.fill.dir/tinf.c
   grass/trunk/raster/r.fill.dir/tinf.h
Log:
r.fill.dir: fix comiler warnings, fix types for read/write

Modified: grass/trunk/raster/r.fill.dir/filldir.c
===================================================================
--- grass/trunk/raster/r.fill.dir/filldir.c	2017-12-28 21:26:07 UTC (rev 71991)
+++ grass/trunk/raster/r.fill.dir/filldir.c	2017-12-28 21:27:36 UTC (rev 71992)
@@ -78,9 +78,10 @@
 /* determine the flow direction at each cell on one row */
 void build_one_row(int i, int nl, int ns, struct band3 *bnd, CELL * dir)
 {
-    int j, offset, inc;
+    int j, inc;
+    size_t offset;
     CELL sdir;
-    double slope;
+    double curslope;
     char *center;
     char *edge;
 
@@ -95,7 +96,7 @@
 	}
 
 	sdir = 0;
-	slope = HUGE_VAL;
+	curslope = HUGE_VAL;
 	if (i == 0) {
 	    sdir = 128;
 	}
@@ -109,28 +110,28 @@
 	    sdir = 2;
 	}
 	else {
-	    slope = -HUGE_VAL;
+	    curslope = -HUGE_VAL;
 
 	    /* check one row back */
 	    edge = bnd->b[0] + offset;
-	    check(64, &sdir, center, edge - inc, 1.4142136, &slope);
-	    check(128, &sdir, center, edge, 1., &slope);
-	    check(1, &sdir, center, edge + inc, 1.4142136, &slope);
+	    check(64, &sdir, center, edge - inc, 1.4142136, &curslope);
+	    check(128, &sdir, center, edge, 1., &curslope);
+	    check(1, &sdir, center, edge + inc, 1.4142136, &curslope);
 
 	    /* check this row */
-	    check(32, &sdir, center, center - inc, 1., &slope);
-	    check(2, &sdir, center, center + inc, 1., &slope);
+	    check(32, &sdir, center, center - inc, 1., &curslope);
+	    check(2, &sdir, center, center + inc, 1., &curslope);
 
 	    /* check one row forward */
 	    edge = bnd->b[2] + offset;
-	    check(16, &sdir, center, edge - inc, 1.4142136, &slope);
-	    check(8, &sdir, center, edge, 1., &slope);
-	    check(4, &sdir, center, edge + inc, 1.4142136, &slope);
+	    check(16, &sdir, center, edge - inc, 1.4142136, &curslope);
+	    check(8, &sdir, center, edge, 1., &curslope);
+	    check(4, &sdir, center, edge + inc, 1.4142136, &curslope);
 	}
 
-	if (slope == 0.)
+	if (curslope == 0.)
 	    sdir = -sdir;
-	else if (slope < 0.)
+	else if (curslope < 0.)
 	    sdir = -256;
 	dir[j] = sdir;
     }
@@ -139,7 +140,8 @@
 
 void filldir(int fe, int fd, int nl, struct band3 *bnd)
 {
-    int i, bufsz;
+    int i;
+    size_t bufsz;
     CELL *dir;
 
     /* fill single-cell depressions, except on outer rows and columns */
@@ -154,12 +156,14 @@
 	    write(fe, bnd->b[1], bnd->sz);
 	}
     }
+    /* why on the last row? it's an outer row */
+#if 0
     advance_band3(0, bnd);
     if (fill_row(nl, bnd->ns, bnd)) {
 	lseek(fe, (off_t) i * bnd->sz, SEEK_SET);
 	write(fe, bnd->b[1], bnd->sz);
     }
-
+#endif
     /* determine the flow direction in each cell.  On outer rows and columns
      * the flow direction is always directly out of the map */
 
@@ -174,9 +178,12 @@
 	build_one_row(i, nl, bnd->ns, bnd, dir);
 	write(fd, dir, bufsz);
     }
+    /* why this extra row ? */
+#if 0
     advance_band3(fe, bnd);
     build_one_row(i, nl, bnd->ns, bnd, dir);
     write(fd, dir, bufsz);
+#endif
 
     G_free(dir);
 

Modified: grass/trunk/raster/r.fill.dir/main.c
===================================================================
--- grass/trunk/raster/r.fill.dir/main.c	2017-12-28 21:26:07 UTC (rev 71991)
+++ grass/trunk/raster/r.fill.dir/main.c	2017-12-28 21:27:36 UTC (rev 71992)
@@ -68,12 +68,14 @@
     const char *tempfile1, *tempfile2, *tempfile3;
     char dir_name[GNAME_MAX];
     char bas_name[GNAME_MAX];
+    struct History history;
 
     struct Cell_head window;
     struct GModule *module;
     struct Option *opt1, *opt2, *opt3, *opt4, *opt5;
     struct Flag *flag1;
-    int in_type, bufsz;
+    int in_type;
+    size_t bufsz;
     void *in_buf;
     CELL *out_buf;
     struct band3 bnd, bndC;
@@ -247,8 +249,12 @@
 	}
 
 	Rast_close(bas_id);
-	close(fm);
+
+	Rast_short_history(bas_name, "raster", &history);
+	Rast_command_history(&history);
+	Rast_write_history(bas_name, &history);
     }
+    close(fm);
 
     G_important_message(_("Writing output raster maps..."));
     for (i = 0; i < nrows; i++) {
@@ -269,9 +275,15 @@
     Rast_write_colors(new_map_name, G_mapset(), &colors);
 
     Rast_close(new_id);
+    Rast_short_history(new_map_name, "raster", &history);
+    Rast_command_history(&history);
+    Rast_write_history(new_map_name, &history);
     close(fe);
     
     Rast_close(dir_id);
+    Rast_short_history(dir_name, "raster", &history);
+    Rast_command_history(&history);
+    Rast_write_history(dir_name, &history);
     close(fd);
 
     unlink(tempfile1);

Modified: grass/trunk/raster/r.fill.dir/tinf.c
===================================================================
--- grass/trunk/raster/r.fill.dir/tinf.c	2017-12-28 21:26:07 UTC (rev 71991)
+++ grass/trunk/raster/r.fill.dir/tinf.c	2017-12-28 21:27:36 UTC (rev 71992)
@@ -11,7 +11,7 @@
  * The actual functions follow. */
 
 int (*is_null) (void *);
-int (*bpe) ();
+size_t (*bpe) ();
 void *(*get_max) (void *, void *);
 void *(*get_min) (void *, void *);
 void (*get_row) (int, void *, int);
@@ -100,17 +100,17 @@
 }
 
 /* return the size of the current type */
-int bpe_c()
+size_t bpe_c()
 {
     return sizeof(CELL);
 }
 
-int bpe_f()
+size_t bpe_f()
 {
     return sizeof(FCELL);
 }
 
-int bpe_d()
+size_t bpe_d()
 {
     return sizeof(DCELL);
 }
@@ -210,17 +210,17 @@
 }
 
 /* Allocate memory for one line of data */
-void *get_buf_c()
+void *get_buf_c(void)
 {
     return (void *)Rast_allocate_c_buf();
 }
 
-void *get_buf_f()
+void *get_buf_f(void)
 {
     return (void *)Rast_allocate_f_buf();
 }
 
-void *get_buf_d()
+void *get_buf_d(void)
 {
     return (void *)Rast_allocate_d_buf();
 }

Modified: grass/trunk/raster/r.fill.dir/tinf.h
===================================================================
--- grass/trunk/raster/r.fill.dir/tinf.h	2017-12-28 21:26:07 UTC (rev 71991)
+++ grass/trunk/raster/r.fill.dir/tinf.h	2017-12-28 21:27:36 UTC (rev 71992)
@@ -13,9 +13,9 @@
 int is_null_f(void *);
 int is_null_d(void *);
 
-int bpe_c();
-int bpe_f();
-int bpe_d();
+size_t bpe_c();
+size_t bpe_f();
+size_t bpe_d();
 
 void *get_min_c(void *, void *);
 void *get_min_f(void *, void *);
@@ -33,9 +33,9 @@
 void put_row_f(int, void *);
 void put_row_d(int, void *);
 
-void *get_buf_c();
-void *get_buf_f();
-void *get_buf_d();
+void *get_buf_c(void);
+void *get_buf_f(void);
+void *get_buf_d(void);
 
 void set_min_c(void *);
 void set_min_f(void *);
@@ -66,7 +66,7 @@
  * its argument list to the list below */
 
 extern int (*is_null) (void *);
-extern int (*bpe) ();
+extern size_t (*bpe) ();
 extern void *(*get_max) (void *, void *);
 extern void *(*get_min) (void *, void *);
 extern void (*get_row) (int, void *, int);
@@ -89,7 +89,7 @@
 struct band3
 {
     int ns;			/* samples per line */
-    int sz;			/* bytes per line */
+    size_t sz;			/* bytes per line */
     char *b[3];			/* pointers to start of each line */
 };
 



More information about the grass-commit mailing list