summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorPedro Vicente Nunes <pvn@hdfgroup.org>2008-02-12 21:16:29 (GMT)
committerPedro Vicente Nunes <pvn@hdfgroup.org>2008-02-12 21:16:29 (GMT)
commit51dd31c33294e2b81ccd1427e101437798f3e42c (patch)
tree5cc19a9d3c7ed5739cd6ed6578d1caa320b18cfc /tools
parent2f69871352b89bb99646a56d0e765829cbd8d527 (diff)
downloadhdf5-51dd31c33294e2b81ccd1427e101437798f3e42c.zip
hdf5-51dd31c33294e2b81ccd1427e101437798f3e42c.tar.gz
hdf5-51dd31c33294e2b81ccd1427e101437798f3e42c.tar.bz2
[svn-r14559] 2nd batch for h5repack 1.6 a la 1.8
1) make the command line syntax same as h5dump, add long switch names 2) percentage printing bug in the copy code remove one unused source file tested: windows, linux, solaris
Diffstat (limited to 'tools')
-rw-r--r--tools/h5repack/Makefile.in6
-rw-r--r--tools/h5repack/h5repack_copy.c48
-rw-r--r--tools/h5repack/h5repack_main.c424
3 files changed, 297 insertions, 181 deletions
diff --git a/tools/h5repack/Makefile.in b/tools/h5repack/Makefile.in
index b7867de..30c22d2 100644
--- a/tools/h5repack/Makefile.in
+++ b/tools/h5repack/Makefile.in
@@ -54,9 +54,9 @@ DISTCLEAN=h5repack.sh
## Source and object files for programs...
##
-PROG_SRC=h5repack.c h5repack_copy.c h5repack_refs.c h5repack_filters.c h5repack_list.c h5repack_main.c h5repack_opttable.c h5repack_parse.c h5repack_verify.c h5repacktst.c
-OBJS=h5repack.lo h5repack_filters.lo h5repack_copy.lo h5repack_refs.lo h5repack_list.lo h5repack_main.lo h5repack_opttable.lo h5repack_parse.lo h5repack_verify.lo
-TEST_OBJS=h5repack.lo h5repack_filters.lo h5repack_copy.lo h5repack_refs.lo h5repack_list.lo h5repack_opttable.lo h5repack_parse.lo h5repack_verify.lo h5repacktst.lo
+PROG_SRC=h5repack.c h5repack_copy.c h5repack_refs.c h5repack_filters.c h5repack_main.c h5repack_opttable.c h5repack_parse.c h5repack_verify.c h5repacktst.c
+OBJS=h5repack.lo h5repack_filters.lo h5repack_copy.lo h5repack_refs.lo h5repack_main.lo h5repack_opttable.lo h5repack_parse.lo h5repack_verify.lo
+TEST_OBJS=h5repack.lo h5repack_filters.lo h5repack_copy.lo h5repack_refs.lo h5repack_opttable.lo h5repack_parse.lo h5repack_verify.lo h5repacktst.lo
DETECT_OBJS=testh5repack_detect_szip.lo
PROG_OBJ=$(PROG_SRC:.c=.lo) $(DETECT_OBJS)
diff --git a/tools/h5repack/h5repack_copy.c b/tools/h5repack/h5repack_copy.c
index 562af8b..3fc2ea6 100644
--- a/tools/h5repack/h5repack_copy.c
+++ b/tools/h5repack/h5repack_copy.c
@@ -29,10 +29,7 @@ extern char *progname;
*/
#define FORMAT_OBJ " %-27s %s\n" /* obj type, name */
#define FORMAT_OBJ_ATTR " %-27s %s\n" /* obj type, name */
-#define PER(A,B) { per = 0; \
- if (A!=0) \
- per = (double) fabs( (double)(B-A) / (double)A ); \
- }
+
/*-------------------------------------------------------------------------
* local functions
@@ -225,7 +222,6 @@ int do_copy_objects(hid_t fidin,
hsize_t dsize_out; /* output dataset size after filter */
int apply_s; /* flag for apply filter to small dataset sizes */
int apply_f; /* flag for apply filter to return error on H5Dcreate */
- double per; /* percent utilization of storage */
void *buf=NULL; /* buffer for raw data */
void *sm_buf=NULL; /* buffer for raw data */
int has_filter; /* current object has a filter */
@@ -490,7 +486,7 @@ int do_copy_objects(hid_t fidin,
} /* hyperslab read */
}/*nelmts*/
- /*-------------------------------------------------------------------------
+ /*-------------------------------------------------------------------------
* amount of compression used
*-------------------------------------------------------------------------
*/
@@ -498,26 +494,36 @@ int do_copy_objects(hid_t fidin,
{
if (apply_s && apply_f)
{
+ double per=0;
+ hssize_t a, b;
+
/* get the storage size of the input dataset */
dsize_out=H5Dget_storage_size(dset_out);
- PER((hssize_t)dsize_in,(hssize_t)dsize_out);
- print_dataset_info(dcpl_out,travt->objs[i].name,per*100.0);
+
+ a = dsize_in; b = dsize_out;
+ if (a!=0)
+ per = (double) (b-a)/a;
+
+ per = -per;
+ per *=100;
+
+ print_dataset_info(dcpl_out,travt->objs[i].name,per);
}
else
print_dataset_info(dcpl_id,travt->objs[i].name,0.0);
-
- /* print a message that the filter was not applied
- (in case there was a filter)
- */
- if ( has_filter && apply_s == 0 )
- printf(" <warning: filter not applied to %s. dataset smaller than %d bytes>\n",
- travt->objs[i].name,
- (int)options->threshold);
-
- if ( has_filter && apply_f == 0 )
- printf(" <warning: could not apply the filter to %s>\n",
- travt->objs[i].name);
-
+
+ /* print a message that the filter was not applied
+ (in case there was a filter)
+ */
+ if ( has_filter && apply_s == 0 )
+ printf(" <warning: filter not applied to %s. dataset smaller than %d bytes>\n",
+ travt->objs[i].name,
+ (int)options->threshold);
+
+ if ( has_filter && apply_f == 0 )
+ printf(" <warning: could not apply the filter to %s>\n",
+ travt->objs[i].name);
+
} /* verbose */
/*-------------------------------------------------------------------------
diff --git a/tools/h5repack/h5repack_main.c b/tools/h5repack/h5repack_main.c
index 6da0c55..4d45d56 100644
--- a/tools/h5repack/h5repack_main.c
+++ b/tools/h5repack/h5repack_main.c
@@ -15,17 +15,41 @@
#include <stdlib.h>
#include <string.h>
+#include <ctype.h>
#include "h5tools_utils.h"
-#include "h5trav.h"
#include "h5repack.h"
+
+static void usage(const char *prog);
+static int parse_number(char *str);
+static void parse_command_line(int argc, const char* argv[], pack_opt_t* options);
+static void read_info(const char *filename,pack_opt_t *options);
+
+
/* module-scoped variables */
const char *progname = "h5repack";
int d_status = EXIT_SUCCESS;
-/* local prototypes */
-static void usage(void);
-static void read_info(const char *filename,pack_opt_t *options);
+/*
+ * Command-line options: The user can specify short or long-named
+ * parameters.
+ */
+static const char *s_opts = "hVvf:l:m:e:nLc:i:s:";
+static struct long_options l_opts[] = {
+ { "help", no_arg, 'h' },
+ { "version", no_arg, 'V' },
+ { "verbose", no_arg, 'v' },
+ { "filter", require_arg, 'f' },
+ { "layout", require_arg, 'l' },
+ { "threshold", require_arg, 'm' },
+ { "file", require_arg, 'e' },
+ { "native", no_arg, 'n' },
+
+ { NULL, 0, '\0' }
+};
+
+
+
/*-------------------------------------------------------------------------
* Function: main
@@ -45,113 +69,280 @@ static void read_info(const char *filename,pack_opt_t *options);
* October 2006: Added a new switch -n, that allows to write the dataset
* using a native type. The default to write is the file type.
*
+ * Modification:
+ * PVN, November 19, 2007
+ * adopted the syntax h5repack [OPTIONS] file1 file2
+ * PVN, November 28, 2007
+ * added support for multiple global filters
*-------------------------------------------------------------------------
*/
-
-
int main(int argc, char **argv)
{
char *infile = NULL;
char *outfile = NULL;
pack_opt_t options; /*the global options */
- int i, ret;
+ int ret;
/* initialize options */
h5repack_init (&options,0);
+
+ parse_command_line(argc, argv, &options);
- if (argc<2)
+ if ( argv[ opt_ind ] != NULL && argv[ opt_ind + 1 ] != NULL )
{
- usage();
- exit(1);
+ infile = argv[ opt_ind ];
+ outfile = argv[ opt_ind + 1 ];
+
+ if ( strcmp( infile, outfile ) == 0 )
+ {
+ error_msg(progname, "file names cannot be the same\n");
+ usage(progname);
+ exit(EXIT_FAILURE);
+
+ }
}
- for ( i = 1; i < argc; i++)
+ else
{
- if (strcmp(argv[i], "-h") == 0) {
- usage();
- exit(0);
- }
- if (strcmp(argv[i], "-i") == 0) {
- infile = argv[++i];
- }
- else if (strcmp(argv[i], "-o") == 0) {
- outfile = argv[++i];
- }
- else if (strcmp(argv[i], "-v") == 0) {
- options.verbose = 1;
- }
- else if (strcmp(argv[i], "-f") == 0) {
+ error_msg(progname, "file names missing\n");
+ usage(progname);
+ exit(EXIT_FAILURE);
+ }
+
+
+ /* pack it */
+ ret=h5repack(infile,outfile,&options);
+
+ /* free tables */
+ h5repack_end(&options);
+
+ if (ret==-1)
+ return 1;
+ else
+ return 0;
+}
+
+
+
+/*-------------------------------------------------------------------------
+ * Function: usage
+ *
+ * Purpose: print usage
+ *
+ * Return: void
+ *
+ *-------------------------------------------------------------------------
+ */
+static void usage(const char *prog)
+{
+ printf("usage: %s [OPTIONS] file1 file2\n", prog);
+ printf(" file1 Input HDF5 File\n");
+ printf(" file2 Output HDF5 File\n");
+ printf(" OPTIONS\n");
+ printf(" -h, --help Print a usage message and exit\n");
+ printf(" -v, --verbose Verbose mode, print object information\n");
+ printf(" -V, --version Print version number and exit\n");
+ printf(" -n, --native Use a native HDF5 type when repacking\n");
+
+ printf(" -m T, --threshold=T Do not apply the filter to datasets smaller than T\n");
+ printf(" -e M, --file=M Name of file M with the -f and -l options\n");
+ printf(" -f FILT, --filter=FILT Filter type\n");
+ printf(" -l LAYT, --layout=LAYT Layout type\n");
+
+ printf("\n");
+
+ printf(" T - is an integer greater than 1, size of dataset in bytes \n");
+ printf(" M - is a filename.\n");
+
+ printf("\n");
+
+ printf(" FILT - is a string with the format:\n");
+ printf("\n");
+ printf(" <list of objects>:<name of filter>=<filter parameters>\n");
+ printf("\n");
+ printf(" <list of objects> is a comma separated list of object names, meaning apply\n");
+ printf(" compression only to those objects. If no names are specified, the filter\n");
+ printf(" is applied to all objects\n");
+ printf(" <name of filter> can be:\n");
+ printf(" GZIP, to apply the HDF5 GZIP filter (GZIP compression)\n");
+ printf(" SZIP, to apply the HDF5 SZIP filter (SZIP compression)\n");
+ printf(" SHUF, to apply the HDF5 shuffle filter\n");
+ printf(" FLET, to apply the HDF5 checksum filter\n");
+ printf(" NONE, to remove all filters\n");
+ printf(" <filter parameters> is optional filter parameter information\n");
+ printf(" GZIP=<deflation level> from 1-9\n");
+ printf(" SZIP=<pixels per block,coding> pixels per block is a even number in\n");
+ printf(" 2-32 and coding method is either EC or NN\n");
+ printf(" SHUF (no parameter)\n");
+ printf(" FLET (no parameter)\n");
+
+ printf(" NONE (no parameter)\n");
+ printf("\n");
+ printf(" LAYT - is a string with the format:\n");
+ printf("\n");
+ printf(" <list of objects>:<layout type>=<layout parameters>\n");
+ printf("\n");
+ printf(" <list of objects> is a comma separated list of object names, meaning that\n");
+ printf(" layout information is supplied for those objects. If no names are\n");
+ printf(" specified, the layout type is applied to all objects\n");
+ printf(" <layout type> can be:\n");
+ printf(" CHUNK, to apply chunking layout\n");
+ printf(" COMPA, to apply compact layout\n");
+ printf(" CONTI, to apply continuous layout\n");
+ printf(" <layout parameters> is optional layout information\n");
+ printf(" CHUNK=DIM[xDIM...xDIM], the chunk size of each dimension\n");
+ printf(" COMPA (no parameter)\n");
+ printf(" CONTI (no parameter)\n");
+ printf("\n");
+ printf("Examples of use:\n");
+ printf("\n");
+ printf("1) h5repack -v -f GZIP=1 file1 file2\n");
+ printf("\n");
+ printf(" GZIP compression with level 1 to all objects\n");
+ printf("\n");
+ printf("2) h5repack -v -f A:SZIP=8,NN file1 file2\n");
+ printf("\n");
+ printf(" SZIP compression with 8 pixels per block and NN coding method to object A\n");
+ printf("\n");
+ printf("3) h5repack -v -l A,B:CHUNK=20x10 -f C,D,F:NONE file1 file2\n");
+ printf("\n");
+ printf(" Chunked layout, with a layout size of 20x10, to objects A and B\n");
+ printf(" and remove filters to objects C, D, F\n");
+ printf("\n");
+
+ printf("4) h5repack -f SHUF -f GZIP=1 file1 file2 \n");
+ printf("\n");
+ printf(" Add both filters SHUF and GZIP in this order to all datasets\n");
+ printf("\n");
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: parse_command_line
+ *
+ * Purpose: parse command line input
+ *
+ *-------------------------------------------------------------------------
+ */
+
+static void parse_command_line(int argc, const char* argv[], pack_opt_t* options)
+{
+
+ int opt;
+
+ /* parse command line options */
+ while ((opt = get_option(argc, argv, s_opts, l_opts)) != EOF)
+ {
+ switch ((char)opt)
+ {
+ case 'h':
+ usage(progname);
+ exit(EXIT_SUCCESS);
+ case 'V':
+ print_version(progname);
+ exit(EXIT_SUCCESS);
+ case 'v':
+ options->verbose = 1;
+ break;
+ case 'f':
- /* add the -f filter option */
- if (h5repack_addfilter(argv[i+1],&options)<0)
+ /* parse the -f filter option */
+ if (h5repack_addfilter( opt_arg, options)<0)
{
error_msg(progname, "in parsing filter\n");
- exit(1);
+ exit(EXIT_FAILURE);
}
-
- /* jump to next */
- ++i;
- }
- else if (strcmp(argv[i], "-l") == 0) {
+ break;
+ case 'l':
/* parse the -l layout option */
- if (h5repack_addlayout(argv[i+1],&options)<0)
+ if (h5repack_addlayout( opt_arg, options)<0)
{
error_msg(progname, "in parsing layout\n");
- exit(1);
+ exit(EXIT_FAILURE);
}
+ break;
- /* jump to next */
- ++i;
- }
-
- else if (strcmp(argv[i], "-m") == 0) {
- options.threshold = parse_number(argv[i+1]);
- if ((int)options.threshold==-1) {
- error_msg(progname, "invalid treshold size <%s>\n",argv[i+1]);
- exit(1);
+
+ case 'm':
+
+ options->threshold = parse_number( opt_arg );
+ if ((int)options->threshold==-1)
+ {
+ error_msg(progname, "invalid treshold size <%s>\n", opt_arg );
+ exit(EXIT_FAILURE);
}
- ++i;
- }
+ break;
- else if (strcmp(argv[i], "-e") == 0) {
- read_info(argv[++i],&options);
- }
- else if (strcmp(argv[i], "-n") == 0) {
- options.use_native = 1;
- }
+ case 'e':
+ read_info( opt_arg, options);
+ break;
+
+ case 'n':
+ options->use_native = 1;
+ break;
- else if (argv[i][0] == '-') {
- error_msg(progname, " - is not a valid argument\n");
- usage();
- exit(1);
- }
- }
+
+
+
+
+ } /* switch */
+
+
+ } /* while */
- if (infile == NULL || outfile == NULL)
+ /* check for file names to be processed */
+ if (argc <= opt_ind || argv[ opt_ind + 1 ] == NULL)
{
- error_msg(progname, "file names missing\n");
- usage();
- exit(1);
+ error_msg(progname, "missing file names\n");
+ usage(progname);
+ exit(EXIT_FAILURE);
}
+
+
+
+
+}
+
+/*-------------------------------------------------------------------------
+ * Function: parse_number
+ *
+ * Purpose: read a number from command line argument
+ *
+ * Return: number, -1 for FAIL
+ *
+ * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu
+ *
+ * Date: September, 23, 2003
+ *
+ *-------------------------------------------------------------------------
+ */
+
+
+int parse_number(char *str)
+{
+ unsigned i;
+ int n;
+ char c;
+ size_t len=strlen(str);
- /* pack it */
- ret=h5repack(infile,outfile,&options);
-
- /* free tables */
- h5repack_end(&options);
-
- if (ret==-1)
- return 1;
- else
- return 0;
+ for ( i=0; i<len; i++)
+ {
+ c = str[i];
+ if (!isdigit(c)){
+ return -1;
+ }
+ }
+ str[i]='\0';
+ n=atoi(str);
+ return n;
}
/*-------------------------------------------------------------------------
* Function: read_info
*
- * Purpose: read comp and chunk options from file
+ * Purpose: read comp and chunk options from a file
*
* Return: void, exit on error
*
@@ -162,7 +353,7 @@ int main(int argc, char **argv)
*-------------------------------------------------------------------------
*/
-static
+static
void read_info(const char *filename,
pack_opt_t *options)
{
@@ -225,7 +416,7 @@ void read_info(const char *filename,
exit(1);
}
}
- /*-------------------------------------------------------------------------
+ /*-------------------------------------------------------------------------
* layout
*-------------------------------------------------------------------------
*/
@@ -255,7 +446,7 @@ void read_info(const char *filename,
exit(1);
}
}
- /*-------------------------------------------------------------------------
+ /*-------------------------------------------------------------------------
* not valid
*-------------------------------------------------------------------------
*/
@@ -270,84 +461,3 @@ void read_info(const char *filename,
}
-
-/*-------------------------------------------------------------------------
- * Function: usage
- *
- * Purpose: print usage
- *
- * Return: void
- *
- *-------------------------------------------------------------------------
- */
-
-static
-void usage(void)
-{
- printf("usage: h5repack -i input -o output [-h] [-v] [-f FILTER] [-l LAYOUT] [-n] [-m size] [-e file]\n");
- printf("\n");
- printf("-i input Input HDF5 File\n");
- printf("-o output Output HDF5 File\n");
- printf("[-h] Print this message\n");
- printf("[-v] Verbose mode\n");
- printf("[-n] Use a native HDF5 type when repacking. Default is the file type\n");
- printf("[-m size] Do not apply the filter to objects smaller than size\n");
- printf("[-e file] Name of file with the -f and -l options\n");
- printf("[-f FILTER] Filter type\n");
- printf("[-l LAYOUT] Layout type\n");
- printf("\n");
- printf("FILTER is a string with the format:\n");
- printf("\n");
- printf(" <list of objects>:<name of filter>=<filter parameters>\n");
- printf("\n");
- printf(" <list of objects> is a comma separated list of object names, meaning apply\n");
- printf(" compression only to those objects. If no names are specified, the filter\n");
- printf(" is applied to all objects\n");
- printf(" <name of filter> can be:\n");
- printf(" GZIP, to apply the HDF5 GZIP filter (GZIP compression)\n");
- printf(" SZIP, to apply the HDF5 SZIP filter (SZIP compression)\n");
- printf(" SHUF, to apply the HDF5 shuffle filter\n");
- printf(" FLET, to apply the HDF5 checksum filter\n");
- printf(" NONE, to remove all filters\n");
- printf(" <filter parameters> is optional filter parameter information\n");
- printf(" GZIP=<deflation level> from 1-9\n");
- printf(" SZIP=<pixels per block,coding> pixels per block is a even number in\n");
- printf(" 2-32 and coding method is either EC or NN\n");
- printf(" SHUF (no parameter)\n");
- printf(" FLET (no parameter)\n");
- printf(" NONE (no parameter)\n");
- printf("\n");
- printf("LAYOUT is a string with the format:\n");
- printf("\n");
- printf(" <list of objects>:<layout type>=<layout parameters>\n");
- printf("\n");
- printf(" <list of objects> is a comma separated list of object names, meaning that\n");
- printf(" layout information is supplied for those objects. If no names are\n");
- printf(" specified, the layout type is applied to all objects\n");
- printf(" <layout type> can be:\n");
- printf(" CHUNK, to apply chunking layout\n");
- printf(" COMPA, to apply compact layout\n");
- printf(" CONTI, to apply continuous layout\n");
- printf(" <layout parameters> is optional layout information\n");
- printf(" CHUNK=DIM[xDIM...xDIM], the chunk size of each dimension\n");
- printf(" COMPA (no parameter)\n");
- printf(" CONTI (no parameter)\n");
- printf("\n");
- printf("Examples of use:\n");
- printf("\n");
- printf("1) h5repack -v -i file1 -o file2 -f GZIP=1\n");
- printf("\n");
- printf(" GZIP compression with level 1 to all objects\n");
- printf("\n");
- printf("2) h5repack -v -i file1 -o file2 -f A:SZIP=8,NN\n");
- printf("\n");
- printf(" SZIP compression with 8 pixels per block and NN coding method to object A\n");
- printf("\n");
- printf("3) h5repack -v -i file1 -o file2 -l A,B:CHUNK=20x10 -f C,D,F:NONE\n");
- printf("\n");
- printf(" Chunked layout, with a layout size of 20x10, to objects A and B\n");
- printf(" and remove filters to objects C, D, F\n");
- printf("\n");
-}
-
-