[GRASS-SVN] r65489 - in grass/trunk: include/defs lib/raster raster/r.null raster/r.support

svn_grass at osgeo.org svn_grass at osgeo.org
Tue Jun 16 16:09:08 PDT 2015


Author: glynn
Date: 2015-06-16 16:09:08 -0700 (Tue, 16 Jun 2015)
New Revision: 65489

Modified:
   grass/trunk/include/defs/raster.h
   grass/trunk/lib/raster/put_row.c
   grass/trunk/raster/r.null/main.c
   grass/trunk/raster/r.support/main.c
Log:
Clean up compressed null support
Fix r.null, r.support to handle compressed nulls


Modified: grass/trunk/include/defs/raster.h
===================================================================
--- grass/trunk/include/defs/raster.h	2015-06-16 21:13:31 UTC (rev 65488)
+++ grass/trunk/include/defs/raster.h	2015-06-16 23:09:08 UTC (rev 65489)
@@ -465,7 +465,7 @@
 void Rast_put_c_row(int, const CELL *);
 void Rast_put_f_row(int, const FCELL *);
 void Rast_put_d_row(int, const DCELL *);
-void Rast__write_null_bits(int, const unsigned char *, int, int, int);
+void Rast__write_null_bits(int, const unsigned char *);
 
 /* put_title.c */
 int Rast_put_cell_title(const char *, const char *);

Modified: grass/trunk/lib/raster/put_row.c
===================================================================
--- grass/trunk/lib/raster/put_row.c	2015-06-16 21:13:31 UTC (rev 65488)
+++ grass/trunk/lib/raster/put_row.c	2015-06-16 23:09:08 UTC (rev 65489)
@@ -481,52 +481,42 @@
 	put_fp_data(fd, null_buf, rast, row, n, map_type);
 }
 
-static void put_null_data(int fd, const char *flags, int row)
+static void put_null_value_row(int fd, const char *flags)
 {
     struct fileinfo *fcb = &R__.fileinfo[fd];
 
+    if (fcb->gdal)
+	G_fatal_error(_("GDAL output doesn't support writing null rows separately"));
+
     if (fcb->null_fd < 0)
 	G_fatal_error(_("No null file for <%s>"), fcb->name);
 
     Rast__convert_01_flags(flags, fcb->null_bits,
 			   fcb->cellhd.cols);
 
-    Rast__write_null_bits(fcb->null_fd, fcb->null_bits, row,
-			  fcb->cellhd.cols, fd);
+    Rast__write_null_bits(fd, fcb->null_bits);
 }
 
