summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorElena Pourmal <epourmal@hdfgroup.org>2015-03-10 22:15:20 (GMT)
committerElena Pourmal <epourmal@hdfgroup.org>2015-03-10 22:15:20 (GMT)
commitca2a0b80c5ca46db7b167cf384bd6e32dfe075c5 (patch)
tree1032c73973af76e2d04fbdb57b9fd023b5cc8d58 /examples
parent92d7b82d61458f9576dc30236b9f9ce03adde9c3 (diff)
downloadhdf5-ca2a0b80c5ca46db7b167cf384bd6e32dfe075c5.zip
hdf5-ca2a0b80c5ca46db7b167cf384bd6e32dfe075c5.tar.gz
hdf5-ca2a0b80c5ca46db7b167cf384bd6e32dfe075c5.tar.bz2
[svn-r26420] Added new example for simple I/O. Modified other examples according to the suggestion in H5VDS-7 (see VDS-178)
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile.am5
-rw-r--r--examples/Makefile.in5
-rw-r--r--examples/h5_vds-eiger.c10
-rw-r--r--examples/h5_vds-exc.c10
-rw-r--r--examples/h5_vds-exclim.c10
-rw-r--r--examples/h5_vds-simpleIO.c186
-rw-r--r--examples/h5_vds.c23
-rw-r--r--examples/run-c-ex.sh.in8
8 files changed, 227 insertions, 30 deletions
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 667fb3a..7c94190 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -38,7 +38,7 @@ EXAMPLE_PROG = h5_write h5_read h5_extend_write h5_chunk_read h5_compound \
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_vds h5_vds-exc \
- h5_vds-exclim h5_vds-eiger
+ h5_vds-exclim h5_vds-eiger h5_vds-simpleIO
TEST_SCRIPT=testh5cc.sh
TEST_EXAMPLES_SCRIPT=$(INSTALL_SCRIPT_FILES)
@@ -50,7 +50,7 @@ INSTALL_FILES = h5_write.c h5_read.c h5_extend_write.c h5_chunk_read.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_vds.c h5_vds-exc.c \
- h5_vds-exclim.c h5_vds-eiger.c
+ h5_vds-exclim.c h5_vds-eiger.c h5_vds-simpleIO.c
@@ -123,6 +123,7 @@ h5_vds: $(srcdir)/h5_vds.c
h5_vds-exc: $(srcdir)/h5_vds-exc.c
h5_vds-exclim: $(srcdir)/h5_vds-exclim.c
h5_vds-eiger: $(srcdir)/h5_vds-eiger.c
+h5_vds-simpleIO: $(srcdir)/h5_vds-simpleIO.c
if BUILD_SHARED_SZIP_CONDITIONAL
LD_LIBRARY_PATH=$(LL_PATH)
diff --git a/examples/Makefile.in b/examples/Makefile.in
index 45a9691..b614977 100644
--- a/examples/Makefile.in
+++ b/examples/Makefile.in
@@ -626,7 +626,7 @@ EXAMPLE_PROG = h5_write h5_read h5_extend_write h5_chunk_read h5_compound \
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_vds h5_vds-exc \
- h5_vds-exclim h5_vds-eiger
+ h5_vds-exclim h5_vds-eiger h5_vds-simpleIO
TEST_SCRIPT = testh5cc.sh
TEST_EXAMPLES_SCRIPT = $(INSTALL_SCRIPT_FILES)
@@ -639,7 +639,7 @@ INSTALL_FILES = h5_write.c h5_read.c h5_extend_write.c h5_chunk_read.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_vds.c h5_vds-exc.c \
- h5_vds-exclim.c h5_vds-eiger.c
+ h5_vds-exclim.c h5_vds-eiger.c h5_vds-simpleIO.c
# The external link examples demonstrate how to use paths; they need
@@ -1096,6 +1096,7 @@ h5_vds: $(srcdir)/h5_vds.c
h5_vds-exc: $(srcdir)/h5_vds-exc.c
h5_vds-exclim: $(srcdir)/h5_vds-exclim.c
h5_vds-eiger: $(srcdir)/h5_vds-eiger.c
+h5_vds-simpleIO: $(srcdir)/h5_vds-simpleIO.c
# How to create EXAMPLEDIR if it doesn't already exist
$(EXAMPLEDIR):
diff --git a/examples/h5_vds-eiger.c b/examples/h5_vds-eiger.c
index d35fc85..93b39b2 100644
--- a/examples/h5_vds-eiger.c
+++ b/examples/h5_vds-eiger.c
@@ -6,6 +6,7 @@
This file is intended for use with HDF5 Library version 1.10
************************************************************/
+/* EIP Add link to the picture */
#include "hdf5.h"
#include <stdio.h>
@@ -133,10 +134,10 @@ main (void)
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 = [%d, %d, %d] \n", (int)start_out[0], (int)start_out[1], (int)start_out[2]);
- printf(" stride = [%d, %d, %d] \n", (int)stride_out[0], (int)stride_out[1], (int)stride_out[2]);
- printf(" count = [%d, %d, %d] \n", (int)count_out[0], (int)count_out[1], (int)count_out[2]);
- printf(" block = [%d, %d, %d] \n", (int)block_out[0], (int)block_out[1], (int)block_out[2]);
+ 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 */
@@ -157,6 +158,7 @@ main (void)
if(H5Sget_select_type(src_space) == H5S_SEL_ALL) {
printf("H5S_ALL \n");
}
+/* EIP read data back */
H5Sclose(vspace);
H5Sclose(src_space);
free(filename);
diff --git a/examples/h5_vds-exc.c b/examples/h5_vds-exc.c
index ceafe68..509b3e1 100644
--- a/examples/h5_vds-exc.c
+++ b/examples/h5_vds-exc.c
@@ -5,6 +5,7 @@
This file is intended for use with HDF5 Library version 1.10
************************************************************/
+/* EIP Add link to the picture */
#include "hdf5.h"
#include <stdio.h>
@@ -171,10 +172,10 @@ main (void)
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 = [%d, %d, %d] \n", (int)start_out[0], (int)start_out[1], (int)start_out[2]);
- printf(" stride = [%d, %d, %d] \n", (int)stride_out[0], (int)stride_out[1], (int)stride_out[2]);
- printf(" count = [%d, %d, %d] \n", (int)count_out[0], (int)count_out[1], (int)count_out[2]);
- printf(" block = [%d, %d, %d] \n", (int)block_out[0], (int)block_out[1], (int)block_out[2]);
+ 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 */
@@ -200,6 +201,7 @@ main (void)
free(filename);
free(dsetname);
}
+/* EIP read data back */
/*
* Close and release resources.
diff --git a/examples/h5_vds-exclim.c b/examples/h5_vds-exclim.c
index 0d88442..af39c55 100644
--- a/examples/h5_vds-exclim.c
+++ b/examples/h5_vds-exclim.c
@@ -6,6 +6,7 @@
This file is intended for use with HDF5 Library version 1.10
************************************************************/
+/* EIP Add link to the picture */
#include "hdf5.h"
#include <stdio.h>
@@ -172,10 +173,10 @@ main (void)
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 = [%d, %d, %d] \n", (int)start_out[0], (int)start_out[1], (int)start_out[2]);
- printf(" stride = [%d, %d, %d] \n", (int)stride_out[0], (int)stride_out[1], (int)stride_out[2]);
- printf(" count = [%d, %d, %d] \n", (int)count_out[0], (int)count_out[1], (int)count_out[2]);
- printf(" block = [%d, %d, %d] \n", (int)block_out[0], (int)block_out[1], (int)block_out[2]);
+ 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 */
@@ -207,6 +208,7 @@ main (void)
free(filename);
free(dsetname);
}
+/* EIP read data back */
/*
* Close and release resources.
diff --git a/examples/h5_vds-simpleIO.c b/examples/h5_vds-simpleIO.c
new file mode 100644
index 0000000..801229c
--- /dev/null
+++ b/examples/h5_vds-simpleIO.c
@@ -0,0 +1,186 @@
+/************************************************************
+
+ This example illustrates the concept of virtual dataset I/O
+ The program creates 2-dim source dataset and writes
+ data to it. Then it creates 2-dim virtual dataset that has
+ the same dimesnion sizes and maps the all elements of the
+ virtual dataset to all elements of the source dataset.
+ Then VDS is read back.
+
+ This file is intended for use with HDF5 Library version 1.10
+
+ ************************************************************/
+/* EIP Add link to the picture */
+
+#include "hdf5.h"
+#include <stdio.h>
+#include <stdlib.h>
+
+#define FILE "vds-simpleIO.h5"
+#define DATASET "VDS"
+#define DIM1 6
+#define DIM0 4
+#define RANK 2
+
+#define SRC_FILE "a.h5"
+#define SRC_DATASET "/A"
+
+
+int
+main (void)
+{
+ hid_t file, space, src_space, vspace, dset; /* Handles */
+ hid_t dcpl;
+ herr_t status;
+ hsize_t vdsdims[2] = {DIM0, DIM1}, /* Virtual dataset dimension */
+ dims[2] = {DIM0, DIM1}; /* Source dataset dimensions */
+ int wdata[DIM0][DIM1], /* Write buffer for source dataset */
+ rdata[DIM0][DIM1], /* Read buffer for virtual dataset */
+ 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;
+ /*
+ * Initialize data.
+ */
+ for (i = 0; i < DIM0; i++)
+ for (j = 0; j < DIM1; j++) wdata[i][j] = i+1;
+
+ /*
+ * Create the source file and the dataset. Write data to the source dataset
+ * and close all resources.
+ */
+
+ file = H5Fcreate (SRC_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ space = H5Screate_simple (RANK, dims, NULL);
+ dset = H5Dcreate (file, SRC_DATASET, H5T_NATIVE_INT, space, H5P_DEFAULT,
+ H5P_DEFAULT, H5P_DEFAULT);
+ status = H5Dwrite (dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
+ wdata[0]);
+ status = H5Sclose (space);
+ status = H5Dclose (dset);
+ status = H5Fclose (file);
+
+ /* Create file in which virtual dataset will be stored. */
+ file = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+
+ /* Create VDS dataspace. */
+ vspace = H5Screate_simple (RANK, vdsdims, NULL);
+
+ /* Set VDS creation property. */
+ dcpl = H5Pcreate (H5P_DATASET_CREATE);
+
+ /*
+ * Build the mappings.
+ * Selections in the source datasets are H5S_ALL.
+ * In the virtual dataset we select the first, the second and the third rows
+ * and map each row to the data in the corresponding source dataset.
+ */
+ src_space = H5Screate_simple (RANK, dims, NULL);
+ status = H5Pset_virtual (dcpl, vspace, SRC_FILE, SRC_DATASET, src_space);
+
+ /* Create a virtual dataset. */
+ dset = H5Dcreate (file, DATASET, H5T_NATIVE_INT, vspace, H5P_DEFAULT,
+ dcpl, H5P_DEFAULT);
+ status = H5Sclose (vspace);
+ status = H5Sclose (src_space);
+ status = H5Dclose (dset);
+#ifdef EIP /*Currently the file with VDS should stay open. Neil will fix the issue */
+ status = H5Fclose (file);
+
+ /*
+ * Now we begin the read section of this example.
+ */
+
+ /*
+ * Open the file and virtual dataset.
+ */
+ file = H5Fopen (FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
+#endif
+ 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 the 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 it is ALL selection and then print selection. */
+ if(H5Sget_select_type(vspace) == H5S_SEL_ALL) {
+ printf("Selection is H5S_ALL \n");
+ }
+ /* 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 ");
+ src_space = H5Pget_virtual_srcspace (dcpl, (size_t)i);
+
+ /* Make sure it is ALL selection and then print selection. */
+ if(H5Sget_select_type(src_space) == H5S_SEL_ALL) {
+ printf("Selection is H5S_ALL \n");
+ }
+ H5Sclose(vspace);
+ H5Sclose(src_space);
+ free(filename);
+ free(dsetname);
+ }
+ /*
+ * Read the data using the default properties.
+ */
+ status = H5Dread (dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
+ rdata[0]);
+
+ /*
+ * Output the data to the screen.
+ */
+ printf (" VDS Data:\n");
+ for (i=0; i<DIM0; i++) {
+ printf (" [");
+ for (j=0; j<DIM1; j++)
+ printf (" %3d", rdata[i][j]);
+ printf ("]\n");
+ }
+ /*
+ * Close and release resources.
+ */
+ status = H5Pclose (dcpl);
+ status = H5Dclose (dset);
+ status = H5Fclose (file);
+
+ return 0;
+}
+
diff --git a/examples/h5_vds.c b/examples/h5_vds.c
index 6a20ed3..8d19527 100644
--- a/examples/h5_vds.c
+++ b/examples/h5_vds.c
@@ -16,6 +16,7 @@
This file is intended for use with HDF5 Library version 1.10
************************************************************/
+/* EIP Add link to the picture */
#include "hdf5.h"
#include <stdio.h>
@@ -47,9 +48,9 @@ main (void)
hid_t file, space, src_space, vspace, dset; /* Handles */
hid_t dcpl;
herr_t status;
- hsize_t vdsdims[2] = {VDSDIM0, VDSDIM1}, /* Virtual satasets dimension */
- dims[1] = {DIM0}, /* Source datasets dimensions */
- start[2], /* Hyperslab parameters */
+ hsize_t vdsdims[2] = {VDSDIM0, VDSDIM1}, /* Virtual datasets dimension */
+ dims[1] = {DIM0}, /* Source datasets dimensions */
+ start[2], /* Hyperslab parameters */
stride[2],
count[2],
block[2];
@@ -156,19 +157,19 @@ main (void)
if (H5D_VIRTUAL == layout)
printf(" Dataset has a virtual layout \n");
else
- printf("Wrong layout found \n");
+ printf(" Wrong layout found \n");
/*
* Find the number of mappings.
*/
status = H5Pget_virtual_count (dcpl, &num_map);
- printf("Number of mappings is %d\n", 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(" Mapping %d \n", i);
printf(" Selection in the virtual dataset ");
/* Get selection in the virttual dataset */
vspace = H5Pget_virtual_vspace (dcpl, (size_t)i);
@@ -190,10 +191,10 @@ main (void)
/* We also can use new APIs to get start, stride, count and block */
if (H5Sis_regular_hyperslab(vspace)) {
status = H5Sget_regular_hyperslab (vspace, start_out, stride_out, count_out, block_out);
- printf(" start = [%d, %d] \n", (int)start_out[0], (int)start_out[1]);
- printf(" stride = [%d, %d] \n", (int)stride_out[0], (int)stride_out[1]);
- printf(" count = [%d, %d] \n", (int)count_out[0], (int)count_out[1]);
- printf(" block = [%d, %d] \n", (int)block_out[0], (int)block_out[1]);
+ printf(" start = [%llu, %llu] \n", (unsigned long long)start_out[0], (unsigned long long)start_out[1]);
+ printf(" stride = [%llu, %llu] \n", (unsigned long long)stride_out[0], (unsigned long long)stride_out[1]);
+ printf(" count = [%llu, %llu] \n", (unsigned long long)count_out[0], (unsigned long long)count_out[1]);
+ printf(" block = [%llu, %llu] \n", (unsigned long long)block_out[0], (unsigned long long)block_out[1]);
}
}
/* Get source file name. */
@@ -223,7 +224,7 @@ main (void)
free(buf);
}
-#ifdef LATER
+#ifdef EIP
/*
* Read the data using the default properties.
*/
diff --git a/examples/run-c-ex.sh.in b/examples/run-c-ex.sh.in
index b41d89d..6bbd6de 100644
--- a/examples/run-c-ex.sh.in
+++ b/examples/run-c-ex.sh.in
@@ -127,11 +127,13 @@ then
RunTest h5_shared_mesg &&\
rm h5_shared_mesg &&\
RunTest h5_vds-eiger &&\
- rm h5_vds-eiger&&\
+ rm h5_vds-eiger &&\
RunTest h5_vds-exclim &&\
- rm h5_vds-exclim&&\
+ rm h5_vds-exclim &&\
RunTest h5_vds-exc &&\
- rm h5_vds-exc&&\
+ rm h5_vds-exc &&\
+ RunTest h5_vds-simpleIO &&\
+ rm h5_vds-simpleIO &&\
RunTest h5_vds &&\
rm h5_vds); then
EXIT_VALUE=${EXIT_SUCCESS}