From f3f74731619798b8e802987b01266348f1fbc027 Mon Sep 17 00:00:00 2001 From: Elena Pourmal Date: Tue, 28 Apr 2015 18:23:02 -0500 Subject: [svn-r26960] Added example of unlimited VDS using Percival use case. --- examples/h5_vds-percival-unlim.c | 293 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 293 insertions(+) create mode 100644 examples/h5_vds-percival-unlim.c diff --git a/examples/h5_vds-percival-unlim.c b/examples/h5_vds-percival-unlim.c new file mode 100644 index 0000000..1911e6d --- /dev/null +++ b/examples/h5_vds-percival-unlim.c @@ -0,0 +1,293 @@ +/************************************************************ + + This example illustrates the concept of the virtual dataset. + Percival use case. Every fifth 10x10 plane in VDS is stored in + the corresponding 3D unlimited dataset. + There are 4 source datasets total. + This file is intended for use with HDF5 Library version 1.10 + + ************************************************************/ +/* EIP Add link to the picture */ + +#include "hdf5.h" +#include +#include + +#define FILE "vds-percival-unlim.h5" +#define DATASET "VDS-Percival-unlim" +#define VDSDIM0 H5S_UNLIMITED +#define VDSDIM1 10 +#define VDSDIM2 10 + +#define DIM0 H5S_UNLIMITED +#define DIM0_1 10 /* Initial size of the datasets */ +#define DIM1 10 +#define DIM2 10 +#define RANK 3 +#define PLANE_STRIDE 4 + +const char *SRC_FILE[] = { + "a.h5", + "b.h5", + "c.h5", + "d.h5" +}; + +const char *SRC_DATASET[] = { + "A", + "B", + "C", + "D" +}; + +int +main (void) +{ + hid_t vfile, file, src_space, mem_space, vspace, + vdset, dset; /* Handles */ + hid_t dcpl; + herr_t status; + hsize_t vdsdims[3] = {4*DIM0_1, VDSDIM1, VDSDIM2}, + vdsdims_max[3] = {VDSDIM0, VDSDIM1, VDSDIM2}, + dims[3] = {DIM0_1, DIM1, DIM2}, + extdims[3] = {2*DIM0_1, DIM1, DIM2}, + chunk_dims[3] = {DIM0_1, DIM1, DIM2}, + dims_max[3] = {DIM0, DIM1, DIM2}, + vdsdims_out[3], + vdsdims_max_out[3], + start[3], /* Hyperslab parameters */ + stride[3], + count[3], + src_count[3], + block[3]; + hsize_t start_out[3], /* Hyperslab parameter out */ + stride_out[3], + count_out[3], + block_out[3]; + int i, j; + H5D_layout_t layout; /* Storage layout */ + size_t num_map; /* Number of mappings */ + ssize_t len; /* Length of the string; also a return value */ + char *filename; + char *dsetname; + int wdata[DIM0_1*DIM1*DIM2]; + + /* + * Create source files and datasets. This step is optional. + */ + for (i=0; i < PLANE_STRIDE; i++) { + /* + * Initialize data for i-th source dataset. + */ + for (j = 0; j < DIM0_1*DIM1*DIM2; j++) wdata[j] = i+1; + + /* + * Create the source files and datasets. Write data to each dataset and + * close all resources. + */ + + file = H5Fcreate (SRC_FILE[i], H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + src_space = H5Screate_simple (RANK, dims, dims_max); + dcpl = H5Pcreate(H5P_DATASET_CREATE); + status = H5Pset_chunk (dcpl, RANK, chunk_dims); + dset = H5Dcreate (file, SRC_DATASET[i], H5T_NATIVE_INT, src_space, H5P_DEFAULT, + dcpl, H5P_DEFAULT); + status = H5Dwrite (dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, + wdata); + status = H5Sclose (src_space); + status = H5Pclose (dcpl); + status = H5Dclose (dset); + status = H5Fclose (file); + } + + file = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + + /* Create VDS dataspace. */ + vspace = H5Screate_simple (RANK, vdsdims, vdsdims_max); + + /* Create dataspaces for the source dataset. */ + src_space = H5Screate_simple (RANK, dims, dims_max); + + /* Create VDS creation property */ + dcpl = H5Pcreate (H5P_DATASET_CREATE); + + /* Initialize hyperslab values */ + + start[0] = 0; + start[1] = 0; + start[2] = 0; + stride[0] = PLANE_STRIDE; /* we will select every fifth plane in VDS */ + stride[1] = 1; + stride[2] = 1; + count[0] = H5S_UNLIMITED; + count[1] = 1; + count[2] = 1; + src_count[0] = H5S_UNLIMITED; + src_count[1] = 1; + src_count[2] = 1; + block[0] = 1; + block[1] = DIM1; + block[2] = DIM2; + + /* + * Build the mappings + * + */ + status = H5Sselect_hyperslab (src_space, H5S_SELECT_SET, start, NULL, src_count, block); + for (i=0; i < PLANE_STRIDE; i++) { + status = H5Sselect_hyperslab (vspace, H5S_SELECT_SET, start, stride, count, block); + status = H5Pset_virtual (dcpl, vspace, SRC_FILE[i], SRC_DATASET[i], src_space); + start[0]++; + } + + H5Sselect_none(vspace); + + /* Create a virtual dataset */ + vdset = H5Dcreate (vfile, DATASET, H5T_NATIVE_INT, vspace, H5P_DEFAULT, + dcpl, H5P_DEFAULT); + status = H5Sclose (vspace); + status = H5Sclose (src_space); + /* Let's get space of the VDS and its dimension; we should get 40x10x10 */ + vspace = H5Dget_space (vdset); + H5Sget_simple_extent_dims (vspace, vdsdims_out, vdsdims_max_out); + printf ("VDS dimensions first time \n"); + printf (" Current: "); + for (i=0; i