mirror of
https://github.com/HDFGroup/hdf5.git
synced 2026-09-25 04:09:44 +03:00
Move C++ and Fortran and examples to HDF5Examples folder (#4552)
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
cmake_minimum_required (VERSION 3.12)
|
||||
cmake_minimum_required (VERSION 3.18)
|
||||
project (HDF5Examples_C C)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Build the C Examples
|
||||
#-----------------------------------------------------------------------------
|
||||
add_subdirectory (${PROJECT_SOURCE_DIR}/TUTR)
|
||||
add_subdirectory (${PROJECT_SOURCE_DIR}/H5D)
|
||||
add_subdirectory (${PROJECT_SOURCE_DIR}/H5G)
|
||||
add_subdirectory (${PROJECT_SOURCE_DIR}/H5T)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required (VERSION 3.12)
|
||||
cmake_minimum_required (VERSION 3.18)
|
||||
project (HDF5Examples_C_H5D C)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required (VERSION 3.12)
|
||||
cmake_minimum_required (VERSION 3.18)
|
||||
project (HDF5Examples_C_H5FLT C)
|
||||
|
||||
set (dyn_examples)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required (VERSION 3.12)
|
||||
cmake_minimum_required (VERSION 3.18)
|
||||
project (HDF5Examples_C_H5G C)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required (VERSION 3.12)
|
||||
cmake_minimum_required (VERSION 3.18)
|
||||
project (H5PAR_C C)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required (VERSION 3.12)
|
||||
cmake_minimum_required (VERSION 3.18)
|
||||
project (HDF5Examples_C_H5T C)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required (VERSION 3.12)
|
||||
cmake_minimum_required (VERSION 3.18)
|
||||
project (HDF5Examples_C_H5VDS C)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required (VERSION 3.12)
|
||||
cmake_minimum_required (VERSION 3.18)
|
||||
project (HDF5Examples_C_PERFORM C)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
Attribute Examples:
|
||||
|
||||
H5Acreate2 example: Show how to create an attribute for a dataset and a group
|
||||
----------------
|
||||
{
|
||||
hid_t file;
|
||||
hid_t group;
|
||||
hid_t dataset;
|
||||
hid_t attr;
|
||||
hid_t dataspace;
|
||||
int32 attr_data;
|
||||
int rank;
|
||||
size_t dimsf[2];
|
||||
|
||||
/* Open the file */
|
||||
file=H5Fopen("example.h5", H5F_ACC_RDWR, H5P_DEFAULT);
|
||||
|
||||
/* Describe the size of the array and create the data space */
|
||||
rank=2;
|
||||
dimsf[0] = H5S_UNLIMITED;
|
||||
dimsf[1] = H5S_UNLIMITED;
|
||||
dataspace = H5Screate_simple(rank, dimsf, NULL);
|
||||
|
||||
/* Create a dataset */
|
||||
dataset = H5Dcreate2(file, "Dataset1", H5T_UINT8, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
||||
|
||||
<Write data to first dataset>
|
||||
|
||||
/* Create an attribute for the dataset */
|
||||
attr = H5Acreate2(dataset, "Attr1", H5T_INT32, H5S_SCALAR, H5P_DEFAULT, H5P_DEFAULT);
|
||||
|
||||
/* Write attribute information */
|
||||
H5Awrite(attr, H5T_INT32, &attr_data);
|
||||
|
||||
/* Close attribute */
|
||||
H5Aclose(attr);
|
||||
|
||||
/* Close dataset */
|
||||
H5Dclose(dataset);
|
||||
|
||||
/* Create a group */
|
||||
group = H5Gcreate2(file, "/Group One", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
||||
|
||||
/* Create an attribute for the dataset */
|
||||
attr = H5Acreate2(group, "Attr1", H5T_INT32, H5S_SCALAR, H5P_DEFAULT, H5P_DEFAULT);
|
||||
|
||||
/* Write attribute information */
|
||||
H5Awrite(attr, H5T_INT32, &attr_data);
|
||||
|
||||
/* Close attribute */
|
||||
H5Aclose(attr);
|
||||
|
||||
/* Close the group */
|
||||
H5Gclose(group);
|
||||
|
||||
/* Close file */
|
||||
H5Fclose(file);
|
||||
}
|
||||
|
||||
|
||||
H5Aiterate example: Print all the names of attributes of a dataset, without
|
||||
any buffers.
|
||||
---------------------
|
||||
|
||||
herr_t print_names (hid_t loc_id, const char *name, void *opdata)
|
||||
{
|
||||
puts (name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
{
|
||||
H5Aiterate (dataset_or_group_id, NULL, print_names, NULL);
|
||||
}
|
||||
|
||||
|
||||
H5Aread Example: Attach to an attribute of a dataset and read in attr. data
|
||||
----------------
|
||||
{
|
||||
hid_t file;
|
||||
hid_t dataset;
|
||||
hid_t attr;
|
||||
int32 attr_data;
|
||||
|
||||
/* Open the file */
|
||||
file=H5Fopen("example.h5", H5F_ACC_RDWR, H5P_DEFAULT);
|
||||
|
||||
/* Open the dataset */
|
||||
dataset=H5Dopen2(file, "Dataset1", H5P_DEFAULT);
|
||||
|
||||
/* Get the OID of the attribute */
|
||||
attr=H5Aopen(dataset, "Attr1", H5P_DEFAULT);
|
||||
|
||||
/* Read attribute */
|
||||
H5Aread(attr,H5T_INT32,attr_data);
|
||||
|
||||
/* Close attribute dataset */
|
||||
H5Aclose(attr);
|
||||
|
||||
/* Close first dataset */
|
||||
H5Dclose(dataset);
|
||||
|
||||
/* Close file */
|
||||
H5Fclose(file);
|
||||
}
|
||||
|
||||
H5Alink Example: Shows how to share an attribute between two datasets.
|
||||
----------------
|
||||
{
|
||||
hid_t file;
|
||||
hid_t dataset1, dataset2;
|
||||
hid_t attr;
|
||||
|
||||
/* Open the file */
|
||||
file=H5Fopen("example.h5", H5F_ACC_RDWR, H5P_DEFAULT);
|
||||
|
||||
/* Open the first dataset */
|
||||
dataset1=H5Dopen2(file, "Dataset1", H5P_DEFAULT);
|
||||
|
||||
/* Open the first dataset */
|
||||
dataset2=H5Dopen2(file, "Dataset2", H5P_DEFAULT);
|
||||
|
||||
/* 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.
|
||||
*/
|
||||
H5Alink(dataset2, attr, "Bar");
|
||||
|
||||
/* Close attribute dataset */
|
||||
H5Aclose(attr);
|
||||
|
||||
/* Close datasets */
|
||||
H5Dclose(dataset1);
|
||||
H5Dclose(dataset2);
|
||||
|
||||
/* Close file */
|
||||
H5Fclose(file);
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
cmake_minimum_required (VERSION 3.18)
|
||||
project (HDF5Examples_C_TUTR C)
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
# Define Sources
|
||||
#-----------------------------------------------------------------------------
|
||||
include (C_sourcefiles.cmake)
|
||||
|
||||
foreach (example_name ${examples})
|
||||
add_executable (${EXAMPLE_VARNAME}_tutr_${example_name} ${PROJECT_SOURCE_DIR}/${example_name}.c)
|
||||
target_compile_options(${EXAMPLE_VARNAME}_tutr_${example_name}
|
||||
PRIVATE
|
||||
"$<$<BOOL:${${EXAMPLE_VARNAME}_USE_16_API}>:-DH5_USE_16_API>"
|
||||
"$<$<BOOL:${${EXAMPLE_VARNAME}_USE_18_API}>:-DH5_USE_18_API>"
|
||||
"$<$<BOOL:${${EXAMPLE_VARNAME}_USE_110_API}>:-DH5_USE_110_API>"
|
||||
"$<$<BOOL:${${EXAMPLE_VARNAME}_USE_112_API}>:-DH5_USE_112_API>"
|
||||
"$<$<BOOL:${${EXAMPLE_VARNAME}_USE_114_API}>:-DH5_USE_114_API>"
|
||||
"$<$<BOOL:${${EXAMPLE_VARNAME}_USE_116_API}>:-DH5_USE_116_API>"
|
||||
)
|
||||
if (H5_HAVE_PARALLEL)
|
||||
target_include_directories (${EXAMPLE_VARNAME}_tutr_${example_name} PUBLIC ${MPI_C_INCLUDE_DIRS})
|
||||
endif ()
|
||||
target_link_libraries (${EXAMPLE_VARNAME}_tutr_${example_name} ${H5EX_HDF5_LINK_LIBS})
|
||||
endforeach ()
|
||||
|
||||
|
||||
if (H5EX_BUILD_TESTING)
|
||||
file (MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/red ${PROJECT_BINARY_DIR}/blue ${PROJECT_BINARY_DIR}/u2w)
|
||||
|
||||
set (${EXAMPLE_VARNAME}_tutr_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
|
||||
refer_deprec.h5
|
||||
refer_extern1.h5
|
||||
refer_extern2.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
|
||||
)
|
||||
|
||||
# Remove any output file left over from previous test run
|
||||
add_test (
|
||||
NAME ${EXAMPLE_VARNAME}_tutr-clear-objects
|
||||
COMMAND ${CMAKE_COMMAND} -E remove ${${EXAMPLE_VARNAME}_tutr_CLEANFILES}
|
||||
)
|
||||
set_tests_properties (${EXAMPLE_VARNAME}_tutr-clear-objects PROPERTIES
|
||||
FIXTURES_SETUP clear_${EXAMPLE_VARNAME}_tutr
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||
)
|
||||
add_test (
|
||||
NAME ${EXAMPLE_VARNAME}_tutr-clean-objects
|
||||
COMMAND ${CMAKE_COMMAND} -E remove ${${EXAMPLE_VARNAME}_tutr_CLEANFILES}
|
||||
)
|
||||
set_tests_properties (${EXAMPLE_VARNAME}_tutr-clean-objects PROPERTIES
|
||||
FIXTURES_CLEANUP clear_${EXAMPLE_VARNAME}_tutr
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||
)
|
||||
|
||||
macro (ADD_H5_TEST testname)
|
||||
if (HDF5_USING_ANALYSIS_TOOL)
|
||||
add_test (NAME ${EXAMPLE_VARNAME}_tutr_${testname} COMMAND ${CMAKE_CROSSCOMPILING_EMULATOR} $<TARGET_FILE:${EXAMPLE_VARNAME}_tutr_${testname}>)
|
||||
else ()
|
||||
add_test (
|
||||
NAME ${EXAMPLE_VARNAME}_tutr_${testname}
|
||||
COMMAND "${CMAKE_COMMAND}"
|
||||
-D "TEST_EMULATOR=${CMAKE_CROSSCOMPILING_EMULATOR}"
|
||||
-D "TEST_PROGRAM=$<TARGET_FILE:${EXAMPLE_VARNAME}_tutr_${testname}>"
|
||||
-D "TEST_ARGS:STRING="
|
||||
-D "TEST_FOLDER=${PROJECT_BINARY_DIR}"
|
||||
-D "TEST_EXPECT=0"
|
||||
-D "TEST_SKIP_COMPARE=TRUE"
|
||||
-D "TEST_OUTPUT=${testname}.out"
|
||||
-D "TEST_LIBRARY_DIRECTORY=${CMAKE_TEST_LIB_DIRECTORY}"
|
||||
-P "${H5EX_RESOURCES_DIR}/runTest.cmake"
|
||||
)
|
||||
endif ()
|
||||
set_tests_properties (${EXAMPLE_VARNAME}_tutr_${testname} PROPERTIES FIXTURES_REQUIRED clear_${EXAMPLE_VARNAME}_tutr)
|
||||
if (last_test)
|
||||
set_tests_properties (${EXAMPLE_VARNAME}_tutr_${testname} PROPERTIES DEPENDS ${last_test})
|
||||
endif ()
|
||||
set (last_test "${EXAMPLE_VARNAME}_tutr_${testname}")
|
||||
endmacro ()
|
||||
|
||||
foreach (example_name ${examples})
|
||||
ADD_H5_TEST (${example_name})
|
||||
endforeach ()
|
||||
endif ()
|
||||
@@ -0,0 +1,97 @@
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
##############################################################################
|
||||
### T E S T I N G ###
|
||||
##############################################################################
|
||||
##############################################################################
|
||||
file (MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/red ${PROJECT_BINARY_DIR}/blue ${PROJECT_BINARY_DIR}/u2w)
|
||||
|
||||
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
|
||||
refer_deprec.h5
|
||||
refer_extern1.h5
|
||||
refer_extern2.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
|
||||
)
|
||||
|
||||
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
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||
)
|
||||
add_test (
|
||||
NAME EXAMPLES-clean-objects
|
||||
COMMAND ${CMAKE_COMMAND} -E remove ${test_ex_CLEANFILES}
|
||||
)
|
||||
set_tests_properties (EXAMPLES-clean-objects PROPERTIES
|
||||
FIXTURES_CLEANUP clear_EXAMPLES
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||
)
|
||||
|
||||
foreach (example ${examples})
|
||||
if (HDF5_USING_ANALYSIS_TOOL)
|
||||
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_FOLDER=${PROJECT_BINARY_DIR}"
|
||||
-P "${HDF_RESOURCES_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 ()
|
||||
@@ -0,0 +1,32 @@
|
||||
#-----------------------------------------------------------------------------
|
||||
# Define Sources, one file per application
|
||||
#-----------------------------------------------------------------------------
|
||||
set (examples
|
||||
h5_crtdat
|
||||
h5_rdwt
|
||||
h5_crtatt
|
||||
h5_crtgrp
|
||||
h5_crtgrpar
|
||||
h5_crtgrpd
|
||||
h5_cmprss
|
||||
h5_extend
|
||||
h5_subset
|
||||
h5_write
|
||||
h5_read
|
||||
h5_extend_write
|
||||
h5_chunk_read
|
||||
h5_compound
|
||||
h5_group
|
||||
h5_select
|
||||
h5_attribute
|
||||
h5_mount
|
||||
h5_ref_extern
|
||||
h5_ref_compat
|
||||
h5_reference_deprec
|
||||
h5_drivers
|
||||
h5_ref2reg_deprec
|
||||
h5_extlink
|
||||
h5_elink_unix2win
|
||||
h5_shared_mesg
|
||||
h5_debug_trace
|
||||
)
|
||||
@@ -0,0 +1,119 @@
|
||||
#
|
||||
# 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.
|
||||
##
|
||||
## Makefile.am
|
||||
## Run automake to generate a Makefile.in from this file.
|
||||
##
|
||||
#
|
||||
# HDF5 Library Examples Makefile(.in)
|
||||
#
|
||||
|
||||
include $(top_srcdir)/config/commence.am
|
||||
|
||||
INSTALL_SCRIPT_FILES = run-c-ex.sh
|
||||
INSTALL_TOP_SCRIPT_FILES = run-all-ex.sh
|
||||
INSTALL_TOP_FILES = README
|
||||
|
||||
# Example programs.
|
||||
# Don't tell automake about them, because if it knew they were programs,
|
||||
# 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_drivers \
|
||||
h5_reference_deprec h5_ref_extern h5_ref_compat h5_ref2reg_deprec \
|
||||
h5_extlink h5_elink_unix2win h5_shared_mesg h5_debug_trace
|
||||
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_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
|
||||
|
||||
# How to build examples, using installed version of h5cc
|
||||
if BUILD_PARALLEL_CONDITIONAL
|
||||
$(EXTRA_PROG): $(H5CC_PP)
|
||||
$(H5CC_PP) $(H5CCFLAGS) $(CFLAGS) -o $@ $(srcdir)/$@.c;
|
||||
else
|
||||
$(EXTRA_PROG): $(H5CC)
|
||||
$(H5CC) $(H5CCFLAGS) $(CFLAGS) -o $@ $(srcdir)/$@.c;
|
||||
endif
|
||||
|
||||
# Some examples depend on files created by other examples.
|
||||
h5_read.chkexe_: h5_write.chkexe_
|
||||
h5_chunk_read.chkexe_: h5_extend_write.chkexe_
|
||||
h5_crtgrpd.chkexe_: h5_crtgrpar.chkexe_
|
||||
# h5_rdwt and h5_crtatt both modify the same file created by
|
||||
# h5_crtdat. Serialize them.
|
||||
h5_rdwt.chkexe_: h5_crtdat.chkexe_
|
||||
h5_crtatt.chkexe_: h5_rdwt.chkexe_
|
||||
|
||||
# The external link examples demonstrate how to use paths; they need
|
||||
# directories to be created to do this.
|
||||
EXTLINK_DIRS=red blue u2w
|
||||
|
||||
$(EXTLINK_DIRS):
|
||||
echo $(mkdir_p) $@
|
||||
$(mkdir_p) $@
|
||||
|
||||
CHECK_CLEANFILES+=$(EXTLINK_DIRS)
|
||||
|
||||
# Example directory
|
||||
# Note: no '/' after DESTDIR. Explanation in commence.am
|
||||
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
|
||||
# will try to build them with the normal C compiler, not h5cc. This is
|
||||
# an inelegant way of solving the problem.
|
||||
# All programs share the same build rule and a dependency on the main hdf5
|
||||
# library above.
|
||||
h5_chunk_read: $(srcdir)/h5_chunk_read.c
|
||||
h5_compound: $(srcdir)/h5_compound.c
|
||||
h5_crtgrpd: $(srcdir)/h5_crtgrpd.c
|
||||
h5_subset: $(srcdir)/h5_subset.c
|
||||
h5_cmprss: $(srcdir)/h5_cmprss.c
|
||||
h5_rdwt: $(srcdir)/h5_rdwt.c
|
||||
h5_crtgrpar: $(srcdir)/h5_crtgrpar.c
|
||||
h5_extend: $(srcdir)/h5_extend.c
|
||||
h5_crtatt: $(srcdir)/h5_crtatt.c
|
||||
h5_crtgrp: $(srcdir)/h5_crtgrp.c
|
||||
h5_crtdat: $(srcdir)/h5_crtdat.c
|
||||
h5_extend_write: $(srcdir)/h5_extend_write.c
|
||||
h5_group: $(srcdir)/h5_group.c
|
||||
h5_write: $(srcdir)/h5_write.c
|
||||
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_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
|
||||
h5_dtransform: $(srcdir)/h5_dtransform.c
|
||||
h5_extlink: $(srcdir)/h5_extlink.c $(EXTLINK_DIRS)
|
||||
h5_elink_unix2win: $(srcdir)/h5_elink_unix2win.c $(EXTLINK_DIRS)
|
||||
h5_shared_mesg: $(srcdir)/h5_shared_mesg.c
|
||||
|
||||
if BUILD_SHARED_SZIP_CONDITIONAL
|
||||
LD_LIBRARY_PATH=$(LL_PATH)
|
||||
endif
|
||||
|
||||
include $(top_srcdir)/config/examples.am
|
||||
include $(top_srcdir)/config/conclude.am
|
||||
@@ -0,0 +1,17 @@
|
||||
HDF5 Examples
|
||||
|
||||
This directory contains example programs for the installed APIs and scripts to
|
||||
compile and run them. Examples in the c and hl/c subdirectories are always
|
||||
installed, and those in fortran, hl/fortran, c++ and hl/c++ will be installed
|
||||
when fortran or c++ are enabled.
|
||||
|
||||
Running the run-all-ex.sh script in this directory will run the scripts and in
|
||||
turn the examples in all the subdirectories where examples are installed. The
|
||||
scripts can also be run individually. The appropriate compile scripts in the
|
||||
bin directory for this install will be used by default to compile and link the
|
||||
example programs. Note that h5redeploy must be run if these binaries are
|
||||
copied or extracted in a directory other than the one where they were initially
|
||||
installed. Compile scripts from other locations can be used by setting an
|
||||
environment variable prefix to the path of the directory containing the bin
|
||||
directory with the compile scripts h5cc, h5fc, etc. For example, export
|
||||
prefix=/usr/local/hdf5 to use h5cc, h5fc, etc. in /usr/local/hdf5/bin.
|
||||
@@ -0,0 +1,293 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*
|
||||
* This program illustrates the usage of the H5A Interface functions.
|
||||
* It creates and writes a dataset, and then creates and writes array,
|
||||
* scalar, and string attributes of the dataset.
|
||||
* Program reopens the file, attaches to the scalar attribute using
|
||||
* attribute name and reads and displays its value. Then index of the
|
||||
* third attribute is used to read and display attribute values.
|
||||
* The H5Aiterate function is used to iterate through the dataset attributes,
|
||||
* and display their names. The function is also reads and displays the values
|
||||
* of the array attribute.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "hdf5.h"
|
||||
|
||||
#define H5FILE_NAME "Attributes.h5"
|
||||
|
||||
#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 ADIM1 2
|
||||
#define ADIM2 3
|
||||
#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 */
|
||||
|
||||
int
|
||||
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_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.;
|
||||
}
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Operator function.
|
||||
*/
|
||||
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;
|
||||
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. */
|
||||
|
||||
/* avoid warnings */
|
||||
(void)opdata;
|
||||
|
||||
/*
|
||||
* Open the attribute using its name.
|
||||
*/
|
||||
attr = H5Aopen(loc_id, name, H5P_DEFAULT);
|
||||
|
||||
/*
|
||||
* Display attribute name.
|
||||
*/
|
||||
printf("\nName : %s\n", name);
|
||||
|
||||
/*
|
||||
* Get attribute datatype, dataspace, rank, and dimensions.
|
||||
*/
|
||||
atype = H5Aget_type(attr);
|
||||
aspace = H5Aget_space(attr);
|
||||
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) {
|
||||
printf("Rank : %d \n", rank);
|
||||
printf("Dimension sizes : ");
|
||||
for (i = 0; i < rank; i++)
|
||||
printf("%d ", (int)sdim[i]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* Read array attribute and display its type and values.
|
||||
*/
|
||||
|
||||
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);
|
||||
printf("Values : ");
|
||||
for (i = 0; i < (int)npoints; i++)
|
||||
printf("%f ", float_array[i]);
|
||||
printf("\n");
|
||||
free(float_array);
|
||||
}
|
||||
|
||||
/*
|
||||
* Release all identifiers.
|
||||
*/
|
||||
H5Tclose(atype);
|
||||
H5Sclose(aspace);
|
||||
H5Aclose(attr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,206 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*
|
||||
* This example shows how to read data from a chunked dataset.
|
||||
* We will read from the file created by h5_extend_write.c
|
||||
*/
|
||||
|
||||
#include "hdf5.h"
|
||||
|
||||
#define H5FILE_NAME "SDSextendible.h5"
|
||||
#define DATASETNAME "ExtendibleArray"
|
||||
#define RANK 2
|
||||
#define RANKC 1
|
||||
#define NX 10
|
||||
#define NY 5
|
||||
|
||||
int
|
||||
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;
|
||||
|
||||
/*
|
||||
* Open the file and the dataset.
|
||||
*/
|
||||
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. */
|
||||
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]));
|
||||
|
||||
/*
|
||||
* Define the memory space to read dataset.
|
||||
*/
|
||||
memspace = H5Screate_simple(RANK, dims, NULL);
|
||||
|
||||
/*
|
||||
* Read dataset back and display.
|
||||
*/
|
||||
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");
|
||||
}
|
||||
|
||||
/*
|
||||
* Close/release resources.
|
||||
*/
|
||||
H5Sclose(memspace);
|
||||
|
||||
/*
|
||||
* dataset rank 2, dimensions 10 x 5
|
||||
* chunk rank 2, dimensions 2 x 5
|
||||
|
||||
* Dataset:
|
||||
* 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
|
||||
* 2 0 0 0 0
|
||||
* 2 0 0 0 0
|
||||
* 2 0 0 0 0
|
||||
* 2 0 0 0 0
|
||||
*/
|
||||
|
||||
/*
|
||||
* Read the third column from the dataset.
|
||||
* First define memory dataspace, then define hyperslab
|
||||
* and read it into column array.
|
||||
*/
|
||||
col_dims[0] = 10;
|
||||
memspace = H5Screate_simple(RANKC, col_dims, NULL);
|
||||
|
||||
/*
|
||||
* Define the column (hyperslab) to read.
|
||||
*/
|
||||
offset[0] = 0;
|
||||
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);
|
||||
printf("\n");
|
||||
printf("Third column: \n");
|
||||
for (i = 0; i < 10; i++) {
|
||||
printf("%d \n", column[i]);
|
||||
}
|
||||
|
||||
/*
|
||||
* Close/release resources.
|
||||
*/
|
||||
H5Sclose(memspace);
|
||||
|
||||
/*
|
||||
* Third column:
|
||||
* 1
|
||||
* 1
|
||||
* 1
|
||||
* 0
|
||||
* 0
|
||||
* 0
|
||||
* 0
|
||||
* 0
|
||||
* 0
|
||||
* 0
|
||||
*/
|
||||
|
||||
/*
|
||||
* Get creation properties list.
|
||||
*/
|
||||
cparms = H5Dget_create_plist(dataset); /* Get properties handle first. */
|
||||
|
||||
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]));
|
||||
|
||||
/*
|
||||
* Define the memory space to read a chunk.
|
||||
*/
|
||||
memspace = H5Screate_simple(rank_chunk, chunk_dims, NULL);
|
||||
|
||||
/*
|
||||
* Define chunk in the file (hyperslab) to read.
|
||||
*/
|
||||
offset[0] = 2;
|
||||
offset[1] = 0;
|
||||
count[0] = chunk_dims[0];
|
||||
count[1] = chunk_dims[1];
|
||||
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);
|
||||
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]);
|
||||
printf("\n");
|
||||
}
|
||||
/*
|
||||
* Chunk:
|
||||
* 1 1 1 0 0
|
||||
* 2 0 0 0 0
|
||||
*/
|
||||
|
||||
/*
|
||||
* Close/release resources.
|
||||
*/
|
||||
H5Sclose(memspace);
|
||||
}
|
||||
|
||||
/*
|
||||
* Close/release resources.
|
||||
*/
|
||||
H5Pclose(cparms);
|
||||
H5Dclose(dataset);
|
||||
H5Sclose(filespace);
|
||||
H5Fclose(file);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,120 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*
|
||||
* 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(void)
|
||||
{
|
||||
|
||||
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];
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Create dataset "Compressed Data" in the group using absolute name. */
|
||||
dims[0] = DIM0;
|
||||
dims[1] = DIM1;
|
||||
dataspace_id = H5Screate_simple(RANK, dims, NULL);
|
||||
|
||||
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);
|
||||
|
||||
/* Set ZLIB / DEFLATE Compression using compression level 6.
|
||||
* To use SZIP Compression comment out these lines.
|
||||
*/
|
||||
status = H5Pset_deflate(plist_id, 6);
|
||||
|
||||
/* 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;
|
||||
|
||||
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);
|
||||
|
||||
/* 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, 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);
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*
|
||||
* This example shows how to create a compound data type,
|
||||
* write an array which has the compound data type to the file,
|
||||
* and read back fields' subsets.
|
||||
*/
|
||||
|
||||
#include "hdf5.h"
|
||||
|
||||
#define H5FILE_NAME "SDScompound.h5"
|
||||
#define DATASETNAME "ArrayOfStructures"
|
||||
#define LENGTH 10
|
||||
#define RANK 1
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
||||
/* First structure and dataset*/
|
||||
typedef struct s1_t {
|
||||
int a;
|
||||
float b;
|
||||
double c;
|
||||
} s1_t;
|
||||
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;
|
||||
} s2_t;
|
||||
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 */
|
||||
|
||||
/*
|
||||
* Initialize the data
|
||||
*/
|
||||
for (i = 0; i < LENGTH; i++) {
|
||||
s1[i].a = i;
|
||||
s1[i].b = i * i;
|
||||
s1[i].c = 1. / (i + 1);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create the data space.
|
||||
*/
|
||||
space = H5Screate_simple(RANK, dim, NULL);
|
||||
|
||||
/*
|
||||
* Create the file.
|
||||
*/
|
||||
file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
||||
|
||||
/*
|
||||
* Create the memory data type.
|
||||
*/
|
||||
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);
|
||||
|
||||
/*
|
||||
* Create the dataset.
|
||||
*/
|
||||
dataset = H5Dcreate2(file, DATASETNAME, s1_tid, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
||||
|
||||
/*
|
||||
* Wtite data to the dataset;
|
||||
*/
|
||||
status = H5Dwrite(dataset, s1_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, s1);
|
||||
|
||||
/*
|
||||
* Release resources
|
||||
*/
|
||||
H5Tclose(s1_tid);
|
||||
H5Sclose(space);
|
||||
H5Dclose(dataset);
|
||||
H5Fclose(file);
|
||||
|
||||
/*
|
||||
* Open the file and the dataset.
|
||||
*/
|
||||
file = H5Fopen(H5FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT);
|
||||
|
||||
dataset = H5Dopen2(file, DATASETNAME, H5P_DEFAULT);
|
||||
|
||||
/*
|
||||
* Create a data type for s2
|
||||
*/
|
||||
s2_tid = H5Tcreate(H5T_COMPOUND, sizeof(s2_t));
|
||||
|
||||
H5Tinsert(s2_tid, "c_name", HOFFSET(s2_t, c), H5T_NATIVE_DOUBLE);
|
||||
H5Tinsert(s2_tid, "a_name", HOFFSET(s2_t, a), H5T_NATIVE_INT);
|
||||
|
||||
/*
|
||||
* Read two fields c and a from s1 dataset. Fields in the file
|
||||
* are found by their names "c_name" and "a_name".
|
||||
*/
|
||||
status = H5Dread(dataset, s2_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, s2);
|
||||
|
||||
/*
|
||||
* Display the fields
|
||||
*/
|
||||
printf("\n");
|
||||
printf("Field c : \n");
|
||||
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);
|
||||
printf("\n");
|
||||
|
||||
/*
|
||||
* Create a data type for s3.
|
||||
*/
|
||||
s3_tid = H5Tcreate(H5T_COMPOUND, sizeof(float));
|
||||
|
||||
status = H5Tinsert(s3_tid, "b_name", 0, H5T_NATIVE_FLOAT);
|
||||
|
||||
/*
|
||||
* Read field b from s1 dataset. Field in the file is found by its name.
|
||||
*/
|
||||
status = H5Dread(dataset, s3_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, s3);
|
||||
|
||||
/*
|
||||
* Display the field
|
||||
*/
|
||||
printf("\n");
|
||||
printf("Field b : \n");
|
||||
for (i = 0; i < LENGTH; i++)
|
||||
printf("%.4f ", s3[i]);
|
||||
printf("\n");
|
||||
|
||||
/*
|
||||
* Release resources
|
||||
*/
|
||||
H5Tclose(s2_tid);
|
||||
H5Tclose(s3_tid);
|
||||
H5Dclose(dataset);
|
||||
H5Fclose(file);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*
|
||||
* This example illustrates how to create an attribute attached to a
|
||||
* dataset. It is used in the HDF5 Tutorial.
|
||||
*/
|
||||
|
||||
#include "hdf5.h"
|
||||
#define FILE "dset.h5"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
||||
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;
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Write the attribute data. */
|
||||
status = H5Awrite(attribute_id, H5T_NATIVE_INT, attr_data);
|
||||
|
||||
/* Close the attribute. */
|
||||
status = H5Aclose(attribute_id);
|
||||
|
||||
/* Close the dataspace. */
|
||||
status = H5Sclose(dataspace_id);
|
||||
|
||||
/* Close to the dataset. */
|
||||
status = H5Dclose(dataset_id);
|
||||
|
||||
/* Close the file. */
|
||||
status = H5Fclose(file_id);
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*
|
||||
* 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(void)
|
||||
{
|
||||
|
||||
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 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);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Close the file. */
|
||||
status = H5Fclose(file_id);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*
|
||||
* 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(void)
|
||||
{
|
||||
|
||||
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 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);
|
||||
|
||||
/* Terminate access to the file. */
|
||||
status = H5Fclose(file_id);
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*
|
||||
* 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(void)
|
||||
{
|
||||
|
||||
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 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_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 the file. */
|
||||
status = H5Fclose(file_id);
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*
|
||||
* This example illustrates how to create a dataset in a group.
|
||||
* It is used in the HDF5 Tutorial.
|
||||
*/
|
||||
|
||||
#include "hdf5.h"
|
||||
#define FILE "groups.h5"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
||||
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 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);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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 first dataset. */
|
||||
status = H5Dclose(dataset_id);
|
||||
|
||||
/* 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 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);
|
||||
|
||||
/* Close the data space for the second dataset. */
|
||||
status = H5Sclose(dataspace_id);
|
||||
|
||||
/* Close the second dataset */
|
||||
status = H5Dclose(dataset_id);
|
||||
|
||||
/* Close the group. */
|
||||
status = H5Gclose(group_id);
|
||||
|
||||
/* Close the file. */
|
||||
status = H5Fclose(file_id);
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/* 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;
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*
|
||||
* This shows how to use the hdf5 virtual file drivers.
|
||||
* The example codes here do not check return values for the
|
||||
* sake of simplicity. As in all proper programs, return codes
|
||||
* should be checked.
|
||||
*/
|
||||
|
||||
#include "hdf5.h"
|
||||
#include "stdlib.h"
|
||||
|
||||
/* global variables */
|
||||
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.
|
||||
*/
|
||||
void
|
||||
cleanup(const char *filename)
|
||||
{
|
||||
if (cleanup_g == -1)
|
||||
cleanup_g = getenv(HDF5_NOCLEANUP) ? 0 : 1;
|
||||
if (cleanup_g)
|
||||
remove(filename);
|
||||
}
|
||||
|
||||
/*
|
||||
* This shows how to use the split file driver.
|
||||
*/
|
||||
void
|
||||
split_file(void)
|
||||
{
|
||||
hid_t fapl, fid;
|
||||
|
||||
/* Example 1: Both metadata and rawdata files are in the same */
|
||||
/* directory. Use Station1-m.h5 and Station1-r.h5 as */
|
||||
/* 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);
|
||||
/* using the file ... */
|
||||
H5Fclose(fid);
|
||||
H5Pclose(fapl);
|
||||
/* Remove files created */
|
||||
cleanup("Station1-m.h5");
|
||||
cleanup("Station1-r.h5");
|
||||
|
||||
/* Example 2: metadata and rawdata files are in different */
|
||||
/* directories. Use PointA-m.h5 and /tmp/PointA-r.h5 as */
|
||||
/* 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);
|
||||
/* using the file ... */
|
||||
H5Fclose(fid);
|
||||
H5Pclose(fapl);
|
||||
/* Remove files created */
|
||||
cleanup("PointA-m.h5");
|
||||
cleanup("/tmp/PointA-r.h5");
|
||||
|
||||
/* Example 3: Using default extension names for the metadata */
|
||||
/* and rawdata files. Use Measure.meta and Measure.raw as */
|
||||
/* 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);
|
||||
/* using the file ... */
|
||||
H5Fclose(fid);
|
||||
H5Pclose(fapl);
|
||||
/* Remove files created */
|
||||
cleanup("Measure.meta");
|
||||
cleanup("Measure.raw");
|
||||
}
|
||||
|
||||
/* Main Body */
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
||||
split_file();
|
||||
|
||||
return (0);
|
||||
}
|
||||
@@ -0,0 +1,172 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*
|
||||
* This example demonstrates how the data transform features of
|
||||
* HDF5 works.
|
||||
*
|
||||
* (1)
|
||||
* The test first writes out data, with no data transform set.
|
||||
* Then, the test reads back this data with a data transform applied.
|
||||
*
|
||||
* (2)
|
||||
* Then, the test writes a new set of data, with a data transform set.
|
||||
* Then, the test reads this new set of data, without a data set.
|
||||
*
|
||||
* (3)
|
||||
* Lastly, the test reads the previous set of data (that was written out
|
||||
* with a data transform) with a data transform set for the read.
|
||||
*
|
||||
* (4)
|
||||
* Get the transform from the property using H5Pget_data_transform.
|
||||
*/
|
||||
|
||||
#include "hdf5.h"
|
||||
|
||||
#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},
|
||||
{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"); \
|
||||
} \
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
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;
|
||||
|
||||
/*
|
||||
* Create a new file using H5F_ACC_TRUNC access,
|
||||
* default file creation properties, and default file
|
||||
* access properties.
|
||||
*/
|
||||
file = H5Fcreate("dtransform.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
||||
|
||||
/*
|
||||
* Describe the size of the array and create the data space for fixed
|
||||
* size dataset.
|
||||
*/
|
||||
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);
|
||||
printf("\nOriginal Data: \n");
|
||||
|
||||
PRINT(windchillF);
|
||||
|
||||
/**************** 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);
|
||||
|
||||
/* Create the dataset transfer property list */
|
||||
dxpl_id_f_to_c = H5Pcreate(H5P_DATASET_XFER);
|
||||
|
||||
/* Set the data transform */
|
||||
H5Pset_data_transform(dxpl_id_f_to_c, f_to_c);
|
||||
|
||||
/* Read out the data with the data transform */
|
||||
H5Dread(dataset, H5T_NATIVE_FLOAT, H5S_ALL, H5S_ALL, dxpl_id_f_to_c, windchillC);
|
||||
|
||||
/* Print the data from the read*/
|
||||
printf("\nData with no write transform, but a read transform: \n");
|
||||
PRINT(windchillC);
|
||||
|
||||
/**************** 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);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Print the data from the read*/
|
||||
printf("\nData with write transform, but no read transform: \n");
|
||||
PRINT(windchillC);
|
||||
|
||||
/************** PART 3 ***************/
|
||||
|
||||
/* Create the dataset transfer property list */
|
||||
dxpl_id_c_to_f = H5Pcreate(H5P_DATASET_XFER);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Print the data from the read*/
|
||||
printf("\nData with both read and write data transform: \n");
|
||||
PRINT(windchillC);
|
||||
|
||||
/************** 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);
|
||||
|
||||
printf("\nTransform string (from dxpl_id_f_to_c) is: %s\n", transform);
|
||||
|
||||
/*
|
||||
* Close/release resources.
|
||||
*/
|
||||
H5Pclose(dxpl_id_c_to_f);
|
||||
H5Pclose(dxpl_id_f_to_c);
|
||||
H5Sclose(dataspace);
|
||||
H5Dclose(dataset);
|
||||
H5Fclose(file);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,207 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/* This program demonstrates how to translate an external link created on
|
||||
* a Windows machine into a format that a *nix machine can read.
|
||||
* This is done by registering a new traversal function for external links.
|
||||
*
|
||||
* This example is designed to be run on Unix and will create an external
|
||||
* link with a Windows-style path. Using the traversal function below,
|
||||
* the example then successfully follows the external link.
|
||||
*
|
||||
* The external link will create a file called "u2w/u2w_target.h5".
|
||||
* The example will fail if the directory u2w does not exist.
|
||||
*/
|
||||
|
||||
#include "hdf5.h"
|
||||
#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
|
||||
* forward slashes with backslashes.
|
||||
* Makes no attempt to handle Windows drive names (e.g., "C:\"), spaces within
|
||||
* file names, quotes, etc. These are left as an exercise for the user. :)
|
||||
* 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)
|
||||
{
|
||||
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)
|
||||
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)
|
||||
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) {
|
||||
/* 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)
|
||||
goto error;
|
||||
|
||||
start_pos = prefix_len;
|
||||
}
|
||||
else {
|
||||
/* Allocate a buffer to hold just the filename */
|
||||
new_fname = malloc(fname_len + 1);
|
||||
start_pos = 0;
|
||||
}
|
||||
|
||||
/* 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] == '/')
|
||||
new_fname[x + start_pos] = '\\';
|
||||
else
|
||||
new_fname[x + start_pos] = file_name[x];
|
||||
}
|
||||
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)
|
||||
goto error;
|
||||
ret_value = H5Oopen(fid, obj_name, lapl_id); /* If this fails, our return value will be negative. */
|
||||
if (H5Fclose(fid) < 0)
|
||||
goto error;
|
||||
|
||||
/* Free file name if it's been allocated */
|
||||
if (new_fname)
|
||||
free(new_fname);
|
||||
|
||||
return ret_value;
|
||||
|
||||
error:
|
||||
/* Free file name if it's been allocated */
|
||||
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 */
|
||||
}};
|
||||
|
||||
/* The example function.
|
||||
* Creates a file named "unix2win.h5" with an external link pointing to
|
||||
* the file "u2w/u2w_target.h5".
|
||||
*
|
||||
* Registers a new traversal function for external links and then
|
||||
* follows the external link to open the target file.
|
||||
*/
|
||||
static int
|
||||
unix2win_example(void)
|
||||
{
|
||||
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;
|
||||
#else
|
||||
if ((fid = H5Fcreate("u2w/u2w_target.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
|
||||
goto error;
|
||||
#endif
|
||||
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;
|
||||
|
||||
/* Create the external link */
|
||||
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.
|
||||
*/
|
||||
|
||||
#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;
|
||||
#endif
|
||||
|
||||
/* Now follow the link */
|
||||
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;
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
printf("Error!\n");
|
||||
H5E_BEGIN_TRY
|
||||
{
|
||||
H5Gclose(gid);
|
||||
H5Fclose(fid);
|
||||
}
|
||||
H5E_END_TRY
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Main function
|
||||
*
|
||||
* Invokes the example function.
|
||||
*/
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
printf("Testing unix2win external links.\n");
|
||||
ret = unix2win_example();
|
||||
|
||||
return ret;
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*
|
||||
* 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
|
||||
|
||||
int
|
||||
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}};
|
||||
|
||||
/* 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}};
|
||||
|
||||
/* 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;
|
||||
|
||||
/* Create the data space with unlimited dimensions. */
|
||||
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);
|
||||
|
||||
/* Modify dataset creation properties, i.e. enable chunking */
|
||||
prop = H5Pcreate(H5P_DATASET_CREATE);
|
||||
status = H5Pset_chunk(prop, RANK, chunk_dims);
|
||||
|
||||
/* Create a new dataset within the file using chunk
|
||||
creation properties. */
|
||||
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);
|
||||
|
||||
/* Extend the dataset. Dataset becomes 10 x 3 */
|
||||
size[0] = dims[0] + dimsext[0];
|
||||
size[1] = dims[1];
|
||||
status = H5Dset_extent(dataset, size);
|
||||
|
||||
/* Select a hyperslab in extended portion of dataset */
|
||||
filespace = H5Dget_space(dataset);
|
||||
offset[0] = 3;
|
||||
offset[1] = 0;
|
||||
status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL, dimsext, NULL);
|
||||
|
||||
/* Define memory space */
|
||||
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);
|
||||
|
||||
/* Close resources */
|
||||
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);
|
||||
|
||||
filespace = H5Dget_space(dataset);
|
||||
rank = H5Sget_simple_extent_ndims(filespace);
|
||||
status_n = H5Sget_simple_extent_dims(filespace, dimsr, NULL);
|
||||
|
||||
prop = H5Dget_create_plist(dataset);
|
||||
|
||||
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);
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
status = H5Pclose(prop);
|
||||
status = H5Dclose(dataset);
|
||||
status = H5Sclose(filespace);
|
||||
status = H5Sclose(memspace);
|
||||
status = H5Fclose(file);
|
||||
}
|
||||
@@ -0,0 +1,178 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*
|
||||
* This example shows how to work with extendible dataset.
|
||||
* In the current version of the library dataset MUST be
|
||||
* chunked.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "hdf5.h"
|
||||
|
||||
#define H5FILE_NAME "SDSextendible.h5"
|
||||
#define DATASETNAME "ExtendibleArray"
|
||||
#define RANK 2
|
||||
#define NX 10
|
||||
#define NY 5
|
||||
|
||||
int
|
||||
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 */
|
||||
|
||||
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;
|
||||
|
||||
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 data3[2][2] = {{3, 3}, {3, 3}};
|
||||
int fillvalue = 0;
|
||||
|
||||
/*
|
||||
* Create the data space with unlimited dimensions.
|
||||
*/
|
||||
dataspace = H5Screate_simple(RANK, dims, maxdims);
|
||||
|
||||
/*
|
||||
* Create a new file. If file exists its contents will be overwritten.
|
||||
*/
|
||||
file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
/*
|
||||
* Create a new dataset within the file using cparms
|
||||
* creation properties.
|
||||
*/
|
||||
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);
|
||||
|
||||
/*
|
||||
* Select a hyperslab.
|
||||
*/
|
||||
filespace = H5Dget_space(dataset);
|
||||
offset[0] = 0;
|
||||
offset[1] = 0;
|
||||
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);
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
/*
|
||||
* Select a hyperslab.
|
||||
*/
|
||||
filespace = H5Dget_space(dataset);
|
||||
offset[0] = 3;
|
||||
offset[1] = 0;
|
||||
status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL, dims2, NULL);
|
||||
|
||||
/*
|
||||
* Define memory space
|
||||
*/
|
||||
dataspace = H5Screate_simple(RANK, dims2, NULL);
|
||||
|
||||
/*
|
||||
* Write the data to the hyperslab.
|
||||
*/
|
||||
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);
|
||||
|
||||
/*
|
||||
* Select a hyperslab
|
||||
*/
|
||||
filespace = H5Dget_space(dataset);
|
||||
offset[0] = 0;
|
||||
offset[1] = 3;
|
||||
status = H5Sselect_hyperslab(filespace, H5S_SELECT_SET, offset, NULL, dims3, NULL);
|
||||
|
||||
/*
|
||||
* Define memory space.
|
||||
*/
|
||||
dataspace = H5Screate_simple(RANK, dims3, NULL);
|
||||
|
||||
/*
|
||||
* Write the data to the hyperslab.
|
||||
*/
|
||||
status = H5Dwrite(dataset, H5T_NATIVE_INT, dataspace, filespace, H5P_DEFAULT, data3);
|
||||
|
||||
/*
|
||||
* Resulting dataset
|
||||
*
|
||||
* 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
|
||||
* 2 0 0 0 0
|
||||
* 2 0 0 0 0
|
||||
* 2 0 0 0 0
|
||||
* 2 0 0 0 0
|
||||
*/
|
||||
/*
|
||||
* Close/release resources.
|
||||
*/
|
||||
H5Dclose(dataset);
|
||||
H5Sclose(dataspace);
|
||||
H5Sclose(filespace);
|
||||
H5Pclose(cparms);
|
||||
H5Fclose(file);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,662 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/* This program demonstrates how to create and use "external links" in
|
||||
* HDF5.
|
||||
*
|
||||
* External links point from one HDF5 file to an object (Group, Dataset, or
|
||||
* committed Datatype) in another file.
|
||||
*/
|
||||
|
||||
#include "hdf5.h"
|
||||
#include <string.h>
|
||||
|
||||
#define SOURCE_FILE "extlink_source.h5"
|
||||
#define TARGET_FILE "extlink_target.h5"
|
||||
|
||||
#define PREFIX_SOURCE_FILE "extlink_prefix_source.h5"
|
||||
|
||||
#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 UD_SOFT_CLASS 65
|
||||
|
||||
#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
|
||||
|
||||
/* 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)
|
||||
{
|
||||
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);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Close the group and the target file */
|
||||
H5Gclose(group_id);
|
||||
|
||||
/* Create an external link in the source file pointing to the target group.
|
||||
* We could instead have created the external link first, then created the
|
||||
* group it points to; the order doesn't matter.
|
||||
*/
|
||||
H5Lcreate_external(TARGET_FILE, "target_group", source_file_id, "ext_link", H5P_DEFAULT, H5P_DEFAULT);
|
||||
|
||||
/* Now we can use the external link to create a new group inside the
|
||||
* target group (even though the target file is closed!). The external
|
||||
* link works just like a soft link.
|
||||
*/
|
||||
group_id = H5Gcreate2(source_file_id, "ext_link/new_group", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
||||
|
||||
/* The group is inside the target file and we can access it normally.
|
||||
* Here, group_id and group2_id point to the same group inside the
|
||||
* target file.
|
||||
*/
|
||||
group2_id = H5Gopen2(targ_file_id, "target_group/new_group", H5P_DEFAULT);
|
||||
|
||||
/* Don't forget to close the IDs we opened. */
|
||||
H5Gclose(group2_id);
|
||||
H5Gclose(group_id);
|
||||
|
||||
H5Fclose(targ_file_id);
|
||||
H5Fclose(source_file_id);
|
||||
|
||||
/* The link from the source file to the target file will work as long as
|
||||
* the target file can be found. If the target file is moved, renamed,
|
||||
* or deleted in the filesystem, HDF5 won't be able to find it and the
|
||||
* external link will "dangle."
|
||||
*/
|
||||
}
|
||||
|
||||
/* External link prefix example
|
||||
*
|
||||
* Uses a group access property list to set a "prefix" for the filenames
|
||||
* accessed through an external link.
|
||||
*
|
||||
* Group access property lists inherit from link access property lists;
|
||||
* the external link prefix property is actually a property of LAPLs.
|
||||
*
|
||||
* This example requires a "red" directory and a "blue" directory to exist
|
||||
* where it is run (so to run this example on Unix, first mkdir red and mkdir
|
||||
* blue).
|
||||
*/
|
||||
static void
|
||||
extlink_prefix_example(void)
|
||||
{
|
||||
hid_t source_file_id, red_file_id, blue_file_id;
|
||||
hid_t group_id, group2_id;
|
||||
hid_t gapl_id;
|
||||
|
||||
/* Create three files, a source and two targets. The targets will have
|
||||
* 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);
|
||||
|
||||
/* 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");
|
||||
|
||||
/* 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
|
||||
* directory, but the files in the red and blue directories both have this
|
||||
* name.
|
||||
*/
|
||||
H5Lcreate_external("prefix_target.h5", "/", source_file_id, "ext_link", H5P_DEFAULT, H5P_DEFAULT);
|
||||
|
||||
/* If we tried to traverse the external link now, we would fail (since the
|
||||
* file it points to doesn't exist). Instead, we'll create a group access
|
||||
* property list that will provide a prefix path to the external link.
|
||||
* Group access property lists inherit the properties of link access
|
||||
* property lists.
|
||||
*/
|
||||
gapl_id = H5Pcreate(H5P_GROUP_ACCESS);
|
||||
H5Pset_elink_prefix(gapl_id, "red/");
|
||||
|
||||
/* Now if we traverse the external link, HDF5 will look for an external
|
||||
* file named red/prefix_target.h5, which exists.
|
||||
* To pass the group access property list, we need to use H5Gopen2.
|
||||
*/
|
||||
group_id = H5Gopen2(source_file_id, "ext_link", gapl_id);
|
||||
|
||||
/* Now we can use the open group ID to create a new group inside the
|
||||
* "red" file.
|
||||
*/
|
||||
group2_id = H5Gcreate2(group_id, "pink", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
||||
|
||||
/* Close both groups. */
|
||||
H5Gclose(group2_id);
|
||||
H5Gclose(group_id);
|
||||
|
||||
/* If we change the prefix, the same external link can find a file in the blue
|
||||
* directory.
|
||||
*/
|
||||
H5Pset_elink_prefix(gapl_id, "blue/");
|
||||
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. */
|
||||
H5Gclose(group2_id);
|
||||
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);
|
||||
group2_id = H5Gopen2(blue_file_id, "sky blue", H5P_DEFAULT);
|
||||
|
||||
/* Clean up our open IDs */
|
||||
H5Gclose(group2_id);
|
||||
H5Gclose(group_id);
|
||||
H5Pclose(gapl_id);
|
||||
H5Fclose(blue_file_id);
|
||||
H5Fclose(red_file_id);
|
||||
H5Fclose(source_file_id);
|
||||
|
||||
/* User-defined links can expand on the ability to pass in parameters
|
||||
* using an access property list; for instance, a user-defined link
|
||||
* might function like an external link but allow the full filename to be
|
||||
* passed in through the access property list.
|
||||
*/
|
||||
}
|
||||
|
||||
/* Soft Link example
|
||||
*
|
||||
* Create a new class of user-defined links that behave like HDF5's built-in
|
||||
* soft links.
|
||||
*
|
||||
* This isn't very useful by itself (HDF5's soft links already do the same
|
||||
* thing), but it can serve as an example for how to reference objects by
|
||||
* name.
|
||||
*/
|
||||
|
||||
/* We need to define the callback function that the soft link will use.
|
||||
* It is defined after the example below.
|
||||
* To keep the example simple, these links don't have a query callback.
|
||||
* In general, link classes should always be query-able.
|
||||
* 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 void
|
||||
soft_link_example(void)
|
||||
{
|
||||
hid_t file_id;
|
||||
hid_t group_id;
|
||||
/* Define the link class that we'll use to register "user-defined soft
|
||||
* 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_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 */
|
||||
}};
|
||||
|
||||
/* 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);
|
||||
group_id = H5Gcreate2(file_id, TARGET_GROUP, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
||||
H5Gclose(group_id);
|
||||
|
||||
/* This is how we create a normal soft link to the group.
|
||||
*/
|
||||
H5Lcreate_soft(TARGET_GROUP, file_id, SOFT_LINK_NAME, H5P_DEFAULT, H5P_DEFAULT);
|
||||
|
||||
/* To do the same thing using a user-defined link, we first have to
|
||||
* register the link class we defined.
|
||||
*/
|
||||
H5Lregister(UD_soft_class);
|
||||
|
||||
/* Now create a user-defined link. We give it the path to the group
|
||||
* as its udata.1
|
||||
*/
|
||||
H5Lcreate_ud(file_id, UD_SOFT_LINK_NAME, (H5L_type_t)UD_SOFT_CLASS, TARGET_GROUP,
|
||||
strlen(TARGET_GROUP) + 1, H5P_DEFAULT, H5P_DEFAULT);
|
||||
|
||||
/* We can access the group through the UD soft link like we would through
|
||||
* a normal soft link. This link will still dangle if the object's
|
||||
* original name is changed or unlinked.
|
||||
*/
|
||||
group_id = H5Gopen2(file_id, UD_SOFT_LINK_NAME, H5P_DEFAULT);
|
||||
|
||||
/* The group is now open normally. Don't forget to close it! */
|
||||
H5Gclose(group_id);
|
||||
|
||||
H5Fclose(file_id);
|
||||
}
|
||||
|
||||
/* UD_soft_traverse
|
||||
* 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)
|
||||
{
|
||||
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.
|
||||
*/
|
||||
ret_value = H5Oopen(cur_group, target, lapl_id);
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
/* Hard Link example
|
||||
*
|
||||
* Create a new class of user-defined links that behave like HDF5's built-in
|
||||
* hard links.
|
||||
*
|
||||
* This isn't very useful by itself (HDF5's hard links already do the same
|
||||
* thing), but it can serve as an example for how to reference objects by
|
||||
* address.
|
||||
*/
|
||||
|
||||
/* We need to define the callback functions that the hard link will use.
|
||||
* These are defined after the example below.
|
||||
* 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)
|
||||
{
|
||||
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 */
|
||||
}};
|
||||
|
||||
/* 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);
|
||||
group_id = H5Gcreate2(file_id, TARGET_GROUP, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
||||
H5Gclose(group_id);
|
||||
|
||||
/* This is how we create a normal hard link to the group. This
|
||||
* creates a second "name" for the group.
|
||||
*/
|
||||
H5Lcreate_hard(file_id, TARGET_GROUP, file_id, HARD_LINK_NAME, H5P_DEFAULT, H5P_DEFAULT);
|
||||
|
||||
/* To do the same thing using a user-defined link, we first have to
|
||||
* register the link class we defined.
|
||||
*/
|
||||
H5Lregister(UD_hard_class);
|
||||
|
||||
/* Since hard links link by object address, we'll need to retrieve
|
||||
* the target group's address. We do this by calling H5Lget_info
|
||||
* on a hard link to the object.
|
||||
*/
|
||||
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.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
|
||||
* other two links to that group and it won't be deleted until the
|
||||
* UD hard link is deleted.
|
||||
*/
|
||||
H5Ldelete(file_id, TARGET_GROUP, H5P_DEFAULT);
|
||||
H5Ldelete(file_id, HARD_LINK_NAME, H5P_DEFAULT);
|
||||
|
||||
/* The group is still accessible through the UD hard link. If this were
|
||||
* a soft link instead, the object would have been deleted when the last
|
||||
* hard link to it was unlinked. */
|
||||
group_id = H5Gopen2(file_id, UD_HARD_LINK_NAME, H5P_DEFAULT);
|
||||
|
||||
/* The group is now open normally. Don't forget to close it! */
|
||||
H5Gclose(group_id);
|
||||
|
||||
/* Removing the user-defined hard link will delete the group. */
|
||||
H5Ldelete(file_id, UD_HARD_LINK_NAME, H5P_DEFAULT);
|
||||
|
||||
H5Fclose(file_id);
|
||||
}
|
||||
|
||||
/* Callbacks for User-defined hard links. */
|
||||
/* UD_hard_create
|
||||
* The most important thing this callback does is to increment the reference
|
||||
* count on the target object. Without this step, the object could be
|
||||
* deleted while this link still pointed to it, resulting in possible data
|
||||
* corruption!
|
||||
* The create callback also checks the arguments used to create this link.
|
||||
* 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)
|
||||
{
|
||||
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(H5O_token_t)) {
|
||||
ret_value = -1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
token = *((const 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 token passed
|
||||
* in points to a real object (although this check is not perfect!) */
|
||||
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;
|
||||
}
|
||||
|
||||
done:
|
||||
/* Close the target object if we opened it */
|
||||
if (target_obj >= 0)
|
||||
H5Oclose(target_obj);
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
/* UD_hard_delete
|
||||
* 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)
|
||||
{
|
||||
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(H5O_token_t)) {
|
||||
ret_value = -1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
token = *((const H5O_token_t *)udata);
|
||||
|
||||
/* Open the object this link points to */
|
||||
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;
|
||||
}
|
||||
|
||||
done:
|
||||
/* Close the target object if we opened it */
|
||||
if (target_obj >= 0)
|
||||
H5Oclose(target_obj);
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
/* UD_hard_traverse
|
||||
* 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)
|
||||
{
|
||||
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(H5O_token_t))
|
||||
return H5I_INVALID_HID;
|
||||
|
||||
token = *((const H5O_token_t *)udata);
|
||||
|
||||
/* 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_token(cur_group, token);
|
||||
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
/* Plist example
|
||||
*
|
||||
* Create a new class of user-defined links that open objects within a file
|
||||
* based on a value passed in through a link access property list.
|
||||
*
|
||||
* Group, dataset, and datatype access property lists all inherit from link
|
||||
* access property lists, so they can be used instead of LAPLs.
|
||||
*/
|
||||
|
||||
/* We need to define the callback functions that this link type will use.
|
||||
* 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 void
|
||||
plist_link_example(void)
|
||||
{
|
||||
hid_t file_id;
|
||||
hid_t group_id, group2_id;
|
||||
hid_t gapl_id;
|
||||
char *path = NULL;
|
||||
|
||||
/* Define the link class that we'll use to register "plist
|
||||
* links" using the callback we defined above.
|
||||
* A link class can have NULL for any callback except its traverse
|
||||
* callback.
|
||||
*/
|
||||
const H5L_class_t UD_plist_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_PLIST_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 67. */
|
||||
"UD_plist_link", /* Link class name for debugging */
|
||||
NULL, /* Creation callback */
|
||||
NULL, /* Move callback */
|
||||
NULL, /* Copy callback */
|
||||
UD_plist_traverse, /* The actual traversal function */
|
||||
NULL, /* Deletion callback */
|
||||
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);
|
||||
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);
|
||||
H5Gclose(group_id);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Create a group access property list to pass in the target for the
|
||||
* plist link.
|
||||
*/
|
||||
gapl_id = H5Pcreate(H5P_GROUP_ACCESS);
|
||||
|
||||
/* There is no HDF5 API for setting the property that controls these
|
||||
* links, so we have to add the property manually
|
||||
*/
|
||||
H5Pinsert2(gapl_id, PLIST_LINK_PROP, sizeof(const char *), &(path), NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
|
||||
/* Set the property to point to the first group. */
|
||||
path = "group_1";
|
||||
H5Pset(gapl_id, PLIST_LINK_PROP, &path);
|
||||
|
||||
/* Open the first group through the plist link using the GAPL we just
|
||||
* created */
|
||||
group_id = H5Gopen2(file_id, "plist_link", gapl_id);
|
||||
|
||||
/* If we change the value set on the property list, it will change where
|
||||
* the plist link points.
|
||||
*/
|
||||
path = "group_1/group_2";
|
||||
H5Pset(gapl_id, PLIST_LINK_PROP, &path);
|
||||
group2_id = H5Gopen2(file_id, "plist_link", gapl_id);
|
||||
|
||||
/* group_id points to group_1 and group2_id points to group_2, both opened
|
||||
* through the same link.
|
||||
* Using more than one of this type of link could quickly become confusing,
|
||||
* since they will all use the same property list; however, there is
|
||||
* nothing to prevent the links from changing the property list in their
|
||||
* traverse callbacks.
|
||||
*/
|
||||
|
||||
/* Clean up */
|
||||
H5Pclose(gapl_id);
|
||||
H5Gclose(group_id);
|
||||
H5Gclose(group2_id);
|
||||
H5Fclose(file_id);
|
||||
}
|
||||
|
||||
/* Traversal callback for User-defined plist links. */
|
||||
/* 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)
|
||||
{
|
||||
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)
|
||||
goto error;
|
||||
|
||||
if (H5Pget(lapl_id, PLIST_LINK_PROP, &path) < 0)
|
||||
goto error;
|
||||
|
||||
/* Open the object by address. If H5Oopen_by_addr fails, ret_value will
|
||||
* be negative to indicate that the traversal function failed.
|
||||
*/
|
||||
ret_value = H5Oopen(cur_group, path, lapl_id);
|
||||
|
||||
return ret_value;
|
||||
|
||||
error:
|
||||
return H5I_INVALID_HID;
|
||||
}
|
||||
|
||||
/* Main function
|
||||
*
|
||||
* Invokes the example functions.
|
||||
*/
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
printf("Testing basic external links.\n");
|
||||
extlink_example();
|
||||
|
||||
printf("Testing external link prefixes.\n");
|
||||
extlink_prefix_example();
|
||||
|
||||
printf("Testing user-defined soft links.\n");
|
||||
soft_link_example();
|
||||
|
||||
printf("Testing user-defined hard links.\n");
|
||||
hard_link_example();
|
||||
|
||||
printf("Testing user-defined property list links.\n");
|
||||
plist_link_example();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,255 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*
|
||||
* This program creates a group in the file and two datasets in the group.
|
||||
* Hard link to the group object is created and one of the datasets is accessed
|
||||
* under new name.
|
||||
* Iterator functions are used to find information about the objects
|
||||
* in the root group and in the created group.
|
||||
*/
|
||||
|
||||
#include "hdf5.h"
|
||||
|
||||
#define H5FILE_NAME "group.h5"
|
||||
#define RANK 2
|
||||
|
||||
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;
|
||||
|
||||
herr_t status;
|
||||
hsize_t dims[2];
|
||||
hsize_t cdims[2];
|
||||
|
||||
int idx_f, idx_g;
|
||||
|
||||
/*
|
||||
* Create a file.
|
||||
*/
|
||||
file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
||||
|
||||
/*
|
||||
* Create a group in the file.
|
||||
*/
|
||||
grp = H5Gcreate2(file, "/Data", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
||||
|
||||
/*
|
||||
* Create dataset "Compressed Data" in the group using absolute
|
||||
* name. Dataset creation property list is modified to use
|
||||
* 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;
|
||||
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);
|
||||
/*
|
||||
* Close the first dataset .
|
||||
*/
|
||||
H5Sclose(dataspace);
|
||||
H5Dclose(dataset);
|
||||
|
||||
/*
|
||||
* Create the second dataset.
|
||||
*/
|
||||
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);
|
||||
|
||||
/*
|
||||
*Close the second dataset and file.
|
||||
*/
|
||||
H5Sclose(dataspace);
|
||||
H5Dclose(dataset);
|
||||
H5Pclose(plist);
|
||||
H5Gclose(grp);
|
||||
H5Fclose(file);
|
||||
|
||||
/*
|
||||
* Now reopen the file and group in the file.
|
||||
*/
|
||||
file = H5Fopen(H5FILE_NAME, H5F_ACC_RDWR, H5P_DEFAULT);
|
||||
grp = H5Gopen2(file, "Data", H5P_DEFAULT);
|
||||
|
||||
/*
|
||||
* 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");
|
||||
printf("\"/Data/Compressed_Data\" dataset is open \n");
|
||||
|
||||
/*
|
||||
* Close the dataset.
|
||||
*/
|
||||
status = H5Dclose(dataset);
|
||||
|
||||
/*
|
||||
* Create hard link to the Data group.
|
||||
*/
|
||||
status = H5Lcreate_hard(file, "Data", H5L_SAME_LOC, "Data_new", H5P_DEFAULT, H5P_DEFAULT);
|
||||
|
||||
/*
|
||||
* We can access "Compressed_Data" dataset using created
|
||||
* hard link "Data_new".
|
||||
*/
|
||||
dataset = H5Dopen2(file, "/Data_new/Compressed_Data", H5P_DEFAULT);
|
||||
if (dataset < 0)
|
||||
printf(" Dataset is not found. \n");
|
||||
printf("\"/Data_new/Compressed_Data\" dataset is open \n");
|
||||
|
||||
/*
|
||||
* Close the dataset.
|
||||
*/
|
||||
status = H5Dclose(dataset);
|
||||
|
||||
/*
|
||||
* Use iterator to see the names of the objects in the root group.
|
||||
*/
|
||||
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");
|
||||
else
|
||||
printf("\"Data\" is unlinked \n");
|
||||
|
||||
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_name2(grp, "/Data_new", H5_INDEX_NAME, H5_ITER_INC, NULL, group_info, NULL,
|
||||
H5P_DEFAULT);
|
||||
|
||||
/*
|
||||
* Close the file.
|
||||
*/
|
||||
|
||||
H5Gclose(grp);
|
||||
H5Fclose(file);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Operator function.
|
||||
*/
|
||||
static herr_t
|
||||
file_info(hid_t loc_id, const char *name, const H5L_info2_t *linfo, void *opdata)
|
||||
{
|
||||
/* avoid compiler warnings */
|
||||
(void)loc_id;
|
||||
(void)opdata;
|
||||
(void)linfo;
|
||||
|
||||
/*
|
||||
* Display group name. The name is passed to the function by
|
||||
* the Library. Some magic :-)
|
||||
*/
|
||||
printf("\nName : %s\n", name);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Operator function.
|
||||
*/
|
||||
static herr_t
|
||||
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 */
|
||||
H5T_class_t t_class;
|
||||
hid_t pid; /* data_property identifier */
|
||||
hsize_t chunk_dims_out[2];
|
||||
int rank_chunk;
|
||||
|
||||
/* avoid warnings */
|
||||
(void)opdata;
|
||||
(void)linfo;
|
||||
|
||||
/*
|
||||
* Open the datasets using their names.
|
||||
*/
|
||||
did = H5Dopen2(loc_id, name, H5P_DEFAULT);
|
||||
|
||||
/*
|
||||
* Display dataset name.
|
||||
*/
|
||||
printf("\nName : %s\n", name);
|
||||
|
||||
/*
|
||||
* Display dataset information.
|
||||
*/
|
||||
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)) {
|
||||
/*
|
||||
* 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]));
|
||||
}
|
||||
else {
|
||||
t_class = H5Tget_class(tid);
|
||||
if (t_class < 0) {
|
||||
puts(" Invalid datatype.\n");
|
||||
}
|
||||
else {
|
||||
if (t_class == H5T_INTEGER)
|
||||
puts(" Datatype is 'H5T_NATIVE_INTEGER'.\n");
|
||||
if (t_class == H5T_FLOAT)
|
||||
puts(" Datatype is 'H5T_NATIVE_FLOAT'.\n");
|
||||
if (t_class == H5T_STRING)
|
||||
puts(" Datatype is 'H5T_NATIVE_STRING'.\n");
|
||||
if (t_class == H5T_BITFIELD)
|
||||
puts(" Datatype is 'H5T_NATIVE_BITFIELD'.\n");
|
||||
if (t_class == H5T_OPAQUE)
|
||||
puts(" Datatype is 'H5T_NATIVE_OPAQUE'.\n");
|
||||
if (t_class == H5T_COMPOUND)
|
||||
puts(" Datatype is 'H5T_NATIVE_COMPOUND'.\n");
|
||||
}
|
||||
}
|
||||
|
||||
H5Dclose(did);
|
||||
H5Pclose(pid);
|
||||
H5Tclose(tid);
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*
|
||||
* This program checks if group exists in a file and creates it including
|
||||
* all intermediate groups.
|
||||
*/
|
||||
|
||||
#include "hdf5.h"
|
||||
|
||||
#define H5FILE_NAME "interm_group.h5"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
||||
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;
|
||||
|
||||
/*
|
||||
* Create a file using the default properties.
|
||||
*/
|
||||
file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
||||
|
||||
/*
|
||||
* Create a group in the file.
|
||||
*/
|
||||
g1_id = H5Gcreate2(file, "/G1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
||||
|
||||
H5Gclose(g1_id);
|
||||
H5Fclose(file);
|
||||
|
||||
/*
|
||||
* Now reopen the file and group in the file.
|
||||
*/
|
||||
file = H5Fopen(H5FILE_NAME, H5F_ACC_RDWR, H5P_DEFAULT);
|
||||
|
||||
/*
|
||||
* Check if group /G1 exists in the file.
|
||||
*/
|
||||
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);
|
||||
}
|
||||
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);
|
||||
|
||||
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;
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*
|
||||
* This program shows the concept of "mounting files".
|
||||
* Program creates one file with group G in it, and another
|
||||
* file with dataset D. Then second file is mounted in the first one
|
||||
* under the "mounting point" G. Dataset D is accessed in the first file
|
||||
* under name /G/D and data is printed out.
|
||||
*/
|
||||
|
||||
#include "hdf5.h"
|
||||
|
||||
#define FILE1 "mount1.h5"
|
||||
#define FILE2 "mount2.h5"
|
||||
|
||||
#define RANK 2
|
||||
#define NX 4
|
||||
#define NY 5
|
||||
|
||||
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 identifiers
|
||||
*/
|
||||
H5Tclose(tid);
|
||||
H5Dclose(did);
|
||||
|
||||
/*
|
||||
* Unmounting second file
|
||||
*/
|
||||
H5Funmount(fid1, "/G");
|
||||
|
||||
/*
|
||||
* Close both files
|
||||
*/
|
||||
H5Fclose(fid1);
|
||||
H5Fclose(fid2);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*
|
||||
* This example illustrates how to write and read data in an existing
|
||||
* dataset. It is used in the HDF5 Tutorial.
|
||||
*/
|
||||
|
||||
#include "hdf5.h"
|
||||
#define FILE "dset.h5"
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
|
||||
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;
|
||||
|
||||
/* 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);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Close the dataset. */
|
||||
status = H5Dclose(dataset_id);
|
||||
|
||||
/* Close the file. */
|
||||
status = H5Fclose(file_id);
|
||||
}
|
||||
@@ -0,0 +1,148 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*
|
||||
* This example reads hyperslab from the SDS.h5 file
|
||||
* created by h5_write.c program into two-dimensional
|
||||
* plane of the three-dimensional array.
|
||||
* Information about dataset in the SDS.h5 file is obtained.
|
||||
*/
|
||||
|
||||
#include "hdf5.h"
|
||||
|
||||
#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
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
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;
|
||||
|
||||
for (j = 0; j < NX; j++) {
|
||||
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);
|
||||
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);
|
||||
printf(" Data size is %d \n", (int)size);
|
||||
|
||||
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]));
|
||||
|
||||
/*
|
||||
* Define hyperslab in the dataset.
|
||||
*/
|
||||
offset[0] = 1;
|
||||
offset[1] = 2;
|
||||
count[0] = NX_SUB;
|
||||
count[1] = NY_SUB;
|
||||
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);
|
||||
|
||||
/*
|
||||
* Define memory hyperslab.
|
||||
*/
|
||||
offset_out[0] = 3;
|
||||
offset_out[1] = 0;
|
||||
offset_out[2] = 0;
|
||||
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);
|
||||
|
||||
/*
|
||||
* 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);
|
||||
for (j = 0; j < NX; j++) {
|
||||
for (i = 0; i < NY; i++)
|
||||
printf("%d ", data_out[j][i][0]);
|
||||
printf("\n");
|
||||
}
|
||||
/*
|
||||
* 0 0 0 0 0 0 0
|
||||
* 0 0 0 0 0 0 0
|
||||
* 0 0 0 0 0 0 0
|
||||
* 3 4 5 6 0 0 0
|
||||
* 4 5 6 7 0 0 0
|
||||
* 5 6 7 8 0 0 0
|
||||
* 0 0 0 0 0 0 0
|
||||
*/
|
||||
|
||||
/*
|
||||
* Close/release resources.
|
||||
*/
|
||||
H5Tclose(datatype);
|
||||
H5Dclose(dataset);
|
||||
H5Sclose(dataspace);
|
||||
H5Sclose(memspace);
|
||||
H5Fclose(file);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,204 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
/*
|
||||
This program shows how to create, store and dereference references
|
||||
to the dataset regions.
|
||||
|
||||
It creates a file and writes a two dimensional integer dataset
|
||||
to it. Then it creates a dataset to store region references in. It
|
||||
stores references to a hyperslab and 3 points selected (for the
|
||||
integer dataset previously created).
|
||||
|
||||
It then reopens the references dataset, reads and dereferences the
|
||||
region references, and then reads and displays the selected hyperslab
|
||||
and selected elements data from the integer dataset.
|
||||
*/
|
||||
|
||||
#include "hdf5.h"
|
||||
|
||||
#define filename "REF_REG.h5"
|
||||
#define dsetnamev "MATRIX"
|
||||
#define dsetnamer "REGION_REFERENCES"
|
||||
|
||||
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;
|
||||
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];
|
||||
|
||||
/*
|
||||
* Create file with default file access and file creation properties.
|
||||
*/
|
||||
file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
||||
|
||||
/*
|
||||
* Create dataspace for datasets.
|
||||
*/
|
||||
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);
|
||||
|
||||
/*
|
||||
* Write data to the dataset.
|
||||
*/
|
||||
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);
|
||||
|
||||
/*
|
||||
* Create a reference to the hyperslab.
|
||||
*/
|
||||
start[0] = 0;
|
||||
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);
|
||||
|
||||
/*
|
||||
* Create a reference to elements selection.
|
||||
*/
|
||||
status = H5Sselect_none(space_id);
|
||||
status = H5Sselect_elements(space_id, H5S_SELECT_SET, num_points, (const hsize_t *)coord);
|
||||
status = H5Rcreate(&ref[1], file_id, dsetnamev, H5R_DATASET_REGION, space_id);
|
||||
|
||||
/*
|
||||
* Write dataset with the references.
|
||||
*/
|
||||
status = H5Dwrite(dsetr_id, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL, H5P_DEFAULT, ref);
|
||||
|
||||
/*
|
||||
* Close all objects.
|
||||
*/
|
||||
status = H5Sclose(space_id);
|
||||
status = H5Sclose(spacer_id);
|
||||
status = H5Dclose(dsetr_id);
|
||||
status = H5Fclose(file_id);
|
||||
|
||||
/*
|
||||
* Reopen the file to read selections back.
|
||||
*/
|
||||
file_id = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT);
|
||||
|
||||
/*
|
||||
* Reopen the dataset with object references and read references
|
||||
* to the buffer.
|
||||
*/
|
||||
dsetr_id = H5Dopen2(file_id, dsetnamer, H5P_DEFAULT);
|
||||
|
||||
status = H5Dread(dsetr_id, H5T_STD_REF_DSETREG, H5S_ALL, H5S_ALL, H5P_DEFAULT, ref_out);
|
||||
|
||||
/*
|
||||
* Dereference the first reference.
|
||||
*/
|
||||
dsetv_id = H5Rdereference2(dsetr_id, H5P_DEFAULT, H5R_DATASET_REGION, &ref_out[0]);
|
||||
/*
|
||||
* 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);
|
||||
/*
|
||||
* 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);
|
||||
|
||||
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);
|
||||
printf("Selected hyperslab: ");
|
||||
for (i = 0; i <= 1; i++) {
|
||||
printf("\n");
|
||||
for (j = 0; j <= 8; j++)
|
||||
printf("%d ", data_out[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
/*
|
||||
* Close dataspace and the dataset.
|
||||
*/
|
||||
status = H5Sclose(space_id);
|
||||
status = H5Dclose(dsetv_id);
|
||||
|
||||
/*
|
||||
* Initialize data_out array again to get point selection.
|
||||
*/
|
||||
for (i = 0; i <= 1; i++)
|
||||
for (j = 0; j <= 8; j++)
|
||||
data_out[i][j] = 0;
|
||||
|
||||
/*
|
||||
* 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]);
|
||||
|
||||
/*
|
||||
* Read selected data from the dataset.
|
||||
*/
|
||||
|
||||
status = H5Dread(dsetv_id, H5T_NATIVE_INT, H5S_ALL, space_id, H5P_DEFAULT, data_out);
|
||||
printf("Selected points: ");
|
||||
for (i = 0; i <= 1; i++) {
|
||||
printf("\n");
|
||||
for (j = 0; j <= 8; j++)
|
||||
printf("%d ", data_out[i][j]);
|
||||
}
|
||||
printf("\n");
|
||||
|
||||
/*
|
||||
* Close dataspace and the dataset.
|
||||
*/
|
||||
status = H5Sclose(space_id);
|
||||
status = H5Dclose(dsetv_id);
|
||||
status = H5Dclose(dsetr_id);
|
||||
status = H5Fclose(file_id);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
@@ -0,0 +1,355 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*
|
||||
* This program shows how the H5Sselect_hyperslab and H5Sselect_elements
|
||||
* functions are used to write selected data from memory to the file.
|
||||
* Program takes 48 elements from the linear buffer and writes them into
|
||||
* the matrix using 3x2 blocks, (4,3) stride and (2,4) count.
|
||||
* Then four elements of the matrix are overwritten with the new values and
|
||||
* file is closed. Program reopens the file and selects the union of two
|
||||
* hyperslabs in the dataset in the file. Then it reads the selection into the
|
||||
* memory dataset preserving the shape of the selection.
|
||||
*/
|
||||
|
||||
#include "hdf5.h"
|
||||
|
||||
#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 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
|
||||
|
||||
/* 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 */
|
||||
int
|
||||
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 */
|
||||
|
||||
hsize_t dim1[] = {MSPACE1_DIM}; /* Dimension size of the first dataset
|
||||
(in memory) */
|
||||
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);
|
||||
|
||||
/*
|
||||
* Create dataspace for the dataset in the file.
|
||||
*/
|
||||
fid = H5Screate_simple(FSPACE_RANK, fdim, NULL);
|
||||
|
||||
/*
|
||||
* Create dataset in the file. Notice that creation
|
||||
* property list plist is used.
|
||||
*/
|
||||
dataset = H5Dcreate2(file, "Matrix in file", H5T_NATIVE_INT, fid, H5P_DEFAULT, plist, H5P_DEFAULT);
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
/*
|
||||
* Create dataspace for the first dataset.
|
||||
*/
|
||||
mid1 = H5Screate_simple(MSPACE1_RANK, dim1, NULL);
|
||||
|
||||
/*
|
||||
* Select hyperslab.
|
||||
* We will use 48 elements of the vector buffer starting at the second element.
|
||||
* Selected elements are 1 2 3 . . . 48
|
||||
*/
|
||||
start[0] = 1;
|
||||
stride[0] = 1;
|
||||
count[0] = 48;
|
||||
block[0] = 1;
|
||||
ret = H5Sselect_hyperslab(mid1, H5S_SELECT_SET, start, stride, count, block);
|
||||
|
||||
/*
|
||||
* Write selection from the vector buffer to the dataset in the file.
|
||||
*
|
||||
* File dataset should look like this:
|
||||
* 0 1 2 0 3 4 0 5 6 0 7 8
|
||||
* 0 9 10 0 11 12 0 13 14 0 15 16
|
||||
* 0 17 18 0 19 20 0 21 22 0 23 24
|
||||
* 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
* 0 25 26 0 27 28 0 29 30 0 31 32
|
||||
* 0 33 34 0 35 36 0 37 38 0 39 40
|
||||
* 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);
|
||||
|
||||
/*
|
||||
* Reset the selection for the file dataspace fid.
|
||||
*/
|
||||
ret = H5Sselect_none(fid);
|
||||
|
||||
/*
|
||||
* Create dataspace for the second dataset.
|
||||
*/
|
||||
mid2 = H5Screate_simple(MSPACE2_RANK, dim2, NULL);
|
||||
|
||||
/*
|
||||
* 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;
|
||||
|
||||
ret = H5Sselect_elements(fid, H5S_SELECT_SET, NPOINTS, (const hsize_t *)coord);
|
||||
|
||||
/*
|
||||
* Write new selection of points to the dataset.
|
||||
*/
|
||||
ret = H5Dwrite(dataset, H5T_NATIVE_INT, mid2, fid, H5P_DEFAULT, values);
|
||||
|
||||
/*
|
||||
* File dataset should look like this:
|
||||
* 53 1 2 0 3 4 0 5 6 0 7 8
|
||||
* 0 9 10 0 11 12 0 13 14 0 15 16
|
||||
* 0 17 18 0 19 20 0 21 22 0 23 24
|
||||
* 0 0 0 59 0 61 0 0 0 0 0 0
|
||||
* 0 25 26 0 27 28 0 29 30 0 31 32
|
||||
* 0 33 34 0 35 36 67 37 38 0 39 40
|
||||
* 0 41 42 0 43 44 0 45 46 0 47 48
|
||||
* 0 0 0 0 0 0 0 0 0 0 0 0
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Close memory file and memory dataspaces.
|
||||
*/
|
||||
ret = H5Sclose(mid1);
|
||||
ret = H5Sclose(mid2);
|
||||
ret = H5Sclose(fid);
|
||||
|
||||
/*
|
||||
* Close dataset.
|
||||
*/
|
||||
ret = H5Dclose(dataset);
|
||||
|
||||
/*
|
||||
* Close the file.
|
||||
*/
|
||||
ret = H5Fclose(file);
|
||||
|
||||
/*
|
||||
* Open the file.
|
||||
*/
|
||||
file = H5Fopen(H5FILE_NAME, H5F_ACC_RDONLY, H5P_DEFAULT);
|
||||
|
||||
/*
|
||||
* Open the dataset.
|
||||
*/
|
||||
dataset = H5Dopen2(file, "Matrix in file", H5P_DEFAULT);
|
||||
|
||||
/*
|
||||
* Get dataspace of the open dataset.
|
||||
*/
|
||||
fid = H5Dget_space(dataset);
|
||||
|
||||
/*
|
||||
* Select first hyperslab for the dataset in the file. The following
|
||||
* elements are selected:
|
||||
* 10 0 11 12
|
||||
* 18 0 19 20
|
||||
* 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);
|
||||
|
||||
/*
|
||||
* Add second selected hyperslab to the selection.
|
||||
* The following elements are selected:
|
||||
* 19 20 0 21 22
|
||||
* 0 61 0 0 0
|
||||
* 27 28 0 29 30
|
||||
* 35 36 67 37 38
|
||||
* 43 44 0 45 46
|
||||
* 0 0 0 0 0
|
||||
* Note that two hyperslabs overlap. Common elements are:
|
||||
* 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);
|
||||
|
||||
/*
|
||||
* Create memory dataspace.
|
||||
*/
|
||||
mid = H5Screate_simple(MSPACE_RANK, mdim, NULL);
|
||||
|
||||
/*
|
||||
* 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);
|
||||
|
||||
/*
|
||||
* Initialize data buffer.
|
||||
*/
|
||||
for (i = 0; i < MSPACE_DIM1; i++) {
|
||||
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);
|
||||
|
||||
/*
|
||||
* Display the result. Memory dataset is:
|
||||
*
|
||||
* 10 0 11 12 0 0 0 0 0
|
||||
* 18 0 19 20 0 21 22 0 0
|
||||
* 0 59 0 61 0 0 0 0 0
|
||||
* 0 0 27 28 0 29 30 0 0
|
||||
* 0 0 35 36 67 37 38 0 0
|
||||
* 0 0 43 44 0 45 46 0 0
|
||||
* 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++)
|
||||
printf("%3d ", matrix_out[i][j]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
/*
|
||||
* Close memory file and memory dataspaces.
|
||||
*/
|
||||
ret = H5Sclose(mid);
|
||||
ret = H5Sclose(fid);
|
||||
|
||||
/*
|
||||
* Close dataset.
|
||||
*/
|
||||
ret = H5Dclose(dataset);
|
||||
|
||||
/*
|
||||
* Close property list
|
||||
*/
|
||||
ret = H5Pclose(plist);
|
||||
|
||||
/*
|
||||
* Close the file.
|
||||
*/
|
||||
ret = H5Fclose(file);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,341 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*
|
||||
* This program illustrates the usage of HDF5's implicit message sharing
|
||||
* feature, which can be used to save space when the same messages are
|
||||
* used many times in a file.
|
||||
*
|
||||
* This example creates a standard file using file creation property lists
|
||||
* to control which messages are shared. Messages that can be shared are
|
||||
* datatypes, dataspaces, attributes, fill values, and filter pipelines.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#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};
|
||||
|
||||
herr_t create_standard_file(const char *filename, hid_t fcpl);
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: main
|
||||
*
|
||||
* Purpose: Enables shared messages using File Creation Property Lists
|
||||
* and creates files using these settings.
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
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;
|
||||
|
||||
/* 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;
|
||||
|
||||
/* There are five kinds of messages that can be shared: datatypes,
|
||||
* dataspaces, attributes, fill values, and filter pipelines.
|
||||
* Shared messages are stored in up to five "indexes," where each
|
||||
* index can contain one or more types of message. Using more indexes
|
||||
* will result in more overhead for sharing, but can also provide
|
||||
* more "tunability" and may affect caching performance.
|
||||
*/
|
||||
/* To begin with, use only one index. */
|
||||
ret = H5Pset_shared_mesg_nindexes(fcpl_id, 1);
|
||||
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,
|
||||
* this is to prevent this overhead for very small messages when little
|
||||
* space would be saved by sharing them anyway.
|
||||
* If the content of the file isn't known beforehand, it's probably best
|
||||
* to set the minimum size "high"; over 100 or 200 bytes. If the content
|
||||
* of the file is known, this value can be used to trade space saved for
|
||||
* performance lost. The smaller this value is, the more messages will
|
||||
* be shared, so the more overhead will be incurred.
|
||||
* This value is in bytes. A shared message involves about 30 bytes of
|
||||
* overhead. Note that even messages that are only written once will
|
||||
* require this overhead (since they "might" be shared in the future),
|
||||
* so setting the minimum size too low may result in a file actually growing
|
||||
* in size.
|
||||
* For this example case, we'll set the minimum sharing size to be small
|
||||
* since we know that every message the "standard" file uses will be
|
||||
* repeated many times.
|
||||
*/
|
||||
/* The other property that each index has is the kinds of messages that
|
||||
* it holds. For the simple case, we'll put every message that could be
|
||||
* shared in this single index.
|
||||
*/
|
||||
ret = H5Pset_shared_mesg_index(fcpl_id, 0, H5O_SHMESG_ALL_FLAG, 40);
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
|
||||
/* The other property that can be set for shared messages is the
|
||||
* list/B-tree cutoff for the indexes.
|
||||
* Each shared message index beins life as a simple list of messages
|
||||
* and becomes a B-tree when "too many" messages are written to it.
|
||||
* 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 "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
|
||||
* the default values. The first value is the maximum list size, the
|
||||
* second the minimum B-tree size.
|
||||
*/
|
||||
ret = H5Pset_shared_mesg_phase_change(fcpl_id, 30, 20);
|
||||
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
|
||||
* completely transparent to the user. Even if the file is closed
|
||||
* and re-opened, this settings will be saved and applied to messages
|
||||
* written later.
|
||||
*/
|
||||
ret = create_standard_file("one_index_file.h5", fcpl_id);
|
||||
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.
|
||||
* For instance, if we set the index to only share very large
|
||||
* messages, none of the messages we write will qualify and the file
|
||||
* will be about the same size as a normal file (with just a little extra
|
||||
* overhead).
|
||||
*/
|
||||
ret = H5Pset_shared_mesg_index(fcpl_id, 0, H5O_SHMESG_ALL_FLAG, 1000);
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
|
||||
ret = create_standard_file("only_huge_mesgs_file.h5", fcpl_id);
|
||||
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;
|
||||
|
||||
ret = create_standard_file("only_dspaces_and_attrs_file.h5", fcpl_id);
|
||||
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;
|
||||
ret = H5Pset_shared_mesg_index(fcpl_id, 0, H5O_SHMESG_DTYPE_FLAG | H5O_SHMESG_SDSPACE_FLAG, 40);
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
ret = H5Pset_shared_mesg_index(fcpl_id, 1, H5O_SHMESG_ATTR_FLAG, 40);
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
|
||||
ret = create_standard_file("separate_indexes_file.h5", fcpl_id);
|
||||
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
|
||||
* datatypes, two dataspaces, and one attribute), using smaller lists will
|
||||
* save some space.
|
||||
*/
|
||||
ret = H5Pset_shared_mesg_nindexes(fcpl_id, 1);
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
ret = H5Pset_shared_mesg_index(fcpl_id, 0, H5O_SHMESG_ALL_FLAG, 40);
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
|
||||
ret = H5Pset_shared_mesg_phase_change(fcpl_id, 5, 0);
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
|
||||
ret = create_standard_file("small_lists_file.h5", fcpl_id);
|
||||
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;
|
||||
|
||||
ret = create_standard_file("btrees_file.h5", fcpl_id);
|
||||
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
|
||||
* depend a great deal on the specific application. If performance is
|
||||
* important, the best thing to do is to play with these settings to find
|
||||
* the ones that work best for you.
|
||||
* 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;
|
||||
return 0;
|
||||
|
||||
error:
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*-------------------------------------------------------------------------
|
||||
* Function: create_standard_file
|
||||
*
|
||||
* Purpose: A helper function for the example. Creates an HDF5 file
|
||||
* with many repeated messages using the file creation
|
||||
* property list FCPL.
|
||||
*
|
||||
* This function only uses datatypes, dataspaces, and
|
||||
* attributes. Fill values and filter pipelines can also
|
||||
* be shared in the same way (i.e., by enabling sharing in
|
||||
* the FCPL and writing the same message more than once).
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
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;
|
||||
|
||||
/* Create the file */
|
||||
file_id = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl_id, H5P_DEFAULT);
|
||||
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
|
||||
* disk, so this type will be an array type rather than an atomic type.
|
||||
* 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;
|
||||
ret = H5Tclose(temp_type_id);
|
||||
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;
|
||||
|
||||
/* 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;
|
||||
attr_space_id = H5Screate_simple(1, dims, dims);
|
||||
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;
|
||||
}
|
||||
|
||||
/* Close all open IDs */
|
||||
ret = H5Tclose(attr_type_id);
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
ret = H5Sclose(attr_space_id);
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
ret = H5Tclose(type_id);
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
ret = H5Sclose(space_id);
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
ret = H5Fclose(file_id);
|
||||
if (ret < 0)
|
||||
goto error;
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
return -1;
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
* 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. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*
|
||||
* 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 DIM0 8 /* size of dataset */
|
||||
#define DIM1 10
|
||||
|
||||
int
|
||||
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;
|
||||
|
||||
/*****************************************************************
|
||||
* 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);
|
||||
|
||||
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;
|
||||
else
|
||||
data[j][i] = 2;
|
||||
}
|
||||
|
||||
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");
|
||||
}
|
||||
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.
|
||||
*****************************************************/
|
||||
|
||||
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;
|
||||
|
||||
stride[0] = 1;
|
||||
stride[1] = 1;
|
||||
|
||||
block[0] = 1;
|
||||
block[1] = 1;
|
||||
|
||||
/* 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);
|
||||
|
||||
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
|
||||
entire dataset back from the file. */
|
||||
|
||||
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");
|
||||
}
|
||||
|
||||
status = H5Sclose(memspace_id);
|
||||
status = H5Sclose(dataspace_id);
|
||||
status = H5Dclose(dataset_id);
|
||||
status = H5Fclose(file_id);
|
||||
}
|
||||
@@ -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. *
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*
|
||||
* This example writes data to the HDF5 file.
|
||||
* Data conversion is performed during write operation.
|
||||
*/
|
||||
|
||||
#include "hdf5.h"
|
||||
|
||||
#define H5FILE_NAME "SDS.h5"
|
||||
#define DATASETNAME "IntArray"
|
||||
#define NX 5 /* dataset dimensions */
|
||||
#define NY 6
|
||||
#define RANK 2
|
||||
|
||||
int
|
||||
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;
|
||||
|
||||
/*
|
||||
* Data and output buffer initialization.
|
||||
*/
|
||||
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
|
||||
* 2 3 4 5 6 7
|
||||
* 3 4 5 6 7 8
|
||||
* 4 5 6 7 8 9
|
||||
*/
|
||||
|
||||
/*
|
||||
* Create a new file using H5F_ACC_TRUNC access,
|
||||
* default file creation properties, and default file
|
||||
* access properties.
|
||||
*/
|
||||
file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
||||
|
||||
/*
|
||||
* Describe the size of the array and create the data space for fixed
|
||||
* size dataset.
|
||||
*/
|
||||
dimsf[0] = NX;
|
||||
dimsf[1] = NY;
|
||||
dataspace = H5Screate_simple(RANK, dimsf, NULL);
|
||||
|
||||
/*
|
||||
* Define datatype for the data in the file.
|
||||
* We will store little endian INT numbers.
|
||||
*/
|
||||
datatype = H5Tcopy(H5T_NATIVE_INT);
|
||||
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);
|
||||
|
||||
/*
|
||||
* Write the data to the dataset using default transfer properties.
|
||||
*/
|
||||
status = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
|
||||
|
||||
/*
|
||||
* Close/release resources.
|
||||
*/
|
||||
H5Sclose(dataspace);
|
||||
H5Tclose(datatype);
|
||||
H5Dclose(dataset);
|
||||
H5Fclose(file);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Executable
+44
@@ -0,0 +1,44 @@
|
||||
#! /bin/sh
|
||||
#
|
||||
# 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.
|
||||
|
||||
#
|
||||
# This file: run-hl-ex.sh
|
||||
# Written by: Larry Knox
|
||||
# Date: May 11, 2010
|
||||
#
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# #
|
||||
# This script will run the scripts to compile and run the installed hdf5 #
|
||||
# examples. #
|
||||
# #
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
echo "Run c examples"
|
||||
if ((cd c; sh ./run-c-ex.sh) && \
|
||||
(if test -d fortran; then
|
||||
echo "Run fortran examples"
|
||||
cd fortran; sh ./run-fortran-ex.sh
|
||||
fi)
|
||||
(if test -d c++; then
|
||||
echo "Run c++ examples"
|
||||
cd c++; sh ./run-c++-ex.sh
|
||||
fi)
|
||||
(if test -d hl; then
|
||||
echo "Run hl examples."
|
||||
cd hl; sh ./run-hl-ex.sh
|
||||
fi)); then
|
||||
echo "Done"
|
||||
exit 0
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -0,0 +1,172 @@
|
||||
#! /bin/sh
|
||||
#
|
||||
# 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.
|
||||
|
||||
#
|
||||
# This file: run-c-ex.sh
|
||||
# Written by: Larry Knox
|
||||
# Date: May 11, 2010
|
||||
#
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
# #
|
||||
# This script will compile and run the c examples from source files installed #
|
||||
# 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. #
|
||||
# #
|
||||
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
|
||||
|
||||
# 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:-../${prefix_relto_examplesdir}}"
|
||||
PARALLEL=@PARALLEL@ # Am I in parallel mode?
|
||||
AR="@AR@"
|
||||
RANLIB="@RANLIB@"
|
||||
if [ "$PARALLEL" = no ]; then
|
||||
H5TOOL="h5cc" # The tool name
|
||||
else
|
||||
H5TOOL="h5pcc" # The tool name
|
||||
fi
|
||||
H5TOOL_BIN="${prefix}/bin/${H5TOOL}" # The path of the tool binary
|
||||
|
||||
#### Run test ####
|
||||
RunTest()
|
||||
{
|
||||
TEST_EXEC=$1
|
||||
Test=$1".c"
|
||||
|
||||
echo
|
||||
echo "################# $1 #################"
|
||||
${H5TOOL_BIN} -o $TEST_EXEC $Test
|
||||
if [ $? -ne 0 ]
|
||||
then
|
||||
echo "messed up compiling $Test"
|
||||
exit 1
|
||||
fi
|
||||
./$TEST_EXEC
|
||||
}
|
||||
|
||||
|
||||
|
||||
################## MAIN ##################
|
||||
|
||||
if ! test -d red; then
|
||||
mkdir red
|
||||
fi
|
||||
if ! test -d blue; then
|
||||
mkdir blue
|
||||
fi
|
||||
if ! test -d u2w; then
|
||||
mkdir u2w
|
||||
fi
|
||||
|
||||
# Run tests
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
if (RunTest h5_crtdat &&\
|
||||
rm h5_crtdat &&\
|
||||
RunTest h5_extend &&\
|
||||
rm h5_extend &&\
|
||||
RunTest h5_rdwt &&\
|
||||
rm h5_rdwt &&\
|
||||
RunTest h5_crtatt &&\
|
||||
rm h5_crtatt &&\
|
||||
RunTest h5_crtgrp &&\
|
||||
rm h5_crtgrp &&\
|
||||
RunTest h5_crtgrpar &&\
|
||||
rm h5_crtgrpar &&\
|
||||
RunTest h5_crtgrpd &&\
|
||||
rm h5_crtgrpd &&\
|
||||
RunTest h5_subset &&\
|
||||
rm h5_subset &&\
|
||||
RunTest h5_cmprss &&\
|
||||
rm h5_cmprss &&\
|
||||
RunTest h5_write &&\
|
||||
rm h5_write &&\
|
||||
RunTest h5_read &&\
|
||||
rm h5_read &&\
|
||||
RunTest h5_extend_write &&\
|
||||
rm h5_extend_write &&\
|
||||
RunTest h5_chunk_read &&\
|
||||
rm h5_chunk_read &&\
|
||||
RunTest h5_compound &&\
|
||||
rm h5_compound &&\
|
||||
RunTest h5_group &&\
|
||||
rm h5_group &&\
|
||||
RunTest h5_select &&\
|
||||
rm h5_select &&\
|
||||
RunTest h5_attribute &&\
|
||||
rm h5_attribute &&\
|
||||
RunTest h5_mount &&\
|
||||
rm h5_mount &&\
|
||||
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_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); then
|
||||
EXIT_VALUE=${EXIT_SUCCESS}
|
||||
else
|
||||
EXIT_VALUE=${EXIT_FAILURE}
|
||||
fi
|
||||
fi
|
||||
|
||||
# Cleanup
|
||||
rm *.o
|
||||
rm *.h5
|
||||
rm -rf red blue u2w
|
||||
echo
|
||||
|
||||
exit $EXIT_VALUE
|
||||
|
||||
@@ -0,0 +1,558 @@
|
||||
#! /bin/sh
|
||||
#
|
||||
# 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.
|
||||
#
|
||||
# Tests for the h5cc compiler tool
|
||||
|
||||
srcdir=@srcdir@
|
||||
|
||||
# Initializations
|
||||
TESTNAME=h5cc
|
||||
EXIT_SUCCESS=0
|
||||
EXIT_FAILURE=1
|
||||
|
||||
# Where the tool is installed.
|
||||
prefix="${prefix:-@prefix@}"
|
||||
PARALLEL=@PARALLEL@ # Am I in parallel mode?
|
||||
AR="@AR@"
|
||||
RANLIB="@RANLIB@"
|
||||
if [ "$PARALLEL" = no ]; then
|
||||
H5TOOL="h5cc" # The tool name
|
||||
else
|
||||
H5TOOL="h5pcc" # The tool name
|
||||
fi
|
||||
H5TOOL_BIN="${prefix}/bin/${H5TOOL}" # The path of the tool binary
|
||||
|
||||
CMP='cmp -s'
|
||||
DIFF='diff -c'
|
||||
|
||||
nerrors=$EXIT_SUCCESS
|
||||
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`
|
||||
H5_USE_116_API_DEFAULT=`grep '#define H5_USE_116_API_DEFAULT ' ../src/H5pubconf.h`
|
||||
|
||||
# setup my machine information.
|
||||
myos=`uname -s`
|
||||
myhostnama=`uname -n`
|
||||
|
||||
# Generate some source files and library for tests.
|
||||
suffix=c # source file suffix
|
||||
hdf5main=${H5TOOL}_hdf5main.$suffix
|
||||
hdf5main_o=${H5TOOL}_hdf5main.o
|
||||
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
|
||||
v114main=${H5TOOL}_v114main.$suffix
|
||||
v114main_o=${H5TOOL}_v114main.o
|
||||
appmain=${H5TOOL}_appmain.$suffix
|
||||
appmain_o=${H5TOOL}_appmain.o
|
||||
prog1=${H5TOOL}_prog1.$suffix
|
||||
prog1_o=${H5TOOL}_prog1.o
|
||||
prog2=${H5TOOL}_prog2.$suffix
|
||||
prog2_o=${H5TOOL}_prog2.o
|
||||
args=${H5TOOL}_args.$suffix
|
||||
args_o=${H5TOOL}_args.o
|
||||
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 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 $v110main $v112main $v114main $appmain $prog1 $prog2"
|
||||
temp_OBJ=`echo $temp_SRC | sed -e "s/\.${suffix}/.o/g"`
|
||||
temp_FILES="a.out $applib"
|
||||
|
||||
# Generate appmain:
|
||||
# An application Main that calls hdf5 and application's own functions.
|
||||
cat > $appmain <<EOF
|
||||
#include "hdf5.h"
|
||||
#define H5FILE_NAME "tmp.h5"
|
||||
extern void sub1(void);
|
||||
extern void sub2(void);
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
hid_t file; /* file and dataset handles */
|
||||
|
||||
/*
|
||||
* Create a new file using H5F_ACC_TRUNC access,
|
||||
* default file creation properties, and default file
|
||||
* access properties.
|
||||
*/
|
||||
sub1();
|
||||
sub2();
|
||||
file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
||||
H5Fclose(file);
|
||||
|
||||
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");
|
||||
}
|
||||
EOF
|
||||
|
||||
# generate prog2
|
||||
cat > $prog2 <<EOF
|
||||
#include <stdio.h>
|
||||
void
|
||||
sub2(void)
|
||||
{
|
||||
printf("in sub2\n");
|
||||
}
|
||||
EOF
|
||||
|
||||
# Generate HDF5 Main Program:
|
||||
# An HDF5 sample program that calls hdf5 functions.
|
||||
cat > $hdf5main <<EOF
|
||||
#include "hdf5.h"
|
||||
#define H5FILE_NAME "tmp.h5"
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
hid_t file; /* file and dataset handles */
|
||||
|
||||
/*
|
||||
* Create a new file using H5F_ACC_TRUNC access,
|
||||
* default file creation properties, and default file
|
||||
* access properties.
|
||||
*/
|
||||
file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
||||
H5Fclose(file);
|
||||
|
||||
printf("HDF5 C Sample program ran successfully. File %s generated.\n", H5FILE_NAME);
|
||||
remove(H5FILE_NAME);
|
||||
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
|
||||
# Generate HDF5 v1.6 Main Program:
|
||||
# This makes unique V1.6 API calls.
|
||||
cat > $v16main <<EOF
|
||||
/* This is a V1.6 API calls example Program. */
|
||||
#include "hdf5.h"
|
||||
#define H5FILE_NAME "tmp.h5"
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
hid_t file, group, group1; /* file and group handles */
|
||||
|
||||
file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
||||
group = H5Gcreate(file, "/Group", 0);
|
||||
group1 = H5Gcreate1(file, "/Group1.6", 0);
|
||||
H5Gclose(group1);
|
||||
H5Gclose(group);
|
||||
H5Fclose(file);
|
||||
|
||||
printf("HDF5 C program created with V1.6 API ran successfully. "
|
||||
"File %s generated.\n", H5FILE_NAME);
|
||||
remove(H5FILE_NAME);
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
|
||||
# Generate HDF5 v1.8 Main Program:
|
||||
# This makes unique V1.8 API calls.
|
||||
cat > $v18main <<EOF
|
||||
/* This is a V1.8 API calls example Program. */
|
||||
#include "hdf5.h"
|
||||
#define H5FILE_NAME "tmp.h5"
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
hid_t file, group, group2; /* 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);
|
||||
H5Gclose(group2);
|
||||
H5Gclose(group);
|
||||
H5Fclose(file);
|
||||
|
||||
printf("HDF5 C program created with V1.8 API ran successfully. "
|
||||
"File %s generated.\n", H5FILE_NAME);
|
||||
remove(H5FILE_NAME);
|
||||
return 0;
|
||||
}
|
||||
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
|
||||
|
||||
# Generate HDF5 v1.14 Main Program:
|
||||
# This makes unique V1.14 API calls.
|
||||
cat > $v114main <<EOF
|
||||
/* This is a V1.14 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.14 API ran successfully. ");
|
||||
/* "File %s generated.\n", H5FILE_NAME);
|
||||
remove(H5FILE_NAME); */
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
|
||||
# Generate args:
|
||||
# An application main that test misc command line arguments being passed.
|
||||
cat > $args <<EOF
|
||||
#include "hdf5.h"
|
||||
#define H5FILE_NAME "check_args.h5"
|
||||
int
|
||||
main (void)
|
||||
{
|
||||
char c = SGL_QUOTE; /* 'H' */
|
||||
char *s = DBL_QUOTE; /* "HDF" */
|
||||
int val = MISC; /* 42 */
|
||||
hid_t file; /* file and dataset handles */
|
||||
|
||||
file = H5Fcreate(H5FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
||||
H5Fclose(file);
|
||||
|
||||
printf("HDF5 C Sample program ran successfully. File %s generated.\n", H5FILE_NAME);
|
||||
remove(H5FILE_NAME);
|
||||
|
||||
return 0;
|
||||
}
|
||||
EOF
|
||||
|
||||
# Parse option
|
||||
# None
|
||||
|
||||
# Print a line-line message left justified in a field of 71 characters
|
||||
# beginning with the word "Testing".
|
||||
#
|
||||
TESTING() {
|
||||
SPACES=" "
|
||||
echo "Testing $* $SPACES" | cut -c1-71 | tr -d '\012'
|
||||
}
|
||||
|
||||
|
||||
# Debug printing
|
||||
# Change : to echo to print the debug statement
|
||||
DPRINT() {
|
||||
: $*
|
||||
}
|
||||
|
||||
# Run a test and print PASS or *FAIL*. If a test fails then increment
|
||||
# the `nerrors' global variable and (if $verbose is set) display the
|
||||
# failed output. The actual output is not removed if $HDF5_NOCLEANUP is
|
||||
# defined.
|
||||
#
|
||||
TOOLTEST() {
|
||||
out=test_$H5TOOL_$$.out
|
||||
err=test_$H5TOOL_$$.err
|
||||
|
||||
# Run test.
|
||||
TESTING $H5TOOL $@
|
||||
$H5TOOL_BIN $@ > $out 2>&1
|
||||
result=$?
|
||||
if [ $result = 0 ]; then
|
||||
echo " PASSED"
|
||||
test $verbose -gt 1 && \
|
||||
( echo "========== results ==========="; cat $out;
|
||||
echo "===============================================") |sed 's/^/ /'
|
||||
else
|
||||
echo "*FAILED*"
|
||||
nerrors="`expr $nerrors + 1`"
|
||||
test $verbose -gt 0 && \
|
||||
( echo "========== results ==========="; cat $out;
|
||||
echo "===============================================") |sed 's/^/ /'
|
||||
fi
|
||||
|
||||
# Clean up output file
|
||||
if test -z "$HDF5_NOCLEANUP"; then
|
||||
rm -f $out
|
||||
fi
|
||||
}
|
||||
|
||||
# Print a "SKIP" message
|
||||
SKIP() {
|
||||
TESTING $H5TOOL $@
|
||||
echo " -SKIP-"
|
||||
}
|
||||
|
||||
|
||||
##############################################################################
|
||||
### T H E T E S T S ###
|
||||
##############################################################################
|
||||
#
|
||||
# Group 1: HDF5 program that calls HDF5 APIs.
|
||||
echo "***"Simple Compile and Link in one step.
|
||||
TOOLTEST $hdf5main
|
||||
# Application program that calls HDF5 and its own functions.
|
||||
TOOLTEST $appmain $prog1 $prog2
|
||||
# Repeat with -shlib option
|
||||
echo "***"Simple Compile and Link with -shlib in one step.
|
||||
TOOLTEST -shlib $hdf5main
|
||||
# Application program that calls HDF5 and its own functions.
|
||||
TOOLTEST -shlib $appmain $prog1 $prog2
|
||||
|
||||
# Group 2: Compile, then link.
|
||||
echo "***"Compile and Link in two steps.
|
||||
TOOLTEST -c $hdf5main
|
||||
TOOLTEST $hdf5main_o
|
||||
TOOLTEST -c $appmain $prog1 $prog2
|
||||
TOOLTEST $appmain_o $prog1_o $prog2_o
|
||||
# Repeat with -shlib option
|
||||
echo "***"Compile and Link with -shlib in two steps.
|
||||
TOOLTEST -c $hdf5main
|
||||
TOOLTEST -shlib $hdf5main_o
|
||||
TOOLTEST -c $appmain $prog1 $prog2
|
||||
TOOLTEST -shlib $appmain_o $prog1_o $prog2_o
|
||||
|
||||
# Group3: Build external library, then link with it.
|
||||
echo "***"Build external library and link with it.
|
||||
TOOLTEST -c $prog1 $prog2
|
||||
$AR cru $applib $prog1_o $prog2_o
|
||||
$RANLIB $applib
|
||||
TOOLTEST $appmain $applib
|
||||
TOOLTEST $appmain_o $applib
|
||||
# Repeat with -shlib option
|
||||
echo "***"Build external library and link with it using -shlib.
|
||||
TOOLTEST -c $prog1 $prog2
|
||||
$AR cru $applib $prog1_o $prog2_o
|
||||
$RANLIB $applib
|
||||
TOOLTEST -shlib $appmain $applib
|
||||
TOOLTEST -shlib $appmain_o $applib
|
||||
|
||||
# Group 4: Just preprocess, no compile, no link.
|
||||
echo "***"Just preprocess, no compile, no link.
|
||||
TOOLTEST -E $hdf5main
|
||||
TOOLTEST -E $appmain $prog1 $prog2
|
||||
|
||||
# Group5: Version compatibility tests.
|
||||
echo "***"Version compatibility tests.
|
||||
# 20200610 Updated for versions 1.10 - 1.14.
|
||||
# If H5_NO_DEPRECATED_SYMBOLS;
|
||||
# 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.
|
||||
# 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."
|
||||
elif [ -n "$H5_USE_116_API_DEFAULT" ]; then
|
||||
echo "H5_USE_116_API_DEFAULT is defined."
|
||||
else
|
||||
echo "No H5 API_DEFAULT is defined."
|
||||
fi
|
||||
if [ -n "$H5_NO_DEPRECATED_SYMBOLS" ]; then
|
||||
echo "H5_NO_DEPRECATED_SYMBOLS is defined."
|
||||
else
|
||||
echo "H5_NO_DEPRECATED_SYMBOLS is not defined."
|
||||
fi
|
||||
if [ -n "$H5_NO_DEPRECATED_SYMBOLS" ]; then
|
||||
echo "Skipping $v16main test"
|
||||
TOOLTEST $v18main
|
||||
TOOLTEST $v18main
|
||||
TOOLTEST $v110main
|
||||
TOOLTEST $v112main
|
||||
TOOLTEST $v114main
|
||||
elif [ -n "$H5_USE_16_API_DEFAULT" ]; then
|
||||
echo "Testing HDF5 with 16_API_DEFAULT"
|
||||
TOOLTEST $v16main
|
||||
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
|
||||
elif [ -n "$H5_USE_114_API_DEFAULT" ]; then
|
||||
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 $v114main
|
||||
else
|
||||
echo "Testing HDF5 with 116_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 -DH5_USE_114_API_DEFAULT $v114main
|
||||
TOOLTEST $v18main
|
||||
TOOLTEST $v110main
|
||||
TOOLTEST $v112main
|
||||
TOOLTEST $v114main
|
||||
fi
|
||||
|
||||
# Group 6: # HDF5 program that depends on input args.
|
||||
echo "***"Simple Compile and Link in one step with user-supplied arguments.
|
||||
TOOLTEST -DSGL_QUOTE=\'H\' -DDBL_QUOTE=\"HDF\" -DMISC=42 $args
|
||||
|
||||
##############################################################################
|
||||
# END
|
||||
##############################################################################
|
||||
|
||||
# Clean up file
|
||||
if test -z "$HDF5_NOCLEANUP"; then
|
||||
rm -f $temp_SRC $temp_OBJ $temp_FILES
|
||||
fi
|
||||
|
||||
if test $nerrors -eq 0 ; then
|
||||
echo "All $TESTNAME tests passed."
|
||||
exit $EXIT_SUCCESS
|
||||
else
|
||||
echo "$TESTNAME tests failed with $nerrors errors."
|
||||
exit $EXIT_FAILURE
|
||||
fi
|
||||
Reference in New Issue
Block a user