diff --git a/src/h5core/h5_hdf5_private.h b/src/h5core/h5_hdf5_private.h index b0b8dda..371dd76 100644 --- a/src/h5core/h5_hdf5_private.h +++ b/src/h5core/h5_hdf5_private.h @@ -322,6 +322,23 @@ hdf5_select_elements_of_dataspace ( HDF5_WRAPPER_RETURN (H5_SUCCESS); } +static inline h5_err_t +hdf5_select_none ( + hid_t space_id + ) { + HDF5_WRAPPER_ENTER1 (h5_err_t, + "%d", + space_id); + herr_t herr = H5Sselect_none (space_id); + if (herr < 0) { + HDF5_WRAPPER_LEAVE ( + h5_error ( + H5_ERR_HDF5, + "Selection for writing zero-length data failed")); + } + HDF5_WRAPPER_RETURN (H5_SUCCESS); +} + static inline h5_ssize_t hdf5_get_selected_npoints_of_dataspace ( hid_t space_id diff --git a/src/h5core/h5u_model.c b/src/h5core/h5u_model.c index 63c730c..a4b740e 100644 --- a/src/h5core/h5u_model.c +++ b/src/h5core/h5u_model.c @@ -65,7 +65,7 @@ h5u_set_num_particles ( hsize_t total; hsize_t dmax = H5S_UNLIMITED; - if (nparticles <= 0) + if (nparticles < 0) H5_CORE_API_LEAVE ( h5_error( H5_ERR_INVAL, @@ -154,11 +154,15 @@ h5u_set_num_particles ( count = nparticles; hstride = 1; - TRY( hdf5_select_hyperslab_of_dataspace( - u->diskshape, - H5S_SELECT_SET, - &start, &hstride, &count, - NULL) ); + if (count > 0) { + TRY( hdf5_select_hyperslab_of_dataspace( + u->diskshape, + H5S_SELECT_SET, + &start, &hstride, &count, + NULL) ); + } else { + hdf5_select_none (u->diskshape); + } #endif H5_CORE_API_RETURN (H5_SUCCESS); } @@ -313,11 +317,14 @@ h5u_set_view_indices ( /* declare local memory datasize */ total = u->nparticles; TRY (u->memshape = hdf5_create_dataspace (1, &total, &dmax)); - TRY (hdf5_select_elements_of_dataspace ( - u->diskshape, - H5S_SELECT_SET, - (hsize_t)nelems, (hsize_t*)indices ) ); - + if (nelems > 0) { + TRY (hdf5_select_elements_of_dataspace ( + u->diskshape, + H5S_SELECT_SET, + (hsize_t)nelems, (hsize_t*)indices ) ); + } else { + TRY (hdf5_select_none (u->diskshape)); + } u->viewindexed = 1; H5_CORE_API_RETURN (H5_SUCCESS);