From 792d03405a71740a1063cda98571b2cd2a267014 Mon Sep 17 00:00:00 2001 From: Pedro Vicente Nunes Date: Tue, 19 Oct 2004 11:10:17 -0500 Subject: [svn-r9435] Purpose: bug fix Description: one case was not handled in the combination of input options (layout and filters) Solution: redo the algorythm that handles all cases Platforms tested: linux Misc. update: --- MANIFEST | 1 - tools/h5repack/Makefile.in | 6 +- tools/h5repack/h5repack.h | 8 +- tools/h5repack/h5repack_copy.c | 22 +-- tools/h5repack/h5repack_filters.c | 288 ++++++++++++++++++++++++++------------ 5 files changed, 209 insertions(+), 116 deletions(-) diff --git a/MANIFEST b/MANIFEST index 5d20ef8..99e73a2 100644 --- a/MANIFEST +++ b/MANIFEST @@ -1442,7 +1442,6 @@ ./tools/h5repack/h5repack.h ./tools/h5repack/h5repack_copy.c ./tools/h5repack/h5repack_filters.c -./tools/h5repack/h5repack_layout.c ./tools/h5repack/h5repack_list.c ./tools/h5repack/h5repack_main.c ./tools/h5repack/h5repack_opttable.c diff --git a/tools/h5repack/Makefile.in b/tools/h5repack/Makefile.in index 630a4e8..73601d4 100644 --- a/tools/h5repack/Makefile.in +++ b/tools/h5repack/Makefile.in @@ -52,10 +52,10 @@ DISTCLEAN=h5repack.sh ## Source and object files for programs... ## -PROG_SRC=h5repack.c h5repack_copy.c h5repack_filters.c h5repack_refs.c h5repack_layout.c h5repack_list.c h5repack_main.c h5repack_opttable.c h5repack_parse.c h5repack_verify.c testh5repack_attr.c testh5repack_dset.c testh5repack_main.c testh5repack_make.c testh5repack_util.c +PROG_SRC=h5repack.c h5repack_copy.c h5repack_filters.c h5repack_refs.c h5repack_list.c h5repack_main.c h5repack_opttable.c h5repack_parse.c h5repack_verify.c testh5repack_attr.c testh5repack_dset.c testh5repack_main.c testh5repack_make.c testh5repack_util.c PROG_OBJ=$(PROG_SRC:.c=.lo) -OBJS=h5repack.lo h5repack_filters.lo h5repack_copy.lo h5repack_refs.lo h5repack_layout.lo h5repack_list.lo h5repack_main.lo h5repack_opttable.lo h5repack_parse.lo h5repack_verify.lo -TEST_OBJS=h5repack.lo h5repack_filters.lo h5repack_copy.lo h5repack_refs.lo h5repack_layout.lo h5repack_list.lo h5repack_opttable.lo h5repack_parse.lo h5repack_verify.lo testh5repack_attr.lo testh5repack_dset.lo testh5repack_main.lo testh5repack_make.lo testh5repack_util.lo +OBJS=h5repack.lo h5repack_filters.lo h5repack_copy.lo h5repack_refs.lo h5repack_list.lo h5repack_main.lo h5repack_opttable.lo h5repack_parse.lo h5repack_verify.lo +TEST_OBJS=h5repack.lo h5repack_filters.lo h5repack_copy.lo h5repack_refs.lo h5repack_list.lo h5repack_opttable.lo h5repack_parse.lo h5repack_verify.lo testh5repack_attr.lo testh5repack_dset.lo testh5repack_main.lo testh5repack_make.lo testh5repack_util.lo PRIVATE_HDR= diff --git a/tools/h5repack/h5repack.h b/tools/h5repack/h5repack.h index ff3d2a8..e99888e 100644 --- a/tools/h5repack/h5repack.h +++ b/tools/h5repack/h5repack.h @@ -180,18 +180,12 @@ int print_filters(hid_t dcpl_id); *------------------------------------------------------------------------- */ -int filter_this(const char* name, - pack_opt_t *options, - pack_info_t *pack); /* info about object to filter */ - int apply_filters(const char* name, /* object name from traverse list */ int rank, /* rank of dataset */ hsize_t *dims, /* dimensions of dataset */ hid_t dcpl_id, /* dataset creation property list */ hid_t type_id, /* datatype */ - pack_opt_t *options, /* repack options */ - int has_layout, /* input chunk */ - pack_info_t *obj); /* info about object to filter */ + pack_opt_t *options); /* repack options */ int has_filter(hid_t dcpl_id, H5Z_filter_t filtnin); diff --git a/tools/h5repack/h5repack_copy.c b/tools/h5repack/h5repack_copy.c index 5ce0e71..7f61d7a 100644 --- a/tools/h5repack/h5repack_copy.c +++ b/tools/h5repack/h5repack_copy.c @@ -245,7 +245,6 @@ int do_copy_objects(hid_t fidin, #endif /* LATER */ int i, j; int wrote=0; - int has_layout; /*------------------------------------------------------------------------- * copy the suppplied object list @@ -256,7 +255,6 @@ int do_copy_objects(hid_t fidin, { buf=NULL; - has_layout=0; switch ( travt->objs[i].type ) { /*------------------------------------------------------------------------- @@ -366,23 +364,11 @@ int do_copy_objects(hid_t fidin, if (H5Dread(dset_in,mtype_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf)<0) goto error; - /*------------------------------------------------------------------------- - * apply the layout; check first if the object is to be modified. - *------------------------------------------------------------------------- + /*------------------------------------------------------------------------- + * apply the filter + *------------------------------------------------------------------------- */ - if (layout_this(dcpl_id,travt->objs[i].name,options,&obj)) - { - obj.chunk.rank=rank; - if (apply_layout(dcpl_id,&obj)<0) - goto error; - has_layout=1; - } - - /*------------------------------------------------------------------------- - * apply the filter; check if the object is to be filtered. - *------------------------------------------------------------------------- - */ - if (apply_filters(travt->objs[i].name,rank,dims,dcpl_id,mtype_id,options,has_layout,&obj)<0) + if (apply_filters(travt->objs[i].name,rank,dims,dcpl_id,mtype_id,options)<0) goto error; }/*nelmts*/ diff --git a/tools/h5repack/h5repack_filters.c b/tools/h5repack/h5repack_filters.c index 5d4d65d..4dc696e 100644 --- a/tools/h5repack/h5repack_filters.c +++ b/tools/h5repack/h5repack_filters.c @@ -18,79 +18,160 @@ /*------------------------------------------------------------------------- - * Function: aux_objinsert_filter + * Function: aux_find_obj * - * Purpose: auxiliary function, inserts the filter in object OBJ - * - * Return: void + * Purpose: find the object name NAME (got from the traverse list) + * in the repack options list * *------------------------------------------------------------------------- */ -static void aux_objinsert_filter(pack_info_t *obj, - filter_info_t filt) +static +int aux_find_obj(const char* name, /* object name from traverse list */ + pack_opt_t *options, /* repack options */ + pack_info_t *obj /*OUT*/) /* info about object to filter */ { - obj->nfilters=1; - obj->filter[0]=filt; - + char *pdest; + int result; + int i; + + for ( i=0; iop_tbl->nelems; i++) + { + if (strcmp(options->op_tbl->objs[i].path,name)==0) + { + *obj = options->op_tbl->objs[i]; + return i; + } + + pdest = strstr(name,options->op_tbl->objs[i].path); + result = (int)(pdest - name); + + /* found at position 1, meaning without '/' */ + if( pdest != NULL && result==1 ) + { + *obj = options->op_tbl->objs[i]; + return i; + } + }/*i*/ + + return -1; } + /*------------------------------------------------------------------------- - * Function: filter_this + * Function: aux_assign_obj * * Purpose: find the object name NAME (got from the traverse list) * in the repack options list; assign the filter information OBJ * * Return: 0 not found, 1 found * - * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu - * - * Date: December 19, 2003 - * *------------------------------------------------------------------------- */ -int filter_this(const char* name, /* object name from traverse list */ - pack_opt_t *options, /* repack options */ - pack_info_t *obj /*OUT*/) /* info about object to filter */ +static +int aux_assign_obj(const char* name, /* object name from traverse list */ + pack_opt_t *options, /* repack options */ + pack_info_t *obj /*OUT*/) /* info about object to filter */ { - char *pdest; - int result; - int i, j; - - /* if we are applying to all objects just return true */ - if (options->all_filter) - { - /* assign the global filter and chunk info to the OBJ info */ - aux_objinsert_filter( obj, options->filter_g ); - obj->chunk=options->chunk_g; - return 1; - } - - for ( i=0; iop_tbl->nelems; i++) - { - for ( j=0; jop_tbl->objs[i].nfilters; j++) - { - if (options->op_tbl->objs[i].filter[j].filtn != -1 ) - { - if (strcmp(options->op_tbl->objs[i].path,name)==0) - { - *obj=options->op_tbl->objs[i]; - return 1; - } - - pdest = strstr(name,options->op_tbl->objs[i].path); - result = (int)(pdest - name); - - /* found at position 1, meaning without '/' */ - if( pdest != NULL && result==1 ) - { - *obj=options->op_tbl->objs[i]; - return 1; - } - } /*if*/ - }/*j*/ - }/*i*/ + + int index, i; + pack_info_t tmp; + + init_packobject(&tmp); + + index = aux_find_obj(name,options,&tmp); + + /* name was on input */ + if (index>=0) + { + + /* applying to all objects */ + if (options->all_layout) + { + /* assign the global layout info to the OBJ info */ + tmp.layout=options->layout_g; + switch (options->layout_g) + { + case H5D_CHUNKED: + tmp.chunk.rank=options->chunk_g.rank; + for ( i=0; ichunk_g.chunk_lengths[i]; + break; + default: + break; + }/*switch*/ + } + else + { + tmp.layout = options->op_tbl->objs[index].layout; + switch (tmp.layout) + { + case H5D_CHUNKED: + tmp.chunk.rank = options->op_tbl->objs[index].chunk.rank; + for ( i=0; iop_tbl->objs[index].chunk.chunk_lengths[i]; + break; + default: + break; + }/*switch*/ + + } + + /* applying to all objects */ + if (options->all_filter) + { + /* assign the global filter */ + tmp.nfilters=1; + tmp.filter[0]=options->filter_g; + } /* if all */ + else + { + tmp.nfilters=options->op_tbl->objs[index].nfilters; + for ( i=0; iop_tbl->objs[index].filter[i]; + } + } + + + } /* if index */ + + + /* no input name */ + + else + { + + if (options->all_filter) + { + /* assign the global filter */ + tmp.nfilters=1; + tmp.filter[0]=options->filter_g; + } + + + if (options->all_layout) + { + /* assign the global layout info to the OBJ info */ + tmp.layout=options->layout_g; + switch (options->layout_g) + { + case H5D_CHUNKED: + tmp.chunk.rank=options->chunk_g.rank; + for ( i=0; ichunk_g.chunk_lengths[i]; + break; + default: + break; + }/*switch*/ + + } + + + } - return 0; + *obj = tmp; + return 1; + } @@ -115,37 +196,31 @@ int apply_filters(const char* name, /* object name from traverse list */ hsize_t *dims, /* dimensions of dataset */ hid_t dcpl_id, /* dataset creation property list */ hid_t type_id, /* dataset datatype */ - pack_opt_t *options, /* repack options */ - int has_layout, /* input chunk */ - pack_info_t *obj) /* info about object to filter */ -{ - int nfilters; /* number of filters in DCPL */ + pack_opt_t *options) /* repack options */ +{ + int nfilters; /* number of filters in DCPL */ unsigned aggression; /* the deflate level */ hsize_t nelmts; /* number of elements in dataset */ size_t size; /* size of datatype in bytes */ int i; - - /* check first if the object is to be filtered */ - if (filter_this(name,options,obj)==0) - return 0; - + pack_info_t obj; + if (rank==0) goto out; /*------------------------------------------------------------------------- - * filters require CHUNK layout; if we do not have one define a default + * initialize the assigment object *------------------------------------------------------------------------- */ - if (has_layout) - { - layout_this(dcpl_id,name,options,obj); - } - else - { - obj->chunk.rank=rank; - for (i=0; ichunk.chunk_lengths[i] = dims[i]; - } + init_packobject(&obj); + + +/*------------------------------------------------------------------------- + * find options + *------------------------------------------------------------------------- + */ + if (aux_assign_obj(name,options,&obj)==0) + return 0; /* check for datasets too small */ @@ -175,8 +250,6 @@ int apply_filters(const char* name, /* object name from traverse list */ return -1; } - - /*------------------------------------------------------------------------- * the type of filter and additional parameter * type can be one of the filters @@ -187,9 +260,24 @@ int apply_filters(const char* name, /* object name from traverse list */ * H5Z_FILTER_SZIP 4 , szip compression *------------------------------------------------------------------------- */ - for ( i=0; infilters; i++) + + if (obj.nfilters) + { + +/*------------------------------------------------------------------------- + * filters require CHUNK layout; if we do not have one define a default + *------------------------------------------------------------------------- + */ + if (obj.layout==-1) + { + obj.chunk.rank=rank; + for (i=0; ifilter[i].filtn) + switch (obj.filter[i].filtn) { default: break; @@ -199,9 +287,9 @@ int apply_filters(const char* name, /* object name from traverse list */ *------------------------------------------------------------------------- */ case H5Z_FILTER_DEFLATE: - aggression=obj->filter[i].cd_values[0]; + aggression=obj.filter[i].cd_values[0]; /* set up for deflated data */ - if(H5Pset_chunk(dcpl_id, obj->chunk.rank, obj->chunk.chunk_lengths)<0) + if(H5Pset_chunk(dcpl_id, obj.chunk.rank, obj.chunk.chunk_lengths)<0) return -1; if(H5Pset_deflate(dcpl_id,aggression)<0) return -1; @@ -216,14 +304,14 @@ int apply_filters(const char* name, /* object name from traverse list */ unsigned options_mask; unsigned pixels_per_block; - pixels_per_block=obj->filter[i].cd_values[0]; - if (obj->filter[i].szip_coding==0) + pixels_per_block=obj.filter[i].cd_values[0]; + if (obj.filter[i].szip_coding==0) options_mask=H5_SZIP_NN_OPTION_MASK; else options_mask=H5_SZIP_EC_OPTION_MASK; /* set up for szip data */ - if(H5Pset_chunk(dcpl_id,obj->chunk.rank,obj->chunk.chunk_lengths)<0) + if(H5Pset_chunk(dcpl_id,obj.chunk.rank,obj.chunk.chunk_lengths)<0) return -1; if (H5Pset_szip(dcpl_id,options_mask,pixels_per_block)<0) return -1; @@ -236,7 +324,7 @@ int apply_filters(const char* name, /* object name from traverse list */ *------------------------------------------------------------------------- */ case H5Z_FILTER_SHUFFLE: - if(H5Pset_chunk(dcpl_id, obj->chunk.rank, obj->chunk.chunk_lengths)<0) + if(H5Pset_chunk(dcpl_id, obj.chunk.rank, obj.chunk.chunk_lengths)<0) return -1; if (H5Pset_shuffle(dcpl_id)<0) return -1; @@ -247,7 +335,7 @@ int apply_filters(const char* name, /* object name from traverse list */ *------------------------------------------------------------------------- */ case H5Z_FILTER_FLETCHER32: - if(H5Pset_chunk(dcpl_id, obj->chunk.rank, obj->chunk.chunk_lengths)<0) + if(H5Pset_chunk(dcpl_id, obj.chunk.rank, obj.chunk.chunk_lengths)<0) return -1; if (H5Pset_fletcher32(dcpl_id)<0) return -1; @@ -255,6 +343,32 @@ int apply_filters(const char* name, /* object name from traverse list */ } /* switch */ }/*i*/ + } + /*obj.nfilters*/ + else + { + /* just apply layout */ + + /* no layout info was found, define the default */ + if (obj.layout==-1) + obj.layout = H5D_CONTIGUOUS; + + + if (H5Pset_layout(dcpl_id, obj.layout)<0) + return -1; + + if (H5D_CHUNKED==obj.layout) { /* set up chunk */ + if(H5Pset_chunk(dcpl_id, obj.chunk.rank, obj.chunk.chunk_lengths)<0) + return -1; + } + else if (H5D_COMPACT==obj.layout) { + if (H5Pset_alloc_time(dcpl_id, H5D_ALLOC_TIME_EARLY)<0) + return -1; + } + + + } + return 0; out: -- cgit v0.12