diff options
Diffstat (limited to 'tools/h5repack/h5repack_copy.c')
-rw-r--r-- | tools/h5repack/h5repack_copy.c | 99 |
1 files changed, 52 insertions, 47 deletions
diff --git a/tools/h5repack/h5repack_copy.c b/tools/h5repack/h5repack_copy.c index 6c47cfb..5153cc4 100644 --- a/tools/h5repack/h5repack_copy.c +++ b/tools/h5repack/h5repack_copy.c @@ -13,11 +13,7 @@ * 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.h" #include "h5tools_utils.h" @@ -543,22 +539,23 @@ int do_copy_objects(hid_t fidin, trav_table_t *travt, pack_opt_t *options) /* repack options */ { - hid_t grp_in=-1; /* group ID */ - hid_t grp_out=-1; /* group ID */ - hid_t dset_in=-1; /* read dataset ID */ - hid_t dset_out=-1; /* write dataset ID */ - hid_t gcpl_in=-1; /* group creation property list */ - hid_t gcpl_out=-1; /* group creation property list */ - hid_t type_in=-1; /* named type ID */ - hid_t type_out=-1; /* named type ID */ - hid_t dcpl_id=-1; /* dataset creation property list ID */ - hid_t dcpl_out=-1; /* dataset creation property list ID */ - hid_t f_space_id=-1; /* file space ID */ - hid_t ftype_id=-1; /* file type ID */ - hid_t wtype_id=-1; /* read/write type ID */ - named_dt_t *named_dt_head=NULL; /* Pointer to the stack of named datatypes copied */ + hid_t grp_in = -1; /* group ID */ + hid_t grp_out = -1; /* group ID */ + hid_t dset_in = -1; /* read dataset ID */ + hid_t dset_out = -1; /* write dataset ID */ + hid_t gcpl_in = -1; /* group creation property list */ + hid_t gcpl_out = -1; /* group creation property list */ + hid_t type_in = -1; /* named type ID */ + hid_t type_out = -1; /* named type ID */ + hid_t dcpl_id = -1; /* dataset creation property list ID */ + hid_t dcpl_out = -1; /* dataset creation property list ID */ + hid_t f_space_id = -1; /* file space ID */ + hid_t ftype_id = -1; /* file type ID */ + hid_t wtype_id = -1; /* read/write type ID */ + named_dt_t *named_dt_head = NULL; /* Pointer to the stack of named datatypes copied */ size_t msize; /* size of type */ hsize_t nelmts; /* number of elements in dataset */ + H5D_space_status_t space_status; /* determines whether space has been allocated for the dataset */ int rank; /* rank of dataset */ hsize_t dims[H5S_MAX_RANK];/* dimensions of dataset */ hsize_t dsize_in; /* input dataset size before filter */ @@ -688,7 +685,7 @@ int do_copy_objects(hid_t fidin, /* check if filters were requested for individual objects */ for (u = 0; u < options->op_tbl->nelems; u++) { - if (strcmp(travt->objs[i].name, options->op_tbl->objs[u].path) == 0) { + if (HDstrcmp(travt->objs[i].name, options->op_tbl->objs[u].path) == 0) { if (options->op_tbl->objs[u].filter->filtn > 0) { req_filter = 1; } @@ -746,11 +743,13 @@ int do_copy_objects(hid_t fidin, HDmemset(dims, 0, sizeof dims); if(H5Sget_simple_extent_dims(f_space_id, dims, NULL) < 0) goto error; + + if(H5Dget_space_status(dset_in, &space_status) < 0) + goto error; + nelmts = 1; - for ( j = 0; j < rank; j++) - { + for(j = 0; j < rank; j++) nelmts *= dims[j]; - } /* wtype_id will have already been set if using a named dtype */ if(!is_named) { @@ -834,20 +833,26 @@ int do_copy_objects(hid_t fidin, * read/write *------------------------------------------------------------------------- */ - if (nelmts) + if(nelmts > 0 && space_status != H5D_SPACE_STATUS_NOT_ALLOCATED) { - size_t need = (size_t)(nelmts*msize); /* bytes needed */ - if ( need < H5TOOLS_MALLOCSIZE ) + size_t need = (size_t)(nelmts * msize); /* bytes needed */ + + /* have to read the whole dataset if there is only one element in the dataset */ + if(need < H5TOOLS_MALLOCSIZE) buf = HDmalloc(need); - if (buf != NULL ) - { - if (H5Dread(dset_in,wtype_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf) < 0) + if(buf != NULL) { + if(H5Dread(dset_in, wtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) goto error; - if (H5Dwrite(dset_out,wtype_id,H5S_ALL,H5S_ALL,H5P_DEFAULT,buf) < 0) + if(H5Dwrite(dset_out, wtype_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0) goto error; - } + /* Check if we have VL data in the dataset's + * datatype that must be reclaimed */ + if(TRUE == H5Tdetect_class(wtype_id, H5T_VLEN)) + if(H5Dvlen_reclaim(wtype_id, f_space_id, H5P_DEFAULT, buf) < 0) + goto error; + } else /* possibly not enough memory, read/write by hyperslabs */ { size_t p_type_nbytes = msize; /*size of memory type */ @@ -949,7 +954,7 @@ int do_copy_objects(hid_t fidin, sm_buf=NULL; } } /* hyperslab read */ - }/*nelmts*/ + } /* if (nelmts>0 && space_status==H5D_SPACE_STATUS_NOT_ALLOCATED) */ /*------------------------------------------------------------------------- * amount of compression used @@ -1212,7 +1217,7 @@ static void print_dataset_info(hid_t dcpl_id, int i; - strcpy(strfilter,"\0"); + HDstrcpy(strfilter,"\0"); /* get information about input filters */ if((nfilters = H5Pget_nfilters(dcpl_id)) < 0) @@ -1229,51 +1234,51 @@ static void print_dataset_info(hid_t dcpl_id, break; case H5Z_FILTER_DEFLATE: - strcat(strfilter,"GZIP "); + HDstrcat(strfilter,"GZIP "); #if defined (PRINT_DEBUG) { unsigned level=cd_values[0]; sprintf(temp,"(%d)",level); - strcat(strfilter,temp); + HDstrcat(strfilter,temp); } #endif break; case H5Z_FILTER_SZIP: - strcat(strfilter,"SZIP "); + HDstrcat(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); + HDstrcat(strfilter,temp); if (options_mask & H5_SZIP_EC_OPTION_MASK) - strcpy(temp,"EC) "); + HDstrcpy(temp,"EC) "); else if (options_mask & H5_SZIP_NN_OPTION_MASK) - strcpy(temp,"NN) "); + HDstrcpy(temp,"NN) "); } - strcat(strfilter,temp); + HDstrcat(strfilter,temp); #endif break; case H5Z_FILTER_SHUFFLE: - strcat(strfilter,"SHUF "); + HDstrcat(strfilter,"SHUF "); break; case H5Z_FILTER_FLETCHER32: - strcat(strfilter,"FLET "); + HDstrcat(strfilter,"FLET "); break; case H5Z_FILTER_NBIT: - strcat(strfilter,"NBIT "); + HDstrcat(strfilter,"NBIT "); break; case H5Z_FILTER_SCALEOFFSET: - strcat(strfilter,"SCALEOFFSET "); + HDstrcat(strfilter,"SCALEOFFSET "); break; } /* switch */ }/*i*/ @@ -1283,10 +1288,10 @@ static void print_dataset_info(hid_t dcpl_id, else { char str[255], temp[20]; - strcpy(str,"dset "); - strcat(str,strfilter); + HDstrcpy(str,"dset "); + HDstrcat(str,strfilter); sprintf(temp," (%.3f:1)",ratio); - strcat(str,temp); + HDstrcat(str,temp); printf(FORMAT_OBJ,str,objname); } } @@ -1364,7 +1369,7 @@ copy_user_block(const char *infile, const char *outfile, hsize_t size) } /* end while */ /* Update size of userblock left to transfer */ - size -= nread; + size = size - (hsize_t)nread; } /* end while */ done: |