diff options
author | Pedro Vicente Nunes <pvn@hdfgroup.org> | 2007-11-28 20:30:43 (GMT) |
---|---|---|
committer | Pedro Vicente Nunes <pvn@hdfgroup.org> | 2007-11-28 20:30:43 (GMT) |
commit | 1b645ffd9177610c42d41c0dffbb7237154b9dad (patch) | |
tree | 1bf0d695d485817eeac809c7fb97911c09d17313 /tools | |
parent | cb2a70feb48da0a5d5d5e17d7682fcd29ca27e39 (diff) | |
download | hdf5-1b645ffd9177610c42d41c0dffbb7237154b9dad.zip hdf5-1b645ffd9177610c42d41c0dffbb7237154b9dad.tar.gz hdf5-1b645ffd9177610c42d41c0dffbb7237154b9dad.tar.bz2 |
[svn-r14299] new feature: add support for h5repack to handle several global filters
usage is to repeat the -f option
tested: windows, linux, solaris
Diffstat (limited to 'tools')
-rw-r--r-- | tools/h5repack/Makefile.am | 4 | ||||
-rw-r--r-- | tools/h5repack/Makefile.in | 11 | ||||
-rw-r--r-- | tools/h5repack/h5repack.c | 881 | ||||
-rw-r--r-- | tools/h5repack/h5repack.h | 23 | ||||
-rw-r--r-- | tools/h5repack/h5repack_copy.c | 434 | ||||
-rw-r--r-- | tools/h5repack/h5repack_filters.c | 73 | ||||
-rw-r--r-- | tools/h5repack/h5repack_list.c | 153 | ||||
-rw-r--r-- | tools/h5repack/h5repack_main.c | 573 | ||||
-rw-r--r-- | tools/h5repack/h5repack_opttable.c | 476 | ||||
-rw-r--r-- | tools/h5repack/h5repack_parse.c | 1048 | ||||
-rw-r--r-- | tools/h5repack/h5repack_refs.c | 2 | ||||
-rw-r--r-- | tools/h5repack/h5repack_verify.c | 11 | ||||
-rw-r--r-- | tools/h5repack/h5repacktst.c | 30 |
13 files changed, 1758 insertions, 1961 deletions
diff --git a/tools/h5repack/Makefile.am b/tools/h5repack/Makefile.am index e053e83..f677de0 100644 --- a/tools/h5repack/Makefile.am +++ b/tools/h5repack/Makefile.am @@ -41,8 +41,8 @@ LDADD=$(LIBH5TOOLS) $(LIBH5TEST) $(LIBHDF5) # Source files COMMON_SOURCES=h5repack.c h5repack_copy.c h5repack_filters.c \ - h5repack_list.c h5repack_opttable.c h5repack_parse.c h5repack_refs.c \ - h5repack_verify.c + h5repack_opttable.c h5repack_parse.c h5repack_refs.c \ + h5repack_verify.c h5repack_SOURCES=$(COMMON_SOURCES) h5repack_main.c diff --git a/tools/h5repack/Makefile.in b/tools/h5repack/Makefile.in index 1823f8b..30f7b32 100644 --- a/tools/h5repack/Makefile.in +++ b/tools/h5repack/Makefile.in @@ -69,9 +69,9 @@ binPROGRAMS_INSTALL = $(INSTALL_PROGRAM) am__EXEEXT_1 = h5repacktst$(EXEEXT) PROGRAMS = $(bin_PROGRAMS) $(noinst_PROGRAMS) am__objects_1 = h5repack.$(OBJEXT) h5repack_copy.$(OBJEXT) \ - h5repack_filters.$(OBJEXT) h5repack_list.$(OBJEXT) \ - h5repack_opttable.$(OBJEXT) h5repack_parse.$(OBJEXT) \ - h5repack_refs.$(OBJEXT) h5repack_verify.$(OBJEXT) + h5repack_filters.$(OBJEXT) h5repack_opttable.$(OBJEXT) \ + h5repack_parse.$(OBJEXT) h5repack_refs.$(OBJEXT) \ + h5repack_verify.$(OBJEXT) am_h5repack_OBJECTS = $(am__objects_1) h5repack_main.$(OBJEXT) h5repack_OBJECTS = $(am_h5repack_OBJECTS) h5repack_LDADD = $(LDADD) @@ -351,8 +351,8 @@ LDADD = $(LIBH5TOOLS) $(LIBH5TEST) $(LIBHDF5) # Source files COMMON_SOURCES = h5repack.c h5repack_copy.c h5repack_filters.c \ - h5repack_list.c h5repack_opttable.c h5repack_parse.c h5repack_refs.c \ - h5repack_verify.c + h5repack_opttable.c h5repack_parse.c h5repack_refs.c \ + h5repack_verify.c h5repack_SOURCES = $(COMMON_SOURCES) h5repack_main.c h5repacktst_SOURCES = $(COMMON_SOURCES) h5repacktst.c @@ -470,7 +470,6 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/h5repack.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/h5repack_copy.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/h5repack_filters.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/h5repack_list.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/h5repack_main.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/h5repack_opttable.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/h5repack_parse.Po@am__quote@ diff --git a/tools/h5repack/h5repack.c b/tools/h5repack/h5repack.c index 45409c4..076ab18 100644 --- a/tools/h5repack/h5repack.c +++ b/tools/h5repack/h5repack.c @@ -15,9 +15,14 @@ #include <stdlib.h> #include <string.h> +#include <ctype.h> + +#include "H5private.h" #include "h5repack.h" +#include "h5tools.h" #include "h5tools_utils.h" + extern char *progname; @@ -28,25 +33,11 @@ extern char *progname; */ static int check_options(pack_opt_t *options); +static int check_objects(const char* fname, pack_opt_t *options); +static const char* get_sfilter (H5Z_filter_t filtn); +static int have_request(pack_opt_t *options); -/*------------------------------------------------------------------------- - * Function: aux_initglb_filter - * - * Purpose: auxiliary function, initialize the options global filter - * - * Return: void - * - *------------------------------------------------------------------------- - */ -static void aux_initglb_filter(pack_opt_t *options) -{ - int k; - options->filter_g.filtn = -1; - for ( k=0; k<CDVALUES; k++) - options->filter_g.cd_values[k] = -1; -} - /*------------------------------------------------------------------------- * Function: h5repack @@ -71,20 +62,20 @@ int h5repack(const char* infile, const char* outfile, pack_opt_t *options) { - /* check input */ - if (check_options(options)<0) - return -1; - - /* check for objects in input that are in the file */ - if (check_objects(infile,options) < 0) - return -1; - - /* copy the objects */ - if (copy_objects(infile,outfile,options) < 0) - return -1; - - - return 0; + /* check input */ + if (check_options(options)<0) + return -1; + + /* check for objects in input that are in the file */ + if (check_objects(infile,options) < 0) + return -1; + + /* copy the objects */ + if (copy_objects(infile,outfile,options) < 0) + return -1; + + + return 0; } @@ -102,10 +93,19 @@ int h5repack(const char* infile, int h5repack_init (pack_opt_t *options, int verbose) { - memset(options,0,sizeof(pack_opt_t)); - options->threshold = 1024; - options->verbose = verbose; - return (options_table_init(&(options->op_tbl))); + int k, n; + memset(options,0,sizeof(pack_opt_t)); + options->threshold = 1024; + options->verbose = verbose; + + for ( n = 0; n < H5_REPACK_MAX_NFILTERS; n++) + { + options->filter_g[n].filtn = -1; + for ( k = 0; k < CDVALUES; k++) + options->filter_g[n].cd_values[k] = -1; + } + + return (options_table_init(&(options->op_tbl))); } /*------------------------------------------------------------------------- @@ -118,7 +118,7 @@ int h5repack_init (pack_opt_t *options, int h5repack_end (pack_opt_t *options) { - return options_table_free(options->op_tbl); + return options_table_free(options->op_tbl); } /*------------------------------------------------------------------------- @@ -135,35 +135,43 @@ int h5repack_end (pack_opt_t *options) int h5repack_addfilter(const char* str, pack_opt_t *options) { - obj_list_t *obj_list=NULL; /*one object list for the -f and -c option entry */ - filter_info_t filt; /*filter info for the current -f option entry */ - int n_objs; /*number of objects in the current -f or -c option entry */ - - if (options->all_filter==1){ - error_msg(progname, "invalid compression input: 'all' option is present \ - with other objects <%s>\n",str); - return -1; - } - - /* parse the -f option */ - obj_list=parse_filter(str,&n_objs,&filt,options); - if (obj_list==NULL) - { - return -1; - } - - if (options->all_filter==1) - { - /* if we are compressing all set the global filter type */ - aux_initglb_filter(options); - options->filter_g=filt; - } - - if (options->all_filter==0) - options_add_filter(obj_list,n_objs,filt,options->op_tbl); - - free(obj_list); - return 0; + obj_list_t *obj_list=NULL; /* one object list for the -f and -l option entry */ + filter_info_t filter; /* filter info for the current -f option entry */ + int n_objs; /* number of objects in the current -f or -l option entry */ + int is_glb; /* is the filter global */ + + + + /* parse the -f option */ + obj_list=parse_filter(str,&n_objs,&filter,options,&is_glb); + if (obj_list==NULL) + { + return -1; + } + + /* if it applies to all objects */ + if (is_glb) + { + + int n; + + n = options->n_filter_g++; /* increase # of global filters */ + + if (options->n_filter_g > H5_REPACK_MAX_NFILTERS) + { + error_msg(progname, "maximum number of filters exceeded for <%s>\n",str); + return -1; + + } + + options->filter_g[n] = filter; + } + + else + options_add_filter(obj_list,n_objs,filter,options->op_tbl); + + free(obj_list); + return 0; } @@ -181,55 +189,55 @@ int h5repack_addfilter(const char* str, int h5repack_addlayout(const char* str, pack_opt_t *options) { - - obj_list_t *obj_list=NULL; /*one object list for the -t and -c option entry */ - int n_objs; /*number of objects in the current -t or -c option entry */ - pack_info_t pack; /*info about layout to extract from parse */ - int j; - - init_packobject(&pack); - - if (options->all_layout==1){ - error_msg(progname, "invalid layout input: 'all' option \ - is present with other objects <%s>\n",str); - return -1; - } - - /* parse the layout option */ - obj_list=parse_layout(str,&n_objs,&pack,options); - if (obj_list==NULL) - return -1; - - /* set global layout option */ - if (options->all_layout==1 ) - { - options->layout_g=pack.layout; - if (pack.layout==H5D_CHUNKED) - { - /* -2 means the NONE option, remove chunking - and set the global layout to contiguous */ - if (pack.chunk.rank==-2) - { - options->layout_g = H5D_CONTIGUOUS; - } - /* otherwise set the global chunking type */ - else - { - options->chunk_g.rank=pack.chunk.rank; - for (j = 0; j < pack.chunk.rank; j++) - options->chunk_g.chunk_lengths[j] = pack.chunk.chunk_lengths[j]; - } - } - } - - if (options->all_layout==0) - options_add_layout(obj_list, - n_objs, - &pack, - options->op_tbl); - - free(obj_list); - return 0; + + obj_list_t *obj_list=NULL; /*one object list for the -t and -c option entry */ + int n_objs; /*number of objects in the current -t or -c option entry */ + pack_info_t pack; /*info about layout to extract from parse */ + int j; + + init_packobject(&pack); + + if (options->all_layout==1){ + error_msg(progname, "invalid layout input: 'all' option \ + is present with other objects <%s>\n",str); + return -1; + } + + /* parse the layout option */ + obj_list=parse_layout(str,&n_objs,&pack,options); + if (obj_list==NULL) + return -1; + + /* set global layout option */ + if (options->all_layout==1 ) + { + options->layout_g=pack.layout; + if (pack.layout==H5D_CHUNKED) + { + /* -2 means the NONE option, remove chunking + and set the global layout to contiguous */ + if (pack.chunk.rank==-2) + { + options->layout_g = H5D_CONTIGUOUS; + } + /* otherwise set the global chunking type */ + else + { + options->chunk_g.rank=pack.chunk.rank; + for (j = 0; j < pack.chunk.rank; j++) + options->chunk_g.chunk_lengths[j] = pack.chunk.chunk_lengths[j]; + } + } + } + + if (options->all_layout==0) + options_add_layout(obj_list, + n_objs, + &pack, + options->op_tbl); + + free(obj_list); + return 0; } @@ -252,149 +260,283 @@ int h5repack_addlayout(const char* str, */ static int check_options(pack_opt_t *options) { - unsigned int i; - int k, j, has_cp=0, has_ck=0; - char slayout[30]; + unsigned int i; + int k, j, has_cp=0, has_ck=0; + char slayout[30]; + + /*------------------------------------------------------------------------- + * objects to layout + *------------------------------------------------------------------------- + */ + if (options->verbose && have_request(options) /* only print if requested */) + { + printf("Objects to modify layout are...\n"); + if (options->all_layout==1) { + switch (options->layout_g) + { + case H5D_COMPACT: + strcpy(slayout,"compact"); + break; + case H5D_CONTIGUOUS: + strcpy(slayout,"contiguous"); + break; + case H5D_CHUNKED: + strcpy(slayout,"chunked"); + break; + default: + strcpy(slayout,"unknown"); + break; + } + printf(" Apply %s layout to all\n", slayout); + if (H5D_CHUNKED==options->layout_g) { + printf("with dimension ["); + for ( j = 0; j < options->chunk_g.rank; j++) + printf("%d ",(int)options->chunk_g.chunk_lengths[j]); + printf("]\n"); + } + } + }/* verbose */ + + for ( i = 0; i < options->op_tbl->nelems; i++) + { + char* name=options->op_tbl->objs[i].path; + + if (options->op_tbl->objs[i].chunk.rank>0) + { + if (options->verbose){ + printf(" <%s> with chunk size ",name); + for ( k = 0; k < options->op_tbl->objs[i].chunk.rank; k++) + printf("%d ",(int)options->op_tbl->objs[i].chunk.chunk_lengths[k]); + printf("\n"); + } + has_ck=1; + } + else if (options->op_tbl->objs[i].chunk.rank==-2) + { + if (options->verbose) + printf(" <%s> %s\n",name,"NONE (contigous)"); + has_ck=1; + } + } + + if (options->all_layout==1 && has_ck){ + error_msg(progname, "invalid chunking input: 'all' option\ + is present with other objects\n"); + return -1; + } + + /*------------------------------------------------------------------------- + * objects to filter + *------------------------------------------------------------------------- + */ + + if (options->verbose && have_request(options) /* only print if requested */) + { + printf("Objects to apply filter are...\n"); + if (options->all_filter==1) + { + + for (k = 0; k < options->n_filter_g; k++ ) + { + H5Z_filter_t filtn=options->filter_g[k].filtn; + switch (filtn) + { + case H5Z_FILTER_NONE: + printf(" Uncompress all\n"); + break; + case H5Z_FILTER_SHUFFLE: + case H5Z_FILTER_FLETCHER32: + printf(" All with %s\n",get_sfilter(filtn)); + break; + case H5Z_FILTER_SZIP: + case H5Z_FILTER_DEFLATE: + printf(" All with %s, parameter %d\n", + get_sfilter(filtn), + options->filter_g[k].cd_values[0]); + break; + } /* k */ + }; + } + } /* verbose */ + + for ( i = 0; i < options->op_tbl->nelems; i++) + { + pack_info_t pack = options->op_tbl->objs[i]; + char* name = pack.path; + + for ( j=0; j<pack.nfilters; j++) + { + if (options->verbose) + { + printf(" <%s> with %s filter\n", + name, + get_sfilter(pack.filter[j].filtn)); + } + + has_cp=1; + + } /* j */ + } /* i */ + + if (options->all_filter==1 && has_cp){ + error_msg(progname, "invalid compression input: 'all' option\ + is present with other objects\n"); + return -1; + } + + /* check options for the latest format */ + if (options->grp_compact < 0) { + error_msg(progname, "invalid maximum number of links to store as header messages\n"); + return -1; + } + if (options->grp_indexed < 0) { + error_msg(progname, "invalid minimum number of links to store in the indexed format\n"); + return -1; + } + if (options->grp_indexed > options->grp_compact) { + error_msg(progname, "minimum indexed size is greater than the maximum compact size\n"); + return -1; + } + for (i=0; i<8; i++) { + if (options->msg_size[i]<0) { + error_msg(progname, "invalid shared message size\n"); + return -1; + } + } + + return 0; +} -/*------------------------------------------------------------------------- - * objects to layout - *------------------------------------------------------------------------- - */ - if (options->verbose && have_request(options) /* only print if requested */) - { - printf("Objects to modify layout are...\n"); - if (options->all_layout==1) { - switch (options->layout_g) - { - case H5D_COMPACT: - strcpy(slayout,"compact"); - break; - case H5D_CONTIGUOUS: - strcpy(slayout,"contiguous"); - break; - case H5D_CHUNKED: - strcpy(slayout,"chunked"); - break; - default: - strcpy(slayout,"unknown"); - break; - } - printf(" Apply %s layout to all\n", slayout); - if (H5D_CHUNKED==options->layout_g) { - printf("with dimension ["); - for ( j = 0; j < options->chunk_g.rank; j++) - printf("%d ",(int)options->chunk_g.chunk_lengths[j]); - printf("]\n"); - } - } - }/* verbose */ - - for ( i = 0; i < options->op_tbl->nelems; i++) - { - char* name=options->op_tbl->objs[i].path; - - if (options->op_tbl->objs[i].chunk.rank>0) - { - if (options->verbose){ - printf(" <%s> with chunk size ",name); - for ( k = 0; k < options->op_tbl->objs[i].chunk.rank; k++) - printf("%d ",(int)options->op_tbl->objs[i].chunk.chunk_lengths[k]); - printf("\n"); - } - has_ck=1; - } - else if (options->op_tbl->objs[i].chunk.rank==-2) - { - if (options->verbose) - printf(" <%s> %s\n",name,"NONE (contigous)"); - has_ck=1; - } - } - - if (options->all_layout==1 && has_ck){ - error_msg(progname, "invalid chunking input: 'all' option\ - is present with other objects\n"); - return -1; - } /*------------------------------------------------------------------------- - * objects to filter + * Function: check_objects + * + * Purpose: locate all HDF5 objects in the file and compare with user + * supplied list + * + * Return: 0, ok, -1 no + * + * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu + * + * Date: September, 23, 2003 + * *------------------------------------------------------------------------- */ - - if (options->verbose && have_request(options) /* only print if requested */) - { - printf("Objects to apply filter are...\n"); - if (options->all_filter==1) - { - H5Z_filter_t filtn=options->filter_g.filtn; - switch (filtn) - { - case H5Z_FILTER_NONE: - printf(" Uncompress all\n"); - break; - case H5Z_FILTER_SHUFFLE: - case H5Z_FILTER_FLETCHER32: - printf(" All with %s\n",get_sfilter(filtn)); - break; - case H5Z_FILTER_SZIP: - case H5Z_FILTER_DEFLATE: - printf(" All with %s, parameter %d\n", - get_sfilter(filtn), - options->filter_g.cd_values[0]); - break; - }; - } - } /* verbose */ - - for ( i = 0; i < options->op_tbl->nelems; i++) - { - pack_info_t pack = options->op_tbl->objs[i]; - char* name = pack.path; - - for ( j=0; j<pack.nfilters; j++) - { - if (options->verbose) - { - printf(" <%s> with %s filter\n", - name, - get_sfilter(pack.filter[j].filtn)); - } - - has_cp=1; - - } /* j */ - } /* i */ - - if (options->all_filter==1 && has_cp){ - error_msg(progname, "invalid compression input: 'all' option\ - is present with other objects\n"); - return -1; - } - - /* check options for the latest format */ - if (options->grp_compact < 0) { - error_msg(progname, "invalid maximum number of links to store as header messages\n"); - return -1; - } - if (options->grp_indexed < 0) { - error_msg(progname, "invalid minimum number of links to store in the indexed format\n"); - return -1; - } - if (options->grp_indexed > options->grp_compact) { - error_msg(progname, "minimum indexed size is greater than the maximum compact size\n"); - return -1; - } - for (i=0; i<8; i++) { - if (options->msg_size[i]<0) { - error_msg(progname, "invalid shared message size\n"); - return -1; - } - } - - return 0; +static int check_objects(const char* fname, + pack_opt_t *options) +{ + hid_t fid; + unsigned int i; + trav_table_t *travt = NULL; + + /* nothing to do */ + if(options->op_tbl->nelems == 0) + return 0; + + /*------------------------------------------------------------------------- + * open the file + *------------------------------------------------------------------------- + */ + if((fid = h5tools_fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT, NULL, NULL, 0)) < 0){ + printf("<%s>: %s\n", fname, H5FOPENERROR ); + return -1; + } + + /*------------------------------------------------------------------------- + * get the list of objects in the file + *------------------------------------------------------------------------- + */ + + /* init table */ + trav_table_init(&travt); + + /* get the list of objects in the file */ + if(h5trav_gettable(fid, travt) < 0) + goto out; + + /*------------------------------------------------------------------------- + * compare with user supplied list + *------------------------------------------------------------------------- + */ + + if(options->verbose) + printf("Opening file <%s>. Searching for objects to modify...\n", fname); + + for(i = 0; i < options->op_tbl->nelems; i++) { + char* name=options->op_tbl->objs[i].path; + if(options->verbose) + printf(" <%s>",name); + + /* the input object names are present in the file and are valid */ + if(h5trav_getindext(name, travt) < 0) { + error_msg(progname, "%s Could not find <%s> in file <%s>. Exiting...\n", + (options->verbose?"\n":""),name,fname); + goto out; + } + if(options->verbose) + printf("...Found\n"); + + /* check for extra filter conditions */ + switch(options->op_tbl->objs[i].filter->filtn) { + /* chunk size must be smaller than pixels per block */ + case H5Z_FILTER_SZIP: + { + int j; + int csize = 1; + int ppb = options->op_tbl->objs[i].filter->cd_values[0]; + hsize_t dims[H5S_MAX_RANK]; + int rank; + hid_t did; + hid_t sid; + + if(options->op_tbl->objs[i].chunk.rank > 0) { + rank = options->op_tbl->objs[i].chunk.rank; + for(j = 0; j < rank; j++) + csize *= (int)options->op_tbl->objs[i].chunk.chunk_lengths[j]; + } + else { + if((did = H5Dopen2(fid, name, H5P_DEFAULT)) < 0) + goto out; + if((sid = H5Dget_space(did)) < 0) + goto out; + if((rank = H5Sget_simple_extent_ndims(sid)) < 0) + goto out; + HDmemset(dims, 0, sizeof dims); + if(H5Sget_simple_extent_dims(sid, dims, NULL) < 0) + goto out; + for(j = 0; j < rank; j++) + csize *= (int)dims[j]; + if(H5Sclose(sid) < 0) + goto out; + if(H5Dclose(did) < 0) + goto out; + } + + if (csize < ppb ) { + printf(" <warning: SZIP settins, chunk size is smaller than pixels per block>\n"); + goto out; + } + } + break; + } + } /* i */ + + /*------------------------------------------------------------------------- + * close + *------------------------------------------------------------------------- + */ + H5Fclose(fid); + trav_table_free(travt); + return 0; + +out: + H5Fclose(fid); + trav_table_free(travt); + return -1; } + + /*------------------------------------------------------------------------- * Function: read_info * @@ -412,107 +554,107 @@ static int check_options(pack_opt_t *options) void read_info(const char *filename, pack_opt_t *options) { - - char stype[10]; - char comp_info[1024]; - FILE *fp; - char c; - int i, rc=1; - char *srcdir = getenv("srcdir"); /* the source directory */ - char data_file[512]=""; /* buffer to hold name of existing file */ - - /* compose the name of the file to open, using the srcdir, if appropriate */ - if (srcdir){ - strcpy(data_file,srcdir); - strcat(data_file,"/"); - } - strcat(data_file,filename); - - - if ((fp = fopen(data_file, "r")) == (FILE *)NULL) { - error_msg(progname, "cannot open options file %s\n", filename); - exit(1); - } - - /* cycle until end of file reached */ - while( 1 ) - { - rc=fscanf(fp, "%s", stype); - if (rc==-1) - break; - - /*------------------------------------------------------------------------- - * filter - *------------------------------------------------------------------------- - */ - if (strcmp(stype,"-f") == 0) { - - /* find begining of info */ - i=0; c='0'; - while( c!=' ' ) - { - fscanf(fp, "%c", &c); - if (feof(fp)) break; - } - c='0'; - /* go until end */ - while( c!=' ' ) - { - fscanf(fp, "%c", &c); - comp_info[i]=c; - i++; - if (feof(fp)) break; - if (c==10 /*eol*/) break; - } - comp_info[i-1]='\0'; /*cut the last " */ - - if (h5repack_addfilter(comp_info,options)==-1){ - error_msg(progname, "could not add compression option\n"); - exit(1); - } - } - /*------------------------------------------------------------------------- - * layout - *------------------------------------------------------------------------- - */ - else if (strcmp(stype,"-l") == 0) { - - /* find begining of info */ - i=0; c='0'; - while( c!=' ' ) - { - fscanf(fp, "%c", &c); - if (feof(fp)) break; - } - c='0'; - /* go until end */ - while( c!=' ' ) - { - fscanf(fp, "%c", &c); - comp_info[i]=c; - i++; - if (feof(fp)) break; - if (c==10 /*eol*/) break; - } - comp_info[i-1]='\0'; /*cut the last " */ - - if (h5repack_addlayout(comp_info,options)==-1){ - error_msg(progname, "could not add chunck option\n"); - exit(1); - } - } - /*------------------------------------------------------------------------- - * not valid - *------------------------------------------------------------------------- - */ - else { - error_msg(progname, "bad file format for %s", filename); - exit(1); - } - } - - fclose(fp); - return; + + char stype[10]; + char comp_info[1024]; + FILE *fp; + char c; + int i, rc=1; + char *srcdir = getenv("srcdir"); /* the source directory */ + char data_file[512]=""; /* buffer to hold name of existing file */ + + /* compose the name of the file to open, using the srcdir, if appropriate */ + if (srcdir){ + strcpy(data_file,srcdir); + strcat(data_file,"/"); + } + strcat(data_file,filename); + + + if ((fp = fopen(data_file, "r")) == (FILE *)NULL) { + error_msg(progname, "cannot open options file %s\n", filename); + exit(1); + } + + /* cycle until end of file reached */ + while( 1 ) + { + rc=fscanf(fp, "%s", stype); + if (rc==-1) + break; + + /*------------------------------------------------------------------------- + * filter + *------------------------------------------------------------------------- + */ + if (strcmp(stype,"-f") == 0) { + + /* find begining of info */ + i=0; c='0'; + while( c!=' ' ) + { + fscanf(fp, "%c", &c); + if (feof(fp)) break; + } + c='0'; + /* go until end */ + while( c!=' ' ) + { + fscanf(fp, "%c", &c); + comp_info[i]=c; + i++; + if (feof(fp)) break; + if (c==10 /*eol*/) break; + } + comp_info[i-1]='\0'; /*cut the last " */ + + if (h5repack_addfilter(comp_info,options)==-1){ + error_msg(progname, "could not add compression option\n"); + exit(1); + } + } + /*------------------------------------------------------------------------- + * layout + *------------------------------------------------------------------------- + */ + else if (strcmp(stype,"-l") == 0) { + + /* find begining of info */ + i=0; c='0'; + while( c!=' ' ) + { + fscanf(fp, "%c", &c); + if (feof(fp)) break; + } + c='0'; + /* go until end */ + while( c!=' ' ) + { + fscanf(fp, "%c", &c); + comp_info[i]=c; + i++; + if (feof(fp)) break; + if (c==10 /*eol*/) break; + } + comp_info[i-1]='\0'; /*cut the last " */ + + if (h5repack_addlayout(comp_info,options)==-1){ + error_msg(progname, "could not add chunck option\n"); + exit(1); + } + } + /*------------------------------------------------------------------------- + * not valid + *------------------------------------------------------------------------- + */ + else { + error_msg(progname, "bad file format for %s", filename); + exit(1); + } + } + + fclose(fp); + return; } @@ -527,7 +669,7 @@ void read_info(const char *filename, * *------------------------------------------------------------------------- */ -int have_request(pack_opt_t *options) +static int have_request(pack_opt_t *options) { if (options->all_filter || options->all_layout || options->op_tbl->nelems) @@ -536,3 +678,38 @@ int have_request(pack_opt_t *options) return 0; } + + +/*------------------------------------------------------------------------- + * Function: get_sfilter + * + * Purpose: return the filter as a string name + * + * Return: name of filter, exit on error + * + *------------------------------------------------------------------------- + */ + +static const char* get_sfilter(H5Z_filter_t filtn) +{ + if (filtn==H5Z_FILTER_NONE) + return "NONE"; + else if (filtn==H5Z_FILTER_DEFLATE) + return "GZIP"; + else if (filtn==H5Z_FILTER_SZIP) + return "SZIP"; + else if (filtn==H5Z_FILTER_SHUFFLE) + return "SHUFFLE"; + else if (filtn==H5Z_FILTER_FLETCHER32) + return "FLETCHER32"; + else if (filtn==H5Z_FILTER_NBIT) + return "NBIT"; + else if (filtn==H5Z_FILTER_SCALEOFFSET) + return "SOFF"; + else { + error_msg(progname, "input error in filter type\n"); + exit(1); + } + return NULL; +} + diff --git a/tools/h5repack/h5repack.h b/tools/h5repack/h5repack.h index d986cc0..e9c4d9a 100644 --- a/tools/h5repack/h5repack.h +++ b/tools/h5repack/h5repack.h @@ -96,9 +96,23 @@ typedef struct { pack_opttbl_t *op_tbl; /*table with all -c and -f options */ int all_layout; /*apply the layout to all objects */ int all_filter; /*apply the filter to all objects */ + +#if defined (NOT_ALL) + filter_info_t filter_g; /*global filter INFO for the ALL case */ + + +#else + + filter_info_t filter_g[H5_REPACK_MAX_NFILTERS]; /*global filter array for the ALL case */ + int n_filter_g; /*number of global filters */ + +#endif + chunk_info_t chunk_g; /*global chunk INFO for the ALL case */ H5D_layout_t layout_g; /*global layout information for the ALL case */ + + int verbose; /*verbose mode */ hsize_t threshold; /*minimum size to compress, in bytes */ int use_native; /*use a native type in write */ @@ -142,9 +156,6 @@ int h5repack_cmpdcpl (const char *fname1, */ -int check_objects(const char* fname, - pack_opt_t *options); - int copy_objects(const char* fnamein, const char* fnameout, pack_opt_t *options); @@ -158,7 +169,6 @@ int do_copy_refobjs(hid_t fidin, void read_info(const char *filename,pack_opt_t *options); void init_packobject(pack_info_t *obj); int print_filters(hid_t dcpl_id); -int have_request(pack_opt_t *options); @@ -221,15 +231,14 @@ pack_info_t* options_get_object( const char *path, obj_list_t* parse_filter(const char *str, int *n_objs, filter_info_t *filt, - pack_opt_t *options); + pack_opt_t *options, + int *is_glb); obj_list_t* parse_layout(const char *str, int *n_objs, pack_info_t *pack, /* info about object */ pack_opt_t *options); -const char* get_sfilter (H5Z_filter_t filtn); -int parse_number(char *str); diff --git a/tools/h5repack/h5repack_copy.c b/tools/h5repack/h5repack_copy.c index 848b609..c4b3a69 100644 --- a/tools/h5repack/h5repack_copy.c +++ b/tools/h5repack/h5repack_copy.c @@ -903,143 +903,143 @@ int copy_attr(hid_t loc_in, pack_opt_t *options ) { - hid_t attr_id=-1; /* attr ID */ - hid_t attr_out=-1; /* attr ID */ - hid_t space_id=-1; /* space ID */ - hid_t ftype_id=-1; /* file type ID */ - hid_t wtype_id=-1; /* read/write type ID */ - size_t msize; /* size of type */ - void *buf=NULL; /* data buffer */ - hsize_t nelmts; /* number of elements in dataset */ - int rank; /* rank of dataset */ - hsize_t dims[H5S_MAX_RANK];/* dimensions of dataset */ - char name[255]; - H5O_info_t oinfo; /* Object info */ - int j; - unsigned u; - - if(H5Oget_info(loc_in, &oinfo) < 0) - goto error; - -/*------------------------------------------------------------------------- - * copy all attributes - *------------------------------------------------------------------------- - */ - - for ( u = 0; u < (unsigned)oinfo.num_attrs; u++) - { - - buf=NULL; - - /* open attribute */ - if((attr_id = H5Aopen_by_idx(loc_in, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)u, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto error; - - /* get name */ - if (H5Aget_name( attr_id, (size_t)255, name ) < 0) - goto error; - - /* get the file datatype */ - if ((ftype_id = H5Aget_type( attr_id )) < 0 ) - goto error; - - /* get the dataspace handle */ - if ((space_id = H5Aget_space( attr_id )) < 0 ) - goto error; - - /* get dimensions */ - if ( (rank = H5Sget_simple_extent_dims(space_id, dims, NULL)) < 0 ) - goto error; - - nelmts=1; - for (j=0; j<rank; j++) - nelmts*=dims[j]; - - if (options->use_native==1) - wtype_id = h5tools_get_native_type(ftype_id); - else - wtype_id = H5Tcopy(ftype_id); - - if ((msize=H5Tget_size(wtype_id))==0) - goto error; - -/*------------------------------------------------------------------------- - * object references are a special case - * we cannot just copy the buffers, but instead we recreate the reference - * this is done on a second sweep of the file that just copies - * the referenced objects - *------------------------------------------------------------------------- - */ - - if (H5T_REFERENCE==H5Tget_class(wtype_id)) - { - ; - } - else - { - /*------------------------------------------------------------------------- - * read to memory - *------------------------------------------------------------------------- - */ - - buf = (void *)HDmalloc((size_t)(nelmts * msize)); - if(buf == NULL) { - error_msg(progname, "cannot read into memory\n" ); - goto error; - } - if(H5Aread(attr_id, wtype_id, buf) < 0) - goto error; - + hid_t attr_id=-1; /* attr ID */ + hid_t attr_out=-1; /* attr ID */ + hid_t space_id=-1; /* space ID */ + hid_t ftype_id=-1; /* file type ID */ + hid_t wtype_id=-1; /* read/write type ID */ + size_t msize; /* size of type */ + void *buf=NULL; /* data buffer */ + hsize_t nelmts; /* number of elements in dataset */ + int rank; /* rank of dataset */ + hsize_t dims[H5S_MAX_RANK];/* dimensions of dataset */ + char name[255]; + H5O_info_t oinfo; /* object info */ + int j; + unsigned u; + + if(H5Oget_info(loc_in, &oinfo) < 0) + goto error; + /*------------------------------------------------------------------------- - * copy + * copy all attributes *------------------------------------------------------------------------- */ - - if((attr_out = H5Acreate2(loc_out, name, ftype_id, space_id, H5P_DEFAULT, H5P_DEFAULT)) < 0) - goto error; - if(H5Awrite(attr_out, wtype_id, buf) < 0) - goto error; - - /*close*/ - if(H5Aclose(attr_out) < 0) - goto error; - - - if(buf) - free(buf); - - } /*H5T_REFERENCE*/ - - - if(options->verbose) - printf(FORMAT_OBJ_ATTR, "attr", name); - -/*------------------------------------------------------------------------- - * close - *------------------------------------------------------------------------- - */ - - if (H5Tclose(ftype_id) < 0) goto error; - if (H5Tclose(wtype_id) < 0) goto error; - if (H5Sclose(space_id) < 0) goto error; - if (H5Aclose(attr_id) < 0) goto error; - - } /* u */ - - - return 0; - + + for ( u = 0; u < (unsigned)oinfo.num_attrs; u++) + { + + buf=NULL; + + /* open attribute */ + if((attr_id = H5Aopen_by_idx(loc_in, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)u, H5P_DEFAULT, H5P_DEFAULT)) < 0) + goto error; + + /* get name */ + if (H5Aget_name( attr_id, (size_t)255, name ) < 0) + goto error; + + /* get the file datatype */ + if ((ftype_id = H5Aget_type( attr_id )) < 0 ) + goto error; + + /* get the dataspace handle */ + if ((space_id = H5Aget_space( attr_id )) < 0 ) + goto error; + + /* get dimensions */ + if ( (rank = H5Sget_simple_extent_dims(space_id, dims, NULL)) < 0 ) + goto error; + + nelmts=1; + for (j=0; j<rank; j++) + nelmts*=dims[j]; + + if (options->use_native==1) + wtype_id = h5tools_get_native_type(ftype_id); + else + wtype_id = H5Tcopy(ftype_id); + + if ((msize=H5Tget_size(wtype_id))==0) + goto error; + + /*------------------------------------------------------------------------- + * object references are a special case + * we cannot just copy the buffers, but instead we recreate the reference + * this is done on a second sweep of the file that just copies + * the referenced objects + *------------------------------------------------------------------------- + */ + + if (H5T_REFERENCE==H5Tget_class(wtype_id)) + { + ; + } + else + { + /*------------------------------------------------------------------------- + * read to memory + *------------------------------------------------------------------------- + */ + + buf = (void *)HDmalloc((size_t)(nelmts * msize)); + if(buf == NULL) { + error_msg(progname, "cannot read into memory\n" ); + goto error; + } + if(H5Aread(attr_id, wtype_id, buf) < 0) + goto error; + + /*------------------------------------------------------------------------- + * copy + *------------------------------------------------------------------------- + */ + + if((attr_out = H5Acreate2(loc_out, name, ftype_id, space_id, H5P_DEFAULT, H5P_DEFAULT)) < 0) + goto error; + if(H5Awrite(attr_out, wtype_id, buf) < 0) + goto error; + + /*close*/ + if(H5Aclose(attr_out) < 0) + goto error; + + + if(buf) + free(buf); + + } /*H5T_REFERENCE*/ + + + if(options->verbose) + printf(FORMAT_OBJ_ATTR, "attr", name); + + /*------------------------------------------------------------------------- + * close + *------------------------------------------------------------------------- + */ + + if (H5Tclose(ftype_id) < 0) goto error; + if (H5Tclose(wtype_id) < 0) goto error; + if (H5Sclose(space_id) < 0) goto error; + if (H5Aclose(attr_id) < 0) goto error; + + } /* u */ + + + return 0; + error: - H5E_BEGIN_TRY { - H5Tclose(ftype_id); - H5Tclose(wtype_id); - H5Sclose(space_id); - H5Aclose(attr_id); - H5Aclose(attr_out); - if (buf) - free(buf); - } H5E_END_TRY; - return -1; + H5E_BEGIN_TRY { + H5Tclose(ftype_id); + H5Tclose(wtype_id); + H5Sclose(space_id); + H5Aclose(attr_id); + H5Aclose(attr_out); + if (buf) + free(buf); + } H5E_END_TRY; + return -1; } @@ -1056,96 +1056,96 @@ static void print_dataset_info(hid_t dcpl_id, char *objname, double per) { - char strfilter[255]; + char strfilter[255]; #if defined (PRINT_DEBUG ) - char temp[255]; + char temp[255]; #endif - int nfilters; /* number of filters */ - unsigned filt_flags; /* filter flags */ - H5Z_filter_t filtn; /* filter identification number */ - unsigned cd_values[20]; /* filter client data values */ - size_t cd_nelmts; /* filter client number of values */ - char f_objname[256]; /* filter objname */ - int i; - - - strcpy(strfilter,"\0"); - - /* get information about input filters */ - if((nfilters = H5Pget_nfilters(dcpl_id)) < 0) - return; - - for(i = 0; i < nfilters; i++) { - cd_nelmts = NELMTS(cd_values); - - filtn = H5Pget_filter2(dcpl_id, (unsigned)i, &filt_flags, &cd_nelmts, - cd_values, sizeof(f_objname), f_objname, NULL); - - switch(filtn) { - default: - break; - - case H5Z_FILTER_DEFLATE: - strcat(strfilter,"GZIP "); - + int nfilters; /* number of filters */ + unsigned filt_flags; /* filter flags */ + H5Z_filter_t filtn; /* filter identification number */ + unsigned cd_values[20]; /* filter client data values */ + size_t cd_nelmts; /* filter client number of values */ + char f_objname[256]; /* filter objname */ + int i; + + + strcpy(strfilter,"\0"); + + /* get information about input filters */ + if((nfilters = H5Pget_nfilters(dcpl_id)) < 0) + return; + + for(i = 0; i < nfilters; i++) { + cd_nelmts = NELMTS(cd_values); + + filtn = H5Pget_filter2(dcpl_id, (unsigned)i, &filt_flags, &cd_nelmts, + cd_values, sizeof(f_objname), f_objname, NULL); + + switch(filtn) { + default: + break; + + case H5Z_FILTER_DEFLATE: + strcat(strfilter,"GZIP "); + #if defined (PRINT_DEBUG) - { - unsigned level=cd_values[0]; - sprintf(temp,"(%d)",level); - strcat(strfilter,temp); - } + { + unsigned level=cd_values[0]; + sprintf(temp,"(%d)",level); + strcat(strfilter,temp); + } #endif - break; - - case H5Z_FILTER_SZIP: - strcat(strfilter,"SZIP "); - + break; + + case H5Z_FILTER_SZIP: + strcat(strfilter,"SZIP "); + #if defined (PRINT_DEBUG) - { - unsigned options_mask=cd_values[0]; /* from dcpl, not filt*/ - unsigned ppb=cd_values[1]; - sprintf(temp,"(%d,",ppb); - strcat(strfilter,temp); - if (options_mask & H5_SZIP_EC_OPTION_MASK) - strcpy(temp,"EC) "); - else if (options_mask & H5_SZIP_NN_OPTION_MASK) - strcpy(temp,"NN) "); - } - strcat(strfilter,temp); - + { + unsigned options_mask=cd_values[0]; /* from dcpl, not filt*/ + unsigned ppb=cd_values[1]; + sprintf(temp,"(%d,",ppb); + strcat(strfilter,temp); + if (options_mask & H5_SZIP_EC_OPTION_MASK) + strcpy(temp,"EC) "); + else if (options_mask & H5_SZIP_NN_OPTION_MASK) + strcpy(temp,"NN) "); + } + strcat(strfilter,temp); + #endif - - break; - - case H5Z_FILTER_SHUFFLE: - strcat(strfilter,"SHUF "); - break; - - case H5Z_FILTER_FLETCHER32: - strcat(strfilter,"FLET "); - break; - - case H5Z_FILTER_NBIT: - strcat(strfilter,"NBIT "); - break; - - case H5Z_FILTER_SCALEOFFSET: - strcat(strfilter,"SCALEOFFSET "); - break; - } /* switch */ - }/*i*/ - - if(*strfilter == '\0') - printf(FORMAT_OBJ,"dset",objname ); - else - { - char str[255], temp[20]; - strcpy(str,"dset "); - strcat(str,strfilter); - sprintf(temp," (%.1f%%)",per); - strcat(str,temp); - printf(FORMAT_OBJ,str,objname); - } + + break; + + case H5Z_FILTER_SHUFFLE: + strcat(strfilter,"SHUF "); + break; + + case H5Z_FILTER_FLETCHER32: + strcat(strfilter,"FLET "); + break; + + case H5Z_FILTER_NBIT: + strcat(strfilter,"NBIT "); + break; + + case H5Z_FILTER_SCALEOFFSET: + strcat(strfilter,"SCALEOFFSET "); + break; + } /* switch */ + }/*i*/ + + if(*strfilter == '\0') + printf(FORMAT_OBJ,"dset",objname ); + else + { + char str[255], temp[20]; + strcpy(str,"dset "); + strcat(str,strfilter); + sprintf(temp," (%.1f%%)",per); + strcat(str,temp); + printf(FORMAT_OBJ,str,objname); + } } /*------------------------------------------------------------------------- diff --git a/tools/h5repack/h5repack_filters.c b/tools/h5repack/h5repack_filters.c index 0e7a557..c1c001c 100644 --- a/tools/h5repack/h5repack_filters.c +++ b/tools/h5repack/h5repack_filters.c @@ -122,7 +122,7 @@ int aux_assign_obj(const char* name, /* object name from traverse lis { /* assign the global filter */ tmp.nfilters=1; - tmp.filter[0]=options->filter_g; + tmp.filter[0]=options->filter_g[0]; } /* if all */ else { @@ -144,9 +144,12 @@ int aux_assign_obj(const char* name, /* object name from traverse lis if (options->all_filter) { - /* assign the global filter */ - tmp.nfilters=1; - tmp.filter[0]=options->filter_g; + int k; + + /* assign the global filters */ + tmp.nfilters=options->n_filter_g; + for ( k = 0; k < options->n_filter_g; k++) + tmp.filter[k]=options->filter_g[k]; } if (options->all_layout) { @@ -424,36 +427,36 @@ int apply_filters(const char* name, /* object name from traverse list */ int print_filters(hid_t dcpl_id) { - int nfilters; /* number of filters */ - unsigned filt_flags; /* filter flags */ - H5Z_filter_t filtn; /* filter identification number */ - unsigned cd_values[20]; /* filter client data values */ - size_t cd_nelmts; /* filter client number of values */ - size_t cd_num; /* filter client data counter */ - char f_name[256]; /* filter name */ - char s[64]; /* temporary string buffer */ - int i; - - /* get information about filters */ - if((nfilters = H5Pget_nfilters(dcpl_id)) < 0) - return -1; - - for(i = 0; i < nfilters; i++) { - cd_nelmts = NELMTS(cd_values); - filtn = H5Pget_filter2(dcpl_id, (unsigned)i, &filt_flags, &cd_nelmts, - cd_values, sizeof(f_name), f_name, NULL); - - f_name[sizeof(f_name)-1] = '\0'; - sprintf(s, "Filter-%d:", i); - printf(" %-10s %s-%u %s {", s, - f_name[0] ? f_name : "method", - (unsigned)filtn, - filt_flags & H5Z_FLAG_OPTIONAL?"OPT":""); - for(cd_num = 0; cd_num < cd_nelmts; cd_num++) - printf("%s%u", cd_num?", ":"", cd_values[cd_num]); - printf("}\n"); - } - - return 0; + int nfilters; /* number of filters */ + unsigned filt_flags; /* filter flags */ + H5Z_filter_t filtn; /* filter identification number */ + unsigned cd_values[20]; /* filter client data values */ + size_t cd_nelmts; /* filter client number of values */ + size_t cd_num; /* filter client data counter */ + char f_name[256]; /* filter name */ + char s[64]; /* temporary string buffer */ + int i; + + /* get information about filters */ + if((nfilters = H5Pget_nfilters(dcpl_id)) < 0) + return -1; + + for(i = 0; i < nfilters; i++) { + cd_nelmts = NELMTS(cd_values); + filtn = H5Pget_filter2(dcpl_id, (unsigned)i, &filt_flags, &cd_nelmts, + cd_values, sizeof(f_name), f_name, NULL); + + f_name[sizeof(f_name)-1] = '\0'; + sprintf(s, "Filter-%d:", i); + printf(" %-10s %s-%u %s {", s, + f_name[0] ? f_name : "method", + (unsigned)filtn, + filt_flags & H5Z_FLAG_OPTIONAL?"OPT":""); + for(cd_num = 0; cd_num < cd_nelmts; cd_num++) + printf("%s%u", cd_num?", ":"", cd_values[cd_num]); + printf("}\n"); + } + + return 0; } diff --git a/tools/h5repack/h5repack_list.c b/tools/h5repack/h5repack_list.c deleted file mode 100644 index 4e1e072..0000000 --- a/tools/h5repack/h5repack_list.c +++ /dev/null @@ -1,153 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * Copyright by the Board of Trustees of the University of Illinois. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the files COPYING and Copyright.html. COPYING can be found at the root * - * of the source code distribution tree; Copyright.html can be found at the * - * root level of an installed copy of the electronic HDF5 document set and * - * is linked from the top-level documents page. It can also be found at * - * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have * - * access to either file, you may request a copy from help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -#include <stdlib.h> -#include <string.h> -#include <stdio.h> -#include "h5repack.h" -#include "H5private.h" -#include "h5tools_utils.h" -#include "h5diff.h" -#include "h5tools.h" - -extern char *progname; - -/*------------------------------------------------------------------------- - * Function: check_objects - * - * Purpose: locate all HDF5 objects in the file and compare with user - * supplied list - * - * Return: 0, ok, -1 no - * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: September, 23, 2003 - * - *------------------------------------------------------------------------- - */ -int check_objects(const char* fname, - pack_opt_t *options) -{ - hid_t fid; - unsigned int i; - trav_table_t *travt = NULL; - - /* nothing to do */ - if(options->op_tbl->nelems == 0) - return 0; - - /*------------------------------------------------------------------------- - * open the file - *------------------------------------------------------------------------- - */ - if((fid = h5tools_fopen(fname, H5F_ACC_RDONLY, H5P_DEFAULT, NULL, NULL, 0)) < 0){ - printf("<%s>: %s\n", fname, H5FOPENERROR ); - return -1; - } - - /*------------------------------------------------------------------------- - * get the list of objects in the file - *------------------------------------------------------------------------- - */ - - /* init table */ - trav_table_init(&travt); - - /* get the list of objects in the file */ - if(h5trav_gettable(fid, travt) < 0) - goto out; - - /*------------------------------------------------------------------------- - * compare with user supplied list - *------------------------------------------------------------------------- - */ - - if(options->verbose) - printf("Opening file <%s>. Searching for objects to modify...\n", fname); - - for(i = 0; i < options->op_tbl->nelems; i++) { - char* name=options->op_tbl->objs[i].path; - if(options->verbose) - printf(" <%s>",name); - - /* the input object names are present in the file and are valid */ - if(h5trav_getindext(name, travt) < 0) { - error_msg(progname, "%s Could not find <%s> in file <%s>. Exiting...\n", - (options->verbose?"\n":""),name,fname); - goto out; - } - if(options->verbose) - printf("...Found\n"); - - /* check for extra filter conditions */ - switch(options->op_tbl->objs[i].filter->filtn) { - /* chunk size must be smaller than pixels per block */ - case H5Z_FILTER_SZIP: - { - int j; - int csize = 1; - int ppb = options->op_tbl->objs[i].filter->cd_values[0]; - hsize_t dims[H5S_MAX_RANK]; - int rank; - hid_t did; - hid_t sid; - - if(options->op_tbl->objs[i].chunk.rank > 0) { - rank = options->op_tbl->objs[i].chunk.rank; - for(j = 0; j < rank; j++) - csize *= (int)options->op_tbl->objs[i].chunk.chunk_lengths[j]; - } - else { - if((did = H5Dopen2(fid, name, H5P_DEFAULT)) < 0) - goto out; - if((sid = H5Dget_space(did)) < 0) - goto out; - if((rank = H5Sget_simple_extent_ndims(sid)) < 0) - goto out; - HDmemset(dims, 0, sizeof dims); - if(H5Sget_simple_extent_dims(sid, dims, NULL) < 0) - goto out; - for(j = 0; j < rank; j++) - csize *= (int)dims[j]; - if(H5Sclose(sid) < 0) - goto out; - if(H5Dclose(did) < 0) - goto out; - } - - if (csize < ppb ) { - printf(" <warning: SZIP settins, chunk size is smaller than pixels per block>\n"); - goto out; - } - } - break; - } - } /* i */ - - /*------------------------------------------------------------------------- - * close - *------------------------------------------------------------------------- - */ - H5Fclose(fid); - trav_table_free(travt); - return 0; - -out: - H5Fclose(fid); - trav_table_free(travt); - return -1; -} - diff --git a/tools/h5repack/h5repack_main.c b/tools/h5repack/h5repack_main.c index 4a07814..22b1709 100644 --- a/tools/h5repack/h5repack_main.c +++ b/tools/h5repack/h5repack_main.c @@ -15,18 +15,15 @@ #include <stdlib.h> #include <string.h> +#include <ctype.h> + #include "h5tools_utils.h" #include "h5repack.h" -#if 0 -#define OLD -#endif -#if defined (OLD) -static void usage(void); -#else static void usage(const char *prog); -#endif +static int parse_number(char *str); +static void parse_command_line(int argc, const char* argv[], pack_opt_t* options); /* module-scoped variables */ @@ -54,297 +51,8 @@ static struct long_options l_opts[] = { { NULL, 0, '\0' } }; -/*------------------------------------------------------------------------- - * Function: parse_command_line - * - * Purpose: parse command line input - * - *------------------------------------------------------------------------- - */ - -#if 0 -#define OLD -#endif - -#if defined (OLD) - - -void parse_command_line(int argc, - const char* argv[], - char** fname1, - char** fname2, - pack_opt_t* options) -{ - - int i; - - if (argc<2) - { - usage(); - exit(1); - } - - for ( i = 1; i < argc; i++) - { - if (strcmp(argv[i], "-h") == 0) { - usage(); - exit(0); - } - else if (strcmp(argv[i], "-V") == 0) { - print_version(progname); - exit(0); - } - else if (strcmp(argv[i], "-i") == 0) { - *fname1 = argv[++i]; - } - else if (strcmp(argv[i], "-o") == 0) { - *fname2 = argv[++i]; - } - else if (strcmp(argv[i], "-v") == 0) { - options->verbose = 1; - } - else if (strcmp(argv[i], "-f") == 0) { - - /* add the -f filter option */ - if (h5repack_addfilter(argv[i+1], options)<0) - { - error_msg(progname, "in parsing filter\n"); - exit(1); - } - - /* jump to next */ - ++i; - } - else if (strcmp(argv[i], "-l") == 0) { - - /* parse the -l layout option */ - if (h5repack_addlayout(argv[i+1], options)<0) - { - error_msg(progname, "in parsing layout\n"); - exit(1); - } - - /* 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); - } - ++i; - } - - else if (strcmp(argv[i], "-e") == 0) { - read_info(argv[++i], options); - } - else if (strcmp(argv[i], "-n") == 0) { - options->use_native = 1; - } - - else if ( (strcmp(argv[i], "-L") == 0) || (strcmp(argv[i], "--latest") == 0)) { - options->latest = 1; - } - - else if ( strncmp(argv[i], "-compact=", 9) == 0 ) { - options->grp_compact = atoi(argv[i]+9); - if (options->grp_compact>0) - options->latest = 1; /* must use latest format */ - } - - else if ( strncmp(argv[i], "-indexed=", 9) == 0 ) { - options->grp_indexed = atoi(argv[i]+9); - if (options->grp_indexed>0) - options->latest = 1; /* must use latest format */ - } - - else if ( strncmp(argv[i], "-ssize=", 7) == 0 ) { - int idx = 0; - int ssize = 0; - char *msgPtr = strchr(argv[i]+7, ':'); - options->latest = 1; /* must use latest format */ - if (msgPtr == NULL) { - ssize = atoi(argv[i]+7); - for (idx=0; idx<5; idx++) - options->msg_size[idx] = ssize; - } - else { - char msgType[10]; - strcpy(msgType, msgPtr+1); - msgPtr[0] = '\0'; - ssize = atoi(argv[i]+7); - if (strcmp(msgType, "dspace") == 0) { - options->msg_size[0] = ssize; - } - else if (strcmp(msgType, "dtype") == 0) { - options->msg_size[1] = ssize; - } - else if (strcmp(msgType, "fill") == 0) { - options->msg_size[2] = ssize; - } - else if (strcmp(msgType, "pline") == 0) { - options->msg_size[3] = ssize; - } - else if (strcmp(msgType, "attr") == 0) { - options->msg_size[4] = ssize; - } - } - } /* else if ( strncmp(argv[i], "-ssize=", 7) == 0 ) */ - - else if (argv[i][0] == '-') { - error_msg(progname, " - is not a valid argument\n"); - usage(); - exit(1); - } - - } - - -} -#else -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': - - /* parse the -f filter option */ - if (h5repack_addfilter( opt_arg, options)<0) - { - error_msg(progname, "in parsing filter\n"); - exit(EXIT_FAILURE); - } - break; - case 'l': - - /* parse the -l layout option */ - if (h5repack_addlayout( opt_arg, options)<0) - { - error_msg(progname, "in parsing layout\n"); - exit(EXIT_FAILURE); - } - break; - - - 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); - } - break; - - case 'e': - read_info( opt_arg, options); - break; - - case 'n': - options->use_native = 1; - break; - - case 'L': - options->latest = 1; - break; - - case 'c': - - options->grp_compact = atoi( opt_arg ); - if (options->grp_compact>0) - options->latest = 1; /* must use latest format */ - break; - - - case 'i': - - options->grp_indexed = atoi( opt_arg ); - if (options->grp_indexed>0) - options->latest = 1; /* must use latest format */ - break; - - case 's': - - { - - int idx = 0; - int ssize = 0; - char *msgPtr = strchr( opt_arg, ':'); - options->latest = 1; /* must use latest format */ - if (msgPtr == NULL) - { - ssize = atoi( opt_arg ); - for (idx=0; idx<5; idx++) - options->msg_size[idx] = ssize; - } - else - { - char msgType[10]; - strcpy(msgType, msgPtr+1); - msgPtr[0] = '\0'; - ssize = atoi( opt_arg ); - if (strcmp(msgType, "dspace") == 0) { - options->msg_size[0] = ssize; - } - else if (strcmp(msgType, "dtype") == 0) { - options->msg_size[1] = ssize; - } - else if (strcmp(msgType, "fill") == 0) { - options->msg_size[2] = ssize; - } - else if (strcmp(msgType, "pline") == 0) { - options->msg_size[3] = ssize; - } - else if (strcmp(msgType, "attr") == 0) { - options->msg_size[4] = ssize; - } - } - } - - break; - - } /* switch */ - - - } /* while */ - - /* check for file names to be processed */ - if (argc <= opt_ind || argv[ opt_ind + 1 ] == NULL) - { - error_msg(progname, "missing file names\n"); - usage(progname); - exit(EXIT_FAILURE); - } - - - - - -} - - -#endif /*------------------------------------------------------------------------- * Function: main @@ -381,13 +89,6 @@ int main(int argc, char **argv) /* initialize options */ h5repack_init (&options,0); -#if defined (OLD) - - parse_command_line(argc, argv, &infile, &outfile, &options); - - -#else - parse_command_line(argc, argv, &options); if ( argv[ opt_ind ] != NULL && argv[ opt_ind + 1 ] != NULL ) @@ -403,8 +104,7 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } -#endif - + /* pack it */ ret=h5repack(infile,outfile,&options); @@ -428,92 +128,6 @@ int main(int argc, char **argv) * *------------------------------------------------------------------------- */ - -#if defined OLD -static void usage(void) -{ - printf("usage: h5repack [-h] [-v] [-V] [-n] [-L] [-c] [-i] [-s] [-m size] [-e file] [-f FILTER] [-l LAYOUT] file1 file2\n"); - printf("\n"); - printf("file1 Input HDF5 File\n"); - printf("file2 Output HDF5 File\n"); - printf("[-h] Print this message\n"); - printf("[-v] Verbose mode, print object information\n"); - printf("[-V] Print HDF5 version number and exit\n"); - printf("[-n] Use a native HDF5 type when repacking. Default is the file type\n"); - printf("[-L, --latest] Use latest version of file format to create groups, datasets and datatypes\n"); - printf("[-c <size>, --compact=<size>] Set the maximum number of links to store as header messages in a group\n"); - printf("[-i <size>, --indexed=<size>] Set the minimum number of links to store in the indexed format\n"); - printf("[-s, --ssize=<size>[:<dspace|dtype|fill|pline|attr>]] Set the shared object header message minimum size\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(" NBIT, to apply the HDF5 NBIT filter (NBIT compression)\n"); - printf(" SOFF, to apply the HDF5 Scale/Offset 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(" NBIT (no parameter)\n"); - printf(" SOFF=<scale_factor,scale_type> scale_factor is an integer and scale_type\n"); - printf(" is either IN or DS\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"); - printf("4) h5repack -L -compact=10 -ssize=20:dtype -i file1 -o file2 \n"); - printf("\n"); - printf(" Using latest file format with maximum compact group size fo 10 and minimum shared datatype size of 20\n"); - printf("\n"); -} - -#else - static void usage(const char *prog) { printf("usage: %s [OPTIONS] file1 file2\n", prog); @@ -606,5 +220,180 @@ static void usage(const char *prog) printf("\n"); } -#endif + +/*------------------------------------------------------------------------- + * 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': + + /* parse the -f filter option */ + if (h5repack_addfilter( opt_arg, options)<0) + { + error_msg(progname, "in parsing filter\n"); + exit(EXIT_FAILURE); + } + break; + case 'l': + + /* parse the -l layout option */ + if (h5repack_addlayout( opt_arg, options)<0) + { + error_msg(progname, "in parsing layout\n"); + exit(EXIT_FAILURE); + } + break; + + + 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); + } + break; + + case 'e': + read_info( opt_arg, options); + break; + + case 'n': + options->use_native = 1; + break; + + case 'L': + options->latest = 1; + break; + + case 'c': + + options->grp_compact = atoi( opt_arg ); + if (options->grp_compact>0) + options->latest = 1; /* must use latest format */ + break; + + + case 'i': + + options->grp_indexed = atoi( opt_arg ); + if (options->grp_indexed>0) + options->latest = 1; /* must use latest format */ + break; + + case 's': + + { + + int idx = 0; + int ssize = 0; + char *msgPtr = strchr( opt_arg, ':'); + options->latest = 1; /* must use latest format */ + if (msgPtr == NULL) + { + ssize = atoi( opt_arg ); + for (idx=0; idx<5; idx++) + options->msg_size[idx] = ssize; + } + else + { + char msgType[10]; + strcpy(msgType, msgPtr+1); + msgPtr[0] = '\0'; + ssize = atoi( opt_arg ); + if (strcmp(msgType, "dspace") == 0) { + options->msg_size[0] = ssize; + } + else if (strcmp(msgType, "dtype") == 0) { + options->msg_size[1] = ssize; + } + else if (strcmp(msgType, "fill") == 0) { + options->msg_size[2] = ssize; + } + else if (strcmp(msgType, "pline") == 0) { + options->msg_size[3] = ssize; + } + else if (strcmp(msgType, "attr") == 0) { + options->msg_size[4] = ssize; + } + } + } + + break; + + } /* switch */ + + + } /* while */ + + /* check for file names to be processed */ + if (argc <= opt_ind || argv[ opt_ind + 1 ] == NULL) + { + 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); + + for ( i=0; i<len; i++) + { + c = str[i]; + if (!isdigit(c)){ + return -1; + } + } + str[i]='\0'; + n=atoi(str); + return n; +} diff --git a/tools/h5repack/h5repack_opttable.c b/tools/h5repack/h5repack_opttable.c index 8492885..b740274 100644 --- a/tools/h5repack/h5repack_opttable.c +++ b/tools/h5repack/h5repack_opttable.c @@ -32,19 +32,19 @@ extern char *progname; void init_packobject(pack_info_t *obj) { - int j, k; - - strcpy(obj->path,"\0"); - for ( j=0; j<H5_REPACK_MAX_NFILTERS; j++) - { - obj->filter[j].filtn = -1; - for ( k=0; k<CDVALUES; k++) - obj->filter[j].cd_values[k] = -1; - } - obj->chunk.rank = -1; - obj->refobj_id = -1; - obj->layout = H5D_LAYOUT_ERROR; - obj->nfilters = 0; + int j, k; + + strcpy(obj->path,"\0"); + for ( j=0; j<H5_REPACK_MAX_NFILTERS; j++) + { + obj->filter[j].filtn = -1; + for ( k=0; k<CDVALUES; k++) + obj->filter[j].cd_values[k] = -1; + } + obj->chunk.rank = -1; + obj->refobj_id = -1; + obj->layout = H5D_LAYOUT_ERROR; + obj->nfilters = 0; } /*------------------------------------------------------------------------- @@ -61,15 +61,15 @@ static void aux_tblinsert_filter(pack_opttbl_t *table, unsigned int I, filter_info_t filt) { - if (table->objs[ I ].nfilters<H5_REPACK_MAX_NFILTERS) - { - table->objs[ I ].filter[ table->objs[ I ].nfilters++ ] = filt; - } - else - { - error_msg(progname, "cannot insert the filter in this object.\ - Maximum capacity exceeded\n"); - } + if (table->objs[ I ].nfilters<H5_REPACK_MAX_NFILTERS) + { + table->objs[ I ].filter[ table->objs[ I ].nfilters++ ] = filt; + } + else + { + error_msg(progname, "cannot insert the filter in this object.\ + Maximum capacity exceeded\n"); + } } /*------------------------------------------------------------------------- @@ -86,26 +86,26 @@ static void aux_tblinsert_layout(pack_opttbl_t *table, unsigned int I, pack_info_t *pack) { - int k; - - table->objs[I].layout = pack->layout; - if (H5D_CHUNKED==pack->layout) - { - /* -2 means the NONE option, remove chunking - and set the layout to contiguous */ - if (pack->chunk.rank==-2) - { - table->objs[I].layout = H5D_CONTIGUOUS; - table->objs[I].chunk.rank = -2; - } - /* otherwise set the chunking type */ - else - { - table->objs[I].chunk.rank = pack->chunk.rank; - for (k = 0; k < pack->chunk.rank; k++) - table->objs[I].chunk.chunk_lengths[k] = pack->chunk.chunk_lengths[k]; - } - } + int k; + + table->objs[I].layout = pack->layout; + if (H5D_CHUNKED==pack->layout) + { + /* -2 means the NONE option, remove chunking + and set the layout to contiguous */ + if (pack->chunk.rank==-2) + { + table->objs[I].layout = H5D_CONTIGUOUS; + table->objs[I].chunk.rank = -2; + } + /* otherwise set the chunking type */ + else + { + table->objs[I].chunk.rank = pack->chunk.rank; + for (k = 0; k < pack->chunk.rank; k++) + table->objs[I].chunk.chunk_lengths[k] = pack->chunk.chunk_lengths[k]; + } + } } @@ -121,19 +121,19 @@ static void aux_tblinsert_layout(pack_opttbl_t *table, static int aux_inctable(pack_opttbl_t *table, int n_objs ) { - unsigned int i; - - table->size += n_objs; - table->objs = (pack_info_t*)realloc(table->objs, table->size * sizeof(pack_info_t)); - if (table->objs==NULL) { - error_msg(progname, "not enough memory for options table\n"); - return -1; - } - for (i = table->nelems; i < table->size; i++) - { - init_packobject(&table->objs[i]); - } - return 0; + unsigned int i; + + table->size += n_objs; + table->objs = (pack_info_t*)realloc(table->objs, table->size * sizeof(pack_info_t)); + if (table->objs==NULL) { + error_msg(progname, "not enough memory for options table\n"); + return -1; + } + for (i = table->nelems; i < table->size; i++) + { + init_packobject(&table->objs[i]); + } + return 0; } /*------------------------------------------------------------------------- @@ -148,28 +148,28 @@ static int aux_inctable(pack_opttbl_t *table, int n_objs ) int options_table_init( pack_opttbl_t **tbl ) { - unsigned int i; - pack_opttbl_t* table = (pack_opttbl_t*) malloc(sizeof(pack_opttbl_t)); - if (table==NULL) { - error_msg(progname, "not enough memory for options table\n"); - return -1; - } - - table->size = 30; - table->nelems = 0; - table->objs = (pack_info_t*) malloc(table->size * sizeof(pack_info_t)); - if (table->objs==NULL) { - error_msg(progname, "not enough memory for options table\n"); - return -1; - } - - for ( i=0; i<table->size; i++) - { - init_packobject(&table->objs[i]); - } - - *tbl = table; - return 0; + unsigned int i; + pack_opttbl_t* table = (pack_opttbl_t*) malloc(sizeof(pack_opttbl_t)); + if (table==NULL) { + error_msg(progname, "not enough memory for options table\n"); + return -1; + } + + table->size = 30; + table->nelems = 0; + table->objs = (pack_info_t*) malloc(table->size * sizeof(pack_info_t)); + if (table->objs==NULL) { + error_msg(progname, "not enough memory for options table\n"); + return -1; + } + + for ( i=0; i<table->size; i++) + { + init_packobject(&table->objs[i]); + } + + *tbl = table; + return 0; } /*------------------------------------------------------------------------- @@ -184,9 +184,9 @@ int options_table_init( pack_opttbl_t **tbl ) int options_table_free( pack_opttbl_t *table ) { - free(table->objs); - free(table); - return 0; + free(table->objs); + free(table); + return 0; } /*------------------------------------------------------------------------- @@ -205,85 +205,85 @@ int options_add_layout( obj_list_t *obj_list, pack_info_t *pack, pack_opttbl_t *table ) { - unsigned int i, I; - int j, added=0, found=0; - - /* increase the size of the collection by N_OBJS if necessary */ - if (table->nelems+n_objs >= table->size) - { - if (aux_inctable(table,n_objs)<0) - return -1; - } - - /* search if this object is already in the table; "path" is the key */ - if (table->nelems>0) - { - /* go tru the supplied list of names */ - for (j = 0; j < n_objs; j++) - { - /* linear table search */ - for (i = 0; i < table->nelems; i++) - { - /*already on the table */ - if (strcmp(obj_list[j].obj,table->objs[i].path)==0) + unsigned int i, I; + int j, added=0, found=0; + + /* increase the size of the collection by N_OBJS if necessary */ + if (table->nelems+n_objs >= table->size) { - /* already chunk info inserted for this one; exit */ - if (table->objs[i].chunk.rank>0) - { - error_msg(progname, "chunk information already inserted for <%s>\n",obj_list[j].obj); - exit(1); - } - /* insert the layout info */ - else - { - aux_tblinsert_layout(table,i,pack); - found=1; - break; - } - } /* if */ - } /* i */ - - if (found==0) - { - /* keep the grow in a temp var */ - I = table->nelems + added; - added++; - strcpy(table->objs[I].path,obj_list[j].obj); - aux_tblinsert_layout(table,I,pack); + if (aux_inctable(table,n_objs)<0) + return -1; } - /* cases where we have an already inserted name but there is a new name also - example: - -f dset1:GZIP=1 -l dset1,dset2:CHUNK=20x20 - dset1 is already inserted, but dset2 must also be - */ - else if (found==1 && strcmp(obj_list[j].obj,table->objs[i].path)!=0) - { - /* keep the grow in a temp var */ - I = table->nelems + added; - added++; - strcpy(table->objs[I].path,obj_list[j].obj); - aux_tblinsert_layout(table,I,pack); - } - } /* j */ - } - - /* first time insertion */ - else - { - /* go tru the supplied list of names */ - for (j = 0; j < n_objs; j++) - { - I = table->nelems + added; - added++; - strcpy(table->objs[I].path,obj_list[j].obj); - aux_tblinsert_layout(table,I,pack); - - } - } - - table->nelems+= added; - - return 0; + + /* search if this object is already in the table; "path" is the key */ + if (table->nelems>0) + { + /* go tru the supplied list of names */ + for (j = 0; j < n_objs; j++) + { + /* linear table search */ + for (i = 0; i < table->nelems; i++) + { + /*already on the table */ + if (strcmp(obj_list[j].obj,table->objs[i].path)==0) + { + /* already chunk info inserted for this one; exit */ + if (table->objs[i].chunk.rank>0) + { + error_msg(progname, "chunk information already inserted for <%s>\n",obj_list[j].obj); + exit(1); + } + /* insert the layout info */ + else + { + aux_tblinsert_layout(table,i,pack); + found=1; + break; + } + } /* if */ + } /* i */ + + if (found==0) + { + /* keep the grow in a temp var */ + I = table->nelems + added; + added++; + strcpy(table->objs[I].path,obj_list[j].obj); + aux_tblinsert_layout(table,I,pack); + } + /* cases where we have an already inserted name but there is a new name also + example: + -f dset1:GZIP=1 -l dset1,dset2:CHUNK=20x20 + dset1 is already inserted, but dset2 must also be + */ + else if (found==1 && strcmp(obj_list[j].obj,table->objs[i].path)!=0) + { + /* keep the grow in a temp var */ + I = table->nelems + added; + added++; + strcpy(table->objs[I].path,obj_list[j].obj); + aux_tblinsert_layout(table,I,pack); + } + } /* j */ + } + + /* first time insertion */ + else + { + /* go tru the supplied list of names */ + for (j = 0; j < n_objs; j++) + { + I = table->nelems + added; + added++; + strcpy(table->objs[I].path,obj_list[j].obj); + aux_tblinsert_layout(table,I,pack); + + } + } + + table->nelems+= added; + + return 0; } @@ -303,76 +303,76 @@ int options_add_filter(obj_list_t *obj_list, filter_info_t filt, pack_opttbl_t *table ) { - - unsigned int i, I; - int j, added=0, found=0; - - /* increase the size of the collection by N_OBJS if necessary */ - if (table->nelems+n_objs >= table->size) - { - if (aux_inctable(table,n_objs)<0) - return -1; - } - - /* search if this object is already in the table; "path" is the key */ - if (table->nelems>0) - { - /* go tru the supplied list of names */ - for (j = 0; j < n_objs; j++) - { - /* linear table search */ - for (i = 0; i < table->nelems; i++) - { - /*already on the table */ - if (strcmp(obj_list[j].obj,table->objs[i].path)==0) + + unsigned int i, I; + int j, added=0, found=0; + + /* increase the size of the collection by N_OBJS if necessary */ + if (table->nelems+n_objs >= table->size) { - /* insert */ - aux_tblinsert_filter(table,i,filt); - found=1; - break; - } /* if */ - } /* i */ - - if (found==0) - { - /* keep the grow in a temp var */ - I = table->nelems + added; - added++; - strcpy(table->objs[I].path,obj_list[j].obj); - aux_tblinsert_filter(table,I,filt); - } - /* cases where we have an already inserted name but there is a new name also - example: - -l dset1:CHUNK=20x20 -f dset1,dset2:GZIP=1 - dset1 is already inserted, but dset2 must also be - */ - else if (found==1 && strcmp(obj_list[j].obj,table->objs[i].path)!=0) - { - /* keep the grow in a temp var */ - I = table->nelems + added; - added++; - strcpy(table->objs[I].path,obj_list[j].obj); - aux_tblinsert_filter(table,I,filt); - } - } /* j */ - } - - /* first time insertion */ - else - { - /* go tru the supplied list of names */ - for (j = 0; j < n_objs; j++) - { - I = table->nelems + added; - added++; - strcpy(table->objs[I].path,obj_list[j].obj); - aux_tblinsert_filter(table,I,filt); - } - } - - table->nelems+= added; - - return 0; + if (aux_inctable(table,n_objs)<0) + return -1; + } + + /* search if this object is already in the table; "path" is the key */ + if (table->nelems>0) + { + /* go tru the supplied list of names */ + for (j = 0; j < n_objs; j++) + { + /* linear table search */ + for (i = 0; i < table->nelems; i++) + { + /*already on the table */ + if (strcmp(obj_list[j].obj,table->objs[i].path)==0) + { + /* insert */ + aux_tblinsert_filter(table,i,filt); + found=1; + break; + } /* if */ + } /* i */ + + if (found==0) + { + /* keep the grow in a temp var */ + I = table->nelems + added; + added++; + strcpy(table->objs[I].path,obj_list[j].obj); + aux_tblinsert_filter(table,I,filt); + } + /* cases where we have an already inserted name but there is a new name also + example: + -l dset1:CHUNK=20x20 -f dset1,dset2:GZIP=1 + dset1 is already inserted, but dset2 must also be + */ + else if (found==1 && strcmp(obj_list[j].obj,table->objs[i].path)!=0) + { + /* keep the grow in a temp var */ + I = table->nelems + added; + added++; + strcpy(table->objs[I].path,obj_list[j].obj); + aux_tblinsert_filter(table,I,filt); + } + } /* j */ + } + + /* first time insertion */ + else + { + /* go tru the supplied list of names */ + for (j = 0; j < n_objs; j++) + { + I = table->nelems + added; + added++; + strcpy(table->objs[I].path,obj_list[j].obj); + aux_tblinsert_filter(table,I,filt); + } + } + + table->nelems+= added; + + return 0; } /*------------------------------------------------------------------------- @@ -388,18 +388,18 @@ int options_add_filter(obj_list_t *obj_list, pack_info_t* options_get_object( const char *path, pack_opttbl_t *table ) { - unsigned int i; - - for ( i = 0; i < table->nelems; i++) - { - /* found it */ - if (strcmp(table->objs[i].path,path)==0) - { - return (&table->objs[i]); - } - } - - return NULL; + unsigned int i; + + for ( i = 0; i < table->nelems; i++) + { + /* found it */ + if (strcmp(table->objs[i].path,path)==0) + { + return (&table->objs[i]); + } + } + + return NULL; } diff --git a/tools/h5repack/h5repack_parse.c b/tools/h5repack/h5repack_parse.c index cf78cac..afb2271 100644 --- a/tools/h5repack/h5repack_parse.c +++ b/tools/h5repack/h5repack_parse.c @@ -17,6 +17,7 @@ #include <string.h> #include <stdio.h> #include <ctype.h> + #include "h5repack.h" #include "h5tools_utils.h" @@ -53,407 +54,376 @@ extern char *progname; obj_list_t* parse_filter(const char *str, int *n_objs, filter_info_t *filt, - pack_opt_t *options) + pack_opt_t *options, + int *is_glb) { - unsigned i, u; - char c; - size_t len=strlen(str); - int j, m, n, k, l, end_obj=-1, no_param=0; - char sobj[MAX_NC_NAME]; - char scomp[10]; - char stype[5]; - char smask[3]; - obj_list_t* obj_list=NULL; - unsigned pixels_per_block; - -#if defined(PARSE_DEBUG) - fprintf(stderr,"%s\n",str); -#endif - - /* initialize compression info */ - memset(filt,0,sizeof(filter_info_t)); - - /* check for the end of object list and number of objects */ - for ( i=0, n=0; i<len; i++) - { - c = str[i]; - if ( c==':' ) - { - end_obj=i; - } - if ( c==',' ) - { - n++; - } - } - - if (end_obj==-1) { /* missing : */ - /* apply to all objects */ - options->all_filter=1; - } - - n++; - obj_list=malloc(n*sizeof(obj_list_t)); - if (obj_list==NULL) - { - error_msg(progname, "could not allocate object list\n"); - return NULL; - } - *n_objs=n; - - /* get object list */ - for ( j=0, k=0, n=0; j<end_obj; j++,k++) - { - c = str[j]; - sobj[k]=c; - if ( c==',' || j==end_obj-1) - { - if ( c==',') sobj[k]='\0'; else sobj[k+1]='\0'; - strcpy(obj_list[n].obj,sobj); - memset(sobj,0,sizeof(sobj)); - n++; - k=-1; - } - } - /* nothing after : */ - if (end_obj+1==(int)len) - { - if (obj_list) free(obj_list); - error_msg(progname, "input Error: Invalid compression type in <%s>\n",str); - exit(1); - } - - - /* get filter additional parameters */ - m=0; - for ( i=end_obj+1, k=0, j=0; i<len; i++,k++) - { - c = str[i]; - scomp[k]=c; - if ( c=='=' || i==len-1) - { - if ( c=='=') { /*one more parameter */ - scomp[k]='\0'; /*cut space */ - -/*------------------------------------------------------------------------- - * H5Z_FILTER_SZIP - * szip has the format SZIP=<pixels per block,coding> - * pixels per block is a even number in 2-32 and coding method is 'EC' or 'NN' - * example SZIP=8,NN - *------------------------------------------------------------------------- - */ - if (strcmp(scomp,"SZIP")==0) + unsigned i, u; + char c; + size_t len=strlen(str); + int j, m, n, k, l, end_obj=-1, no_param=0; + char sobj[MAX_NC_NAME]; + char scomp[10]; + char stype[5]; + char smask[3]; + obj_list_t* obj_list=NULL; + unsigned pixels_per_block; + + + /* initialize compression info */ + memset(filt,0,sizeof(filter_info_t)); + *is_glb = 0; + + /* check for the end of object list and number of objects */ + for ( i=0, n=0; i<len; i++) { - l=-1; /* mask index check */ - for ( m=0,u=i+1; u<len; u++,m++) - { - if (str[u]==',') - { - stype[m]='\0'; /* end digit of szip */ - l=0; /* start EC or NN search */ - u++; /* skip ',' */ - } - c = str[u]; - if (!isdigit(c) && l==-1){ - if (obj_list) free(obj_list); - error_msg(progname, "compression parameter not digit in <%s>\n",str); - exit(1); - } - if (l==-1) - stype[m]=c; - else - { - smask[l]=c; - l++; - if (l==2) - { - smask[l]='\0'; - i=len-1; /* end */ - (*n_objs)--; /* we counted an extra ',' */ - if (strcmp(smask,"NN")==0) - filt->cd_values[j++]=H5_SZIP_NN_OPTION_MASK; - else if (strcmp(smask,"EC")==0) - filt->cd_values[j++]=H5_SZIP_EC_OPTION_MASK; - else + c = str[i]; + if ( c==':' ) { - error_msg(progname, "szip mask must be 'NN' or 'EC' \n"); - exit(1); + end_obj=i; } - - } - } - - } /* u */ - } /*if */ - -/*------------------------------------------------------------------------- - * H5Z_FILTER_SCALEOFFSET - * scaleoffset has the format SOFF=<scale_factor,scale_type> - * scale_type can be - * integer datatype, H5Z_SO_INT (IN) - * float datatype using D-scaling method, H5Z_SO_FLOAT_DSCALE (DS) - * float datatype using E-scaling method, H5Z_SO_FLOAT_ESCALE (ES) , not yet implemented - * for integer datatypes, scale_factor denotes Minimum Bits - * for float datatypes, scale_factor denotes decimal scale factor - * examples - * SOFF=31,IN - * SOFF=3,DF - *------------------------------------------------------------------------- - */ - - else if (strcmp(scomp,"SOFF")==0) + if ( c==',' ) + { + n++; + } + } + + if (end_obj==-1) { /* missing : */ + /* apply to all objects */ + options->all_filter=1; + *is_glb = 1; + } + + n++; + obj_list=malloc(n*sizeof(obj_list_t)); + if (obj_list==NULL) { - l=-1; /* mask index check */ - for ( m=0,u=i+1; u<len; u++,m++) - { - if (str[u]==',') - { - stype[m]='\0'; /* end digit */ - l=0; /* start 'IN' , 'DS', or 'ES' search */ - u++; /* skip ',' */ - } - c = str[u]; - if (!isdigit(c) && l==-1){ - if (obj_list) free(obj_list); - error_msg(progname, "compression parameter is not a digit in <%s>\n",str); - exit(1); - } - if (l==-1) - stype[m]=c; - else - { - smask[l]=c; - l++; - if (l==2) - { - smask[l]='\0'; - i=len-1; /* end */ - (*n_objs)--; /* we counted an extra ',' */ - if (strcmp(smask,"IN")==0) - filt->cd_values[j++]=H5Z_SO_INT; - else if (strcmp(smask,"DS")==H5Z_SO_FLOAT_DSCALE) - filt->cd_values[j++]=H5Z_SO_FLOAT_DSCALE; - else + error_msg(progname, "could not allocate object list\n"); + return NULL; + } + *n_objs=n; + + /* get object list */ + for ( j=0, k=0, n=0; j<end_obj; j++,k++) + { + c = str[j]; + sobj[k]=c; + if ( c==',' || j==end_obj-1) { - error_msg(progname, "scale type must be 'IN' or 'DS' \n"); - exit(1); + if ( c==',') sobj[k]='\0'; else sobj[k+1]='\0'; + strcpy(obj_list[n].obj,sobj); + memset(sobj,0,sizeof(sobj)); + n++; + k=-1; } - - } - } - - } /* u */ - } /*if */ - - -/*------------------------------------------------------------------------- - * all other filters - *------------------------------------------------------------------------- - */ - - else + } + /* nothing after : */ + if (end_obj+1==(int)len) { - /* here we could have 1 or 2 digits */ - for ( m=0,u=i+1; u<len; u++,m++) - { - c = str[u]; - if (!isdigit(c)){ - if (obj_list) free(obj_list); - error_msg(progname, "compression parameter is not a digit in <%s>\n",str); - exit(1); - } - stype[m]=c; - } /* u */ - - stype[m]='\0'; - } /*if */ - - - - filt->cd_values[j++]=atoi(stype); - i+=m; /* jump */ + if (obj_list) free(obj_list); + error_msg(progname, "input Error: Invalid compression type in <%s>\n",str); + exit(1); + } + + + /* get filter additional parameters */ + m=0; + for ( i=end_obj+1, k=0, j=0; i<len; i++,k++) + { + c = str[i]; + scomp[k]=c; + if ( c=='=' || i==len-1) + { + if ( c=='=') /*one more parameter */ + { + scomp[k]='\0'; /*cut space */ + + /*------------------------------------------------------------------------- + * H5Z_FILTER_SZIP + * szip has the format SZIP=<pixels per block,coding> + * pixels per block is a even number in 2-32 and coding method is 'EC' or 'NN' + * example SZIP=8,NN + *------------------------------------------------------------------------- + */ + if (strcmp(scomp,"SZIP")==0) + { + l=-1; /* mask index check */ + for ( m=0,u=i+1; u<len; u++,m++) + { + if (str[u]==',') + { + stype[m]='\0'; /* end digit of szip */ + l=0; /* start EC or NN search */ + u++; /* skip ',' */ + } + c = str[u]; + if (!isdigit(c) && l==-1){ + if (obj_list) free(obj_list); + error_msg(progname, "compression parameter not digit in <%s>\n",str); + exit(1); + } + if (l==-1) + stype[m]=c; + else + { + smask[l]=c; + l++; + if (l==2) + { + smask[l]='\0'; + i=len-1; /* end */ + (*n_objs)--; /* we counted an extra ',' */ + if (strcmp(smask,"NN")==0) + filt->cd_values[j++]=H5_SZIP_NN_OPTION_MASK; + else if (strcmp(smask,"EC")==0) + filt->cd_values[j++]=H5_SZIP_EC_OPTION_MASK; + else + { + error_msg(progname, "szip mask must be 'NN' or 'EC' \n"); + exit(1); + } + + } + } + + } /* u */ + } /*if */ + + /*------------------------------------------------------------------------- + * H5Z_FILTER_SCALEOFFSET + * scaleoffset has the format SOFF=<scale_factor,scale_type> + * scale_type can be + * integer datatype, H5Z_SO_INT (IN) + * float datatype using D-scaling method, H5Z_SO_FLOAT_DSCALE (DS) + * float datatype using E-scaling method, H5Z_SO_FLOAT_ESCALE (ES) , not yet implemented + * for integer datatypes, scale_factor denotes Minimum Bits + * for float datatypes, scale_factor denotes decimal scale factor + * examples + * SOFF=31,IN + * SOFF=3,DF + *------------------------------------------------------------------------- + */ + + else if (strcmp(scomp,"SOFF")==0) + { + l=-1; /* mask index check */ + for ( m=0,u=i+1; u<len; u++,m++) + { + if (str[u]==',') + { + stype[m]='\0'; /* end digit */ + l=0; /* start 'IN' , 'DS', or 'ES' search */ + u++; /* skip ',' */ + } + c = str[u]; + if (!isdigit(c) && l==-1){ + if (obj_list) free(obj_list); + error_msg(progname, "compression parameter is not a digit in <%s>\n",str); + exit(1); + } + if (l==-1) + stype[m]=c; + else + { + smask[l]=c; + l++; + if (l==2) + { + smask[l]='\0'; + i=len-1; /* end */ + (*n_objs)--; /* we counted an extra ',' */ + if (strcmp(smask,"IN")==0) + filt->cd_values[j++]=H5Z_SO_INT; + else if (strcmp(smask,"DS")==H5Z_SO_FLOAT_DSCALE) + filt->cd_values[j++]=H5Z_SO_FLOAT_DSCALE; + else + { + error_msg(progname, "scale type must be 'IN' or 'DS' \n"); + exit(1); + } + + } + } + + } /* u */ + } /*if */ + + + /*------------------------------------------------------------------------- + * all other filters + *------------------------------------------------------------------------- + */ + + else + { + /* here we could have 1 or 2 digits */ + for ( m=0,u=i+1; u<len; u++,m++) + { + c = str[u]; + if (!isdigit(c)){ + if (obj_list) free(obj_list); + error_msg(progname, "compression parameter is not a digit in <%s>\n",str); + exit(1); + } + stype[m]=c; + } /* u */ + + stype[m]='\0'; + } /*if */ + + + + filt->cd_values[j++]=atoi(stype); + i+=m; /* jump */ } - else if (i==len-1) { /*no more parameters */ - scomp[k+1]='\0'; - no_param=1; + else if (i==len-1) + { /*no more parameters */ + scomp[k+1]='\0'; + no_param=1; } - -/*------------------------------------------------------------------------- - * H5Z_FILTER_NONE - *------------------------------------------------------------------------- - */ + + /*------------------------------------------------------------------------- + * H5Z_FILTER_NONE + *------------------------------------------------------------------------- + */ if (strcmp(scomp,"NONE")==0) - filt->filtn=H5Z_FILTER_NONE; - -/*------------------------------------------------------------------------- - * H5Z_FILTER_DEFLATE - *------------------------------------------------------------------------- - */ + filt->filtn=H5Z_FILTER_NONE; + + /*------------------------------------------------------------------------- + * H5Z_FILTER_DEFLATE + *------------------------------------------------------------------------- + */ else if (strcmp(scomp,"GZIP")==0) { - filt->filtn=H5Z_FILTER_DEFLATE; - if (no_param) { /*no more parameters, GZIP must have parameter */ - if (obj_list) free(obj_list); - error_msg(progname, "missing compression parameter in <%s>\n",str); - exit(1); - } + filt->filtn=H5Z_FILTER_DEFLATE; + if (no_param) { /*no more parameters, GZIP must have parameter */ + if (obj_list) free(obj_list); + error_msg(progname, "missing compression parameter in <%s>\n",str); + exit(1); + } } - -/*------------------------------------------------------------------------- - * H5Z_FILTER_SZIP - *------------------------------------------------------------------------- - */ + + /*------------------------------------------------------------------------- + * H5Z_FILTER_SZIP + *------------------------------------------------------------------------- + */ else if (strcmp(scomp,"SZIP")==0) { - filt->filtn=H5Z_FILTER_SZIP; - if (no_param) { /*no more parameters, SZIP must have parameter */ - if (obj_list) free(obj_list); - error_msg(progname, "missing compression parameter in <%s>\n",str); - exit(1); - } + filt->filtn=H5Z_FILTER_SZIP; + if (no_param) { /*no more parameters, SZIP must have parameter */ + if (obj_list) free(obj_list); + error_msg(progname, "missing compression parameter in <%s>\n",str); + exit(1); + } } - -/*------------------------------------------------------------------------- - * H5Z_FILTER_SHUFFLE - *------------------------------------------------------------------------- - */ + + /*------------------------------------------------------------------------- + * H5Z_FILTER_SHUFFLE + *------------------------------------------------------------------------- + */ else if (strcmp(scomp,"SHUF")==0) { - filt->filtn=H5Z_FILTER_SHUFFLE; - if (m>0){ /*shuffle does not have parameter */ - if (obj_list) free(obj_list); - error_msg(progname, "extra parameter in SHUF <%s>\n",str); - exit(1); - } + filt->filtn=H5Z_FILTER_SHUFFLE; + if (m>0){ /*shuffle does not have parameter */ + if (obj_list) free(obj_list); + error_msg(progname, "extra parameter in SHUF <%s>\n",str); + exit(1); + } } -/*------------------------------------------------------------------------- - * H5Z_FILTER_FLETCHER32 - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5Z_FILTER_FLETCHER32 + *------------------------------------------------------------------------- + */ else if (strcmp(scomp,"FLET")==0) { - filt->filtn=H5Z_FILTER_FLETCHER32; - if (m>0){ /*shuffle does not have parameter */ - if (obj_list) free(obj_list); - error_msg(progname, "extra parameter in FLET <%s>\n",str); - exit(1); - } + filt->filtn=H5Z_FILTER_FLETCHER32; + if (m>0){ /*shuffle does not have parameter */ + if (obj_list) free(obj_list); + error_msg(progname, "extra parameter in FLET <%s>\n",str); + exit(1); + } } -/*------------------------------------------------------------------------- - * H5Z_FILTER_NBIT - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5Z_FILTER_NBIT + *------------------------------------------------------------------------- + */ else if (strcmp(scomp,"NBIT")==0) { - filt->filtn=H5Z_FILTER_NBIT; - if (m>0){ /*nbit does not have parameter */ - if (obj_list) free(obj_list); - error_msg(progname, "extra parameter in NBIT <%s>\n",str); - exit(1); - } + filt->filtn=H5Z_FILTER_NBIT; + if (m>0){ /*nbit does not have parameter */ + if (obj_list) free(obj_list); + error_msg(progname, "extra parameter in NBIT <%s>\n",str); + exit(1); + } } -/*------------------------------------------------------------------------- - * H5Z_FILTER_SCALEOFFSET - *------------------------------------------------------------------------- - */ + /*------------------------------------------------------------------------- + * H5Z_FILTER_SCALEOFFSET + *------------------------------------------------------------------------- + */ else if (strcmp(scomp,"SOFF")==0) { - filt->filtn=H5Z_FILTER_SCALEOFFSET; - if (no_param) { /*no more parameters, SOFF must have parameter */ - if (obj_list) free(obj_list); - error_msg(progname, "missing compression parameter in <%s>\n",str); - exit(1); - } + filt->filtn=H5Z_FILTER_SCALEOFFSET; + if (no_param) { /*no more parameters, SOFF must have parameter */ + if (obj_list) free(obj_list); + error_msg(progname, "missing compression parameter in <%s>\n",str); + exit(1); + } } else { - if (obj_list) free(obj_list); - error_msg(progname, "invalid filter type in <%s>\n",str); - exit(1); + if (obj_list) free(obj_list); + error_msg(progname, "invalid filter type in <%s>\n",str); + exit(1); } } } /*i*/ - -/*------------------------------------------------------------------------- - * check valid parameters - *------------------------------------------------------------------------- - */ - - switch (filt->filtn) - { - - case H5Z_FILTER_DEFLATE: - if (filt->cd_values[0]<0 || filt->cd_values[0]>9 ){ - if (obj_list) free(obj_list); - error_msg(progname, "invalid compression parameter in <%s>\n",str); - exit(1); - } - break; - - - case H5Z_FILTER_SZIP: - pixels_per_block=filt->cd_values[0]; - if ((pixels_per_block%2)==1) { - if (obj_list) free(obj_list); - error_msg(progname, "pixels_per_block is not even in <%s>\n",str); - exit(1); - } - if (pixels_per_block>H5_SZIP_MAX_PIXELS_PER_BLOCK) { - if (obj_list) free(obj_list); - error_msg(progname, "pixels_per_block is too large in <%s>\n",str); - exit(1); - } - if ( (strcmp(smask,"NN")!=0) && (strcmp(smask,"EC")!=0) ) { - if (obj_list) free(obj_list); - error_msg(progname, "szip mask must be 'NN' or 'EC' \n"); - exit(1); - } - break; - case H5Z_FILTER_SCALEOFFSET: - if (filt->cd_values[0]<0 ){ - if (obj_list) free(obj_list); - error_msg(progname, "invalid compression parameter in <%s>\n",str); - exit(1); - } - break; - }; - - return obj_list; + + /*------------------------------------------------------------------------- + * check valid parameters + *------------------------------------------------------------------------- + */ + + switch (filt->filtn) + { + + case H5Z_FILTER_DEFLATE: + if (filt->cd_values[0]<0 || filt->cd_values[0]>9 ){ + if (obj_list) free(obj_list); + error_msg(progname, "invalid compression parameter in <%s>\n",str); + exit(1); + } + break; + + + case H5Z_FILTER_SZIP: + pixels_per_block=filt->cd_values[0]; + if ((pixels_per_block%2)==1) { + if (obj_list) free(obj_list); + error_msg(progname, "pixels_per_block is not even in <%s>\n",str); + exit(1); + } + if (pixels_per_block>H5_SZIP_MAX_PIXELS_PER_BLOCK) { + if (obj_list) free(obj_list); + error_msg(progname, "pixels_per_block is too large in <%s>\n",str); + exit(1); + } + if ( (strcmp(smask,"NN")!=0) && (strcmp(smask,"EC")!=0) ) { + if (obj_list) free(obj_list); + error_msg(progname, "szip mask must be 'NN' or 'EC' \n"); + exit(1); + } + break; + case H5Z_FILTER_SCALEOFFSET: + if (filt->cd_values[0]<0 ){ + if (obj_list) free(obj_list); + error_msg(progname, "invalid compression parameter in <%s>\n",str); + exit(1); + } + break; + }; + + return obj_list; } -/*------------------------------------------------------------------------- - * Function: get_sfilter - * - * Purpose: return the filter as a string name - * - * Return: name of filter, exit on error - * - *------------------------------------------------------------------------- - */ - -const char* get_sfilter(H5Z_filter_t filtn) -{ - if (filtn==H5Z_FILTER_NONE) - return "NONE"; - else if (filtn==H5Z_FILTER_DEFLATE) - return "GZIP"; - else if (filtn==H5Z_FILTER_SZIP) - return "SZIP"; - else if (filtn==H5Z_FILTER_SHUFFLE) - return "SHUFFLE"; - else if (filtn==H5Z_FILTER_FLETCHER32) - return "FLETCHER32"; - else if (filtn==H5Z_FILTER_NBIT) - return "NBIT"; - else if (filtn==H5Z_FILTER_SCALEOFFSET) - return "SOFF"; - else { - error_msg(progname, "input error in filter type\n"); - exit(1); - } - return NULL; -} - /*------------------------------------------------------------------------- * Function: parse_layout @@ -481,205 +451,171 @@ obj_list_t* parse_layout(const char *str, pack_info_t *pack, /* info about layout needed */ pack_opt_t *options) { - obj_list_t* obj_list=NULL; - unsigned i; - char c; - size_t len=strlen(str); - int j, n, k, end_obj=-1, c_index; - char sobj[MAX_NC_NAME]; - char sdim[10]; - char slayout[10]; - - - memset(sdim, '\0', sizeof(sdim)); - memset(sobj, '\0', sizeof(sobj)); - memset(slayout, '\0', sizeof(slayout)); - - /* check for the end of object list and number of objects */ - for ( i=0, n=0; i<len; i++) - { - c = str[i]; - if ( c==':' ) - { - end_obj=i; - } - if ( c==',' ) - { - n++; - } - } - - if (end_obj==-1) { /* missing : chunk all */ - options->all_layout=1; - } - - n++; - obj_list=malloc(n*sizeof(obj_list_t)); - if (obj_list==NULL) - { - error_msg(progname, "could not allocate object list\n"); - return NULL; - } - *n_objs=n; - - /* get object list */ - for ( j=0, k=0, n=0; j<end_obj; j++,k++) - { - c = str[j]; - sobj[k]=c; - if ( c==',' || j==end_obj-1) - { - if ( c==',') sobj[k]='\0'; else sobj[k+1]='\0'; - strcpy(obj_list[n].obj,sobj); - memset(sobj,0,sizeof(sobj)); - n++; - k=-1; - } - } - - /* nothing after : */ - if (end_obj+1==(int)len) - { - if (obj_list) free(obj_list); - error_msg(progname, "in parse layout, no characters after : in <%s>\n",str); - exit(1); - } - - /* get layout info */ - for ( j=end_obj+1, n=0; n<=5; j++,n++) - { - if (n==5) - { - slayout[n]='\0'; /*cut string */ - if (strcmp(slayout,"COMPA")==0) - pack->layout=H5D_COMPACT; - else if (strcmp(slayout,"CONTI")==0) - pack->layout=H5D_CONTIGUOUS; - else if (strcmp(slayout,"CHUNK")==0) - pack->layout=H5D_CHUNKED; - else { - error_msg(progname, "in parse layout, not a valid layout in <%s>\n",str); - exit(1); - } - } - else - { - c = str[j]; - slayout[n]=c; - } - } /* j */ - - - if ( pack->layout==H5D_CHUNKED ) - { - -/*------------------------------------------------------------------------- - * get chunk info - *------------------------------------------------------------------------- - */ - k=0; - - if (j>(int)len) - { - if (obj_list) free(obj_list); - error_msg(progname, "in parse layout, <%s> Chunk dimensions missing\n",str); - exit(1); - } - - for ( i=j, c_index=0; i<len; i++) - { - c = str[i]; - sdim[k]=c; - k++; /*increment sdim index */ - - if (!isdigit(c) && c!='x' - && c!='N' && c!='O' && c!='N' && c!='E' - ){ - if (obj_list) free(obj_list); - error_msg(progname, "in parse layout, <%s> Not a valid character in <%s>\n", - sdim,str); - exit(1); + obj_list_t* obj_list=NULL; + unsigned i; + char c; + size_t len=strlen(str); + int j, n, k, end_obj=-1, c_index; + char sobj[MAX_NC_NAME]; + char sdim[10]; + char slayout[10]; + + + memset(sdim, '\0', sizeof(sdim)); + memset(sobj, '\0', sizeof(sobj)); + memset(slayout, '\0', sizeof(slayout)); + + /* check for the end of object list and number of objects */ + for ( i=0, n=0; i<len; i++) + { + c = str[i]; + if ( c==':' ) + { + end_obj=i; + } + if ( c==',' ) + { + n++; + } } - - if ( c=='x' || i==len-1) + + if (end_obj==-1) { /* missing : chunk all */ + options->all_layout=1; + } + + n++; + obj_list=malloc(n*sizeof(obj_list_t)); + if (obj_list==NULL) + { + error_msg(progname, "could not allocate object list\n"); + return NULL; + } + *n_objs=n; + + /* get object list */ + for ( j=0, k=0, n=0; j<end_obj; j++,k++) + { + c = str[j]; + sobj[k]=c; + if ( c==',' || j==end_obj-1) + { + if ( c==',') sobj[k]='\0'; else sobj[k+1]='\0'; + strcpy(obj_list[n].obj,sobj); + memset(sobj,0,sizeof(sobj)); + n++; + k=-1; + } + } + + /* nothing after : */ + if (end_obj+1==(int)len) { - if ( c=='x') { - sdim[k-1]='\0'; - k=0; - pack->chunk.chunk_lengths[c_index]=atoi(sdim); - if (pack->chunk.chunk_lengths[c_index]==0) { - if (obj_list) free(obj_list); - error_msg(progname, "in parse layout, <%s> conversion to number in <%s>\n", - sdim,str); - exit(1); - } - c_index++; - } - else if (i==len-1) { /*no more parameters */ - sdim[k]='\0'; - k=0; - if (strcmp(sdim,"NONE")==0) - { - pack->chunk.rank=-2; - } - else - { - pack->chunk.chunk_lengths[c_index]=atoi(sdim); - if (pack->chunk.chunk_lengths[c_index]==0){ if (obj_list) free(obj_list); - error_msg(progname, "in parse layout, <%s> conversion to number in <%s>\n", - sdim,str); + error_msg(progname, "in parse layout, no characters after : in <%s>\n",str); exit(1); - } - pack->chunk.rank=c_index+1; - } - } /*if */ - } /*if c=='x' || i==len-1 */ - } /*i*/ - - - } /*H5D_CHUNKED*/ - - - return obj_list; + } + + /* get layout info */ + for ( j=end_obj+1, n=0; n<=5; j++,n++) + { + if (n==5) + { + slayout[n]='\0'; /*cut string */ + if (strcmp(slayout,"COMPA")==0) + pack->layout=H5D_COMPACT; + else if (strcmp(slayout,"CONTI")==0) + pack->layout=H5D_CONTIGUOUS; + else if (strcmp(slayout,"CHUNK")==0) + pack->layout=H5D_CHUNKED; + else { + error_msg(progname, "in parse layout, not a valid layout in <%s>\n",str); + exit(1); + } + } + else + { + c = str[j]; + slayout[n]=c; + } + } /* j */ + + + if ( pack->layout==H5D_CHUNKED ) + { + + /*------------------------------------------------------------------------- + * get chunk info + *------------------------------------------------------------------------- + */ + k=0; + + if (j>(int)len) + { + if (obj_list) free(obj_list); + error_msg(progname, "in parse layout, <%s> Chunk dimensions missing\n",str); + exit(1); + } + + for ( i=j, c_index=0; i<len; i++) + { + c = str[i]; + sdim[k]=c; + k++; /*increment sdim index */ + + if (!isdigit(c) && c!='x' + && c!='N' && c!='O' && c!='N' && c!='E' + ){ + if (obj_list) free(obj_list); + error_msg(progname, "in parse layout, <%s> Not a valid character in <%s>\n", + sdim,str); + exit(1); + } + + if ( c=='x' || i==len-1) + { + if ( c=='x') { + sdim[k-1]='\0'; + k=0; + pack->chunk.chunk_lengths[c_index]=atoi(sdim); + if (pack->chunk.chunk_lengths[c_index]==0) { + if (obj_list) free(obj_list); + error_msg(progname, "in parse layout, <%s> conversion to number in <%s>\n", + sdim,str); + exit(1); + } + c_index++; + } + else if (i==len-1) { /*no more parameters */ + sdim[k]='\0'; + k=0; + if (strcmp(sdim,"NONE")==0) + { + pack->chunk.rank=-2; + } + else + { + pack->chunk.chunk_lengths[c_index]=atoi(sdim); + if (pack->chunk.chunk_lengths[c_index]==0){ + if (obj_list) free(obj_list); + error_msg(progname, "in parse layout, <%s> conversion to number in <%s>\n", + sdim,str); + exit(1); + } + pack->chunk.rank=c_index+1; + } + } /*if */ + } /*if c=='x' || i==len-1 */ + } /*i*/ + + + } /*H5D_CHUNKED*/ + + + return obj_list; } -/*------------------------------------------------------------------------- - * 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); - - for ( i=0; i<len; i++) - { - c = str[i]; - if (!isdigit(c)){ - return -1; - } - } - str[i]='\0'; - n=atoi(str); - return n; -} - diff --git a/tools/h5repack/h5repack_refs.c b/tools/h5repack/h5repack_refs.c index 64d1990..85af317 100644 --- a/tools/h5repack/h5repack_refs.c +++ b/tools/h5repack/h5repack_refs.c @@ -31,7 +31,7 @@ static const char* MapIdToName(hid_t refobj_id,trav_table_t *travt); static int copy_refs_attr(hid_t loc_in, hid_t loc_out, pack_opt_t *options, - trav_table_t *travt, hid_t fidout); + trav_table_t *travt, hid_t fidout); /*------------------------------------------------------------------------- * Function: do_copy_refobjs diff --git a/tools/h5repack/h5repack_verify.c b/tools/h5repack/h5repack_verify.c index 995aca1..d6bd2a3 100644 --- a/tools/h5repack/h5repack_verify.c +++ b/tools/h5repack/h5repack_verify.c @@ -243,8 +243,15 @@ int h5repack_verify(const char *fname, *------------------------------------------------------------------------- */ if(options->all_filter == 1) - if(has_filter(dcpl_id, options->filter_g.filtn) == 0) - ret = 0; + { + int k; + + for (k = 0; k < options->n_filter_g; k++ ) + { + if (has_filter(dcpl_id, options->filter_g[k].filtn) == 0) + ret = 0; + } + } /*------------------------------------------------------------------------- * layout check diff --git a/tools/h5repack/h5repacktst.c b/tools/h5repack/h5repacktst.c index 0e99d4f..60e489b 100644 --- a/tools/h5repack/h5repacktst.c +++ b/tools/h5repack/h5repacktst.c @@ -1355,6 +1355,36 @@ if (szip_can_encode) { /*------------------------------------------------------------------------- + * test several global filters + *------------------------------------------------------------------------- + */ + + TESTING(" several global filters"); + +#if defined (H5_HAVE_FILTER_DEFLATE) && defined (H5_HAVE_FILTER_SHUFFLE) + + if (h5repack_init (&pack_options, 0) < 0) + GOERROR; + if (h5repack_addfilter("GZIP=1",&pack_options) < 0) + GOERROR; + if (h5repack_addfilter("SHUF",&pack_options) < 0) + GOERROR; + if (h5repack(FNAME11,FNAME11OUT,&pack_options) < 0) + GOERROR; + if (h5diff(FNAME11,FNAME11OUT,NULL,NULL,&diff_options) >0) + GOERROR; + if (h5repack_verify(FNAME11OUT,&pack_options)<=0) + GOERROR; + if (h5repack_end (&pack_options) < 0) + GOERROR; + + PASSED(); +#else + SKIPPED(); +#endif + + +/*------------------------------------------------------------------------- * clean temporary test files *------------------------------------------------------------------------- */ |