[GRASS-SVN] r70337 - grass/trunk/raster/r.compress
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Jan 11 01:24:59 PST 2017
Author: mmetz
Date: 2017-01-11 01:24:59 -0800 (Wed, 11 Jan 2017)
New Revision: 70337
Modified:
grass/trunk/raster/r.compress/main.c
grass/trunk/raster/r.compress/r.compress.html
Log:
r.compress: add shell-style output, add info about NULL file compression
Modified: grass/trunk/raster/r.compress/main.c
===================================================================
--- grass/trunk/raster/r.compress/main.c 2017-01-11 03:27:04 UTC (rev 70336)
+++ grass/trunk/raster/r.compress/main.c 2017-01-11 09:24:59 UTC (rev 70337)
@@ -37,6 +37,7 @@
*****************************************************************************/
#include <stdlib.h>
+#include <stdio.h>
#include <limits.h>
#include <string.h>
#include <sys/types.h>
@@ -46,9 +47,12 @@
#include <grass/glocale.h>
static int process(char *, int);
-static int pprint(char *);
+static int pprint(char *, int);
static int doit(char *, int, RASTER_MAP_TYPE);
+/* compressed null file, see lib/raster/open.c */
+#define NULLC_FILE "nullcmpr"
+
int main(int argc, char *argv[])
{
int stat;
@@ -56,7 +60,7 @@
char *name;
struct GModule *module;
struct Option *map;
- struct Flag *uncompress, *pflag;
+ struct Flag *uncompress, *pflag, *gflag;
G_gisinit(argv[0]);
@@ -77,12 +81,16 @@
pflag->key = 'p';
pflag->description = _("Print compression information and data type of input map(s)");
+ gflag = G_define_flag();
+ gflag->key = 'g';
+ gflag->description = _("Print compression information in shell script style");
+
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
- if (pflag->answer) {
+ if (pflag->answer || gflag->answer) {
for (n = 0; (name = map->answers[n]); n++)
- pprint(name);
+ pprint(name, gflag->answer);
exit(EXIT_SUCCESS);
}
@@ -284,7 +292,7 @@
}
-static int pprint(char *name)
+static int pprint(char *name, int shell_style)
{
struct Cell_head cellhd;
char rname[GNAME_MAX], rmapset[GMAPSET_MAX];
@@ -323,19 +331,41 @@
if (cellhd.compressed == 1 && map_type != CELL_TYPE)
cellhd.compressed = 2;
- if (cellhd.compressed == 0) {
- G_message(_("<%s> is uncompressed (method %i: %s). Data type: %s"), name, cellhd.compressed,
- "NONE",
- (map_type == CELL_TYPE ? "CELL" :
- (map_type == DCELL_TYPE ? "DCELL" :
- (map_type == FCELL_TYPE ? "FCELL" : "??"))));
+ if (!shell_style) {
+ if (cellhd.compressed == 0) {
+ G_message(_("<%s> is uncompressed (method %i: %s). Data type: %s"), name, cellhd.compressed,
+ "NONE",
+ (map_type == CELL_TYPE ? "CELL" :
+ (map_type == DCELL_TYPE ? "DCELL" :
+ (map_type == FCELL_TYPE ? "FCELL" : "??"))));
+ }
+ else if (cellhd.compressed > 0) {
+ G_message(_("<%s> is compressed (method %i: %s). Data type: %s"), name, cellhd.compressed,
+ G_compressor_name(cellhd.compressed),
+ (map_type == CELL_TYPE ? "CELL" :
+ (map_type == DCELL_TYPE ? "DCELL" :
+ (map_type == FCELL_TYPE ? "FCELL" : "??"))));
+ }
+
+ if (G_find_file2_misc("cell_misc", NULLC_FILE, name, G_mapset())) {
+ G_message(_("<%s> has a compressed NULL file"), name);
+ } else {
+ G_message(_("<%s> has an uncompressed NULL file"), name);
+ }
}
- else if (cellhd.compressed > 0) {
- G_message(_("<%s> is compressed (method %i: %s). Data type: %s"), name, cellhd.compressed,
- G_compressor_name(cellhd.compressed),
- (map_type == CELL_TYPE ? "CELL" :
- (map_type == DCELL_TYPE ? "DCELL" :
- (map_type == FCELL_TYPE ? "FCELL" : "??"))));
+ else {
+ fprintf(stdout, "%s|%s", name,
+ (map_type == CELL_TYPE ? "CELL" :
+ (map_type == DCELL_TYPE ? "DCELL" :
+ (map_type == FCELL_TYPE ? "FCELL" : "??"))));
+ if (cellhd.compressed == 0)
+ fprintf(stdout, "|NONE");
+ else
+ fprintf(stdout, "|%s", G_compressor_name(cellhd.compressed));
+ if (G_find_file2_misc("cell_misc", NULLC_FILE, name, G_mapset()))
+ fprintf(stdout, "|YES\n");
+ else
+ fprintf(stdout, "|NO\n");
}
return 0;
Modified: grass/trunk/raster/r.compress/r.compress.html
===================================================================
--- grass/trunk/raster/r.compress/r.compress.html 2017-01-11 03:27:04 UTC (rev 70336)
+++ grass/trunk/raster/r.compress/r.compress.html 2017-01-11 09:24:59 UTC (rev 70337)
@@ -47,6 +47,14 @@
module simply informs the user that the map is already decompressed and
exits.
+<p>
+Information about the compression method and data type of the input
+raster map(s) can be printed in shell style with the <b>-g</b> flag. In
+this case, the module prints to <tt>stdout</tt> one line per input map
+with the fields "input map name", "data type",
+"name of data compression method", "NULL file
+compression" separated by the pipe character. NULL file
+compression is indicated with "YES" or "NO".
<h3>TERMINOLOGY</h3>
More information about the grass-commit
mailing list