Skip to content

Commit

Permalink
rest_vol_dataset: (fix) Write hyperslab (memory)
Browse files Browse the repository at this point in the history
- Improved the function RV_dataset_write() such it makes use
  of the function H5Dgather() to gather the data needed
  for writing a hyperslab (memory) to a file. This approach
  is similar to the one found in the function RV_dataset_read().
- Adapted the hyperslab and point selection test.
  • Loading branch information
jwsblokland committed Aug 23, 2023
1 parent 875b8ce commit 69ccdeb
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/rest_vol_dataset.c
Original file line number Diff line number Diff line change
Expand Up @@ -829,6 +829,13 @@ RV_dataset_write(size_t count, void *dset[], hid_t mem_type_id[], hid_t mem_spac
FUNC_GOTO_ERROR(H5E_DATATYPE, H5E_BADVALUE, FAIL, "memory datatype is invalid");

write_body_len = (size_t)file_select_npoints * dtype_size;
if (NULL == (write_body = (char *)RV_malloc(write_body_len)))
FUNC_GOTO_ERROR(H5E_DATASPACE, H5E_CANTALLOC, FAIL,
"can't allocate space for the 'write_body' values");
if (H5Dgather(mem_space_id[0], buf[0], mem_type_id[0], write_body_len, write_body, NULL,
write_body) < 0)
FUNC_GOTO_ERROR(H5E_DATASET, H5E_WRITEERROR, FAIL, "can't gather data to write buffer");
buf[0] = write_body;
} /* end if */
else {
if (H5T_STD_REF_OBJ == mem_type_id[0]) {
Expand Down
30 changes: 27 additions & 3 deletions test/test_rest_vol.c
Original file line number Diff line number Diff line change
Expand Up @@ -8539,6 +8539,7 @@ test_write_dataset_data_verification(void)
{
hssize_t space_npoints;
hsize_t dims[DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK] = {10, 10, 10};
hsize_t mdims[1];
hsize_t start[DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK];
hsize_t stride[DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK];
hsize_t count[DATASET_DATA_VERIFY_WRITE_TEST_DSET_SPACE_RANK];
Expand All @@ -8550,6 +8551,7 @@ test_write_dataset_data_verification(void)
hid_t container_group = -1;
hid_t dset_id = -1;
hid_t fspace_id = -1;
hid_t mspace_id = -1;
void *data = NULL;
void *write_buf = NULL;
void *read_buf = NULL;
Expand Down Expand Up @@ -8697,23 +8699,34 @@ test_write_dataset_data_verification(void)
}

/* Write to first two rows of dataset */
mdims[0] = dims[1] * 2;
start[0] = 0;
stride[0] = 1;
count[0] = dims[1] * 2;
block[0] = 1;
if ((mspace_id = H5Screate_simple(1, mdims, NULL)) < 0)
TEST_ERROR
if (H5Sselect_hyperslab(mspace_id, H5S_SELECT_SET, start, stride, count, block) < 0)
TEST_ERROR

start[0] = start[1] = start[2] = 0;
stride[0] = stride[1] = stride[2] = 1;
count[0] = 2;
count[1] = dims[1];
count[2] = 1;
block[0] = block[1] = block[2] = 1;

if (H5Sselect_hyperslab(fspace_id, H5S_SELECT_SET, start, stride, count, block) < 0)
TEST_ERROR

if (H5Dwrite(dset_id, DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPE, H5S_ALL, fspace_id, H5P_DEFAULT,
if (H5Dwrite(dset_id, DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPE, mspace_id, fspace_id, H5P_DEFAULT,
write_buf) < 0) {
H5_FAILED();
printf(" couldn't write to dataset\n");
goto error;
}

if (H5Sclose(mspace_id) < 0)
TEST_ERROR
if (H5Sclose(fspace_id) < 0)
TEST_ERROR
if (H5Dclose(dset_id) < 0)
Expand Down Expand Up @@ -8814,6 +8827,15 @@ test_write_dataset_data_verification(void)
}

/* Select a series of 10 points in the dataset */
mdims[0] = DATASET_DATA_VERIFY_WRITE_TEST_NUM_POINTS;
if ((mspace_id = H5Screate_simple(1, mdims, NULL)) < 0)
TEST_ERROR
for (i = 0; i < DATASET_DATA_VERIFY_WRITE_TEST_NUM_POINTS; i++) {
points[i] = i;
}
if (H5Sselect_elements(mspace_id, H5S_SELECT_SET, DATASET_DATA_VERIFY_WRITE_TEST_NUM_POINTS, points) < 0)
TEST_ERROR

for (i = 0; i < DATASET_DATA_VERIFY_WRITE_TEST_NUM_POINTS; i++) {
size_t j;

Expand All @@ -8824,13 +8846,15 @@ test_write_dataset_data_verification(void)
if (H5Sselect_elements(fspace_id, H5S_SELECT_SET, DATASET_DATA_VERIFY_WRITE_TEST_NUM_POINTS, points) < 0)
TEST_ERROR

if (H5Dwrite(dset_id, DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPE, H5S_ALL, fspace_id, H5P_DEFAULT,
if (H5Dwrite(dset_id, DATASET_DATA_VERIFY_WRITE_TEST_DSET_DTYPE, mspace_id, fspace_id, H5P_DEFAULT,
write_buf) < 0) {
H5_FAILED();
printf(" couldn't write to dataset\n");
goto error;
}

if (H5Sclose(mspace_id) < 0)
TEST_ERROR
if (H5Sclose(fspace_id) < 0)
TEST_ERROR
if (H5Dclose(dset_id) < 0)
Expand Down

0 comments on commit 69ccdeb

Please sign in to comment.