2017-01-27 03:34:12 +08:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
|
|
* Copyright by The HDF Group. *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
2024-10-19 12:13:04 +08:00
|
|
|
* the LICENSE file, which can be found at the root of the source code *
|
2021-02-17 22:52:04 +08:00
|
|
|
* distribution tree, or in https://www.hdfgroup.org/licenses. *
|
2017-04-18 03:32:16 +08:00
|
|
|
* If you do not have access to either file, you may request a copy from *
|
|
|
|
* help@hdfgroup.org. *
|
2017-01-27 03:34:12 +08:00
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
|
|
|
#include "h5test.h"
|
|
|
|
#include "vds_swmr.h"
|
|
|
|
|
2019-07-03 12:43:45 +08:00
|
|
|
static hsize_t VDS_PLANE[RANK] = {1, FULL_HEIGHT, WIDTH};
|
|
|
|
|
2017-01-27 03:34:12 +08:00
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
2023-09-09 07:06:23 +08:00
|
|
|
hid_t fid = H5I_INVALID_HID; /* HDF5 file ID */
|
|
|
|
hid_t faplid = H5I_INVALID_HID; /* file access property list ID */
|
|
|
|
hid_t did = H5I_INVALID_HID; /* dataset ID */
|
|
|
|
hid_t msid = H5I_INVALID_HID; /* memory dataspace ID */
|
|
|
|
hid_t fsid = H5I_INVALID_HID; /* file dataspace ID */
|
2017-01-27 03:34:12 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
hsize_t start[RANK]; /* hyperslab start point */
|
2017-01-27 03:34:12 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
int n_elements = 0; /* size of buffer (elements) */
|
|
|
|
size_t size = 0; /* size of buffer (bytes) */
|
2022-07-27 05:45:46 +08:00
|
|
|
int *buffer = NULL; /* data buffer */
|
2017-01-27 03:34:12 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
int n_dims = -1; /* # dimensions in dataset */
|
|
|
|
hsize_t dims[RANK]; /* current size of dataset */
|
|
|
|
hsize_t max_dims[RANK]; /* max size of dataset */
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Open the VDS file and dataset */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((faplid = h5_fileaccess()) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((fid = H5Fopen(VDS_FILE_NAME, H5F_ACC_RDONLY | H5F_ACC_SWMR_READ, faplid)) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((did = H5Dopen2(fid, VDS_DSET_NAME, H5P_DEFAULT)) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Create the read buffer */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (VDS_PLANE[1] * VDS_PLANE[2] > INT_MAX)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2020-01-24 05:12:00 +08:00
|
|
|
n_elements = (int)(VDS_PLANE[1] * VDS_PLANE[2]);
|
2020-09-30 22:27:10 +08:00
|
|
|
size = (size_t)n_elements * sizeof(int);
|
2023-06-29 06:48:12 +08:00
|
|
|
if (NULL == (buffer = (int *)malloc(size)))
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Create memory dataspace */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((msid = H5Screate_simple(RANK, VDS_PLANE, NULL)) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Read data until the dataset is full (via the writer) */
|
|
|
|
do {
|
|
|
|
|
|
|
|
/* Refresh metadata */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Drefresh(did) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Get the dataset dimensions */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((fsid = H5Dget_space(did)) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Sget_simple_extent_dims(fsid, dims, max_dims) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Check the reported size of the VDS */
|
2020-09-30 22:27:10 +08:00
|
|
|
if ((n_dims = H5Sget_simple_extent_ndims(fsid)) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (n_dims != RANK)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Sget_simple_extent_dims(fsid, dims, max_dims) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2017-01-27 03:34:12 +08:00
|
|
|
/* NOTE: Don't care what dims[0] is. */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (dims[1] != FULL_HEIGHT)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (dims[2] != WIDTH)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (max_dims[0] != H5S_UNLIMITED)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (max_dims[1] != FULL_HEIGHT)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (max_dims[2] != WIDTH)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
/* Continue if there's nothing to read */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (0 == dims[0]) {
|
|
|
|
if (H5Sclose(fsid) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2017-01-27 03:34:12 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Read a plane from the VDS */
|
|
|
|
/* At this time, we just make sure we can read planes without errors. */
|
|
|
|
start[0] = dims[0] - 1;
|
|
|
|
start[1] = 0;
|
|
|
|
start[2] = 0;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Sselect_hyperslab(fsid, H5S_SELECT_SET, start, NULL, VDS_PLANE, NULL) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Dread(did, H5T_NATIVE_INT, msid, fsid, H5P_DEFAULT, buffer) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Sclose(fsid) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2017-01-27 03:34:12 +08:00
|
|
|
|
|
|
|
} while (dims[0] < N_PLANES_TO_WRITE);
|
|
|
|
|
|
|
|
/* Close file and dataset */
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Pclose(faplid) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Sclose(msid) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Dclose(did) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2020-09-30 22:27:10 +08:00
|
|
|
if (H5Fclose(fid) < 0)
|
2022-05-04 23:49:01 +08:00
|
|
|
TEST_ERROR;
|
2017-01-27 03:34:12 +08:00
|
|
|
|
2023-06-29 06:48:12 +08:00
|
|
|
free(buffer);
|
2017-01-27 03:34:12 +08:00
|
|
|
|
2023-06-28 23:31:32 +08:00
|
|
|
fprintf(stderr, "SWMR reader exited successfully\n");
|
2017-01-27 03:34:12 +08:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
|
|
|
|
error:
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
H5E_BEGIN_TRY
|
|
|
|
{
|
|
|
|
if (fid >= 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
(void)H5Fclose(fid);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (faplid >= 0)
|
2018-10-27 14:33:07 +08:00
|
|
|
(void)H5Pclose(faplid);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (did >= 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
(void)H5Dclose(did);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (msid >= 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
(void)H5Sclose(msid);
|
2020-09-30 22:27:10 +08:00
|
|
|
if (fsid >= 0)
|
2017-01-27 03:34:12 +08:00
|
|
|
(void)H5Sclose(fsid);
|
2020-09-30 22:27:10 +08:00
|
|
|
}
|
|
|
|
H5E_END_TRY
|
2017-01-27 03:34:12 +08:00
|
|
|
|
2023-06-29 06:48:12 +08:00
|
|
|
free(buffer);
|
2022-05-04 23:49:01 +08:00
|
|
|
|
2023-06-28 23:31:32 +08:00
|
|
|
fprintf(stderr, "ERROR: SWMR reader exited with errors\n");
|
2017-01-27 03:34:12 +08:00
|
|
|
return EXIT_FAILURE;
|
|
|
|
|
|
|
|
} /* end main */
|