From 7881deb15e681d6cee22b8c0f20257c762d115b7 Mon Sep 17 00:00:00 2001 From: Elena Pourmal Date: Sat, 21 Feb 2015 22:26:08 -0500 Subject: [svn-r26268] Added VDS example. I ran bin/reconfigure on jam and it modified test/Makefile.in. May be Neil fixed Makefile.am, but didn't run reconfigure? Tested on jam. --- MANIFEST | 1 + examples/Makefile.am | 5 +- examples/Makefile.in | 5 +- examples/h5_vds.c | 244 ++++++++++++++++++++++++++++++++++++++++++++++++ examples/run-c-ex.sh.in | 4 +- test/Makefile.in | 2 +- 6 files changed, 255 insertions(+), 6 deletions(-) create mode 100644 examples/h5_vds.c diff --git a/MANIFEST b/MANIFEST index a0737ef..b6a3168 100644 --- a/MANIFEST +++ b/MANIFEST @@ -150,6 +150,7 @@ ./examples/h5_ref2reg.c ./examples/h5_shared_mesg.c ./examples/ph5example.c +./examples/h5_vds.c ./examples/testh5cc.sh.in ./examples/README diff --git a/examples/Makefile.am b/examples/Makefile.am index 5d0da93..419bb7f 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -37,7 +37,7 @@ EXAMPLE_PROG = h5_write h5_read h5_extend_write h5_chunk_read h5_compound \ h5_crtgrpd h5_subset h5_cmprss h5_rdwt h5_crtgrpar h5_extend \ h5_crtatt h5_crtgrp h5_crtdat \ h5_group h5_select h5_attribute h5_mount h5_reference h5_drivers \ - h5_ref2reg h5_extlink h5_elink_unix2win h5_shared_mesg + h5_ref2reg h5_extlink h5_elink_unix2win h5_shared_mesg h5_vds TEST_SCRIPT=testh5cc.sh TEST_EXAMPLES_SCRIPT=$(INSTALL_SCRIPT_FILES) @@ -48,7 +48,7 @@ INSTALL_FILES = h5_write.c h5_read.c h5_extend_write.c h5_chunk_read.c \ h5_extend.c h5_crtatt.c h5_crtgrp.c h5_crtdat.c \ h5_compound.c h5_group.c h5_select.c h5_attribute.c h5_mount.c \ h5_reference.c h5_drivers.c h5_extlink.c h5_elink_unix2win.c \ - h5_ref2reg.c h5_shared_mesg.c ph5example.c + h5_ref2reg.c h5_shared_mesg.c ph5example.c h5_vds.c @@ -117,6 +117,7 @@ h5_dtransform: $(srcdir)/h5_dtransform.c h5_extlink: $(srcdir)/h5_extlink.c $(EXTLINK_DIRS) h5_elink_unix2win: $(srcdir)/h5_elink_unix2win.c $(EXTLINK_DIRS) h5_shared_mesg: $(srcdir)/h5_shared_mesg.c +h5_vds: $(srcdir)/h5_vds.c if BUILD_SHARED_SZIP_CONDITIONAL LD_LIBRARY_PATH=$(LL_PATH) diff --git a/examples/Makefile.in b/examples/Makefile.in index 71a9b4c..c4b8e3f 100644 --- a/examples/Makefile.in +++ b/examples/Makefile.in @@ -624,7 +624,7 @@ EXAMPLE_PROG = h5_write h5_read h5_extend_write h5_chunk_read h5_compound \ h5_crtgrpd h5_subset h5_cmprss h5_rdwt h5_crtgrpar h5_extend \ h5_crtatt h5_crtgrp h5_crtdat \ h5_group h5_select h5_attribute h5_mount h5_reference h5_drivers \ - h5_ref2reg h5_extlink h5_elink_unix2win h5_shared_mesg + h5_ref2reg h5_extlink h5_elink_unix2win h5_shared_mesg h5_vds TEST_SCRIPT = testh5cc.sh TEST_EXAMPLES_SCRIPT = $(INSTALL_SCRIPT_FILES) @@ -636,7 +636,7 @@ INSTALL_FILES = h5_write.c h5_read.c h5_extend_write.c h5_chunk_read.c \ h5_extend.c h5_crtatt.c h5_crtgrp.c h5_crtdat.c \ h5_compound.c h5_group.c h5_select.c h5_attribute.c h5_mount.c \ h5_reference.c h5_drivers.c h5_extlink.c h5_elink_unix2win.c \ - h5_ref2reg.c h5_shared_mesg.c ph5example.c + h5_ref2reg.c h5_shared_mesg.c ph5example.c h5_vds.c # The external link examples demonstrate how to use paths; they need @@ -1089,6 +1089,7 @@ h5_dtransform: $(srcdir)/h5_dtransform.c h5_extlink: $(srcdir)/h5_extlink.c $(EXTLINK_DIRS) h5_elink_unix2win: $(srcdir)/h5_elink_unix2win.c $(EXTLINK_DIRS) h5_shared_mesg: $(srcdir)/h5_shared_mesg.c +h5_vds: $(srcdir)/h5_vds.c # How to create EXAMPLEDIR if it doesn't already exist $(EXAMPLEDIR): diff --git a/examples/h5_vds.c b/examples/h5_vds.c new file mode 100644 index 0000000..ed30b5b --- /dev/null +++ b/examples/h5_vds.c @@ -0,0 +1,244 @@ +/************************************************************ + + This example illustrates the concept of the virtual dataset. + The program creates three 1-dim source datasets and writes + data to them. Then it creates 2-dim virtual dataset and + maps the first three rows of the virtual dataset to the data + in the source datasets. Elements of a row are mapped to all + elements of the corresponding source dataset. + The fourth row is not mapped and will be filled with the fill + values when virtual dataset is read back. + + The program closes all datasets, and then reopens the virtual + dataset, and finds and prints its creation properties. + Then it reads the values. + + This file is intended for use with HDF5 Library version 1.10 + + ************************************************************/ + +#include "hdf5.h" +#include +#include + +#define FILE "vds.h5" +#define DATASET "VDS" +#define VDSDIM1 6 +#define VDSDIM0 4 +#define DIM0 6 +#define RANK1 1 +#define RANK2 2 + +const char *SRC_FILE[] = { + "a.h5", + "b.h5", + "c.h5" +}; + +const char *SRC_DATASET[] = { + "A", + "B", + "C" +}; + +int +main (void) +{ + hid_t file, space, src_space, vspace, dset; /* Handles */ + hid_t dcpl; + herr_t status; + hsize_t vdsdims[2] = {VDSDIM0, VDSDIM1}, /* Datasets dimension */ + dims[1] = {DIM0}, + start[2], /* Hyperslab parameters */ + stride[2], + count[2], + block[2]; + int wdata[DIM0], /* Write buffer for source dataset */ + rdata[VDSDIM0][VDSDIM1], /* Read buffer for virtual dataset */ + i, j, k, l; + int fill_value = -1; /* Fill value for VDS */ + 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; + hsize_t nblocks; + hsize_t *buf; /* Buffer to hold hyperslab coordinates */ + + /* + * Create source files and datasets. This step is optional. + */ + for (i=0; i < 3; i++) { + /* + * Initialize data for i-th source dataset. + */ + for (j = 0; j < DIM0; 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); + space = H5Screate_simple (RANK1, dims, NULL); + dset = H5Dcreate (file, SRC_DATASET[i], H5T_NATIVE_INT, space, H5P_DEFAULT, + H5P_DEFAULT, H5P_DEFAULT); + status = H5Dwrite (dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, + wdata); + status = H5Sclose (space); + status = H5Dclose (dset); + status = H5Fclose (file); + } + + file = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + + /* Create VDS dataspace. */ + space = H5Screate_simple (RANK2, vdsdims, NULL); + src_space = H5Screate_simple (RANK1, dims, NULL); + + /* Create VDS creation property */ + dcpl = H5Pcreate (H5P_DATASET_CREATE); + status = H5Pset_fill_value (dcpl, H5T_NATIVE_INT, &fill_value); + + /* Initialize hyperslab values */ + start[0] = 0; + start[1] = 0; + count[0] = 1; + count[1] = 1; + block[0] = 1; + block[1] = VDSDIM1; + + /* + * Build the mappings. + * + * Select the first, the second and the third rows and map each row to the data in the + * corresponding source datasets. + */ + for (i = 0; i < 3; i++) { + start[0] = (hsize_t)i; + /* Select i-th row in the virtual dataset; selection in the source datasets is the same. */ + status = H5Sselect_hyperslab (space, H5S_SELECT_SET, start, NULL, count, block); + status = H5Pset_virtual (dcpl, space, SRC_FILE[i], SRC_DATASET[i], src_space); + status = H5Sselect_none (space); + } + + /* Create a virtual dataset */ + dset = H5Dcreate (file, DATASET, H5T_NATIVE_INT, space, H5P_DEFAULT, + dcpl, H5P_DEFAULT); + status = H5Sclose (space); + status = H5Sclose (src_space); + status = H5Dclose (dset); + status = H5Fclose (file); + + /* + * Now we begin the read section of this example. + */ + + /* + * Open file and virtual dataset using the default properties. + */ + file = H5Fopen (FILE, H5F_ACC_RDONLY, H5P_DEFAULT); + dset = H5Dopen (file, DATASET, H5P_DEFAULT); + + /* + * Get creation property list and mapping properties. + */ + dcpl = H5Dget_create_plist (dset); + + /* + * Get storage layout. + */ + layout = H5Pget_layout (dcpl); + if (H5D_VIRTUAL == layout) + printf(" Dataset has a virtual layout \n"); + else + printf("Wrong layout found \n"); + + /* + * Find number of mappings. + */ + status = H5Pget_virtual_count (dcpl, &num_map); + printf("Number of mappings is %d\n", 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 "); + /* Get selection in the virttual dataset */ + vspace = H5Pget_virtual_vspace (dcpl, (size_t)i); + + /* Make sure that this is a hyperslab selection and then print information. */ + if (H5Sget_select_type(vspace) == H5S_SEL_HYPERSLABS) { + nblocks = H5Sget_select_hyper_nblocks (vspace); + buf = (hsize_t *)malloc(sizeof(hsize_t)*2*RANK2*nblocks); + status = H5Sget_select_hyper_blocklist (vspace, (hsize_t)0, nblocks, buf); + for (l=0; l