[GRASS-SVN] r43539 - grass/trunk/raster/r.surf.contour

svn_grass at osgeo.org svn_grass at osgeo.org
Mon Sep 20 13:03:03 EDT 2010


Author: mmetz
Date: 2010-09-20 17:03:02 +0000 (Mon, 20 Sep 2010)
New Revision: 43539

Modified:
   grass/trunk/raster/r.surf.contour/contour.h
   grass/trunk/raster/r.surf.contour/find_con.c
   grass/trunk/raster/r.surf.contour/main.c
   grass/trunk/raster/r.surf.contour/read_cell.c
Log:
add fp and NULL (nodata) support

Modified: grass/trunk/raster/r.surf.contour/contour.h
===================================================================
--- grass/trunk/raster/r.surf.contour/contour.h	2010-09-20 17:01:22 UTC (rev 43538)
+++ grass/trunk/raster/r.surf.contour/contour.h	2010-09-20 17:03:02 UTC (rev 43539)
@@ -24,7 +24,7 @@
 extern int maxr;
 extern int array_size;
 extern double i_val_l_f;
-extern CELL **con;
+extern DCELL **con;
 extern FLAG *seen, *mask;
 extern NODE *zero;
 
@@ -35,8 +35,8 @@
 NODE *addpts(NODE *, int, int, int, int, int *);
 
 /* find_con.c */
-int find_con(int, int, double *, double *, CELL *, CELL *);
+int find_con(int, int, double *, double *, DCELL *, DCELL *);
 
 /* read_cell.c */
-CELL **read_cell(const char *);
-void free_cell(CELL **);
+DCELL **read_cell(const char *);
+void free_cell(DCELL **);

Modified: grass/trunk/raster/r.surf.contour/find_con.c
===================================================================
--- grass/trunk/raster/r.surf.contour/find_con.c	2010-09-20 17:01:22 UTC (rev 43538)
+++ grass/trunk/raster/r.surf.contour/find_con.c	2010-09-20 17:03:02 UTC (rev 43539)
@@ -1,15 +1,18 @@
 #include <math.h>
 #include "contour.h"
 
