From afc3563b76badc2345ca955d7d48fe16cceaf0c8 Mon Sep 17 00:00:00 2001 From: Pedro Vicente Nunes Date: Mon, 26 Jan 2004 18:20:20 -0500 Subject: [svn-r8113] Purpose: new library function H5Pdelete_filter deletes one or all filters from a dataset creation property list this was done for the NONE option of h5repack, added tests for this feature added a test for the new function in /test/dsets.c Description: Solution: Platforms tested: linux solaris AIX Misc. update: --- src/H5Pdcpl.c | 49 +++++++++++++++ src/H5Ppublic.h | 2 + src/H5Z.c | 80 ++++++++++++++++++++++++ src/H5Zprivate.h | 2 + test/dsets.c | 121 +++++++++++++++++++++++++++++++++++++ tools/h5repack/h5repack_copy.c | 3 +- tools/h5repack/h5repack_filters.c | 80 ++++++++++++------------ tools/h5repack/h5repack_verify.c | 17 ++++-- tools/h5repack/testh5repack_main.c | 87 ++++++++++++++++++++++++-- tools/lib/h5trav.c | 2 +- 10 files changed, 389 insertions(+), 54 deletions(-) diff --git a/src/H5Pdcpl.c b/src/H5Pdcpl.c index f61ebf0..5ee9c17 100644 --- a/src/H5Pdcpl.c +++ b/src/H5Pdcpl.c @@ -1621,3 +1621,52 @@ done: FUNC_LEAVE_API(ret_value); } +/*------------------------------------------------------------------------- + * Function: H5Pdelete_filter + * + * Purpose: Deletes a filter from the dataset creation property list; + * deletes all filters if FILTER is H5Z_FILTER_NONE + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Pedro Vicente + * January 26, 2004 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ + +herr_t +H5Pdelete_filter(hid_t plist_id, H5Z_filter_t filter) +{ + H5P_genplist_t *plist; /* Property list pointer */ + H5O_pline_t pline; /* Filter pipeline */ + herr_t ret_value = SUCCEED; /* return value */ + + FUNC_ENTER_API(H5Pdelete_filter, FAIL); + H5TRACE2("e","iZf",plist_id,filter); + + /* Get the property list structure */ + if(NULL == (plist = H5P_object_verify(plist_id,H5P_DATASET_CREATE))) + HGOTO_ERROR(H5E_ATOM, H5E_BADATOM, FAIL, "can't find object for ID"); + + /* Get pipeline info */ + if(H5P_get(plist, H5D_CRT_DATA_PIPELINE_NAME, &pline) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5Z_FILTER_ERROR, "can't get pipeline"); + + if (pline.filter) + { + /* Delete filter */ + if(H5Z_delete(&pline, filter) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTGET, H5Z_FILTER_ERROR, "can't delete filter"); + + /* Put the I/O pipeline information back into the property list */ + if(H5P_set(plist, H5D_CRT_DATA_PIPELINE_NAME, &pline) < 0) + HGOTO_ERROR(H5E_PLIST, H5E_CANTSET, FAIL, "can't set pipeline"); + } + +done: + FUNC_LEAVE_API(ret_value); +} + diff --git a/src/H5Ppublic.h b/src/H5Ppublic.h index cada129..3a7f754 100644 --- a/src/H5Ppublic.h +++ b/src/H5Ppublic.h @@ -299,6 +299,8 @@ H5_DLL herr_t H5Pset_hyper_vector_size(hid_t fapl_id, size_t size); H5_DLL herr_t H5Pget_hyper_vector_size(hid_t fapl_id, size_t *size/*out*/); H5_DLL herr_t H5Pset_small_data_block_size(hid_t fapl_id, hsize_t size); H5_DLL herr_t H5Pget_small_data_block_size(hid_t fapl_id, hsize_t *size/*out*/); +H5_DLL herr_t H5Pdelete_filter(hid_t plist_id, H5Z_filter_t filter); + #ifdef __cplusplus } diff --git a/src/H5Z.c b/src/H5Z.c index 3a1b7a2..6aa984f 100644 --- a/src/H5Z.c +++ b/src/H5Z.c @@ -1084,3 +1084,83 @@ done: FUNC_LEAVE_NOAPI(ret_value) } /* end H5Z_all_filters_avail() */ + + +/*------------------------------------------------------------------------- + * Function: H5Z_delete + * + * Purpose: Delete filter FILTER from pipeline PLINE; + * deletes all filters if FILTER is H5Z_FILTER_NONE + * + * Return: Non-negative on success/Negative on failure + * + * Programmer: Pedro Vicente + * Monday, January 26, 2004 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +herr_t +H5Z_delete(H5O_pline_t *pline, H5Z_filter_t filter) +{ + size_t idx; /* Index of filter in pipeline */ + herr_t ret_value=SUCCEED; /* Return value */ + size_t i, found=0; + + FUNC_ENTER_NOAPI(H5Z_delete, FAIL) + + /* Check args */ + assert(pline); + assert(filter>=0 && filter<=H5Z_FILTER_MAX); + + /* if the pipeline has no filters, just return */ + if(pline->nused==0) + HGOTO_DONE(FALSE) + + /* Delete all filters */ + if (H5Z_FILTER_NONE==filter) + { + if(H5O_reset(H5O_PLINE_ID, pline)<0) + HGOTO_ERROR(H5E_PLINE, H5E_CANTFREE, FAIL, "can't release pipeline info") + } + /* Delete filter */ + else + { + /* Locate the filter in the pipeline */ + for(idx=0; idxnused; idx++) + { + if(pline->filter[idx].id==filter) + { + found=1; + break; + } + } + /* filter was not found in the pipeline */ + if (!found) + HGOTO_ERROR(H5E_PLINE, H5E_NOTFOUND, FAIL, "filter not in pipeline") + + /* Free, reset */ + H5MM_xfree(pline->filter[idx].name); + H5MM_xfree(pline->filter[idx].cd_values); + HDmemset(&pline->filter[idx], 0, sizeof (H5Z_filter_info_t)); + + /* Reorder array */ + if (idx+1nused) + { + for(i=idx; inused; i++) + { + pline->filter[i] = pline->filter[i+1]; + } + } + /* Decrement number of used filters */ + pline->nused--; + + } + +done: + FUNC_LEAVE_NOAPI(ret_value) +} + + + diff --git a/src/H5Zprivate.h b/src/H5Zprivate.h index 08c0d93..d87f735 100644 --- a/src/H5Zprivate.h +++ b/src/H5Zprivate.h @@ -58,5 +58,7 @@ H5_DLL herr_t H5Z_set_local(hid_t dcpl_id, hid_t type_id); H5_DLL H5Z_filter_info_t *H5Z_filter_info(const struct H5O_pline_t *pline, H5Z_filter_t filter); H5_DLL htri_t H5Z_all_filters_avail(const struct H5O_pline_t *pline); +H5_DLL herr_t H5Z_delete(struct H5O_pline_t *pline, H5Z_filter_t filter); + #endif diff --git a/test/dsets.c b/test/dsets.c index fe72215..5121234 100644 --- a/test/dsets.c +++ b/test/dsets.c @@ -3074,6 +3074,126 @@ error: return -1; } /* end test_compare_dcpl() */ + + +/*------------------------------------------------------------------------- + * Function: test_filter_delete + * + * Purpose: Tests deletion of filters from a dataset creation property list + * + * Return: Success: 0 + * Failure: -1 + * + * Programmer: Pedro Vicente + * Monday, January 26, 2004 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static herr_t +test_filter_delete(hid_t file) +{ + H5Z_filter_t filtn; /* filter identification number */ + hid_t dsid; /* dataset ID */ + hid_t sid; /* dataspace ID */ + hid_t dcpl; /* dataset creation property list ID */ + hid_t dcpl1; /* dataset creation property list ID */ + hsize_t dims[2] = {20,20}; /* dataspace dimensions */ + hsize_t chunk_dims[2] = {10,10}; /* chunk dimensions */ + size_t nfilters; /* number of filters in DCPL */ + size_t i; + + TESTING("filter deletion"); + + /* Create the data space */ + if ((sid = H5Screate_simple(2, dims, NULL))<0) goto error; + + /* Create dcpl */ + if((dcpl = H5Pcreate(H5P_DATASET_CREATE))<0) goto error; + if(H5Pset_chunk(dcpl, 2, chunk_dims)<0) goto error; + +#if defined H5_HAVE_FILTER_FLETCHER32 + if (H5Pset_fletcher32 (dcpl)<0) goto error; +#endif + +#if defined H5_HAVE_FILTER_DEFLATE + if (H5Pset_deflate (dcpl, 6)<0) goto error; +#endif + +#if defined H5_HAVE_FILTER_SHUFFLE + if (H5Pset_shuffle (dcpl)<0) goto error; +#endif + + /* Create a dataset */ + if ((dsid = H5Dcreate(file,"dsetdel", H5T_NATIVE_INT, sid, dcpl)) <0) goto error; + + /* Get copy of dataset's dataset creation property list */ + if ((dcpl1=H5Dget_create_plist(dsid))<0) goto error; + +/*---------------------------------------------------------------------- + * delete the deflate filter + *---------------------------------------------------------------------- + */ + +#if defined H5_HAVE_FILTER_DEFLATE + + /* delete the deflate filter */ + if (H5Pdelete_filter(dcpl1,H5Z_FILTER_DEFLATE)<0) goto error; + + /* get information about filters */ + if ((nfilters = H5Pget_nfilters(dcpl1))<0) goto error; + + /* check if filter was deleted */ + for (i=0; inobjs; i++) { + buf=NULL; switch ( travt->objs[i].type ) { /*------------------------------------------------------------------------- @@ -283,7 +284,7 @@ int do_copy_objects(hid_t fidin, if (rank) { /* filters require CHUNK layout; if we do not have one define a default */ - if (obj.chunk.rank==0) + if (obj.chunk.rank<=0) { obj.chunk.rank=rank; for (j=0; jnfilters; i++) { - cd_nelmts = NELMTS(cd_values); - filtn = H5Pget_filter(dcpl_id, - (unsigned)i, - &filt_flags, - &cd_nelmts, - cd_values, - sizeof(f_name), - f_name); - } + if (obj->filter[i].filtn==H5Z_FILTER_NONE) + { + if (nfilters && H5Pdelete_filter(dcpl_id,H5Z_FILTER_NONE)<0) + return -1; + + return 1; + } + } + + +/*------------------------------------------------------------------------- + * the type of filter and additional parameter + * type can be one of the filters + * H5Z_FILTER_NONE 0, uncompress if compressed + * H5Z_FILTER_DEFLATE 1 , deflation like gzip + * H5Z_FILTER_SHUFFLE 2 , shuffle the data + * H5Z_FILTER_FLETCHER32 3 , fletcher32 checksum of EDC + * H5Z_FILTER_SZIP 4 , szip compression + *------------------------------------------------------------------------- + */ -/* - the type of filter and additional parameter - type can be one of the filters - H5Z_FILTER_NONE 0, uncompress if compressed - H5Z_FILTER_DEFLATE 1 , deflation like gzip - H5Z_FILTER_SHUFFLE 2 , shuffle the data - H5Z_FILTER_FLETCHER32 3 , fletcher32 checksum of EDC - H5Z_FILTER_SZIP 4 , szip compression -*/ - for ( j=0; jnfilters; j++) + for ( i=0; infilters; i++) { - switch (obj->filter[j].filtn) + switch (obj->filter[i].filtn) { - case H5Z_FILTER_NONE: - + default: break; - case H5Z_FILTER_DEFLATE: - - aggression=obj->filter[j].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) @@ -232,7 +233,7 @@ int apply_filters(hid_t dcpl_id, case H5Z_FILTER_SZIP: - szip_pixels_per_block=obj->filter[j].cd_values[0]; + szip_pixels_per_block=obj->filter[i].cd_values[0]; /* check szip parameters */ if (check_szip(obj->chunk.rank, @@ -273,13 +274,10 @@ int apply_filters(hid_t dcpl_id, return -1; break; - - - default: - break; + } /* switch */ - }/*j*/ + }/*i*/ return 0; } diff --git a/tools/h5repack/h5repack_verify.c b/tools/h5repack/h5repack_verify.c index 2283bc5..bbf0492 100644 --- a/tools/h5repack/h5repack_verify.c +++ b/tools/h5repack/h5repack_verify.c @@ -47,11 +47,15 @@ int has_filter(hid_t dcpl_id, /* if no information about the input filter is requested return exit */ if (filtnin==-1) - return 1; + return 1; /* get information about filters */ if ((nfilters = H5Pget_nfilters(dcpl_id))<0) return -1; + + /* if we do not have filters and the requested filter is NONE, return 1 */ + if (!nfilters && filtnin==H5Z_FILTER_NONE) + return 1; for (i=0; ifilter[j].filtn>H5Z_FILTER_NONE ) + { + if (has_layout(dcpl_id,obj)==0) + ret=0; + } /*------------------------------------------------------------------------- * close @@ -248,7 +255,7 @@ int h5repack_verify(const char *fname, * filter check *------------------------------------------------------------------------- */ - if (options->all_filter==1){ + if (options->all_filter==1 ){ if (has_filter(dcpl_id,options->filter_g.filtn)==0) ret=0; } diff --git a/tools/h5repack/testh5repack_main.c b/tools/h5repack/testh5repack_main.c index d81f311..fc7d571 100644 --- a/tools/h5repack/testh5repack_main.c +++ b/tools/h5repack/testh5repack_main.c @@ -96,6 +96,82 @@ error: } /*------------------------------------------------------------------------- + * Function: test_filter_none + * + * Purpose: + * + * 1) delete filters form the filter pipeline + * 2) use the h5diff utility to compare the input and output file; + * it returns RET==0 if the objects have the same data + * 3) use API functions to verify the compression/chunking input on the output file + * + * Return: Success: zero + * Failure: 1 + * + * Programmer: Pedro Vicente + * September, 19, 2003 + * + * + *------------------------------------------------------------------------- + */ +static int +test_filter_none(void) +{ + pack_opt_t pack_options; + diff_opt_t diff_options; + memset(&diff_options, 0, sizeof (diff_opt_t)); + memset(&pack_options, 0, sizeof (pack_opt_t)); + + TESTING(" delete filters"); + +/*------------------------------------------------------------------------- + * test the NONE global option + *------------------------------------------------------------------------- + */ + + if (h5repack_init (&pack_options, 0)<0) + TEST_ERROR; + if (h5repack_addfilter("dset_gzip:NONE",&pack_options)<0) + TEST_ERROR; + if (h5repack(FNAME4,FNAME4OUT,&pack_options)<0) + TEST_ERROR; + if (h5diff(FNAME4,FNAME4OUT,NULL,NULL,&diff_options) == 1) + TEST_ERROR; + if (h5repack_verify(FNAME4OUT,&pack_options)<=0) + TEST_ERROR; + if (h5repack_end (&pack_options)<0) + TEST_ERROR; + +/*------------------------------------------------------------------------- + * test the NONE specific option; uncompress a dataset + *------------------------------------------------------------------------- + */ + + if (h5repack_init (&pack_options, 0)<0) + TEST_ERROR; + if (h5repack_addfilter("dset_gzip:NONE",&pack_options)<0) + TEST_ERROR; + if (h5repack_addfilter("dset1:NONE",&pack_options)<0) + TEST_ERROR; + if (h5repack(FNAME4,FNAME4OUT,&pack_options)<0) + TEST_ERROR; + if (h5diff(FNAME4,FNAME4OUT,NULL,NULL,&diff_options) == 1) + TEST_ERROR; + if (h5repack_verify(FNAME4OUT,&pack_options)<=0) + TEST_ERROR; + if (h5repack_end (&pack_options)<0) + TEST_ERROR; + + PASSED(); + return 0; + +error: + return 1; + + +} + +/*------------------------------------------------------------------------- * Function: test_filter_deflate * * Purpose: @@ -182,7 +258,8 @@ test_filter_deflate(void) TEST_ERROR; if (h5repack_end (&pack_options)<0) TEST_ERROR; - + + PASSED(); #else SKIPPED(); @@ -193,11 +270,8 @@ test_filter_deflate(void) error: return 1; #endif - - } - /*------------------------------------------------------------------------- * Function: test_filter_szip * @@ -347,10 +421,8 @@ error: return 1; #endif - } - /*------------------------------------------------------------------------- * Function: test_filter_checksum * @@ -743,6 +815,9 @@ int main (void) /* test a copy with no filters */ nerrors += test_copy(); + /* test a copy with the delete filters option */ + nerrors += test_filter_none(); + /* test a copy with the deflate filter */ nerrors += test_filter_deflate(); diff --git a/tools/lib/h5trav.c b/tools/lib/h5trav.c index a005636..9c1db43 100644 --- a/tools/lib/h5trav.c +++ b/tools/lib/h5trav.c @@ -624,7 +624,7 @@ int h5trav_getindext(const char *name, trav_table_t *table) result = (int)(pdest - table->objs[i].name); /* found at position 1, meaning without '/' */ - if( pdest != NULL && result==1 ) + if( pdest != NULL && result==1 && strlen(table->objs[i].name)-1==strlen(name)) return i; /* search also in the list of links */ -- cgit v0.12