-static void put_null_value_row(int fd, const char *buf)
+static void write_null_bits_compressed(const unsigned char *flags,
+				       int row, size_t size, int fd)
 {
     struct fileinfo *fcb = &R__.fileinfo[fd];
-
-    if (fcb->gdal)
-	G_fatal_error(_("GDAL output doesn't support writing null rows separately"));
-
-    put_null_data(fd, buf, fcb->null_cur_row);
-
-    fcb->null_cur_row++;
-}
-
-static void write_null_bits_compressed(int null_fd, const unsigned char *flags,
-				int row, size_t size, int fd)
-{
-    struct fileinfo *fcb = &R__.fileinfo[fd];
     unsigned char *compressed_buf;
     ssize_t nwrite;
 
-    fcb->null_row_ptr[row] = lseek(null_fd, 0L, SEEK_CUR);
+    fcb->null_row_ptr[row] = lseek(fcb->null_fd, 0L, SEEK_CUR);
 
     compressed_buf = G_alloca(size + 1);
 
     nwrite = G_zlib_compress(flags, size, compressed_buf, size);
 
     if (nwrite < size) {
-	if (write(null_fd, compressed_buf, nwrite) != nwrite)
+	if (write(fcb->null_fd, compressed_buf, nwrite) != nwrite)
 	    G_fatal_error(_("Error writing compressed null data for row %d of <%s>"),
 			  row, fcb->name);
     }
     else {
-	if (write(null_fd, flags, size) != size)
+	if (write(fcb->null_fd, flags, size) != size)
 	    G_fatal_error(_("Error writing compressed null data for row %d of <%s>"),
 			  row, fcb->name);
     }
@@ -537,7 +527,6 @@
 /*!
    \brief Write null data
 
-   \param null_fd file descriptor of null file where data is to be written
    \param flags ?
    \param row row number
    \param col col number
@@ -545,26 +534,26 @@
 
    \return void
  */
-void Rast__write_null_bits(int null_fd, const unsigned char *flags, int row,
-			   int cols, int fd)
+void Rast__write_null_bits(int fd, const unsigned char *flags)
 {
     struct fileinfo *fcb = &R__.fileinfo[fd];
+    int row = fcb->null_cur_row++;
     off_t offset;
     size_t size;
 
-    size = Rast__null_bitstream_size(cols);
+    size = Rast__null_bitstream_size(fcb->cellhd.cols);
 
     if (fcb->null_row_ptr) {
-	write_null_bits_compressed(null_fd, flags, row, size, fd);
+	write_null_bits_compressed(flags, row, size, fd);
 	return;
     }
 
-    offset = (off_t) size *row;
+    offset = (off_t) size * row;
 
-    if (lseek(null_fd, offset, SEEK_SET) < 0)
+    if (lseek(fcb->null_fd, offset, SEEK_SET) < 0)
 	G_fatal_error(_("Error writing null row %d of <%s>"), row, fcb->name);
 
-    if (write(null_fd, flags, size) != size)
+    if (write(fcb->null_fd, flags, size) != size)
 	G_fatal_error(_("Error writing null row %d of <%s>"), row, fcb->name);
 }
 

Modified: grass/trunk/raster/r.null/main.c
===================================================================
--- grass/trunk/raster/r.null/main.c	2015-06-16 21:13:31 UTC (rev 65488)
+++ grass/trunk/raster/r.null/main.c	2015-06-16 23:09:08 UTC (rev 65489)
@@ -31,7 +31,7 @@
     const char *name, *mapset;
     char rname[GNAME_MAX], rmapset[GMAPSET_MAX];
     char path[GPATH_MAX];
-    int row, col, null_fd;
+    int row, col, fd;
     unsigned char *null_bits;
     RASTER_MAP_TYPE map_type;
     int change_null = 0, create, remove, only_int, only_fp, only_null;
@@ -170,17 +170,17 @@
 	for (col = 0; col < Rast__null_bitstream_size(cellhd.cols); col++)
 	    null_bits[col] = 0;
 
-	null_fd = G_open_new_misc("cell_misc", "null", name);
+	fd = Rast__open_null_write(name);
 
 	G_verbose_message(_("Writing new null file for raster map <%s>..."),
 			  name);
 
 	for (row = 0; row < cellhd.rows; row++) {
 	    G_percent(row, cellhd.rows, 1);
-	    Rast__write_null_bits(null_fd, null_bits, row, cellhd.cols, 0);
+	    Rast__write_null_bits(fd, null_bits);
 	}
 	G_percent(row, cellhd.rows, 1);
-	close(null_fd);
+	Rast__close_null(fd);
 
 	G_done_msg(_("Raster map <%s> modified."), name);
 
@@ -191,9 +191,10 @@
 	/* write a file of no-nulls */
 	G_verbose_message(_("Removing null file for raster map <%s>..."),
 			   name);
-	null_fd = G_open_new_misc("cell_misc", "null", name);
 	G_file_name_misc(path, "cell_misc", "null", name, mapset);
 	unlink(path);
+	G_file_name_misc(path, "cell_misc", "null2", name, mapset);
+	unlink(path);
 
 	G_done_msg(_("Raster map <%s> modified."), name);
 

Modified: grass/trunk/raster/r.support/main.c
===================================================================
--- grass/trunk/raster/r.support/main.c	2015-06-16 21:13:31 UTC (rev 65488)
+++ grass/trunk/raster/r.support/main.c	2015-06-16 23:09:08 UTC (rev 65489)
@@ -271,7 +271,7 @@
     if (null_flag->answer) {
 	unsigned char *null_bits;
 	int row, col;
-	int null_fd;
+	int fd;
 
 	if (is_reclass)
 	    G_fatal_error(_("[%s] is a reclass of another map. Exiting."),
@@ -283,22 +283,21 @@
 	    null_bits[col] = 0;
 
 	/* Open null file for writing */
-	null_fd = G_open_new_misc("cell_misc", "null", raster->answer);
+	fd = Rast__open_null_write(raster->answer);
 
 	G_message(_("Writing new null file for [%s]... "), raster->answer);
 	for (row = 0; row < cellhd.rows; row++) {
 	    G_percent(row, cellhd.rows, 1);
-	    Rast__write_null_bits(null_fd, null_bits, row, cellhd.cols, 0);
+	    Rast__write_null_bits(fd, null_bits);
 	}
 	G_percent(row, cellhd.rows, 1);
 
 	/* Cleanup */
-	close(null_fd);
+	Rast__close_null(fd);
 	G_free(null_bits);
     }
 
     if (del_flag->answer) {
-	int null_fd;
 	char path[GPATH_MAX];
 
 	if (is_reclass)
@@ -308,10 +307,10 @@
 	/* Write a file of no-nulls */
 	G_message(_("Removing null file for [%s]...\n"), raster->answer);
 
-	null_fd = G_open_new_misc("cell_misc", "null", raster->answer);
 	G_file_name_misc(path, "cell_misc", "null", raster->answer, G_mapset());
 	unlink(path);
-	close(null_fd);
+	G_file_name_misc(path, "cell_misc", "null2", raster->answer, G_mapset());
+	unlink(path);
 
 	G_done_msg(_("Done."));
     }



More information about the grass-commit mailing list