-int find_con(int r, int c, double *d1, double *d2, CELL * con1, CELL * con2)
+int find_con(int r, int c, double *d1, double *d2, DCELL * con1, DCELL * con2)
 {
     int ct, low_ct, node_ct;
     int rr, cc, dor, doc;
     double dd, shortest;
-    CELL value;
+    DCELL value;
 
-    *con1 = 0;
+/*    *con1 = 0;
     *con2 = 0;
+*/
+    Rast_set_d_null_value(con1, 1);
+    Rast_set_d_null_value(con2, 1);
     *d1 = *d2 = 1.0;
     shortest = nrows * ncols;
     for (rr = minr; rr <= maxr; rr++) {
@@ -42,9 +45,9 @@
 	if (rr >= 0 && cc >= 0 && rr < nrows && cc < ncols
 	    && zero[ct].d < shortest && !flag_get(mask, rr, cc)) {
 	    value = con[rr][cc];
-	    if (value == 0)
+	    if (Rast_is_d_null_value(&value))
 		zero = addpts(zero, r, c, rr, cc, &node_ct);
-	    else if (*con1 == 0) {
+	    else if (Rast_is_d_null_value(con1)) {
 		*con1 = value;
 		*d1 = MIN(dor, doc) * 1.414 + ABS(dor - doc);
 		shortest = *d1 * 2.0 * i_val_l_f;
@@ -56,7 +59,7 @@
 		    shortest = dd * 2.0 * i_val_l_f;
 		}
 	    }
-	    else if (*con2 == 0) {
+	    else if (Rast_is_d_null_value(con2)) {
 		*con2 = value;
 		*d2 = MIN(dor, doc) * 1.414 + ABS(dor - doc);
 		shortest = *d2;

Modified: grass/trunk/raster/r.surf.contour/main.c
===================================================================
--- grass/trunk/raster/r.surf.contour/main.c	2010-09-20 17:01:22 UTC (rev 43538)
+++ grass/trunk/raster/r.surf.contour/main.c	2010-09-20 17:03:02 UTC (rev 43539)
@@ -36,19 +36,19 @@
 int maxr;
 int array_size;
 double i_val_l_f;
-CELL **con;
+DCELL **con;
 FLAG *seen, *mask;
 NODE *zero;
 
 int main(int argc, char *argv[])
 {
     int r, c;
-    CELL con1, con2;
+    DCELL con1, con2;
     double d1, d2;
-    CELL *alt_row;
+    DCELL *alt_row;
     const char *con_name, *alt_name;
     int file_fd;
-    CELL value;
+    DCELL value;
     struct History history;
     struct GModule *module;
     struct Option *opt1, *opt2;
@@ -77,15 +77,15 @@
     ncols = Rast_window_cols();
     i_val_l_f = nrows + ncols;
     con = read_cell(con_name);
-    alt_row = (CELL *) G_malloc(ncols * sizeof(CELL));
+    alt_row = (DCELL *) G_malloc(ncols * sizeof(DCELL));
     seen = flag_create(nrows, ncols);
     mask = flag_create(nrows, ncols);
     if (NULL != G_find_file("cell", "MASK", G_mapset())) {
 	file_fd = Rast_open_old("MASK", G_mapset());
 	for (r = 0; r < nrows; r++) {
-	    Rast_get_c_row_nomask(file_fd, alt_row, r);
+	    Rast_get_d_row_nomask(file_fd, alt_row, r);
 	    for (c = 0; c < ncols; c++)
-		if (!alt_row[c])
+		if (Rast_is_d_null_value(&(alt_row[c])))
 		    FLAG_SET(mask, r, c);
 	}
 	Rast_close(file_fd);
@@ -95,25 +95,25 @@
     maxc = ncols - 1;
     maxr = nrows - 1;
     array_size = INIT_AR;
-    file_fd = Rast_open_c_new(alt_name);
+    file_fd = Rast_open_new(alt_name, DCELL_TYPE);
     for (r = 0; r < nrows; r++) {
 	G_percent(r, nrows, 1);
 	for (c = 0; c < ncols; c++) {
 	    if (FLAG_GET(mask, r, c))
 		continue;
 	    value = con[r][c];
-	    if (value != 0) {
+	    if (!Rast_is_d_null_value(&value)) {
 		alt_row[c] = value;
 		continue;
 	    }
 	    find_con(r, c, &d1, &d2, &con1, &con2);
 	    if (con2 > 0)
-		alt_row[c] = (CELL) (d2 * con1 / (d1 + d2) +
-				     d1 * con2 / (d1 + d2) + 0.5);
+		alt_row[c] = (DCELL) (d2 * con1 / (d1 + d2) +
+				     d1 * con2 / (d1 + d2) /* + 0.5 */);
 	    else
 		alt_row[c] = con1;
 	}
-	Rast_put_row(file_fd, alt_row, CELL_TYPE);
+	Rast_put_row(file_fd, alt_row, DCELL_TYPE);
     }
     G_percent(1, 1, 1);
     

Modified: grass/trunk/raster/r.surf.contour/read_cell.c
===================================================================
--- grass/trunk/raster/r.surf.contour/read_cell.c	2010-09-20 17:01:22 UTC (rev 43538)
+++ grass/trunk/raster/r.surf.contour/read_cell.c	2010-09-20 17:03:02 UTC (rev 43539)
@@ -2,23 +2,23 @@
 #include <grass/raster.h>
 #include <grass/glocale.h>
 
-CELL **read_cell(const char *name)
+DCELL **read_cell(const char *name)
 {
     int nrows = Rast_window_rows();
     int ncols = Rast_window_cols();
-    CELL *buf, **idx;
+    DCELL *buf, **idx;
     int fd;
     int row;
 
     fd = Rast_open_old(name, "");
     
-    buf = G_malloc((size_t) nrows * ncols * sizeof(CELL));
-    idx = G_malloc(nrows * sizeof(CELL *));
+    buf = G_malloc((size_t) nrows * ncols * sizeof(DCELL));
+    idx = G_malloc(nrows * sizeof(DCELL *));
     
     for (row = 0; row < nrows; row++) {
 	idx[row] = &buf[row * ncols];
 
-	Rast_get_c_row(fd, idx[row], row);
+	Rast_get_d_row(fd, idx[row], row);
     }
     
     Rast_close(fd);
@@ -26,7 +26,7 @@
     return idx;
 }
 
-void free_cell(CELL **idx)
+void free_cell(DCELL **idx)
 {
     G_free(idx[0]);
     G_free(idx);



More information about the grass-commit mailing list