summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorDana Robinson <derobins@hdfgroup.org>2022-04-13 21:17:29 (GMT)
committerDana Robinson <derobins@hdfgroup.org>2022-04-13 21:17:29 (GMT)
commitcabc39c3e197e2591449d2604bfee26465fb60e1 (patch)
treed5f39f5f5965584bf9bf49646a2af617adfd3e4e /examples
parent7355f4c505092a7a85474b47f18d5206028e2c95 (diff)
parentab69f5df770ee3cc6cd6c81d905a5317b894a002 (diff)
downloadhdf5-feature/coding_standards.zip
hdf5-feature/coding_standards.tar.gz
hdf5-feature/coding_standards.tar.bz2
Merge branch 'develop' into feature/coding_standardsfeature/coding_standards
Diffstat (limited to 'examples')
-rw-r--r--examples/Attributes.txt6
-rw-r--r--examples/CMakeLists.txt57
-rw-r--r--examples/CMakeTests.cmake105
-rw-r--r--examples/Makefile.am44
-rw-r--r--examples/h5_attribute.c379
-rw-r--r--examples/h5_chunk_read.c105
-rw-r--r--examples/h5_cmprss.c141
-rw-r--r--examples/h5_compound.c58
-rw-r--r--examples/h5_crtatt.c59
-rw-r--r--examples/h5_crtdat.c45
-rw-r--r--examples/h5_crtgrp.c28
-rw-r--r--examples/h5_crtgrpar.c40
-rw-r--r--examples/h5_crtgrpd.c101
-rw-r--r--examples/h5_debug_trace.c140
-rw-r--r--examples/h5_drivers.c21
-rw-r--r--examples/h5_dtransform.c100
-rw-r--r--examples/h5_elink_unix2win.c128
-rw-r--r--examples/h5_extend.c143
-rw-r--r--examples/h5_extend_write.c104
-rw-r--r--examples/h5_extlink.c284
-rw-r--r--examples/h5_group.c125
-rw-r--r--examples/h5_interm_group.c76
-rw-r--r--examples/h5_mount.c200
-rw-r--r--examples/h5_rdwt.c46
-rw-r--r--examples/h5_read.c106
-rw-r--r--examples/h5_ref2reg_deprec.c (renamed from examples/h5_ref2reg.c)95
-rw-r--r--examples/h5_ref_compat.c89
-rw-r--r--examples/h5_ref_extern.c92
-rw-r--r--examples/h5_reference.c147
-rw-r--r--examples/h5_reference_deprec.c146
-rw-r--r--examples/h5_select.c226
-rw-r--r--examples/h5_shared_mesg.c209
-rw-r--r--examples/h5_subset.c165
-rw-r--r--examples/h5_vds-eiger.c233
-rw-r--r--examples/h5_vds-exc.c302
-rw-r--r--examples/h5_vds-exclim.c293
-rw-r--r--examples/h5_vds-percival-unlim-maxmin.c410
-rw-r--r--examples/h5_vds-percival-unlim.c464
-rw-r--r--examples/h5_vds-percival.c310
-rw-r--r--examples/h5_vds-simpleIO.c185
-rw-r--r--examples/h5_vds.c256
-rw-r--r--examples/h5_write.c40
-rw-r--r--examples/ph5_filtered_writes.c490
-rw-r--r--examples/ph5_filtered_writes_no_sel.c370
-rw-r--r--examples/ph5example.c873
-rwxr-xr-xexamples/run-all-ex.sh2
-rw-r--r--examples/run-c-ex.sh.in52
-rw-r--r--examples/testh5cc.sh.in151
48 files changed, 4727 insertions, 3514 deletions
diff --git a/examples/Attributes.txt b/examples/Attributes.txt
index 0f25f68..6cba42b 100644
--- a/examples/Attributes.txt
+++ b/examples/Attributes.txt
@@ -1,4 +1,4 @@
-Attribute Examples:
+Attribute Examples:
H5Acreate2 example: Show how to create an attribute for a dataset and a group
----------------
@@ -19,7 +19,7 @@ H5Acreate2 example: Show how to create an attribute for a dataset and a group
rank=2;
dimsf[0] = H5S_UNLIMITED;
dimsf[1] = H5S_UNLIMITED;
- dataspace = H5Screate_simple(rank, dimsf, NULL);
+ dataspace = H5Screate_simple(rank, dimsf, NULL);
/* Create a dataset */
dataset = H5Dcreate2(file, "Dataset1", H5T_UINT8, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
@@ -122,7 +122,7 @@ H5Alink Example: Shows how to share an attribute between two datasets.
/* Get the OID of the attribute */
attr=H5Aopen(dataset1, "Foo", H5P_DEFAULT);
- /*
+ /*
* Create an attribute in the second dataset to the attribute in dataset1,
* changing the name of the attribute information in dataset2.
*/
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt
index 6e1f79d..3f329c1 100644
--- a/examples/CMakeLists.txt
+++ b/examples/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required (VERSION 3.10)
+cmake_minimum_required (VERSION 3.12)
project (HDF5_EXAMPLES C)
#-----------------------------------------------------------------------------
@@ -23,12 +23,15 @@ set (examples
h5_select
h5_attribute
h5_mount
- h5_reference
+ h5_ref_extern
+ h5_ref_compat
+ h5_reference_deprec
h5_drivers
- h5_ref2reg
+ h5_ref2reg_deprec
h5_extlink
h5_elink_unix2win
h5_shared_mesg
+ h5_debug_trace
h5_vds
h5_vds-exc
h5_vds-exclim
@@ -39,9 +42,17 @@ set (examples
h5_vds-percival-unlim-maxmin
)
+if (H5_HAVE_PARALLEL)
+ set (parallel_examples
+ ph5example
+ ph5_filtered_writes
+ ph5_filtered_writes_no_sel
+ )
+endif ()
+
foreach (example ${examples})
add_executable (${example} ${HDF5_EXAMPLES_SOURCE_DIR}/${example}.c)
- target_include_directories (${example} PRIVATE "${HDF5_SRC_DIR};${HDF5_BINARY_DIR};$<$<BOOL:${HDF5_ENABLE_PARALLEL}>:${MPI_C_INCLUDE_DIRS}>")
+ target_include_directories (${example} PRIVATE "${HDF5_SRC_DIR};${HDF5_SRC_BINARY_DIR};$<$<BOOL:${HDF5_ENABLE_PARALLEL}>:${MPI_C_INCLUDE_DIRS}>")
if (NOT BUILD_SHARED_LIBS)
TARGET_C_PROPERTIES (${example} STATIC)
target_link_libraries (${example} PRIVATE ${HDF5_LIB_TARGET})
@@ -50,21 +61,37 @@ foreach (example ${examples})
target_link_libraries (${example} PRIVATE ${HDF5_LIBSH_TARGET})
endif ()
set_target_properties (${example} PROPERTIES FOLDER examples)
+
+ #-----------------------------------------------------------------------------
+ # Add Target to clang-format
+ #-----------------------------------------------------------------------------
+ if (HDF5_ENABLE_FORMATTERS)
+ clang_format (HDF5_EXAMPLES_${example}_FORMAT ${example})
+ endif ()
endforeach ()
if (H5_HAVE_PARALLEL)
- add_executable (ph5example ${HDF5_EXAMPLES_SOURCE_DIR}/ph5example.c)
- target_include_directories (ph5example PRIVATE "${HDF5_SRC_DIR};${HDF5_BINARY_DIR};$<$<BOOL:${HDF5_ENABLE_PARALLEL}>:${MPI_C_INCLUDE_DIRS}>")
- if (NOT BUILD_SHARED_LIBS)
- TARGET_C_PROPERTIES (ph5example STATIC)
- target_link_libraries (ph5example PRIVATE ${HDF5_LIB_TARGET} ${MPI_C_LIBRARIES})
- else ()
- TARGET_C_PROPERTIES (ph5example SHARED)
- target_link_libraries (ph5example PRIVATE ${HDF5_LIBSH_TARGET} ${MPI_C_LIBRARIES})
- endif ()
- set_target_properties (ph5example PROPERTIES FOLDER examples)
+ foreach (parallel_example ${parallel_examples})
+ add_executable (${parallel_example} ${HDF5_EXAMPLES_SOURCE_DIR}/${parallel_example}.c)
+ target_include_directories (${parallel_example} PRIVATE "${HDF5_SRC_DIR};${HDF5_SRC_BINARY_DIR};$<$<BOOL:${HDF5_ENABLE_PARALLEL}>:${MPI_C_INCLUDE_DIRS}>")
+ if (NOT BUILD_SHARED_LIBS)
+ TARGET_C_PROPERTIES (${parallel_example} STATIC)
+ target_link_libraries (${parallel_example} PRIVATE ${HDF5_LIB_TARGET} ${MPI_C_LIBRARIES})
+ else ()
+ TARGET_C_PROPERTIES (${parallel_example} SHARED)
+ target_link_libraries (${parallel_example} PRIVATE ${HDF5_LIBSH_TARGET} ${MPI_C_LIBRARIES})
+ endif ()
+ set_target_properties (${parallel_example} PROPERTIES FOLDER examples)
+
+ #-----------------------------------------------------------------------------
+ # Add Target to clang-format
+ #-----------------------------------------------------------------------------
+ if (HDF5_ENABLE_FORMATTERS)
+ clang_format (HDF5_EXAMPLES_${parallel_example}_FORMAT ${parallel_example})
+ endif ()
+ endforeach ()
endif ()
-if (BUILD_TESTING)
+if (BUILD_TESTING AND HDF5_TEST_EXAMPLES)
include (CMakeTests.cmake)
endif ()
diff --git a/examples/CMakeTests.cmake b/examples/CMakeTests.cmake
index ea3b2c5..3e24ba0 100644
--- a/examples/CMakeTests.cmake
+++ b/examples/CMakeTests.cmake
@@ -5,7 +5,7 @@
# 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
-# distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.
+# distribution tree, or in https://www.hdfgroup.org/licenses.
# If you do not have access to either file, you may request a copy from
# help@hdfgroup.org.
#
@@ -64,54 +64,63 @@ set (test_ex_CLEANFILES
vds-eiger.h5
)
-# Remove any output file left over from previous test run
-add_test (
- NAME EXAMPLES-clear-objects
- COMMAND ${CMAKE_COMMAND} -E remove ${test_ex_CLEANFILES}
-)
-set_tests_properties (EXAMPLES-clear-objects PROPERTIES FIXTURES_SETUP clear_EXAMPLES)
+if (HDF5_TEST_SERIAL)
+ # Remove any output file left over from previous test run
+ add_test (
+ NAME EXAMPLES-clear-objects
+ COMMAND ${CMAKE_COMMAND} -E remove ${test_ex_CLEANFILES}
+ )
+ set_tests_properties (EXAMPLES-clear-objects PROPERTIES FIXTURES_SETUP clear_EXAMPLES)
-foreach (example ${examples})
- if (HDF5_ENABLE_USING_MEMCHECKER)
- add_test (NAME EXAMPLES-${example} COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:${example}>)
- else ()
- add_test (NAME EXAMPLES-${example} COMMAND "${CMAKE_COMMAND}"
- -D "TEST_EMULATOR=${CMAKE_CROSSCOMPILING_EMULATOR}"
- -D "TEST_PROGRAM=$<TARGET_FILE:${example}>"
- -D "TEST_ARGS:STRING="
- -D "TEST_EXPECT=0"
- -D "TEST_SKIP_COMPARE=TRUE"
- -D "TEST_OUTPUT=${example}.txt"
- #-D "TEST_REFERENCE=${example}.out"
- -D "TEST_FOLDER=${PROJECT_BINARY_DIR}"
- -P "${HDF_RESOURCES_EXT_DIR}/runTest.cmake"
- )
- endif ()
- set_tests_properties (EXAMPLES-${example} PROPERTIES FIXTURES_REQUIRED clear_EXAMPLES)
- if (last_test)
- set_tests_properties (EXAMPLES-${example} PROPERTIES DEPENDS ${last_test})
- endif ()
- set (last_test "EXAMPLES-${example}")
-endforeach ()
+ foreach (example ${examples})
+ if (HDF5_ENABLE_USING_MEMCHECKER)
+ add_test (NAME EXAMPLES-${example} COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:${example}>)
+ else ()
+ add_test (NAME EXAMPLES-${example} COMMAND "${CMAKE_COMMAND}"
+ -D "TEST_EMULATOR=${CMAKE_CROSSCOMPILING_EMULATOR}"
+ -D "TEST_PROGRAM=$<TARGET_FILE:${example}>"
+ -D "TEST_ARGS:STRING="
+ -D "TEST_EXPECT=0"
+ -D "TEST_SKIP_COMPARE=TRUE"
+ -D "TEST_OUTPUT=${example}.txt"
+ #-D "TEST_REFERENCE=${example}.out"
+ -D "TEST_FOLDER=${PROJECT_BINARY_DIR}"
+ -P "${HDF_RESOURCES_EXT_DIR}/runTest.cmake"
+ )
+ endif ()
+ set_tests_properties (EXAMPLES-${example} PROPERTIES FIXTURES_REQUIRED clear_EXAMPLES)
+ if (last_test)
+ set_tests_properties (EXAMPLES-${example} PROPERTIES DEPENDS ${last_test})
+ endif ()
+ set (last_test "EXAMPLES-${example}")
+ endforeach ()
+endif ()
### Windows pops up a modal permission dialog on this test
-if (H5_HAVE_PARALLEL AND NOT WIN32)
- if (HDF5_ENABLE_USING_MEMCHECKER)
- add_test (NAME MPI_TEST_EXAMPLES-ph5example COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${MPIEXEC_MAX_NUMPROCS} ${MPIEXEC_PREFLAGS} $<TARGET_FILE:ph5example> ${MPIEXEC_POSTFLAGS})
- else ()
- add_test (NAME MPI_TEST_EXAMPLES-ph5example COMMAND "${CMAKE_COMMAND}"
- -D "TEST_PROGRAM=${MPIEXEC_EXECUTABLE};${MPIEXEC_NUMPROC_FLAG};${MPIEXEC_MAX_NUMPROCS};${MPIEXEC_PREFLAGS};$<TARGET_FILE:ph5example>;${MPIEXEC_POSTFLAGS}"
- -D "TEST_ARGS:STRING="
- -D "TEST_EXPECT=0"
- -D "TEST_OUTPUT=ph5example.out"
- -D "TEST_REFERENCE:STRING=PHDF5 tests finished with no errors"
- -D "TEST_FILTER:STRING=PHDF5 tests finished with no errors"
- -D "TEST_FOLDER=${PROJECT_BINARY_DIR}"
- -P "${HDF_RESOURCES_EXT_DIR}/grepTest.cmake"
- )
- endif ()
- if (last_test)
- set_tests_properties (MPI_TEST_EXAMPLES-ph5example PROPERTIES DEPENDS ${last_test})
- endif ()
- set (last_test "MPI_TEST_EXAMPLES-ph5example")
+if (H5_HAVE_PARALLEL AND HDF5_TEST_PARALLEL AND NOT WIN32)
+ # Ensure that 24 is a multiple of the number of processes.
+ # The number 24 corresponds to SPACE1_DIM1 and SPACE1_DIM2 defined in ph5example.c
+ math(EXPR NUMPROCS "24 / ((24 + ${MPIEXEC_MAX_NUMPROCS} - 1) / ${MPIEXEC_MAX_NUMPROCS})")
+
+ foreach (parallel_example ${parallel_examples})
+ if (HDF5_ENABLE_USING_MEMCHECKER)
+ add_test (NAME MPI_TEST_EXAMPLES-${parallel_example} COMMAND ${MPIEXEC_EXECUTABLE} ${MPIEXEC_NUMPROC_FLAG} ${NUMPROCS} ${MPIEXEC_PREFLAGS} $<TARGET_FILE:${parallel_example}> ${MPIEXEC_POSTFLAGS})
+ else ()
+ add_test (NAME MPI_TEST_EXAMPLES-${parallel_example} COMMAND "${CMAKE_COMMAND}"
+ -D "TEST_PROGRAM=${MPIEXEC_EXECUTABLE};${MPIEXEC_NUMPROC_FLAG};${NUMPROCS};${MPIEXEC_PREFLAGS};$<TARGET_FILE:${parallel_example}>;${MPIEXEC_POSTFLAGS}"
+ -D "TEST_ARGS:STRING="
+ -D "TEST_EXPECT=0"
+ -D "TEST_SKIP_COMPARE=TRUE"
+ -D "TEST_OUTPUT=${parallel_example}.out"
+ -D "TEST_REFERENCE:STRING=PHDF5 example finished with no errors"
+ #-D "TEST_FILTER:STRING=PHDF5 tests finished with no errors"
+ -D "TEST_FOLDER=${PROJECT_BINARY_DIR}"
+ -P "${HDF_RESOURCES_EXT_DIR}/grepTest.cmake"
+ )
+ endif ()
+ if (last_test)
+ set_tests_properties (MPI_TEST_EXAMPLES-${parallel_example} PROPERTIES DEPENDS ${last_test})
+ endif ()
+ set (last_test "MPI_TEST_EXAMPLES-${parallel_example}")
+ endforeach ()
endif ()
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 554ee44..161f789 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -6,7 +6,7 @@
# 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
-# distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.
+# distribution tree, or in https://www.hdfgroup.org/licenses.
# If you do not have access to either file, you may request a copy from
# help@hdfgroup.org.
##
@@ -20,7 +20,7 @@
include $(top_srcdir)/config/commence.am
if BUILD_PARALLEL_CONDITIONAL
- EXAMPLE_PROG_PARA = ph5example
+ EXAMPLE_PROG_PARA = ph5example ph5_filtered_writes ph5_filtered_writes_no_sel
endif
INSTALL_SCRIPT_FILES = run-c-ex.sh
@@ -34,23 +34,25 @@ INSTALL_TOP_FILES = README
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_vds h5_vds-exc \
- h5_vds-exclim h5_vds-eiger h5_vds-simpleIO h5_vds-percival \
- h5_vds-percival-unlim h5_vds-percival-unlim-maxmin
-TEST_SCRIPT=testh5cc.sh
+ h5_group h5_select h5_attribute h5_mount h5_drivers \
+ h5_reference_deprec h5_ref_extern h5_ref_compat h5_ref2reg_deprec \
+ h5_extlink h5_elink_unix2win h5_shared_mesg h5_debug_trace \
+ h5_vds h5_vds-exc h5_vds-exclim h5_vds-eiger h5_vds-simpleIO \
+ h5_vds-percival h5_vds-percival-unlim h5_vds-percival-unlim-maxmin
+TEST_SCRIPT=testh5cc.sh
TEST_EXAMPLES_SCRIPT=$(INSTALL_SCRIPT_FILES)
# Install files
# List all file that should be installed in examples directory
-INSTALL_FILES = h5_write.c h5_read.c h5_extend_write.c h5_chunk_read.c \
- h5_crtgrpd.c h5_subset.c h5_cmprss.c h5_rdwt.c h5_crtgrpar.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_vds.c h5_vds-exc.c \
- h5_vds-exclim.c h5_vds-eiger.c h5_vds-simpleIO.c h5_vds-percival.c \
- h5_vds-percival-unlim.c h5_vds-percival-unlim-maxmin.c
+INSTALL_FILES = h5_write.c h5_read.c h5_extend_write.c h5_chunk_read.c h5_compound.c \
+ h5_crtgrpd.c h5_subset.c h5_cmprss.c h5_rdwt.c h5_crtgrpar.c h5_extend.c \
+ h5_crtatt.c h5_crtgrp.c h5_crtdat.c \
+ h5_group.c h5_select.c h5_attribute.c h5_mount.c h5_drivers.c \
+ h5_reference_deprec.c h5_ref_extern.c h5_ref_compat.c h5_ref2reg_deprec.c \
+ h5_extlink.c h5_elink_unix2win.c h5_shared_mesg.c h5_debug_trace.c \
+ ph5example.c ph5_filtered_writes.c ph5_filtered_writes_no_sel.c \
+ h5_vds.c h5_vds-exc.c h5_vds-exclim.c h5_vds-eiger.c h5_vds-simpleIO.c \
+ h5_vds-percival.c h5_vds-percival-unlim.c h5_vds-percival-unlim-maxmin.c
@@ -84,8 +86,8 @@ CHECK_CLEANFILES+=$(EXTLINK_DIRS)
# Example directory
# Note: no '/' after DESTDIR. Explanation in commence.am
-EXAMPLEDIR=${DESTDIR}$(exec_prefix)/share/hdf5_examples/c
-EXAMPLETOPDIR=${DESTDIR}$(exec_prefix)/share/hdf5_examples
+EXAMPLEDIR=${DESTDIR}$(examplesdir)/c
+EXAMPLETOPDIR=${DESTDIR}$(examplesdir)
# List dependencies for each program. Normally, automake would take
# care of this for us, but if we tell automake about the programs it
@@ -111,10 +113,14 @@ h5_read: $(srcdir)/h5_read.c
h5_select: $(srcdir)/h5_select.c
h5_attribute: $(srcdir)/h5_attribute.c
h5_mount: $(srcdir)/h5_mount.c
-h5_reference: $(srcdir)/h5_reference.c
-h5_ref2reg: $(srcdir)/h5_ref2reg.c
+h5_ref_compat: $(srcdir)/h5_ref_compat.c
+h5_ref_extern: $(srcdir)/h5_ref_extern.c
+h5_reference_deprec: $(srcdir)/h5_reference_deprec.c
+h5_ref2reg_deprec: $(srcdir)/h5_ref2reg_deprec.c
h5_drivers: $(srcdir)/h5_drivers.c
ph5example: $(srcdir)/ph5example.c
+ph5_filtered_writes: $(srcdir)/ph5_filtered_writes.c
+ph5_filtered_writes_no_sel: $(srcdir)/ph5_filtered_writes_no_sel.c
h5_dtransform: $(srcdir)/h5_dtransform.c
h5_extlink: $(srcdir)/h5_extlink.c $(EXTLINK_DIRS)
h5_elink_unix2win: $(srcdir)/h5_elink_unix2win.c $(EXTLINK_DIRS)
diff --git a/examples/h5_attribute.c b/examples/h5_attribute.c
index e3b5759..97be7f5 100644
--- a/examples/h5_attribute.c
+++ b/examples/h5_attribute.c
@@ -6,7 +6,7 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -29,193 +29,195 @@
#define H5FILE_NAME "Attributes.h5"
-#define RANK 1 /* Rank and size of the dataset */
-#define SIZE 7
+#define RANK 1 /* Rank and size of the dataset */
+#define SIZE 7
-#define ARANK 2 /* Rank and dimension sizes of the first dataset attribute */
+#define ARANK 2 /* Rank and dimension sizes of the first dataset attribute */
#define ADIM1 2
#define ADIM2 3
-#define ANAME "Float attribute" /* Name of the array attribute */
+#define ANAME "Float attribute" /* Name of the array attribute */
#define ANAMES "Character attribute" /* Name of the string attribute */
static herr_t attr_info(hid_t loc_id, const char *name, const H5A_info_t *ainfo, void *opdata);
- /* Operator function */
+/* Operator function */
int
-main (void)
+main(void)
{
- hid_t file, dataset; /* File and dataset identifiers */
-
- hid_t fid; /* Dataspace identifier */
- hid_t attr1, attr2, attr3; /* Attribute identifiers */
- hid_t attr;
- hid_t aid1, aid2, aid3; /* Attribute dataspace identifiers */
- hid_t atype, atype_mem; /* Attribute type */
- H5T_class_t type_class;
-
- hsize_t fdim[] = {SIZE};
- hsize_t adim[] = {ADIM1, ADIM2}; /* Dimensions of the first attribute */
-
- float matrix[ADIM1][ADIM2]; /* Attribute data */
-
- herr_t ret; /* Return value */
- H5O_info_t oinfo; /* Object info */
- unsigned i, j; /* Counters */
- char string_out[80]; /* Buffer to read string attribute back */
- int point_out; /* Buffer to read scalar attribute back */
-
- /*
- * Data initialization.
- */
- int vector[] = {1, 2, 3, 4, 5, 6, 7}; /* Dataset data */
- int point = 1; /* Value of the scalar attribute */
- char string[] = "ABCD"; /* Value of the string attribute */
-
-
- for (i=0; i < ADIM1; i++) { /* Values of the array attribute */
- for (j=0; j < ADIM2; j++)
- matrix[i][j] = -1.;
- }
-
- /*
- * Create a file.
- */
- file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- /*
- * Create the dataspace for the dataset in the file.
- */
- fid = H5Screate(H5S_SIMPLE);
- ret = H5Sset_extent_simple(fid, RANK, fdim, NULL);
-
- /*
- * Create the dataset in the file.
- */
- dataset = H5Dcreate2(file, "Dataset", H5T_NATIVE_INT, fid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
-
- /*
- * Write data to the dataset.
- */
- ret = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL , H5S_ALL, H5P_DEFAULT, vector);
-
- /*
- * Create dataspace for the first attribute.
- */
- aid1 = H5Screate(H5S_SIMPLE);
- ret = H5Sset_extent_simple(aid1, ARANK, adim, NULL);
-
- /*
- * Create array attribute.
- */
- attr1 = H5Acreate2(dataset, ANAME, H5T_NATIVE_FLOAT, aid1, H5P_DEFAULT, H5P_DEFAULT);
-
- /*
- * Write array attribute.
- */
- ret = H5Awrite(attr1, H5T_NATIVE_FLOAT, matrix);
-
- /*
- * Create scalar attribute.
- */
- aid2 = H5Screate(H5S_SCALAR);
- attr2 = H5Acreate2(dataset, "Integer attribute", H5T_NATIVE_INT, aid2,
- H5P_DEFAULT, H5P_DEFAULT);
-
- /*
- * Write scalar attribute.
- */
- ret = H5Awrite(attr2, H5T_NATIVE_INT, &point);
-
- /*
- * Create string attribute.
- */
- aid3 = H5Screate(H5S_SCALAR);
- atype = H5Tcopy(H5T_C_S1);
- H5Tset_size(atype, 5);
- H5Tset_strpad(atype,H5T_STR_NULLTERM);
- attr3 = H5Acreate2(dataset, ANAMES, atype, aid3, H5P_DEFAULT, H5P_DEFAULT);
-
- /*
- * Write string attribute.
- */
- ret = H5Awrite(attr3, atype, string);
-
- /*
- * Close attribute and file dataspaces, and datatype.
- */
- ret = H5Sclose(aid1);
- ret = H5Sclose(aid2);
- ret = H5Sclose(aid3);
- ret = H5Sclose(fid);
- ret = H5Tclose(atype);
-
- /*
- * Close the attributes.
- */
- ret = H5Aclose(attr1);
- ret = H5Aclose(attr2);
- ret = H5Aclose(attr3);
-
- /*
- * Close the dataset.
- */
- ret = H5Dclose(dataset);
-
- /*
- * Close the file.
- */
- ret = H5Fclose(file);
-
- /*
- * Reopen the file.
- */
- file = H5Fopen(H5FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT);
-
- /*
- * Open the dataset.
- */
- dataset = H5Dopen2(file, "Dataset", H5P_DEFAULT);
-
- /*
- * Attach to the scalar attribute using attribute name, then read and
- * display its value.
- */
- attr = H5Aopen(dataset, "Integer attribute", H5P_DEFAULT);
- ret = H5Aread(attr, H5T_NATIVE_INT, &point_out);
- printf("The value of the attribute \"Integer attribute\" is %d \n", point_out);
- ret = H5Aclose(attr);
-
- /*
- * Find string attribute by iterating through all attributes
- */
- ret = H5Oget_info2(dataset, &oinfo, H5O_INFO_ALL);
- for(i = 0; i < (unsigned)oinfo.num_attrs; i++) {
- attr = H5Aopen_by_idx(dataset, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)i, H5P_DEFAULT, H5P_DEFAULT);
- atype = H5Aget_type(attr);
- type_class = H5Tget_class(atype);
- if (type_class == H5T_STRING) {
- atype_mem = H5Tget_native_type(atype, H5T_DIR_ASCEND);
- ret = H5Aread(attr, atype_mem, string_out);
- printf("Found string attribute; its index is %d , value = %s \n", i, string_out);
- ret = H5Tclose(atype_mem);
- }
- ret = H5Aclose(attr);
- ret = H5Tclose(atype);
+ hid_t file, dataset; /* File and dataset identifiers */
+
+ hid_t fid; /* Dataspace identifier */
+ hid_t attr1, attr2, attr3; /* Attribute identifiers */
+ hid_t attr;
+ hid_t aid1, aid2, aid3; /* Attribute dataspace identifiers */
+ hid_t atype, atype_mem; /* Attribute type */
+ H5T_class_t type_class;
+
+ hsize_t fdim[] = {SIZE};
+ hsize_t adim[] = {ADIM1, ADIM2}; /* Dimensions of the first attribute */
+
+ float matrix[ADIM1][ADIM2]; /* Attribute data */
+
+ herr_t ret; /* Return value */
+ H5O_info2_t oinfo; /* Object info */
+ unsigned i, j; /* Counters */
+ char string_out[80]; /* Buffer to read string attribute back */
+ int point_out; /* Buffer to read scalar attribute back */
+
+ /*
+ * Data initialization.
+ */
+ int vector[] = {1, 2, 3, 4, 5, 6, 7}; /* Dataset data */
+ int point = 1; /* Value of the scalar attribute */
+ char string[] = "ABCD"; /* Value of the string attribute */
+
+ for (i = 0; i < ADIM1; i++) { /* Values of the array attribute */
+ for (j = 0; j < ADIM2; j++)
+ matrix[i][j] = -1.;
}
- /*
- * Get attribute info using iteration function.
- */
+ /*
+ * Create a file.
+ */
+ file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+
+ /*
+ * Create the dataspace for the dataset in the file.
+ */
+ fid = H5Screate(H5S_SIMPLE);
+ ret = H5Sset_extent_simple(fid, RANK, fdim, NULL);
+
+ /*
+ * Create the dataset in the file.
+ */
+ dataset = H5Dcreate2(file, "Dataset", H5T_NATIVE_INT, fid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+
+ /*
+ * Write data to the dataset.
+ */
+ ret = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, vector);
+
+ /*
+ * Create dataspace for the first attribute.
+ */
+ aid1 = H5Screate(H5S_SIMPLE);
+ ret = H5Sset_extent_simple(aid1, ARANK, adim, NULL);
+
+ /*
+ * Create array attribute.
+ */
+ attr1 = H5Acreate2(dataset, ANAME, H5T_NATIVE_FLOAT, aid1, H5P_DEFAULT, H5P_DEFAULT);
+
+ /*
+ * Write array attribute.
+ */
+ ret = H5Awrite(attr1, H5T_NATIVE_FLOAT, matrix);
+
+ /*
+ * Create scalar attribute.
+ */
+ aid2 = H5Screate(H5S_SCALAR);
+ attr2 = H5Acreate2(dataset, "Integer attribute", H5T_NATIVE_INT, aid2, H5P_DEFAULT, H5P_DEFAULT);
+
+ /*
+ * Write scalar attribute.
+ */
+ ret = H5Awrite(attr2, H5T_NATIVE_INT, &point);
+
+ /*
+ * Create string attribute.
+ */
+ aid3 = H5Screate(H5S_SCALAR);
+ atype = H5Tcopy(H5T_C_S1);
+ H5Tset_size(atype, 5);
+ H5Tset_strpad(atype, H5T_STR_NULLTERM);
+ attr3 = H5Acreate2(dataset, ANAMES, atype, aid3, H5P_DEFAULT, H5P_DEFAULT);
+
+ /*
+ * Write string attribute.
+ */
+ ret = H5Awrite(attr3, atype, string);
+
+ /*
+ * Close attribute and file dataspaces, and datatype.
+ */
+ ret = H5Sclose(aid1);
+ ret = H5Sclose(aid2);
+ ret = H5Sclose(aid3);
+ ret = H5Sclose(fid);
+ ret = H5Tclose(atype);
+
+ /*
+ * Close the attributes.
+ */
+ ret = H5Aclose(attr1);
+ ret = H5Aclose(attr2);
+ ret = H5Aclose(attr3);
+
+ /*
+ * Close the dataset.
+ */
+ ret = H5Dclose(dataset);
+
+ /*
+ * Close the file.
+ */
+ ret = H5Fclose(file);
+
+ /*
+ * Reopen the file.
+ */
+ file = H5Fopen(H5FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT);
+
+ /*
+ * Open the dataset.
+ */
+ dataset = H5Dopen2(file, "Dataset", H5P_DEFAULT);
+
+ /*
+ * Attach to the scalar attribute using attribute name, then read and
+ * display its value.
+ */
+ attr = H5Aopen(dataset, "Integer attribute", H5P_DEFAULT);
+ ret = H5Aread(attr, H5T_NATIVE_INT, &point_out);
+ printf("The value of the attribute \"Integer attribute\" is %d \n", point_out);
+ ret = H5Aclose(attr);
+
+ //! [H5Oget_info3_snip]
+
+ /*
+ * Find string attribute by iterating through all attributes
+ */
+ ret = H5Oget_info3(dataset, &oinfo, H5O_INFO_NUM_ATTRS);
+ for (i = 0; i < (unsigned)oinfo.num_attrs; i++) {
+ attr = H5Aopen_by_idx(dataset, ".", H5_INDEX_CRT_ORDER, H5_ITER_INC, (hsize_t)i, H5P_DEFAULT,
+ H5P_DEFAULT);
+ atype = H5Aget_type(attr);
+ type_class = H5Tget_class(atype);
+ if (type_class == H5T_STRING) {
+ atype_mem = H5Tget_native_type(atype, H5T_DIR_ASCEND);
+ ret = H5Aread(attr, atype_mem, string_out);
+ printf("Found string attribute; its index is %d , value = %s \n", i, string_out);
+ ret = H5Tclose(atype_mem);
+ }
+ ret = H5Aclose(attr);
+ ret = H5Tclose(atype);
+ }
+
+ //! [H5Oget_info3_snip]
+ /*
+ * Get attribute info using iteration function.
+ */
ret = H5Aiterate2(dataset, H5_INDEX_NAME, H5_ITER_INC, NULL, attr_info, NULL);
- /*
- * Close the dataset and the file.
- */
- H5Dclose(dataset);
- H5Fclose(file);
+ /*
+ * Close the dataset and the file.
+ */
+ H5Dclose(dataset);
+ H5Fclose(file);
- return 0;
+ return 0;
}
/*
@@ -224,16 +226,16 @@ main (void)
static herr_t
attr_info(hid_t loc_id, const char *name, const H5A_info_t *ainfo, void *opdata)
{
- hid_t attr, atype, aspace; /* Attribute, datatype and dataspace identifiers */
- int rank;
+ hid_t attr, atype, aspace; /* Attribute, datatype and dataspace identifiers */
+ int rank;
hsize_t sdim[64];
- herr_t ret;
- int i;
- size_t npoints; /* Number of elements in the array attribute. */
- float *float_array; /* Pointer to the array attribute. */
+ herr_t ret;
+ int i;
+ size_t npoints; /* Number of elements in the array attribute. */
+ float * float_array; /* Pointer to the array attribute. */
/* avoid warnings */
- opdata = opdata;
+ (void)opdata;
/*
* Open the attribute using its name.
@@ -250,17 +252,17 @@ attr_info(hid_t loc_id, const char *name, const H5A_info_t *ainfo, void *opdata)
*/
atype = H5Aget_type(attr);
aspace = H5Aget_space(attr);
- rank = H5Sget_simple_extent_ndims(aspace);
- ret = H5Sget_simple_extent_dims(aspace, sdim, NULL);
+ rank = H5Sget_simple_extent_ndims(aspace);
+ ret = H5Sget_simple_extent_dims(aspace, sdim, NULL);
/*
* Display rank and dimension sizes for the array attribute.
*/
- if(rank > 0) {
+ if (rank > 0) {
printf("Rank : %d \n", rank);
printf("Dimension sizes : ");
- for (i=0; i< rank; i++)
+ for (i = 0; i < rank; i++)
printf("%d ", (int)sdim[i]);
printf("\n");
}
@@ -271,11 +273,11 @@ attr_info(hid_t loc_id, const char *name, const H5A_info_t *ainfo, void *opdata)
if (H5T_FLOAT == H5Tget_class(atype)) {
printf("Type : FLOAT \n");
- npoints = H5Sget_simple_extent_npoints(aspace);
- float_array = (float *)malloc(sizeof(float)*(int)npoints);
- ret = H5Aread(attr, atype, float_array);
+ npoints = H5Sget_simple_extent_npoints(aspace);
+ float_array = (float *)malloc(sizeof(float) * (int)npoints);
+ ret = H5Aread(attr, atype, float_array);
printf("Values : ");
- for( i = 0; i < (int)npoints; i++)
+ for (i = 0; i < (int)npoints; i++)
printf("%f ", float_array[i]);
printf("\n");
free(float_array);
@@ -290,4 +292,3 @@ attr_info(hid_t loc_id, const char *name, const H5A_info_t *ainfo, void *opdata)
return 0;
}
-
diff --git a/examples/h5_chunk_read.c b/examples/h5_chunk_read.c
index c3455f4..408a844 100644
--- a/examples/h5_chunk_read.c
+++ b/examples/h5_chunk_read.c
@@ -6,7 +6,7 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -18,68 +18,66 @@
#include "hdf5.h"
-#define H5FILE_NAME "SDSextendible.h5"
+#define H5FILE_NAME "SDSextendible.h5"
#define DATASETNAME "ExtendibleArray"
-#define RANK 2
-#define RANKC 1
-#define NX 10
-#define NY 5
+#define RANK 2
+#define RANKC 1
+#define NX 10
+#define NY 5
int
-main (void)
+main(void)
{
- hid_t file; /* handles */
- hid_t dataset;
- hid_t filespace;
- hid_t memspace;
- hid_t cparms;
- hsize_t dims[2]; /* dataset and chunk dimensions*/
- hsize_t chunk_dims[2];
- hsize_t col_dims[1];
- hsize_t count[2];
- hsize_t offset[2];
-
- herr_t status, status_n;
-
- int data_out[NX][NY]; /* buffer for dataset to be read */
- int chunk_out[2][5]; /* buffer for chunk to be read */
- int column[10]; /* buffer for column to be read */
- int rank, rank_chunk;
- int i, j;
-
-
+ hid_t file; /* handles */
+ hid_t dataset;
+ hid_t filespace;
+ hid_t memspace;
+ hid_t cparms;
+ hsize_t dims[2]; /* dataset and chunk dimensions*/
+ hsize_t chunk_dims[2];
+ hsize_t col_dims[1];
+ hsize_t count[2];
+ hsize_t offset[2];
+
+ herr_t status, status_n;
+
+ int data_out[NX][NY]; /* buffer for dataset to be read */
+ int chunk_out[2][5]; /* buffer for chunk to be read */
+ int column[10]; /* buffer for column to be read */
+ int rank, rank_chunk;
+ int i, j;
/*
* Open the file and the dataset.
*/
- file = H5Fopen(H5FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT);
+ file = H5Fopen(H5FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT);
dataset = H5Dopen2(file, DATASETNAME, H5P_DEFAULT);
/*
* Get dataset rank and dimension.
*/
- filespace = H5Dget_space(dataset); /* Get filespace handle first. */
+ filespace = H5Dget_space(dataset); /* Get filespace handle first. */
rank = H5Sget_simple_extent_ndims(filespace);
status_n = H5Sget_simple_extent_dims(filespace, dims, NULL);
- printf("dataset rank %d, dimensions %lu x %lu\n",
- rank, (unsigned long)(dims[0]), (unsigned long)(dims[1]));
+ printf("dataset rank %d, dimensions %lu x %lu\n", rank, (unsigned long)(dims[0]),
+ (unsigned long)(dims[1]));
/*
* Define the memory space to read dataset.
*/
- memspace = H5Screate_simple(RANK,dims,NULL);
+ memspace = H5Screate_simple(RANK, dims, NULL);
/*
* Read dataset back and display.
*/
- status = H5Dread(dataset, H5T_NATIVE_INT, memspace, filespace,
- H5P_DEFAULT, data_out);
+ status = H5Dread(dataset, H5T_NATIVE_INT, memspace, filespace, H5P_DEFAULT, data_out);
printf("\n");
printf("Dataset: \n");
for (j = 0; j < dims[0]; j++) {
- for (i = 0; i < dims[1]; i++) printf("%d ", data_out[j][i]);
- printf("\n");
+ for (i = 0; i < dims[1]; i++)
+ printf("%d ", data_out[j][i]);
+ printf("\n");
}
/*
@@ -110,7 +108,7 @@ main (void)
* and read it into column array.
*/
col_dims[0] = 10;
- memspace = H5Screate_simple(RANKC, col_dims, NULL);
+ memspace = H5Screate_simple(RANKC, col_dims, NULL);
/*
* Define the column (hyperslab) to read.
@@ -119,14 +117,12 @@ main (void)
offset[1] = 2;
count[0] = 10;
count[1] = 1;
- status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL,
- count, NULL);
- status = H5Dread(dataset, H5T_NATIVE_INT, memspace, filespace,
- H5P_DEFAULT, column);
+ status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL, count, NULL);
+ status = H5Dread(dataset, H5T_NATIVE_INT, memspace, filespace, H5P_DEFAULT, column);
printf("\n");
printf("Third column: \n");
for (i = 0; i < 10; i++) {
- printf("%d \n", column[i]);
+ printf("%d \n", column[i]);
}
/*
@@ -153,19 +149,19 @@ main (void)
*/
cparms = H5Dget_create_plist(dataset); /* Get properties handle first. */
- if (H5D_CHUNKED == H5Pget_layout(cparms)) {
+ if (H5D_CHUNKED == H5Pget_layout(cparms)) {
- /*
- * Get chunking information: rank and dimensions
- */
- rank_chunk = H5Pget_chunk(cparms, 2, chunk_dims);
- printf("chunk rank %d, dimensions %lu x %lu\n", rank_chunk,
- (unsigned long)(chunk_dims[0]), (unsigned long)(chunk_dims[1]));
+ /*
+ * Get chunking information: rank and dimensions
+ */
+ rank_chunk = H5Pget_chunk(cparms, 2, chunk_dims);
+ printf("chunk rank %d, dimensions %lu x %lu\n", rank_chunk, (unsigned long)(chunk_dims[0]),
+ (unsigned long)(chunk_dims[1]));
/*
* Define the memory space to read a chunk.
*/
- memspace = H5Screate_simple(rank_chunk,chunk_dims,NULL);
+ memspace = H5Screate_simple(rank_chunk, chunk_dims, NULL);
/*
* Define chunk in the file (hyperslab) to read.
@@ -174,18 +170,17 @@ main (void)
offset[1] = 0;
count[0] = chunk_dims[0];
count[1] = chunk_dims[1];
- status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL,
- count, NULL);
+ status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL, count, NULL);
/*
* Read chunk back and display.
*/
- status = H5Dread(dataset, H5T_NATIVE_INT, memspace, filespace,
- H5P_DEFAULT, chunk_out);
+ status = H5Dread(dataset, H5T_NATIVE_INT, memspace, filespace, H5P_DEFAULT, chunk_out);
printf("\n");
printf("Chunk: \n");
for (j = 0; j < chunk_dims[0]; j++) {
- for (i = 0; i < chunk_dims[1]; i++) printf("%d ", chunk_out[j][i]);
+ for (i = 0; i < chunk_dims[1]; i++)
+ printf("%d ", chunk_out[j][i]);
printf("\n");
}
/*
diff --git a/examples/h5_cmprss.c b/examples/h5_cmprss.c
index b51ec44..d8848e2 100644
--- a/examples/h5_cmprss.c
+++ b/examples/h5_cmprss.c
@@ -6,117 +6,116 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-/*
+/*
* This example illustrates how to create a compressed dataset.
* It is used in the HDF5 Tutorial.
- */
+ */
#include "hdf5.h"
-#define FILE "cmprss.h5"
-#define RANK 2
-#define DIM0 100
-#define DIM1 20
-
-int main () {
+#define FILE "cmprss.h5"
+#define RANK 2
+#define DIM0 100
+#define DIM1 20
- hid_t file_id, dataset_id, dataspace_id; /* identifiers */
- hid_t plist_id;
+int
+main()
+{
- size_t nelmts;
- unsigned flags, filter_info;
+ hid_t file_id, dataset_id, dataspace_id; /* identifiers */
+ hid_t plist_id;
+
+ size_t nelmts;
+ unsigned flags, filter_info;
H5Z_filter_t filter_type;
- herr_t status;
- hsize_t dims[2];
- hsize_t cdims[2];
-
- int i,j, numfilt;
- int buf[DIM0][DIM1];
- int rbuf [DIM0][DIM1];
+ herr_t status;
+ hsize_t dims[2];
+ hsize_t cdims[2];
+
+ int i, j, numfilt;
+ int buf[DIM0][DIM1];
+ int rbuf[DIM0][DIM1];
- /* Uncomment these variables to use SZIP compression
+ /* Uncomment these variables to use SZIP compression
unsigned szip_options_mask;
unsigned szip_pixels_per_block;
*/
/* Create a file. */
- file_id = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
+ file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create dataset "Compressed Data" in the group using absolute name. */
- dims[0] = DIM0;
- dims[1] = DIM1;
- dataspace_id = H5Screate_simple (RANK, dims, NULL);
+ dims[0] = DIM0;
+ dims[1] = DIM1;
+ dataspace_id = H5Screate_simple(RANK, dims, NULL);
- plist_id = H5Pcreate (H5P_DATASET_CREATE);
+ plist_id = H5Pcreate(H5P_DATASET_CREATE);
/* Dataset must be chunked for compression */
cdims[0] = 20;
cdims[1] = 20;
- status = H5Pset_chunk (plist_id, 2, cdims);
+ status = H5Pset_chunk(plist_id, 2, cdims);
/* Set ZLIB / DEFLATE Compression using compression level 6.
- * To use SZIP Compression comment out these lines.
- */
- status = H5Pset_deflate (plist_id, 6);
+ * To use SZIP Compression comment out these lines.
+ */
+ status = H5Pset_deflate(plist_id, 6);
- /* Uncomment these lines to set SZIP Compression
+ /* Uncomment these lines to set SZIP Compression
szip_options_mask = H5_SZIP_NN_OPTION_MASK;
szip_pixels_per_block = 16;
status = H5Pset_szip (plist_id, szip_options_mask, szip_pixels_per_block);
*/
-
- dataset_id = H5Dcreate2 (file_id, "Compressed_Data", H5T_STD_I32BE,
- dataspace_id, H5P_DEFAULT, plist_id, H5P_DEFAULT);
- for (i = 0; i< DIM0; i++)
- for (j=0; j<DIM1; j++)
- buf[i][j] = i+j;
+ dataset_id = H5Dcreate2(file_id, "Compressed_Data", H5T_STD_I32BE, dataspace_id, H5P_DEFAULT, plist_id,
+ H5P_DEFAULT);
- status = H5Dwrite (dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
+ for (i = 0; i < DIM0; i++)
+ for (j = 0; j < DIM1; j++)
+ buf[i][j] = i + j;
- status = H5Sclose (dataspace_id);
- status = H5Dclose (dataset_id);
- status = H5Pclose (plist_id);
- status = H5Fclose (file_id);
+ status = H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf);
+
+ status = H5Sclose(dataspace_id);
+ status = H5Dclose(dataset_id);
+ status = H5Pclose(plist_id);
+ status = H5Fclose(file_id);
/* Now reopen the file and dataset in the file. */
- file_id = H5Fopen (FILE, H5F_ACC_RDWR, H5P_DEFAULT);
- dataset_id = H5Dopen2 (file_id, "Compressed_Data", H5P_DEFAULT);
+ file_id = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT);
+ dataset_id = H5Dopen2(file_id, "Compressed_Data", H5P_DEFAULT);
/* Retrieve filter information. */
- plist_id = H5Dget_create_plist (dataset_id);
-
- numfilt = H5Pget_nfilters (plist_id);
- printf ("Number of filters associated with dataset: %i\n", numfilt);
-
- for (i=0; i<numfilt; i++) {
- nelmts = 0;
- filter_type = H5Pget_filter2 (plist_id, 0, &flags, &nelmts, NULL, 0, NULL,
- &filter_info);
- printf ("Filter Type: ");
- switch (filter_type) {
- case H5Z_FILTER_DEFLATE:
- printf ("H5Z_FILTER_DEFLATE\n");
- break;
- case H5Z_FILTER_SZIP:
- printf ("H5Z_FILTER_SZIP\n");
- break;
- default:
- printf ("Other filter type included.\n");
- }
+ plist_id = H5Dget_create_plist(dataset_id);
+
+ numfilt = H5Pget_nfilters(plist_id);
+ printf("Number of filters associated with dataset: %i\n", numfilt);
+
+ for (i = 0; i < numfilt; i++) {
+ nelmts = 0;
+ filter_type = H5Pget_filter2(plist_id, i, &flags, &nelmts, NULL, 0, NULL, &filter_info);
+ printf("Filter Type: ");
+ switch (filter_type) {
+ case H5Z_FILTER_DEFLATE:
+ printf("H5Z_FILTER_DEFLATE\n");
+ break;
+ case H5Z_FILTER_SZIP:
+ printf("H5Z_FILTER_SZIP\n");
+ break;
+ default:
+ printf("Other filter type included.\n");
+ }
}
- status = H5Dread (dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL,
- H5P_DEFAULT, rbuf);
-
- status = H5Dclose (dataset_id);
- status = H5Pclose (plist_id);
- status = H5Fclose (file_id);
+ status = H5Dread(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf);
+
+ status = H5Dclose(dataset_id);
+ status = H5Pclose(plist_id);
+ status = H5Fclose(file_id);
}
diff --git a/examples/h5_compound.c b/examples/h5_compound.c
index b3b3a4a..093852d 100644
--- a/examples/h5_compound.c
+++ b/examples/h5_compound.c
@@ -6,7 +6,7 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -19,10 +19,10 @@
#include "hdf5.h"
-#define H5FILE_NAME "SDScompound.h5"
-#define DATASETNAME "ArrayOfStructures"
-#define LENGTH 10
-#define RANK 1
+#define H5FILE_NAME "SDScompound.h5"
+#define DATASETNAME "ArrayOfStructures"
+#define LENGTH 10
+#define RANK 1
int
main(void)
@@ -30,38 +30,37 @@ main(void)
/* First structure and dataset*/
typedef struct s1_t {
- int a;
- float b;
- double c;
+ int a;
+ float b;
+ double c;
} s1_t;
- s1_t s1[LENGTH];
- hid_t s1_tid; /* File datatype identifier */
+ s1_t s1[LENGTH];
+ hid_t s1_tid; /* File datatype identifier */
/* Second structure (subset of s1_t) and dataset*/
typedef struct s2_t {
- double c;
- int a;
+ double c;
+ int a;
} s2_t;
- s2_t s2[LENGTH];
- hid_t s2_tid; /* Memory datatype handle */
+ s2_t s2[LENGTH];
+ hid_t s2_tid; /* Memory datatype handle */
/* Third "structure" ( will be used to read float field of s1) */
- hid_t s3_tid; /* Memory datatype handle */
- float s3[LENGTH];
-
- int i;
- hid_t file, dataset, space; /* Handles */
- herr_t status;
- hsize_t dim[] = {LENGTH}; /* Dataspace dimensions */
+ hid_t s3_tid; /* Memory datatype handle */
+ float s3[LENGTH];
+ int i;
+ hid_t file, dataset, space; /* Handles */
+ herr_t status;
+ hsize_t dim[] = {LENGTH}; /* Dataspace dimensions */
/*
* Initialize the data
*/
- for (i = 0; i< LENGTH; i++) {
+ for (i = 0; i < LENGTH; i++) {
s1[i].a = i;
- s1[i].b = i*i;
- s1[i].c = 1./(i+1);
+ s1[i].b = i * i;
+ s1[i].c = 1. / (i + 1);
}
/*
@@ -77,7 +76,7 @@ main(void)
/*
* Create the memory data type.
*/
- s1_tid = H5Tcreate (H5T_COMPOUND, sizeof(s1_t));
+ s1_tid = H5Tcreate(H5T_COMPOUND, sizeof(s1_t));
H5Tinsert(s1_tid, "a_name", HOFFSET(s1_t, a), H5T_NATIVE_INT);
H5Tinsert(s1_tid, "c_name", HOFFSET(s1_t, c), H5T_NATIVE_DOUBLE);
H5Tinsert(s1_tid, "b_name", HOFFSET(s1_t, b), H5T_NATIVE_FLOAT);
@@ -126,12 +125,14 @@ main(void)
*/
printf("\n");
printf("Field c : \n");
- for( i = 0; i < LENGTH; i++) printf("%.4f ", s2[i].c);
+ for (i = 0; i < LENGTH; i++)
+ printf("%.4f ", s2[i].c);
printf("\n");
printf("\n");
printf("Field a : \n");
- for( i = 0; i < LENGTH; i++) printf("%d ", s2[i].a);
+ for (i = 0; i < LENGTH; i++)
+ printf("%d ", s2[i].a);
printf("\n");
/*
@@ -151,7 +152,8 @@ main(void)
*/
printf("\n");
printf("Field b : \n");
- for( i = 0; i < LENGTH; i++) printf("%.4f ", s3[i]);
+ for (i = 0; i < LENGTH; i++)
+ printf("%.4f ", s3[i]);
printf("\n");
/*
diff --git a/examples/h5_crtatt.c b/examples/h5_crtatt.c
index ade17ba..3edc75d 100644
--- a/examples/h5_crtatt.c
+++ b/examples/h5_crtatt.c
@@ -6,7 +6,7 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -19,43 +19,44 @@
#include "hdf5.h"
#define FILE "dset.h5"
-int main() {
+int
+main()
+{
- hid_t file_id, dataset_id, attribute_id, dataspace_id; /* identifiers */
- hsize_t dims;
- int attr_data[2];
- herr_t status;
+ hid_t file_id, dataset_id, attribute_id, dataspace_id; /* identifiers */
+ hsize_t dims;
+ int attr_data[2];
+ herr_t status;
- /* Initialize the attribute data. */
- attr_data[0] = 100;
- attr_data[1] = 200;
+ /* Initialize the attribute data. */
+ attr_data[0] = 100;
+ attr_data[1] = 200;
- /* Open an existing file. */
- file_id = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT);
+ /* Open an existing file. */
+ file_id = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT);
- /* Open an existing dataset. */
- dataset_id = H5Dopen2(file_id, "/dset", H5P_DEFAULT);
+ /* Open an existing dataset. */
+ dataset_id = H5Dopen2(file_id, "/dset", H5P_DEFAULT);
- /* Create the data space for the attribute. */
- dims = 2;
- dataspace_id = H5Screate_simple(1, &dims, NULL);
+ /* Create the data space for the attribute. */
+ dims = 2;
+ dataspace_id = H5Screate_simple(1, &dims, NULL);
- /* Create a dataset attribute. */
- attribute_id = H5Acreate2 (dataset_id, "Units", H5T_STD_I32BE, dataspace_id,
- H5P_DEFAULT, H5P_DEFAULT);
+ /* Create a dataset attribute. */
+ attribute_id = H5Acreate2(dataset_id, "Units", H5T_STD_I32BE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT);
- /* Write the attribute data. */
- status = H5Awrite(attribute_id, H5T_NATIVE_INT, attr_data);
+ /* Write the attribute data. */
+ status = H5Awrite(attribute_id, H5T_NATIVE_INT, attr_data);
- /* Close the attribute. */
- status = H5Aclose(attribute_id);
+ /* Close the attribute. */
+ status = H5Aclose(attribute_id);
- /* Close the dataspace. */
- status = H5Sclose(dataspace_id);
+ /* Close the dataspace. */
+ status = H5Sclose(dataspace_id);
- /* Close to the dataset. */
- status = H5Dclose(dataset_id);
+ /* Close to the dataset. */
+ status = H5Dclose(dataset_id);
- /* Close the file. */
- status = H5Fclose(file_id);
+ /* Close the file. */
+ status = H5Fclose(file_id);
}
diff --git a/examples/h5_crtdat.c b/examples/h5_crtdat.c
index 4a876d2..4450367 100644
--- a/examples/h5_crtdat.c
+++ b/examples/h5_crtdat.c
@@ -6,44 +6,45 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
- * This example illustrates how to create a dataset that is a 4 x 6
+ * This example illustrates how to create a dataset that is a 4 x 6
* array. It is used in the HDF5 Tutorial.
*/
#include "hdf5.h"
#define FILE "dset.h5"
-int main() {
+int
+main()
+{
- hid_t file_id, dataset_id, dataspace_id; /* identifiers */
- hsize_t dims[2];
- herr_t status;
+ hid_t file_id, dataset_id, dataspace_id; /* identifiers */
+ hsize_t dims[2];
+ herr_t status;
- /* Create a new file using default properties. */
- file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ /* Create a new file using default properties. */
+ file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
- /* Create the data space for the dataset. */
- dims[0] = 4;
- dims[1] = 6;
- dataspace_id = H5Screate_simple(2, dims, NULL);
+ /* Create the data space for the dataset. */
+ dims[0] = 4;
+ dims[1] = 6;
+ dataspace_id = H5Screate_simple(2, dims, NULL);
- /* Create the dataset. */
- dataset_id = H5Dcreate2(file_id, "/dset", H5T_STD_I32BE, dataspace_id,
- H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ /* Create the dataset. */
+ dataset_id =
+ H5Dcreate2(file_id, "/dset", H5T_STD_I32BE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
- /* End access to the dataset and release resources used by it. */
- status = H5Dclose(dataset_id);
+ /* End access to the dataset and release resources used by it. */
+ status = H5Dclose(dataset_id);
- /* Terminate access to the data space. */
- status = H5Sclose(dataspace_id);
+ /* Terminate access to the data space. */
+ status = H5Sclose(dataspace_id);
- /* Close the file. */
- status = H5Fclose(file_id);
+ /* Close the file. */
+ status = H5Fclose(file_id);
}
-
diff --git a/examples/h5_crtgrp.c b/examples/h5_crtgrp.c
index 89bddce..abddf09 100644
--- a/examples/h5_crtgrp.c
+++ b/examples/h5_crtgrp.c
@@ -6,33 +6,35 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
- * This example illustrates how to create and close a group.
+ * This example illustrates how to create and close a group.
* It is used in the HDF5 Tutorial.
*/
#include "hdf5.h"
#define FILE "group.h5"
-int main() {
+int
+main()
+{
- hid_t file_id, group_id; /* identifiers */
- herr_t status;
+ hid_t file_id, group_id; /* identifiers */
+ herr_t status;
- /* Create a new file using default properties. */
- file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ /* Create a new file using default properties. */
+ file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
- /* Create a group named "/MyGroup" in the file. */
- group_id = H5Gcreate2(file_id, "/MyGroup", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ /* Create a group named "/MyGroup" in the file. */
+ group_id = H5Gcreate2(file_id, "/MyGroup", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
- /* Close the group. */
- status = H5Gclose(group_id);
+ /* Close the group. */
+ status = H5Gclose(group_id);
- /* Terminate access to the file. */
- status = H5Fclose(file_id);
+ /* Terminate access to the file. */
+ status = H5Fclose(file_id);
}
diff --git a/examples/h5_crtgrpar.c b/examples/h5_crtgrpar.c
index 6f8c6e8..a4d5f38 100644
--- a/examples/h5_crtgrpar.c
+++ b/examples/h5_crtgrpar.c
@@ -6,41 +6,43 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
- * This example illustrates the creation of groups using absolute and
+ * This example illustrates the creation of groups using absolute and
* relative names. It is used in the HDF5 Tutorial.
*/
#include "hdf5.h"
#define FILE "groups.h5"
-int main() {
+int
+main()
+{
- hid_t file_id, group1_id, group2_id, group3_id; /* identifiers */
- herr_t status;
+ hid_t file_id, group1_id, group2_id, group3_id; /* identifiers */
+ herr_t status;
- /* Create a new file using default properties. */
- file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ /* Create a new file using default properties. */
+ file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
- /* Create group "MyGroup" in the root group using absolute name. */
- group1_id = H5Gcreate2(file_id, "/MyGroup", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ /* Create group "MyGroup" in the root group using absolute name. */
+ group1_id = H5Gcreate2(file_id, "/MyGroup", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
- /* Create group "Group_A" in group "MyGroup" using absolute name. */
- group2_id = H5Gcreate2(file_id, "/MyGroup/Group_A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ /* Create group "Group_A" in group "MyGroup" using absolute name. */
+ group2_id = H5Gcreate2(file_id, "/MyGroup/Group_A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
- /* Create group "Group_B" in group "MyGroup" using relative name. */
- group3_id = H5Gcreate2(group1_id, "Group_B", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ /* Create group "Group_B" in group "MyGroup" using relative name. */
+ group3_id = H5Gcreate2(group1_id, "Group_B", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
- /* Close groups. */
- status = H5Gclose(group1_id);
- status = H5Gclose(group2_id);
- status = H5Gclose(group3_id);
+ /* Close groups. */
+ status = H5Gclose(group1_id);
+ status = H5Gclose(group2_id);
+ status = H5Gclose(group3_id);
- /* Close the file. */
- status = H5Fclose(file_id);
+ /* Close the file. */
+ status = H5Fclose(file_id);
}
diff --git a/examples/h5_crtgrpd.c b/examples/h5_crtgrpd.c
index 35c4389..3095aa0 100644
--- a/examples/h5_crtgrpd.c
+++ b/examples/h5_crtgrpd.c
@@ -6,7 +6,7 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -19,71 +19,70 @@
#include "hdf5.h"
#define FILE "groups.h5"
-int main() {
+int
+main()
+{
- hid_t file_id, group_id, dataset_id, dataspace_id; /* identifiers */
- hsize_t dims[2];
- herr_t status;
- int i, j, dset1_data[3][3], dset2_data[2][10];
+ hid_t file_id, group_id, dataset_id, dataspace_id; /* identifiers */
+ hsize_t dims[2];
+ herr_t status;
+ int i, j, dset1_data[3][3], dset2_data[2][10];
- /* Initialize the first dataset. */
- for (i = 0; i < 3; i++)
- for (j = 0; j < 3; j++)
- dset1_data[i][j] = j + 1;
+ /* Initialize the first dataset. */
+ for (i = 0; i < 3; i++)
+ for (j = 0; j < 3; j++)
+ dset1_data[i][j] = j + 1;
- /* Initialize the second dataset. */
- for (i = 0; i < 2; i++)
- for (j = 0; j < 10; j++)
- dset2_data[i][j] = j + 1;
+ /* Initialize the second dataset. */
+ for (i = 0; i < 2; i++)
+ for (j = 0; j < 10; j++)
+ dset2_data[i][j] = j + 1;
- /* Open an existing file. */
- file_id = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT);
+ /* Open an existing file. */
+ file_id = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT);
- /* Create the data space for the first dataset. */
- dims[0] = 3;
- dims[1] = 3;
- dataspace_id = H5Screate_simple(2, dims, NULL);
+ /* Create the data space for the first dataset. */
+ dims[0] = 3;
+ dims[1] = 3;
+ dataspace_id = H5Screate_simple(2, dims, NULL);
- /* Create a dataset in group "MyGroup". */
- dataset_id = H5Dcreate2(file_id, "/MyGroup/dset1", H5T_STD_I32BE, dataspace_id,
- H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ /* Create a dataset in group "MyGroup". */
+ dataset_id = H5Dcreate2(file_id, "/MyGroup/dset1", H5T_STD_I32BE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT,
+ H5P_DEFAULT);
- /* Write the first dataset. */
- status = H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
- dset1_data);
+ /* Write the first dataset. */
+ status = H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset1_data);
- /* Close the data space for the first dataset. */
- status = H5Sclose(dataspace_id);
+ /* Close the data space for the first dataset. */
+ status = H5Sclose(dataspace_id);
- /* Close the first dataset. */
- status = H5Dclose(dataset_id);
+ /* Close the first dataset. */
+ status = H5Dclose(dataset_id);
- /* Open an existing group of the specified file. */
- group_id = H5Gopen2(file_id, "/MyGroup/Group_A", H5P_DEFAULT);
+ /* Open an existing group of the specified file. */
+ group_id = H5Gopen2(file_id, "/MyGroup/Group_A", H5P_DEFAULT);
- /* Create the data space for the second dataset. */
- dims[0] = 2;
- dims[1] = 10;
- dataspace_id = H5Screate_simple(2, dims, NULL);
+ /* Create the data space for the second dataset. */
+ dims[0] = 2;
+ dims[1] = 10;
+ dataspace_id = H5Screate_simple(2, dims, NULL);
- /* Create the second dataset in group "Group_A". */
- dataset_id = H5Dcreate2(group_id, "dset2", H5T_STD_I32BE, dataspace_id,
- H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ /* Create the second dataset in group "Group_A". */
+ dataset_id =
+ H5Dcreate2(group_id, "dset2", H5T_STD_I32BE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
- /* Write the second dataset. */
- status = H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
- dset2_data);
+ /* Write the second dataset. */
+ status = H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset2_data);
- /* Close the data space for the second dataset. */
- status = H5Sclose(dataspace_id);
+ /* Close the data space for the second dataset. */
+ status = H5Sclose(dataspace_id);
- /* Close the second dataset */
- status = H5Dclose(dataset_id);
+ /* Close the second dataset */
+ status = H5Dclose(dataset_id);
- /* Close the group. */
- status = H5Gclose(group_id);
+ /* Close the group. */
+ status = H5Gclose(group_id);
- /* Close the file. */
- status = H5Fclose(file_id);
+ /* Close the file. */
+ status = H5Fclose(file_id);
}
-
diff --git a/examples/h5_debug_trace.c b/examples/h5_debug_trace.c
new file mode 100644
index 0000000..0f0ec97
--- /dev/null
+++ b/examples/h5_debug_trace.c
@@ -0,0 +1,140 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Copyright by The HDF Group. *
+ * Copyright by the Board of Trustees of the University of Illinois. *
+ * 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 files COPYING and Copyright.html. COPYING can be found at the root *
+ * of the source code distribution tree; Copyright.html can be found at the *
+ * root level of an installed copy of the electronic HDF5 document set and *
+ * is linked from the top-level documents page. It can also be found at *
+ * http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
+ * access to either file, you may request a copy from help@hdfgroup.org. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/* This example demonstrates debug trace output.
+ *
+ * Debug/trace/performance output is not tested as a regular part of our
+ * testing so this program gives a quick check that it's all working.
+ *
+ * Preconditions:
+ *
+ * You need to set an environment variable named HDF5_DEBUG to have a value
+ * of "+all trace ttimes". In the bash shell, you'd use:
+ *
+ * export HDF5_DEBUG="+all trace ttimes"
+ *
+ * When you are done with this test program, you can set the variable back
+ * to "-all" to suppress trace output.
+ *
+ * Usage:
+ *
+ * Compile and run the test program, then inspect the output. You should see
+ * trace information for each HDF5 function call that increase over time.
+ * Each time stamp is in seconds and designated with an '@' sign. The
+ * elapsed time for the function call is given in seconds in the [dt= ]
+ * part.
+ *
+ * You will also get summary output for the shuffle filter performance and
+ * data type conversion performance. These will include the elapsed time
+ * (always) and the system and user times (if available on your system). On
+ * fast machines, these numbers may be 0.0. Adjust the loop variables in
+ * the program as needed to generate reasonable output.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "hdf5.h"
+
+#define BUF_SIZE 1048576
+#define N_LOOPS 64
+
+#define TESTFILE "h5_debug_trace_out.h5"
+
+int
+main(int argc, char **argv)
+{
+ int i, j;
+ int *data;
+
+ hid_t fid;
+ hid_t pid;
+ hid_t did;
+ hid_t sid;
+
+ hsize_t dims[1] = {BUF_SIZE};
+ hsize_t chunk_sizes[1] = {1024};
+
+ herr_t err;
+
+ /*************************************************************************/
+
+ /* Warn the user about trace deluge to come */
+
+ printf("Testing debug/trace/performance data generation\n");
+ printf("\n");
+ printf("This test should generate a large amount of trace data\n");
+ printf("\n");
+ printf("*** BEGIN TRACE OUTPUT ***\n");
+ printf("\n");
+ fflush(stdout);
+
+ /* This will emit H5Tconvert() performance information */
+
+ for (i = 0; i < N_LOOPS; i++) {
+
+ /* The buffer has to be large enough to hold the conversion output */
+ data = (int *)malloc(BUF_SIZE * sizeof(double));
+
+ for (j = 0; j < BUF_SIZE; j++) {
+ data[j] = j;
+ }
+
+ err = H5Tconvert(H5T_NATIVE_INT, H5T_NATIVE_DOUBLE, BUF_SIZE, data, NULL, H5P_DEFAULT);
+
+ if (err < 0) {
+ fprintf(stderr, "ERROR: Conversion failed\n");
+ free(data);
+ return err;
+ }
+
+ free(data);
+ }
+
+ /* This will emit H5Z performance information */
+
+ data = (int *)malloc(BUF_SIZE * sizeof(int));
+
+ for (i = 0; i < BUF_SIZE; i++) {
+ data[i] = i;
+ }
+
+ fid = H5Fcreate(TESTFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+
+ pid = H5Pcreate(H5P_DATASET_CREATE);
+ err = H5Pset_chunk(pid, 1, chunk_sizes);
+ err = H5Pset_shuffle(pid);
+
+ sid = H5Screate_simple(1, dims, dims);
+ did = H5Dcreate2(fid, "somedata", H5T_NATIVE_INT, sid, H5P_DEFAULT, pid, H5P_DEFAULT);
+ err = H5Dwrite(did, H5T_NATIVE_INT, sid, sid, H5P_DEFAULT, data);
+
+ H5Sclose(sid);
+ H5Dclose(did);
+ H5Pclose(pid);
+ H5Fclose(fid);
+
+ free(data);
+
+ /* Finished */
+ fflush(stdout);
+ printf("\n");
+ printf("*** END TRACE OUTPUT ***\n");
+ printf("\n");
+
+ remove(TESTFILE);
+
+ return 0;
+}
diff --git a/examples/h5_drivers.c b/examples/h5_drivers.c
index 43c1fc7..d9321ed 100644
--- a/examples/h5_drivers.c
+++ b/examples/h5_drivers.c
@@ -6,7 +6,7 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -22,13 +22,12 @@
#include "stdlib.h"
/* global variables */
-int cleanup_g = -1; /* whether to clean. Init to not set. */
+int cleanup_g = -1; /* whether to clean. Init to not set. */
/* prototypes */
void cleanup(const char *);
void split_file(void);
-
/*
* Cleanup a file unless $HDF5_NOCLEANUP is set.
*/
@@ -36,12 +35,11 @@ void
cleanup(const char *filename)
{
if (cleanup_g == -1)
- cleanup_g = getenv("HDF5_NOCLEANUP") ? 0 : 1;
+ cleanup_g = getenv(HDF5_NOCLEANUP) ? 0 : 1;
if (cleanup_g)
- remove(filename);
+ remove(filename);
}
-
/*
* This shows how to use the split file driver.
*/
@@ -55,7 +53,7 @@ split_file(void)
/* the metadata and rawdata files. */
fapl = H5Pcreate(H5P_FILE_ACCESS);
H5Pset_fapl_split(fapl, "-m.h5", H5P_DEFAULT, "-r.h5", H5P_DEFAULT);
- fid=H5Fcreate("Station1",H5F_ACC_TRUNC,H5P_DEFAULT,fapl);
+ fid = H5Fcreate("Station1", H5F_ACC_TRUNC, H5P_DEFAULT, fapl);
/* using the file ... */
H5Fclose(fid);
H5Pclose(fapl);
@@ -68,7 +66,7 @@ split_file(void)
/* the metadata and rawdata files. */
fapl = H5Pcreate(H5P_FILE_ACCESS);
H5Pset_fapl_split(fapl, "-m.h5", H5P_DEFAULT, "/tmp/%s-r.h5", H5P_DEFAULT);
- fid=H5Fcreate("PointA",H5F_ACC_TRUNC,H5P_DEFAULT,fapl);
+ fid = H5Fcreate("PointA", H5F_ACC_TRUNC, H5P_DEFAULT, fapl);
/* using the file ... */
H5Fclose(fid);
H5Pclose(fapl);
@@ -81,7 +79,7 @@ split_file(void)
/* the metadata and rawdata files. */
fapl = H5Pcreate(H5P_FILE_ACCESS);
H5Pset_fapl_split(fapl, NULL, H5P_DEFAULT, NULL, H5P_DEFAULT);
- fid=H5Fcreate("Measure",H5F_ACC_TRUNC,H5P_DEFAULT,fapl);
+ fid = H5Fcreate("Measure", H5F_ACC_TRUNC, H5P_DEFAULT, fapl);
/* using the file ... */
H5Fclose(fid);
H5Pclose(fapl);
@@ -90,13 +88,12 @@ split_file(void)
cleanup("Measure.raw");
}
-
/* Main Body */
int
-main (void)
+main(void)
{
split_file();
- return(0);
+ return (0);
}
diff --git a/examples/h5_dtransform.c b/examples/h5_dtransform.c
index 0b718ad..a364ec1 100644
--- a/examples/h5_dtransform.c
+++ b/examples/h5_dtransform.c
@@ -6,7 +6,7 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -33,50 +33,48 @@
#include "hdf5.h"
-#define ROWS 12
-#define COLS 18
+#define ROWS 12
+#define COLS 18
+/* clang-format off */
const float windchillF[ROWS][COLS] =
- { {36.0, 31.0, 25.0, 19.0, 13.0, 7.0, 1.0, -5.0, -11.0, -16.0, -22.0, -28.0, -34.0, -40.0, -46.0, -52.0, -57.0, -63.0 },
- {34.0, 27.0, 21.0, 15.0, 9.0, 3.0, -4.0, -10.0, -16.0, -22.0, -28.0, -35.0, -41.0, -47.0, -53.0, -59.0, -66.0, -72.0 } ,
- {32.0, 25.0, 19.0, 13.0, 6.0, 0.0, -7.0, -13.0, -19.0, -26.0, -32.0, -39.0, -45.0, -51.0, -58.0, -64.0, -71.0, -77.0 },
- {30.0, 24.0, 17.0, 11.0, 4.0, -2.0, -9.0, -15.0, -22.0, -29.0, -35.0, -42.0, -48.0, -55.0, -61.0, -68.0, -74.0, -81.0 },
- {29.0, 23.0, 16.0, 9.0, 3.0, -4.0, -11.0, -17.0, -24.0, -31.0, -37.0, -44.0, -51.0, -58.0, -64.0, -71.0, -78.0, -84.0 },
- {28.0, 22.0, 15.0, 8.0, 1.0, -5.0, -12.0, -19.0, -26.0, -33.0, -39.0, -46.0, -53.0, -60.0, -67.0, -73.0, -80.0, -87.0 },
- {28.0, 21.0, 14.0, 7.0, 0.0, -7.0, -14.0, -21.0, -27.0, -34.0, -41.0, -48.0, -55.0, -62.0, -69.0, -76.0, -82.0, -89.0 },
- {27.0, 20.0, 13.0, 6.0, -1.0, -8.0, -15.0, -22.0, -29.0, -36.0, -43.0, -50.0, -57.0, -64.0, -71.0, -78.0, -84.0, -91.0 },
- {26.0, 19.0, 12.0, 5.0, -2.0, -9.0, -16.0, -23.0, -30.0, -37.0, -44.0, -51.0, -58.0, -65.0, -72.0, -79.0, -86.0, -93.0 },
+ { {36.0, 31.0, 25.0, 19.0, 13.0, 7.0, 1.0, -5.0, -11.0, -16.0, -22.0, -28.0, -34.0, -40.0, -46.0, -52.0, -57.0, -63.0},
+ {34.0, 27.0, 21.0, 15.0, 9.0, 3.0, -4.0, -10.0, -16.0, -22.0, -28.0, -35.0, -41.0, -47.0, -53.0, -59.0, -66.0, -72.0},
+ {32.0, 25.0, 19.0, 13.0, 6.0, 0.0, -7.0, -13.0, -19.0, -26.0, -32.0, -39.0, -45.0, -51.0, -58.0, -64.0, -71.0, -77.0},
+ {30.0, 24.0, 17.0, 11.0, 4.0, -2.0, -9.0, -15.0, -22.0, -29.0, -35.0, -42.0, -48.0, -55.0, -61.0, -68.0, -74.0, -81.0},
+ {29.0, 23.0, 16.0, 9.0, 3.0, -4.0, -11.0, -17.0, -24.0, -31.0, -37.0, -44.0, -51.0, -58.0, -64.0, -71.0, -78.0, -84.0},
+ {28.0, 22.0, 15.0, 8.0, 1.0, -5.0, -12.0, -19.0, -26.0, -33.0, -39.0, -46.0, -53.0, -60.0, -67.0, -73.0, -80.0, -87.0},
+ {28.0, 21.0, 14.0, 7.0, 0.0, -7.0, -14.0, -21.0, -27.0, -34.0, -41.0, -48.0, -55.0, -62.0, -69.0, -76.0, -82.0, -89.0},
+ {27.0, 20.0, 13.0, 6.0, -1.0, -8.0, -15.0, -22.0, -29.0, -36.0, -43.0, -50.0, -57.0, -64.0, -71.0, -78.0, -84.0, -91.0},
+ {26.0, 19.0, 12.0, 5.0, -2.0, -9.0, -16.0, -23.0, -30.0, -37.0, -44.0, -51.0, -58.0, -65.0, -72.0, -79.0, -86.0, -93.0},
{26.0, 19.0, 12.0, 4.0, -3.0, -10.0, -17.0, -24.0, -31.0, -38.0, -45.0, -52.0, -60.0, -67.0, -74.0, -81.0, -88.0, -95.0},
{25.0, 18.0, 11.0, 4.0, -3.0, -11.0, -18.0, -25.0, -32.0, -39.0, -46.0, -54.0, -61.0, -68.0, -75.0, -82.0, -89.0, -97.0},
{25.0, 17.0, 10.0, 3.0, -4.0, -11.0, -19.0, -26.0, -33.0, -40.0, -48.0, -55.0, -62.0, -69.0, -76.0, -84.0, -91.0, -98.0}
};
+/* clang-format on */
-#define PRINT(array) \
-{ \
- for(i=0; i<ROWS; i++) \
- { \
- for(j=0; j<COLS; j++) \
- printf("%6.2f ", array[i][j]); \
- printf("\n"); \
- } \
-}
-
-
-
+#define PRINT(array) \
+ { \
+ for (i = 0; i < ROWS; i++) { \
+ for (j = 0; j < COLS; j++) \
+ printf("%6.2f ", array[i][j]); \
+ printf("\n"); \
+ } \
+ }
int
-main (void)
+main(void)
{
- hid_t file, dataset; /* file and dataset handles */
- hid_t dataspace; /* handles */
- hsize_t dimsf[2]; /* dataset dimensions */
+ hid_t file, dataset; /* file and dataset handles */
+ hid_t dataspace; /* handles */
+ hsize_t dimsf[2]; /* dataset dimensions */
herr_t status;
- hid_t dxpl_id_f_to_c, dxpl_id_c_to_f; /* data transform handles */
- const char* f_to_c = "(5/9.0)*(x-32)";
- const char* c_to_f = "(9/5.0)*x + 32";
- char* transform;
- float windchillC[ROWS][COLS];
- int i,j, transform_size;
+ hid_t dxpl_id_f_to_c, dxpl_id_c_to_f; /* data transform handles */
+ const char *f_to_c = "(5/9.0)*(x-32)";
+ const char *c_to_f = "(9/5.0)*x + 32";
+ char * transform;
+ float windchillC[ROWS][COLS];
+ int i, j, transform_size;
/*
* Create a new file using H5F_ACC_TRUNC access,
@@ -89,28 +87,25 @@ main (void)
* Describe the size of the array and create the data space for fixed
* size dataset.
*/
- dimsf[0] = ROWS;
- dimsf[1] = COLS;
+ dimsf[0] = ROWS;
+ dimsf[1] = COLS;
dataspace = H5Screate_simple(2, dimsf, NULL);
/*
* Create a new dataset within the file using defined dataspace and
* datatype and default dataset creation properties.
*/
- dataset = H5Dcreate2(file, "data_no_trans", H5T_NATIVE_FLOAT, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ dataset =
+ H5Dcreate2(file, "data_no_trans", H5T_NATIVE_FLOAT, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
printf("\nOriginal Data: \n");
PRINT(windchillF);
-
-
-
-/**************** PART 1 **************/
+ /**************** PART 1 **************/
/*
* Write the data to the dataset using default transfer properties (ie, no transform set)
*/
- status = H5Dwrite(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL,
- H5P_DEFAULT, windchillF);
+ status = H5Dwrite(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, windchillF);
/* Create the dataset transfer property list */
dxpl_id_f_to_c = H5Pcreate(H5P_DATASET_XFER);
@@ -125,13 +120,11 @@ main (void)
printf("\nData with no write transform, but a read transform: \n");
PRINT(windchillC);
-
-/**************** PART 2 **************/
+ /**************** PART 2 **************/
/*
* Write the data to the dataset with the f_to_c transform set
*/
- status = H5Dwrite(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL,
- dxpl_id_f_to_c, windchillF);
+ status = H5Dwrite(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, dxpl_id_f_to_c, windchillF);
/* Read out the data with the default transfer list (ie, no transform set) */
H5Dread(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, H5P_DEFAULT, windchillC);
@@ -140,8 +133,7 @@ main (void)
printf("\nData with write transform, but no read transform: \n");
PRINT(windchillC);
-/************** PART 3 ***************/
-
+ /************** PART 3 ***************/
/* Create the dataset transfer property list */
dxpl_id_c_to_f = H5Pcreate(H5P_DATASET_XFER);
@@ -149,12 +141,10 @@ main (void)
/* Set the data transform to be used on the read*/
H5Pset_data_transform(dxpl_id_c_to_f, c_to_f);
-
/*
* Write the data to the dataset using the f_to_c transform
*/
- status = H5Dwrite(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL,
- dxpl_id_f_to_c, windchillF);
+ status = H5Dwrite(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, dxpl_id_f_to_c, windchillF);
/* Read the data with the c_to_f data transform */
H5Dread(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, dxpl_id_c_to_f, windchillC);
@@ -163,10 +153,10 @@ main (void)
printf("\nData with both read and write data transform: \n");
PRINT(windchillC);
-/************** PART 4 **************/
+ /************** PART 4 **************/
transform_size = H5Pget_data_transform(dxpl_id_f_to_c, NULL, 0);
- transform = (char*) malloc(transform_size+1);
- H5Pget_data_transform(dxpl_id_f_to_c, transform, transform_size+1);
+ transform = (char *)malloc(transform_size + 1);
+ H5Pget_data_transform(dxpl_id_f_to_c, transform, transform_size + 1);
printf("\nTransform string (from dxpl_id_f_to_c) is: %s\n", transform);
diff --git a/examples/h5_elink_unix2win.c b/examples/h5_elink_unix2win.c
index c29e7db..6eca266 100644
--- a/examples/h5_elink_unix2win.c
+++ b/examples/h5_elink_unix2win.c
@@ -6,7 +6,7 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -27,7 +27,6 @@
#include <stdlib.h>
#include <string.h>
-
/* "Windows to Unix" traversal function for external links
*
* Translates a filename stored in Unix format to Windows format by replacing
@@ -37,45 +36,44 @@
* Note that this may not be necessary on your system; many Windows systems can
* understand Unix paths.
*/
-static hid_t elink_unix2win_trav(const char *link_name, hid_t cur_group,
- const void *udata, size_t udata_size, hid_t lapl_id, hid_t dxpl_id)
+static hid_t
+elink_unix2win_trav(const char *link_name, hid_t cur_group, const void *udata, size_t udata_size,
+ hid_t lapl_id, hid_t dxpl_id)
{
- hid_t fid;
- const char *file_name;
- const char *obj_name;
- char *new_fname = NULL; /* Buffer allocated to hold Unix file path */
- ssize_t prefix_len; /* External link prefix length */
- size_t fname_len;
- size_t start_pos; /* Initial position in new_fname buffer */
- size_t x; /* Counter variable */
- hid_t ret_value = -1;
+ hid_t fid;
+ const char *file_name;
+ const char *obj_name;
+ char * new_fname = NULL; /* Buffer allocated to hold Unix file path */
+ ssize_t prefix_len; /* External link prefix length */
+ size_t fname_len;
+ size_t start_pos; /* Initial position in new_fname buffer */
+ size_t x; /* Counter variable */
+ hid_t ret_value = -1;
printf("Converting Unix path to Windows path.\n");
- if(H5Lunpack_elink_val(udata, udata_size, NULL, &file_name, &obj_name) < 0)
+ if (H5Lunpack_elink_val(udata, udata_size, NULL, &file_name, &obj_name) < 0)
goto error;
fname_len = strlen(file_name);
/* See if the external link prefix property is set */
- if((prefix_len = H5Pget_elink_prefix(lapl_id, NULL, 0)) < 0)
+ if ((prefix_len = H5Pget_elink_prefix(lapl_id, NULL, 0)) < 0)
goto error;
/* If so, prepend it to the filename. We assume that the prefix
* is in the correct format for the current file system.
*/
- if(prefix_len > 0)
- {
+ if (prefix_len > 0) {
/* Allocate a buffer to hold the filename plus prefix */
new_fname = malloc(prefix_len + fname_len + 1);
/* Copy the prefix into the buffer */
- if(H5Pget_elink_prefix(lapl_id, new_fname, (size_t)(prefix_len + 1)) < 0)
+ if (H5Pget_elink_prefix(lapl_id, new_fname, (size_t)(prefix_len + 1)) < 0)
goto error;
start_pos = prefix_len;
}
- else
- {
+ else {
/* Allocate a buffer to hold just the filename */
new_fname = malloc(fname_len + 1);
start_pos = 0;
@@ -84,9 +82,8 @@ static hid_t elink_unix2win_trav(const char *link_name, hid_t cur_group,
/* We should now copy file_name into new_fname starting at position pos.
* We'll convert '/' characters into '\' characters as we go.
*/
- for(x=0; file_name[x] != '\0'; x++)
- {
- if(file_name[x] == '/')
+ for (x = 0; file_name[x] != '\0'; x++) {
+ if (file_name[x] == '/')
new_fname[x + start_pos] = '\\';
else
new_fname[x + start_pos] = file_name[x];
@@ -94,38 +91,37 @@ static hid_t elink_unix2win_trav(const char *link_name, hid_t cur_group,
new_fname[x + start_pos] = '\0';
/* Now open the file and object within it */
- if((fid = H5Fopen(new_fname, H5F_ACC_RDWR, H5P_DEFAULT)) < 0)
+ if ((fid = H5Fopen(new_fname, H5F_ACC_RDWR, H5P_DEFAULT)) < 0)
goto error;
ret_value = H5Oopen(fid, obj_name, lapl_id); /* If this fails, our return value will be negative. */
- if(H5Fclose(fid) < 0)
+ if (H5Fclose(fid) < 0)
goto error;
/* Free file name if it's been allocated */
- if(new_fname)
+ if (new_fname)
free(new_fname);
return ret_value;
error:
/* Free file name if it's been allocated */
- if(new_fname)
+ if (new_fname)
free(new_fname);
return -1;
}
const H5L_class_t elink_unix2win_class[1] = {{
- H5L_LINK_CLASS_T_VERS, /* H5L_class_t version */
- H5L_TYPE_EXTERNAL, /* Link type id number */
- "unix2win external link", /* Link class name for debugging */
- NULL, /* Creation callback */
- NULL, /* Move callback */
- NULL, /* Copy callback */
- elink_unix2win_trav, /* The actual traversal function */
- NULL, /* Deletion callback */
- NULL /* Query callback */
+ H5L_LINK_CLASS_T_VERS, /* H5L_class_t version */
+ H5L_TYPE_EXTERNAL, /* Link type id number */
+ "unix2win external link", /* Link class name for debugging */
+ NULL, /* Creation callback */
+ NULL, /* Move callback */
+ NULL, /* Copy callback */
+ elink_unix2win_trav, /* The actual traversal function */
+ NULL, /* Deletion callback */
+ NULL /* Query callback */
}};
-
/* The example function.
* Creates a file named "unix2win.h5" with an external link pointing to
* the file "u2w/u2w_target.h5".
@@ -136,55 +132,65 @@ const H5L_class_t elink_unix2win_class[1] = {{
static int
unix2win_example(void)
{
- hid_t fid = (-1); /* File ID */
- hid_t gid = (-1); /* Group ID */
+ hid_t fid = (-1); /* File ID */
+ hid_t gid = (-1); /* Group ID */
/* Create the target file. */
#ifdef H5_HAVE_WIN32_API
- if((fid=H5Fcreate("u2w\\u2w_target.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT))<0) goto error;
+ if ((fid = H5Fcreate("u2w\\u2w_target.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto error;
#else
- if((fid=H5Fcreate("u2w/u2w_target.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT))<0) goto error;
+ if ((fid = H5Fcreate("u2w/u2w_target.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto error;
#endif
- if(H5Fclose(fid) < 0) goto error;
+ if (H5Fclose(fid) < 0)
+ goto error;
/* Create the source file with an external link in Windows format */
- if((fid=H5Fcreate("unix2win.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT))<0) goto error;
+ if ((fid = H5Fcreate("unix2win.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
+ goto error;
/* Create the external link */
- if(H5Lcreate_external("u2w/../u2w/u2w_target.h5", "/", fid, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0) goto error;
+ if (H5Lcreate_external("u2w/../u2w/u2w_target.h5", "/", fid, "ext_link", H5P_DEFAULT, H5P_DEFAULT) < 0)
+ goto error;
- /* If we are not on Windows, assume we are on a Unix-y filesystem and
- * follow the external link normally.
- * If we are on Windows, register the unix2win traversal function so
- * that external links can be traversed.
- */
+ /* If we are not on Windows, assume we are on a Unix-y filesystem and
+ * follow the external link normally.
+ * If we are on Windows, register the unix2win traversal function so
+ * that external links can be traversed.
+ */
#ifdef H5_HAVE_WIN32_API
/* Register the elink_unix2win class defined above to replace default
* external links
*/
- if(H5Lregister(elink_unix2win_class) < 0) goto error;
+ if (H5Lregister(elink_unix2win_class) < 0)
+ goto error;
#endif
/* Now follow the link */
- if((gid = H5Gopen2(fid, "ext_link", H5P_DEFAULT)) < 0) goto error;
+ if ((gid = H5Gopen2(fid, "ext_link", H5P_DEFAULT)) < 0)
+ goto error;
printf("Successfully followed external link.\n");
/* Close the group and the file */
- if(H5Gclose(gid) <0) goto error;
- if(H5Fclose(fid) <0) goto error;
+ if (H5Gclose(gid) < 0)
+ goto error;
+ if (H5Fclose(fid) < 0)
+ goto error;
return 0;
- error:
+error:
printf("Error!\n");
- H5E_BEGIN_TRY {
- H5Gclose (gid);
- H5Fclose (fid);
- } H5E_END_TRY;
+ H5E_BEGIN_TRY
+ {
+ H5Gclose(gid);
+ H5Fclose(fid);
+ }
+ H5E_END_TRY;
return -1;
}
-
/* Main function
*
@@ -193,12 +199,10 @@ unix2win_example(void)
int
main(void)
{
- int ret;
+ int ret;
printf("Testing unix2win external links.\n");
ret = unix2win_example();
return ret;
}
-
-
diff --git a/examples/h5_extend.c b/examples/h5_extend.c
index 6e3cff2..5807694 100644
--- a/examples/h5_extend.c
+++ b/examples/h5_extend.c
@@ -6,139 +6,126 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
- * This example how to work with extendible datasets. The dataset
+ * This example how to work with extendible datasets. The dataset
* must be chunked in order to be extendible.
- *
+ *
* It is used in the HDF5 Tutorial.
*/
-
#include "hdf5.h"
#define FILENAME "extend.h5"
#define DATASETNAME "ExtendibleArray"
-#define RANK 2
+#define RANK 2
int
-main (void)
+main(void)
{
- hid_t file; /* handles */
- hid_t dataspace, dataset;
- hid_t filespace, memspace;
- hid_t prop;
-
- hsize_t dims[2] = {3, 3}; /* dataset dimensions at creation time */
- hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED};
- herr_t status;
- hsize_t chunk_dims[2] = {2, 5};
- int data[3][3] = { {1, 1, 1}, /* data to write */
- {1, 1, 1},
- {1, 1, 1} };
+ hid_t file; /* handles */
+ hid_t dataspace, dataset;
+ hid_t filespace, memspace;
+ hid_t prop;
+
+ hsize_t dims[2] = {3, 3}; /* dataset dimensions at creation time */
+ hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED};
+ herr_t status;
+ hsize_t chunk_dims[2] = {2, 5};
+ int data[3][3] = {{1, 1, 1}, /* data to write */
+ {1, 1, 1},
+ {1, 1, 1}};
/* Variables used in extending and writing to the extended portion of dataset */
- hsize_t size[2];
- hsize_t offset[2];
- hsize_t dimsext[2] = {7, 3}; /* extend dimensions */
- int dataext[7][3] = { {2, 3, 4},
- {2, 3, 4},
- {2, 3, 4},
- {2, 3, 4},
- {2, 3, 4},
- {2, 3, 4},
- {2, 3, 4} };
+ hsize_t size[2];
+ hsize_t offset[2];
+ hsize_t dimsext[2] = {7, 3}; /* extend dimensions */
+ int dataext[7][3] = {{2, 3, 4}, {2, 3, 4}, {2, 3, 4}, {2, 3, 4}, {2, 3, 4}, {2, 3, 4}, {2, 3, 4}};
/* Variables used in reading data back */
- hsize_t chunk_dimsr[2];
- hsize_t dimsr[2];
- hsize_t i, j;
- int rdata[10][3];
- herr_t status_n;
- int rank, rank_chunk;
+ hsize_t chunk_dimsr[2];
+ hsize_t dimsr[2];
+ hsize_t i, j;
+ int rdata[10][3];
+ herr_t status_n;
+ int rank, rank_chunk;
/* Create the data space with unlimited dimensions. */
- dataspace = H5Screate_simple (RANK, dims, maxdims);
+ dataspace = H5Screate_simple(RANK, dims, maxdims);
/* Create a new file. If file exists its contents will be overwritten. */
- file = H5Fcreate (FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ file = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Modify dataset creation properties, i.e. enable chunking */
- prop = H5Pcreate (H5P_DATASET_CREATE);
- status = H5Pset_chunk (prop, RANK, chunk_dims);
+ prop = H5Pcreate(H5P_DATASET_CREATE);
+ status = H5Pset_chunk(prop, RANK, chunk_dims);
- /* Create a new dataset within the file using chunk
+ /* Create a new dataset within the file using chunk
creation properties. */
- dataset = H5Dcreate2 (file, DATASETNAME, H5T_NATIVE_INT, dataspace,
- H5P_DEFAULT, prop, H5P_DEFAULT);
+ dataset = H5Dcreate2(file, DATASETNAME, H5T_NATIVE_INT, dataspace, H5P_DEFAULT, prop, H5P_DEFAULT);
/* Write data to dataset */
- status = H5Dwrite (dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL,
- H5P_DEFAULT, data);
+ status = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
/* Extend the dataset. Dataset becomes 10 x 3 */
- size[0] = dims[0]+ dimsext[0];
+ size[0] = dims[0] + dimsext[0];
size[1] = dims[1];
- status = H5Dset_extent (dataset, size);
+ status = H5Dset_extent(dataset, size);
/* Select a hyperslab in extended portion of dataset */
- filespace = H5Dget_space (dataset);
+ filespace = H5Dget_space(dataset);
offset[0] = 3;
offset[1] = 0;
- status = H5Sselect_hyperslab (filespace, H5S_SELECT_SET, offset, NULL,
- dimsext, NULL);
+ status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL, dimsext, NULL);
/* Define memory space */
- memspace = H5Screate_simple (RANK, dimsext, NULL);
+ memspace = H5Screate_simple(RANK, dimsext, NULL);
/* Write the data to the extended portion of dataset */
- status = H5Dwrite (dataset, H5T_NATIVE_INT, memspace, filespace,
- H5P_DEFAULT, dataext);
+ status = H5Dwrite(dataset, H5T_NATIVE_INT, memspace, filespace, H5P_DEFAULT, dataext);
/* Close resources */
- status = H5Dclose (dataset);
- status = H5Pclose (prop);
- status = H5Sclose (dataspace);
- status = H5Sclose (memspace);
- status = H5Sclose (filespace);
- status = H5Fclose (file);
+ status = H5Dclose(dataset);
+ status = H5Pclose(prop);
+ status = H5Sclose(dataspace);
+ status = H5Sclose(memspace);
+ status = H5Sclose(filespace);
+ status = H5Fclose(file);
/********************************************
* Re-open the file and read the data back. *
********************************************/
- file = H5Fopen (FILENAME, H5F_ACC_RDONLY, H5P_DEFAULT);
- dataset = H5Dopen2 (file, DATASETNAME, H5P_DEFAULT);
+ file = H5Fopen(FILENAME, H5F_ACC_RDONLY, H5P_DEFAULT);
+ dataset = H5Dopen2(file, DATASETNAME, H5P_DEFAULT);
- filespace = H5Dget_space (dataset);
- rank = H5Sget_simple_extent_ndims (filespace);
- status_n = H5Sget_simple_extent_dims (filespace, dimsr, NULL);
+ filespace = H5Dget_space(dataset);
+ rank = H5Sget_simple_extent_ndims(filespace);
+ status_n = H5Sget_simple_extent_dims(filespace, dimsr, NULL);
- prop = H5Dget_create_plist (dataset);
+ prop = H5Dget_create_plist(dataset);
- if (H5D_CHUNKED == H5Pget_layout (prop))
- rank_chunk = H5Pget_chunk (prop, rank, chunk_dimsr);
+ if (H5D_CHUNKED == H5Pget_layout(prop))
+ rank_chunk = H5Pget_chunk(prop, rank, chunk_dimsr);
- memspace = H5Screate_simple (rank, dimsr, NULL);
- status = H5Dread (dataset, H5T_NATIVE_INT, memspace, filespace,
- H5P_DEFAULT, rdata);
+ memspace = H5Screate_simple(rank, dimsr, NULL);
+ status = H5Dread(dataset, H5T_NATIVE_INT, memspace, filespace, H5P_DEFAULT, rdata);
printf("\n");
printf("Dataset: \n");
- for (j = 0; j < dimsr[0]; j++)
- {
- for (i = 0; i < dimsr[1]; i++)
- printf("%d ", rdata[j][i]);
- printf("\n");
+ for (j = 0; j < dimsr[0]; j++) {
+ for (i = 0; i < dimsr[1]; i++)
+ printf("%d ", rdata[j][i]);
+ printf("\n");
}
- status = H5Pclose (prop);
- status = H5Dclose (dataset);
- status = H5Sclose (filespace);
- status = H5Sclose (memspace);
- status = H5Fclose (file);
+ status = H5Pclose(prop);
+ status = H5Dclose(dataset);
+ status = H5Sclose(filespace);
+ status = H5Sclose(memspace);
+ status = H5Fclose(file);
}
diff --git a/examples/h5_extend_write.c b/examples/h5_extend_write.c
index 4abda30..f5db1cf 100644
--- a/examples/h5_extend_write.c
+++ b/examples/h5_extend_write.c
@@ -6,7 +6,7 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -20,43 +20,42 @@
#include "hdf5.h"
-#define H5FILE_NAME "SDSextendible.h5"
+#define H5FILE_NAME "SDSextendible.h5"
#define DATASETNAME "ExtendibleArray"
-#define RANK 2
-#define NX 10
-#define NY 5
+#define RANK 2
+#define NX 10
+#define NY 5
int
-main (void)
+main(void)
{
- hid_t file; /* handles */
- hid_t dataspace, dataset;
- hid_t filespace;
- hid_t cparms;
- hsize_t dims[2] = { 3, 3}; /*
- * dataset dimensions
- * at the creation time
- */
- hsize_t dims1[2] = { 3, 3}; /* data1 dimensions */
- hsize_t dims2[2] = { 7, 1}; /* data2 dimensions */
- hsize_t dims3[2] = { 2, 2}; /* data3 dimensions */
+ hid_t file; /* handles */
+ hid_t dataspace, dataset;
+ hid_t filespace;
+ hid_t cparms;
+ hsize_t dims[2] = {3, 3}; /*
+ * dataset dimensions
+ * at the creation time
+ */
+ hsize_t dims1[2] = {3, 3}; /* data1 dimensions */
+ hsize_t dims2[2] = {7, 1}; /* data2 dimensions */
+ hsize_t dims3[2] = {2, 2}; /* data3 dimensions */
- hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED};
- hsize_t chunk_dims[2] ={2, 5};
- hsize_t size[2];
- hsize_t offset[2];
+ hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED};
+ hsize_t chunk_dims[2] = {2, 5};
+ hsize_t size[2];
+ hsize_t offset[2];
- herr_t status;
+ herr_t status;
- int data1[3][3] = { {1, 1, 1}, /* data to write */
- {1, 1, 1},
- {1, 1, 1} };
+ int data1[3][3] = {{1, 1, 1}, /* data to write */
+ {1, 1, 1},
+ {1, 1, 1}};
- int data2[7] = { 2, 2, 2, 2, 2, 2, 2};
+ int data2[7] = {2, 2, 2, 2, 2, 2, 2};
- int data3[2][2] = { {3, 3},
- {3, 3} };
- int fillvalue = 0;
+ int data3[2][2] = {{3, 3}, {3, 3}};
+ int fillvalue = 0;
/*
* Create the data space with unlimited dimensions.
@@ -72,22 +71,21 @@ main (void)
* Modify dataset creation properties, i.e. enable chunking.
*/
cparms = H5Pcreate(H5P_DATASET_CREATE);
- status = H5Pset_chunk( cparms, RANK, chunk_dims);
- status = H5Pset_fill_value (cparms, H5T_NATIVE_INT, &fillvalue );
+ status = H5Pset_chunk(cparms, RANK, chunk_dims);
+ status = H5Pset_fill_value(cparms, H5T_NATIVE_INT, &fillvalue);
/*
* Create a new dataset within the file using cparms
* creation properties.
*/
- dataset = H5Dcreate2(file, DATASETNAME, H5T_NATIVE_INT, dataspace, H5P_DEFAULT,
- cparms, H5P_DEFAULT);
+ dataset = H5Dcreate2(file, DATASETNAME, H5T_NATIVE_INT, dataspace, H5P_DEFAULT, cparms, H5P_DEFAULT);
/*
* Extend the dataset. This call assures that dataset is at least 3 x 3.
*/
- size[0] = 3;
- size[1] = 3;
- status = H5Dset_extent(dataset, size);
+ size[0] = 3;
+ size[1] = 3;
+ status = H5Dset_extent(dataset, size);
/*
* Select a hyperslab.
@@ -95,22 +93,20 @@ main (void)
filespace = H5Dget_space(dataset);
offset[0] = 0;
offset[1] = 0;
- status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL,
- dims1, NULL);
+ status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL, dims1, NULL);
/*
* Write the data to the hyperslab.
*/
- status = H5Dwrite(dataset, H5T_NATIVE_INT, dataspace, filespace,
- H5P_DEFAULT, data1);
+ status = H5Dwrite(dataset, H5T_NATIVE_INT, dataspace, filespace, H5P_DEFAULT, data1);
/*
* Extend the dataset. Dataset becomes 10 x 3.
*/
- dims[0] = dims1[0] + dims2[0];
- size[0] = dims[0];
- size[1] = dims[1];
- status = H5Dset_extent(dataset, size);
+ dims[0] = dims1[0] + dims2[0];
+ size[0] = dims[0];
+ size[1] = dims[1];
+ status = H5Dset_extent(dataset, size);
/*
* Select a hyperslab.
@@ -118,8 +114,7 @@ main (void)
filespace = H5Dget_space(dataset);
offset[0] = 3;
offset[1] = 0;
- status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL,
- dims2, NULL);
+ status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL, dims2, NULL);
/*
* Define memory space
@@ -129,16 +124,15 @@ main (void)
/*
* Write the data to the hyperslab.
*/
- status = H5Dwrite(dataset, H5T_NATIVE_INT, dataspace, filespace,
- H5P_DEFAULT, data2);
+ status = H5Dwrite(dataset, H5T_NATIVE_INT, dataspace, filespace, H5P_DEFAULT, data2);
/*
* Extend the dataset. Dataset becomes 10 x 5.
*/
- dims[1] = dims1[1] + dims3[1];
- size[0] = dims[0];
- size[1] = dims[1];
- status = H5Dset_extent(dataset, size);
+ dims[1] = dims1[1] + dims3[1];
+ size[0] = dims[0];
+ size[1] = dims[1];
+ status = H5Dset_extent(dataset, size);
/*
* Select a hyperslab
@@ -146,8 +140,7 @@ main (void)
filespace = H5Dget_space(dataset);
offset[0] = 0;
offset[1] = 3;
- status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL,
- dims3, NULL);
+ status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL, dims3, NULL);
/*
* Define memory space.
@@ -157,8 +150,7 @@ main (void)
/*
* Write the data to the hyperslab.
*/
- status = H5Dwrite(dataset, H5T_NATIVE_INT, dataspace, filespace,
- H5P_DEFAULT, data3);
+ status = H5Dwrite(dataset, H5T_NATIVE_INT, dataspace, filespace, H5P_DEFAULT, data3);
/*
* Resulting dataset
diff --git a/examples/h5_extlink.c b/examples/h5_extlink.c
index 229e465..61fd589 100644
--- a/examples/h5_extlink.c
+++ b/examples/h5_extlink.c
@@ -6,7 +6,7 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -26,37 +26,36 @@
#define PREFIX_SOURCE_FILE "extlink_prefix_source.h5"
-#define SOFT_LINK_FILE "soft_link.h5"
-#define SOFT_LINK_NAME "soft_link_to_group"
+#define SOFT_LINK_FILE "soft_link.h5"
+#define SOFT_LINK_NAME "soft_link_to_group"
#define UD_SOFT_LINK_NAME "ud_soft_link"
-#define TARGET_GROUP "target_group"
+#define TARGET_GROUP "target_group"
#define UD_SOFT_CLASS 65
-#define HARD_LINK_FILE "hard_link.h5"
-#define HARD_LINK_NAME "hard_link_to_group"
+#define HARD_LINK_FILE "hard_link.h5"
+#define HARD_LINK_NAME "hard_link_to_group"
#define UD_HARD_LINK_NAME "ud_hard_link"
#define UD_HARD_CLASS 66
#define PLIST_LINK_PROP "plist_link_prop"
-#define UD_PLIST_CLASS 66
+#define UD_PLIST_CLASS 66
-
-
/* Basic external link example
*
* Creates two files and uses an external link to access an object in the
* second file from the first file.
*/
-static void extlink_example(void)
+static void
+extlink_example(void)
{
hid_t source_file_id, targ_file_id;
hid_t group_id, group2_id;
/* Create two files, a source and a target */
source_file_id = H5Fcreate(SOURCE_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
- targ_file_id = H5Fcreate(TARGET_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ targ_file_id = H5Fcreate(TARGET_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create a group in the target file for the external link to point to. */
group_id = H5Gcreate2(targ_file_id, "target_group", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
@@ -96,7 +95,6 @@ static void extlink_example(void)
*/
}
-
/* External link prefix example
*
* Uses a group access property list to set a "prefix" for the filenames
@@ -109,7 +107,8 @@ static void extlink_example(void)
* where it is run (so to run this example on Unix, first mkdir red and mkdir
* blue).
*/
-static void extlink_prefix_example(void)
+static void
+extlink_prefix_example(void)
{
hid_t source_file_id, red_file_id, blue_file_id;
hid_t group_id, group2_id;
@@ -119,14 +118,15 @@ static void extlink_prefix_example(void)
* the same name, but one will be located in the red directory and one will
* be located in the blue directory */
source_file_id = H5Fcreate(PREFIX_SOURCE_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
- red_file_id = H5Fcreate("red/prefix_target.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
- blue_file_id = H5Fcreate("blue/prefix_target.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ red_file_id = H5Fcreate("red/prefix_target.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ blue_file_id = H5Fcreate("blue/prefix_target.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* This test needs a red and a blue directory in the filesystem. If they're not present,
* trying to create the files above will fail.
*/
- if(red_file_id < 0 || blue_file_id < 0)
- printf("This test requires directories named 'red' and 'blue' to exist. Did you forget to create them?\n");
+ if (red_file_id < 0 || blue_file_id < 0)
+ printf("This test requires directories named 'red' and 'blue' to exist. Did you forget to create "
+ "them?\n");
/* Create an external link in the source file pointing to the root group of
* a file named prefix_target.h5. This file doesn't exist in the current
@@ -163,7 +163,7 @@ static void extlink_prefix_example(void)
* directory.
*/
H5Pset_elink_prefix(gapl_id, "blue/");
- group_id = H5Gopen2(source_file_id, "ext_link", gapl_id);
+ group_id = H5Gopen2(source_file_id, "ext_link", gapl_id);
group2_id = H5Gcreate2(group_id, "sky blue", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/* Close both groups. */
@@ -171,7 +171,7 @@ static void extlink_prefix_example(void)
H5Gclose(group_id);
/* Each file has had a group created inside it using the same external link. */
- group_id = H5Gopen2(red_file_id, "pink", H5P_DEFAULT);
+ group_id = H5Gopen2(red_file_id, "pink", H5P_DEFAULT);
group2_id = H5Gopen2(blue_file_id, "sky blue", H5P_DEFAULT);
/* Clean up our open IDs */
@@ -189,7 +189,6 @@ static void extlink_prefix_example(void)
*/
}
-
/* Soft Link example
*
* Create a new class of user-defined links that behave like HDF5's built-in
@@ -207,10 +206,11 @@ static void extlink_prefix_example(void)
* We might also have wanted to supply a creation callback that checks
* that a path was supplied in the udata.
*/
-static hid_t UD_soft_traverse(const char *link_name, hid_t cur_group,
- const void *udata, size_t udata_size, hid_t lapl_id, hid_t dxpl_id);
+static hid_t UD_soft_traverse(const char *link_name, hid_t cur_group, const void *udata, size_t udata_size,
+ hid_t lapl_id, hid_t dxpl_id);
-static void soft_link_example(void)
+static void
+soft_link_example(void)
{
hid_t file_id;
hid_t group_id;
@@ -220,27 +220,26 @@ static void soft_link_example(void)
* callback.
*/
const H5L_class_t UD_soft_class[1] = {{
- H5L_LINK_CLASS_T_VERS, /* Version number for this struct.
- * This field is always H5L_LINK_CLASS_T_VERS */
- (H5L_type_t)UD_SOFT_CLASS, /* Link class id number. This can be any
- * value between H5L_TYPE_UD_MIN (64) and
- * H5L_TYPE_MAX (255). It should be a
- * value that isn't already being used by
- * another kind of link. We'll use 65. */
- "UD_soft_link", /* Link class name for debugging */
- NULL, /* Creation callback */
- NULL, /* Move callback */
- NULL, /* Copy callback */
- UD_soft_traverse, /* The actual traversal function */
- NULL, /* Deletion callback */
- NULL /* Query callback */
+ H5L_LINK_CLASS_T_VERS, /* Version number for this struct.
+ * This field is always H5L_LINK_CLASS_T_VERS */
+ (H5L_type_t)UD_SOFT_CLASS, /* Link class id number. This can be any
+ * value between H5L_TYPE_UD_MIN (64) and
+ * H5L_TYPE_MAX (255). It should be a
+ * value that isn't already being used by
+ * another kind of link. We'll use 65. */
+ "UD_soft_link", /* Link class name for debugging */
+ NULL, /* Creation callback */
+ NULL, /* Move callback */
+ NULL, /* Copy callback */
+ UD_soft_traverse, /* The actual traversal function */
+ NULL, /* Deletion callback */
+ NULL /* Query callback */
}};
-
/* First, create a file and an object within the file for the link to
* point to.
*/
- file_id = H5Fcreate(SOFT_LINK_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ file_id = H5Fcreate(SOFT_LINK_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
group_id = H5Gcreate2(file_id, TARGET_GROUP, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Gclose(group_id);
@@ -275,12 +274,13 @@ static void soft_link_example(void)
* The actual traversal function simply needs to open the correct object by
* name and return its ID.
*/
-
-static hid_t UD_soft_traverse(const char *link_name, hid_t cur_group,
- const void *udata, size_t udata_size, hid_t lapl_id, hid_t dxpl_id)
+
+static hid_t
+UD_soft_traverse(const char *link_name, hid_t cur_group, const void *udata, size_t udata_size, hid_t lapl_id,
+ hid_t dxpl_id)
{
- const char *target = (const char *) udata;
- hid_t ret_value;
+ const char *target = (const char *)udata;
+ hid_t ret_value;
/* Pass the udata straight through to HDF5. If it's invalid, let HDF5
* return an error.
@@ -289,7 +289,6 @@ static hid_t UD_soft_traverse(const char *link_name, hid_t cur_group,
return ret_value;
}
-
/* Hard Link example
*
* Create a new class of user-defined links that behave like HDF5's built-in
@@ -305,45 +304,44 @@ static hid_t UD_soft_traverse(const char *link_name, hid_t cur_group,
* To keep the example simple, these links don't have a query callback.
* Generally, real link classes should always be query-able.
*/
-static herr_t UD_hard_create(const char *link_name, hid_t loc_group,
- const void *udata, size_t udata_size, hid_t lcpl_id);
-static herr_t UD_hard_delete(const char *link_name, hid_t loc_group,
- const void *udata, size_t udata_size);
-static hid_t UD_hard_traverse(const char *link_name, hid_t cur_group,
- const void *udata, size_t udata_size, hid_t lapl_id, hid_t dxpl_id);
-
-static void hard_link_example(void)
+static herr_t UD_hard_create(const char *link_name, hid_t loc_group, const void *udata, size_t udata_size,
+ hid_t lcpl_id);
+static herr_t UD_hard_delete(const char *link_name, hid_t loc_group, const void *udata, size_t udata_size);
+static hid_t UD_hard_traverse(const char *link_name, hid_t cur_group, const void *udata, size_t udata_size,
+ hid_t lapl_id, hid_t dxpl_id);
+
+static void
+hard_link_example(void)
{
- hid_t file_id;
- hid_t group_id;
- H5L_info_t li;
+ hid_t file_id;
+ hid_t group_id;
+ H5L_info2_t li;
/* Define the link class that we'll use to register "user-defined hard
* links" using the callbacks we defined above.
* A link class can have NULL for any callback except its traverse
* callback.
*/
const H5L_class_t UD_hard_class[1] = {{
- H5L_LINK_CLASS_T_VERS, /* Version number for this struct.
- * This field is always H5L_LINK_CLASS_T_VERS */
- (H5L_type_t)UD_HARD_CLASS, /* Link class id number. This can be any
- * value between H5L_TYPE_UD_MIN (64) and
- * H5L_TYPE_MAX (255). It should be a
- * value that isn't already being used by
- * another kind of link. We'll use 66. */
- "UD_hard_link", /* Link class name for debugging */
- UD_hard_create, /* Creation callback */
- NULL, /* Move callback */
- NULL, /* Copy callback */
- UD_hard_traverse, /* The actual traversal function */
- UD_hard_delete, /* Deletion callback */
- NULL /* Query callback */
+ H5L_LINK_CLASS_T_VERS, /* Version number for this struct.
+ * This field is always H5L_LINK_CLASS_T_VERS */
+ (H5L_type_t)UD_HARD_CLASS, /* Link class id number. This can be any
+ * value between H5L_TYPE_UD_MIN (64) and
+ * H5L_TYPE_MAX (255). It should be a
+ * value that isn't already being used by
+ * another kind of link. We'll use 66. */
+ "UD_hard_link", /* Link class name for debugging */
+ UD_hard_create, /* Creation callback */
+ NULL, /* Move callback */
+ NULL, /* Copy callback */
+ UD_hard_traverse, /* The actual traversal function */
+ UD_hard_delete, /* Deletion callback */
+ NULL /* Query callback */
}};
-
/* First, create a file and an object within the file for the link to
* point to.
*/
- file_id = H5Fcreate(HARD_LINK_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ file_id = H5Fcreate(HARD_LINK_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
group_id = H5Gcreate2(file_id, TARGET_GROUP, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Gclose(group_id);
@@ -361,13 +359,13 @@ static void hard_link_example(void)
* the target group's address. We do this by calling H5Lget_info
* on a hard link to the object.
*/
- H5Lget_info(file_id, TARGET_GROUP, &li, H5P_DEFAULT);
+ H5Lget_info2(file_id, TARGET_GROUP, &li, H5P_DEFAULT);
/* Now create a user-defined link. We give it the group's address
* as its udata.
*/
- H5Lcreate_ud(file_id, UD_HARD_LINK_NAME, (H5L_type_t)UD_HARD_CLASS, &(li.u.address),
- sizeof(li.u.address), H5P_DEFAULT, H5P_DEFAULT);
+ H5Lcreate_ud(file_id, UD_HARD_LINK_NAME, (H5L_type_t)UD_HARD_CLASS, &(li.u.token), sizeof(H5O_token_t),
+ H5P_DEFAULT, H5P_DEFAULT);
/* The UD hard link has now incremented the group's reference count
* like a normal hard link would. This means that we can unlink the
@@ -401,42 +399,44 @@ static void hard_link_example(void)
* If this function returns a negative value, the call to H5Lcreate_ud()
* will also return failure and the link will not be created.
*/
-static herr_t UD_hard_create(const char *link_name, hid_t loc_group,
- const void *udata, size_t udata_size, hid_t lcpl_id)
+static herr_t
+UD_hard_create(const char *link_name, hid_t loc_group, const void *udata, size_t udata_size, hid_t lcpl_id)
{
- haddr_t addr;
- hid_t target_obj = -1;
- herr_t ret_value = 0;
+ H5O_token_t token;
+ hid_t target_obj = H5I_INVALID_HID;
+ herr_t ret_value = 0;
/* Make sure that the address passed in looks valid */
- if(udata_size != sizeof(haddr_t))
- {
- ret_value = -1;
- goto done;
+ if (udata_size != sizeof(H5O_token_t)) {
+ ret_value = -1;
+ goto done;
}
- addr = *((const haddr_t *) udata);
+ token = *((H5O_token_t *)udata);
+
+ //! [H5Oopen_by_token_snip]
/* Open the object this link points to so that we can increment
- * its reference count. This also ensures that the address passed
+ * its reference count. This also ensures that the token passed
* in points to a real object (although this check is not perfect!) */
- target_obj= H5Oopen_by_addr(loc_group, addr);
- if(target_obj < 0)
- {
- ret_value = -1;
- goto done;
+ target_obj = H5Oopen_by_token(loc_group, token);
+
+ //! [H5Oopen_by_token_snip]
+
+ if (target_obj < 0) {
+ ret_value = -1;
+ goto done;
}
/* Increment the reference count of the target object */
- if(H5Oincr_refcount(target_obj) < 0)
- {
- ret_value = -1;
- goto done;
+ if (H5Oincr_refcount(target_obj) < 0) {
+ ret_value = -1;
+ goto done;
}
done:
/* Close the target object if we opened it */
- if(target_obj >= 0)
+ if (target_obj >= 0)
H5Oclose(target_obj);
return ret_value;
}
@@ -445,42 +445,39 @@ done:
* Since the creation function increments the object's reference count, it's
* important to decrement it again when the link is deleted.
*/
-static herr_t UD_hard_delete(const char *link_name, hid_t loc_group,
- const void *udata, size_t udata_size)
+static herr_t
+UD_hard_delete(const char *link_name, hid_t loc_group, const void *udata, size_t udata_size)
{
- haddr_t addr;
- hid_t target_obj = -1;
- herr_t ret_value = 0;
+ H5O_token_t token;
+ hid_t target_obj = H5I_INVALID_HID;
+ herr_t ret_value = 0;
/* Sanity check; we have already verified the udata's size in the creation
* callback.
*/
- if(udata_size != sizeof(haddr_t))
- {
- ret_value = -1;
- goto done;
+ if (udata_size != sizeof(H5O_token_t)) {
+ ret_value = -1;
+ goto done;
}
- addr = *((const haddr_t *) udata);
+ token = *((H5O_token_t *)udata);
/* Open the object this link points to */
- target_obj= H5Oopen_by_addr(loc_group, addr);
- if(target_obj < 0)
- {
- ret_value = -1;
- goto done;
+ target_obj = H5Oopen_by_token(loc_group, token);
+ if (target_obj < 0) {
+ ret_value = -1;
+ goto done;
}
/* Decrement the reference count of the target object */
- if(H5Odecr_refcount(target_obj) < 0)
- {
- ret_value = -1;
- goto done;
+ if (H5Odecr_refcount(target_obj) < 0) {
+ ret_value = -1;
+ goto done;
}
done:
/* Close the target object if we opened it */
- if(target_obj >= 0)
+ if (target_obj >= 0)
H5Oclose(target_obj);
return ret_value;
}
@@ -489,30 +486,29 @@ done:
* The actual traversal function simply needs to open the correct object and
* return its ID.
*/
-static hid_t UD_hard_traverse(const char *link_name, hid_t cur_group,
- const void *udata, size_t udata_size, hid_t lapl_id, hid_t dxpl_id)
+static hid_t
+UD_hard_traverse(const char *link_name, hid_t cur_group, const void *udata, size_t udata_size, hid_t lapl_id,
+ hid_t dxpl_id)
{
- haddr_t addr;
- hid_t ret_value = -1;
+ H5O_token_t token;
+ hid_t ret_value = H5I_INVALID_HID;
/* Sanity check; we have already verified the udata's size in the creation
* callback.
*/
- if(udata_size != sizeof(haddr_t))
- return -1;
+ if (udata_size != sizeof(H5O_token_t))
+ return H5I_INVALID_HID;
- addr = *((const haddr_t *) udata);
+ token = *((H5O_token_t *)udata);
- /* Open the object by address. If H5Oopen_by_addr fails, ret_value will
+ /* Open the object by token. If H5Oopen_by_token fails, ret_value will
* be negative to indicate that the traversal function failed.
*/
- ret_value = H5Oopen_by_addr(cur_group, addr);
+ ret_value = H5Oopen_by_token(cur_group, token);
return ret_value;
}
-
-
/* Plist example
*
* Create a new class of user-defined links that open objects within a file
@@ -526,10 +522,11 @@ static hid_t UD_hard_traverse(const char *link_name, hid_t cur_group,
* These are defined after the example below.
* These links have no udata, so they don't need a query function.
*/
-static hid_t UD_plist_traverse(const char *link_name, hid_t cur_group,
- const void *udata, size_t udata_size, hid_t lapl_id, hid_t dxpl_id);
+static hid_t UD_plist_traverse(const char *link_name, hid_t cur_group, const void *udata, size_t udata_size,
+ hid_t lapl_id, hid_t dxpl_id);
-static void plist_link_example(void)
+static void
+plist_link_example(void)
{
hid_t file_id;
hid_t group_id, group2_id;
@@ -558,11 +555,10 @@ static void plist_link_example(void)
NULL /* Query callback */
}};
-
/* First, create a file and two objects within the file for the link to
* point to.
*/
- file_id = H5Fcreate(HARD_LINK_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ file_id = H5Fcreate(HARD_LINK_FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
group_id = H5Gcreate2(file_id, "group_1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
H5Gclose(group_id);
group_id = H5Gcreate2(file_id, "group_1/group_2", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
@@ -570,8 +566,7 @@ static void plist_link_example(void)
/* Register "plist links" and create one. It has no udata at all. */
H5Lregister(UD_plist_class);
- H5Lcreate_ud(file_id, "plist_link", (H5L_type_t)UD_PLIST_CLASS, NULL, 0,
- H5P_DEFAULT, H5P_DEFAULT);
+ H5Lcreate_ud(file_id, "plist_link", (H5L_type_t)UD_PLIST_CLASS, NULL, 0, H5P_DEFAULT, H5P_DEFAULT);
/* Create a group access property list to pass in the target for the
* plist link.
@@ -617,17 +612,18 @@ static void plist_link_example(void)
/* UD_plist_traverse
* Open a path passed in through the property list.
*/
-static hid_t UD_plist_traverse(const char *link_name, hid_t cur_group,
- const void *udata, size_t udata_size, hid_t lapl_id, hid_t dxpl_id)
+static hid_t
+UD_plist_traverse(const char *link_name, hid_t cur_group, const void *udata, size_t udata_size, hid_t lapl_id,
+ hid_t dxpl_id)
{
- char * path;
- hid_t ret_value = -1;
+ char *path;
+ hid_t ret_value = H5I_INVALID_HID;
/* If the link property isn't set or can't be found, traversal fails. */
- if(H5Pexist(lapl_id, PLIST_LINK_PROP) < 0)
+ if (H5Pexist(lapl_id, PLIST_LINK_PROP) < 0)
goto error;
- if(H5Pget(lapl_id, PLIST_LINK_PROP, &path) < 0)
+ if (H5Pget(lapl_id, PLIST_LINK_PROP, &path) < 0)
goto error;
/* Open the object by address. If H5Oopen_by_addr fails, ret_value will
@@ -638,16 +634,14 @@ static hid_t UD_plist_traverse(const char *link_name, hid_t cur_group,
return ret_value;
error:
- return -1;
+ return H5I_INVALID_HID;
}
-
-
/* Main function
*
* Invokes the example functions.
*/
- int
+int
main(void)
{
printf("Testing basic external links.\n");
@@ -667,5 +661,3 @@ main(void)
return 0;
}
-
-
diff --git a/examples/h5_group.c b/examples/h5_group.c
index 8e89165..40acafe 100644
--- a/examples/h5_group.c
+++ b/examples/h5_group.c
@@ -6,7 +6,7 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -19,31 +19,29 @@
* in the root group and in the created group.
*/
-
#include "hdf5.h"
+#define H5FILE_NAME "group.h5"
+#define RANK 2
-#define H5FILE_NAME "group.h5"
-#define RANK 2
-
-static herr_t file_info(hid_t loc_id, const char *name, const H5L_info_t *linfo,
- void *opdata); /* Link iteration operator function */
-static herr_t group_info(hid_t loc_id, const char *name, const H5L_info_t *linfo,
- void *opdata); /* Link iteration operator function */
+static herr_t file_info(hid_t loc_id, const char *name, const H5L_info2_t *linfo,
+ void *opdata); /* Link iteration operator function */
+static herr_t group_info(hid_t loc_id, const char *name, const H5L_info2_t *linfo,
+ void *opdata); /* Link iteration operator function */
int
main(void)
{
- hid_t file;
- hid_t grp;
- hid_t dataset, dataspace;
- hid_t plist;
+ hid_t file;
+ hid_t grp;
+ hid_t dataset, dataspace;
+ hid_t plist;
- herr_t status;
- hsize_t dims[2];
- hsize_t cdims[2];
+ herr_t status;
+ hsize_t dims[2];
+ hsize_t cdims[2];
- int idx_f, idx_g;
+ int idx_f, idx_g;
/*
* Create a file.
@@ -61,16 +59,16 @@ main(void)
* GZIP compression with the compression effort set to 6.
* Note that compression can be used only when dataset is chunked.
*/
- dims[0] = 1000;
- dims[1] = 20;
- cdims[0] = 20;
- cdims[1] = 20;
+ dims[0] = 1000;
+ dims[1] = 20;
+ cdims[0] = 20;
+ cdims[1] = 20;
dataspace = H5Screate_simple(RANK, dims, NULL);
plist = H5Pcreate(H5P_DATASET_CREATE);
- H5Pset_chunk(plist, 2, cdims);
- H5Pset_deflate( plist, 6);
- dataset = H5Dcreate2(file, "/Data/Compressed_Data", H5T_NATIVE_INT,
- dataspace, H5P_DEFAULT, plist, H5P_DEFAULT);
+ H5Pset_chunk(plist, 2, cdims);
+ H5Pset_deflate(plist, 6);
+ dataset =
+ H5Dcreate2(file, "/Data/Compressed_Data", H5T_NATIVE_INT, dataspace, H5P_DEFAULT, plist, H5P_DEFAULT);
/*
* Close the first dataset .
*/
@@ -80,11 +78,11 @@ main(void)
/*
* Create the second dataset.
*/
- dims[0] = 500;
- dims[1] = 20;
+ dims[0] = 500;
+ dims[1] = 20;
dataspace = H5Screate_simple(RANK, dims, NULL);
- dataset = H5Dcreate2(file, "/Data/Float_Data", H5T_NATIVE_FLOAT,
- dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ dataset = H5Dcreate2(file, "/Data/Float_Data", H5T_NATIVE_FLOAT, dataspace, H5P_DEFAULT, H5P_DEFAULT,
+ H5P_DEFAULT);
/*
*Close the second dataset and file.
@@ -105,7 +103,8 @@ main(void)
* Access "Compressed_Data" dataset in the group.
*/
dataset = H5Dopen2(grp, "Compressed_Data", H5P_DEFAULT);
- if( dataset < 0) printf(" Dataset 'Compressed-Data' is not found. \n");
+ if (dataset < 0)
+ printf(" Dataset 'Compressed-Data' is not found. \n");
printf("\"/Data/Compressed_Data\" dataset is open \n");
/*
@@ -123,7 +122,8 @@ main(void)
* hard link "Data_new".
*/
dataset = H5Dopen2(file, "/Data_new/Compressed_Data", H5P_DEFAULT);
- if( dataset < 0) printf(" Dataset is not found. \n");
+ if (dataset < 0)
+ printf(" Dataset is not found. \n");
printf("\"/Data_new/Compressed_Data\" dataset is open \n");
/*
@@ -131,28 +131,28 @@ main(void)
*/
status = H5Dclose(dataset);
-
/*
* Use iterator to see the names of the objects in the root group.
*/
- idx_f = H5Literate(file, H5_INDEX_NAME, H5_ITER_INC, NULL, file_info, NULL);
+ idx_f = H5Literate2(file, H5_INDEX_NAME, H5_ITER_INC, NULL, file_info, NULL);
/*
* Unlink name "Data" and use iterator to see the names
* of the objects in the file root direvtory.
*/
- if(H5Ldelete(file, "Data", H5P_DEFAULT) < 0)
- printf(" H5Ldelete failed \n");
+ if (H5Ldelete(file, "Data", H5P_DEFAULT) < 0)
+ printf(" H5Ldelete failed \n");
else
- printf("\"Data\" is unlinked \n");
+ printf("\"Data\" is unlinked \n");
- idx_f = H5Literate(file, H5_INDEX_NAME, H5_ITER_INC, NULL, file_info, NULL);
+ idx_f = H5Literate2(file, H5_INDEX_NAME, H5_ITER_INC, NULL, file_info, NULL);
/*
* Use iterator to see the names of the objects in the group
* /Data_new.
*/
- idx_g = H5Literate_by_name(grp, "/Data_new", H5_INDEX_NAME, H5_ITER_INC, NULL, group_info, NULL, H5P_DEFAULT);
+ idx_g = H5Literate_by_name2(grp, "/Data_new", H5_INDEX_NAME, H5_ITER_INC, NULL, group_info, NULL,
+ H5P_DEFAULT);
/*
* Close the file.
@@ -168,12 +168,12 @@ main(void)
* Operator function.
*/
static herr_t
-file_info(hid_t loc_id, const char *name, const H5L_info_t *linfo, void *opdata)
+file_info(hid_t loc_id, const char *name, const H5L_info2_t *linfo, void *opdata)
{
/* avoid compiler warnings */
- loc_id = loc_id;
- opdata = opdata;
- linfo = linfo;
+ (void)loc_id;
+ (void)opdata;
+ (void)linfo;
/*
* Display group name. The name is passed to the function by
@@ -184,23 +184,22 @@ file_info(hid_t loc_id, const char *name, const H5L_info_t *linfo, void *opdata)
return 0;
}
-
/*
* Operator function.
*/
static herr_t
-group_info(hid_t loc_id, const char *name, const H5L_info_t *linfo, void *opdata)
+group_info(hid_t loc_id, const char *name, const H5L_info2_t *linfo, void *opdata)
{
- hid_t did; /* dataset identifier */
- hid_t tid; /* datatype identifier */
+ hid_t did; /* dataset identifier */
+ hid_t tid; /* datatype identifier */
H5T_class_t t_class;
- hid_t pid; /* data_property identifier */
- hsize_t chunk_dims_out[2];
- int rank_chunk;
+ hid_t pid; /* data_property identifier */
+ hsize_t chunk_dims_out[2];
+ int rank_chunk;
/* avoid warnings */
- opdata = opdata;
- linfo = linfo;
+ (void)opdata;
+ (void)linfo;
/*
* Open the datasets using their names.
@@ -215,38 +214,37 @@ group_info(hid_t loc_id, const char *name, const H5L_info_t *linfo, void *opdata
/*
* Display dataset information.
*/
- tid = H5Dget_type(did); /* get datatype*/
+ tid = H5Dget_type(did); /* get datatype*/
pid = H5Dget_create_plist(did); /* get creation property list */
/*
* Check if dataset is chunked.
*/
- if(H5D_CHUNKED == H5Pget_layout(pid)) {
+ if (H5D_CHUNKED == H5Pget_layout(pid)) {
/*
* get chunking information: rank and dimensions.
*/
rank_chunk = H5Pget_chunk(pid, 2, chunk_dims_out);
- printf("chunk rank %d, dimensions %lu x %lu\n", rank_chunk,
- (unsigned long)(chunk_dims_out[0]),
- (unsigned long)(chunk_dims_out[1]));
+ printf("chunk rank %d, dimensions %lu x %lu\n", rank_chunk, (unsigned long)(chunk_dims_out[0]),
+ (unsigned long)(chunk_dims_out[1]));
}
else {
t_class = H5Tget_class(tid);
- if(t_class < 0) {
+ if (t_class < 0) {
puts(" Invalid datatype.\n");
}
else {
- if(t_class == H5T_INTEGER)
+ if (t_class == H5T_INTEGER)
puts(" Datatype is 'H5T_NATIVE_INTEGER'.\n");
- if(t_class == H5T_FLOAT)
+ if (t_class == H5T_FLOAT)
puts(" Datatype is 'H5T_NATIVE_FLOAT'.\n");
- if(t_class == H5T_STRING)
+ if (t_class == H5T_STRING)
puts(" Datatype is 'H5T_NATIVE_STRING'.\n");
- if(t_class == H5T_BITFIELD)
+ if (t_class == H5T_BITFIELD)
puts(" Datatype is 'H5T_NATIVE_BITFIELD'.\n");
- if(t_class == H5T_OPAQUE)
+ if (t_class == H5T_OPAQUE)
puts(" Datatype is 'H5T_NATIVE_OPAQUE'.\n");
- if(t_class == H5T_COMPOUND)
+ if (t_class == H5T_COMPOUND)
puts(" Datatype is 'H5T_NATIVE_COMPOUND'.\n");
}
}
@@ -256,4 +254,3 @@ group_info(hid_t loc_id, const char *name, const H5L_info_t *linfo, void *opdata
H5Tclose(tid);
return 0;
}
-
diff --git a/examples/h5_interm_group.c b/examples/h5_interm_group.c
index 6507fd1..c2cafa6 100644
--- a/examples/h5_interm_group.c
+++ b/examples/h5_interm_group.c
@@ -6,7 +6,7 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -16,27 +16,24 @@
* all intermediate groups.
*/
-
#include "hdf5.h"
-
-#define H5FILE_NAME "interm_group.h5"
-#define TRUE 1
-#define FALSE 0
+#define H5FILE_NAME "interm_group.h5"
+#define TRUE 1
+#define FALSE 0
int
main(void)
{
- hid_t file;
- hid_t g1_id, g2_id, g3_id;
- hid_t grp_crt_plist;
+ hid_t file;
+ hid_t g1_id, g2_id, g3_id;
+ hid_t grp_crt_plist;
H5G_info_t g2_info;
- char name[3];
-
- herr_t status;
- int i;
+ char name[3];
+ herr_t status;
+ int i;
/*
* Create a file using the default properties.
@@ -59,53 +56,44 @@ main(void)
/*
* Check if group /G1 exists in the file.
*/
- if(H5Lexists(file, "/G1", H5P_DEFAULT) !=FALSE)
- printf("Group /G1 exists in the file\n");
+ if (H5Lexists(file, "/G1", H5P_DEFAULT) != FALSE)
+ printf("Group /G1 exists in the file\n");
/*
* Check that group G2/G3 exists in /G1 and if not create it using
* intermediate group creation property.
*/
g1_id = H5Gopen2(file, "/G1", H5P_DEFAULT);
-/* Next commented call causes error stack to be printed out; the next one
- * works fine; is it a bug or a feature? EIP 04-25-07
-*/
-/* if (H5Lexists(g1_id, "G2/G3", H5P_DEFAULT) !=TRUE) { */
- if (H5Lexists(g1_id, "G2", H5P_DEFAULT) !=TRUE) {
-
- grp_crt_plist = H5Pcreate(H5P_LINK_CREATE);
-
- /* Set flag for intermediate group creation */
- status = H5Pset_create_intermediate_group(grp_crt_plist, TRUE);
- g3_id = H5Gcreate2(g1_id, "G2/G3", grp_crt_plist, H5P_DEFAULT, H5P_DEFAULT);
- H5Gclose(g3_id);
+ /* Next commented call causes error stack to be printed out; the next one
+ * works fine; is it a bug or a feature? EIP 04-25-07
+ */
+ /* if (H5Lexists(g1_id, "G2/G3", H5P_DEFAULT) !=TRUE) { */
+ if (H5Lexists(g1_id, "G2", H5P_DEFAULT) != TRUE) {
+
+ grp_crt_plist = H5Pcreate(H5P_LINK_CREATE);
+
+ /* Set flag for intermediate group creation */
+ status = H5Pset_create_intermediate_group(grp_crt_plist, TRUE);
+ g3_id = H5Gcreate2(g1_id, "G2/G3", grp_crt_plist, H5P_DEFAULT, H5P_DEFAULT);
+ H5Gclose(g3_id);
}
H5Gclose(g1_id);
-
/* Now check if group /G1/G2 exists in the file, then open it and print
* its members names
*/
if (H5Lexists(file, "/G1/G2", H5P_DEFAULT)) {
- g2_id = H5Gopen2(file, "/G1/G2", H5P_DEFAULT);
- status = H5Gget_info(g2_id, &g2_info);
- printf("Group /G1/G2 has %d member(s)\n", (int)g2_info.nlinks);
+ g2_id = H5Gopen2(file, "/G1/G2", H5P_DEFAULT);
+ status = H5Gget_info(g2_id, &g2_info);
+ printf("Group /G1/G2 has %d member(s)\n", (int)g2_info.nlinks);
- for (i=0; i < (int)g2_info.nlinks; i++) {
- H5Lget_name_by_idx(g2_id, ".", H5_INDEX_NAME, H5_ITER_NATIVE, (hsize_t)i,
- name, 3, H5P_DEFAULT);
- printf("Object's name is %s\n", name);
-
- }
- H5Gclose(g2_id);
+ for (i = 0; i < (int)g2_info.nlinks; i++) {
+ H5Lget_name_by_idx(g2_id, ".", H5_INDEX_NAME, H5_ITER_NATIVE, (hsize_t)i, name, 3, H5P_DEFAULT);
+ printf("Object's name is %s\n", name);
+ }
+ H5Gclose(g2_id);
}
H5Fclose(file);
return 0;
}
-
-
-
-
-
-
diff --git a/examples/h5_mount.c b/examples/h5_mount.c
index a2e16c5..3f087f7 100644
--- a/examples/h5_mount.c
+++ b/examples/h5_mount.c
@@ -6,7 +6,7 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -25,107 +25,105 @@
#define FILE2 "mount2.h5"
#define RANK 2
-#define NX 4
-#define NY 5
+#define NX 4
+#define NY 5
-int main(void)
+int
+main(void)
{
- hid_t fid1, fid2, gid; /* Files and group identifiers */
- hid_t did, tid, sid; /* Dataset and datatype identifiers */
-
- herr_t status;
- hsize_t dims[] = {NX,NY}; /* Dataset dimensions */
-
- int i, j;
- int bm[NX][NY], bm_out[NX][NY]; /* Data buffers */
-
- /*
- * Initialization of buffer matrix "bm"
- */
- for(i =0; i < NX; i++)
- for(j = 0; j < NY; j++)
- bm[i][j] = i + j;
-
- /*
- * Create first file and a group in it.
- */
- fid1 = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
- gid = H5Gcreate2(fid1, "/G", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
-
- /*
- * Close group and file
- */
- H5Gclose(gid);
- H5Fclose(fid1);
-
- /*
- * Create second file and dataset "D" in it.
- */
- fid2 = H5Fcreate(FILE2, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
- dims[0] = NX;
- dims[1] = NY;
- sid = H5Screate_simple(RANK, dims, NULL);
- did = H5Dcreate2(fid2, "D", H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
-
- /*
- * Write data to the dataset.
- */
- status = H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, bm);
-
- /*
- * Close all identifiers.
- */
- H5Sclose(sid);
- H5Dclose(did);
- H5Fclose(fid2);
-
- /*
- * Reopen both files
- */
- fid1 = H5Fopen(FILE1, H5F_ACC_RDONLY, H5P_DEFAULT);
- fid2 = H5Fopen(FILE2, H5F_ACC_RDONLY, H5P_DEFAULT);
-
- /*
- * Mount second file under G in the first file.
- */
- H5Fmount(fid1, "/G", fid2, H5P_DEFAULT);
-
- /*
- * Access dataset D in the first file under /G/D name.
- */
- did = H5Dopen2(fid1, "/G/D", H5P_DEFAULT);
- tid = H5Dget_type(did);
- status = H5Dread(did, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, bm_out);
-
- /*
- * Print out the data.
- */
- for(i=0; i<NX; i++){
- for(j=0; j<NY; j++)
- printf(" %d", bm_out[i][j]);
- printf("\n");
- }
-
- /*
- * Close all identifers
- */
- H5Tclose(tid);
- H5Dclose(did);
-
- /*
- * Unmounting second file
- */
- H5Funmount(fid1, "/G");
-
- /*
- * Close both files
- */
- H5Fclose(fid1);
- H5Fclose(fid2);
-
- return 0;
+ hid_t fid1, fid2, gid; /* Files and group identifiers */
+ hid_t did, tid, sid; /* Dataset and datatype identifiers */
+
+ herr_t status;
+ hsize_t dims[] = {NX, NY}; /* Dataset dimensions */
+
+ int i, j;
+ int bm[NX][NY], bm_out[NX][NY]; /* Data buffers */
+
+ /*
+ * Initialization of buffer matrix "bm"
+ */
+ for (i = 0; i < NX; i++)
+ for (j = 0; j < NY; j++)
+ bm[i][j] = i + j;
+
+ /*
+ * Create first file and a group in it.
+ */
+ fid1 = H5Fcreate(FILE1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ gid = H5Gcreate2(fid1, "/G", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+
+ /*
+ * Close group and file
+ */
+ H5Gclose(gid);
+ H5Fclose(fid1);
+
+ /*
+ * Create second file and dataset "D" in it.
+ */
+ fid2 = H5Fcreate(FILE2, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ dims[0] = NX;
+ dims[1] = NY;
+ sid = H5Screate_simple(RANK, dims, NULL);
+ did = H5Dcreate2(fid2, "D", H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+
+ /*
+ * Write data to the dataset.
+ */
+ status = H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, bm);
+
+ /*
+ * Close all identifiers.
+ */
+ H5Sclose(sid);
+ H5Dclose(did);
+ H5Fclose(fid2);
+
+ /*
+ * Reopen both files
+ */
+ fid1 = H5Fopen(FILE1, H5F_ACC_RDONLY, H5P_DEFAULT);
+ fid2 = H5Fopen(FILE2, H5F_ACC_RDONLY, H5P_DEFAULT);
+
+ /*
+ * Mount second file under G in the first file.
+ */
+ H5Fmount(fid1, "/G", fid2, H5P_DEFAULT);
+
+ /*
+ * Access dataset D in the first file under /G/D name.
+ */
+ did = H5Dopen2(fid1, "/G/D", H5P_DEFAULT);
+ tid = H5Dget_type(did);
+ status = H5Dread(did, tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, bm_out);
+
+ /*
+ * Print out the data.
+ */
+ for (i = 0; i < NX; i++) {
+ for (j = 0; j < NY; j++)
+ printf(" %d", bm_out[i][j]);
+ printf("\n");
+ }
+
+ /*
+ * Close all identifiers
+ */
+ H5Tclose(tid);
+ H5Dclose(did);
+
+ /*
+ * Unmounting second file
+ */
+ H5Funmount(fid1, "/G");
+
+ /*
+ * Close both files
+ */
+ H5Fclose(fid1);
+ H5Fclose(fid2);
+
+ return 0;
}
-
-
-
diff --git a/examples/h5_rdwt.c b/examples/h5_rdwt.c
index 6cd7f0f..ba5ddae 100644
--- a/examples/h5_rdwt.c
+++ b/examples/h5_rdwt.c
@@ -6,12 +6,12 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-/*
+/*
* This example illustrates how to write and read data in an existing
* dataset. It is used in the HDF5 Tutorial.
*/
@@ -19,33 +19,33 @@
#include "hdf5.h"
#define FILE "dset.h5"
-int main() {
+int
+main()
+{
- hid_t file_id, dataset_id; /* identifiers */
- herr_t status;
- int i, j, dset_data[4][6];
+ hid_t file_id, dataset_id; /* identifiers */
+ herr_t status;
+ int i, j, dset_data[4][6];
- /* Initialize the dataset. */
- for (i = 0; i < 4; i++)
- for (j = 0; j < 6; j++)
- dset_data[i][j] = i * 6 + j + 1;
+ /* Initialize the dataset. */
+ for (i = 0; i < 4; i++)
+ for (j = 0; j < 6; j++)
+ dset_data[i][j] = i * 6 + j + 1;
- /* Open an existing file. */
- file_id = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT);
+ /* Open an existing file. */
+ file_id = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT);
- /* Open an existing dataset. */
- dataset_id = H5Dopen2(file_id, "/dset", H5P_DEFAULT);
+ /* Open an existing dataset. */
+ dataset_id = H5Dopen2(file_id, "/dset", H5P_DEFAULT);
- /* Write the dataset. */
- status = H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
- dset_data);
+ /* Write the dataset. */
+ status = H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_data);
- status = H5Dread(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
- dset_data);
+ status = H5Dread(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_data);
- /* Close the dataset. */
- status = H5Dclose(dataset_id);
+ /* Close the dataset. */
+ status = H5Dclose(dataset_id);
- /* Close the file. */
- status = H5Fclose(file_id);
+ /* Close the file. */
+ status = H5Fclose(file_id);
}
diff --git a/examples/h5_read.c b/examples/h5_read.c
index 7fd8ad4..afd3b14 100644
--- a/examples/h5_read.c
+++ b/examples/h5_read.c
@@ -6,7 +6,7 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -20,71 +20,73 @@
#include "hdf5.h"
-#define H5FILE_NAME "SDS.h5"
+#define H5FILE_NAME "SDS.h5"
#define DATASETNAME "IntArray"
-#define NX_SUB 3 /* hyperslab dimensions */
-#define NY_SUB 4
-#define NX 7 /* output buffer dimensions */
-#define NY 7
-#define NZ 3
-#define RANK 2
-#define RANK_OUT 3
+#define NX_SUB 3 /* hyperslab dimensions */
+#define NY_SUB 4
+#define NX 7 /* output buffer dimensions */
+#define NY 7
+#define NZ 3
+#define RANK 2
+#define RANK_OUT 3
int
-main (void)
+main(void)
{
- hid_t file, dataset; /* handles */
+ hid_t file, dataset; /* handles */
hid_t datatype, dataspace;
hid_t memspace;
- H5T_class_t t_class; /* data type class */
- H5T_order_t order; /* data order */
- size_t size; /*
- * size of the data element
- * stored in file
- */
- hsize_t dimsm[3]; /* memory space dimensions */
- hsize_t dims_out[2]; /* dataset dimensions */
- herr_t status;
-
- int data_out[NX][NY][NZ ]; /* output buffer */
-
- hsize_t count[2]; /* size of the hyperslab in the file */
- hsize_t offset[2]; /* hyperslab offset in the file */
- hsize_t count_out[3]; /* size of the hyperslab in memory */
- hsize_t offset_out[3]; /* hyperslab offset in memory */
- int i, j, k, status_n, rank;
+ H5T_class_t t_class; /* data type class */
+ H5T_order_t order; /* data order */
+ size_t size; /*
+ * size of the data element
+ * stored in file
+ */
+ hsize_t dimsm[3]; /* memory space dimensions */
+ hsize_t dims_out[2]; /* dataset dimensions */
+ herr_t status;
+
+ int data_out[NX][NY][NZ]; /* output buffer */
+
+ hsize_t count[2]; /* size of the hyperslab in the file */
+ hsize_t offset[2]; /* hyperslab offset in the file */
+ hsize_t count_out[3]; /* size of the hyperslab in memory */
+ hsize_t offset_out[3]; /* hyperslab offset in memory */
+ int i, j, k, status_n, rank;
for (j = 0; j < NX; j++) {
- for (i = 0; i < NY; i++) {
- for (k = 0; k < NZ ; k++)
- data_out[j][i][k] = 0;
- }
+ for (i = 0; i < NY; i++) {
+ for (k = 0; k < NZ; k++)
+ data_out[j][i][k] = 0;
+ }
}
/*
* Open the file and the dataset.
*/
- file = H5Fopen(H5FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT);
+ file = H5Fopen(H5FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT);
dataset = H5Dopen2(file, DATASETNAME, H5P_DEFAULT);
/*
* Get datatype and dataspace handles and then query
* dataset class, order, size, rank and dimensions.
*/
- datatype = H5Dget_type(dataset); /* datatype handle */
- t_class = H5Tget_class(datatype);
- if (t_class == H5T_INTEGER) printf("Data set has INTEGER type \n");
- order = H5Tget_order(datatype);
- if (order == H5T_ORDER_LE) printf("Little endian order \n");
-
- size = H5Tget_size(datatype);
+ datatype = H5Dget_type(dataset); /* datatype handle */
+ t_class = H5Tget_class(datatype);
+ if (t_class == H5T_INTEGER)
+ printf("Data set has INTEGER type \n");
+ order = H5Tget_order(datatype);
+ if (order == H5T_ORDER_LE)
+ printf("Little endian order \n");
+
+ size = H5Tget_size(datatype);
printf(" Data size is %d \n", (int)size);
- dataspace = H5Dget_space(dataset); /* dataspace handle */
+ dataspace = H5Dget_space(dataset); /* dataspace handle */
rank = H5Sget_simple_extent_ndims(dataspace);
status_n = H5Sget_simple_extent_dims(dataspace, dims_out, NULL);
- printf("rank %d, dimensions %lu x %lu \n", rank,
- (unsigned long)(dims_out[0]), (unsigned long)(dims_out[1]));
+ printf("rank %d, dimensions %lu x %lu \n", rank, (unsigned long)(dims_out[0]),
+ (unsigned long)(dims_out[1]));
/*
* Define hyperslab in the dataset.
@@ -93,16 +95,15 @@ main (void)
offset[1] = 2;
count[0] = NX_SUB;
count[1] = NY_SUB;
- status = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, offset, NULL,
- count, NULL);
+ status = H5Sselect_hyperslab(dataspace, H5S_SELECT_SET, offset, NULL, count, NULL);
/*
* Define the memory dataspace.
*/
dimsm[0] = NX;
dimsm[1] = NY;
- dimsm[2] = NZ ;
- memspace = H5Screate_simple(RANK_OUT,dimsm,NULL);
+ dimsm[2] = NZ;
+ memspace = H5Screate_simple(RANK_OUT, dimsm, NULL);
/*
* Define memory hyperslab.
@@ -113,18 +114,17 @@ main (void)
count_out[0] = NX_SUB;
count_out[1] = NY_SUB;
count_out[2] = 1;
- status = H5Sselect_hyperslab(memspace, H5S_SELECT_SET, offset_out, NULL,
- count_out, NULL);
+ status = H5Sselect_hyperslab(memspace, H5S_SELECT_SET, offset_out, NULL, count_out, NULL);
/*
* Read data from hyperslab in the file into the hyperslab in
* memory and display.
*/
- status = H5Dread(dataset, H5T_NATIVE_INT, memspace, dataspace,
- H5P_DEFAULT, data_out);
+ status = H5Dread(dataset, H5T_NATIVE_INT, memspace, dataspace, H5P_DEFAULT, data_out);
for (j = 0; j < NX; j++) {
- for (i = 0; i < NY; i++) printf("%d ", data_out[j][i][0]);
- printf("\n");
+ for (i = 0; i < NY; i++)
+ printf("%d ", data_out[j][i][0]);
+ printf("\n");
}
/*
* 0 0 0 0 0 0 0
diff --git a/examples/h5_ref2reg.c b/examples/h5_ref2reg_deprec.c
index dc2964c..0752e62 100644
--- a/examples/h5_ref2reg.c
+++ b/examples/h5_ref2reg_deprec.c
@@ -6,7 +6,7 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -26,33 +26,34 @@
#include "hdf5.h"
-#define filename "REF_REG.h5"
+#define filename "REF_REG.h5"
#define dsetnamev "MATRIX"
#define dsetnamer "REGION_REFERENCES"
-int main(void)
+int
+main(void)
{
- hid_t file_id; /* file identifier */
- hid_t space_id; /* dataspace identifiers */
- hid_t spacer_id;
- hid_t dsetv_id; /*dataset identifiers*/
- hid_t dsetr_id;
- hsize_t dims[2] = {2,9};
- hsize_t dimsr[1] = {2};
- int rank = 2;
- int rankr =1;
- herr_t status;
+ hid_t file_id; /* file identifier */
+ hid_t space_id; /* dataspace identifiers */
+ hid_t spacer_id;
+ hid_t dsetv_id; /*dataset identifiers*/
+ hid_t dsetr_id;
+ hsize_t dims[2] = {2, 9};
+ hsize_t dimsr[1] = {2};
+ int rank = 2;
+ int rankr = 1;
+ herr_t status;
hdset_reg_ref_t ref[2];
hdset_reg_ref_t ref_out[2];
- int data[2][9] = {{1,1,2,3,3,4,5,5,6},{1,2,2,3,4,4,5,6,6}};
- int data_out[2][9] = {{0,0,0,0,0,0,0,0,0},{0,0,0,0,0,0,0,0,0}};
- hsize_t start[2];
- hsize_t count[2];
- hsize_t coord[2][3] = {{0, 0, 1}, {6, 0, 8}};
- unsigned num_points = 3;
- int i, j;
- size_t name_size1, name_size2;
- char buf1[10], buf2[10];
+ int data[2][9] = {{1, 1, 2, 3, 3, 4, 5, 5, 6}, {1, 2, 2, 3, 4, 4, 5, 6, 6}};
+ int data_out[2][9] = {{0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 0}};
+ hsize_t start[2];
+ hsize_t count[2];
+ hsize_t coord[2][3] = {{0, 0, 1}, {6, 0, 8}};
+ unsigned num_points = 3;
+ int i, j;
+ size_t name_size1, name_size2;
+ char buf1[10], buf2[10];
/*
* Create file with default file access and file creation properties.
@@ -62,24 +63,26 @@ int main(void)
/*
* Create dataspace for datasets.
*/
- space_id = H5Screate_simple(rank, dims, NULL);
+ space_id = H5Screate_simple(rank, dims, NULL);
spacer_id = H5Screate_simple(rankr, dimsr, NULL);
/*
* Create integer dataset.
*/
- dsetv_id = H5Dcreate2(file_id, dsetnamev, H5T_NATIVE_INT, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ dsetv_id =
+ H5Dcreate2(file_id, dsetnamev, H5T_NATIVE_INT, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/*
* Write data to the dataset.
*/
- status = H5Dwrite(dsetv_id, H5T_NATIVE_INT, H5S_ALL , H5S_ALL, H5P_DEFAULT,data);
+ status = H5Dwrite(dsetv_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
status = H5Dclose(dsetv_id);
/*
* Dataset with references.
*/
- dsetr_id = H5Dcreate2(file_id, dsetnamer, H5T_STD_REF_DSETREG, spacer_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ dsetr_id =
+ H5Dcreate2(file_id, dsetnamer, H5T_STD_REF_DSETREG, spacer_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/*
* Create a reference to the hyperslab.
@@ -88,8 +91,8 @@ int main(void)
start[1] = 3;
count[0] = 2;
count[1] = 3;
- status = H5Sselect_hyperslab(space_id, H5S_SELECT_SET, start, NULL, count, NULL);
- status = H5Rcreate(&ref[0], file_id, dsetnamev, H5R_DATASET_REGION, space_id);
+ status = H5Sselect_hyperslab(space_id, H5S_SELECT_SET, start, NULL, count, NULL);
+ status = H5Rcreate(&ref[0], file_id, dsetnamev, H5R_DATASET_REGION, space_id);
/*
* Create a reference to elements selection.
@@ -101,7 +104,7 @@ int main(void)
/*
* Write dataset with the references.
*/
- status = H5Dwrite(dsetr_id, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL, H5P_DEFAULT,ref);
+ status = H5Dwrite(dsetr_id, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL, H5P_DEFAULT, ref);
/*
* Close all objects.
@@ -114,7 +117,7 @@ int main(void)
/*
* Reopen the file to read selections back.
*/
- file_id = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT);
+ file_id = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT);
/*
* Reopen the dataset with object references and read references
@@ -122,8 +125,7 @@ int main(void)
*/
dsetr_id = H5Dopen2(file_id, dsetnamer, H5P_DEFAULT);
- status = H5Dread(dsetr_id, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL,
- H5P_DEFAULT, ref_out);
+ status = H5Dread(dsetr_id, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL, H5P_DEFAULT, ref_out);
/*
* Dereference the first reference.
@@ -133,26 +135,26 @@ int main(void)
* Get name of the dataset the first region reference points to
* using H5Rget_name
*/
- name_size1 = H5Rget_name(dsetr_id, H5R_DATASET_REGION, &ref_out[0], (char*)buf1, 10);
- printf(" Dataset's name (returned by H5Rget_name) the reference points to is %s, name length is %d\n", buf1, (int)name_size1);
+ name_size1 = H5Rget_name(dsetr_id, H5R_DATASET_REGION, &ref_out[0], (char *)buf1, 10);
+ printf(" Dataset's name (returned by H5Rget_name) the reference points to is %s, name length is %d\n",
+ buf1, (int)name_size1);
/*
* Get name of the dataset the first region reference points to
* using H5Iget_name
*/
- name_size2 = H5Iget_name(dsetv_id, (char*)buf2, 10);
- printf(" Dataset's name (returned by H5Iget_name) the reference points to is %s, name length is %d\n", buf2, (int)name_size2);
+ name_size2 = H5Iget_name(dsetv_id, (char *)buf2, 10);
+ printf(" Dataset's name (returned by H5Iget_name) the reference points to is %s, name length is %d\n",
+ buf2, (int)name_size2);
- space_id = H5Rget_region(dsetr_id, H5R_DATASET_REGION,&ref_out[0]);
+ space_id = H5Rget_region(dsetr_id, H5R_DATASET_REGION, &ref_out[0]);
/*
* Read and display hyperslab selection from the dataset.
*/
- status = H5Dread(dsetv_id, H5T_NATIVE_INT, H5S_ALL, space_id,
- H5P_DEFAULT, data_out);
+ status = H5Dread(dsetv_id, H5T_NATIVE_INT, H5S_ALL, space_id, H5P_DEFAULT, data_out);
printf("Selected hyperslab: ");
- for (i = 0; i <= 1; i++)
- {
+ for (i = 0; i <= 1; i++) {
printf("\n");
for (j = 0; j <= 8; j++)
printf("%d ", data_out[i][j]);
@@ -176,17 +178,15 @@ int main(void)
* Dereference the second reference.
*/
dsetv_id = H5Rdereference2(dsetr_id, H5P_DEFAULT, H5R_DATASET_REGION, &ref_out[1]);
- space_id = H5Rget_region(dsetv_id, H5R_DATASET_REGION,&ref_out[1]);
+ space_id = H5Rget_region(dsetv_id, H5R_DATASET_REGION, &ref_out[1]);
/*
* Read selected data from the dataset.
*/
- status = H5Dread(dsetv_id, H5T_NATIVE_INT, H5S_ALL, space_id,
- H5P_DEFAULT, data_out);
+ status = H5Dread(dsetv_id, H5T_NATIVE_INT, H5S_ALL, space_id, H5P_DEFAULT, data_out);
printf("Selected points: ");
- for (i = 0; i <= 1; i++)
- {
+ for (i = 0; i <= 1; i++) {
printf("\n");
for (j = 0; j <= 8; j++)
printf("%d ", data_out[i][j]);
@@ -203,6 +203,3 @@ int main(void)
return 0;
}
-
-
-
diff --git a/examples/h5_ref_compat.c b/examples/h5_ref_compat.c
new file mode 100644
index 0000000..cce755b
--- /dev/null
+++ b/examples/h5_ref_compat.c
@@ -0,0 +1,89 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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 *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
+ * If you do not have access to either file, you may request a copy from *
+ * help@hdfgroup.org. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/*
+ * The example below illustrates the use of the new API with a file that was
+ * written using the old-style reference API, showing how one can take
+ * advantage of the automatic type conversion from old reference type to new
+ * reference type.
+ */
+
+#include <stdlib.h>
+
+#include "hdf5.h"
+#include <assert.h>
+
+#define H5FILE_NAME "refer_deprec.h5"
+
+#define NDIMS 1 /* Number of dimensions */
+#define BUF_SIZE 4 /* Size of example buffer */
+#define NREFS 1 /* Number of references */
+
+int
+main(void)
+{
+ hid_t file1, dset1, space1;
+ hsize_t dset1_dims[NDIMS] = {BUF_SIZE};
+ int dset_buf[BUF_SIZE];
+
+ hid_t dset2, space2;
+ hsize_t dset2_dims[NDIMS] = {NREFS};
+ hobj_ref_t ref_buf[NREFS] = {0};
+ H5R_ref_t new_ref_buf[NREFS] = {0};
+ H5O_type_t obj_type;
+ int i;
+
+ for (i = 0; i < BUF_SIZE; i++)
+ dset_buf[i] = i;
+
+ /* Create file with one dataset and close it */
+ file1 = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+
+ space1 = H5Screate_simple(NDIMS, dset1_dims, NULL);
+ dset1 = H5Dcreate2(file1, "dataset1", H5T_NATIVE_INT, space1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ H5Dwrite(dset1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_buf);
+ H5Dclose(dset1);
+ H5Sclose(space1);
+
+ /**
+ * Create reference to dataset1 with deprecated API
+ * (reminder: there is no destroy call for those references)
+ */
+ H5Rcreate(&ref_buf[0], file1, "dataset1", H5R_OBJECT, H5I_INVALID_HID);
+
+ /* Store reference in separate dataset using deprecated reference type */
+ space2 = H5Screate_simple(NDIMS, dset2_dims, NULL);
+ dset2 = H5Dcreate2(file1, "references", H5T_STD_REF_OBJ, space2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ H5Dwrite(dset2, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, ref_buf);
+ H5Dclose(dset2);
+ H5Sclose(space2);
+ H5Fclose(file1);
+
+ /* Read reference from file using new reference type */
+ file1 = H5Fopen(H5FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT);
+ dset2 = H5Dopen2(file1, "references", H5P_DEFAULT);
+ H5Dread(dset2, H5T_STD_REF, H5S_ALL, H5S_ALL, H5P_DEFAULT, new_ref_buf);
+ H5Dclose(dset2);
+
+ /* Access reference and read dataset data through new API */
+ assert(H5Rget_type((const H5R_ref_t *)&new_ref_buf[0]) == H5R_OBJECT2);
+ H5Rget_obj_type3(&new_ref_buf[0], H5P_DEFAULT, &obj_type);
+ assert(obj_type == H5O_TYPE_DATASET);
+ dset1 = H5Ropen_object(&new_ref_buf[0], H5P_DEFAULT, H5P_DEFAULT);
+ H5Dread(dset1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_buf);
+ H5Dclose(dset1);
+ H5Rdestroy(&new_ref_buf[0]);
+
+ for (i = 0; i < BUF_SIZE; i++)
+ assert(dset_buf[i] == i);
+ return 0;
+}
diff --git a/examples/h5_ref_extern.c b/examples/h5_ref_extern.c
new file mode 100644
index 0000000..691d235
--- /dev/null
+++ b/examples/h5_ref_extern.c
@@ -0,0 +1,92 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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 *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
+ * If you do not have access to either file, you may request a copy from *
+ * help@hdfgroup.org. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/*
+ * The example below illustrates the use of the new API with files that are
+ * opened read-only. Created references to the objects in that file are
+ * stored into a separate file, and accessed from that file, without the user
+ * explicitly opening the original file that was referenced.
+ */
+
+#include <stdlib.h>
+
+#include "hdf5.h"
+#include <assert.h>
+
+#define H5FILE_NAME1 "refer_extern1.h5"
+#define H5FILE_NAME2 "refer_extern2.h5"
+
+#define NDIMS 1 /* Number of dimensions */
+#define BUF_SIZE 4 /* Size of example buffer */
+#define NREFS 1 /* Number of references */
+
+int
+main(void)
+{
+ hid_t file1, dset1, space1;
+ hsize_t dset1_dims[NDIMS] = {BUF_SIZE};
+ int dset_buf[BUF_SIZE];
+
+ hid_t file2, dset2, space2;
+ hsize_t dset2_dims[NDIMS] = {NREFS};
+ H5R_ref_t ref_buf[NREFS] = {0};
+ H5O_type_t obj_type;
+ int i;
+
+ for (i = 0; i < BUF_SIZE; i++)
+ dset_buf[i] = i;
+
+ /* Create file with one dataset and close it */
+ file1 = H5Fcreate(H5FILE_NAME1, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ space1 = H5Screate_simple(NDIMS, dset1_dims, NULL);
+ dset1 = H5Dcreate2(file1, "dataset1", H5T_NATIVE_INT, space1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ H5Dwrite(dset1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_buf);
+ H5Dclose(dset1);
+ H5Sclose(space1);
+ H5Fclose(file1);
+
+ /* Create reference to dataset1 in "refer_extern1.h5" */
+ file1 = H5Fopen(H5FILE_NAME1, H5F_ACC_RDONLY, H5P_DEFAULT);
+ H5Rcreate_object(file1, "dataset1", H5P_DEFAULT, &ref_buf[0]);
+ H5Fclose(file1);
+
+ /* Store reference in dataset in separate file "refer_extern2.h5" */
+ file2 = H5Fcreate(H5FILE_NAME2, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ space2 = H5Screate_simple(NDIMS, dset2_dims, NULL);
+ dset2 = H5Dcreate2(file2, "references", H5T_STD_REF, space2, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ H5Dwrite(dset2, H5T_STD_REF, H5S_ALL, H5S_ALL, H5P_DEFAULT, ref_buf);
+ H5Dclose(dset2);
+ H5Sclose(space2);
+ H5Fclose(file2);
+ H5Rdestroy(&ref_buf[0]);
+
+ /* Read reference back from "refer_extern2.h5" */
+ file2 = H5Fopen(H5FILE_NAME2, H5F_ACC_RDONLY, H5P_DEFAULT);
+ dset2 = H5Dopen2(file2, "references", H5P_DEFAULT);
+ H5Dread(dset2, H5T_STD_REF, H5S_ALL, H5S_ALL, H5P_DEFAULT, ref_buf);
+ H5Dclose(dset2);
+ H5Fclose(file2);
+
+ /* Access reference and read dataset data without opening original file */
+ assert(H5Rget_type((const H5R_ref_t *)&ref_buf[0]) == H5R_OBJECT2);
+ H5Rget_obj_type3(&ref_buf[0], H5P_DEFAULT, &obj_type);
+ assert(obj_type == H5O_TYPE_DATASET);
+ dset1 = H5Ropen_object(&ref_buf[0], H5P_DEFAULT, H5P_DEFAULT);
+ H5Dread(dset1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, dset_buf);
+ H5Dclose(dset1);
+ H5Rdestroy(&ref_buf[0]);
+
+ for (i = 0; i < BUF_SIZE; i++)
+ assert(dset_buf[i] == i);
+
+ return 0;
+}
diff --git a/examples/h5_reference.c b/examples/h5_reference.c
deleted file mode 100644
index 32a5f59..0000000
--- a/examples/h5_reference.c
+++ /dev/null
@@ -1,147 +0,0 @@
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * Copyright by The HDF Group. *
- * Copyright by the Board of Trustees of the University of Illinois. *
- * 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
- * If you do not have access to either file, you may request a copy from *
- * help@hdfgroup.org. *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
- /*
- * This program illustrates how references to objects can be used.
- * Program creates a dataset and a group in a file. It also creates
- * second dataset, and references to the first dataset and the group
- * are stored in it.
- * Program reopens the file and reads dataset with the references.
- * References are used to open the objects. Information about the
- * objects is displayed.
- */
-
-#include <stdlib.h>
-
-#include "hdf5.h"
-
-#define H5FILE_NAME "refere.h5"
-
-int
-main(void) {
- hid_t fid; /* File, group, datasets, datatypes */
- hid_t gid_a; /* and dataspaces identifiers */
- hid_t did_b, sid_b, tid_b;
- hid_t did_r, tid_r, sid_r;
- H5O_type_t obj_type;
- herr_t status;
-
- hobj_ref_t *wbuf; /* buffer to write to disk */
- hobj_ref_t *rbuf; /* buffer to read from disk */
-
-
- hsize_t dim_r[1];
- hsize_t dim_b[2];
-
- /*
- * Create a file using default properties.
- */
- fid = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- /*
- * Create group "A" in the file.
- */
- gid_a = H5Gcreate2(fid, "A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
-
- /*
- * Create dataset "B" in the file.
- */
- dim_b[0] = 2;
- dim_b[1] = 6;
- sid_b = H5Screate_simple(2, dim_b, NULL);
- did_b = H5Dcreate2(fid, "B", H5T_NATIVE_FLOAT, sid_b, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
-
- /*
- * Create dataset "R" to store references to the objects "A" and "B".
- */
- dim_r[0] = 2;
- sid_r = H5Screate_simple(1, dim_r, NULL);
- tid_r = H5Tcopy(H5T_STD_REF_OBJ);
- did_r = H5Dcreate2(fid, "R", tid_r, sid_r, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
-
- /*
- * Allocate write and read buffers.
- */
- wbuf = (hobj_ref_t *)malloc(sizeof(hobj_ref_t) * 2);
- rbuf = (hobj_ref_t *)malloc(sizeof(hobj_ref_t) * 2);
-
- /*
- * Create references to the group "A" and dataset "B"
- * and store them in the wbuf.
- */
- H5Rcreate(&wbuf[0], fid, "A", H5R_OBJECT, (hid_t)-1);
- H5Rcreate(&wbuf[1], fid, "B", H5R_OBJECT, (hid_t)-1);
-
- /*
- * Write dataset R using default transfer properties.
- */
- status = H5Dwrite(did_r, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, wbuf);
-
- /*
- * Close all objects.
- */
- H5Gclose(gid_a);
-
- H5Sclose(sid_b);
- H5Dclose(did_b);
-
- H5Tclose(tid_r);
- H5Sclose(sid_r);
- H5Dclose(did_r);
-
- H5Fclose(fid);
-
- /*
- * Reopen the file.
- */
- fid = H5Fopen(H5FILE_NAME, H5F_ACC_RDWR, H5P_DEFAULT);
-
- /*
- * Open and read dataset "R".
- */
- did_r = H5Dopen2(fid, "R", H5P_DEFAULT);
- status = H5Dread(did_r, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf);
-
- /*
- * Find the type of referenced objects.
- */
- status = H5Rget_obj_type2(did_r, H5R_OBJECT, &rbuf[0], &obj_type);
- if(obj_type == H5O_TYPE_GROUP)
- printf("First dereferenced object is a group. \n");
-
- status = H5Rget_obj_type2(did_r, H5R_OBJECT, &rbuf[1], &obj_type);
- if(obj_type == H5O_TYPE_DATASET)
- printf("Second dereferenced object is a dataset. \n");
-
- /*
- * Get datatype of the dataset "B"
- */
- did_b = H5Rdereference2(did_r, H5P_DEFAULT, H5R_OBJECT, &rbuf[1]);
- tid_b = H5Dget_type(did_b);
- if(H5Tequal(tid_b, H5T_NATIVE_FLOAT))
- printf("Datatype of the dataset is H5T_NATIVE_FLOAT.\n");
- printf("\n");
-
- /*
- * Close all objects and free memory buffers.
- */
- H5Dclose(did_r);
- H5Dclose(did_b);
- H5Tclose(tid_b);
- H5Fclose(fid);
- free(rbuf);
- free(wbuf);
-
- return 0;
- }
-
diff --git a/examples/h5_reference_deprec.c b/examples/h5_reference_deprec.c
new file mode 100644
index 0000000..e0592c1
--- /dev/null
+++ b/examples/h5_reference_deprec.c
@@ -0,0 +1,146 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Copyright by The HDF Group. *
+ * Copyright by the Board of Trustees of the University of Illinois. *
+ * 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 *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
+ * If you do not have access to either file, you may request a copy from *
+ * help@hdfgroup.org. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/*
+ * This program illustrates how references to objects can be used.
+ * Program creates a dataset and a group in a file. It also creates
+ * second dataset, and references to the first dataset and the group
+ * are stored in it.
+ * Program reopens the file and reads dataset with the references.
+ * References are used to open the objects. Information about the
+ * objects is displayed.
+ */
+
+#include <stdlib.h>
+
+#include "hdf5.h"
+
+#define H5FILE_NAME "refere.h5"
+
+int
+main(void)
+{
+ hid_t fid; /* File, group, datasets, datatypes */
+ hid_t gid_a; /* and dataspaces identifiers */
+ hid_t did_b, sid_b, tid_b;
+ hid_t did_r, tid_r, sid_r;
+ H5O_type_t obj_type;
+ herr_t status;
+
+ hobj_ref_t *wbuf; /* buffer to write to disk */
+ hobj_ref_t *rbuf; /* buffer to read from disk */
+
+ hsize_t dim_r[1];
+ hsize_t dim_b[2];
+
+ /*
+ * Create a file using default properties.
+ */
+ fid = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+
+ /*
+ * Create group "A" in the file.
+ */
+ gid_a = H5Gcreate2(fid, "A", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+
+ /*
+ * Create dataset "B" in the file.
+ */
+ dim_b[0] = 2;
+ dim_b[1] = 6;
+ sid_b = H5Screate_simple(2, dim_b, NULL);
+ did_b = H5Dcreate2(fid, "B", H5T_NATIVE_FLOAT, sid_b, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+
+ /*
+ * Create dataset "R" to store references to the objects "A" and "B".
+ */
+ dim_r[0] = 2;
+ sid_r = H5Screate_simple(1, dim_r, NULL);
+ tid_r = H5Tcopy(H5T_STD_REF_OBJ);
+ did_r = H5Dcreate2(fid, "R", tid_r, sid_r, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+
+ /*
+ * Allocate write and read buffers.
+ */
+ wbuf = (hobj_ref_t *)malloc(sizeof(hobj_ref_t) * 2);
+ rbuf = (hobj_ref_t *)malloc(sizeof(hobj_ref_t) * 2);
+
+ /*
+ * Create references to the group "A" and dataset "B"
+ * and store them in the wbuf.
+ */
+ H5Rcreate(&wbuf[0], fid, "A", H5R_OBJECT, (hid_t)-1);
+ H5Rcreate(&wbuf[1], fid, "B", H5R_OBJECT, (hid_t)-1);
+
+ /*
+ * Write dataset R using default transfer properties.
+ */
+ status = H5Dwrite(did_r, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, wbuf);
+
+ /*
+ * Close all objects.
+ */
+ H5Gclose(gid_a);
+
+ H5Sclose(sid_b);
+ H5Dclose(did_b);
+
+ H5Tclose(tid_r);
+ H5Sclose(sid_r);
+ H5Dclose(did_r);
+
+ H5Fclose(fid);
+
+ /*
+ * Reopen the file.
+ */
+ fid = H5Fopen(H5FILE_NAME, H5F_ACC_RDWR, H5P_DEFAULT);
+
+ /*
+ * Open and read dataset "R".
+ */
+ did_r = H5Dopen2(fid, "R", H5P_DEFAULT);
+ status = H5Dread(did_r, H5T_STD_REF_OBJ, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf);
+
+ /*
+ * Find the type of referenced objects.
+ */
+ status = H5Rget_obj_type2(did_r, H5R_OBJECT, &rbuf[0], &obj_type);
+ if (obj_type == H5O_TYPE_GROUP)
+ printf("First dereferenced object is a group. \n");
+
+ status = H5Rget_obj_type2(did_r, H5R_OBJECT, &rbuf[1], &obj_type);
+ if (obj_type == H5O_TYPE_DATASET)
+ printf("Second dereferenced object is a dataset. \n");
+
+ /*
+ * Get datatype of the dataset "B"
+ */
+ did_b = H5Rdereference2(did_r, H5P_DEFAULT, H5R_OBJECT, &rbuf[1]);
+ tid_b = H5Dget_type(did_b);
+ if (H5Tequal(tid_b, H5T_NATIVE_FLOAT))
+ printf("Datatype of the dataset is H5T_NATIVE_FLOAT.\n");
+ printf("\n");
+
+ /*
+ * Close all objects and free memory buffers.
+ */
+ H5Dclose(did_r);
+ H5Dclose(did_b);
+ H5Tclose(tid_b);
+ H5Fclose(fid);
+ free(rbuf);
+ free(wbuf);
+
+ return 0;
+}
diff --git a/examples/h5_select.c b/examples/h5_select.c
index bbc877c..e8aeb50 100644
--- a/examples/h5_select.c
+++ b/examples/h5_select.c
@@ -6,7 +6,7 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -26,78 +26,80 @@
#define H5FILE_NAME "Select.h5"
-#define MSPACE1_RANK 1 /* Rank of the first dataset in memory */
-#define MSPACE1_DIM 50 /* Dataset size in memory */
+#define MSPACE1_RANK 1 /* Rank of the first dataset in memory */
+#define MSPACE1_DIM 50 /* Dataset size in memory */
-#define MSPACE2_RANK 1 /* Rank of the second dataset in memory */
-#define MSPACE2_DIM 4 /* Dataset size in memory */
+#define MSPACE2_RANK 1 /* Rank of the second dataset in memory */
+#define MSPACE2_DIM 4 /* Dataset size in memory */
-#define FSPACE_RANK 2 /* Dataset rank as it is stored in the file */
-#define FSPACE_DIM1 8 /* Dimension sizes of the dataset as it is
- stored in the file */
-#define FSPACE_DIM2 12
+#define FSPACE_RANK 2 /* Dataset rank as it is stored in the file */
+#define FSPACE_DIM1 \
+ 8 /* Dimension sizes of the dataset as it is \
+ stored in the file */
+#define FSPACE_DIM2 12
- /* We will read dataset back from the file
- to the dataset in memory with these
- dataspace parameters. */
-#define MSPACE_RANK 2
-#define MSPACE_DIM1 8
-#define MSPACE_DIM2 9
+/* We will read dataset back from the file
+ to the dataset in memory with these
+ dataspace parameters. */
+#define MSPACE_RANK 2
+#define MSPACE_DIM1 8
+#define MSPACE_DIM2 9
-#define NPOINTS 4 /* Number of points that will be selected
- and overwritten */
+#define NPOINTS \
+ 4 /* Number of points that will be selected \
+ and overwritten */
int
-main (void)
+main(void)
{
- hid_t file, dataset; /* File and dataset identifiers */
- hid_t mid1, mid2, mid, fid; /* Dataspace identifiers */
- hid_t plist; /* Dataset property list identifier */
+ hid_t file, dataset; /* File and dataset identifiers */
+ hid_t mid1, mid2, mid, fid; /* Dataspace identifiers */
+ hid_t plist; /* Dataset property list identifier */
- hsize_t dim1[] = {MSPACE1_DIM}; /* Dimension size of the first dataset
+ hsize_t dim1[] = {MSPACE1_DIM}; /* Dimension size of the first dataset
(in memory) */
- hsize_t dim2[] = {MSPACE2_DIM}; /* Dimension size of the second dataset
+ hsize_t dim2[] = {MSPACE2_DIM}; /* Dimension size of the second dataset
(in memory */
- hsize_t fdim[] = {FSPACE_DIM1, FSPACE_DIM2};
- /* Dimension sizes of the dataset (on disk) */
- hsize_t mdim[] = {MSPACE_DIM1, MSPACE_DIM2}; /* Dimension sizes of the
- dataset in memory when we
- read selection from the
- dataset on the disk */
-
- hsize_t start[2]; /* Start of hyperslab */
- hsize_t stride[2]; /* Stride of hyperslab */
- hsize_t count[2]; /* Block count */
- hsize_t block[2]; /* Block sizes */
-
- hsize_t coord[NPOINTS][FSPACE_RANK]; /* Array to store selected points
- from the file dataspace */
- herr_t ret;
- unsigned i,j;
- int fillvalue = 0; /* Fill value for the dataset */
-
- int matrix_out[MSPACE_DIM1][MSPACE_DIM2]; /* Buffer to read from the
- dataset */
- int vector[MSPACE1_DIM];
- int values[] = {53, 59, 61, 67}; /* New values to be written */
-
- /*
- * Buffers' initialization.
- */
- vector[0] = vector[MSPACE1_DIM - 1] = -1;
- for(i = 1; i < MSPACE1_DIM - 1; i++)
- vector[i] = i;
-
- /*
- * Create a file.
- */
- file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- /*
- * Create property list for a dataset and set up fill values.
- */
- plist = H5Pcreate(H5P_DATASET_CREATE);
- ret = H5Pset_fill_value(plist, H5T_NATIVE_INT, &fillvalue);
+ hsize_t fdim[] = {FSPACE_DIM1, FSPACE_DIM2};
+ /* Dimension sizes of the dataset (on disk) */
+ hsize_t mdim[] = {MSPACE_DIM1, MSPACE_DIM2}; /* Dimension sizes of the
+ dataset in memory when we
+ read selection from the
+ dataset on the disk */
+
+ hsize_t start[2]; /* Start of hyperslab */
+ hsize_t stride[2]; /* Stride of hyperslab */
+ hsize_t count[2]; /* Block count */
+ hsize_t block[2]; /* Block sizes */
+
+ hsize_t coord[NPOINTS][FSPACE_RANK]; /* Array to store selected points
+ from the file dataspace */
+ herr_t ret;
+ unsigned i, j;
+ int fillvalue = 0; /* Fill value for the dataset */
+
+ int matrix_out[MSPACE_DIM1][MSPACE_DIM2]; /* Buffer to read from the
+ dataset */
+ int vector[MSPACE1_DIM];
+ int values[] = {53, 59, 61, 67}; /* New values to be written */
+
+ /*
+ * Buffers' initialization.
+ */
+ vector[0] = vector[MSPACE1_DIM - 1] = -1;
+ for (i = 1; i < MSPACE1_DIM - 1; i++)
+ vector[i] = i;
+
+ /*
+ * Create a file.
+ */
+ file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+
+ /*
+ * Create property list for a dataset and set up fill values.
+ */
+ plist = H5Pcreate(H5P_DATASET_CREATE);
+ ret = H5Pset_fill_value(plist, H5T_NATIVE_INT, &fillvalue);
/*
* Create dataspace for the dataset in the file.
@@ -114,11 +116,15 @@ main (void)
* Select hyperslab for the dataset in the file, using 3x2 blocks,
* (4,3) stride and (2,4) count starting at the position (0,1).
*/
- start[0] = 0; start[1] = 1;
- stride[0] = 4; stride[1] = 3;
- count[0] = 2; count[1] = 4;
- block[0] = 3; block[1] = 2;
- ret = H5Sselect_hyperslab(fid, H5S_SELECT_SET, start, stride, count, block);
+ start[0] = 0;
+ start[1] = 1;
+ stride[0] = 4;
+ stride[1] = 3;
+ count[0] = 2;
+ count[1] = 4;
+ block[0] = 3;
+ block[1] = 2;
+ ret = H5Sselect_hyperslab(fid, H5S_SELECT_SET, start, stride, count, block);
/*
* Create dataspace for the first dataset.
@@ -134,7 +140,7 @@ main (void)
stride[0] = 1;
count[0] = 48;
block[0] = 1;
- ret = H5Sselect_hyperslab(mid1, H5S_SELECT_SET, start, stride, count, block);
+ ret = H5Sselect_hyperslab(mid1, H5S_SELECT_SET, start, stride, count, block);
/*
* Write selection from the vector buffer to the dataset in the file.
@@ -149,7 +155,7 @@ main (void)
* 0 41 42 0 43 44 0 45 46 0 47 48
* 0 0 0 0 0 0 0 0 0 0 0 0
*/
- ret = H5Dwrite(dataset, H5T_NATIVE_INT, mid1, fid, H5P_DEFAULT, vector);
+ ret = H5Dwrite(dataset, H5T_NATIVE_INT, mid1, fid, H5P_DEFAULT, vector);
/*
* Reset the selection for the file dataspace fid.
@@ -164,10 +170,14 @@ main (void)
/*
* Select sequence of NPOINTS points in the file dataspace.
*/
- coord[0][0] = 0; coord[0][1] = 0;
- coord[1][0] = 3; coord[1][1] = 3;
- coord[2][0] = 3; coord[2][1] = 5;
- coord[3][0] = 5; coord[3][1] = 6;
+ coord[0][0] = 0;
+ coord[0][1] = 0;
+ coord[1][0] = 3;
+ coord[1][1] = 3;
+ coord[2][0] = 3;
+ coord[2][1] = 5;
+ coord[3][0] = 5;
+ coord[3][1] = 6;
ret = H5Sselect_elements(fid, H5S_SELECT_SET, NPOINTS, (const hsize_t *)coord);
@@ -229,11 +239,15 @@ main (void)
* 0 59 0 61
*
*/
- start[0] = 1; start[1] = 2;
- block[0] = 1; block[1] = 1;
- stride[0] = 1; stride[1] = 1;
- count[0] = 3; count[1] = 4;
- ret = H5Sselect_hyperslab(fid, H5S_SELECT_SET, start, stride, count, block);
+ start[0] = 1;
+ start[1] = 2;
+ block[0] = 1;
+ block[1] = 1;
+ stride[0] = 1;
+ stride[1] = 1;
+ count[0] = 3;
+ count[1] = 4;
+ ret = H5Sselect_hyperslab(fid, H5S_SELECT_SET, start, stride, count, block);
/*
* Add second selected hyperslab to the selection.
@@ -248,11 +262,15 @@ main (void)
* 19 20
* 0 61
*/
- start[0] = 2; start[1] = 4;
- block[0] = 1; block[1] = 1;
- stride[0] = 1; stride[1] = 1;
- count[0] = 6; count[1] = 5;
- ret = H5Sselect_hyperslab(fid, H5S_SELECT_OR, start, stride, count, block);
+ start[0] = 2;
+ start[1] = 4;
+ block[0] = 1;
+ block[1] = 1;
+ stride[0] = 1;
+ stride[1] = 1;
+ count[0] = 6;
+ count[1] = 5;
+ ret = H5Sselect_hyperslab(fid, H5S_SELECT_OR, start, stride, count, block);
/*
* Create memory dataspace.
@@ -263,30 +281,37 @@ main (void)
* Select two hyperslabs in memory. Hyperslabs has the same
* size and shape as the selected hyperslabs for the file dataspace.
*/
- start[0] = 0; start[1] = 0;
- block[0] = 1; block[1] = 1;
- stride[0] = 1; stride[1] = 1;
- count[0] = 3; count[1] = 4;
- ret = H5Sselect_hyperslab(mid, H5S_SELECT_SET, start, stride, count, block);
-
- start[0] = 1; start[1] = 2;
- block[0] = 1; block[1] = 1;
- stride[0] = 1; stride[1] = 1;
- count[0] = 6; count[1] = 5;
- ret = H5Sselect_hyperslab(mid, H5S_SELECT_OR, start, stride, count, block);
+ start[0] = 0;
+ start[1] = 0;
+ block[0] = 1;
+ block[1] = 1;
+ stride[0] = 1;
+ stride[1] = 1;
+ count[0] = 3;
+ count[1] = 4;
+ ret = H5Sselect_hyperslab(mid, H5S_SELECT_SET, start, stride, count, block);
+
+ start[0] = 1;
+ start[1] = 2;
+ block[0] = 1;
+ block[1] = 1;
+ stride[0] = 1;
+ stride[1] = 1;
+ count[0] = 6;
+ count[1] = 5;
+ ret = H5Sselect_hyperslab(mid, H5S_SELECT_OR, start, stride, count, block);
/*
* Initialize data buffer.
*/
for (i = 0; i < MSPACE_DIM1; i++) {
- for (j = 0; j < MSPACE_DIM2; j++)
+ for (j = 0; j < MSPACE_DIM2; j++)
matrix_out[i][j] = 0;
}
/*
* Read data back to the buffer matrix_out.
*/
- ret = H5Dread(dataset, H5T_NATIVE_INT, mid, fid,
- H5P_DEFAULT, matrix_out);
+ ret = H5Dread(dataset, H5T_NATIVE_INT, mid, fid, H5P_DEFAULT, matrix_out);
/*
* Display the result. Memory dataset is:
@@ -300,8 +325,8 @@ main (void)
* 0 0 0 0 0 0 0 0 0
* 0 0 0 0 0 0 0 0 0
*/
- for(i = 0; i < MSPACE_DIM1; i++) {
- for(j = 0; j < MSPACE_DIM2; j++)
+ for (i = 0; i < MSPACE_DIM1; i++) {
+ for (j = 0; j < MSPACE_DIM2; j++)
printf("%3d ", matrix_out[i][j]);
printf("\n");
}
@@ -329,4 +354,3 @@ main (void)
return 0;
}
-
diff --git a/examples/h5_shared_mesg.c b/examples/h5_shared_mesg.c
index 4e1f92a..f26b360 100644
--- a/examples/h5_shared_mesg.c
+++ b/examples/h5_shared_mesg.c
@@ -6,7 +6,7 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -27,29 +27,13 @@
#include "hdf5.h"
#define NUM_DATASETS 40
-const char* DSETNAME[] = {
- "dataset0", "dataset1",
- "dataset2", "dataset3",
- "dataset4", "dataset5",
- "dataset6", "dataset7",
- "dataset8", "dataset9",
- "dataset10", "dataset11",
- "dataset12", "dataset13",
- "dataset14", "dataset15",
- "dataset16", "dataset17",
- "dataset18", "dataset19",
- "dataset20", "dataset21",
- "dataset22", "dataset23",
- "dataset24", "dataset25",
- "dataset26", "dataset27",
- "dataset28", "dataset29",
- "dataset30", "dataset31",
- "dataset32", "dataset33",
- "dataset34", "dataset35",
- "dataset36", "dataset37",
- "dataset38", "dataset39",
- NULL
-};
+const char *DSETNAME[] = {"dataset0", "dataset1", "dataset2", "dataset3", "dataset4", "dataset5",
+ "dataset6", "dataset7", "dataset8", "dataset9", "dataset10", "dataset11",
+ "dataset12", "dataset13", "dataset14", "dataset15", "dataset16", "dataset17",
+ "dataset18", "dataset19", "dataset20", "dataset21", "dataset22", "dataset23",
+ "dataset24", "dataset25", "dataset26", "dataset27", "dataset28", "dataset29",
+ "dataset30", "dataset31", "dataset32", "dataset33", "dataset34", "dataset35",
+ "dataset36", "dataset37", "dataset38", "dataset39", NULL};
herr_t create_standard_file(const char *filename, hid_t fcpl);
@@ -61,21 +45,24 @@ herr_t create_standard_file(const char *filename, hid_t fcpl);
*
*-------------------------------------------------------------------------
*/
-int main(void)
+int
+main(void)
{
- hid_t fcpl_id;
+ hid_t fcpl_id;
herr_t ret;
/* Create a file creation property list */
fcpl_id = H5Pcreate(H5P_FILE_CREATE);
- if(fcpl_id < 0) goto error;
+ if (fcpl_id < 0)
+ goto error;
/* The file creation property list is the default list right now.
* Create a file using it (this is the same as creating a file with
* H5P_DEFAULT). Implicit shared messages will be disabled.
*/
ret = create_standard_file("default_file.h5", fcpl_id);
- if(ret < 0) goto error;
+ if (ret < 0)
+ goto error;
/* There are five kinds of messages that can be shared: datatypes,
* dataspaces, attributes, fill values, and filter pipelines.
@@ -86,7 +73,8 @@ int main(void)
*/
/* To begin with, use only one index. */
ret = H5Pset_shared_mesg_nindexes(fcpl_id, 1);
- if(ret < 0) goto error;
+ if (ret < 0)
+ goto error;
/* Each index has a "minimum message size" for a message of that
* type to be shared. Since sharing a message creates some overhead,
@@ -111,7 +99,8 @@ int main(void)
* shared in this single index.
*/
ret = H5Pset_shared_mesg_index(fcpl_id, 0, H5O_SHMESG_ALL_FLAG, 40);
- if(ret < 0) goto error;
+ if (ret < 0)
+ goto error;
/* The other property that can be set for shared messages is the
* list/B-tree cutoff for the indexes.
@@ -120,7 +109,7 @@ int main(void)
* This keeps the indexes simple when only a few messages are shared,
* but allows them to scale for many messages. If many messages are
* deleted from the B-tree, it scales back down into a list.
- * A "resonable" setting for maximum list size and minimum btree size
+ * A "reasonable" setting for maximum list size and minimum btree size
* depends on what kinds of messages will be stored in the file.
* These numbers are the same for all indexes in a file.
* We'll guess at some numbers, though we could just as easily have kept
@@ -128,7 +117,8 @@ int main(void)
* second the minimum B-tree size.
*/
ret = H5Pset_shared_mesg_phase_change(fcpl_id, 30, 20);
- if(ret < 0) goto error;
+ if (ret < 0)
+ goto error;
/* Now create a file with this property list. After the FCPL is used,
* everything is automatic; messages will be shared and this will be
@@ -137,7 +127,8 @@ int main(void)
* written later.
*/
ret = create_standard_file("one_index_file.h5", fcpl_id);
- if(ret < 0) goto error;
+ if (ret < 0)
+ goto error;
/* Now try some variations on this. The FCPL hasn't been closed, so
* we don't need to re-create it.
@@ -147,36 +138,42 @@ int main(void)
* overhead).
*/
ret = H5Pset_shared_mesg_index(fcpl_id, 0, H5O_SHMESG_ALL_FLAG, 1000);
- if(ret < 0) goto error;
+ if (ret < 0)
+ goto error;
ret = create_standard_file("only_huge_mesgs_file.h5", fcpl_id);
- if(ret < 0) goto error;
-
+ if (ret < 0)
+ goto error;
/* Or, suppose we only wanted to shared dataspaces and
* attributes (which might make sense if we were going to use committed
* datatypes). We could change the flags on the index:
*/
ret = H5Pset_shared_mesg_index(fcpl_id, 0, H5O_SHMESG_SDSPACE_FLAG | H5O_SHMESG_ATTR_FLAG, 40);
- if(ret < 0) goto error;
+ if (ret < 0)
+ goto error;
ret = create_standard_file("only_dspaces_and_attrs_file.h5", fcpl_id);
- if(ret < 0) goto error;
-
+ if (ret < 0)
+ goto error;
/* We could create a second index and put attributes in it to separate them
* from datatypes and dataspaces (and then run some performance metrics to
* see whether this improved caching performance).
*/
ret = H5Pset_shared_mesg_nindexes(fcpl_id, 2);
- if(ret < 0) goto error;
+ if (ret < 0)
+ goto error;
ret = H5Pset_shared_mesg_index(fcpl_id, 0, H5O_SHMESG_DTYPE_FLAG | H5O_SHMESG_SDSPACE_FLAG, 40);
- if(ret < 0) goto error;
+ if (ret < 0)
+ goto error;
ret = H5Pset_shared_mesg_index(fcpl_id, 1, H5O_SHMESG_ATTR_FLAG, 40);
- if(ret < 0) goto error;
+ if (ret < 0)
+ goto error;
ret = create_standard_file("separate_indexes_file.h5", fcpl_id);
- if(ret < 0) goto error;
+ if (ret < 0)
+ goto error;
/* We can try twiddling the "phase change" values and see what it does to
* the file size. Since there's only a few different messages (two
@@ -184,25 +181,30 @@ int main(void)
* save some space.
*/
ret = H5Pset_shared_mesg_nindexes(fcpl_id, 1);
- if(ret < 0) goto error;
+ if (ret < 0)
+ goto error;
ret = H5Pset_shared_mesg_index(fcpl_id, 0, H5O_SHMESG_ALL_FLAG, 40);
- if(ret < 0) goto error;
+ if (ret < 0)
+ goto error;
ret = H5Pset_shared_mesg_phase_change(fcpl_id, 5, 0);
- if(ret < 0) goto error;
+ if (ret < 0)
+ goto error;
ret = create_standard_file("small_lists_file.h5", fcpl_id);
- if(ret < 0) goto error;
+ if (ret < 0)
+ goto error;
/* Or we could create indexes that are never lists, but are created as
* B-trees. We do this by setting the "maximum list size" to zero.
*/
ret = H5Pset_shared_mesg_phase_change(fcpl_id, 0, 0);
- if(ret < 0) goto error;
+ if (ret < 0)
+ goto error;
ret = create_standard_file("btrees_file.h5", fcpl_id);
- if(ret < 0) goto error;
-
+ if (ret < 0)
+ goto error;
/* Obviously there are a lot more permutations of these options possible.
* Performance will often be a tradeoff of speed for space, but will
@@ -212,10 +214,10 @@ int main(void)
* Please let The HDF Group (help@hdfgroup.org) know what you find!
*/
-
/* Close the property list */
ret = H5Pclose(fcpl_id);
- if(ret < 0) goto error;
+ if (ret < 0)
+ goto error;
return 0;
error:
@@ -225,7 +227,7 @@ error:
/*-------------------------------------------------------------------------
* Function: create_standard_file
*
- * Purpose: A helper functon for the example. Creates an HDF5 file
+ * Purpose: A helper function for the example. Creates an HDF5 file
* with many repeated messages using the file creation
* property list FCPL.
*
@@ -238,21 +240,22 @@ error:
herr_t
create_standard_file(const char *filename, hid_t fcpl_id)
{
- hid_t file_id=-1;
- hid_t type_id=-1, temp_type_id=-1;
- hsize_t dims[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
- hid_t space_id=-1;
- hid_t attr_type_id = -1;
- hid_t attr_space_id = -1;
- int attr_data[] = {1,2,3,4,5,6,7,8,9,0};
- hid_t dset_id=-1;
- hid_t attr_id=-1;
- int x;
- herr_t ret;
+ hid_t file_id = -1;
+ hid_t type_id = -1, temp_type_id = -1;
+ hsize_t dims[] = {10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
+ hid_t space_id = -1;
+ hid_t attr_type_id = -1;
+ hid_t attr_space_id = -1;
+ int attr_data[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 0};
+ hid_t dset_id = -1;
+ hid_t attr_id = -1;
+ int x;
+ herr_t ret;
/* Create the file */
file_id = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl_id, H5P_DEFAULT);
- if(file_id < 0) goto error;
+ if (file_id < 0)
+ goto error;
/* Create the datatype we'll be using. Generally, sharing messages
* is most useful when the message is complex and takes more space on
@@ -260,66 +263,80 @@ create_standard_file(const char *filename, hid_t fcpl_id)
* However, any type can be shared.
*/
temp_type_id = H5Tarray_create2(H5T_NATIVE_INT, 2, dims);
- if(temp_type_id < 0) goto error;
- type_id = H5Tarray_create2(temp_type_id, 2, dims);
- if(type_id < 0) goto error;
+ if (temp_type_id < 0)
+ goto error;
+ type_id = H5Tarray_create2(temp_type_id, 2, dims);
+ if (type_id < 0)
+ goto error;
ret = H5Tclose(temp_type_id);
- if(ret < 0) goto error;
+ if (ret < 0)
+ goto error;
/* Create the dataspace we'll be using.
* Again, create a more complex dataspace so that more space will
* be saved when we share it.
*/
space_id = H5Screate_simple(10, dims, dims);
- if(space_id < 0) goto error;
+ if (space_id < 0)
+ goto error;
/* Create a datatype and dataspace for the attributes we'll be creating.
* The datatype will be a single integer, and each attribute will hold
* 10 integers.
*/
attr_type_id = H5Tcopy(H5T_NATIVE_INT);
- if(attr_type_id < 0) goto error;
+ if (attr_type_id < 0)
+ goto error;
attr_space_id = H5Screate_simple(1, dims, dims);
- if(attr_space_id < 0) goto error;
-
+ if (attr_space_id < 0)
+ goto error;
/* Begin using the messages many times. Do this by creating datasets
* that use this datatype, dataspace, and have this attribute.
*/
- for(x = 0; x < NUM_DATASETS; ++x) {
- /* Create a dataset */
- dset_id = H5Dcreate2(file_id, DSETNAME[x], type_id, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
- if(dset_id < 0) goto error;
-
- /* Create an attribute on the dataset */
- attr_id = H5Acreate2(dset_id, "attr_name", attr_type_id, attr_space_id, H5P_DEFAULT, H5P_DEFAULT);
- if(attr_id < 0) goto error;
-
- /* Write data to the attribute */
- ret = H5Awrite(attr_id, H5T_NATIVE_INT, attr_data);
- if(ret < 0) goto error;
-
- ret = H5Aclose(attr_id);
- if(ret < 0) goto error;
- ret = H5Dclose(dset_id);
- if(ret < 0) goto error;
+ for (x = 0; x < NUM_DATASETS; ++x) {
+ /* Create a dataset */
+ dset_id = H5Dcreate2(file_id, DSETNAME[x], type_id, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ if (dset_id < 0)
+ goto error;
+
+ /* Create an attribute on the dataset */
+ attr_id = H5Acreate2(dset_id, "attr_name", attr_type_id, attr_space_id, H5P_DEFAULT, H5P_DEFAULT);
+ if (attr_id < 0)
+ goto error;
+
+ /* Write data to the attribute */
+ ret = H5Awrite(attr_id, H5T_NATIVE_INT, attr_data);
+ if (ret < 0)
+ goto error;
+
+ ret = H5Aclose(attr_id);
+ if (ret < 0)
+ goto error;
+ ret = H5Dclose(dset_id);
+ if (ret < 0)
+ goto error;
}
/* Close all open IDs */
ret = H5Tclose(attr_type_id);
- if(ret < 0) goto error;
+ if (ret < 0)
+ goto error;
ret = H5Sclose(attr_space_id);
- if(ret < 0) goto error;
+ if (ret < 0)
+ goto error;
ret = H5Tclose(type_id);
- if(ret < 0) goto error;
+ if (ret < 0)
+ goto error;
ret = H5Sclose(space_id);
- if(ret < 0) goto error;
+ if (ret < 0)
+ goto error;
ret = H5Fclose(file_id);
- if(ret < 0) goto error;
+ if (ret < 0)
+ goto error;
return 0;
error:
return -1;
}
-
diff --git a/examples/h5_subset.c b/examples/h5_subset.c
index 904d3f8..3580046 100644
--- a/examples/h5_subset.c
+++ b/examples/h5_subset.c
@@ -6,102 +6,97 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-/*
- * This example illustrates how to read/write a subset of data (a slab)
+/*
+ * This example illustrates how to read/write a subset of data (a slab)
* from/to a dataset in an HDF5 file. It is used in the HDF5 Tutorial.
*/
-
+
#include "hdf5.h"
#define FILE "subset.h5"
-#define DATASETNAME "IntArray"
-#define RANK 2
-
-#define DIM0_SUB 3 /* subset dimensions */
-#define DIM1_SUB 4
+#define DATASETNAME "IntArray"
+#define RANK 2
+#define DIM0_SUB 3 /* subset dimensions */
+#define DIM1_SUB 4
-#define DIM0 8 /* size of dataset */
-#define DIM1 10
+#define DIM0 8 /* size of dataset */
+#define DIM1 10
int
-main (void)
+main(void)
{
- hsize_t dims[2], dimsm[2];
- int data[DIM0][DIM1]; /* data to write */
- int sdata[DIM0_SUB][DIM1_SUB]; /* subset to write */
- int rdata[DIM0][DIM1]; /* buffer for read */
-
- hid_t file_id, dataset_id; /* handles */
- hid_t dataspace_id, memspace_id;
-
- herr_t status;
-
- hsize_t count[2]; /* size of subset in the file */
- hsize_t offset[2]; /* subset offset in the file */
- hsize_t stride[2];
- hsize_t block[2];
- int i, j;
-
-
+ hsize_t dims[2], dimsm[2];
+ int data[DIM0][DIM1]; /* data to write */
+ int sdata[DIM0_SUB][DIM1_SUB]; /* subset to write */
+ int rdata[DIM0][DIM1]; /* buffer for read */
+
+ hid_t file_id, dataset_id; /* handles */
+ hid_t dataspace_id, memspace_id;
+
+ herr_t status;
+
+ hsize_t count[2]; /* size of subset in the file */
+ hsize_t offset[2]; /* subset offset in the file */
+ hsize_t stride[2];
+ hsize_t block[2];
+ int i, j;
+
/*****************************************************************
* Create a new file with default creation and access properties.*
* Then create a dataset and write data to it and close the file *
* and dataset. *
*****************************************************************/
- file_id = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
-
- dims[0] = DIM0;
- dims[1] = DIM1;
- dataspace_id = H5Screate_simple (RANK, dims, NULL);
+ file_id = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
- dataset_id = H5Dcreate2 (file_id, DATASETNAME, H5T_STD_I32BE, dataspace_id,
- H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ dims[0] = DIM0;
+ dims[1] = DIM1;
+ dataspace_id = H5Screate_simple(RANK, dims, NULL);
+ dataset_id =
+ H5Dcreate2(file_id, DATASETNAME, H5T_STD_I32BE, dataspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
for (j = 0; j < DIM0; j++) {
- for (i = 0; i < DIM1; i++)
- if (i< (DIM1/2))
- data[j][i] = 1;
+ for (i = 0; i < DIM1; i++)
+ if (i < (DIM1 / 2))
+ data[j][i] = 1;
else
- data[j][i] = 2;
- }
+ data[j][i] = 2;
+ }
- status = H5Dwrite (dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL,
- H5P_DEFAULT, data);
+ status = H5Dwrite(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
- printf ("\nData Written to File:\n");
- for (i = 0; i<DIM0; i++){
- for (j = 0; j<DIM1; j++)
- printf (" %i", data[i][j]);
- printf ("\n");
+ printf("\nData Written to File:\n");
+ for (i = 0; i < DIM0; i++) {
+ for (j = 0; j < DIM1; j++)
+ printf(" %i", data[i][j]);
+ printf("\n");
}
- status = H5Sclose (dataspace_id);
- status = H5Dclose (dataset_id);
- status = H5Fclose (file_id);
-
+ status = H5Sclose(dataspace_id);
+ status = H5Dclose(dataset_id);
+ status = H5Fclose(file_id);
/*****************************************************
* Reopen the file and dataset and write a subset of *
- * values to the dataset.
+ * values to the dataset.
*****************************************************/
- file_id = H5Fopen (FILE, H5F_ACC_RDWR, H5P_DEFAULT);
- dataset_id = H5Dopen2 (file_id, DATASETNAME, H5P_DEFAULT);
+ file_id = H5Fopen(FILE, H5F_ACC_RDWR, H5P_DEFAULT);
+ dataset_id = H5Dopen2(file_id, DATASETNAME, H5P_DEFAULT);
/* Specify size and shape of subset to write. */
offset[0] = 1;
offset[1] = 2;
- count[0] = DIM0_SUB;
- count[1] = DIM1_SUB;
+ count[0] = DIM0_SUB;
+ count[1] = DIM1_SUB;
stride[0] = 1;
stride[1] = 1;
@@ -109,43 +104,39 @@ main (void)
block[0] = 1;
block[1] = 1;
- /* Create memory space with size of subset. Get file dataspace
+ /* Create memory space with size of subset. Get file dataspace
and select subset from file dataspace. */
- dimsm[0] = DIM0_SUB;
- dimsm[1] = DIM1_SUB;
- memspace_id = H5Screate_simple (RANK, dimsm, NULL);
+ dimsm[0] = DIM0_SUB;
+ dimsm[1] = DIM1_SUB;
+ memspace_id = H5Screate_simple(RANK, dimsm, NULL);
- dataspace_id = H5Dget_space (dataset_id);
- status = H5Sselect_hyperslab (dataspace_id, H5S_SELECT_SET, offset,
- stride, count, block);
+ dataspace_id = H5Dget_space(dataset_id);
+ status = H5Sselect_hyperslab(dataspace_id, H5S_SELECT_SET, offset, stride, count, block);
- /* Write a subset of data to the dataset, then read the
+ /* Write a subset of data to the dataset, then read the
entire dataset back from the file. */
- printf ("\nWrite subset to file specifying:\n");
- printf (" offset=1x2 stride=1x1 count=3x4 block=1x1\n");
+ printf("\nWrite subset to file specifying:\n");
+ printf(" offset=1x2 stride=1x1 count=3x4 block=1x1\n");
for (j = 0; j < DIM0_SUB; j++) {
- for (i = 0; i < DIM1_SUB; i++)
- sdata[j][i] = 5;
- }
-
- status = H5Dwrite (dataset_id, H5T_NATIVE_INT, memspace_id,
- dataspace_id, H5P_DEFAULT, sdata);
-
- status = H5Dread (dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL,
- H5P_DEFAULT, rdata);
-
- printf ("\nData in File after Subset is Written:\n");
- for (i = 0; i<DIM0; i++){
- for (j = 0; j<DIM1; j++)
- printf (" %i", rdata[i][j]);
- printf ("\n");
+ for (i = 0; i < DIM1_SUB; i++)
+ sdata[j][i] = 5;
+ }
+
+ status = H5Dwrite(dataset_id, H5T_NATIVE_INT, memspace_id, dataspace_id, H5P_DEFAULT, sdata);
+
+ status = H5Dread(dataset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rdata);
+
+ printf("\nData in File after Subset is Written:\n");
+ for (i = 0; i < DIM0; i++) {
+ for (j = 0; j < DIM1; j++)
+ printf(" %i", rdata[i][j]);
+ printf("\n");
}
- status = H5Sclose (memspace_id);
- status = H5Sclose (dataspace_id);
- status = H5Dclose (dataset_id);
- status = H5Fclose (file_id);
-
+ status = H5Sclose(memspace_id);
+ status = H5Sclose(dataspace_id);
+ status = H5Dclose(dataset_id);
+ status = H5Fclose(file_id);
}
diff --git a/examples/h5_vds-eiger.c b/examples/h5_vds-eiger.c
index 13b5d93..281db3c 100644
--- a/examples/h5_vds-eiger.c
+++ b/examples/h5_vds-eiger.c
@@ -5,14 +5,14 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example illustrates the concept of the virtual dataset.
- Eiger use case. Every 5 frames 10x10 are in the source
+ Eiger use case. Every 5 frames 10x10 are in the source
dataset "/A" in file with the name f-<#>.h5
This file is intended for use with HDF5 Library version 1.10
@@ -23,85 +23,73 @@
#include <stdio.h>
#include <stdlib.h>
-#define FILE "vds-eiger.h5"
-#define DATASET "VDS-Eiger"
-#define VDSDIM0 5
-#define VDSDIM1 10
-#define VDSDIM2 10
-#define DIM0 5
-#define DIM1 10
-#define DIM2 10
-#define RANK 3
+#define FILE "vds-eiger.h5"
+#define DATASET "VDS-Eiger"
+#define VDSDIM0 5
+#define VDSDIM1 10
+#define VDSDIM2 10
+#define DIM0 5
+#define DIM1 10
+#define DIM2 10
+#define RANK 3
int
-main (void)
+main(void)
{
- hid_t file, src_space, vspace,
- dset; /* Handles */
- hid_t dcpl;
- herr_t status;
- hsize_t vdsdims[3] = {VDSDIM0, VDSDIM1, VDSDIM2},
- vdsdims_max[3] = {H5S_UNLIMITED, VDSDIM1, VDSDIM1},
- dims[3] = {DIM0, DIM1, DIM2},
- start[3], /* Hyperslab parameters */
- stride[3],
- count[3],
- block[3];
- hsize_t start_out[3], /* Hyperslab parameter out */
- stride_out[3],
- count_out[3],
- block_out[3];
+ hid_t file, src_space, vspace, dset; /* Handles */
+ hid_t dcpl;
+ herr_t status;
+ hsize_t vdsdims[3] = {VDSDIM0, VDSDIM1, VDSDIM2}, vdsdims_max[3] = {H5S_UNLIMITED, VDSDIM1, VDSDIM1},
+ dims[3] = {DIM0, DIM1, DIM2}, start[3], /* Hyperslab parameters */
+ stride[3], count[3], block[3];
+ hsize_t start_out[3], /* Hyperslab parameter out */
+ stride_out[3], count_out[3], block_out[3];
int i;
- 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;
+ 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;
-
- file = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ file = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create VDS dataspace. */
- vspace = H5Screate_simple (RANK, vdsdims, vdsdims_max);
+ vspace = H5Screate_simple(RANK, vdsdims, vdsdims_max);
/* Create dataspaces for the source dataset. */
- src_space = H5Screate_simple (RANK, dims, NULL);
+ src_space = H5Screate_simple(RANK, dims, NULL);
/* Create VDS creation property */
- dcpl = H5Pcreate (H5P_DATASET_CREATE);
-
+ dcpl = H5Pcreate(H5P_DATASET_CREATE);
+
/* Initialize hyperslab values */
- start[0] = 0;
- start[1] = 0;
- start[2] = 0;
+ start[0] = 0;
+ start[1] = 0;
+ start[2] = 0;
stride[0] = DIM0;
stride[1] = 1;
stride[2] = 1;
- count[0] = H5S_UNLIMITED;
- count[1] = 1;
- count[2] = 1;
- block[0] = DIM0;
- block[1] = DIM1;
- block[2] = DIM2;
-
- /*
- * Build the mappings
- *
- */
- status = H5Sselect_hyperslab (vspace, H5S_SELECT_SET, start, stride, count, block);
- status = H5Pset_virtual (dcpl, vspace, "f-%b.h5", "/A", src_space);
-
-
-
- /* Create a virtual dataset */
- dset = H5Dcreate2 (file, DATASET, H5T_NATIVE_INT, vspace, H5P_DEFAULT,
- dcpl, H5P_DEFAULT);
- status = H5Sclose (vspace);
- status = H5Sclose (src_space);
- status = H5Dclose (dset);
- status = H5Fclose (file);
-
+ count[0] = H5S_UNLIMITED;
+ count[1] = 1;
+ count[2] = 1;
+ block[0] = DIM0;
+ block[1] = DIM1;
+ block[2] = DIM2;
+
+ /*
+ * Build the mappings
+ *
+ */
+ status = H5Sselect_hyperslab(vspace, H5S_SELECT_SET, start, stride, count, block);
+ status = H5Pset_virtual(dcpl, vspace, "f-%b.h5", "/A", src_space);
+
+ /* Create a virtual dataset */
+ dset = H5Dcreate2(file, DATASET, H5T_NATIVE_INT, vspace, H5P_DEFAULT, dcpl, H5P_DEFAULT);
+ status = H5Sclose(vspace);
+ status = H5Sclose(src_space);
+ status = H5Dclose(dset);
+ status = H5Fclose(file);
/*
* Now we begin the read section of this example.
@@ -110,79 +98,82 @@ main (void)
/*
* Open file and dataset using the default properties.
*/
- file = H5Fopen (FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
- dset = H5Dopen2 (file, DATASET, H5P_DEFAULT);
+ file = H5Fopen(FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
+ dset = H5Dopen2(file, DATASET, H5P_DEFAULT);
/*
* Get creation property list and mapping properties.
*/
- dcpl = H5Dget_create_plist (dset);
+ dcpl = H5Dget_create_plist(dset);
/*
* Get storage layout.
*/
- layout = H5Pget_layout (dcpl);
+ layout = H5Pget_layout(dcpl);
- if (H5D_VIRTUAL == layout)
+ 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", (int)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");
- /* Get selection in the virttual dataset */
- 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 ");
- src_space = H5Pget_virtual_srcspace (dcpl, (size_t)i);
- if(H5Sget_select_type(src_space) == H5S_SEL_ALL) {
- printf("H5S_ALL \n");
- }
-/* EIP read data back */
- H5Sclose(vspace);
- H5Sclose(src_space);
- free(filename);
- free(dsetname);
- }
+ /*
+ * Find number of mappings.
+ */
+ status = H5Pget_virtual_count(dcpl, &num_map);
+ printf(" Number of mappings is %d\n", (int)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");
+ /* Get selection in the virttual dataset */
+ 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 ");
+ src_space = H5Pget_virtual_srcspace(dcpl, (size_t)i);
+ if (H5Sget_select_type(src_space) == H5S_SEL_ALL) {
+ printf("H5S_ALL \n");
+ }
+ /* EIP read data back */
+ H5Sclose(vspace);
+ H5Sclose(src_space);
+ free(filename);
+ free(dsetname);
+ }
/*
* Close and release resources.
*/
- status = H5Pclose (dcpl);
- status = H5Dclose (dset);
- status = H5Fclose (file);
+ status = H5Pclose(dcpl);
+ status = H5Dclose(dset);
+ status = H5Fclose(file);
return 0;
}
-
diff --git a/examples/h5_vds-exc.c b/examples/h5_vds-exc.c
index aaf1fa8..00b8c6b 100644
--- a/examples/h5_vds-exc.c
+++ b/examples/h5_vds-exc.c
@@ -5,7 +5,7 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -22,81 +22,56 @@
#include <stdio.h>
#include <stdlib.h>
-#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"
-};
+#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"};
int
-main (void)
+main(void)
{
- 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 */
- stride[3],
- count[3],
- block[3];
- hsize_t start_out[3],
- stride_out[3],
- count_out[3],
- block_out[3];
+ 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 */
+ stride[3], count[3], block[3];
+ hsize_t start_out[3], stride_out[3], count_out[3], block_out[3];
int k = 2;
int n = 3;
int i;
- 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;
+ 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;
-
- file = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ file = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create VDS dataspace. */
- space = H5Screate_simple (RANK, vdsdims, vdsdims_max);
+ space = H5Screate_simple(RANK, vdsdims, vdsdims_max);
/* Create dataspaces for A, C, and E datasets. */
- ksrc_space = H5Screate_simple (RANK, kdims, kdims_max);
+ ksrc_space = H5Screate_simple(RANK, kdims, kdims_max);
/* Create dataspaces for B, D, and F datasets. */
- nsrc_space = H5Screate_simple (RANK, ndims, ndims_max);
+ nsrc_space = H5Screate_simple(RANK, ndims, ndims_max);
/* Create VDS creation property */
- dcpl = H5Pcreate (H5P_DATASET_CREATE);
-
+ dcpl = H5Pcreate(H5P_DATASET_CREATE);
+
/* Initialize hyperslab values */
start[0] = 0;
@@ -109,42 +84,40 @@ main (void)
block[1] = k;
block[2] = VDSDIM2;
- /*
- * 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);
-
+ /*
+ * 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);
/*
* Now we begin the read section of this example.
@@ -153,85 +126,92 @@ main (void)
/*
* Open file and dataset using the default properties.
*/
- file = H5Fopen (FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
- dset = H5Dopen2 (file, DATASET, H5P_DEFAULT);
+ file = H5Fopen(FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
+ dset = H5Dopen2(file, DATASET, H5P_DEFAULT);
/*
* Get creation property list and mapping properties.
*/
- dcpl = H5Dget_create_plist (dset);
+ dcpl = H5Dget_create_plist(dset);
/*
* Get storage layout.
*/
- layout = H5Pget_layout (dcpl);
+ layout = H5Pget_layout(dcpl);
- if (H5D_VIRTUAL == layout)
+ 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 %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");
- /* Get selection in the virttual dataset */
- 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 */
+ /*
+ * 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");
+ /* Get selection in the virttual dataset */
+ 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 */
/*
* Close and release resources.
*/
- status = H5Pclose (dcpl);
- status = H5Dclose (dset);
- status = H5Fclose (file);
+ status = H5Pclose(dcpl);
+ status = H5Dclose(dset);
+ status = H5Fclose(file);
return 0;
}
-
diff --git a/examples/h5_vds-exclim.c b/examples/h5_vds-exclim.c
index fea096a..c90941d 100644
--- a/examples/h5_vds-exclim.c
+++ b/examples/h5_vds-exclim.c
@@ -5,7 +5,7 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -23,78 +23,54 @@
#include <stdio.h>
#include <stdlib.h>
-#define FILE "vds-exclim.h5"
-#define DATASET "VDS-Excaliburlim"
-#define VDSDIM0 3
-#define VDSDIM1 15
-#define VDSDIM2 6
-#define KDIM0 3
-#define KDIM1 2
-#define KDIM2 6
-#define NDIM0 3
-#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"
-};
+#define FILE "vds-exclim.h5"
+#define DATASET "VDS-Excaliburlim"
+#define VDSDIM0 3
+#define VDSDIM1 15
+#define VDSDIM2 6
+#define KDIM0 3
+#define KDIM1 2
+#define KDIM2 6
+#define NDIM0 3
+#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"};
int
-main (void)
+main(void)
{
- 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},
- kdims[3] = {KDIM0, KDIM1, KDIM2},
- ndims[3] = {NDIM0, NDIM1, NDIM2},
- start[3], /* Hyperslab parameters */
- stride[3],
- count[3],
- block[3];
- hsize_t start_out[3],
- stride_out[3],
- count_out[3],
- block_out[3];
+ 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}, kdims[3] = {KDIM0, KDIM1, KDIM2},
+ ndims[3] = {NDIM0, NDIM1, NDIM2}, start[3], /* Hyperslab parameters */
+ stride[3], count[3], block[3];
+ hsize_t start_out[3], stride_out[3], count_out[3], block_out[3];
int k = 2;
int n = 3;
int i;
- 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;
+ 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;
-
- file = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ file = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create VDS dataspace. */
- space = H5Screate_simple (RANK, vdsdims, NULL);
+ space = H5Screate_simple(RANK, vdsdims, NULL);
/* Create dataspaces for A, C, and E datasets. */
- ksrc_space = H5Screate_simple (RANK, kdims, NULL);
+ ksrc_space = H5Screate_simple(RANK, kdims, NULL);
/* Create dataspaces for B, D, and F datasets. */
- nsrc_space = H5Screate_simple (RANK, ndims, NULL);
+ nsrc_space = H5Screate_simple(RANK, ndims, NULL);
/* Create VDS creation property */
- dcpl = H5Pcreate (H5P_DATASET_CREATE);
-
+ dcpl = H5Pcreate(H5P_DATASET_CREATE);
+
/* Initialize hyperslab values */
start[0] = 0;
@@ -107,40 +83,38 @@ main (void)
block[1] = k;
block[2] = VDSDIM2;
- /*
- * Build the mappings for A, C and E source datasets.
- *
- */
- 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[0] and block[1] */
- start[0] = 0;
- block[1] = n;
- /*
- * Build the mappings for B, D and F source datasets.
- *
- */
- 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);
-
+ /*
+ * Build the mappings for A, C and E source datasets.
+ *
+ */
+ 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[0] and block[1] */
+ start[0] = 0;
+ block[1] = n;
+ /*
+ * Build the mappings for B, D and F source datasets.
+ *
+ */
+ 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);
/*
* Now we begin the read section of this example.
@@ -149,85 +123,92 @@ main (void)
/*
* Open file and dataset using the default properties.
*/
- file = H5Fopen (FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
- dset = H5Dopen2 (file, DATASET, H5P_DEFAULT);
+ file = H5Fopen(FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
+ dset = H5Dopen2(file, DATASET, H5P_DEFAULT);
/*
* Get creation property list and mapping properties.
*/
- dcpl = H5Dget_create_plist (dset);
+ dcpl = H5Dget_create_plist(dset);
/*
* Get storage layout.
*/
- layout = H5Pget_layout (dcpl);
+ layout = H5Pget_layout(dcpl);
- if (H5D_VIRTUAL == layout)
+ 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 %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");
- /* Get selection in the virttual dataset */
- 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 (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]);
- }
- }
- H5Sclose(vspace);
- H5Sclose(src_space);
- free(filename);
- free(dsetname);
- }
-/* EIP read data back */
+ /*
+ * 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");
+ /* Get selection in the virttual dataset */
+ 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(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]);
+ }
+ }
+ H5Sclose(vspace);
+ H5Sclose(src_space);
+ free(filename);
+ free(dsetname);
+ }
+ /* EIP read data back */
/*
* Close and release resources.
*/
- status = H5Pclose (dcpl);
- status = H5Dclose (dset);
- status = H5Fclose (file);
+ status = H5Pclose(dcpl);
+ status = H5Dclose(dset);
+ status = H5Fclose(file);
return 0;
}
-
diff --git a/examples/h5_vds-percival-unlim-maxmin.c b/examples/h5_vds-percival-unlim-maxmin.c
index 0273bbc..f459c20 100644
--- a/examples/h5_vds-percival-unlim-maxmin.c
+++ b/examples/h5_vds-percival-unlim-maxmin.c
@@ -5,15 +5,15 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
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.
+ Percival use case. Every fifth 10x10 plane in VDS is stored in
+ the corresponding 3D unlimited dataset.
There are 4 source datasets total.
Each of the source datasets is extended to different sizes.
VDS access property can be used to get max and min extent.
@@ -26,186 +26,163 @@
#include <stdio.h>
#include <stdlib.h>
-#define VFILE "vds-percival-unlim-maxmin.h5"
-#define DATASET "VDS-Percival-unlim-maxmin"
-#define VDSDIM0 H5S_UNLIMITED
-#define VDSDIM1 10
-#define VDSDIM2 10
-
-#define DIM0 H5S_UNLIMITED
-#define DIM0_1 4 /* Initial size of the source 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"
-};
+#define VFILE "vds-percival-unlim-maxmin.h5"
+#define DATASET "VDS-Percival-unlim-maxmin"
+#define VDSDIM0 H5S_UNLIMITED
+#define VDSDIM1 10
+#define VDSDIM2 10
+
+#define DIM0 H5S_UNLIMITED
+#define DIM0_1 4 /* Initial size of the source 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)
+main(void)
{
- hid_t vfile, file, src_space, mem_space, vspace,
- vdset, dset; /* Handles */
- hid_t dcpl, dapl;
- herr_t status;
- hsize_t vdsdims[3] = {4*DIM0_1, VDSDIM1, VDSDIM2},
- vdsdims_max[3] = {VDSDIM0, VDSDIM1, VDSDIM2},
- dims[3] = {DIM0_1, DIM1, DIM2},
- memdims[3] = {DIM0_1, DIM1, DIM2},
- extdims[3] = {0, DIM1, DIM2}, /* Dimensions of the extended source datasets */
- 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];
+ hid_t vfile, file, src_space, mem_space, vspace, vdset, dset; /* Handles */
+ hid_t dcpl, dapl;
+ herr_t status;
+ hsize_t vdsdims[3] = {4 * DIM0_1, VDSDIM1, VDSDIM2}, vdsdims_max[3] = {VDSDIM0, VDSDIM1, VDSDIM2},
+ dims[3] = {DIM0_1, DIM1, DIM2}, memdims[3] = {DIM0_1, DIM1, DIM2},
+ extdims[3] = {0, DIM1, DIM2}, /* Dimensions of the extended source datasets */
+ 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];
+ 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++) {
+ 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;
+ 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
+ * 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 = H5Dcreate2 (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);
- }
-
- vfile = H5Fcreate (VFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ 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 = H5Dcreate2(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);
+ }
+
+ vfile = H5Fcreate(VFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create VDS dataspace. */
- vspace = H5Screate_simple (RANK, vdsdims, vdsdims_max);
+ vspace = H5Screate_simple(RANK, vdsdims, vdsdims_max);
/* Create dataspaces for the source dataset. */
- src_space = H5Screate_simple (RANK, dims, dims_max);
+ src_space = H5Screate_simple(RANK, dims, dims_max);
/* Create VDS creation property */
- dcpl = H5Pcreate (H5P_DATASET_CREATE);
-
+ 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;
+ 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;
+ block[0] = 1;
+ block[1] = DIM1;
+ block[2] = DIM2;
- /*
- * Build the mappings
+ /*
+ * 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]++;
- }
+ 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);
+ H5Sselect_none(vspace);
/* Create a virtual dataset */
- vdset = H5Dcreate2 (vfile, DATASET, H5T_NATIVE_INT, vspace, H5P_DEFAULT,
- dcpl, H5P_DEFAULT);
- status = H5Sclose (vspace);
- status = H5Sclose (src_space);
- status = H5Pclose (dcpl);
+ vdset = H5Dcreate2(vfile, DATASET, H5T_NATIVE_INT, vspace, H5P_DEFAULT, dcpl, H5P_DEFAULT);
+ status = H5Sclose(vspace);
+ status = H5Sclose(src_space);
+ status = H5Pclose(dcpl);
/* Let's add data to the source datasets and check new dimensions for VDS */
/* We will add only one plane to the first source dataset, two planes to the
second one, three to the third, and four to the forth. */
- for (i=0; i < PLANE_STRIDE; i++) {
+ for (i = 0; i < PLANE_STRIDE; i++) {
/*
* Initialize data for i-th source dataset.
*/
- for (j = 0; j < (i+1)*DIM1*DIM2; j++) wdata[j] = 10*(i+1);
+ for (j = 0; j < (i + 1) * DIM1 * DIM2; j++)
+ wdata[j] = 10 * (i + 1);
/*
- * Open the source files and datasets. Appen data to each dataset and
+ * Open the source files and datasets. Append data to each dataset and
* close all resources.
*/
- file = H5Fopen (SRC_FILE[i], H5F_ACC_RDWR, H5P_DEFAULT);
- dset = H5Dopen2 (file, SRC_DATASET[i], H5P_DEFAULT);
- extdims[0] = DIM0_1+i+1;
- status = H5Dset_extent (dset, extdims);
- src_space = H5Dget_space (dset);
- start[0] = DIM0_1;
- start[1] = 0;
- start[2] = 0;
- count[0] = 1;
- count[1] = 1;
- count[2] = 1;
- block[0] = i+1;
- block[1] = DIM1;
- block[2] = DIM2;
-
- memdims[0] = i+1;
- mem_space = H5Screate_simple(RANK, memdims, NULL);
- status = H5Sselect_hyperslab (src_space, H5S_SELECT_SET, start, NULL, count, block);
- status = H5Dwrite (dset, H5T_NATIVE_INT, mem_space, src_space, H5P_DEFAULT,
- wdata);
- status = H5Sclose (src_space);
- status = H5Dclose (dset);
- status = H5Fclose (file);
- }
-
- status = H5Dclose (vdset);
- status = H5Fclose (vfile);
-
+ file = H5Fopen(SRC_FILE[i], H5F_ACC_RDWR, H5P_DEFAULT);
+ dset = H5Dopen2(file, SRC_DATASET[i], H5P_DEFAULT);
+ extdims[0] = DIM0_1 + i + 1;
+ status = H5Dset_extent(dset, extdims);
+ src_space = H5Dget_space(dset);
+ start[0] = DIM0_1;
+ start[1] = 0;
+ start[2] = 0;
+ count[0] = 1;
+ count[1] = 1;
+ count[2] = 1;
+ block[0] = i + 1;
+ block[1] = DIM1;
+ block[2] = DIM2;
+
+ memdims[0] = i + 1;
+ mem_space = H5Screate_simple(RANK, memdims, NULL);
+ status = H5Sselect_hyperslab(src_space, H5S_SELECT_SET, start, NULL, count, block);
+ status = H5Dwrite(dset, H5T_NATIVE_INT, mem_space, src_space, H5P_DEFAULT, wdata);
+ status = H5Sclose(src_space);
+ status = H5Dclose(dset);
+ status = H5Fclose(file);
+ }
+
+ status = H5Dclose(vdset);
+ status = H5Fclose(vfile);
+
/*
* Now we begin the read section of this example.
*/
@@ -213,108 +190,115 @@ main (void)
/*
* Open file and dataset using the default properties.
*/
- vfile = H5Fopen (VFILE, H5F_ACC_RDONLY, H5P_DEFAULT);
-
- /*
+ vfile = H5Fopen(VFILE, H5F_ACC_RDONLY, H5P_DEFAULT);
+
+ /*
* Open VDS using different access properties to use max or
* min extents depending on the sizes of the underlying datasets
*/
- dapl = H5Pcreate (H5P_DATASET_ACCESS);
+ dapl = H5Pcreate(H5P_DATASET_ACCESS);
- for(i = 0; i < 2; i++) {
- status = H5Pset_virtual_view (dapl, i ? H5D_VDS_LAST_AVAILABLE : H5D_VDS_FIRST_MISSING);
- vdset = H5Dopen2 (vfile, DATASET, dapl);
+ for (i = 0; i < 2; i++) {
+ status = H5Pset_virtual_view(dapl, i ? H5D_VDS_LAST_AVAILABLE : H5D_VDS_FIRST_MISSING);
+ vdset = H5Dopen2(vfile, DATASET, dapl);
/* Let's get space of the VDS and its dimension; we should get 32(or 20)x10x10 */
- vspace = H5Dget_space (vdset);
- H5Sget_simple_extent_dims (vspace, vdsdims_out, vdsdims_max_out);
- printf ("VDS dimensions, bounds = H5D_VDS_%s: ", i ? "LAST_AVAILABLE" : "FIRST_MISSING");
- for (j=0; j<RANK; j++)
- printf (" %d ", (int)vdsdims_out[j]);
- printf ("\n");
+ vspace = H5Dget_space(vdset);
+ H5Sget_simple_extent_dims(vspace, vdsdims_out, vdsdims_max_out);
+ printf("VDS dimensions, bounds = H5D_VDS_%s: ", i ? "LAST_AVAILABLE" : "FIRST_MISSING");
+ for (j = 0; j < RANK; j++)
+ printf(" %d ", (int)vdsdims_out[j]);
+ printf("\n");
/* Close */
- status = H5Dclose (vdset);
- status = H5Sclose (vspace);
+ status = H5Dclose(vdset);
+ status = H5Sclose(vspace);
}
- status = H5Pclose (dapl);
+ status = H5Pclose(dapl);
- vdset = H5Dopen2 (vfile, DATASET, H5P_DEFAULT);
+ vdset = H5Dopen2(vfile, DATASET, H5P_DEFAULT);
/*
* Get creation property list and mapping properties.
*/
- dcpl = H5Dget_create_plist (vdset);
+ dcpl = H5Dget_create_plist(vdset);
/*
* Get storage layout.
*/
- layout = H5Pget_layout (dcpl);
+ layout = H5Pget_layout(dcpl);
- if (H5D_VIRTUAL == layout)
+ 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 %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");
- /* Get selection in the virttual dataset */
- 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(src_space)) {
- 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);
- }
+ /*
+ * 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");
+ /* Get selection in the virttual dataset */
+ 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(src_space)) {
+ 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);
+ }
/*
* Close and release resources.
*/
- status = H5Pclose (dcpl);
- status = H5Dclose (vdset);
- status = H5Fclose (vfile);
+ status = H5Pclose(dcpl);
+ status = H5Dclose(vdset);
+ status = H5Fclose(vfile);
return 0;
}
-
diff --git a/examples/h5_vds-percival-unlim.c b/examples/h5_vds-percival-unlim.c
index f6a5f50..a4c853d 100644
--- a/examples/h5_vds-percival-unlim.c
+++ b/examples/h5_vds-percival-unlim.c
@@ -5,15 +5,15 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
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.
+ 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
@@ -24,191 +24,168 @@
#include <stdio.h>
#include <stdlib.h>
-#define VFILE "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"
-};
+#define VFILE "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)
+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];
+ 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, k;
- 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];
+ 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];
int rdata[80][10][10];
int a_rdata[20][10][10];
/*
* Create source files and datasets. This step is optional.
*/
- for (i=0; i < PLANE_STRIDE; i++) {
+ 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;
+ 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
+ * 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 = H5Dcreate2 (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);
- }
-
- vfile = H5Fcreate (VFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ 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 = H5Dcreate2(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);
+ }
+
+ vfile = H5Fcreate(VFILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create VDS dataspace. */
- vspace = H5Screate_simple (RANK, vdsdims, vdsdims_max);
+ vspace = H5Screate_simple(RANK, vdsdims, vdsdims_max);
/* Create dataspaces for the source dataset. */
- src_space = H5Screate_simple (RANK, dims, dims_max);
+ src_space = H5Screate_simple(RANK, dims, dims_max);
/* Create VDS creation property */
- dcpl = H5Pcreate (H5P_DATASET_CREATE);
-
+ 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;
+ 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;
+ block[0] = 1;
+ block[1] = DIM1;
+ block[2] = DIM2;
- /*
- * Build the mappings
+ /*
+ * 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]++;
- }
+ 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);
+ H5Sselect_none(vspace);
/* Create a virtual dataset */
- vdset = H5Dcreate2 (vfile, DATASET, H5T_NATIVE_INT, vspace, H5P_DEFAULT,
- dcpl, H5P_DEFAULT);
- status = H5Sclose (vspace);
- status = H5Sclose (src_space);
- status = H5Pclose (dcpl);
+ vdset = H5Dcreate2(vfile, DATASET, H5T_NATIVE_INT, vspace, H5P_DEFAULT, dcpl, H5P_DEFAULT);
+ status = H5Sclose(vspace);
+ status = H5Sclose(src_space);
+ status = H5Pclose(dcpl);
/* 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<RANK; i++)
- printf (" %d ", (int)vdsdims_out[i]);
- printf ("\n");
+ 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 < RANK; i++)
+ printf(" %d ", (int)vdsdims_out[i]);
+ printf("\n");
/* Let's add data to the source datasets and check new dimensions for VDS */
- for (i=0; i < PLANE_STRIDE; i++) {
+ 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] = 10*(i+1);
+ for (j = 0; j < DIM0_1 * DIM1 * DIM2; j++)
+ wdata[j] = 10 * (i + 1);
/*
- * Create the source files and datasets. Write data to each dataset and
+ * Create the source files and datasets. Write data to each dataset and
* close all resources.
*/
- file = H5Fopen (SRC_FILE[i], H5F_ACC_RDWR, H5P_DEFAULT);
- dset = H5Dopen2 (file, SRC_DATASET[i], H5P_DEFAULT);
- status = H5Dset_extent (dset, extdims);
- src_space = H5Dget_space (dset);
- start[0] = DIM0_1;
- start[1] = 0;
- start[2] = 0;
- count[0] = 1;
- count[1] = 1;
- count[2] = 1;
- block[0] = DIM0_1;
- block[1] = DIM1;
- block[2] = DIM2;
-
- mem_space = H5Screate_simple(RANK, dims, NULL);
- status = H5Sselect_hyperslab (src_space, H5S_SELECT_SET, start, NULL, count, block);
- status = H5Dwrite (dset, H5T_NATIVE_INT, mem_space, src_space, H5P_DEFAULT,
- wdata);
- status = H5Sclose (src_space);
- status = H5Dclose (dset);
- status = H5Fclose (file);
- }
-
- status = H5Dclose (vdset);
- status = H5Fclose (vfile);
-
+ file = H5Fopen(SRC_FILE[i], H5F_ACC_RDWR, H5P_DEFAULT);
+ dset = H5Dopen2(file, SRC_DATASET[i], H5P_DEFAULT);
+ status = H5Dset_extent(dset, extdims);
+ src_space = H5Dget_space(dset);
+ start[0] = DIM0_1;
+ start[1] = 0;
+ start[2] = 0;
+ count[0] = 1;
+ count[1] = 1;
+ count[2] = 1;
+ block[0] = DIM0_1;
+ block[1] = DIM1;
+ block[2] = DIM2;
+
+ mem_space = H5Screate_simple(RANK, dims, NULL);
+ status = H5Sselect_hyperslab(src_space, H5S_SELECT_SET, start, NULL, count, block);
+ status = H5Dwrite(dset, H5T_NATIVE_INT, mem_space, src_space, H5P_DEFAULT, wdata);
+ status = H5Sclose(src_space);
+ status = H5Dclose(dset);
+ status = H5Fclose(file);
+ }
+
+ status = H5Dclose(vdset);
+ status = H5Fclose(vfile);
+
/*
* Now we begin the read section of this example.
*/
@@ -216,91 +193,99 @@ main (void)
/*
* Open file and dataset using the default properties.
*/
- vfile = H5Fopen (VFILE, H5F_ACC_RDONLY, H5P_DEFAULT);
- vdset = H5Dopen2 (vfile, DATASET, H5P_DEFAULT);
+ vfile = H5Fopen(VFILE, H5F_ACC_RDONLY, H5P_DEFAULT);
+ vdset = H5Dopen2(vfile, DATASET, H5P_DEFAULT);
/*
* Get creation property list and mapping properties.
*/
- dcpl = H5Dget_create_plist (vdset);
+ dcpl = H5Dget_create_plist(vdset);
/*
* Get storage layout.
*/
- layout = H5Pget_layout (dcpl);
+ layout = H5Pget_layout(dcpl);
- if (H5D_VIRTUAL == layout)
+ 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 %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");
- /* Get selection in the virttual dataset */
- 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(src_space)) {
- 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);
- }
+ /*
+ * 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");
+ /* Get selection in the virttual dataset */
+ 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(src_space)) {
+ 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);
+ }
/*
* Read data from VDS.
*/
- vspace = H5Dget_space (vdset);
- H5Sget_simple_extent_dims (vspace, vdsdims_out, vdsdims_max_out);
- printf ("VDS dimensions second time \n");
- printf (" Current: ");
- for (i=0; i<RANK; i++)
- printf (" %d ", (int)vdsdims_out[i]);
- printf ("\n");
+ vspace = H5Dget_space(vdset);
+ H5Sget_simple_extent_dims(vspace, vdsdims_out, vdsdims_max_out);
+ printf("VDS dimensions second time \n");
+ printf(" Current: ");
+ for (i = 0; i < RANK; i++)
+ printf(" %d ", (int)vdsdims_out[i]);
+ printf("\n");
/* Read all VDS data */
/* EIP We should be able to do it by using H5S_ALL instead of making selection
- * or using H5Sselect_all from vspace.
+ * or using H5Sselect_all from vspace.
*/
start[0] = 0;
start[1] = 0;
@@ -312,53 +297,50 @@ main (void)
block[1] = vdsdims_out[1];
block[2] = vdsdims_out[2];
- status = H5Sselect_hyperslab (vspace, H5S_SELECT_SET, start, NULL, count, block);
+ status = H5Sselect_hyperslab(vspace, H5S_SELECT_SET, start, NULL, count, block);
mem_space = H5Screate_simple(RANK, vdsdims_out, NULL);
- status = H5Dread (vdset, H5T_NATIVE_INT, mem_space, vspace, H5P_DEFAULT,
- rdata);
- printf (" All data: \n");
- for (i=0; i < (int)vdsdims_out[0]; i++) {
- for (j=0; j < (int)vdsdims_out[1]; j++) {
- printf ("(%d, %d, 0)", i, j);
- for (k=0; k < (int)vdsdims_out[2]; k++)
- printf (" %d ", rdata[i][j][k]);
- printf ("\n");
+ status = H5Dread(vdset, H5T_NATIVE_INT, mem_space, vspace, H5P_DEFAULT, rdata);
+ printf(" All data: \n");
+ for (i = 0; i < (int)vdsdims_out[0]; i++) {
+ for (j = 0; j < (int)vdsdims_out[1]; j++) {
+ printf("(%d, %d, 0)", i, j);
+ for (k = 0; k < (int)vdsdims_out[2]; k++)
+ printf(" %d ", rdata[i][j][k]);
+ printf("\n");
}
}
/* Read VDS, but only data mapeed to dataset a.h5 */
- start[0] = 0;
- start[1] = 0;
- start[2] = 0;
+ start[0] = 0;
+ start[1] = 0;
+ start[2] = 0;
stride[0] = PLANE_STRIDE;
stride[1] = 1;
stride[2] = 1;
- count[0] = 2*DIM0_1;
- count[1] = 1;
- count[2] = 1;
- block[0] = 1;
- block[1] = vdsdims_out[1];
- block[2] = vdsdims_out[2];
- dims[0] = 2*DIM0_1;
- status = H5Sselect_hyperslab (vspace, H5S_SELECT_SET, start, stride, count, block);
- mem_space = H5Screate_simple(RANK, dims, NULL);
- status = H5Dread (vdset, H5T_NATIVE_INT, mem_space, vspace, H5P_DEFAULT,
- a_rdata);
- printf (" All data: \n");
- for (i=0; i < 2*DIM0_1; i++) {
- for (j=0; j < (int)vdsdims_out[1]; j++) {
- printf ("(%d, %d, 0)", i, j);
- for (k=0; k < (int)vdsdims_out[2]; k++)
- printf (" %d ", a_rdata[i][j][k]);
- printf ("\n");
+ count[0] = 2 * DIM0_1;
+ count[1] = 1;
+ count[2] = 1;
+ block[0] = 1;
+ block[1] = vdsdims_out[1];
+ block[2] = vdsdims_out[2];
+ dims[0] = 2 * DIM0_1;
+ status = H5Sselect_hyperslab(vspace, H5S_SELECT_SET, start, stride, count, block);
+ mem_space = H5Screate_simple(RANK, dims, NULL);
+ status = H5Dread(vdset, H5T_NATIVE_INT, mem_space, vspace, H5P_DEFAULT, a_rdata);
+ printf(" All data: \n");
+ for (i = 0; i < 2 * DIM0_1; i++) {
+ for (j = 0; j < (int)vdsdims_out[1]; j++) {
+ printf("(%d, %d, 0)", i, j);
+ for (k = 0; k < (int)vdsdims_out[2]; k++)
+ printf(" %d ", a_rdata[i][j][k]);
+ printf("\n");
}
}
/*
* Close and release resources.
*/
status = H5Sclose(mem_space);
- status = H5Pclose (dcpl);
- status = H5Dclose (vdset);
- status = H5Fclose (vfile);
+ status = H5Pclose(dcpl);
+ status = H5Dclose(vdset);
+ status = H5Fclose(vfile);
return 0;
}
-
diff --git a/examples/h5_vds-percival.c b/examples/h5_vds-percival.c
index 11a974b..12397be 100644
--- a/examples/h5_vds-percival.c
+++ b/examples/h5_vds-percival.c
@@ -5,15 +5,15 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
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.
+ Percival use case. Every fifth 10x10 plane in VDS is stored in
+ the corresponding 3D unlimited dataset.
EIP: For now we will use finite dimension.
There are 4 source datasets total.
This file is intended for use with HDF5 Library version 1.10
@@ -25,146 +25,127 @@
#include <stdio.h>
#include <stdlib.h>
-#define FILE "vds-percival.h5"
-#define DATASET "VDS-Percival"
+#define FILE "vds-percival.h5"
+#define DATASET "VDS-Percival"
/* later
-#define VDSDIM0 H5S_UNLIMITED
+#define VDSDIM0 H5S_UNLIMITED
*/
-#define VDSDIM0 40
-#define VDSDIM1 10
-#define VDSDIM2 10
+#define VDSDIM0 40
+#define VDSDIM1 10
+#define VDSDIM2 10
/* later
-#define DIM0 H5S_UNLIMITED
+#define DIM0 H5S_UNLIMITED
*/
-#define DIM0 10
-#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"
-};
+#define DIM0 10
+#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)
+main(void)
{
- hid_t file, src_space, vspace,
- dset; /* Handles */
- hid_t dcpl;
- herr_t status;
- hsize_t vdsdims[3] = {VDSDIM0, VDSDIM1, VDSDIM2},
- vdsdims_max[3] = {VDSDIM0, VDSDIM1, VDSDIM2},
- dims[3] = {DIM0, DIM1, DIM2},
- dims_max[3] = {DIM0, DIM1, DIM2},
- start[3], /* Hyperslab start parameter for VDS */
- 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];
+ hid_t file, src_space, vspace, dset; /* Handles */
+ hid_t dcpl;
+ herr_t status;
+ hsize_t vdsdims[3] = {VDSDIM0, VDSDIM1, VDSDIM2}, vdsdims_max[3] = {VDSDIM0, VDSDIM1, VDSDIM2},
+ dims[3] = {DIM0, DIM1, DIM2}, dims_max[3] = {DIM0, DIM1, DIM2},
+ start[3], /* Hyperslab start parameter for VDS */
+ 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*DIM1*DIM2];
+ 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 * DIM1 * DIM2];
/*
* Create source files and datasets. This step is optional.
*/
- for (i=0; i < PLANE_STRIDE; i++) {
+ for (i = 0; i < PLANE_STRIDE; i++) {
/*
* Initialize data for i-th source dataset.
*/
- for (j = 0; j < DIM0*DIM1*DIM2; j++) wdata[j] = i+1;
+ for (j = 0; j < DIM0 * DIM1 * DIM2; j++)
+ wdata[j] = i + 1;
/*
- * Create the source files and datasets. Write data to each dataset and
+ * 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, NULL);
- dset = H5Dcreate2 (file, SRC_DATASET[i], H5T_NATIVE_INT, src_space, H5P_DEFAULT,
- H5P_DEFAULT, H5P_DEFAULT);
- status = H5Dwrite (dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
- wdata);
- status = H5Sclose (src_space);
- status = H5Dclose (dset);
- status = H5Fclose (file);
- }
+ file = H5Fcreate(SRC_FILE[i], H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ src_space = H5Screate_simple(RANK, dims, NULL);
+ dset = H5Dcreate2(file, SRC_DATASET[i], H5T_NATIVE_INT, src_space, H5P_DEFAULT, H5P_DEFAULT,
+ H5P_DEFAULT);
+ status = H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wdata);
+ status = H5Sclose(src_space);
+ status = H5Dclose(dset);
+ status = H5Fclose(file);
+ }
- file = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ file = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create VDS dataspace. */
- vspace = H5Screate_simple (RANK, vdsdims, vdsdims_max);
+ vspace = H5Screate_simple(RANK, vdsdims, vdsdims_max);
/* Create dataspaces for the source dataset. */
- src_space = H5Screate_simple (RANK, dims, dims_max);
+ src_space = H5Screate_simple(RANK, dims, dims_max);
/* Create VDS creation property */
- dcpl = H5Pcreate (H5P_DATASET_CREATE);
-
+ dcpl = H5Pcreate(H5P_DATASET_CREATE);
+
/* Initialize hyperslab values */
- start[0] = 0;
- start[1] = 0;
- start[2] = 0;
+ 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;
-/* later
- count[0] = H5S_UNLIMITED;
-*/
- count[0] = VDSDIM0/4;
+ /* later
+ count[0] = H5S_UNLIMITED;
+ */
+ count[0] = VDSDIM0 / 4;
count[1] = 1;
count[2] = 1;
-/* later
- src_count[0] = H5S_UNLIMITED;
-*/
+ /* later
+ src_count[0] = H5S_UNLIMITED;
+ */
src_count[0] = DIM0;
src_count[1] = 1;
src_count[2] = 1;
- block[0] = 1;
- block[1] = DIM1;
- block[2] = DIM2;
+ block[0] = 1;
+ block[1] = DIM1;
+ block[2] = DIM2;
- /*
- * Build the mappings
+ /*
+ * 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]++;
- }
+ 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);
+ H5Sselect_none(vspace);
/* Create a virtual dataset */
- dset = H5Dcreate2 (file, DATASET, H5T_NATIVE_INT, vspace, H5P_DEFAULT,
- dcpl, H5P_DEFAULT);
- status = H5Sclose (vspace);
- status = H5Sclose (src_space);
- status = H5Dclose (dset);
- status = H5Fclose (file);
-
+ dset = H5Dcreate2(file, DATASET, H5T_NATIVE_INT, vspace, H5P_DEFAULT, dcpl, H5P_DEFAULT);
+ status = H5Sclose(vspace);
+ status = H5Sclose(src_space);
+ status = H5Dclose(dset);
+ status = H5Fclose(file);
+
/*
* Now we begin the read section of this example.
*/
@@ -172,82 +153,89 @@ main (void)
/*
* Open file and dataset using the default properties.
*/
- file = H5Fopen (FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
- dset = H5Dopen2 (file, DATASET, H5P_DEFAULT);
+ file = H5Fopen(FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
+ dset = H5Dopen2(file, DATASET, H5P_DEFAULT);
/*
* Get creation property list and mapping properties.
*/
- dcpl = H5Dget_create_plist (dset);
+ dcpl = H5Dget_create_plist(dset);
/*
* Get storage layout.
*/
- layout = H5Pget_layout (dcpl);
+ layout = H5Pget_layout(dcpl);
- if (H5D_VIRTUAL == layout)
+ 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 %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");
- /* Get selection in the virttual dataset */
- 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(src_space)) {
- 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);
- }
+ /*
+ * 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");
+ /* Get selection in the virttual dataset */
+ 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(src_space)) {
+ 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);
+ }
/*
* Close and release resources.
*/
- status = H5Pclose (dcpl);
- status = H5Dclose (dset);
- status = H5Fclose (file);
+ status = H5Pclose(dcpl);
+ status = H5Dclose(dset);
+ status = H5Fclose(file);
return 0;
}
-
diff --git a/examples/h5_vds-simpleIO.c b/examples/h5_vds-simpleIO.c
index 56fa72b..6472766 100644
--- a/examples/h5_vds-simpleIO.c
+++ b/examples/h5_vds-simpleIO.c
@@ -5,7 +5,7 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -14,7 +14,7 @@
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 dimension sizes and maps the all elements of the
+ the same dimension sizes and maps the all elements of the
virtual dataset to all elements of the source dataset.
Then VDS is read back.
@@ -27,79 +27,76 @@
#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"
+#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)
+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;
+ 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 = H5Dcreate2 (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);
+ 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 = H5Dcreate2(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);
+ file = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create VDS dataspace. */
- vspace = H5Screate_simple (RANK, vdsdims, NULL);
+ vspace = H5Screate_simple(RANK, vdsdims, NULL);
/* Set VDS creation property. */
- dcpl = H5Pcreate (H5P_DATASET_CREATE);
-
- /*
+ 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.
+ * 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);
+ src_space = H5Screate_simple(RANK, dims, NULL);
+ status = H5Pset_virtual(dcpl, vspace, SRC_FILE, SRC_DATASET, src_space);
/* Create a virtual dataset. */
- dset = H5Dcreate2 (file, DATASET, H5T_NATIVE_INT, vspace, H5P_DEFAULT,
- dcpl, H5P_DEFAULT);
- status = H5Sclose (vspace);
- status = H5Sclose (src_space);
- status = H5Dclose (dset);
- status = H5Fclose (file);
-
+ dset = H5Dcreate2(file, DATASET, H5T_NATIVE_INT, vspace, H5P_DEFAULT, dcpl, H5P_DEFAULT);
+ status = H5Sclose(vspace);
+ status = H5Sclose(src_space);
+ status = H5Dclose(dset);
+ status = H5Fclose(file);
+
/*
* Now we begin the read section of this example.
*/
@@ -107,60 +104,60 @@ main (void)
/*
* Open the file and virtual dataset.
*/
- file = H5Fopen (FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
- dset = H5Dopen2 (file, DATASET, H5P_DEFAULT);
+ file = H5Fopen(FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
+ dset = H5Dopen2(file, DATASET, H5P_DEFAULT);
/*
* Get creation property list and mapping properties.
*/
- dcpl = H5Dget_create_plist (dset);
+ dcpl = H5Dget_create_plist(dset);
/*
* Get storage layout.
*/
- layout = H5Pget_layout (dcpl);
- if (H5D_VIRTUAL == 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 %lu\n", (unsigned long)num_map);
+ /*
+ * Find the 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++) {
+ /*
+ * 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);
+ 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");
+ 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);
+ 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);
+ 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);
+ 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");
+ if (H5Sget_select_type(src_space) == H5S_SEL_ALL) {
+ printf("Selection is H5S_ALL \n");
}
H5Sclose(vspace);
H5Sclose(src_space);
@@ -170,26 +167,24 @@ main (void)
/*
* Read the data using the default properties.
*/
- status = H5Dread (dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
- rdata[0]);
+ 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");
+ 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);
+ status = H5Pclose(dcpl);
+ status = H5Dclose(dset);
+ status = H5Fclose(file);
return 0;
}
-
diff --git a/examples/h5_vds.c b/examples/h5_vds.c
index 76b849a..e036204 100644
--- a/examples/h5_vds.c
+++ b/examples/h5_vds.c
@@ -6,7 +6,7 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -16,15 +16,15 @@
This example illustrates the concept of virtual dataset.
The program creates three 1-dim source datasets and writes
data to them. Then it creates a 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
+ 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 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.
+ Then it reads the values.
This file is intended for use with HDF5 Library version 1.10
@@ -35,89 +35,75 @@
#include <stdio.h>
#include <stdlib.h>
-#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"
-};
+#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)
+main(void)
{
- hid_t file, space, src_space, vspace, dset; /* Handles */
- hid_t dcpl;
- herr_t status;
- 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];
- hsize_t start_out[2],
- stride_out[2],
- count_out[2],
- block_out[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;
+ hid_t file, space, src_space, vspace, dset; /* Handles */
+ hid_t dcpl;
+ herr_t status;
+ 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];
+ hsize_t start_out[2], stride_out[2], count_out[2], block_out[2];
+ int wdata[DIM0], /* Write buffer for source dataset */
+ rdata[VDSDIM0][VDSDIM1], /* Read buffer for virtual dataset */
+ i, j, k, l, block_inc;
+ 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 */
+ hsize_t * buf; /* Buffer to hold hyperslab coordinates */
/*
* Create source files and datasets. This step is optional.
*/
- for (i=0; i < 3; i++) {
+ for (i = 0; i < 3; i++) {
/*
* Initialize data for i-th source dataset.
*/
- for (j = 0; j < DIM0; j++) wdata[j] = i+1;
-
+ for (j = 0; j < DIM0; j++)
+ wdata[j] = i + 1;
+
/*
- * Create the source files and datasets. Write data to each dataset and
+ * 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 = H5Dcreate2 (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(SRC_FILE[i], H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ space = H5Screate_simple(RANK1, dims, NULL);
+ dset = H5Dcreate2(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);
}
/* Create file in which virtual dataset will be stored. */
- file = H5Fcreate (FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ file = H5Fcreate(FILE, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
/* Create VDS dataspace. */
- space = H5Screate_simple (RANK2, vdsdims, NULL);
+ space = H5Screate_simple(RANK2, vdsdims, NULL);
/* Set VDS creation property. */
- dcpl = H5Pcreate (H5P_DATASET_CREATE);
- status = H5Pset_fill_value (dcpl, H5T_NATIVE_INT, &fill_value);
-
+ dcpl = H5Pcreate(H5P_DATASET_CREATE);
+ status = H5Pset_fill_value(dcpl, H5T_NATIVE_INT, &fill_value);
+
/* Initialize hyperslab values. */
start[0] = 0;
start[1] = 0;
@@ -126,28 +112,27 @@ main (void)
block[0] = 1;
block[1] = VDSDIM1;
- /*
+ /*
* 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.
+ * 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 (RANK1, dims, NULL);
+ src_space = H5Screate_simple(RANK1, dims, NULL);
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_hyperslab(space, H5S_SELECT_SET, start, NULL, count, block);
+ status = H5Pset_virtual(dcpl, space, SRC_FILE[i], SRC_DATASET[i], src_space);
}
/* Create a virtual dataset. */
- dset = H5Dcreate2 (file, DATASET, H5T_NATIVE_INT, space, H5P_DEFAULT,
- dcpl, H5P_DEFAULT);
- status = H5Sclose (space);
- status = H5Sclose (src_space);
- status = H5Dclose (dset);
- status = H5Fclose (file);
-
+ dset = H5Dcreate2(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.
*/
@@ -155,80 +140,85 @@ main (void)
/*
* Open the file and virtual dataset.
*/
- file = H5Fopen (FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
- dset = H5Dopen2 (file, DATASET, H5P_DEFAULT);
+ file = H5Fopen(FILE, H5F_ACC_RDONLY, H5P_DEFAULT);
+ dset = H5Dopen2(file, DATASET, H5P_DEFAULT);
/*
* Get creation property list and mapping properties.
*/
- dcpl = H5Dget_create_plist (dset);
+ dcpl = H5Dget_create_plist(dset);
/*
* Get storage layout.
*/
- layout = H5Pget_layout (dcpl);
- if (H5D_VIRTUAL == 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 %lu\n", (unsigned long)num_map);
+ /*
+ * Find the 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++) {
+ /*
+ * 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);
+ 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<nblocks; l++) {
+ 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 < nblocks; l++) {
+ block_inc = 2 * RANK2 * l;
printf("(");
- for (k=0; k<RANK2-1; k++)
- printf("%d,", (int)buf[k]);
- printf("%d ) - (", (int)buf[k]);
- for (k=0; k<RANK2-1; k++)
- printf("%d,", (int)buf[RANK2+k]);
- printf("%d)\n", (int)buf[RANK2+k]);
+ for (k = 0; k < RANK2 - 1; k++)
+ printf("%d,", (int)buf[block_inc + k]);
+ printf("%d) - (", (int)buf[block_inc + k]);
+ for (k = 0; k < RANK2 - 1; k++)
+ printf("%d,", (int)buf[block_inc + RANK2 + k]);
+ printf("%d)\n", (int)buf[block_inc + RANK2 + k]);
}
- /* We also can use new APIs to get start, stride, count and block */
+ /* 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 = [%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]);
+ status = H5Sget_regular_hyperslab(vspace, start_out, stride_out, count_out, block_out);
+ 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. */
- 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);
+ 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);
+ 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);
+ src_space = H5Pget_virtual_srcspace(dcpl, (size_t)i);
/* Make sure it is ALL selection and then print the coordinates. */
- if(H5Sget_select_type(src_space) == H5S_SEL_ALL) {
- printf("(0) - (%d) \n", DIM0-1);
+ if (H5Sget_select_type(src_space) == H5S_SEL_ALL) {
+ printf("(0) - (%d) \n", DIM0 - 1);
}
H5Sclose(vspace);
H5Sclose(src_space);
@@ -240,26 +230,24 @@ main (void)
/*
* Read the data using the default properties.
*/
- status = H5Dread (dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT,
- rdata[0]);
+ 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<VDSDIM0; i++) {
- printf (" [");
- for (j=0; j<VDSDIM1; j++)
- printf (" %3d", rdata[i][j]);
- printf ("]\n");
+ printf(" VDS Data:\n");
+ for (i = 0; i < VDSDIM0; i++) {
+ printf(" [");
+ for (j = 0; j < VDSDIM1; j++)
+ printf(" %3d", rdata[i][j]);
+ printf("]\n");
}
/*
* Close and release resources.
*/
- status = H5Pclose (dcpl);
- status = H5Dclose (dset);
- status = H5Fclose (file);
+ status = H5Pclose(dcpl);
+ status = H5Dclose(dset);
+ status = H5Fclose(file);
return 0;
}
-
diff --git a/examples/h5_write.c b/examples/h5_write.c
index 1a7cfe7..c2bf136 100644
--- a/examples/h5_write.c
+++ b/examples/h5_write.c
@@ -6,7 +6,7 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -18,28 +18,28 @@
#include "hdf5.h"
-#define H5FILE_NAME "SDS.h5"
+#define H5FILE_NAME "SDS.h5"
#define DATASETNAME "IntArray"
-#define NX 5 /* dataset dimensions */
-#define NY 6
-#define RANK 2
+#define NX 5 /* dataset dimensions */
+#define NY 6
+#define RANK 2
int
-main (void)
+main(void)
{
- hid_t file, dataset; /* file and dataset handles */
- hid_t datatype, dataspace; /* handles */
- hsize_t dimsf[2]; /* dataset dimensions */
- herr_t status;
- int data[NX][NY]; /* data to write */
- int i, j;
+ hid_t file, dataset; /* file and dataset handles */
+ hid_t datatype, dataspace; /* handles */
+ hsize_t dimsf[2]; /* dataset dimensions */
+ herr_t status;
+ int data[NX][NY]; /* data to write */
+ int i, j;
/*
* Data and output buffer initialization.
*/
- for(j = 0; j < NX; j++)
- for(i = 0; i < NY; i++)
- data[j][i] = i + j;
+ for (j = 0; j < NX; j++)
+ for (i = 0; i < NY; i++)
+ data[j][i] = i + j;
/*
* 0 1 2 3 4 5
* 1 2 3 4 5 6
@@ -59,8 +59,8 @@ main (void)
* Describe the size of the array and create the data space for fixed
* size dataset.
*/
- dimsf[0] = NX;
- dimsf[1] = NY;
+ dimsf[0] = NX;
+ dimsf[1] = NY;
dataspace = H5Screate_simple(RANK, dimsf, NULL);
/*
@@ -68,14 +68,13 @@ main (void)
* We will store little endian INT numbers.
*/
datatype = H5Tcopy(H5T_NATIVE_INT);
- status = H5Tset_order(datatype, H5T_ORDER_LE);
+ status = H5Tset_order(datatype, H5T_ORDER_LE);
/*
* Create a new dataset within the file using defined dataspace and
* datatype and default dataset creation properties.
*/
- dataset = H5Dcreate2(file, DATASETNAME, datatype, dataspace,
- H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ dataset = H5Dcreate2(file, DATASETNAME, datatype, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
/*
* Write the data to the dataset using default transfer properties.
@@ -92,4 +91,3 @@ main (void)
return 0;
}
-
diff --git a/examples/ph5_filtered_writes.c b/examples/ph5_filtered_writes.c
new file mode 100644
index 0000000..0f399dd
--- /dev/null
+++ b/examples/ph5_filtered_writes.c
@@ -0,0 +1,490 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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 *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
+ * If you do not have access to either file, you may request a copy from *
+ * help@hdfgroup.org. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/*
+ * Example of using the parallel HDF5 library to write to datasets
+ * with filters applied to them.
+ *
+ * If the HDF5_NOCLEANUP environment variable is set, the file that
+ * this example creates will not be removed as the example finishes.
+ *
+ * The need of requirement of parallel file prefix is that in general
+ * the current working directory in which compiling is done, is not suitable
+ * for parallel I/O and there is no standard pathname for parallel file
+ * systems. In some cases, the parallel file name may even need some
+ * parallel file type prefix such as: "pfs:/GF/...". Therefore, this
+ * example parses the HDF5_PARAPREFIX environment variable for a prefix,
+ * if one is needed.
+ */
+
+#include <stdlib.h>
+
+#include "hdf5.h"
+
+#if defined(H5_HAVE_PARALLEL) && defined(H5_HAVE_PARALLEL_FILTERED_WRITES)
+
+#define EXAMPLE_FILE "ph5_filtered_writes.h5"
+#define EXAMPLE_DSET1_NAME "DSET1"
+#define EXAMPLE_DSET2_NAME "DSET2"
+
+#define EXAMPLE_DSET_DIMS 2
+#define EXAMPLE_DSET_CHUNK_DIM_SIZE 10
+
+/* Dataset datatype */
+#define HDF5_DATATYPE H5T_NATIVE_INT
+typedef int C_DATATYPE;
+
+#ifndef PATH_MAX
+#define PATH_MAX 512
+#endif
+
+/* Global variables */
+int mpi_rank, mpi_size;
+
+/*
+ * Routine to set an HDF5 filter on the given DCPL
+ */
+static void
+set_filter(hid_t dcpl_id)
+{
+ htri_t filter_avail;
+
+ /*
+ * Check if 'deflate' filter is available
+ */
+ filter_avail = H5Zfilter_avail(H5Z_FILTER_DEFLATE);
+ if (filter_avail < 0)
+ return;
+ else if (filter_avail) {
+ /*
+ * Set 'deflate' filter with reasonable
+ * compression level on DCPL
+ */
+ H5Pset_deflate(dcpl_id, 6);
+ }
+ else {
+ /*
+ * Set Fletcher32 checksum filter on DCPL
+ * since it is always available in HDF5
+ */
+ H5Pset_fletcher32(dcpl_id);
+ }
+}
+
+/*
+ * Routine to fill a data buffer with data. Assumes
+ * dimension rank is 2 and data is stored contiguous.
+ */
+void
+fill_databuf(hsize_t start[], hsize_t count[], hsize_t stride[], C_DATATYPE *data)
+{
+ C_DATATYPE *dataptr = data;
+ hsize_t i, j;
+
+ /* Use MPI rank value for data */
+ for (i = 0; i < count[0]; i++) {
+ for (j = 0; j < count[1]; j++) {
+ *dataptr++ = mpi_rank;
+ }
+ }
+}
+
+/* Cleanup created file */
+static void
+cleanup(char *filename)
+{
+ hbool_t do_cleanup = getenv(HDF5_NOCLEANUP) ? 0 : 1;
+
+ if (do_cleanup)
+ MPI_File_delete(filename, MPI_INFO_NULL);
+}
+
+/*
+ * Routine to write to a dataset in a fashion
+ * where no chunks in the dataset are written
+ * to by more than 1 MPI rank. This will
+ * generally give the best performance as the
+ * MPI ranks will need the least amount of
+ * inter-process communication.
+ */
+static void
+write_dataset_no_overlap(hid_t file_id, hid_t dxpl_id)
+{
+ C_DATATYPE data[EXAMPLE_DSET_CHUNK_DIM_SIZE][4 * EXAMPLE_DSET_CHUNK_DIM_SIZE];
+ hsize_t dataset_dims[EXAMPLE_DSET_DIMS];
+ hsize_t chunk_dims[EXAMPLE_DSET_DIMS];
+ hsize_t start[EXAMPLE_DSET_DIMS];
+ hsize_t stride[EXAMPLE_DSET_DIMS];
+ hsize_t count[EXAMPLE_DSET_DIMS];
+ size_t i, j;
+ hid_t dset_id = H5I_INVALID_HID;
+ hid_t dcpl_id = H5I_INVALID_HID;
+ hid_t file_dataspace = H5I_INVALID_HID;
+
+ /*
+ * ------------------------------------
+ * Setup Dataset Creation Property List
+ * ------------------------------------
+ */
+
+ dcpl_id = H5Pcreate(H5P_DATASET_CREATE);
+
+ /*
+ * REQUIRED: Dataset chunking must be enabled to
+ * apply a data filter to the dataset.
+ * Chunks in the dataset are of size
+ * EXAMPLE_DSET_CHUNK_DIM_SIZE x EXAMPLE_DSET_CHUNK_DIM_SIZE.
+ */
+ chunk_dims[0] = EXAMPLE_DSET_CHUNK_DIM_SIZE;
+ chunk_dims[1] = EXAMPLE_DSET_CHUNK_DIM_SIZE;
+ H5Pset_chunk(dcpl_id, EXAMPLE_DSET_DIMS, chunk_dims);
+
+ /* Set filter to be applied to created datasets */
+ set_filter(dcpl_id);
+
+ /*
+ * ------------------------------------
+ * Define the dimensions of the dataset
+ * and create it
+ * ------------------------------------
+ */
+
+ /*
+ * Create a dataset composed of 4 chunks
+ * per MPI rank. The first dataset dimension
+ * scales according to the number of MPI ranks.
+ * The second dataset dimension stays fixed
+ * according to the chunk size.
+ */
+ dataset_dims[0] = EXAMPLE_DSET_CHUNK_DIM_SIZE * mpi_size;
+ dataset_dims[1] = 4 * EXAMPLE_DSET_CHUNK_DIM_SIZE;
+
+ file_dataspace = H5Screate_simple(EXAMPLE_DSET_DIMS, dataset_dims, NULL);
+
+ /* Create the dataset */
+ dset_id = H5Dcreate2(file_id, EXAMPLE_DSET1_NAME, HDF5_DATATYPE, file_dataspace, H5P_DEFAULT, dcpl_id,
+ H5P_DEFAULT);
+
+ /*
+ * ------------------------------------
+ * Setup selection in the dataset for
+ * each MPI rank
+ * ------------------------------------
+ */
+
+ /*
+ * Each MPI rank's selection covers a
+ * single chunk in the first dataset
+ * dimension. Each MPI rank's selection
+ * covers 4 chunks in the second dataset
+ * dimension. This leads to each MPI rank
+ * writing to 4 chunks of the dataset.
+ */
+ start[0] = mpi_rank * EXAMPLE_DSET_CHUNK_DIM_SIZE;
+ start[1] = 0;
+ stride[0] = 1;
+ stride[1] = 1;
+ count[0] = EXAMPLE_DSET_CHUNK_DIM_SIZE;
+ count[1] = 4 * EXAMPLE_DSET_CHUNK_DIM_SIZE;
+
+ H5Sselect_hyperslab(file_dataspace, H5S_SELECT_SET, start, stride, count, NULL);
+
+ /*
+ * --------------------------------------
+ * Fill data buffer with MPI rank's rank
+ * value to make it easy to see which
+ * part of the dataset each rank wrote to
+ * --------------------------------------
+ */
+
+ fill_databuf(start, count, stride, &data[0][0]);
+
+ /*
+ * ---------------------------------
+ * Write to the dataset collectively
+ * ---------------------------------
+ */
+
+ H5Dwrite(dset_id, HDF5_DATATYPE, H5S_BLOCK, file_dataspace, dxpl_id, data);
+
+ /*
+ * --------------
+ * Close HDF5 IDs
+ * --------------
+ */
+
+ H5Sclose(file_dataspace);
+ H5Pclose(dcpl_id);
+ H5Dclose(dset_id);
+}
+
+/*
+ * Routine to write to a dataset in a fashion
+ * where every chunk in the dataset is written
+ * to by every MPI rank. This will generally
+ * give the worst performance as the MPI ranks
+ * will need the most amount of inter-process
+ * communication.
+ */
+static void
+write_dataset_overlap(hid_t file_id, hid_t dxpl_id)
+{
+ C_DATATYPE *data = NULL;
+ hsize_t dataset_dims[EXAMPLE_DSET_DIMS];
+ hsize_t chunk_dims[EXAMPLE_DSET_DIMS];
+ hsize_t start[EXAMPLE_DSET_DIMS];
+ hsize_t stride[EXAMPLE_DSET_DIMS];
+ hsize_t count[EXAMPLE_DSET_DIMS];
+ size_t i, j;
+ hid_t dset_id = H5I_INVALID_HID;
+ hid_t dcpl_id = H5I_INVALID_HID;
+ hid_t file_dataspace = H5I_INVALID_HID;
+
+ /*
+ * ------------------------------------
+ * Setup Dataset Creation Property List
+ * ------------------------------------
+ */
+
+ dcpl_id = H5Pcreate(H5P_DATASET_CREATE);
+
+ /*
+ * REQUIRED: Dataset chunking must be enabled to
+ * apply a data filter to the dataset.
+ * Chunks in the dataset are of size
+ * mpi_size x EXAMPLE_DSET_CHUNK_DIM_SIZE.
+ */
+ chunk_dims[0] = mpi_size;
+ chunk_dims[1] = EXAMPLE_DSET_CHUNK_DIM_SIZE;
+ H5Pset_chunk(dcpl_id, EXAMPLE_DSET_DIMS, chunk_dims);
+
+ /* Set filter to be applied to created datasets */
+ set_filter(dcpl_id);
+
+ /*
+ * ------------------------------------
+ * Define the dimensions of the dataset
+ * and create it
+ * ------------------------------------
+ */
+
+ /*
+ * Create a dataset composed of N chunks,
+ * where N is the number of MPI ranks. The
+ * first dataset dimension scales according
+ * to the number of MPI ranks. The second
+ * dataset dimension stays fixed according
+ * to the chunk size.
+ */
+ dataset_dims[0] = mpi_size * chunk_dims[0];
+ dataset_dims[1] = EXAMPLE_DSET_CHUNK_DIM_SIZE;
+
+ file_dataspace = H5Screate_simple(EXAMPLE_DSET_DIMS, dataset_dims, NULL);
+
+ /* Create the dataset */
+ dset_id = H5Dcreate2(file_id, EXAMPLE_DSET2_NAME, HDF5_DATATYPE, file_dataspace, H5P_DEFAULT, dcpl_id,
+ H5P_DEFAULT);
+
+ /*
+ * ------------------------------------
+ * Setup selection in the dataset for
+ * each MPI rank
+ * ------------------------------------
+ */
+
+ /*
+ * Each MPI rank's selection covers
+ * part of every chunk in the first
+ * dimension. Each MPI rank's selection
+ * covers all of every chunk in the
+ * second dimension. This leads to
+ * each MPI rank writing an equal
+ * amount of data to every chunk
+ * in the dataset.
+ */
+ start[0] = mpi_rank;
+ start[1] = 0;
+ stride[0] = chunk_dims[0];
+ stride[1] = 1;
+ count[0] = mpi_size;
+ count[1] = EXAMPLE_DSET_CHUNK_DIM_SIZE;
+
+ H5Sselect_hyperslab(file_dataspace, H5S_SELECT_SET, start, stride, count, NULL);
+
+ /*
+ * --------------------------------------
+ * Fill data buffer with MPI rank's rank
+ * value to make it easy to see which
+ * part of the dataset each rank wrote to
+ * --------------------------------------
+ */
+
+ data = malloc(mpi_size * EXAMPLE_DSET_CHUNK_DIM_SIZE * sizeof(C_DATATYPE));
+
+ fill_databuf(start, count, stride, data);
+
+ /*
+ * ---------------------------------
+ * Write to the dataset collectively
+ * ---------------------------------
+ */
+
+ H5Dwrite(dset_id, HDF5_DATATYPE, H5S_BLOCK, file_dataspace, dxpl_id, data);
+
+ free(data);
+
+ /*
+ * --------------
+ * Close HDF5 IDs
+ * --------------
+ */
+
+ H5Sclose(file_dataspace);
+ H5Pclose(dcpl_id);
+ H5Dclose(dset_id);
+}
+
+int
+main(int argc, char **argv)
+{
+ MPI_Comm comm = MPI_COMM_WORLD;
+ MPI_Info info = MPI_INFO_NULL;
+ hid_t file_id = H5I_INVALID_HID;
+ hid_t fapl_id = H5I_INVALID_HID;
+ hid_t dxpl_id = H5I_INVALID_HID;
+ char * par_prefix = NULL;
+ char filename[PATH_MAX];
+
+ MPI_Init(&argc, &argv);
+ MPI_Comm_size(comm, &mpi_size);
+ MPI_Comm_rank(comm, &mpi_rank);
+
+ /*
+ * ----------------------------------
+ * Start parallel access to HDF5 file
+ * ----------------------------------
+ */
+
+ /* Setup File Access Property List with parallel I/O access */
+ fapl_id = H5Pcreate(H5P_FILE_ACCESS);
+ H5Pset_fapl_mpio(fapl_id, comm, info);
+
+ /*
+ * OPTIONAL: Set collective metadata reads on FAPL to allow
+ * parallel writes to filtered datasets to perform
+ * better at scale. While not strictly necessary,
+ * this is generally recommended.
+ */
+ H5Pset_all_coll_metadata_ops(fapl_id, true);
+
+ /*
+ * OPTIONAL: Set the latest file format version for HDF5 in
+ * order to gain access to different dataset chunk
+ * index types and better data encoding methods.
+ * While not strictly necessary, this is generally
+ * recommended.
+ */
+ H5Pset_libver_bounds(fapl_id, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST);
+
+ /* Parse any parallel prefix and create filename */
+ par_prefix = getenv("HDF5_PARAPREFIX");
+
+ snprintf(filename, PATH_MAX, "%s%s%s", par_prefix ? par_prefix : "", par_prefix ? "/" : "", EXAMPLE_FILE);
+
+ /* Create HDF5 file */
+ file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id);
+
+ /*
+ * --------------------------------------
+ * Setup Dataset Transfer Property List
+ * with collective I/O
+ * --------------------------------------
+ */
+
+ dxpl_id = H5Pcreate(H5P_DATASET_XFER);
+
+ /*
+ * REQUIRED: Setup collective I/O for the dataset
+ * write operations. Parallel writes to
+ * filtered datasets MUST be collective,
+ * even if some ranks have no data to
+ * contribute to the write operation.
+ *
+ * Refer to the 'ph5_filtered_writes_no_sel'
+ * example to see how to setup a dataset
+ * write when one or more MPI ranks have
+ * no data to contribute to the write
+ * operation.
+ */
+ H5Pset_dxpl_mpio(dxpl_id, H5FD_MPIO_COLLECTIVE);
+
+ /*
+ * --------------------------------
+ * Create and write to each dataset
+ * --------------------------------
+ */
+
+ /*
+ * Write to a dataset in a fashion where no
+ * chunks in the dataset are written to by
+ * more than 1 MPI rank. This will generally
+ * give the best performance as the MPI ranks
+ * will need the least amount of inter-process
+ * communication.
+ */
+ write_dataset_no_overlap(file_id, dxpl_id);
+
+ /*
+ * Write to a dataset in a fashion where
+ * every chunk in the dataset is written
+ * to by every MPI rank. This will generally
+ * give the worst performance as the MPI ranks
+ * will need the most amount of inter-process
+ * communication.
+ */
+ write_dataset_overlap(file_id, dxpl_id);
+
+ /*
+ * ------------------
+ * Close all HDF5 IDs
+ * ------------------
+ */
+
+ H5Pclose(dxpl_id);
+ H5Pclose(fapl_id);
+ H5Fclose(file_id);
+
+ printf("PHDF5 example finished with no errors\n");
+
+ /*
+ * ------------------------------------
+ * Cleanup created HDF5 file and finish
+ * ------------------------------------
+ */
+
+ cleanup(filename);
+
+ MPI_Finalize();
+
+ return 0;
+}
+
+#else
+
+int
+main(void)
+{
+ printf("HDF5 not configured with parallel support or parallel filtered writes are disabled!\n");
+ return 0;
+}
+
+#endif
diff --git a/examples/ph5_filtered_writes_no_sel.c b/examples/ph5_filtered_writes_no_sel.c
new file mode 100644
index 0000000..2e29838
--- /dev/null
+++ b/examples/ph5_filtered_writes_no_sel.c
@@ -0,0 +1,370 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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 *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
+ * If you do not have access to either file, you may request a copy from *
+ * help@hdfgroup.org. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/*
+ * Example of using the parallel HDF5 library to collectively write to
+ * datasets with filters applied to them when one or MPI ranks do not
+ * have data to contribute to the dataset.
+ *
+ * If the HDF5_NOCLEANUP environment variable is set, the file that
+ * this example creates will not be removed as the example finishes.
+ *
+ * The need of requirement of parallel file prefix is that in general
+ * the current working directory in which compiling is done, is not suitable
+ * for parallel I/O and there is no standard pathname for parallel file
+ * systems. In some cases, the parallel file name may even need some
+ * parallel file type prefix such as: "pfs:/GF/...". Therefore, this
+ * example parses the HDF5_PARAPREFIX environment variable for a prefix,
+ * if one is needed.
+ */
+
+#include <stdlib.h>
+
+#include "hdf5.h"
+
+#if defined(H5_HAVE_PARALLEL) && defined(H5_HAVE_PARALLEL_FILTERED_WRITES)
+
+#define EXAMPLE_FILE "ph5_filtered_writes_no_sel.h5"
+#define EXAMPLE_DSET_NAME "DSET"
+
+#define EXAMPLE_DSET_DIMS 2
+#define EXAMPLE_DSET_CHUNK_DIM_SIZE 10
+
+/* Dataset datatype */
+#define HDF5_DATATYPE H5T_NATIVE_INT
+typedef int C_DATATYPE;
+
+#ifndef PATH_MAX
+#define PATH_MAX 512
+#endif
+
+/* Global variables */
+int mpi_rank, mpi_size;
+
+/*
+ * Routine to set an HDF5 filter on the given DCPL
+ */
+static void
+set_filter(hid_t dcpl_id)
+{
+ htri_t filter_avail;
+
+ /*
+ * Check if 'deflate' filter is available
+ */
+ filter_avail = H5Zfilter_avail(H5Z_FILTER_DEFLATE);
+ if (filter_avail < 0)
+ return;
+ else if (filter_avail) {
+ /*
+ * Set 'deflate' filter with reasonable
+ * compression level on DCPL
+ */
+ H5Pset_deflate(dcpl_id, 6);
+ }
+ else {
+ /*
+ * Set Fletcher32 checksum filter on DCPL
+ * since it is always available in HDF5
+ */
+ H5Pset_fletcher32(dcpl_id);
+ }
+}
+
+/*
+ * Routine to fill a data buffer with data. Assumes
+ * dimension rank is 2 and data is stored contiguous.
+ */
+void
+fill_databuf(hsize_t start[], hsize_t count[], hsize_t stride[], C_DATATYPE *data)
+{
+ C_DATATYPE *dataptr = data;
+ hsize_t i, j;
+
+ /* Use MPI rank value for data */
+ for (i = 0; i < count[0]; i++) {
+ for (j = 0; j < count[1]; j++) {
+ *dataptr++ = mpi_rank;
+ }
+ }
+}
+
+/* Cleanup created file */
+static void
+cleanup(char *filename)
+{
+ hbool_t do_cleanup = getenv(HDF5_NOCLEANUP) ? 0 : 1;
+
+ if (do_cleanup)
+ MPI_File_delete(filename, MPI_INFO_NULL);
+}
+
+/*
+ * Routine to write to a dataset in a fashion
+ * where no chunks in the dataset are written
+ * to by more than 1 MPI rank. This will
+ * generally give the best performance as the
+ * MPI ranks will need the least amount of
+ * inter-process communication.
+ */
+static void
+write_dataset_some_no_sel(hid_t file_id, hid_t dxpl_id)
+{
+ C_DATATYPE data[EXAMPLE_DSET_CHUNK_DIM_SIZE][4 * EXAMPLE_DSET_CHUNK_DIM_SIZE];
+ hsize_t dataset_dims[EXAMPLE_DSET_DIMS];
+ hsize_t chunk_dims[EXAMPLE_DSET_DIMS];
+ hsize_t start[EXAMPLE_DSET_DIMS];
+ hsize_t stride[EXAMPLE_DSET_DIMS];
+ hsize_t count[EXAMPLE_DSET_DIMS];
+ hbool_t no_selection;
+ size_t i, j;
+ hid_t dset_id = H5I_INVALID_HID;
+ hid_t dcpl_id = H5I_INVALID_HID;
+ hid_t file_dataspace = H5I_INVALID_HID;
+
+ /*
+ * ------------------------------------
+ * Setup Dataset Creation Property List
+ * ------------------------------------
+ */
+
+ dcpl_id = H5Pcreate(H5P_DATASET_CREATE);
+
+ /*
+ * REQUIRED: Dataset chunking must be enabled to
+ * apply a data filter to the dataset.
+ * Chunks in the dataset are of size
+ * EXAMPLE_DSET_CHUNK_DIM_SIZE x EXAMPLE_DSET_CHUNK_DIM_SIZE.
+ */
+ chunk_dims[0] = EXAMPLE_DSET_CHUNK_DIM_SIZE;
+ chunk_dims[1] = EXAMPLE_DSET_CHUNK_DIM_SIZE;
+ H5Pset_chunk(dcpl_id, EXAMPLE_DSET_DIMS, chunk_dims);
+
+ /* Set filter to be applied to created datasets */
+ set_filter(dcpl_id);
+
+ /*
+ * ------------------------------------
+ * Define the dimensions of the dataset
+ * and create it
+ * ------------------------------------
+ */
+
+ /*
+ * Create a dataset composed of 4 chunks
+ * per MPI rank. The first dataset dimension
+ * scales according to the number of MPI ranks.
+ * The second dataset dimension stays fixed
+ * according to the chunk size.
+ */
+ dataset_dims[0] = EXAMPLE_DSET_CHUNK_DIM_SIZE * mpi_size;
+ dataset_dims[1] = 4 * EXAMPLE_DSET_CHUNK_DIM_SIZE;
+
+ file_dataspace = H5Screate_simple(EXAMPLE_DSET_DIMS, dataset_dims, NULL);
+
+ /* Create the dataset */
+ dset_id = H5Dcreate2(file_id, EXAMPLE_DSET_NAME, HDF5_DATATYPE, file_dataspace, H5P_DEFAULT, dcpl_id,
+ H5P_DEFAULT);
+
+ /*
+ * ------------------------------------
+ * Setup selection in the dataset for
+ * each MPI rank
+ * ------------------------------------
+ */
+
+ /*
+ * Odd rank value MPI ranks do not
+ * contribute any data to the dataset.
+ */
+ no_selection = (mpi_rank % 2) == 1;
+
+ if (no_selection) {
+ /*
+ * MPI ranks not contributing data to
+ * the dataset should call H5Sselect_none
+ * on the file dataspace that will be
+ * passed to H5Dwrite.
+ */
+ H5Sselect_none(file_dataspace);
+ }
+ else {
+ /*
+ * Even MPI ranks contribute data to
+ * the dataset. Each MPI rank's selection
+ * covers a single chunk in the first dataset
+ * dimension. Each MPI rank's selection
+ * covers 4 chunks in the second dataset
+ * dimension. This leads to each contributing
+ * MPI rank writing to 4 chunks of the dataset.
+ */
+ start[0] = mpi_rank * EXAMPLE_DSET_CHUNK_DIM_SIZE;
+ start[1] = 0;
+ stride[0] = 1;
+ stride[1] = 1;
+ count[0] = EXAMPLE_DSET_CHUNK_DIM_SIZE;
+ count[1] = 4 * EXAMPLE_DSET_CHUNK_DIM_SIZE;
+
+ H5Sselect_hyperslab(file_dataspace, H5S_SELECT_SET, start, stride, count, NULL);
+
+ /*
+ * --------------------------------------
+ * Fill data buffer with MPI rank's rank
+ * value to make it easy to see which
+ * part of the dataset each rank wrote to
+ * --------------------------------------
+ */
+
+ fill_databuf(start, count, stride, &data[0][0]);
+ }
+
+ /*
+ * ---------------------------------
+ * Write to the dataset collectively
+ * ---------------------------------
+ */
+
+ H5Dwrite(dset_id, HDF5_DATATYPE, no_selection ? H5S_ALL : H5S_BLOCK, file_dataspace, dxpl_id, data);
+
+ /*
+ * --------------
+ * Close HDF5 IDs
+ * --------------
+ */
+
+ H5Sclose(file_dataspace);
+ H5Pclose(dcpl_id);
+ H5Dclose(dset_id);
+}
+
+int
+main(int argc, char **argv)
+{
+ MPI_Comm comm = MPI_COMM_WORLD;
+ MPI_Info info = MPI_INFO_NULL;
+ hid_t file_id = H5I_INVALID_HID;
+ hid_t fapl_id = H5I_INVALID_HID;
+ hid_t dxpl_id = H5I_INVALID_HID;
+ char * par_prefix = NULL;
+ char filename[PATH_MAX];
+
+ MPI_Init(&argc, &argv);
+ MPI_Comm_size(comm, &mpi_size);
+ MPI_Comm_rank(comm, &mpi_rank);
+
+ /*
+ * ----------------------------------
+ * Start parallel access to HDF5 file
+ * ----------------------------------
+ */
+
+ /* Setup File Access Property List with parallel I/O access */
+ fapl_id = H5Pcreate(H5P_FILE_ACCESS);
+ H5Pset_fapl_mpio(fapl_id, comm, info);
+
+ /*
+ * OPTIONAL: Set collective metadata reads on FAPL to allow
+ * parallel writes to filtered datasets to perform
+ * better at scale. While not strictly necessary,
+ * this is generally recommended.
+ */
+ H5Pset_all_coll_metadata_ops(fapl_id, true);
+
+ /*
+ * OPTIONAL: Set the latest file format version for HDF5 in
+ * order to gain access to different dataset chunk
+ * index types and better data encoding methods.
+ * While not strictly necessary, this is generally
+ * recommended.
+ */
+ H5Pset_libver_bounds(fapl_id, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST);
+
+ /* Parse any parallel prefix and create filename */
+ par_prefix = getenv("HDF5_PARAPREFIX");
+
+ snprintf(filename, PATH_MAX, "%s%s%s", par_prefix ? par_prefix : "", par_prefix ? "/" : "", EXAMPLE_FILE);
+
+ /* Create HDF5 file */
+ file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id);
+
+ /*
+ * --------------------------------------
+ * Setup Dataset Transfer Property List
+ * with collective I/O
+ * --------------------------------------
+ */
+
+ dxpl_id = H5Pcreate(H5P_DATASET_XFER);
+
+ /*
+ * REQUIRED: Setup collective I/O for the dataset
+ * write operations. Parallel writes to
+ * filtered datasets MUST be collective,
+ * even if some ranks have no data to
+ * contribute to the write operation.
+ */
+ H5Pset_dxpl_mpio(dxpl_id, H5FD_MPIO_COLLECTIVE);
+
+ /*
+ * --------------------------------
+ * Create and write to the dataset
+ * --------------------------------
+ */
+
+ /*
+ * Write to a dataset in a fashion where no
+ * chunks in the dataset are written to by
+ * more than 1 MPI rank and some MPI ranks
+ * have nothing to contribute to the dataset.
+ * In this case, the MPI ranks that have no
+ * data to contribute must still participate
+ * in the collective H5Dwrite call, but should
+ * call H5Sselect_none on the file dataspace
+ * passed to the H5Dwrite call.
+ */
+ write_dataset_some_no_sel(file_id, dxpl_id);
+
+ /*
+ * ------------------
+ * Close all HDF5 IDs
+ * ------------------
+ */
+
+ H5Pclose(dxpl_id);
+ H5Pclose(fapl_id);
+ H5Fclose(file_id);
+
+ printf("PHDF5 example finished with no errors\n");
+
+ /*
+ * ------------------------------------
+ * Cleanup created HDF5 file and finish
+ * ------------------------------------
+ */
+
+ cleanup(filename);
+
+ MPI_Finalize();
+
+ return 0;
+}
+
+#else
+
+int
+main(void)
+{
+ printf("HDF5 not configured with parallel support or parallel filtered writes are disabled!\n");
+ return 0;
+}
+
+#endif
diff --git a/examples/ph5example.c b/examples/ph5example.c
index d718479..f16b055 100644
--- a/examples/ph5example.c
+++ b/examples/ph5example.c
@@ -6,7 +6,7 @@
* 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 *
- * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
@@ -30,7 +30,7 @@
* for parallel I/O and there is no standard pathname for parallel file
* systems. In some cases, the parallel file name may even needs some
* parallel file type prefix such as: "pfs:/GF/...". Therefore, this
- * example requires an explicite parallel file prefix. See the usage
+ * example requires an explicit parallel file prefix. See the usage
* for more detail.
*/
@@ -46,69 +46,73 @@
/* Define some handy debugging shorthands, routines, ... */
/* debugging tools */
-#define MESG(x)\
- if (verbose) printf("%s\n", x);\
-
-#define MPI_BANNER(mesg)\
- {printf("--------------------------------\n");\
- printf("Proc %d: ", mpi_rank); \
- printf("*** %s\n", mesg);\
- printf("--------------------------------\n");}
+#define MESG(x) \
+ if (verbose) \
+ printf("%s\n", x);
+
+#define MPI_BANNER(mesg) \
+ { \
+ printf("--------------------------------\n"); \
+ printf("Proc %d: ", mpi_rank); \
+ printf("*** %s\n", mesg); \
+ printf("--------------------------------\n"); \
+ }
-#define SYNC(comm)\
- {MPI_BANNER("doing a SYNC"); MPI_Barrier(comm); MPI_BANNER("SYNC DONE");}
+#define SYNC(comm) \
+ { \
+ MPI_BANNER("doing a SYNC"); \
+ MPI_Barrier(comm); \
+ MPI_BANNER("SYNC DONE"); \
+ }
/* End of Define some handy debugging shorthands, routines, ... */
/* Constants definitions */
/* 24 is a multiple of 2, 3, 4, 6, 8, 12. Neat for parallel tests. */
-#define SPACE1_DIM1 24
-#define SPACE1_DIM2 24
-#define SPACE1_RANK 2
-#define DATASETNAME1 "Data1"
-#define DATASETNAME2 "Data2"
-#define DATASETNAME3 "Data3"
+#define SPACE1_DIM1 24
+#define SPACE1_DIM2 24
+#define SPACE1_RANK 2
+#define DATASETNAME1 "Data1"
+#define DATASETNAME2 "Data2"
+#define DATASETNAME3 "Data3"
/* hyperslab layout styles */
-#define BYROW 1 /* divide into slabs of rows */
-#define BYCOL 2 /* divide into blocks of columns */
-
-#define PARAPREFIX "HDF5_PARAPREFIX" /* file prefix environment variable name */
+#define BYROW 1 /* divide into slabs of rows */
+#define BYCOL 2 /* divide into blocks of columns */
+#define PARAPREFIX "HDF5_PARAPREFIX" /* file prefix environment variable name */
/* dataset data type. Int's can be easily octo dumped. */
typedef int DATATYPE;
/* global variables */
-int nerrors = 0; /* errors count */
+int nerrors = 0; /* errors count */
#ifndef PATH_MAX
-#define PATH_MAX 512
-#endif /* !PATH_MAX */
-char testfiles[2][PATH_MAX];
+#define PATH_MAX 512
+#endif /* !PATH_MAX */
+char testfiles[2][PATH_MAX];
-
-int mpi_size, mpi_rank; /* mpi variables */
+int mpi_size, mpi_rank; /* mpi variables */
/* option flags */
-int verbose = 0; /* verbose, default as no. */
-int doread=1; /* read test */
-int dowrite=1; /* write test */
-int docleanup=1; /* cleanup */
+int verbose = 0; /* verbose, default as no. */
+int doread = 1; /* read test */
+int dowrite = 1; /* write test */
+int docleanup = 1; /* cleanup */
/* Prototypes */
void slab_set(hsize_t start[], hsize_t count[], hsize_t stride[], int mode);
-void dataset_fill(hsize_t start[], hsize_t count[], hsize_t stride[], DATATYPE * dataset);
-void dataset_print(hsize_t start[], hsize_t count[], hsize_t stride[], DATATYPE * dataset);
-int dataset_vrfy(hsize_t start[], hsize_t count[], hsize_t stride[], DATATYPE *dataset, DATATYPE *original);
+void dataset_fill(hsize_t start[], hsize_t count[], hsize_t stride[], DATATYPE *dataset);
+void dataset_print(hsize_t start[], hsize_t count[], hsize_t stride[], DATATYPE *dataset);
+int dataset_vrfy(hsize_t start[], hsize_t count[], hsize_t stride[], DATATYPE *dataset, DATATYPE *original);
void phdf5writeInd(char *filename);
void phdf5readInd(char *filename);
void phdf5writeAll(char *filename);
void phdf5readAll(char *filename);
void test_split_comm_access(char filenames[][PATH_MAX]);
-int parse_options(int argc, char **argv);
+int parse_options(int argc, char **argv);
void usage(void);
-int mkfilenames(char *prefix);
+int mkfilenames(char *prefix);
void cleanup(void);
-
/*
* Setup the dimensions of the hyperslab.
* Two modes--by rows or by columns.
@@ -117,113 +121,110 @@ void cleanup(void);
void
slab_set(hsize_t start[], hsize_t count[], hsize_t stride[], int mode)
{
- switch (mode){
- case BYROW:
- /* Each process takes a slabs of rows. */
- stride[0] = 1;
- stride[1] = 1;
- count[0] = SPACE1_DIM1/mpi_size;
- count[1] = SPACE1_DIM2;
- start[0] = mpi_rank*count[0];
- start[1] = 0;
- break;
- case BYCOL:
- /* Each process takes a block of columns. */
- stride[0] = 1;
- stride[1] = 1;
- count[0] = SPACE1_DIM1;
- count[1] = SPACE1_DIM2/mpi_size;
- start[0] = 0;
- start[1] = mpi_rank*count[1];
- break;
- default:
- /* Unknown mode. Set it to cover the whole dataset. */
- printf("unknown slab_set mode (%d)\n", mode);
- stride[0] = 1;
- stride[1] = 1;
- count[0] = SPACE1_DIM1;
- count[1] = SPACE1_DIM2;
- start[0] = 0;
- start[1] = 0;
- break;
+ switch (mode) {
+ case BYROW:
+ /* Each process takes a slabs of rows. */
+ stride[0] = 1;
+ stride[1] = 1;
+ count[0] = SPACE1_DIM1 / mpi_size;
+ count[1] = SPACE1_DIM2;
+ start[0] = mpi_rank * count[0];
+ start[1] = 0;
+ break;
+ case BYCOL:
+ /* Each process takes a block of columns. */
+ stride[0] = 1;
+ stride[1] = 1;
+ count[0] = SPACE1_DIM1;
+ count[1] = SPACE1_DIM2 / mpi_size;
+ start[0] = 0;
+ start[1] = mpi_rank * count[1];
+ break;
+ default:
+ /* Unknown mode. Set it to cover the whole dataset. */
+ printf("unknown slab_set mode (%d)\n", mode);
+ stride[0] = 1;
+ stride[1] = 1;
+ count[0] = SPACE1_DIM1;
+ count[1] = SPACE1_DIM2;
+ start[0] = 0;
+ start[1] = 0;
+ break;
}
}
-
/*
* Fill the dataset with trivial data for testing.
* Assume dimension rank is 2 and data is stored contiguous.
*/
void
-dataset_fill(hsize_t start[], hsize_t count[], hsize_t stride[], DATATYPE * dataset)
+dataset_fill(hsize_t start[], hsize_t count[], hsize_t stride[], DATATYPE *dataset)
{
DATATYPE *dataptr = dataset;
- hsize_t i, j;
+ hsize_t i, j;
/* put some trivial data in the data_array */
- for (i=0; i < count[0]; i++){
- for (j=0; j < count[1]; j++){
- *dataptr++ = (i*stride[0]+start[0])*100 + (j*stride[1]+start[1]+1);
- }
+ for (i = 0; i < count[0]; i++) {
+ for (j = 0; j < count[1]; j++) {
+ *dataptr++ = (i * stride[0] + start[0]) * 100 + (j * stride[1] + start[1] + 1);
+ }
}
}
-
/*
* Print the content of the dataset.
*/
-void dataset_print(hsize_t start[], hsize_t count[], hsize_t stride[], DATATYPE * dataset)
+void
+dataset_print(hsize_t start[], hsize_t count[], hsize_t stride[], DATATYPE *dataset)
{
DATATYPE *dataptr = dataset;
- hsize_t i, j;
+ hsize_t i, j;
/* print the slab read */
- for (i=0; i < count[0]; i++){
- printf("Row %lu: ", (unsigned long)(i*stride[0]+start[0]));
- for (j=0; j < count[1]; j++){
- printf("%03d ", *dataptr++);
- }
- printf("\n");
+ for (i = 0; i < count[0]; i++) {
+ printf("Row %lu: ", (unsigned long)(i * stride[0] + start[0]));
+ for (j = 0; j < count[1]; j++) {
+ printf("%03d ", *dataptr++);
+ }
+ printf("\n");
}
}
-
/*
* Print the content of the dataset.
*/
-int dataset_vrfy(hsize_t start[], hsize_t count[], hsize_t stride[], DATATYPE *dataset, DATATYPE *original)
+int
+dataset_vrfy(hsize_t start[], hsize_t count[], hsize_t stride[], DATATYPE *dataset, DATATYPE *original)
{
-#define MAX_ERR_REPORT 10 /* Maximum number of errors reported */
+#define MAX_ERR_REPORT 10 /* Maximum number of errors reported */
hsize_t i, j;
- int nerr;
+ int nerr;
/* print it if verbose */
if (verbose)
- dataset_print(start, count, stride, dataset);
+ dataset_print(start, count, stride, dataset);
nerr = 0;
- for (i=0; i < count[0]; i++){
- for (j=0; j < count[1]; j++){
- if (*dataset++ != *original++){
- nerr++;
- if (nerr <= MAX_ERR_REPORT){
- printf("Dataset Verify failed at [%lu][%lu](row %lu, col %lu): expect %d, got %d\n",
- (unsigned long)i, (unsigned long)j,
- (unsigned long)(i*stride[0]+start[0]), (unsigned long)(j*stride[1]+start[1]),
- *(dataset-1), *(original-1));
- }
- }
- }
+ for (i = 0; i < count[0]; i++) {
+ for (j = 0; j < count[1]; j++) {
+ if (*dataset++ != *original++) {
+ nerr++;
+ if (nerr <= MAX_ERR_REPORT) {
+ printf("Dataset Verify failed at [%lu][%lu](row %lu, col %lu): expect %d, got %d\n",
+ (unsigned long)i, (unsigned long)j, (unsigned long)(i * stride[0] + start[0]),
+ (unsigned long)(j * stride[1] + start[1]), *(dataset - 1), *(original - 1));
+ }
+ }
+ }
}
if (nerr > MAX_ERR_REPORT)
- printf("[more errors ...]\n");
+ printf("[more errors ...]\n");
if (nerr)
- printf("%d errors found in dataset_vrfy\n", nerr);
- return(nerr);
+ printf("%d errors found in dataset_vrfy\n", nerr);
+ return (nerr);
}
-
/*
* Example of using the parallel HDF5 library to create two datasets
* in one HDF5 files with parallel MPIO access support.
@@ -235,32 +236,31 @@ int dataset_vrfy(hsize_t start[], hsize_t count[], hsize_t stride[], DATATYPE *d
void
phdf5writeInd(char *filename)
{
- hid_t fid1; /* HDF5 file IDs */
- hid_t acc_tpl1; /* File access templates */
- hid_t sid1; /* Dataspace ID */
- hid_t file_dataspace; /* File dataspace ID */
- hid_t mem_dataspace; /* memory dataspace ID */
- hid_t dataset1, dataset2; /* Dataset ID */
- hsize_t dims1[SPACE1_RANK] =
- {SPACE1_DIM1,SPACE1_DIM2}; /* dataspace dim sizes */
- DATATYPE data_array1[SPACE1_DIM1][SPACE1_DIM2]; /* data buffer */
+ hid_t fid1; /* HDF5 file IDs */
+ hid_t acc_tpl1; /* File access templates */
+ hid_t sid1; /* Dataspace ID */
+ hid_t file_dataspace; /* File dataspace ID */
+ hid_t mem_dataspace; /* memory dataspace ID */
+ hid_t dataset1, dataset2; /* Dataset ID */
+ hsize_t dims1[SPACE1_RANK] = {SPACE1_DIM1, SPACE1_DIM2}; /* dataspace dim sizes */
+ DATATYPE data_array1[SPACE1_DIM1][SPACE1_DIM2]; /* data buffer */
- hsize_t start[SPACE1_RANK]; /* for hyperslab setting */
- hsize_t count[SPACE1_RANK], stride[SPACE1_RANK]; /* for hyperslab setting */
+ hsize_t start[SPACE1_RANK]; /* for hyperslab setting */
+ hsize_t count[SPACE1_RANK], stride[SPACE1_RANK]; /* for hyperslab setting */
- herr_t ret; /* Generic return value */
+ herr_t ret; /* Generic return value */
MPI_Comm comm = MPI_COMM_WORLD;
MPI_Info info = MPI_INFO_NULL;
if (verbose)
- printf("Independent write test on file %s\n", filename);
+ printf("Independent write test on file %s\n", filename);
/* -------------------
* START AN HDF5 FILE
* -------------------*/
/* setup file access template with parallel IO access. */
- acc_tpl1 = H5Pcreate (H5P_FILE_ACCESS);
+ acc_tpl1 = H5Pcreate(H5P_FILE_ACCESS);
assert(acc_tpl1 != FAIL);
MESG("H5Pcreate access succeed");
/* set Parallel access with communicator */
@@ -277,70 +277,60 @@ phdf5writeInd(char *filename)
ret = H5Pclose(acc_tpl1);
assert(ret != FAIL);
-
/* --------------------------
* Define the dimensions of the overall datasets
* and the slabs local to the MPI process.
* ------------------------- */
/* setup dimensionality object */
sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
- assert (sid1 != FAIL);
+ assert(sid1 != FAIL);
MESG("H5Screate_simple succeed");
-
/* create a dataset collectively */
- dataset1 = H5Dcreate2(fid1, DATASETNAME1, H5T_NATIVE_INT, sid1,
- H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ dataset1 = H5Dcreate2(fid1, DATASETNAME1, H5T_NATIVE_INT, sid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
assert(dataset1 != FAIL);
MESG("H5Dcreate2 succeed");
/* create another dataset collectively */
- dataset2 = H5Dcreate2(fid1, DATASETNAME2, H5T_NATIVE_INT, sid1,
- H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ dataset2 = H5Dcreate2(fid1, DATASETNAME2, H5T_NATIVE_INT, sid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
assert(dataset2 != FAIL);
MESG("H5Dcreate2 succeed");
-
-
/* set up dimensions of the slab this process accesses */
- start[0] = mpi_rank*SPACE1_DIM1/mpi_size;
- start[1] = 0;
- count[0] = SPACE1_DIM1/mpi_size;
- count[1] = SPACE1_DIM2;
+ start[0] = mpi_rank * SPACE1_DIM1 / mpi_size;
+ start[1] = 0;
+ count[0] = SPACE1_DIM1 / mpi_size;
+ count[1] = SPACE1_DIM2;
stride[0] = 1;
- stride[1] =1;
-if (verbose)
- printf("start[]=(%lu,%lu), count[]=(%lu,%lu), total datapoints=%lu\n",
- (unsigned long)start[0], (unsigned long)start[1],
- (unsigned long)count[0], (unsigned long)count[1],
- (unsigned long)(count[0]*count[1]));
+ stride[1] = 1;
+ if (verbose)
+ printf("start[]=(%lu,%lu), count[]=(%lu,%lu), total datapoints=%lu\n", (unsigned long)start[0],
+ (unsigned long)start[1], (unsigned long)count[0], (unsigned long)count[1],
+ (unsigned long)(count[0] * count[1]));
/* put some trivial data in the data_array */
dataset_fill(start, count, stride, &data_array1[0][0]);
MESG("data_array initialized");
/* create a file dataspace independently */
- file_dataspace = H5Dget_space (dataset1);
+ file_dataspace = H5Dget_space(dataset1);
assert(file_dataspace != FAIL);
MESG("H5Dget_space succeed");
- ret=H5Sselect_hyperslab(file_dataspace, H5S_SELECT_SET, start, stride,
- count, NULL);
+ ret = H5Sselect_hyperslab(file_dataspace, H5S_SELECT_SET, start, stride, count, NULL);
assert(ret != FAIL);
MESG("H5Sset_hyperslab succeed");
/* create a memory dataspace independently */
- mem_dataspace = H5Screate_simple (SPACE1_RANK, count, NULL);
- assert (mem_dataspace != FAIL);
+ mem_dataspace = H5Screate_simple(SPACE1_RANK, count, NULL);
+ assert(mem_dataspace != FAIL);
/* write data independently */
- ret = H5Dwrite(dataset1, H5T_NATIVE_INT, mem_dataspace, file_dataspace,
- H5P_DEFAULT, data_array1);
+ ret = H5Dwrite(dataset1, H5T_NATIVE_INT, mem_dataspace, file_dataspace, H5P_DEFAULT, data_array1);
assert(ret != FAIL);
MESG("H5Dwrite succeed");
/* write data independently */
- ret = H5Dwrite(dataset2, H5T_NATIVE_INT, mem_dataspace, file_dataspace,
- H5P_DEFAULT, data_array1);
+ ret = H5Dwrite(dataset2, H5T_NATIVE_INT, mem_dataspace, file_dataspace, H5P_DEFAULT, data_array1);
assert(ret != FAIL);
MESG("H5Dwrite succeed");
@@ -348,10 +338,10 @@ if (verbose)
H5Sclose(file_dataspace);
/* close dataset collectively */
- ret=H5Dclose(dataset1);
+ ret = H5Dclose(dataset1);
assert(ret != FAIL);
MESG("H5Dclose1 succeed");
- ret=H5Dclose(dataset2);
+ ret = H5Dclose(dataset2);
assert(ret != FAIL);
MESG("H5Dclose2 succeed");
@@ -366,39 +356,38 @@ if (verbose)
void
phdf5readInd(char *filename)
{
- hid_t fid1; /* HDF5 file IDs */
- hid_t acc_tpl1; /* File access templates */
- hid_t file_dataspace; /* File dataspace ID */
- hid_t mem_dataspace; /* memory dataspace ID */
- hid_t dataset1, dataset2; /* Dataset ID */
- DATATYPE data_array1[SPACE1_DIM1][SPACE1_DIM2]; /* data buffer */
- DATATYPE data_origin1[SPACE1_DIM1][SPACE1_DIM2]; /* expected data buffer */
+ hid_t fid1; /* HDF5 file IDs */
+ hid_t acc_tpl1; /* File access templates */
+ hid_t file_dataspace; /* File dataspace ID */
+ hid_t mem_dataspace; /* memory dataspace ID */
+ hid_t dataset1, dataset2; /* Dataset ID */
+ DATATYPE data_array1[SPACE1_DIM1][SPACE1_DIM2]; /* data buffer */
+ DATATYPE data_origin1[SPACE1_DIM1][SPACE1_DIM2]; /* expected data buffer */
- hsize_t start[SPACE1_RANK]; /* for hyperslab setting */
- hsize_t count[SPACE1_RANK], stride[SPACE1_RANK]; /* for hyperslab setting */
+ hsize_t start[SPACE1_RANK]; /* for hyperslab setting */
+ hsize_t count[SPACE1_RANK], stride[SPACE1_RANK]; /* for hyperslab setting */
- herr_t ret; /* Generic return value */
+ herr_t ret; /* Generic return value */
MPI_Comm comm = MPI_COMM_WORLD;
MPI_Info info = MPI_INFO_NULL;
if (verbose)
- printf("Independent read test on file %s\n", filename);
+ printf("Independent read test on file %s\n", filename);
/* setup file access template */
- acc_tpl1 = H5Pcreate (H5P_FILE_ACCESS);
+ acc_tpl1 = H5Pcreate(H5P_FILE_ACCESS);
assert(acc_tpl1 != FAIL);
/* set Parallel access with communicator */
ret = H5Pset_fapl_mpio(acc_tpl1, comm, info);
assert(ret != FAIL);
-
/* open the file collectively */
- fid1=H5Fopen(filename,H5F_ACC_RDWR,acc_tpl1);
+ fid1 = H5Fopen(filename, H5F_ACC_RDWR, acc_tpl1);
assert(fid1 != FAIL);
/* Release file-access template */
- ret=H5Pclose(acc_tpl1);
+ ret = H5Pclose(acc_tpl1);
assert(ret != FAIL);
/* open the dataset1 collectively */
@@ -409,37 +398,33 @@ phdf5readInd(char *filename)
dataset2 = H5Dopen2(fid1, DATASETNAME1, H5P_DEFAULT);
assert(dataset2 != FAIL);
-
/* set up dimensions of the slab this process accesses */
- start[0] = mpi_rank*SPACE1_DIM1/mpi_size;
- start[1] = 0;
- count[0] = SPACE1_DIM1/mpi_size;
- count[1] = SPACE1_DIM2;
+ start[0] = mpi_rank * SPACE1_DIM1 / mpi_size;
+ start[1] = 0;
+ count[0] = SPACE1_DIM1 / mpi_size;
+ count[1] = SPACE1_DIM2;
stride[0] = 1;
- stride[1] =1;
-if (verbose)
- printf("start[]=(%lu,%lu), count[]=(%lu,%lu), total datapoints=%lu\n",
- (unsigned long)start[0], (unsigned long)start[1],
- (unsigned long)count[0], (unsigned long)count[1],
- (unsigned long)(count[0]*count[1]));
+ stride[1] = 1;
+ if (verbose)
+ printf("start[]=(%lu,%lu), count[]=(%lu,%lu), total datapoints=%lu\n", (unsigned long)start[0],
+ (unsigned long)start[1], (unsigned long)count[0], (unsigned long)count[1],
+ (unsigned long)(count[0] * count[1]));
/* create a file dataspace independently */
- file_dataspace = H5Dget_space (dataset1);
+ file_dataspace = H5Dget_space(dataset1);
assert(file_dataspace != FAIL);
- ret=H5Sselect_hyperslab(file_dataspace, H5S_SELECT_SET, start, stride,
- count, NULL);
+ ret = H5Sselect_hyperslab(file_dataspace, H5S_SELECT_SET, start, stride, count, NULL);
assert(ret != FAIL);
/* create a memory dataspace independently */
- mem_dataspace = H5Screate_simple (SPACE1_RANK, count, NULL);
- assert (mem_dataspace != FAIL);
+ mem_dataspace = H5Screate_simple(SPACE1_RANK, count, NULL);
+ assert(mem_dataspace != FAIL);
/* fill dataset with test data */
dataset_fill(start, count, stride, &data_origin1[0][0]);
/* read data independently */
- ret = H5Dread(dataset1, H5T_NATIVE_INT, mem_dataspace, file_dataspace,
- H5P_DEFAULT, data_array1);
+ ret = H5Dread(dataset1, H5T_NATIVE_INT, mem_dataspace, file_dataspace, H5P_DEFAULT, data_array1);
assert(ret != FAIL);
/* verify the read data with original expected data */
@@ -447,8 +432,7 @@ if (verbose)
assert(ret != FAIL);
/* read data independently */
- ret = H5Dread(dataset2, H5T_NATIVE_INT, mem_dataspace, file_dataspace,
- H5P_DEFAULT, data_array1);
+ ret = H5Dread(dataset2, H5T_NATIVE_INT, mem_dataspace, file_dataspace, H5P_DEFAULT, data_array1);
assert(ret != FAIL);
/* verify the read data with original expected data */
@@ -456,9 +440,9 @@ if (verbose)
assert(ret == 0);
/* close dataset collectively */
- ret=H5Dclose(dataset1);
+ ret = H5Dclose(dataset1);
assert(ret != FAIL);
- ret=H5Dclose(dataset2);
+ ret = H5Dclose(dataset2);
assert(ret != FAIL);
/* release all IDs created */
@@ -468,7 +452,6 @@ if (verbose)
H5Fclose(fid1);
}
-
/*
* Example of using the parallel HDF5 library to create two datasets
* in one HDF5 file with collective parallel access support.
@@ -481,33 +464,32 @@ if (verbose)
void
phdf5writeAll(char *filename)
{
- hid_t fid1; /* HDF5 file IDs */
- hid_t acc_tpl1; /* File access templates */
- hid_t xfer_plist; /* Dataset transfer properties list */
- hid_t sid1; /* Dataspace ID */
- hid_t file_dataspace; /* File dataspace ID */
- hid_t mem_dataspace; /* memory dataspace ID */
- hid_t dataset1, dataset2; /* Dataset ID */
- hsize_t dims1[SPACE1_RANK] =
- {SPACE1_DIM1,SPACE1_DIM2}; /* dataspace dim sizes */
- DATATYPE data_array1[SPACE1_DIM1][SPACE1_DIM2]; /* data buffer */
-
- hsize_t start[SPACE1_RANK]; /* for hyperslab setting */
- hsize_t count[SPACE1_RANK], stride[SPACE1_RANK]; /* for hyperslab setting */
-
- herr_t ret; /* Generic return value */
+ hid_t fid1; /* HDF5 file IDs */
+ hid_t acc_tpl1; /* File access templates */
+ hid_t xfer_plist; /* Dataset transfer properties list */
+ hid_t sid1; /* Dataspace ID */
+ hid_t file_dataspace; /* File dataspace ID */
+ hid_t mem_dataspace; /* memory dataspace ID */
+ hid_t dataset1, dataset2; /* Dataset ID */
+ hsize_t dims1[SPACE1_RANK] = {SPACE1_DIM1, SPACE1_DIM2}; /* dataspace dim sizes */
+ DATATYPE data_array1[SPACE1_DIM1][SPACE1_DIM2]; /* data buffer */
+
+ hsize_t start[SPACE1_RANK]; /* for hyperslab setting */
+ hsize_t count[SPACE1_RANK], stride[SPACE1_RANK]; /* for hyperslab setting */
+
+ herr_t ret; /* Generic return value */
MPI_Comm comm = MPI_COMM_WORLD;
MPI_Info info = MPI_INFO_NULL;
if (verbose)
- printf("Collective write test on file %s\n", filename);
+ printf("Collective write test on file %s\n", filename);
/* -------------------
* START AN HDF5 FILE
* -------------------*/
/* setup file access template with parallel IO access. */
- acc_tpl1 = H5Pcreate (H5P_FILE_ACCESS);
+ acc_tpl1 = H5Pcreate(H5P_FILE_ACCESS);
assert(acc_tpl1 != FAIL);
MESG("H5Pcreate access succeed");
/* set Parallel access with communicator */
@@ -516,25 +498,23 @@ phdf5writeAll(char *filename)
MESG("H5Pset_fapl_mpio succeed");
/* create the file collectively */
- fid1=H5Fcreate(filename,H5F_ACC_TRUNC,H5P_DEFAULT,acc_tpl1);
+ fid1 = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, acc_tpl1);
assert(fid1 != FAIL);
MESG("H5Fcreate succeed");
/* Release file-access template */
- ret=H5Pclose(acc_tpl1);
+ ret = H5Pclose(acc_tpl1);
assert(ret != FAIL);
-
/* --------------------------
* Define the dimensions of the overall datasets
* and create the dataset
* ------------------------- */
/* setup dimensionality object */
- sid1 = H5Screate_simple (SPACE1_RANK, dims1, NULL);
- assert (sid1 != FAIL);
+ sid1 = H5Screate_simple(SPACE1_RANK, dims1, NULL);
+ assert(sid1 != FAIL);
MESG("H5Screate_simple succeed");
-
/* create a dataset collectively */
dataset1 = H5Dcreate2(fid1, DATASETNAME1, H5T_NATIVE_INT, sid1, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
assert(dataset1 != FAIL);
@@ -551,43 +531,40 @@ phdf5writeAll(char *filename)
/* Dataset1: each process takes a block of rows. */
slab_set(start, count, stride, BYROW);
-if (verbose)
- printf("start[]=(%lu,%lu), count[]=(%lu,%lu), total datapoints=%lu\n",
- (unsigned long)start[0], (unsigned long)start[1],
- (unsigned long)count[0], (unsigned long)count[1],
- (unsigned long)(count[0]*count[1]));
+ if (verbose)
+ printf("start[]=(%lu,%lu), count[]=(%lu,%lu), total datapoints=%lu\n", (unsigned long)start[0],
+ (unsigned long)start[1], (unsigned long)count[0], (unsigned long)count[1],
+ (unsigned long)(count[0] * count[1]));
/* create a file dataspace independently */
- file_dataspace = H5Dget_space (dataset1);
+ file_dataspace = H5Dget_space(dataset1);
assert(file_dataspace != FAIL);
MESG("H5Dget_space succeed");
- ret=H5Sselect_hyperslab(file_dataspace, H5S_SELECT_SET, start, stride,
- count, NULL);
+ ret = H5Sselect_hyperslab(file_dataspace, H5S_SELECT_SET, start, stride, count, NULL);
assert(ret != FAIL);
MESG("H5Sset_hyperslab succeed");
/* create a memory dataspace independently */
- mem_dataspace = H5Screate_simple (SPACE1_RANK, count, NULL);
- assert (mem_dataspace != FAIL);
+ mem_dataspace = H5Screate_simple(SPACE1_RANK, count, NULL);
+ assert(mem_dataspace != FAIL);
/* fill the local slab with some trivial data */
dataset_fill(start, count, stride, &data_array1[0][0]);
MESG("data_array initialized");
- if (verbose){
- MESG("data_array created");
- dataset_print(start, count, stride, &data_array1[0][0]);
+ if (verbose) {
+ MESG("data_array created");
+ dataset_print(start, count, stride, &data_array1[0][0]);
}
/* set up the collective transfer properties list */
- xfer_plist = H5Pcreate (H5P_DATASET_XFER);
+ xfer_plist = H5Pcreate(H5P_DATASET_XFER);
assert(xfer_plist != FAIL);
- ret=H5Pset_dxpl_mpio(xfer_plist, H5FD_MPIO_COLLECTIVE);
+ ret = H5Pset_dxpl_mpio(xfer_plist, H5FD_MPIO_COLLECTIVE);
assert(ret != FAIL);
MESG("H5Pcreate xfer succeed");
/* write data collectively */
- ret = H5Dwrite(dataset1, H5T_NATIVE_INT, mem_dataspace, file_dataspace,
- xfer_plist, data_array1);
+ ret = H5Dwrite(dataset1, H5T_NATIVE_INT, mem_dataspace, file_dataspace, xfer_plist, data_array1);
assert(ret != FAIL);
MESG("H5Dwrite succeed");
@@ -600,51 +577,48 @@ if (verbose)
/* Dataset2: each process takes a block of columns. */
slab_set(start, count, stride, BYCOL);
-if (verbose)
- printf("start[]=(%lu,%lu), count[]=(%lu,%lu), total datapoints=%lu\n",
- (unsigned long)start[0], (unsigned long)start[1],
- (unsigned long)count[0], (unsigned long)count[1],
- (unsigned long)(count[0]*count[1]));
+ if (verbose)
+ printf("start[]=(%lu,%lu), count[]=(%lu,%lu), total datapoints=%lu\n", (unsigned long)start[0],
+ (unsigned long)start[1], (unsigned long)count[0], (unsigned long)count[1],
+ (unsigned long)(count[0] * count[1]));
/* put some trivial data in the data_array */
dataset_fill(start, count, stride, &data_array1[0][0]);
MESG("data_array initialized");
- if (verbose){
- MESG("data_array created");
- dataset_print(start, count, stride, &data_array1[0][0]);
+ if (verbose) {
+ MESG("data_array created");
+ dataset_print(start, count, stride, &data_array1[0][0]);
}
/* create a file dataspace independently */
- file_dataspace = H5Dget_space (dataset1);
+ file_dataspace = H5Dget_space(dataset1);
assert(file_dataspace != FAIL);
MESG("H5Dget_space succeed");
- ret=H5Sselect_hyperslab(file_dataspace, H5S_SELECT_SET, start, stride,
- count, NULL);
+ ret = H5Sselect_hyperslab(file_dataspace, H5S_SELECT_SET, start, stride, count, NULL);
assert(ret != FAIL);
MESG("H5Sset_hyperslab succeed");
/* create a memory dataspace independently */
- mem_dataspace = H5Screate_simple (SPACE1_RANK, count, NULL);
- assert (mem_dataspace != FAIL);
+ mem_dataspace = H5Screate_simple(SPACE1_RANK, count, NULL);
+ assert(mem_dataspace != FAIL);
/* fill the local slab with some trivial data */
dataset_fill(start, count, stride, &data_array1[0][0]);
MESG("data_array initialized");
- if (verbose){
- MESG("data_array created");
- dataset_print(start, count, stride, &data_array1[0][0]);
+ if (verbose) {
+ MESG("data_array created");
+ dataset_print(start, count, stride, &data_array1[0][0]);
}
/* set up the collective transfer properties list */
- xfer_plist = H5Pcreate (H5P_DATASET_XFER);
+ xfer_plist = H5Pcreate(H5P_DATASET_XFER);
assert(xfer_plist != FAIL);
- ret=H5Pset_dxpl_mpio(xfer_plist, H5FD_MPIO_COLLECTIVE);
+ ret = H5Pset_dxpl_mpio(xfer_plist, H5FD_MPIO_COLLECTIVE);
assert(ret != FAIL);
MESG("H5Pcreate xfer succeed");
/* write data independently */
- ret = H5Dwrite(dataset2, H5T_NATIVE_INT, mem_dataspace, file_dataspace,
- xfer_plist, data_array1);
+ ret = H5Dwrite(dataset2, H5T_NATIVE_INT, mem_dataspace, file_dataspace, xfer_plist, data_array1);
assert(ret != FAIL);
MESG("H5Dwrite succeed");
@@ -653,14 +627,13 @@ if (verbose)
H5Sclose(mem_dataspace);
H5Pclose(xfer_plist);
-
/*
* All writes completed. Close datasets collectively
*/
- ret=H5Dclose(dataset1);
+ ret = H5Dclose(dataset1);
assert(ret != FAIL);
MESG("H5Dclose1 succeed");
- ret=H5Dclose(dataset2);
+ ret = H5Dclose(dataset2);
assert(ret != FAIL);
MESG("H5Dclose2 succeed");
@@ -683,31 +656,31 @@ if (verbose)
void
phdf5readAll(char *filename)
{
- hid_t fid1; /* HDF5 file IDs */
- hid_t acc_tpl1; /* File access templates */
- hid_t xfer_plist; /* Dataset transfer properties list */
- hid_t file_dataspace; /* File dataspace ID */
- hid_t mem_dataspace; /* memory dataspace ID */
- hid_t dataset1, dataset2; /* Dataset ID */
- DATATYPE data_array1[SPACE1_DIM1][SPACE1_DIM2]; /* data buffer */
- DATATYPE data_origin1[SPACE1_DIM1][SPACE1_DIM2]; /* expected data buffer */
+ hid_t fid1; /* HDF5 file IDs */
+ hid_t acc_tpl1; /* File access templates */
+ hid_t xfer_plist; /* Dataset transfer properties list */
+ hid_t file_dataspace; /* File dataspace ID */
+ hid_t mem_dataspace; /* memory dataspace ID */
+ hid_t dataset1, dataset2; /* Dataset ID */
+ DATATYPE data_array1[SPACE1_DIM1][SPACE1_DIM2]; /* data buffer */
+ DATATYPE data_origin1[SPACE1_DIM1][SPACE1_DIM2]; /* expected data buffer */
- hsize_t start[SPACE1_RANK]; /* for hyperslab setting */
- hsize_t count[SPACE1_RANK], stride[SPACE1_RANK]; /* for hyperslab setting */
+ hsize_t start[SPACE1_RANK]; /* for hyperslab setting */
+ hsize_t count[SPACE1_RANK], stride[SPACE1_RANK]; /* for hyperslab setting */
- herr_t ret; /* Generic return value */
+ herr_t ret; /* Generic return value */
MPI_Comm comm = MPI_COMM_WORLD;
MPI_Info info = MPI_INFO_NULL;
if (verbose)
- printf("Collective read test on file %s\n", filename);
+ printf("Collective read test on file %s\n", filename);
/* -------------------
* OPEN AN HDF5 FILE
* -------------------*/
/* setup file access template with parallel IO access. */
- acc_tpl1 = H5Pcreate (H5P_FILE_ACCESS);
+ acc_tpl1 = H5Pcreate(H5P_FILE_ACCESS);
assert(acc_tpl1 != FAIL);
MESG("H5Pcreate access succeed");
/* set Parallel access with communicator */
@@ -716,15 +689,14 @@ phdf5readAll(char *filename)
MESG("H5Pset_fapl_mpio succeed");
/* open the file collectively */
- fid1=H5Fopen(filename,H5F_ACC_RDWR,acc_tpl1);
+ fid1 = H5Fopen(filename, H5F_ACC_RDWR, acc_tpl1);
assert(fid1 != FAIL);
MESG("H5Fopen succeed");
/* Release file-access template */
- ret=H5Pclose(acc_tpl1);
+ ret = H5Pclose(acc_tpl1);
assert(ret != FAIL);
-
/* --------------------------
* Open the datasets in it
* ------------------------- */
@@ -744,43 +716,40 @@ phdf5readAll(char *filename)
/* Dataset1: each process takes a block of columns. */
slab_set(start, count, stride, BYCOL);
-if (verbose)
- printf("start[]=(%lu,%lu), count[]=(%lu,%lu), total datapoints=%lu\n",
- (unsigned long)start[0], (unsigned long)start[1],
- (unsigned long)count[0], (unsigned long)count[1],
- (unsigned long)(count[0]*count[1]));
+ if (verbose)
+ printf("start[]=(%lu,%lu), count[]=(%lu,%lu), total datapoints=%lu\n", (unsigned long)start[0],
+ (unsigned long)start[1], (unsigned long)count[0], (unsigned long)count[1],
+ (unsigned long)(count[0] * count[1]));
/* create a file dataspace independently */
- file_dataspace = H5Dget_space (dataset1);
+ file_dataspace = H5Dget_space(dataset1);
assert(file_dataspace != FAIL);
MESG("H5Dget_space succeed");
- ret=H5Sselect_hyperslab(file_dataspace, H5S_SELECT_SET, start, stride,
- count, NULL);
+ ret = H5Sselect_hyperslab(file_dataspace, H5S_SELECT_SET, start, stride, count, NULL);
assert(ret != FAIL);
MESG("H5Sset_hyperslab succeed");
/* create a memory dataspace independently */
- mem_dataspace = H5Screate_simple (SPACE1_RANK, count, NULL);
- assert (mem_dataspace != FAIL);
+ mem_dataspace = H5Screate_simple(SPACE1_RANK, count, NULL);
+ assert(mem_dataspace != FAIL);
/* fill dataset with test data */
dataset_fill(start, count, stride, &data_origin1[0][0]);
MESG("data_array initialized");
- if (verbose){
- MESG("data_array created");
- dataset_print(start, count, stride, &data_array1[0][0]);
+ if (verbose) {
+ MESG("data_array created");
+ dataset_print(start, count, stride, &data_array1[0][0]);
}
/* set up the collective transfer properties list */
- xfer_plist = H5Pcreate (H5P_DATASET_XFER);
+ xfer_plist = H5Pcreate(H5P_DATASET_XFER);
assert(xfer_plist != FAIL);
- ret=H5Pset_dxpl_mpio(xfer_plist, H5FD_MPIO_COLLECTIVE);
+ ret = H5Pset_dxpl_mpio(xfer_plist, H5FD_MPIO_COLLECTIVE);
assert(ret != FAIL);
MESG("H5Pcreate xfer succeed");
/* read data collectively */
- ret = H5Dread(dataset1, H5T_NATIVE_INT, mem_dataspace, file_dataspace,
- xfer_plist, data_array1);
+ ret = H5Dread(dataset1, H5T_NATIVE_INT, mem_dataspace, file_dataspace, xfer_plist, data_array1);
assert(ret != FAIL);
MESG("H5Dread succeed");
@@ -797,43 +766,40 @@ if (verbose)
/* Dataset2: each process takes a block of rows. */
slab_set(start, count, stride, BYROW);
-if (verbose)
- printf("start[]=(%lu,%lu), count[]=(%lu,%lu), total datapoints=%lu\n",
- (unsigned long)start[0], (unsigned long)start[1],
- (unsigned long)count[0], (unsigned long)count[1],
- (unsigned long)(count[0]*count[1]));
+ if (verbose)
+ printf("start[]=(%lu,%lu), count[]=(%lu,%lu), total datapoints=%lu\n", (unsigned long)start[0],
+ (unsigned long)start[1], (unsigned long)count[0], (unsigned long)count[1],
+ (unsigned long)(count[0] * count[1]));
/* create a file dataspace independently */
- file_dataspace = H5Dget_space (dataset1);
+ file_dataspace = H5Dget_space(dataset1);
assert(file_dataspace != FAIL);
MESG("H5Dget_space succeed");
- ret=H5Sselect_hyperslab(file_dataspace, H5S_SELECT_SET, start, stride,
- count, NULL);
+ ret = H5Sselect_hyperslab(file_dataspace, H5S_SELECT_SET, start, stride, count, NULL);
assert(ret != FAIL);
MESG("H5Sset_hyperslab succeed");
/* create a memory dataspace independently */
- mem_dataspace = H5Screate_simple (SPACE1_RANK, count, NULL);
- assert (mem_dataspace != FAIL);
+ mem_dataspace = H5Screate_simple(SPACE1_RANK, count, NULL);
+ assert(mem_dataspace != FAIL);
/* fill dataset with test data */
dataset_fill(start, count, stride, &data_origin1[0][0]);
MESG("data_array initialized");
- if (verbose){
- MESG("data_array created");
- dataset_print(start, count, stride, &data_array1[0][0]);
+ if (verbose) {
+ MESG("data_array created");
+ dataset_print(start, count, stride, &data_array1[0][0]);
}
/* set up the collective transfer properties list */
- xfer_plist = H5Pcreate (H5P_DATASET_XFER);
+ xfer_plist = H5Pcreate(H5P_DATASET_XFER);
assert(xfer_plist != FAIL);
- ret=H5Pset_dxpl_mpio(xfer_plist, H5FD_MPIO_COLLECTIVE);
+ ret = H5Pset_dxpl_mpio(xfer_plist, H5FD_MPIO_COLLECTIVE);
assert(ret != FAIL);
MESG("H5Pcreate xfer succeed");
/* read data independently */
- ret = H5Dread(dataset2, H5T_NATIVE_INT, mem_dataspace, file_dataspace,
- xfer_plist, data_array1);
+ ret = H5Dread(dataset2, H5T_NATIVE_INT, mem_dataspace, file_dataspace, xfer_plist, data_array1);
assert(ret != FAIL);
MESG("H5Dread succeed");
@@ -846,14 +812,13 @@ if (verbose)
H5Sclose(mem_dataspace);
H5Pclose(xfer_plist);
-
/*
* All reads completed. Close datasets collectively
*/
- ret=H5Dclose(dataset1);
+ ret = H5Dclose(dataset1);
assert(ret != FAIL);
MESG("H5Dclose1 succeed");
- ret=H5Dclose(dataset2);
+ ret = H5Dclose(dataset2);
assert(ret != FAIL);
MESG("H5Dclose2 succeed");
@@ -877,52 +842,53 @@ test_split_comm_access(char filenames[][PATH_MAX])
{
MPI_Comm comm;
MPI_Info info = MPI_INFO_NULL;
- int color, mrc;
- int newrank, newprocs;
- hid_t fid; /* file IDs */
- hid_t acc_tpl; /* File access properties */
- herr_t ret; /* generic return value */
+ int color, mrc;
+ int newrank, newprocs;
+ hid_t fid; /* file IDs */
+ hid_t acc_tpl; /* File access properties */
+ herr_t ret; /* generic return value */
if (verbose)
- printf("Independent write test on file %s %s\n",
- filenames[0], filenames[1]);
-
- color = mpi_rank%2;
- mrc = MPI_Comm_split (MPI_COMM_WORLD, color, mpi_rank, &comm);
- assert(mrc==MPI_SUCCESS);
- MPI_Comm_size(comm,&newprocs);
- MPI_Comm_rank(comm,&newrank);
-
- if (color){
- /* odd-rank processes */
- mrc = MPI_Barrier(comm);
- assert(mrc==MPI_SUCCESS);
- }else{
- /* even-rank processes */
- /* setup file access template */
- acc_tpl = H5Pcreate (H5P_FILE_ACCESS);
- assert(acc_tpl != FAIL);
-
- /* set Parallel access with communicator */
- ret = H5Pset_fapl_mpio(acc_tpl, comm, info);
- assert(ret != FAIL);
-
- /* create the file collectively */
- fid=H5Fcreate(filenames[color],H5F_ACC_TRUNC,H5P_DEFAULT,acc_tpl);
- assert(fid != FAIL);
- MESG("H5Fcreate succeed");
-
- /* Release file-access template */
- ret=H5Pclose(acc_tpl);
- assert(ret != FAIL);
-
- ret=H5Fclose(fid);
- assert(ret != FAIL);
+ printf("Independent write test on file %s %s\n", filenames[0], filenames[1]);
+
+ color = mpi_rank % 2;
+ mrc = MPI_Comm_split(MPI_COMM_WORLD, color, mpi_rank, &comm);
+ assert(mrc == MPI_SUCCESS);
+ MPI_Comm_size(comm, &newprocs);
+ MPI_Comm_rank(comm, &newrank);
+
+ if (color) {
+ /* odd-rank processes */
+ mrc = MPI_Barrier(comm);
+ assert(mrc == MPI_SUCCESS);
}
- if (mpi_rank == 0){
- mrc = MPI_File_delete(filenames[color], info);
- assert(mrc==MPI_SUCCESS);
+ else {
+ /* even-rank processes */
+ /* setup file access template */
+ acc_tpl = H5Pcreate(H5P_FILE_ACCESS);
+ assert(acc_tpl != FAIL);
+
+ /* set Parallel access with communicator */
+ ret = H5Pset_fapl_mpio(acc_tpl, comm, info);
+ assert(ret != FAIL);
+
+ /* create the file collectively */
+ fid = H5Fcreate(filenames[color], H5F_ACC_TRUNC, H5P_DEFAULT, acc_tpl);
+ assert(fid != FAIL);
+ MESG("H5Fcreate succeed");
+
+ /* Release file-access template */
+ ret = H5Pclose(acc_tpl);
+ assert(ret != FAIL);
+
+ ret = H5Fclose(fid);
+ assert(ret != FAIL);
}
+ if (mpi_rank == 0) {
+ mrc = MPI_File_delete(filenames[color], info);
+ assert(mrc == MPI_SUCCESS);
+ }
+ MPI_Comm_free(&comm);
}
/*
@@ -933,7 +899,7 @@ usage(void)
{
printf("Usage: testphdf5 [-f <prefix>] [-r] [-w] [-v]\n");
printf("\t-f\tfile prefix for parallel test files.\n");
- printf("\t \te.g. pfs:/PFS/myname\n");
+ printf("\t \t e.g. pfs:/PFS/myname\n");
printf("\t \tcan be set via $" PARAPREFIX ".\n");
printf("\t \tDefault is current directory.\n");
printf("\t-c\tno cleanup\n");
@@ -944,7 +910,6 @@ usage(void)
printf("\n");
}
-
/*
* compose the test filename with the prefix supplied.
* return code: 0 if no error
@@ -953,88 +918,93 @@ usage(void)
int
mkfilenames(char *prefix)
{
- int i, n;
+ int i, n;
size_t strsize;
/* filename will be prefix/ParaEgN.h5 where N is 0 to 9. */
/* So, string must be big enough to hold the prefix, / and 10 more chars */
/* and the terminating null. */
strsize = strlen(prefix) + 12;
- if (strsize > PATH_MAX){
- printf("File prefix too long; Use a short path name.\n");
- return(1);
+ if (strsize > PATH_MAX) {
+ printf("File prefix too long; Use a short path name.\n");
+ return (1);
}
- n = sizeof(testfiles)/sizeof(testfiles[0]);
- if (n > 9){
- printf("Warning: Too many entries in testfiles. "
- "Need to adjust the code to accommodate the large size.\n");
+ n = sizeof(testfiles) / sizeof(testfiles[0]);
+ if (n > 9) {
+ printf("Warning: Too many entries in testfiles. "
+ "Need to adjust the code to accommodate the large size.\n");
}
- for (i=0; i<n; i++){
- sprintf(testfiles[i], "%s/ParaEg%d.h5", prefix, i);
+ for (i = 0; i < n; i++) {
+ snprintf(testfiles[i], PATH_MAX, "%s/ParaEg%d.h5", prefix, i);
}
- return(0);
-
+ return (0);
}
-
/*
* parse the command line options
*/
int
-parse_options(int argc, char **argv){
+parse_options(int argc, char **argv)
+{
int i, n;
/* initialize testfiles to nulls */
- n = sizeof(testfiles)/sizeof(testfiles[0]);
- for (i=0; i<n; i++){
- testfiles[i][0] = '\0';
+ n = sizeof(testfiles) / sizeof(testfiles[0]);
+ for (i = 0; i < n; i++) {
+ testfiles[i][0] = '\0';
}
- while (--argc){
- if (**(++argv) != '-'){
- break;
- }else{
- switch(*(*argv+1)){
- case 'f': ++argv;
- if (--argc < 1){
- usage();
- nerrors++;
- return(1);
- }
- if (mkfilenames(*argv)){
- nerrors++;
- return(1);
- }
- break;
- case 'c': docleanup = 0; /* no cleanup */
- break;
- case 'r': doread = 0;
- break;
- case 'w': dowrite = 0;
- break;
- case 'v': verbose = 1;
- break;
- default: usage();
- nerrors++;
- return(1);
- }
- }
+ while (--argc) {
+ if (**(++argv) != '-') {
+ break;
+ }
+ else {
+ switch (*(*argv + 1)) {
+ case 'f':
+ ++argv;
+ if (--argc < 1) {
+ usage();
+ nerrors++;
+ return (1);
+ }
+ if (mkfilenames(*argv)) {
+ nerrors++;
+ return (1);
+ }
+ break;
+ case 'c':
+ docleanup = 0; /* no cleanup */
+ break;
+ case 'r':
+ doread = 0;
+ break;
+ case 'w':
+ dowrite = 0;
+ break;
+ case 'v':
+ verbose = 1;
+ break;
+ default:
+ usage();
+ nerrors++;
+ return (1);
+ }
+ }
}
/* check the file prefix */
- if (testfiles[0][0] == '\0'){
- /* try get it from environment variable HDF5_PARAPREFIX */
- char *env;
- char *env_default = "."; /* default to current directory */
- if ((env=getenv(PARAPREFIX))==NULL){
- env = env_default;
- }
- mkfilenames(env);
+ if (testfiles[0][0] == '\0') {
+ /* try get it from environment variable HDF5_PARAPREFIX */
+ char *env;
+ char *env_default = "."; /* default to current directory */
+ if ((env = getenv(PARAPREFIX)) == NULL) {
+ env = env_default;
+ }
+ mkfilenames(env);
}
- return(0);
+ return (0);
}
-
/*
* cleanup test files created
*/
@@ -1043,88 +1013,87 @@ cleanup(void)
{
int i, n;
- n = sizeof(testfiles)/sizeof(testfiles[0]);
- for (i=0; i<n; i++){
- MPI_File_delete(testfiles[i], MPI_INFO_NULL);
+ n = sizeof(testfiles) / sizeof(testfiles[0]);
+ for (i = 0; i < n; i++) {
+ MPI_File_delete(testfiles[i], MPI_INFO_NULL);
}
}
-
/* Main Program */
int
main(int argc, char **argv)
{
- int mpi_namelen;
+ int mpi_namelen;
char mpi_name[MPI_MAX_PROCESSOR_NAME];
- int i, n;
+ int i, n;
- MPI_Init(&argc,&argv);
- MPI_Comm_size(MPI_COMM_WORLD,&mpi_size);
- MPI_Comm_rank(MPI_COMM_WORLD,&mpi_rank);
- MPI_Get_processor_name(mpi_name,&mpi_namelen);
+ MPI_Init(&argc, &argv);
+ MPI_Comm_size(MPI_COMM_WORLD, &mpi_size);
+ MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
+ MPI_Get_processor_name(mpi_name, &mpi_namelen);
/* Make sure datasets can be divided into equal chunks by the processes */
- if ((SPACE1_DIM1 % mpi_size) || (SPACE1_DIM2 % mpi_size)){
- printf("DIM1(%d) and DIM2(%d) must be multiples of processes (%d)\n",
- SPACE1_DIM1, SPACE1_DIM2, mpi_size);
- nerrors++;
- goto finish;
+ if ((SPACE1_DIM1 % mpi_size) || (SPACE1_DIM2 % mpi_size)) {
+ printf("DIM1(%d) and DIM2(%d) must be multiples of processes (%d)\n", SPACE1_DIM1, SPACE1_DIM2,
+ mpi_size);
+ nerrors++;
+ goto finish;
}
if (parse_options(argc, argv) != 0)
- goto finish;
+ goto finish;
/* show test file names */
- if (mpi_rank == 0){
- n = sizeof(testfiles)/sizeof(testfiles[0]);
- printf("Parallel test files are:\n");
- for (i=0; i<n; i++){
- printf(" %s\n", testfiles[i]);
- }
+ if (mpi_rank == 0) {
+ n = sizeof(testfiles) / sizeof(testfiles[0]);
+ printf("Parallel test files are:\n");
+ for (i = 0; i < n; i++) {
+ printf(" %s\n", testfiles[i]);
+ }
}
- if (dowrite){
- MPI_BANNER("testing PHDF5 dataset using split communicators...");
- test_split_comm_access(testfiles);
- MPI_BANNER("testing PHDF5 dataset independent write...");
- phdf5writeInd(testfiles[0]);
- MPI_BANNER("testing PHDF5 dataset collective write...");
- phdf5writeAll(testfiles[1]);
+ if (dowrite) {
+ MPI_BANNER("testing PHDF5 dataset using split communicators...");
+ test_split_comm_access(testfiles);
+ MPI_BANNER("testing PHDF5 dataset independent write...");
+ phdf5writeInd(testfiles[0]);
+ MPI_BANNER("testing PHDF5 dataset collective write...");
+ phdf5writeAll(testfiles[1]);
}
- if (doread){
- MPI_BANNER("testing PHDF5 dataset independent read...");
- phdf5readInd(testfiles[0]);
- MPI_BANNER("testing PHDF5 dataset collective read...");
- phdf5readAll(testfiles[1]);
+ if (doread) {
+ MPI_BANNER("testing PHDF5 dataset independent read...");
+ phdf5readInd(testfiles[0]);
+ MPI_BANNER("testing PHDF5 dataset collective read...");
+ phdf5readAll(testfiles[1]);
}
- if (!(dowrite || doread)){
- usage();
- nerrors++;
+ if (!(dowrite || doread)) {
+ usage();
+ nerrors++;
}
finish:
- if (mpi_rank == 0){ /* only process 0 reports */
- if (nerrors)
- printf("***PHDF5 tests detected %d errors***\n", nerrors);
- else{
- printf("===================================\n");
- printf("PHDF5 tests finished with no errors\n");
- printf("===================================\n");
- }
+ if (mpi_rank == 0) { /* only process 0 reports */
+ if (nerrors)
+ printf("***PHDF5 example detected %d errors***\n", nerrors);
+ else {
+ printf("=====================================\n");
+ printf("PHDF5 example finished with no errors\n");
+ printf("=====================================\n");
+ }
}
if (docleanup)
- cleanup();
+ cleanup();
MPI_Finalize();
- return(nerrors);
+ return (nerrors);
}
-#else /* H5_HAVE_PARALLEL */
+#else /* H5_HAVE_PARALLEL */
/* dummy program since H5_HAVE_PARALLE is not configured in */
int
main(void)
{
-printf("No PHDF5 example because parallel is not configured in\n");
-return(0);
+ printf("No PHDF5 example because parallel is not configured in\n");
+ return (0);
}
#endif /* H5_HAVE_PARALLEL */
diff --git a/examples/run-all-ex.sh b/examples/run-all-ex.sh
index 878e0f8..afd4308 100755
--- a/examples/run-all-ex.sh
+++ b/examples/run-all-ex.sh
@@ -6,7 +6,7 @@
# 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
-# distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.
+# distribution tree, or in https://www.hdfgroup.org/licenses.
# If you do not have access to either file, you may request a copy from
# help@hdfgroup.org.
diff --git a/examples/run-c-ex.sh.in b/examples/run-c-ex.sh.in
index 209cdd7..aae1d34 100644
--- a/examples/run-c-ex.sh.in
+++ b/examples/run-c-ex.sh.in
@@ -6,7 +6,7 @@
# 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
-# distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.
+# distribution tree, or in https://www.hdfgroup.org/licenses.
# If you do not have access to either file, you may request a copy from
# help@hdfgroup.org.
@@ -18,7 +18,7 @@
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
# #
# This script will compile and run the c examples from source files installed #
-# in .../share/hdf5_examples/c using h5cc or h5pc. The order for running #
+# in @examplesdir@/c using h5cc or h5pc. The order for running #
# programs with RunTest in the MAIN section below is taken from the Makefile. #
# The order is important since some of the test programs use data files created #
# by earlier test programs. Any future additions should be placed accordingly. #
@@ -28,10 +28,33 @@
# Initializations
EXIT_SUCCESS=0
EXIT_FAILURE=1
-
+
+#
+# Try to derive the path to the installation $prefix established
+# by ./configure relative to the examples directory established by
+# ./configure. If successful, set `prefix_relto_examplesdir` to the
+# relative path. Otherwise, set `prefix_relto_examplesdir` to the
+# absolute installation $prefix.
+#
+# This script uses the value of `prefix` in the user's environment, if
+# it is set, below. The content of $() is evaluated in a sub-shell, so
+# if `prefix` is set in the user's environment, the shell statements in
+# $() won't clobbered it.
+#
+prefix_relto_examplesdir=$(
+prefix=@prefix@
+examplesdir=@examplesdir@
+if [ ${examplesdir##${prefix}/} != ${examplesdir} ]; then
+ echo $(echo ${examplesdir##${prefix}/} | \
+ sed 's,[^/][^/]*,..,g')
+else
+ echo $prefix
+fi
+)
+
# Where the tool is installed.
-# default is relative path to installed location of the tools
-prefix="${prefix:-../../..}"
+# default is relative path to installed location of the tools
+prefix="${prefix:-../${prefix_relto_examplesdir}}"
PARALLEL=@PARALLEL@ # Am I in parallel mode?
AR="@AR@"
RANLIB="@RANLIB@"
@@ -112,16 +135,25 @@ then
rm h5_attribute &&\
RunTest h5_mount &&\
rm h5_mount &&\
- RunTest h5_reference &&\
- rm h5_reference &&\
+ RunTest h5_reference_deprec &&\
+ rm h5_reference_deprec &&\
+ RunTest h5_ref_extern &&\
+ rm h5_ref_extern &&\
+ RunTest h5_ref_compat &&\
+ rm h5_ref_compat &&\
RunTest h5_drivers &&\
rm h5_drivers &&\
- RunTest h5_ref2reg &&\
- rm h5_ref2reg &&\
+ RunTest h5_ref2reg_deprec &&\
+ rm h5_ref2reg_deprec &&\
RunTest h5_extlink &&\
rm h5_extlink &&\
RunTest h5_elink_unix2win &&\
rm h5_elink_unix2win &&\
+ OLD_DEBUG_STRING=$HDF5_DEBUG &&\
+ export HDF5_DEBUG="+all +trace +ttimes" &&\
+ RunTest h5_debug_trace &&\
+ HDF5_DEBUG=$OLD_DEBUG_STRING &&\
+ rm h5_debug_trace &&\
RunTest h5_shared_mesg &&\
rm h5_shared_mesg &&\
RunTest h5_vds-eiger &&\
@@ -152,5 +184,5 @@ rm *.h5
rm -rf red blue u2w
echo
-exit $EXIT_VALUE
+exit $EXIT_VALUE
diff --git a/examples/testh5cc.sh.in b/examples/testh5cc.sh.in
index 800d4d4..a8974bf 100644
--- a/examples/testh5cc.sh.in
+++ b/examples/testh5cc.sh.in
@@ -7,7 +7,7 @@
# 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
-# distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.
+# distribution tree, or in https://www.hdfgroup.org/licenses.
# If you do not have access to either file, you may request a copy from
# help@hdfgroup.org.
#
@@ -48,6 +48,10 @@ verbose=${HDF5_VERBOSE:-1} # 0: none; 1: default; 2: chatty; 3: everything
test $verbose -gt 2 && set -x
H5_NO_DEPRECATED_SYMBOLS=`grep '#define H5_NO_DEPRECATED_SYMBOLS ' ../src/H5pubconf.h`
H5_USE_16_API_DEFAULT=`grep '#define H5_USE_16_API_DEFAULT ' ../src/H5pubconf.h`
+H5_USE_18_API_DEFAULT=`grep '#define H5_USE_18_API_DEFAULT ' ../src/H5pubconf.h`
+H5_USE_110_API_DEFAULT=`grep '#define H5_USE_110_API_DEFAULT ' ../src/H5pubconf.h`
+H5_USE_112_API_DEFAULT=`grep '#define H5_USE_112_API_DEFAULT ' ../src/H5pubconf.h`
+H5_USE_114_API_DEFAULT=`grep '#define H5_USE_114_API_DEFAULT ' ../src/H5pubconf.h`
# setup my machine information.
myos=`uname -s`
@@ -61,6 +65,10 @@ v16main=${H5TOOL}_v16main.$suffix
v16main_o=${H5TOOL}_v16main.o
v18main=${H5TOOL}_v18main.$suffix
v18main_o=${H5TOOL}_v18main.o
+v110main=${H5TOOL}_v110main.$suffix
+v110main_o=${H5TOOL}_v110main.o
+v112main=${H5TOOL}_v112main.$suffix
+v112main_o=${H5TOOL}_v112main.o
appmain=${H5TOOL}_appmain.$suffix
appmain_o=${H5TOOL}_appmain.o
prog1=${H5TOOL}_prog1.$suffix
@@ -72,9 +80,9 @@ applib=libapp${H5TOOL}.a
# short hands
# Caution: if some *.h5 files must be cleaned here, list them by names.
# Don't use the wildcard form of *.h5 as it will wipe out even *.h5 generated
-# by otehr test programs. This will cause a racing condition error when
+# by other test programs. This will cause a racing condition error when
# parallel make (e.g., gmake -j 4) is used.
-temp_SRC="$hdf5main $v16main $v18main $appmain $prog1 $prog2"
+temp_SRC="$hdf5main $v16main $v18main $v110main $v112main $appmain $prog1 $prog2"
temp_OBJ=`echo $temp_SRC | sed -e "s/\.${suffix}/.o/g"`
temp_FILES="a.out $applib"
@@ -83,6 +91,8 @@ temp_FILES="a.out $applib"
cat > $appmain <<EOF
#include "hdf5.h"
#define H5FILE_NAME "tmp.h5"
+extern void sub1(void);
+extern void sub2(void);
int
main (void)
{
@@ -100,13 +110,15 @@ main (void)
printf("HDF5 C Sample program ran successfully. File %s generated.\n", H5FILE_NAME);
remove(H5FILE_NAME);
-
+
return 0;
-}
+}
EOF
# generate prog1
cat > $prog1 <<EOF
+#include <stdio.h>
+void
sub1(void)
{
printf("in sub1\n");
@@ -115,6 +127,8 @@ EOF
# generate prog2
cat > $prog2 <<EOF
+#include <stdio.h>
+void
sub2(void)
{
printf("in sub2\n");
@@ -143,7 +157,7 @@ main (void)
remove(H5FILE_NAME);
return 0;
-}
+}
EOF
# Generate HDF5 v1.6 Main Program:
@@ -196,6 +210,82 @@ main (void)
}
EOF
+# Generate HDF5 v1.10 Main Program:
+# This makes unique V1.10 API calls.
+cat > $v110main <<EOF
+/* This is a V1.10 API calls example Program. */
+#include "hdf5.h"
+#define H5FILE_NAME "tmp.h5"
+int
+main (void)
+{
+ hid_t file, group, group2, dset, dset2; /* file and group handles */
+
+ file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
+ group = H5Gcreate(file, "/Group", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ group2 = H5Gcreate2(file, "/Group1.8", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
+ dset = H5Dopen(group, "Dataset", H5P_DEFAULT);
+ dset2 = H5Dopen2(group2, "Dataset2", H5P_DEFAULT);
+ H5Dclose(dset);
+ H5Dclose(dset2);
+ H5Gclose(group2);
+ H5Gclose(group);
+ H5Fclose(file);
+
+ printf("HDF5 C program created with V1.10 API ran successfully. "
+ "File %s generated.\n", H5FILE_NAME);
+ remove(H5FILE_NAME);
+ return 0;
+}
+EOF
+
+# Generate HDF5 v1.12 Main Program:
+# This makes unique V1.12 API calls.
+cat > $v112main <<EOF
+/* This is a V1.12 API calls example Program. */
+#include "hdf5.h"
+#define H5FILE_NAME "tmp.h5"
+#define SPACE1_RANK 3
+int
+main (void)
+{
+ hid_t sid; /* Dataspace ID */
+ hid_t fapl = -1; /* File access property list ID */
+ int rank; /* Logical rank of dataspace */
+ hsize_t dims[] = {3, 3, 15};
+ size_t sbuf_size=0;
+ herr_t ret; /* Generic return value */
+ hsize_t start[] = {0, 0, 0};
+ hsize_t stride[] = {2, 5, 3};
+ hsize_t count[] = {2, 2, 2};
+ hsize_t block[] = {1, 3, 1};
+
+ /* Create the file access property list */
+ fapl = H5Pcreate(H5P_FILE_ACCESS);
+
+ /* Set low/high bounds in the fapl */
+ ret = H5Pset_libver_bounds(fapl, H5F_LIBVER_EARLIEST,
+ H5F_LIBVER_LATEST);
+
+ /* Create the dataspace */
+ sid = H5Screate_simple(SPACE1_RANK, dims, NULL);
+
+ /* Set the hyperslab selection */
+ ret = H5Sselect_hyperslab(sid, H5S_SELECT_SET, start, stride, count, block);
+
+ /* Encode simple dataspace in a buffer with the fapl setting */
+ ret = H5Sencode(sid, NULL, &sbuf_size, fapl);
+
+ /* Encode simple dataspace in a buffer with the fapl setting */
+ ret = H5Sencode2(sid, NULL, &sbuf_size, fapl);
+
+ printf("HDF5 C program created with V1.12 API ran successfully. ");
+/* "File %s generated.\n", H5FILE_NAME);
+ remove(H5FILE_NAME); */
+ return 0;
+}
+EOF
+
# Parse option
# None
@@ -304,17 +394,30 @@ TOOLTEST -E $appmain $prog1 $prog2
# Group5: Version compatibility tests.
echo "***"Version compatibility tests.
-# Test these two cases now. More later.
+# 20200610 Updated for versions 1.10 - 1.14.
# If H5_NO_DEPRECATED_SYMBOLS;
-# then only v18main works.
+# then versions v18main, v110main, and v112main work.
+# -DH5_USE_<N>_API_DEFAULT flags cannot be used with H5_NO_DEPRECATED_SYMBOLS;
# else if H5_USE_16_API_DEFAULT;
-# then v16main works and -DH5_NO_DEPRECATED_SYMBOLS v18main also works.
-# else v18main works and -DH5_USE_16_API_DEFAULT v16main also works.
+# then v16main works.
+# else v18main works and -DH5_USE_16_API_DEFAULT v16main also works.
+# as new versions with versioned functions are added, they will work with and
+# should be added to H5_NO_DEPRECATED_SYMBOLS and to the else section, with and
+# without the -DH5_USE_<N>_API_DEFAULT flag. A new H5_USE_<N>_API_DEFAULT section
+# should also be added.
#
if [ -n "$H5_USE_16_API_DEFAULT" ]; then
echo "H5_USE_16_API_DEFAULT is defined."
+elif [ -n "$H5_USE_18_API_DEFAULT" ]; then
+ echo "H5_USE_18_API_DEFAULT is defined."
+elif [ -n "$H5_USE_110_API_DEFAULT" ]; then
+ echo "H5_USE_110_API_DEFAULT is defined."
+elif [ -n "$H5_USE_112_API_DEFAULT" ]; then
+ echo "H5_USE_112_API_DEFAULT is defined."
+elif [ -n "$H5_USE_114_API_DEFAULT" ]; then
+ echo "H5_USE_114_API_DEFAULT is defined."
else
- echo "H5_USE_16_API_DEFAULT is not defined."
+ echo "No H5 API_DEFAULT is defined."
fi
if [ -n "$H5_NO_DEPRECATED_SYMBOLS" ]; then
echo "H5_NO_DEPRECATED_SYMBOLS is defined."
@@ -324,12 +427,36 @@ fi
if [ -n "$H5_NO_DEPRECATED_SYMBOLS" ]; then
echo "Skipping $v16main test"
TOOLTEST $v18main
+ TOOLTEST $v18main
+ TOOLTEST $v110main
+ TOOLTEST $v112main
elif [ -n "$H5_USE_16_API_DEFAULT" ]; then
+ echo "Testing HDF5 with 16_API_DEFAULT"
TOOLTEST $v16main
- TOOLTEST -DH5_NO_DEPRECATED_SYMBOLS $v18main
+elif [ -n "$H5_USE_18_API_DEFAULT" ]; then
+ echo "Testing HDF5 with 18_API_DEFAULT"
+ TOOLTEST -DH5_USE_16_API_DEFAULT $v16main
+ TOOLTEST $v18main
+elif [ -n "$H5_USE_110_API_DEFAULT" ]; then
+ echo "Testing HDF5 with 110_API_DEFAULT"
+ TOOLTEST -DH5_USE_16_API_DEFAULT $v16main
+ TOOLTEST -DH5_USE_18_API_DEFAULT $v18main
+ TOOLTEST $v110main
+elif [ -n "$H5_USE_112_API_DEFAULT" ]; then
+ echo "Testing HDF5 with 112_API_DEFAULT"
+ TOOLTEST -DH5_USE_16_API_DEFAULT $v16main
+ TOOLTEST -DH5_USE_18_API_DEFAULT $v18main
+ TOOLTEST -DH5_USE_110_API_DEFAULT $v110main
+ TOOLTEST $v112main
else
+ echo "Testing HDF5 with 114_API_DEFAULT"
TOOLTEST -DH5_USE_16_API_DEFAULT $v16main
+ TOOLTEST -DH5_USE_18_API_DEFAULT $v18main
+ TOOLTEST -DH5_USE_110_API_DEFAULT $v110main
+ TOOLTEST -DH5_USE_112_API_DEFAULT $v112main
TOOLTEST $v18main
+ TOOLTEST $v110main
+ TOOLTEST $v112main
fi
##############################################################################