瀏覽代碼

r.null: fix recreate and remove NULL file

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@70338 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 8 年之前
父節點
當前提交
4e84ce8fda
共有 1 個文件被更改,包括 21 次插入3 次删除
  1. 21 3
      raster/r.null/main.c

+ 21 - 3
raster/r.null/main.c

@@ -196,8 +196,26 @@ int main(int argc, char *argv[])
     }
     }
 
 
     if (recreate) {
     if (recreate) {
+	/* (un-)compress NULL file */
 	int in_fd;
 	int in_fd;
-	/* write a file of no-nulls */
+	char *nullcompr = getenv("GRASS_COMPRESS_NULLS");
+        int donullcompr = (nullcompr && atoi(nullcompr)) ? 1 : 0;
+
+	G_debug(1, "NULL compression is currently %s", donullcompr ? "enabled" : "disabled");
+
+	if (donullcompr) {
+	    if (G_find_file2_misc("cell_misc", "nullcmpr", name, mapset)) {
+		G_message(_("The NULL file is already compressed, nothing to do."));
+		exit(EXIT_SUCCESS);
+	    }
+	}
+	else {
+	    if (G_find_file2_misc("cell_misc", "null", name, mapset)) {
+		G_message(_("The NULL file is already uncompressed, nothing to do."));
+		exit(EXIT_SUCCESS);
+	    }
+	}
+
 	null_bits = Rast__allocate_null_bits(cellhd.cols);
 	null_bits = Rast__allocate_null_bits(cellhd.cols);
 	Rast__init_null_bits(null_bits, cellhd.cols);
 	Rast__init_null_bits(null_bits, cellhd.cols);
 
 
@@ -223,12 +241,12 @@ int main(int argc, char *argv[])
     }
     }
 
 
     if (remove) {
     if (remove) {
-	/* write a file of no-nulls */
+	/* remove NULL file */
 	G_verbose_message(_("Removing null file for raster map <%s>..."),
 	G_verbose_message(_("Removing null file for raster map <%s>..."),
 			   name);
 			   name);
 	G_file_name_misc(path, "cell_misc", "null", name, mapset);
 	G_file_name_misc(path, "cell_misc", "null", name, mapset);
 	unlink(path);
 	unlink(path);
-	G_file_name_misc(path, "cell_misc", "null2", name, mapset);
+	G_file_name_misc(path, "cell_misc", "nullcmpr", name, mapset);
 	unlink(path);
 	unlink(path);
 
 
 	G_done_msg(_("Raster map <%s> modified."), name);
 	G_done_msg(_("Raster map <%s> modified."), name);