diff options
Diffstat (limited to 'examples')
-rw-r--r-- | examples/CMakeLists.txt | 42 | ||||
-rw-r--r-- | examples/CMakeTests.cmake | 289 | ||||
-rw-r--r-- | examples/Makefile.am | 34 | ||||
-rw-r--r-- | examples/h5_extend_write.c | 6 | ||||
-rw-r--r-- | examples/h5_extlink.c | 4 | ||||
-rw-r--r-- | examples/h5_ref2reg_deprec.c (renamed from examples/h5_ref2reg.c) | 0 | ||||
-rw-r--r-- | examples/h5_ref_compat.c | 90 | ||||
-rw-r--r-- | examples/h5_ref_extern.c | 94 | ||||
-rw-r--r-- | examples/h5_reference_deprec.c (renamed from examples/h5_reference.c) | 0 | ||||
-rw-r--r-- | examples/run-c-ex.sh.in | 12 |
10 files changed, 328 insertions, 243 deletions
diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 2239d64..9f42f95 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -23,9 +23,11 @@ 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 @@ -41,32 +43,28 @@ set (examples 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_C_PROPERTIES (${example} STATIC) - target_link_libraries (${example} PRIVATE ${HDF5_LIB_TARGET}) - set_target_properties (${example} PROPERTIES FOLDER examples) - if (BUILD_SHARED_LIBS) - add_executable (${example}-shared ${HDF5_EXAMPLES_SOURCE_DIR}/${example}.c) - target_include_directories(${example}-shared PRIVATE "${HDF5_SRC_DIR};${HDF5_BINARY_DIR};$<$<BOOL:${HDF5_ENABLE_PARALLEL}>:${MPI_C_INCLUDE_DIRS}>") - TARGET_C_PROPERTIES (${example}-shared SHARED) - target_link_libraries (${example}-shared PRIVATE ${HDF5_LIBSH_TARGET}) - set_target_properties (${example}-shared PROPERTIES FOLDER examples) + target_include_directories (${example} PRIVATE "${HDF5_SRC_DIR};${HDF5_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}) + else () + TARGET_C_PROPERTIES (${example} SHARED) + target_link_libraries (${example} PRIVATE ${HDF5_LIBSH_TARGET}) endif () + set_target_properties (${example} PROPERTIES FOLDER examples) 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}>") - TARGET_C_PROPERTIES (ph5example STATIC) - target_link_libraries (ph5example PRIVATE ${HDF5_LIB_TARGET} ${MPI_C_LIBRARIES}) - set_target_properties (ph5example PROPERTIES FOLDER examples) - if (BUILD_SHARED_LIBS) - add_executable (ph5example-shared ${HDF5_EXAMPLES_SOURCE_DIR}/ph5example.c) - target_include_directories(ph5example-shared PRIVATE "${HDF5_SRC_DIR};${HDF5_BINARY_DIR};$<$<BOOL:${HDF5_ENABLE_PARALLEL}>:${MPI_C_INCLUDE_DIRS}>") - TARGET_C_PROPERTIES (ph5example-shared SHARED) - target_link_libraries (ph5example-shared PRIVATE ${HDF5_LIBSH_TARGET} ${MPI_C_LIBRARIES}) - set_target_properties (ph5example-shared PROPERTIES FOLDER examples) + 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) endif () if (BUILD_TESTING) diff --git a/examples/CMakeTests.cmake b/examples/CMakeTests.cmake index dd4766a..ea3b2c5 100644 --- a/examples/CMakeTests.cmake +++ b/examples/CMakeTests.cmake @@ -15,208 +15,103 @@ ### T E S T I N G ### ############################################################################## ############################################################################## - file (MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/red ${PROJECT_BINARY_DIR}/blue ${PROJECT_BINARY_DIR}/u2w) - if (BUILD_SHARED_LIBS) - file (MAKE_DIRECTORY "${PROJECT_BINARY_DIR}/H5EX-shared") - file (MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/H5EX-shared/red ${PROJECT_BINARY_DIR}/H5EX-shared/blue ${PROJECT_BINARY_DIR}/H5EX-shared/u2w) - endif () +file (MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/red ${PROJECT_BINARY_DIR}/blue ${PROJECT_BINARY_DIR}/u2w) - # Remove any output file left over from previous test run - add_test ( - NAME EXAMPLES-clear-objects - COMMAND ${CMAKE_COMMAND} - -E remove - Attributes.h5 - btrees_file.h5 - cmprss.h5 - default_file.h5 - dset.h5 - extend.h5 - extlink_prefix_source.h5 - extlink_source.h5 - extlink_target.h5 - group.h5 - groups.h5 - hard_link.h5 - mount1.h5 - mount2.h5 - one_index_file.h5 - only_dspaces_and_attrs_file.h5 - only_huge_mesgs_file.h5 - REF_REG.h5 - refere.h5 - SDS.h5 - SDScompound.h5 - SDSextendible.h5 - Select.h5 - separate_indexes_file.h5 - small_lists_file.h5 - soft_link.h5 - subset.h5 - unix2win.h5 - blue/prefix_target.h5 - red/prefix_target.h5 - u2w/u2w_target.h5 - vds.h5 - vds-exc.h5 - vds-excalibur.h5 - vds-exclim.h5 - vds-percival.h5 - vds-percival-unlim.h5 - vds-percival-unlim-maxmin.h5 - a.h5 - b.h5 - c.h5 - d.h5 - vds-simpleIO.h5 - vds-eiger.h5 - ) - if (NOT "${last_test}" STREQUAL "") - set_tests_properties (EXAMPLES-clear-objects PROPERTIES DEPENDS ${last_test}) - endif () - set (last_test "EXAMPLES-clear-objects") +set (test_ex_CLEANFILES + Attributes.h5 + btrees_file.h5 + cmprss.h5 + default_file.h5 + dset.h5 + extend.h5 + extlink_prefix_source.h5 + extlink_source.h5 + extlink_target.h5 + group.h5 + groups.h5 + hard_link.h5 + mount1.h5 + mount2.h5 + one_index_file.h5 + only_dspaces_and_attrs_file.h5 + only_huge_mesgs_file.h5 + REF_REG.h5 + refere.h5 + SDS.h5 + SDScompound.h5 + SDSextendible.h5 + Select.h5 + separate_indexes_file.h5 + small_lists_file.h5 + soft_link.h5 + subset.h5 + unix2win.h5 + blue/prefix_target.h5 + red/prefix_target.h5 + u2w/u2w_target.h5 + vds.h5 + vds-exc.h5 + vds-excalibur.h5 + vds-exclim.h5 + vds-percival.h5 + vds-percival-unlim.h5 + vds-percival-unlim-maxmin.h5 + a.h5 + b.h5 + c.h5 + d.h5 + vds-simpleIO.h5 + vds-eiger.h5 +) - foreach (example ${examples}) - if (HDF5_ENABLE_USING_MEMCHECKER) - add_test (NAME EXAMPLES-${example} COMMAND $<TARGET_FILE:${example}>) - else () - add_test (NAME EXAMPLES-${example} COMMAND "${CMAKE_COMMAND}" - -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 () - if (NOT "${last_test}" STREQUAL "") - set_tests_properties (EXAMPLES-${example} PROPERTIES DEPENDS ${last_test}) - endif () - set (last_test "EXAMPLES-${example}") - endforeach () +# 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 (BUILD_SHARED_LIBS) - # Remove any output file left over from previous test run - add_test ( - NAME EXAMPLES-shared-clear-objects - COMMAND ${CMAKE_COMMAND} - -E remove - Attributes.h5 - btrees_file.h5 - cmprss.h5 - default_file.h5 - dset.h5 - extend.h5 - extlink_prefix_source.h5 - extlink_source.h5 - extlink_target.h5 - group.h5 - groups.h5 - hard_link.h5 - mount1.h5 - mount2.h5 - one_index_file.h5 - only_dspaces_and_attrs_file.h5 - only_huge_mesgs_file.h5 - REF_REG.h5 - refere.h5 - SDS.h5 - SDScompound.h5 - SDSextendible.h5 - Select.h5 - separate_indexes_file.h5 - small_lists_file.h5 - soft_link.h5 - subset.h5 - unix2win.h5 - vds.h5 - vds-exc.h5 - vds-excalibur.h5 - vds-exclim.h5 - vds-percival.h5 - vds-percival-unlim.h5 - vds-percival-unlim-maxmin.h5 - a.h5 - b.h5 - c.h5 - d.h5 - vds-simpleIO.h5 - vds-eiger.h5 - blue/prefix_target.h5 - red/prefix_target.h5 - u2w/u2w_target.h5 - WORKING_DIRECTORY - ${PROJECT_BINARY_DIR}/H5EX-shared +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" ) - if (NOT "${last_test}" STREQUAL "") - set_tests_properties (EXAMPLES-shared-clear-objects PROPERTIES DEPENDS ${last_test}) - endif () - set (last_test "EXAMPLES-shared-clear-objects") - - foreach (example ${examples}) - if (HDF5_ENABLE_USING_MEMCHECKER) - add_test (NAME EXAMPLES-shared-${example} COMMAND $<TARGET_FILE:${example}-shared>) - else () - add_test (NAME EXAMPLES-shared-${example} COMMAND "${CMAKE_COMMAND}" - -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}/H5EX-shared" - -P "${HDF_RESOURCES_EXT_DIR}/runTest.cmake" - ) - endif () - set_tests_properties (EXAMPLES-shared-${example} PROPERTIES WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/H5EX-shared) - if (NOT "${last_test}" STREQUAL "") - set_tests_properties (EXAMPLES-shared-${example} PROPERTIES DEPENDS ${last_test}) - endif () - set (last_test "EXAMPLES-shared-${example}") - endforeach () 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 () ### 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 EXAMPLES-ph5example COMMAND $<TARGET_FILE:ph5example>) - else () - add_test (NAME EXAMPLES-ph5example COMMAND "${CMAKE_COMMAND}" - -D "TEST_PROGRAM=$<TARGET_FILE:ph5example>" - -D "TEST_ARGS:STRING=" - -D "TEST_EXPECT=0" - -D "TEST_SKIP_COMPARE=TRUE" - -D "TEST_OUTPUT=ph5example.txt" - #-D "TEST_REFERENCE=ph5example.out" - -D "TEST_FOLDER=${PROJECT_BINARY_DIR}" - -P "${HDF_RESOURCES_EXT_DIR}/runTest.cmake" - ) - endif () - if (NOT "${last_test}" STREQUAL "") - set_tests_properties (EXAMPLES-ph5example PROPERTIES DEPENDS ${last_test}) - endif () - set (last_test "EXAMPLES-ph5example") - if (BUILD_SHARED_LIBS) - if (HDF5_ENABLE_USING_MEMCHECKER) - add_test (NAME EXAMPLES-shared-ph5example COMMAND $<TARGET_FILE:ph5example-shared>) - else () - add_test (NAME EXAMPLES-shared-ph5example COMMAND "${CMAKE_COMMAND}" - -D "TEST_PROGRAM=$<TARGET_FILE:ph5example-shared>" - -D "TEST_ARGS:STRING=" - -D "TEST_EXPECT=0" - -D "TEST_SKIP_COMPARE=TRUE" - -D "TEST_OUTPUT=ph5example-shared.txt" - #-D "TEST_REFERENCE=ph5example-shared.out" - -D "TEST_FOLDER=${PROJECT_BINARY_DIR}/H5EX-shared" - -P "${HDF_RESOURCES_EXT_DIR}/runTest.cmake" - ) - endif () - set_tests_properties (EXAMPLES-shared-ph5example PROPERTIES WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/H5EX-shared) - if (NOT "${last_test}" STREQUAL "") - set_tests_properties (EXAMPLES-shared-ph5example PROPERTIES DEPENDS ${last_test}) - endif () - set (last_test "EXAMPLES-shared-ph5example") - endif () +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") +endif () diff --git a/examples/Makefile.am b/examples/Makefile.am index c07b52b..5b428cd 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -32,25 +32,27 @@ INSTALL_TOP_FILES = README # it would try to compile them instead of using the h5cc script. # Use the boilerplate in config/examples.am instead. 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 + 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_deprec h5_drivers \ + h5_ref_extern h5_ref_compat \ + h5_ref2reg_deprec 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 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 + 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_deprec.c h5_drivers.c h5_extlink.c h5_elink_unix2win.c \ + h5_ref_extern.c h5_ref_compat.c \ + h5_ref2reg_deprec.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 @@ -111,8 +113,10 @@ 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 h5_dtransform: $(srcdir)/h5_dtransform.c diff --git a/examples/h5_extend_write.c b/examples/h5_extend_write.c index f3f6077..4abda30 100644 --- a/examples/h5_extend_write.c +++ b/examples/h5_extend_write.c @@ -163,9 +163,9 @@ main (void) /* * Resulting dataset * - * 1 1 1 3 3 - * 1 1 1 3 3 - * 1 1 1 0 0 + * 1 1 1 3 3 + * 1 1 1 3 3 + * 1 1 1 0 0 * 2 0 0 0 0 * 2 0 0 0 0 * 2 0 0 0 0 diff --git a/examples/h5_extlink.c b/examples/h5_extlink.c index 1a07656..229e465 100644 --- a/examples/h5_extlink.c +++ b/examples/h5_extlink.c @@ -208,7 +208,7 @@ static void extlink_prefix_example(void) * 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); + const void *udata, size_t udata_size, hid_t lapl_id, hid_t dxpl_id); static void soft_link_example(void) { @@ -277,7 +277,7 @@ static void soft_link_example(void) */ 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) + 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; diff --git a/examples/h5_ref2reg.c b/examples/h5_ref2reg_deprec.c index dc2964c..dc2964c 100644 --- a/examples/h5_ref2reg.c +++ b/examples/h5_ref2reg_deprec.c diff --git a/examples/h5_ref_compat.c b/examples/h5_ref_compat.c new file mode 100644 index 0000000..a1fbf96 --- /dev/null +++ b/examples/h5_ref_compat.c @@ -0,0 +1,90 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * 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://support.hdfgroup.org/ftp/HDF5/releases. * + * 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((const H5R_ref_t *)&new_ref_buf[0], H5P_DEFAULT, &obj_type); + assert(obj_type == H5O_TYPE_DATASET); + dset1 = H5Ropen_object((const H5R_ref_t *)&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..4327a06 --- /dev/null +++ b/examples/h5_ref_extern.c @@ -0,0 +1,94 @@ +/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * 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://support.hdfgroup.org/ftp/HDF5/releases. * + * 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", &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((const H5R_ref_t *)&ref_buf[0], H5P_DEFAULT, &obj_type); + assert(obj_type == H5O_TYPE_DATASET); + dset1 = H5Ropen_object((const H5R_ref_t *)&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_deprec.c index 32a5f59..32a5f59 100644 --- a/examples/h5_reference.c +++ b/examples/h5_reference_deprec.c diff --git a/examples/run-c-ex.sh.in b/examples/run-c-ex.sh.in index ffb01bc..3648706 100644 --- a/examples/run-c-ex.sh.in +++ b/examples/run-c-ex.sh.in @@ -112,12 +112,16 @@ 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 &&\ |