2017-04-18 03:32:16 +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 *
|
|
|
|
* the COPYING file, which can be found at the root of the source code *
|
2021-02-17 22:52:36 +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. *
|
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
2015-03-05 01:03:32 +08:00
|
|
|
/************************************************************
|
|
|
|
|
|
|
|
This example illustrates the concept of the virtual dataset.
|
|
|
|
Excalibur use case with k=2 and m=3.
|
|
|
|
This file is intended for use with HDF5 Library version 1.10
|
|
|
|
|
|
|
|
************************************************************/
|
2015-03-11 06:15:20 +08:00
|
|
|
/* EIP Add link to the picture */
|
2015-03-05 01:03:32 +08:00
|
|
|
|
|
|
|
#include "hdf5.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
#define FILE "vds-exc.h5"
|
|
|
|
#define DATASET "VDS-Excalibur"
|
|
|
|
#define VDSDIM0 0
|
|
|
|
#define VDSDIM1 15
|
|
|
|
#define VDSDIM2 6
|
|
|
|
#define KDIM0 0
|
|
|
|
#define KDIM1 2
|
|
|
|
#define KDIM2 6
|
|
|
|
#define NDIM0 0
|
|
|
|
#define NDIM1 3
|
|
|
|
#define NDIM2 6
|
|
|
|
#define RANK 3
|
|
|
|
|
|
|
|
const char *SRC_FILE[] = {"a.h5", "b.h5", "c.h5", "d.h5", "e.h5", "f.h5"};
|
|
|
|
|
|
|
|
const char *SRC_DATASET[] = {"A", "B", "C", "D", "E", "F"};
|
2015-03-05 01:03:32 +08:00
|
|
|
|
|
|
|
int
|
2020-09-30 22:27:10 +08:00
|
|
|
main(void)
|
2015-03-05 01:03:32 +08:00
|
|
|
{
|
2020-09-30 22:27:10 +08:00
|
|
|
hid_t file, space, ksrc_space, nsrc_space, vspace, src_space, dset; /* Handles */
|
|
|
|
hid_t dcpl;
|
|
|
|
herr_t status;
|
|
|
|
hsize_t vdsdims[3] = {VDSDIM0, VDSDIM1, VDSDIM2}, vdsdims_max[3] = {H5S_UNLIMITED, VDSDIM1, VDSDIM2},
|
|
|
|
kdims[3] = {KDIM0, KDIM1, KDIM2}, kdims_max[3] = {H5S_UNLIMITED, KDIM1, KDIM2},
|
|
|
|
ndims[3] = {NDIM0, NDIM1, NDIM2}, ndims_max[3] = {H5S_UNLIMITED, NDIM1, NDIM2},
|
|
|
|
start[3], /* Hyperslab parameters */
|
2023-06-19 13:13:38 +08:00
|
|
|
count[3], block[3];
|
2020-09-30 22:27:10 +08:00
|
|
|
hsize_t start_out[3], stride_out[3], count_out[3], block_out[3];
|
2015-03-05 01:03:32 +08:00
|
|
|
int k = 2;
|
|
|
|
int n = 3;
|
|
|
|
int i;
|
2020-09-30 22:27:10 +08:00
|
|
|
H5D_layout_t layout; /* Storage layout */
|
|
|
|
size_t num_map; /* Number of mappings */
|
|
|
|
ssize_t len; /* Length of the string; also a return value */
|
2022-07-27 05:45:46 +08:00
|
|
|
char *filename;
|
|
|
|
char *dsetname;
|
2015-03-05 01:03:32 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
file = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
2015-03-05 01:03:32 +08:00
|
|
|
|
|
|
|
/* Create VDS dataspace. */
|
2020-09-30 22:27:10 +08:00
|
|
|
space = H5Screate_simple(RANK, vdsdims, vdsdims_max);
|
2015-03-05 01:03:32 +08:00
|
|
|
/* Create dataspaces for A, C, and E datasets. */
|
2020-09-30 22:27:10 +08:00
|
|
|
ksrc_space = H5Screate_simple(RANK, kdims, kdims_max);
|
2015-03-05 01:03:32 +08:00
|
|
|
/* Create dataspaces for B, D, and F datasets. */
|
2020-09-30 22:27:10 +08:00
|
|
|
nsrc_space = H5Screate_simple(RANK, ndims, ndims_max);
|
2015-03-05 01:03:32 +08:00
|
|
|
|
|
|
|
/* Create VDS creation property */
|
2020-09-30 22:27:10 +08:00
|
|
|
dcpl = H5Pcreate(H5P_DATASET_CREATE);
|
2020-04-21 07:12:00 +08:00
|
|
|
|
2015-03-05 01:03:32 +08:00
|
|
|
/* Initialize hyperslab values */
|
|
|
|
|
|
|
|
start[0] = 0;
|
|
|
|
start[1] = 0;
|
|
|
|
start[2] = 0;
|
|
|
|
count[0] = H5S_UNLIMITED;
|
|
|
|
count[1] = 1;
|
|
|
|
count[2] = 1;
|
|
|
|
block[0] = 1;
|
|
|
|
block[1] = k;
|
2015-03-06 07:04:57 +08:00
|
|
|
block[2] = VDSDIM2;
|
2015-03-05 01:03:32 +08:00
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
/*
|
|
|
|
* Build the mappings for A, C and E source datasets.
|
|
|
|
* Unlimited hyperslab selection is the same in the source datasets.
|
|
|
|
* Unlimited hyperslab selections in the virtual dataset have different offsets.
|
|
|
|
*/
|
|
|
|
status = H5Sselect_hyperslab(ksrc_space, H5S_SELECT_SET, start, NULL, count, block);
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
start[1] = (hsize_t)((k + n) * i);
|
|
|
|
status = H5Sselect_hyperslab(space, H5S_SELECT_SET, start, NULL, count, block);
|
|
|
|
status = H5Pset_virtual(dcpl, space, SRC_FILE[2 * i], SRC_DATASET[2 * i], ksrc_space);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reinitialize start[1] and block[1] to build the second set of mappings. */
|
|
|
|
start[1] = 0;
|
|
|
|
block[1] = n;
|
|
|
|
/*
|
|
|
|
* Build the mappings for B, D and F source datasets.
|
|
|
|
* Unlimited hyperslab selection is the same in the source datasets.
|
|
|
|
* Unlimited hyperslab selections in the virtual dataset have different offsets.
|
|
|
|
*/
|
|
|
|
status = H5Sselect_hyperslab(nsrc_space, H5S_SELECT_SET, start, NULL, count, block);
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
|
|
start[1] = (hsize_t)(k + (k + n) * i);
|
|
|
|
status = H5Sselect_hyperslab(space, H5S_SELECT_SET, start, NULL, count, block);
|
|
|
|
status = H5Pset_virtual(dcpl, space, SRC_FILE[2 * i + 1], SRC_DATASET[2 * i + 1], nsrc_space);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create a virtual dataset */
|
|
|
|
dset = H5Dcreate2(file, DATASET, H5T_NATIVE_INT, space, H5P_DEFAULT, dcpl, H5P_DEFAULT);
|
|
|
|
status = H5Sclose(space);
|
|
|
|
status = H5Sclose(nsrc_space);
|
|
|
|
status = H5Sclose(ksrc_space);
|
|
|
|
status = H5Dclose(dset);
|
|
|
|
status = H5Fclose(file);
|
2015-03-05 01:03:32 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now we begin the read section of this example.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Open file and dataset using the default properties.
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
file = H5Fopen(FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
|
|
|
|
dset = H5Dopen2(file, DATASET, H5P_DEFAULT);
|
2015-03-05 01:03:32 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get creation property list and mapping properties.
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
dcpl = H5Dget_create_plist(dset);
|
2015-03-05 01:03:32 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Get storage layout.
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
layout = H5Pget_layout(dcpl);
|
2015-03-05 01:03:32 +08:00
|
|
|
|
2020-04-21 07:12:00 +08:00
|
|
|
if (H5D_VIRTUAL == layout)
|
2015-03-05 01:03:32 +08:00
|
|
|
printf(" Dataset has a virtual layout \n");
|
|
|
|
else
|
|
|
|
printf("Wrong layout found \n");
|
|
|
|
|
2020-09-30 22:27:10 +08:00
|
|
|
/*
|
|
|
|
* Find number of mappings.
|
|
|
|
*/
|
|
|
|
status = H5Pget_virtual_count(dcpl, &num_map);
|
|
|
|
printf(" Number of mappings is %lu\n", (unsigned long)num_map);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get mapping parameters for each mapping.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < (int)num_map; i++) {
|
|
|
|
printf(" Mapping %d \n", i);
|
|
|
|
printf(" Selection in the virtual dataset \n");
|
2022-08-11 04:57:26 +08:00
|
|
|
/* Get selection in the virtual dataset */
|
2020-09-30 22:27:10 +08:00
|
|
|
vspace = H5Pget_virtual_vspace(dcpl, (size_t)i);
|
|
|
|
if (H5Sget_select_type(vspace) == H5S_SEL_HYPERSLABS) {
|
|
|
|
if (H5Sis_regular_hyperslab(vspace)) {
|
|
|
|
status = H5Sget_regular_hyperslab(vspace, start_out, stride_out, count_out, block_out);
|
|
|
|
printf(" start = [%llu, %llu, %llu] \n", (unsigned long long)start_out[0],
|
|
|
|
(unsigned long long)start_out[1], (unsigned long long)start_out[2]);
|
|
|
|
printf(" stride = [%llu, %llu, %llu] \n", (unsigned long long)stride_out[0],
|
|
|
|
(unsigned long long)stride_out[1], (unsigned long long)stride_out[2]);
|
|
|
|
printf(" count = [%llu, %llu, %llu] \n", (unsigned long long)count_out[0],
|
|
|
|
(unsigned long long)count_out[1], (unsigned long long)count_out[2]);
|
|
|
|
printf(" block = [%llu, %llu, %llu] \n", (unsigned long long)block_out[0],
|
|
|
|
(unsigned long long)block_out[1], (unsigned long long)block_out[2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Get source file name */
|
|
|
|
len = H5Pget_virtual_filename(dcpl, (size_t)i, NULL, 0);
|
|
|
|
filename = (char *)malloc((size_t)len * sizeof(char) + 1);
|
|
|
|
H5Pget_virtual_filename(dcpl, (size_t)i, filename, len + 1);
|
|
|
|
printf(" Source filename %s\n", filename);
|
|
|
|
|
|
|
|
/* Get source dataset name */
|
|
|
|
len = H5Pget_virtual_dsetname(dcpl, (size_t)i, NULL, 0);
|
|
|
|
dsetname = (char *)malloc((size_t)len * sizeof(char) + 1);
|
|
|
|
H5Pget_virtual_dsetname(dcpl, (size_t)i, dsetname, len + 1);
|
|
|
|
printf(" Source dataset name %s\n", dsetname);
|
|
|
|
|
|
|
|
/* Get selection in the source dataset */
|
|
|
|
printf(" Selection in the source dataset \n");
|
|
|
|
src_space = H5Pget_virtual_srcspace(dcpl, (size_t)i);
|
|
|
|
if (H5Sget_select_type(src_space) == H5S_SEL_HYPERSLABS) {
|
|
|
|
if (H5Sis_regular_hyperslab(vspace)) {
|
|
|
|
status = H5Sget_regular_hyperslab(src_space, start_out, stride_out, count_out, block_out);
|
|
|
|
printf(" start = [%llu, %llu, %llu] \n", (unsigned long long)start_out[0],
|
|
|
|
(unsigned long long)start_out[1], (unsigned long long)start_out[2]);
|
|
|
|
printf(" stride = [%llu, %llu, %llu] \n", (unsigned long long)stride_out[0],
|
|
|
|
(unsigned long long)stride_out[1], (unsigned long long)stride_out[2]);
|
|
|
|
printf(" count = [%llu, %llu, %llu] \n", (unsigned long long)count_out[0],
|
|
|
|
(unsigned long long)count_out[1], (unsigned long long)count_out[2]);
|
|
|
|
printf(" block = [%llu, %llu, %llu] \n", (unsigned long long)block_out[0],
|
|
|
|
(unsigned long long)block_out[1], (unsigned long long)block_out[2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
H5Sclose(vspace);
|
|
|
|
H5Sclose(src_space);
|
|
|
|
free(filename);
|
|
|
|
free(dsetname);
|
|
|
|
}
|
|
|
|
/* EIP read data back */
|
2015-03-05 01:03:32 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Close and release resources.
|
|
|
|
*/
|
2020-09-30 22:27:10 +08:00
|
|
|
status = H5Pclose(dcpl);
|
|
|
|
status = H5Dclose(dset);
|
|
|
|
status = H5Fclose(file);
|
2015-03-05 01:03:32 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|