diff options
Diffstat (limited to 'tools/h5repack/h5repack_copy.c')
-rw-r--r-- | tools/h5repack/h5repack_copy.c | 55 |
1 files changed, 34 insertions, 21 deletions
diff --git a/tools/h5repack/h5repack_copy.c b/tools/h5repack/h5repack_copy.c index c015f0a..9a73919 100644 --- a/tools/h5repack/h5repack_copy.c +++ b/tools/h5repack/h5repack_copy.c @@ -228,6 +228,8 @@ out: * Programmer: Pedro Vicente, pvn@ncsa.uiuc.edu * * Date: October, 23, 2003 + * Modified: December, 03, 2004 - added a check for H5Dcreate; if the dataset + * cannot be created with the requested filter, use the input one * *------------------------------------------------------------------------- */ @@ -244,6 +246,7 @@ int do_copy_objects(hid_t fidin, hid_t type_in; /* named type ID */ hid_t type_out; /* named type ID */ hid_t dcpl_id; /* dataset creation property list ID */ + hid_t dcpl_out; /* dataset creation property list ID */ hid_t space_id; /* space ID */ hid_t ftype_id; /* file data type ID */ hid_t mtype_id; /* memory data type ID */ @@ -254,9 +257,6 @@ int do_copy_objects(hid_t fidin, hsize_t dims[H5S_MAX_RANK];/* dimensions of dataset */ hsize_t dsize_in; /* input dataset size before filter */ int next; /* external files */ -#ifdef LATER - hsize_t dsize_out; /* output dataset size after filter */ -#endif /* LATER */ int i, j; int wrote=0; @@ -305,6 +305,7 @@ int do_copy_objects(hid_t fidin, *------------------------------------------------------------------------- */ case H5G_DATASET: + if ((dset_in=H5Dopen(fidin,travt->objs[i].name))<0) goto error; if ((space_id=H5Dget_space(dset_in))<0) @@ -313,6 +314,8 @@ int do_copy_objects(hid_t fidin, goto error; if ((dcpl_id=H5Dget_create_plist(dset_in))<0) goto error; + if ((dcpl_out = H5Pcopy (dcpl_id))<0) + goto error; if ( (rank=H5Sget_simple_extent_ndims(space_id))<0) goto error; HDmemset(dims, 0, sizeof dims); @@ -321,6 +324,9 @@ int do_copy_objects(hid_t fidin, nelmts=1; for (j=0; j<rank; j++) nelmts*=dims[j]; + + if (options->verbose) + print_obj(dcpl_id,travt->objs[i].name ); if ((mtype_id=h5tools_get_native_type(ftype_id))<0) goto error; @@ -379,17 +385,36 @@ int do_copy_objects(hid_t fidin, * apply the filter *------------------------------------------------------------------------- */ - if (apply_filters(travt->objs[i].name,rank,dims,dcpl_id,mtype_id,options)<0) + if (apply_filters(travt->objs[i].name,rank,dims,dcpl_out,mtype_id,options)<0) goto error; }/*nelmts*/ /*------------------------------------------------------------------------- - * create/write dataset/close + * create; + * disable error checking in case the dataset cannot be created with the + * modified dcpl; in that case use the original instead *------------------------------------------------------------------------- */ - if ((dset_out=H5Dcreate(fidout,travt->objs[i].name,mtype_id,space_id,dcpl_id))<0) - goto error; + + H5E_BEGIN_TRY { + dset_out=H5Dcreate(fidout,travt->objs[i].name,mtype_id,space_id,dcpl_out); + } H5E_END_TRY; + + if (dset_out==FAIL) + { + if ((dset_out=H5Dcreate(fidout,travt->objs[i].name,mtype_id,space_id,dcpl_id))<0) + goto error; + + if (options->verbose) + printf("Warning: Could not apply the filter to <%s>\n", travt->objs[i].name); + } + + /*------------------------------------------------------------------------- + * write dataset + *------------------------------------------------------------------------- + */ + if (dsize_in && nelmts) { if (H5Dwrite(dset_out,mtype_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf)<0) goto error; @@ -402,26 +427,12 @@ int do_copy_objects(hid_t fidin, if (copy_attr(dset_in,dset_out,options)<0) goto error; -#ifdef LATER - /*------------------------------------------------------------------------- - * store the storage sizes - *------------------------------------------------------------------------- - */ - - dsize_out=H5Dget_storage_size(dset_out); -#endif /* LATER */ - /*close */ if (H5Dclose(dset_out)<0) goto error; if (buf) free(buf); - - if (options->verbose && wrote) - print_obj(dcpl_id,travt->objs[i].name ); - - }/*H5T_STD_REF_OBJ*/ }/*can_read*/ @@ -437,6 +448,8 @@ int do_copy_objects(hid_t fidin, goto error; if (H5Pclose(dcpl_id)<0) goto error; + if (H5Pclose(dcpl_out)<0) + goto error; if (H5Sclose(space_id)<0) goto error; if (H5Dclose(dset_in)<0) |