summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/h5repack/h5repack_copy.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/tools/h5repack/h5repack_copy.c b/tools/h5repack/h5repack_copy.c
index 6c47cfb..7d2c929 100644
--- a/tools/h5repack/h5repack_copy.c
+++ b/tools/h5repack/h5repack_copy.c
@@ -559,6 +559,7 @@ int do_copy_objects(hid_t fidin,
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 */
@@ -746,6 +747,10 @@ 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++)
{
@@ -834,9 +839,11 @@ 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 */
+
+ /* have to read the whole dataset if there is only one element in the dataset */
if ( need < H5TOOLS_MALLOCSIZE )
buf = HDmalloc(need);
@@ -847,7 +854,6 @@ int do_copy_objects(hid_t fidin,
if (H5Dwrite(dset_out,wtype_id,H5S_ALL,H5S_ALL,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 +955,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