[svn-r29226] HDFFV-9552: merge in java code.

This commit is contained in:
Allen Byrne
2016-02-28 21:43:00 -05:00
parent a1617b7cdb
commit 63249be0e1
290 changed files with 74248 additions and 46 deletions
+159 -6
View File
@@ -121,6 +121,9 @@ set (HDF5_F90_TEST_LIB_CORENAME "hdf5_test_fortran")
set (HDF5_F90_C_TEST_LIB_CORENAME "hdf5_test_f90cstub")
set (HDF5_HL_F90_LIB_CORENAME "hdf5_hl_fortran")
set (HDF5_HL_F90_C_LIB_CORENAME "hdf5_hl_f90cstub")
set (HDF5_JAVA_JNI_LIB_CORENAME "hdf5_java")
set (HDF5_JAVA_HDF5_LIB_CORENAME "jarhdf5")
set (HDF5_JAVA_TEST_LIB_CORENAME "jartest5")
#-----------------------------------------------------------------------------
# Set the true names of all the libraries if customized by external project
@@ -137,6 +140,9 @@ set (HDF5_F90_TEST_LIB_NAME "${HDF5_EXTERNAL_LIB_PREFIX}${HDF5_F90_TEST_LIB_
set (HDF5_F90_C_TEST_LIB_NAME "${HDF5_EXTERNAL_LIB_PREFIX}${HDF5_F90_C_TEST_LIB_CORENAME}")
set (HDF5_HL_F90_LIB_NAME "${HDF5_EXTERNAL_LIB_PREFIX}${HDF5_HL_F90_LIB_CORENAME}")
set (HDF5_HL_F90_C_LIB_NAME "${HDF5_EXTERNAL_LIB_PREFIX}${HDF5_HL_F90_C_LIB_CORENAME}")
set (HDF5_JAVA_JNI_LIB_NAME "${HDF5_EXTERNAL_LIB_PREFIX}${HDF5_JAVA_JNI_LIB_CORENAME}")
set (HDF5_JAVA_HDF5_LIB_NAME "${HDF5_EXTERNAL_LIB_PREFIX}${HDF5_JAVA_HDF5_LIB_CORENAME}")
set (HDF5_JAVA_TEST_LIB_NAME "${HDF5_EXTERNAL_LIB_PREFIX}${HDF5_JAVA_TEST_LIB_CORENAME}")
#-----------------------------------------------------------------------------
# Set the target names of all the libraries
@@ -153,6 +159,9 @@ set (HDF5_F90_TEST_LIB_TARGET "${HDF5_F90_TEST_LIB_CORENAME}-static")
set (HDF5_F90_C_TEST_LIB_TARGET "${HDF5_F90_C_TEST_LIB_CORENAME}-static")
set (HDF5_HL_F90_LIB_TARGET "${HDF5_HL_F90_LIB_CORENAME}-static")
set (HDF5_HL_F90_C_LIB_TARGET "${HDF5_HL_F90_C_LIB_CORENAME}-static")
set (HDF5_JAVA_JNI_LIB_TARGET "${HDF5_JAVA_JNI_LIB_CORENAME}")
set (HDF5_JAVA_HDF5_LIB_TARGET "${HDF5_JAVA_HDF5_LIB_CORENAME}")
set (HDF5_JAVA_TEST_LIB_TARGET "${HDF5_JAVA_TEST_LIB_CORENAME}")
set (HDF5_LIBSH_TARGET "${HDF5_LIB_CORENAME}-shared")
set (HDF5_TEST_LIBSH_TARGET "${HDF5_TEST_LIB_CORENAME}-shared")
set (HDF5_CPP_LIBSH_TARGET "${HDF5_CPP_LIB_CORENAME}-shared")
@@ -180,20 +189,37 @@ set (HDF5_HL_CPP_SRC_DIR ${HDF5_SOURCE_DIR}/hl/c++)
set (HDF5_TOOLS_SRC_DIR ${HDF5_SOURCE_DIR}/tools)
set (HDF5_PERFORM_SRC_DIR ${HDF5_SOURCE_DIR}/tools/perform)
set (HDF5_F90_SRC_DIR ${HDF5_SOURCE_DIR}/fortran)
set (HDF5_JAVA_JNI_SRC_DIR ${HDF5_SOURCE_DIR}/java/src/jni)
set (HDF5_JAVA_HDF5_SRC_DIR ${HDF5_SOURCE_DIR}/java/src/hdf)
set (HDF5_JAVA_TEST_SRC_DIR ${HDF5_SOURCE_DIR}/java/test)
set (HDF5_JAVA_LIB_DIR ${HDF5_SOURCE_DIR}/java/lib)
set (HDF5_JAVA_LOGGING_JAR ${HDF5_SOURCE_DIR}/java/lib/slf4j-api-1.7.5.jar)
set (HDF5_JAVA_LOGGING_NOP_JAR ${HDF5_SOURCE_DIR}/java/lib/ext/slf4j-nop-1.7.5.jar)
set (HDF5_JAVA_LOGGING_SIMPLE_JAR ${HDF5_SOURCE_DIR}/java/lib/ext/slf4j-simple-1.7.5.jar)
if (APPLE)
option (HDF5_BUILD_FRAMEWORKS "TRUE to build as frameworks libraries, FALSE to build according to BUILD_SHARED_LIBS" FALSE)
endif (APPLE)
if (NOT HDF5_INSTALL_BIN_DIR)
set (HDF5_INSTALL_BIN_DIR bin)
endif (NOT HDF5_INSTALL_BIN_DIR)
if (NOT HDF5_INSTALL_LIB_DIR)
if (APPLE)
if (HDF5_BUILD_FRAMEWORKS)
set (HDF5_INSTALL_JAR_DIR ../Java)
else (HDF5_BUILD_FRAMEWORKS)
set (HDF5_INSTALL_JAR_DIR lib)
endif (HDF5_BUILD_FRAMEWORKS)
set (HDF5_INSTALL_FMWK_DIR ${CMAKE_INSTALL_FRAMEWORK_PREFIX})
else (APPLE)
set (HDF5_INSTALL_JAR_DIR lib)
endif (APPLE)
set (HDF5_INSTALL_LIB_DIR lib)
endif (NOT HDF5_INSTALL_LIB_DIR)
if (NOT HDF5_INSTALL_INCLUDE_DIR)
set (HDF5_INSTALL_INCLUDE_DIR include)
endif (NOT HDF5_INSTALL_INCLUDE_DIR)
option (HDF5_BUILD_FRAMEWORKS "TRUE to build as frameworks libraries, FALSE to build according to BUILD_SHARED_LIBS" FALSE)
if (NOT HDF5_INSTALL_DATA_DIR)
if (NOT WIN32)
if (APPLE)
@@ -242,6 +268,83 @@ string (REGEX REPLACE ".*LT_VERS_AGE[ \t]+=[ \t]+([0-9]*).*$"
"\\1" H5_SOVERS_RELEASE ${_lt_vers_am_contents})
MATH (EXPR H5_SOVERS_MAJOR ${H5_SOVERS_INTERFACE}-${H5_SOVERS_RELEASE})
message (STATUS "SOVERSION: ${H5_SOVERS_MAJOR}.${H5_SOVERS_RELEASE}.${H5_SOVERS_MINOR}")
string (REGEX MATCH ".*LT_TOOLS_VERS_INTERFACE[ \t]+=[ \t]+([0-9]*).*$" H5_TOOLS_SOVERS_EXISTS ${_lt_vers_am_contents})
if(H5_TOOLS_SOVERS_EXISTS)
string (REGEX REPLACE ".*LT_TOOLS_VERS_INTERFACE[ \t]+=[ \t]+([0-9]*).*$"
"\\1" H5_TOOLS_SOVERS_INTERFACE ${_lt_vers_am_contents})
string (REGEX REPLACE ".*LT_TOOLS_VERS_REVISION[ \t]+=[ \t]+([0-9]*).*$"
"\\1" H5_TOOLS_SOVERS_MINOR ${_lt_vers_am_contents})
string (REGEX REPLACE ".*LT_TOOLS_VERS_AGE[ \t]+=[ \t]+([0-9]*).*$"
"\\1" H5_TOOLS_SOVERS_RELEASE ${_lt_vers_am_contents})
MATH (EXPR H5_TOOLS_SOVERS_MAJOR ${H5_TOOLS_SOVERS_INTERFACE}-${H5_TOOLS_SOVERS_RELEASE})
message (STATUS "SOVERSION_TOOLS: ${H5_TOOLS_SOVERS_MAJOR}.${H5_TOOLS_SOVERS_RELEASE}.${H5_TOOLS_SOVERS_MINOR}")
endif()
string (REGEX REPLACE ".*LT_CXX_VERS_INTERFACE[ \t]+=[ \t]+([0-9]*).*$" H5_CXX_SOVERS_EXISTS ${_lt_vers_am_contents})
if(H5_CXX_SOVERS_EXISTS)
string (REGEX REPLACE ".*LT_CXX_VERS_INTERFACE[ \t]+=[ \t]+([0-9]*).*$"
"\\1" H5_CXX_SOVERS_INTERFACE ${_lt_vers_am_contents})
string (REGEX REPLACE ".*LT_CXX_VERS_REVISION[ \t]+=[ \t]+([0-9]*).*$"
"\\1" H5_CXX_SOVERS_MINOR ${_lt_vers_am_contents})
string (REGEX REPLACE ".*LT_CXX_VERS_AGE[ \t]+=[ \t]+([0-9]*).*$"
"\\1" H5_CXX_SOVERS_RELEASE ${_lt_vers_am_contents})
MATH (EXPR H5_CXX_SOVERS_MAJOR ${H5_CXX_SOVERS_INTERFACE}-${H5_CXX_SOVERS_RELEASE})
message (STATUS "SOVERSION_CXX: ${H5_CXX_SOVERS_MAJOR}.${H5_CXX_SOVERS_RELEASE}.${H5_CXX_SOVERS_MINOR}")
endif()
string (REGEX REPLACE ".*LT_F_VERS_INTERFACE[ \t]+=[ \t]+([0-9]*).*$" H5_F_SOVERS_EXISTS ${_lt_vers_am_contents})
if(H5_F_SOVERS_EXISTS)
string (REGEX REPLACE ".*LT_F_VERS_INTERFACE[ \t]+=[ \t]+([0-9]*).*$"
"\\1" H5_F_SOVERS_INTERFACE ${_lt_vers_am_contents})
string (REGEX REPLACE ".*LT_F_VERS_REVISION[ \t]+=[ \t]+([0-9]*).*$"
"\\1" H5_F_SOVERS_MINOR ${_lt_vers_am_contents})
string (REGEX REPLACE ".*LT_F_VERS_AGE[ \t]+=[ \t]+([0-9]*).*$"
"\\1" H5_F_SOVERS_RELEASE ${_lt_vers_am_contents})
MATH (EXPR H5_F_SOVERS_MAJOR ${H5_F_SOVERS_INTERFACE}-${H5_F_SOVERS_RELEASE})
message (STATUS "SOVERSION_F: ${H5_F_SOVERS_MAJOR}.${H5_F_SOVERS_RELEASE}.${H5_F_SOVERS_MINOR}")
endif()
string (REGEX REPLACE ".*LT_HL_VERS_INTERFACE[ \t]+=[ \t]+([0-9]*).*$" H5_HL_SOVERS_EXISTS ${_lt_vers_am_contents})
if(H5_HL_SOVERS_EXISTS)
string (REGEX REPLACE ".*LT_HL_VERS_INTERFACE[ \t]+=[ \t]+([0-9]*).*$"
"\\1" H5_HL_SOVERS_INTERFACE ${_lt_vers_am_contents})
string (REGEX REPLACE ".*LT_HL_VERS_REVISION[ \t]+=[ \t]+([0-9]*).*$"
"\\1" H5_HL_SOVERS_MINOR ${_lt_vers_am_contents})
string (REGEX REPLACE ".*LT_HL_VERS_AGE[ \t]+=[ \t]+([0-9]*).*$"
"\\1" H5_HL_SOVERS_RELEASE ${_lt_vers_am_contents})
MATH (EXPR H5_HL_SOVERS_MAJOR ${H5_HL_SOVERS_INTERFACE}-${H5_HL_SOVERS_RELEASE})
message (STATUS "SOVERSION_HL: ${H5_HL_SOVERS_MAJOR}.${H5_HL_SOVERS_RELEASE}.${H5_HL_SOVERS_MINOR}")
endif()
string (REGEX REPLACE ".*LT_HL_CXX_VERS_INTERFACE[ \t]+=[ \t]+([0-9]*).*$" H5_HL_CXX_SOVERS_EXISTS ${_lt_vers_am_contents})
if(H5_HL_CXX_SOVERS_EXISTS)
string (REGEX REPLACE ".*LT_HL_CXX_VERS_INTERFACE[ \t]+=[ \t]+([0-9]*).*$"
"\\1" H5_HL_CXX_SOVERS_INTERFACE ${_lt_vers_am_contents})
string (REGEX REPLACE ".*LT_HL_CXX_VERS_REVISION[ \t]+=[ \t]+([0-9]*).*$"
"\\1" H5_HL_CXX_SOVERS_MINOR ${_lt_vers_am_contents})
string (REGEX REPLACE ".*LT_HL_CXX_VERS_AGE[ \t]+=[ \t]+([0-9]*).*$"
"\\1" H5_HL_CXX_SOVERS_RELEASE ${_lt_vers_am_contents})
MATH (EXPR H5_HL_CXX_SOVERS_MAJOR ${H5_HL_CXX_SOVERS_INTERFACE}-${H5_HL_CXX_SOVERS_RELEASE})
message (STATUS "SOVERSION_HL_CXX: ${H5_HL_CXX_SOVERS_MAJOR}.${H5_HL_CXX_SOVERS_RELEASE}.${H5_HL_CXX_SOVERS_MINOR}")
endif()
string (REGEX REPLACE ".*LT_HL_F_VERS_INTERFACE[ \t]+=[ \t]+([0-9]*).*$" H5_HL_F_SOVERS_EXISTS ${_lt_vers_am_contents})
if(H5_HL_F_SOVERS_EXISTS)
string (REGEX REPLACE ".*LT_HL_F_VERS_INTERFACE[ \t]+=[ \t]+([0-9]*).*$"
"\\1" H5_HL_F_SOVERS_INTERFACE ${_lt_vers_am_contents})
string (REGEX REPLACE ".*LT_HL_F_VERS_REVISION[ \t]+=[ \t]+([0-9]*).*$"
"\\1" H5_HL_F_SOVERS_MINOR ${_lt_vers_am_contents})
string (REGEX REPLACE ".*LT_HL_F_VERS_AGE[ \t]+=[ \t]+([0-9]*).*$"
"\\1" H5_HL_F_SOVERS_RELEASE ${_lt_vers_am_contents})
MATH (EXPR H5_HL_F_SOVERS_MAJOR ${H5_HL_F_SOVERS_INTERFACE}-${H5_HL_F_SOVERS_RELEASE})
message (STATUS "SOVERSION_HL_F: ${H5_HL_F_SOVERS_MAJOR}.${H5_HL_F_SOVERS_RELEASE}.${H5_HL_F_SOVERS_MINOR}")
endif()
string (REGEX REPLACE ".*LT_JAVA_VERS_INTERFACE[ \t]+=[ \t]+([0-9]*).*$" H5_JAVA_SOVERS_EXISTS ${_lt_vers_am_contents})
if(H5_JAVA_SOVERS_EXISTS)
string (REGEX REPLACE ".*LT_JAVA_VERS_INTERFACE[ \t]+=[ \t]+([0-9]*).*$"
"\\1" H5_JAVA_SOVERS_INTERFACE ${_lt_vers_am_contents})
string (REGEX REPLACE ".*LT_JAVA_VERS_REVISION[ \t]+=[ \t]+([0-9]*).*$"
"\\1" H5_JAVA_SOVERS_MINOR ${_lt_vers_am_contents})
string (REGEX REPLACE ".*LT_JAVA_VERS_AGE[ \t]+=[ \t]+([0-9]*).*$"
"\\1" H5_JAVA_SOVERS_RELEASE ${_lt_vers_am_contents})
MATH (EXPR H5_JAVA_SOVERS_MAJOR ${H5_JAVA_SOVERS_INTERFACE}-${H5_JAVA_SOVERS_RELEASE})
message (STATUS "SOVERSION_JAVA: ${H5_JAVA_SOVERS_MAJOR}.${H5_JAVA_SOVERS_RELEASE}.${H5_JAVA_SOVERS_MINOR}")
endif()
#-----------------------------------------------------------------------------
# Basic HDF5 stuff here
@@ -257,6 +360,41 @@ else (NOT "${H5_VERS_SUBRELEASE}" STREQUAL "")
set (HDF5_PACKAGE_VERSION_STRING "${HDF5_PACKAGE_VERSION}")
endif (NOT "${H5_VERS_SUBRELEASE}" STREQUAL "")
set (HDF5_PACKAGE_SOVERSION "${H5_SOVERS_MAJOR}.${H5_SOVERS_RELEASE}.${H5_SOVERS_MINOR}")
if(H5_TOOLS_SOVERS_EXISTS)
set (HDF5_TOOLS_PACKAGE_SOVERSION "${H5_TOOLS_SOVERS_MAJOR}.${H5_TOOLS_SOVERS_RELEASE}.${H5_TOOLS_SOVERS_MINOR}")
else()
set (HDF5_TOOLS_PACKAGE_SOVERSION "${H5_SOVERS_MAJOR}.${H5_SOVERS_RELEASE}.${H5_SOVERS_MINOR}")
endif()
if(H5_CXX_SOVERS_EXISTS)
set (HDF5_CXX_PACKAGE_SOVERSION "${H5_CXX_SOVERS_MAJOR}.${H5_CXX_SOVERS_RELEASE}.${H5_CXX_SOVERS_MINOR}")
else()
set (HDF5_CXX_PACKAGE_SOVERSION "${H5_SOVERS_MAJOR}.${H5_SOVERS_RELEASE}.${H5_SOVERS_MINOR}")
endif()
if(H5_F_SOVERS_EXISTS)
set (HDF5_F_PACKAGE_SOVERSION "${H5_F_SOVERS_MAJOR}.${H5_F_SOVERS_RELEASE}.${H5_F_SOVERS_MINOR}")
else()
set (HDF5_F_PACKAGE_SOVERSION "${H5_SOVERS_MAJOR}.${H5_SOVERS_RELEASE}.${H5_SOVERS_MINOR}")
endif()
if(H5_HL_SOVERS_EXISTS)
set (HDF5_HL_PACKAGE_SOVERSION "${H5_HL_SOVERS_MAJOR}.${H5_HL_SOVERS_RELEASE}.${H5_HL_SOVERS_MINOR}")
else()
set (HDF5_HL_PACKAGE_SOVERSION "${H5_SOVERS_MAJOR}.${H5_SOVERS_RELEASE}.${H5_SOVERS_MINOR}")
endif()
if(H5_HL_F_SOVERS_EXISTS)
set (HDF5_HL_CXX_PACKAGE_SOVERSION "${H5_HL_CXX_SOVERS_MAJOR}.${H5_HL_CXX_SOVERS_RELEASE}.${H5_HL_CXX_SOVERS_MINOR}")
else()
set (HDF5_HL_CXX_PACKAGE_SOVERSION "${H5_SOVERS_MAJOR}.${H5_SOVERS_RELEASE}.${H5_SOVERS_MINOR}")
endif()
if(H5_HL_F_SOVERS_EXISTS)
set (HDF5_HL_F_PACKAGE_SOVERSION "${H5_HL_F_SOVERS_MAJOR}.${H5_HL_F_SOVERS_RELEASE}.${H5_HL_F_SOVERS_MINOR}")
else()
set (HDF5_HL_F_PACKAGE_SOVERSION "${H5_SOVERS_MAJOR}.${H5_SOVERS_RELEASE}.${H5_SOVERS_MINOR}")
endif()
if(H5_JAVA_SOVERS_EXISTS)
set (HDF5_PACKAGE_SOVERSION "${H5_JAVA_SOVERS_MAJOR}.${H5_JAVA_SOVERS_RELEASE}.${H5_JAVA_SOVERS_MINOR}")
else()
set (HDF5_JAVA_PACKAGE_SOVERSION "${H5_SOVERS_MAJOR}.${H5_SOVERS_RELEASE}.${H5_SOVERS_MINOR}")
endif()
set (HDF5_PACKAGE_STRING "${HDF5_PACKAGE_NAME} ${HDF5_PACKAGE_VERSION_STRING}")
set (HDF5_PACKAGE_TARNAME "${HDF5_PACKAGE}${HDF_PACKAGE_EXT}")
set (HDF5_PACKAGE_URL "http://www.hdfgroup.org")
@@ -285,6 +423,11 @@ if (NOT HDF5_EXTERNALLY_CONFIGURED)
set (CMAKE_Fortran_MODULE_DIRECTORY
${PROJECT_BINARY_DIR}/bin CACHE PATH "Single Directory for all fortran modules."
)
if (WIN32)
set (CMAKE_TEST_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${CMAKE_BUILD_TYPE})
else (WIN32)
set (CMAKE_TEST_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
endif (WIN32)
else (NOT HDF5_EXTERNALLY_CONFIGURED)
# if we are externally configured, but the project uses old cmake scripts
# this may not be set and utilities like H5detect will fail
@@ -773,11 +916,21 @@ endif (EXISTS "${HDF5_SOURCE_DIR}/c++" AND IS_DIRECTORY "${HDF5_SOURCE_DIR}/c++"
# Check if Fortran's default real is double precision. If it is and HL is
# being built then configure should fail due to bug HDFFV-889.
#-----------------------------------------------------------------------------
if (HDF5_BUILD_FORTRAN AND HDF5_BUILD_HL_LIB )
if (NOT FORTRAN_DEFAULT_REAL_NOT_DOUBLE)
message (FATAL_ERROR " **** Fortran high-level routines are not supported when the default REAL is DOUBLE PRECISION, use HDF5_BUILD_HL_LIB:BOOL=OFF **** ")
endif (NOT FORTRAN_DEFAULT_REAL_NOT_DOUBLE)
endif (HDF5_BUILD_FORTRAN AND HDF5_BUILD_HL_LIB )
if (HDF5_BUILD_FORTRAN AND HDF5_BUILD_HL_LIB)
if (NOT FORTRAN_DEFAULT_REAL_NOT_DOUBLE)
message (FATAL_ERROR " **** Fortran high-level routines are not supported when the default REAL is DOUBLE PRECISION, use HDF5_BUILD_HL_LIB:BOOL=OFF **** ")
endif (NOT FORTRAN_DEFAULT_REAL_NOT_DOUBLE)
endif (HDF5_BUILD_FORTRAN AND HDF5_BUILD_HL_LIB)
#-----------------------------------------------------------------------------
# Option to build HDF5 Java Library
#-----------------------------------------------------------------------------
if (EXISTS "${HDF5_SOURCE_DIR}/java" AND IS_DIRECTORY "${HDF5_SOURCE_DIR}/java")
option (HDF5_BUILD_JAVA "Build Java HDF5 Library" ON)
if (HDF5_BUILD_JAVA)
add_subdirectory (${HDF5_SOURCE_DIR}/java ${PROJECT_BINARY_DIR}/java)
endif (HDF5_BUILD_JAVA)
endif (EXISTS "${HDF5_SOURCE_DIR}/java" AND IS_DIRECTORY "${HDF5_SOURCE_DIR}/java")
#-----------------------------------------------------------------------------
# Generate the H5pubconf.h file containing user settings needed by compilation
+318 -2
View File
@@ -27,14 +27,33 @@
./MANIFEST
./Makefile.dist
./Makefile.am
./m4/aclocal_fc.m4
./m4/aclocal_cxx.m4
./README.txt
./BRANCH.txt
./acsite.m4
./autogen.sh
./configure.ac
./m4/aclocal_cxx.m4
./m4/aclocal_fc.m4
./m4/ax_check_class.m4
./m4/ax_check_classpath.m4
./m4/ax_check_java_home.m4
./m4/ax_check_junit.m4
./m4/ax_check_rqrd_class.m4
./m4/ax_java_check_class.m4
./m4/ax_java_options.m4
./m4/ax_jni_include_dir.m4
./m4/ax_prog_jar.m4
./m4/ax_prog_java_cc.m4
./m4/ax_prog_java_works.m4
./m4/ax_prog_java.m4
./m4/ax_prog_javac_works.m4
./m4/ax_prog_javac.m4
./m4/ax_prog_javadoc.m4
./m4/ax_prog_javah.m4
./m4/ax_try_compile_java.m4
./m4/ax_try_run_java.m4
./bin/COPYING
./bin/bbrelease _DO_NOT_DISTRIBUTE_
./bin/buildhdf5
@@ -2416,13 +2435,306 @@
./hl/c++/test/ptableTest.cpp
./hl/c++/test/Makefile.am
# java
./java/COPYING
./java/Makefile.am
./java/CMakeLists.txt
./java/src/Makefile.am
./java/src/CMakeLists.txt
./java/src/jni/Makefile.am
./java/src/jni/CMakeLists.txt
./java/src/jni/exceptionImp.c
./java/src/jni/exceptionImp.h
./java/src/jni/h5Constants.c
./java/src/jni/nativeData.c
./java/src/jni/nativeData.h
./java/src/jni/h5jni.h
./java/src/jni/h5util.c
./java/src/jni/h5util.h
./java/src/jni/h5Imp.c
./java/src/jni/h5Imp.h
./java/src/jni/h5aImp.c
./java/src/jni/h5aImp.h
./java/src/jni/h5dImp.c
./java/src/jni/h5dImp.h
./java/src/jni/h5eImp.c
./java/src/jni/h5eImp.h
./java/src/jni/h5fImp.c
./java/src/jni/h5fImp.h
./java/src/jni/h5gImp.c
./java/src/jni/h5gImp.h
./java/src/jni/h5iImp.c
./java/src/jni/h5iImp.h
./java/src/jni/h5lImp.c
./java/src/jni/h5lImp.h
./java/src/jni/h5oImp.c
./java/src/jni/h5oImp.h
./java/src/jni/h5pImp.c
./java/src/jni/h5pImp.h
./java/src/jni/h5plImp.c
./java/src/jni/h5plImp.h
./java/src/jni/h5rImp.c
./java/src/jni/h5rImp.h
./java/src/jni/h5sImp.c
./java/src/jni/h5sImp.h
./java/src/jni/h5tImp.c
./java/src/jni/h5tImp.h
./java/src/jni/h5zImp.c
./java/src/jni/h5zImp.h
./java/src/hdf/CMakeLists.txt
./java/src/hdf/hdf5lib/CMakeLists.txt
./java/src/hdf/hdf5lib/callbacks/Callbacks.java
./java/src/hdf/hdf5lib/callbacks/H5A_iterate_cb.java
./java/src/hdf/hdf5lib/callbacks/H5A_iterate_t.java
./java/src/hdf/hdf5lib/callbacks/H5D_iterate_cb.java
./java/src/hdf/hdf5lib/callbacks/H5D_iterate_t.java
./java/src/hdf/hdf5lib/callbacks/H5E_walk_cb.java
./java/src/hdf/hdf5lib/callbacks/H5E_walk_t.java
./java/src/hdf/hdf5lib/callbacks/H5L_iterate_cb.java
./java/src/hdf/hdf5lib/callbacks/H5L_iterate_t.java
./java/src/hdf/hdf5lib/callbacks/H5O_iterate_cb.java
./java/src/hdf/hdf5lib/callbacks/H5O_iterate_t.java
./java/src/hdf/hdf5lib/callbacks/H5P_cls_close_func_cb.java
./java/src/hdf/hdf5lib/callbacks/H5P_cls_close_func_t.java
./java/src/hdf/hdf5lib/callbacks/H5P_cls_copy_func_cb.java
./java/src/hdf/hdf5lib/callbacks/H5P_cls_copy_func_t.java
./java/src/hdf/hdf5lib/callbacks/H5P_cls_create_func_cb.java
./java/src/hdf/hdf5lib/callbacks/H5P_cls_create_func_t.java
./java/src/hdf/hdf5lib/callbacks/H5P_prp_close_func_cb.java
./java/src/hdf/hdf5lib/callbacks/H5P_prp_compare_func_cb.java
./java/src/hdf/hdf5lib/callbacks/H5P_prp_copy_func_cb.java
./java/src/hdf/hdf5lib/callbacks/H5P_prp_create_func_cb.java
./java/src/hdf/hdf5lib/callbacks/H5P_prp_delete_func_cb.java
./java/src/hdf/hdf5lib/callbacks/H5P_prp_get_func_cb.java
./java/src/hdf/hdf5lib/callbacks/H5P_prp_set_func_cb.java
./java/src/hdf/hdf5lib/callbacks/H5P_iterate_cb.java
./java/src/hdf/hdf5lib/callbacks/H5P_iterate_t.java
./java/src/hdf/hdf5lib/exceptions/HDF5AtomException.java
./java/src/hdf/hdf5lib/exceptions/HDF5AttributeException.java
./java/src/hdf/hdf5lib/exceptions/HDF5BtreeException.java
./java/src/hdf/hdf5lib/exceptions/HDF5DataFiltersException.java
./java/src/hdf/hdf5lib/exceptions/HDF5DataStorageException.java
./java/src/hdf/hdf5lib/exceptions/HDF5DatasetInterfaceException.java
./java/src/hdf/hdf5lib/exceptions/HDF5DataspaceInterfaceException.java
./java/src/hdf/hdf5lib/exceptions/HDF5DatatypeInterfaceException.java
./java/src/hdf/hdf5lib/exceptions/HDF5Exception.java
./java/src/hdf/hdf5lib/exceptions/HDF5ExternalFileListException.java
./java/src/hdf/hdf5lib/exceptions/HDF5FileInterfaceException.java
./java/src/hdf/hdf5lib/exceptions/HDF5FunctionArgumentException.java
./java/src/hdf/hdf5lib/exceptions/HDF5FunctionEntryExitException.java
./java/src/hdf/hdf5lib/exceptions/HDF5HeapException.java
./java/src/hdf/hdf5lib/exceptions/HDF5InternalErrorException.java
./java/src/hdf/hdf5lib/exceptions/HDF5JavaException.java
./java/src/hdf/hdf5lib/exceptions/HDF5LibraryException.java
./java/src/hdf/hdf5lib/exceptions/HDF5LowLevelIOException.java
./java/src/hdf/hdf5lib/exceptions/HDF5MetaDataCacheException.java
./java/src/hdf/hdf5lib/exceptions/HDF5ObjectHeaderException.java
./java/src/hdf/hdf5lib/exceptions/HDF5PropertyListInterfaceException.java
./java/src/hdf/hdf5lib/exceptions/HDF5ReferenceException.java
./java/src/hdf/hdf5lib/exceptions/HDF5ResourceUnavailableException.java
./java/src/hdf/hdf5lib/exceptions/HDF5SymbolTableException.java
./java/src/hdf/hdf5lib/structs/H5_ih_info_t.java
./java/src/hdf/hdf5lib/structs/H5A_info_t.java
./java/src/hdf/hdf5lib/structs/H5AC_cache_config_t.java
./java/src/hdf/hdf5lib/structs/H5E_error2_t.java
./java/src/hdf/hdf5lib/structs/H5F_info2_t.java
./java/src/hdf/hdf5lib/structs/H5G_info_t.java
./java/src/hdf/hdf5lib/structs/H5L_info_t.java
./java/src/hdf/hdf5lib/structs/H5O_hdr_info_t.java
./java/src/hdf/hdf5lib/structs/H5O_info_t.java
./java/src/hdf/hdf5lib/H5.java
./java/src/hdf/hdf5lib/HDF5Constants.java
./java/src/hdf/hdf5lib/HDF5GroupInfo.java
./java/src/hdf/hdf5lib/HDFArray.java
./java/src/hdf/hdf5lib/HDFNativeData.java
./java/examples/Makefile.am
./java/examples/CMakeLists.txt
./java/examples/intro/Makefile.am
./java/examples/intro/CMakeLists.txt
./java/examples/intro/runExample.sh.in
./java/examples/intro/H5_CreateAttribute.java
./java/examples/intro/H5_CreateDataset.java
./java/examples/intro/H5_CreateFile.java
./java/examples/intro/H5_CreateGroup.java
./java/examples/intro/H5_CreateGroupAbsoluteRelative.java
./java/examples/intro/H5_CreateGroupDataset.java
./java/examples/intro/H5_ReadWrite.java
./java/examples/groups/Makefile.am
./java/examples/groups/CMakeLists.txt
./java/examples/groups/runExample.sh.in
./java/examples/groups/H5Ex_G_Create.java
./java/examples/groups/H5Ex_G_Iterate.java
./java/examples/groups/H5Ex_G_Compact.java
./java/examples/groups/H5Ex_G_Corder.java
./java/examples/groups/H5Ex_G_Intermediate.java
./java/examples/groups/H5Ex_G_Phase.java
./java/examples/groups/H5Ex_G_Traverse.java
./java/examples/groups/H5Ex_G_Visit.java
./java/examples/groups/h5ex_g_iterate.h5
./java/examples/groups/h5ex_g_visit.h5
./java/examples/datasets/Makefile.am
./java/examples/datasets/CMakeLists.txt
./java/examples/datasets/runExample.sh.in
./java/examples/datasets/H5Ex_D_Alloc.java
./java/examples/datasets/H5Ex_D_Checksum.java
./java/examples/datasets/H5Ex_D_Chunk.java
./java/examples/datasets/H5Ex_D_Compact.java
./java/examples/datasets/H5Ex_D_External.java
./java/examples/datasets/H5Ex_D_FillValue.java
./java/examples/datasets/H5Ex_D_Gzip.java
./java/examples/datasets/H5Ex_D_Hyperslab.java
./java/examples/datasets/H5Ex_D_ReadWrite.java
./java/examples/datasets/H5Ex_D_Shuffle.java
./java/examples/datasets/H5Ex_D_Szip.java
./java/examples/datasets/H5Ex_D_UnlimitedAdd.java
./java/examples/datasets/H5Ex_D_UnlimitedGzip.java
./java/examples/datasets/H5Ex_D_UnlimitedMod.java
./java/examples/datasets/H5Ex_D_Nbit.java
./java/examples/datasets/H5Ex_D_Transform.java
./java/examples/datasets/H5Ex_D_Sofloat.java
./java/examples/datasets/H5Ex_D_Soint.java
./java/examples/datatypes/Makefile.am
./java/examples/datatypes/CMakeLists.txt
./java/examples/datatypes/runExample.sh.in
./java/examples/datatypes/H5Ex_T_Array.java
./java/examples/datatypes/H5Ex_T_ArrayAttribute.java
./java/examples/datatypes/H5Ex_T_Bit.java
./java/examples/datatypes/H5Ex_T_BitAttribute.java
./java/examples/datatypes/H5Ex_T_Commit.java
./java/examples/datatypes/H5Ex_T_Compound.java
./java/examples/datatypes/H5Ex_T_CompoundAttribute.java
./java/examples/datatypes/H5Ex_T_Float.java
./java/examples/datatypes/H5Ex_T_FloatAttribute.java
./java/examples/datatypes/H5Ex_T_Integer.java
./java/examples/datatypes/H5Ex_T_IntegerAttribute.java
./java/examples/datatypes/H5Ex_T_ObjectReference.java
./java/examples/datatypes/H5Ex_T_ObjectReferenceAttribute.java
./java/examples/datatypes/H5Ex_T_Opaque.java
./java/examples/datatypes/H5Ex_T_OpaqueAttribute.java
./java/examples/datatypes/H5Ex_T_String.java
./java/examples/datatypes/H5Ex_T_StringAttribute.java
./java/examples/datatypes/H5Ex_T_VLString.java
./java/examples/testfiles/examples.intro.H5_CreateAttribute.txt
./java/examples/testfiles/examples.intro.H5_CreateDataset.txt
./java/examples/testfiles/examples.intro.H5_CreateFile.txt
./java/examples/testfiles/examples.intro.H5_CreateGroup.txt
./java/examples/testfiles/examples.intro.H5_CreateGroupAbsoluteRelative.txt
./java/examples/testfiles/examples.intro.H5_CreateGroupDataset.txt
./java/examples/testfiles/examples.intro.H5_ReadWrite.txt
./java/examples/testfiles/examples.groups.H5Ex_G_Create.txt
./java/examples/testfiles/examples.groups.H5Ex_G_Iterate.txt
./java/examples/testfiles/examples.groups.H5Ex_G_Compact.txt
./java/examples/testfiles/examples.groups.H5Ex_G_Corder.txt
./java/examples/testfiles/examples.groups.H5Ex_G_Intermediate.txt
./java/examples/testfiles/examples.groups.H5Ex_G_Phase.txt
./java/examples/testfiles/examples.groups.H5Ex_G_Visit.txt
./java/examples/testfiles/examples.datasets.H5Ex_D_Alloc.txt
./java/examples/testfiles/examples.datasets.H5Ex_D_Checksum.txt
./java/examples/testfiles/examples.datasets.H5Ex_D_Chunk.txt
./java/examples/testfiles/examples.datasets.H5Ex_D_Compact.txt
./java/examples/testfiles/examples.datasets.H5Ex_D_External.txt
./java/examples/testfiles/examples.datasets.H5Ex_D_FillValue.txt
./java/examples/testfiles/examples.datasets.H5Ex_D_Gzip.txt
./java/examples/testfiles/examples.datasets.H5Ex_D_Hyperslab.txt
./java/examples/testfiles/examples.datasets.H5Ex_D_ReadWrite.txt
./java/examples/testfiles/examples.datasets.H5Ex_D_Shuffle.txt
./java/examples/testfiles/examples.datasets.H5Ex_D_Szip.txt
./java/examples/testfiles/examples.datasets.H5Ex_D_UnlimitedAdd.txt
./java/examples/testfiles/examples.datasets.H5Ex_D_UnlimitedGzip.txt
./java/examples/testfiles/examples.datasets.H5Ex_D_UnlimitedMod.txt
./java/examples/testfiles/examples.datasets.H5Ex_D_Nbit.txt
./java/examples/testfiles/examples.datasets.H5Ex_D_Transform.txt
./java/examples/testfiles/examples.datasets.H5Ex_D_Sofloat.txt
./java/examples/testfiles/examples.datasets.H5Ex_D_Soint.txt
./java/examples/testfiles/examples.datatypes.H5Ex_T_Array.txt
./java/examples/testfiles/examples.datatypes.H5Ex_T_ArrayAttribute.txt
./java/examples/testfiles/examples.datatypes.H5Ex_T_Bit.txt
./java/examples/testfiles/examples.datatypes.H5Ex_T_BitAttribute.txt
./java/examples/testfiles/examples.datatypes.H5Ex_T_Commit.txt
./java/examples/testfiles/examples.datatypes.H5Ex_T_Compound.txt
./java/examples/testfiles/examples.datatypes.H5Ex_T_CompoundAttribute.txt
./java/examples/testfiles/examples.datatypes.H5Ex_T_Float.txt
./java/examples/testfiles/examples.datatypes.H5Ex_T_FloatAttribute.txt
./java/examples/testfiles/examples.datatypes.H5Ex_T_Integer.txt
./java/examples/testfiles/examples.datatypes.H5Ex_T_IntegerAttribute.txt
./java/examples/testfiles/examples.datatypes.H5Ex_T_ObjectReference.txt
./java/examples/testfiles/examples.datatypes.H5Ex_T_ObjectReferenceAttribute.txt
./java/examples/testfiles/examples.datatypes.H5Ex_T_Opaque.txt
./java/examples/testfiles/examples.datatypes.H5Ex_T_OpaqueAttribute.txt
./java/examples/testfiles/examples.datatypes.H5Ex_T_String.txt
./java/examples/testfiles/examples.datatypes.H5Ex_T_StringAttribute.txt
./java/examples/testfiles/examples.datatypes.H5Ex_T_VLString.txt
./java/test/Makefile.am
./java/test/CMakeLists.txt
./java/test/junit.sh.in
./java/test/JUnit-interface.txt
./java/test/h5ex_g_iterate.hdf
./java/test/TestH5.java
./java/test/TestH5A.java
./java/test/TestH5Dparams.java
./java/test/TestH5D.java
./java/test/TestH5Dplist.java
./java/test/TestH5E.java
./java/test/TestH5Edefault.java
./java/test/TestH5Eregister.java
./java/test/TestH5Fparams.java
./java/test/TestH5Fbasic.java
./java/test/TestH5F.java
./java/test/TestH5Gbasic.java
./java/test/TestH5G.java
./java/test/TestH5Giterate.java
./java/test/TestH5Lparams.java
./java/test/TestH5Lbasic.java
./java/test/TestH5Lcreate.java
./java/test/TestH5Oparams.java
./java/test/TestH5Obasic.java
./java/test/TestH5Ocreate.java
./java/test/TestH5Ocopy.java
./java/test/TestH5P.java
./java/test/TestH5PData.java
./java/test/TestH5Pfapl.java
./java/test/TestH5Plist.java
./java/test/TestH5Pvirtual.java
./java/test/TestH5PL.java
./java/test/TestH5R.java
./java/test/TestH5Sbasic.java
./java/test/TestH5S.java
./java/test/TestH5Tparams.java
./java/test/TestH5Tbasic.java
./java/test/TestH5T.java
./java/test/TestH5Z.java
./java/test/TestAll.java
./java/lib/hamcrest-core.jar
./java/lib/junit.jar
./java/lib/simplelogger.properties
./java/lib/slf4j-api-1.7.5.jar
./java/lib/ext/slf4j-nop-1.7.5.jar
./java/lib/ext/slf4j-simple-1.7.5.jar
# CMake-specific Files
./config/cmake/cacheinit.cmake
./config/cmake/CMakeFindJavaCommon.cmake
./config/cmake/ConversionTests.c
./config/cmake/ConfigureChecks.cmake
./config/cmake/CPack.Info.plist.in
./config/cmake/CTestCustom.cmake
./config/cmake/FindHDF5.cmake.in
./config/cmake/FindHDFJAVA.cmake.in
./config/cmake/FindJNI.cmake
./config/cmake/H5cxx_config.h.in
./config/cmake/H5pubconf.h.in
./config/cmake/hdf5-config.cmake.in
@@ -2431,11 +2743,15 @@
./config/cmake/HDF5_Process_Flex_Files.cmake
./config/cmake/HDF5Macros.cmake
./config/cmake/HDF5UseFortran.cmake
./config/cmake/jrunTest.cmake
./config/cmake/libhdf5.settings.cmake.in
./config/cmake/mccacheinit.cmake
./config/cmake/patch.xml
./config/cmake/PkgInfo.in
./config/cmake/README.txt.cmake.in
./config/cmake/UseJava.cmake
./config/cmake/UseJavaClassFilelist.cmake
./config/cmake/UseJavaSymlinks.cmake
./config/cmake/userblockTest.cmake
./config/cmake/vfdTest.cmake
+7 -2
View File
@@ -66,6 +66,11 @@ if BUILD_FORTRAN_CONDITIONAL
else
FORTRAN_DIR=
endif
if BUILD_JAVA_CONDITIONAL
JAVA_DIR=java
else
JAVA_DIR=
endif
if BUILD_HDF5_HL_CONDITIONAL
HDF5_HL_DIR =hl
else
@@ -73,8 +78,8 @@ else
endif
SUBDIRS = src test $(TESTPARALLEL_DIR) tools . $(CXX_DIR) $(FORTRAN_DIR) \
$(HDF5_HL_DIR)
DIST_SUBDIRS = src test testpar tools . c++ fortran hl examples
$(JAVA_DIR) $(HDF5_HL_DIR)
DIST_SUBDIRS = src test testpar tools . c++ fortran hl examples java
# Some files generated during configure that should be cleaned
DISTCLEANFILES=config/stamp1 config/stamp2
+1 -1
View File
@@ -94,7 +94,7 @@ if (BUILD_SHARED_LIBS)
TARGET_C_PROPERTIES (${HDF5_CPP_LIBSH_TARGET} SHARED " " " ")
target_link_libraries (${HDF5_CPP_LIBSH_TARGET} ${HDF5_LIBSH_TARGET})
set_global_variable (HDF5_LIBRARIES_TO_EXPORT "${HDF5_LIBRARIES_TO_EXPORT};${HDF5_CPP_LIBSH_TARGET}")
H5_SET_LIB_OPTIONS (${HDF5_CPP_LIBSH_TARGET} ${HDF5_CPP_LIB_NAME} SHARED)
H5_SET_LIB_OPTIONS (${HDF5_CPP_LIBSH_TARGET} ${HDF5_CPP_LIB_NAME} SHARED ${HDF5_CXX_PACKAGE_SOVERSION})
set_target_properties (${HDF5_CPP_LIBSH_TARGET} PROPERTIES
FOLDER libraries/cpp
COMPILE_DEFINITIONS "H5_BUILT_AS_DYNAMIC_LIB"
+41
View File
@@ -0,0 +1,41 @@
#=============================================================================
# Copyright 2013-2014 Kitware, Inc.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
# Do not include this module directly from code outside CMake!
set(_JAVA_HOME "")
if(JAVA_HOME AND IS_DIRECTORY "${JAVA_HOME}")
set(_JAVA_HOME "${JAVA_HOME}")
set(_JAVA_HOME_EXPLICIT 1)
else()
set(_ENV_JAVA_HOME "")
if(DEFINED ENV{JAVA_HOME})
file(TO_CMAKE_PATH "$ENV{JAVA_HOME}" _ENV_JAVA_HOME)
endif()
if(_ENV_JAVA_HOME AND IS_DIRECTORY "${_ENV_JAVA_HOME}")
set(_JAVA_HOME "${_ENV_JAVA_HOME}")
set(_JAVA_HOME_EXPLICIT 1)
else()
set(_CMD_JAVA_HOME "")
if(APPLE AND EXISTS /usr/libexec/java_home)
execute_process(COMMAND /usr/libexec/java_home
OUTPUT_VARIABLE _CMD_JAVA_HOME OUTPUT_STRIP_TRAILING_WHITESPACE)
endif()
if(_CMD_JAVA_HOME AND IS_DIRECTORY "${_CMD_JAVA_HOME}")
set(_JAVA_HOME "${_CMD_JAVA_HOME}")
set(_JAVA_HOME_EXPLICIT 0)
endif()
unset(_CMD_JAVA_HOME)
endif()
unset(_ENV_JAVA_HOME)
endif()
+68
View File
@@ -0,0 +1,68 @@
#
# To be used by projects that make use of CMakeified hdf-java
#
#
# Find the HDFJAVA includes and get all installed hdf-java library settings from
# HDFJAVA-config.cmake file : Requires a CMake compatible hdf-java-@HDFJAVA_PACKAGE_VERSION@ or later
# for this feature to work. The following vars are set if hdf-java is found.
#
# HDFJAVA_FOUND - True if found, otherwise all other vars are undefined
# HDFJAVA_VERSION_STRING - full version (e.g. @HDFJAVA_PACKAGE_VERSION@)
# HDFJAVA_VERSION_MAJOR - major part of version (e.g. @HDFJAVA_PACKAGE_VERSION_MAJOR@)
# HDFJAVA_VERSION_MINOR - minor part (e.g. @HDFJAVA_PACKAGE_VERSION_MINOR@)
#
# Target names that are valid (depending on enabled options)
# will be the following
#
#
# To aid in finding HDFJAVA as part of a subproject set
# HDFJAVA_ROOT_DIR_HINT to the location where @HDFJAVA_PACKAGE@@HDF_PACKAGE_EXT@-config.cmake lies
INCLUDE (SelectLibraryConfigurations)
INCLUDE (FindPackageHandleStandardArgs)
# The HINTS option should only be used for values computed from the system.
set (_HDFJAVA_HINTS
$ENV{HOME}/.local
$ENV{HDFJAVA_ROOT}
$ENV{HDFJAVA_ROOT_DIR_HINT}
)
# Hard-coded guesses should still go in PATHS. This ensures that the user
# environment can always override hard guesses.
set (_HDFJAVA_PATHS
$ENV{HOME}/.local
$ENV{HDFJAVA_ROOT}
$ENV{HDFJAVA_ROOT_DIR_HINT}
/usr/lib/@HDFJAVA_PACKAGE@
/usr/share/@HDFJAVA_PACKAGE@
/usr/local/@HDFJAVA_PACKAGE@
/usr/local/@HDFJAVA_PACKAGE@/share
)
FIND_PATH (HDFJAVA_ROOT_DIR "@HDFJAVA_PACKAGE@@HDF_PACKAGE_EXT@-config.cmake"
HINTS ${_HDFJAVA_HINTS}
PATHS ${_HDFJAVA_PATHS}
PATH_SUFFIXES
cmake/@HDFJAVA_PACKAGE@
lib/cmake/@HDFJAVA_PACKAGE@
share/cmake/@HDFJAVA_PACKAGE@
)
FIND_PATH (HDFJAVA_LIBRARY "jarhdf5-@HDFJAVA_PACKAGE_VERSION@.jar"
HINTS ${_HDFJAVA_HINTS}
PATHS ${_HDFJAVA_PATHS}
PATH_SUFFIXES
lib
)
if (HDFJAVA_ROOT_DIR)
set (HDFJAVA_FOUND "YES")
INCLUDE (${HDFJAVA_ROOT_DIR}/@HDFJAVA_PACKAGE@@HDF_PACKAGE_EXT@-config.cmake)
set (HDFJAVA_LIBRARIES "${HDFJAVA_LIBRARY}")
set (HDFJAVA_INCLUDE_DIRS
${HDFJAVA_LIBRARY}/jarhdf-@HDFJAVA_PACKAGE_VERSION@.jar
${HDFJAVA_LIBRARY}/jarhdf5-@HDFJAVA_PACKAGE_VERSION@.jar
)
endif (HDFJAVA_ROOT_DIR)
+342
View File
@@ -0,0 +1,342 @@
#.rst:
# FindJNI
# -------
#
# Find JNI java libraries.
#
# This module finds if Java is installed and determines where the
# include files and libraries are. It also determines what the name of
# the library is. The caller may set variable JAVA_HOME to specify a
# Java installation prefix explicitly.
#
# This module sets the following result variables:
#
# ::
#
# JNI_INCLUDE_DIRS = the include dirs to use
# JNI_LIBRARIES = the libraries to use
# JNI_FOUND = TRUE if JNI headers and libraries were found.
# JAVA_AWT_LIBRARY = the path to the jawt library
# JAVA_JVM_LIBRARY = the path to the jvm library
# JAVA_INCLUDE_PATH = the include path to jni.h
# JAVA_INCLUDE_PATH2 = the include path to jni_md.h
# JAVA_AWT_INCLUDE_PATH = the include path to jawt.h
#=============================================================================
# Copyright 2001-2009 Kitware, Inc.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
# Expand {libarch} occurences to java_libarch subdirectory(-ies) and set ${_var}
macro(java_append_library_directories _var)
# Determine java arch-specific library subdir
# Mostly based on openjdk/jdk/make/common/shared/Platform.gmk as of openjdk
# 1.6.0_18 + icedtea patches. However, it would be much better to base the
# guess on the first part of the GNU config.guess platform triplet.
if(CMAKE_SYSTEM_PROCESSOR STREQUAL "x86_64")
if(CMAKE_LIBRARY_ARCHITECTURE STREQUAL "x86_64-linux-gnux32")
set(_java_libarch "x32" "amd64" "i386")
else()
set(_java_libarch "amd64" "i386")
endif()
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^i.86$")
set(_java_libarch "i386")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^alpha")
set(_java_libarch "alpha")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm")
# Subdir is "arm" for both big-endian (arm) and little-endian (armel).
set(_java_libarch "arm")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^mips")
# mips* machines are bi-endian mostly so processor does not tell
# endianess of the underlying system.
set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}" "mips" "mipsel" "mipseb" "mips64" "mips64el" "mipsn32" "mipsn32el")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64le")
set(_java_libarch "ppc64" "ppc64le")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)64")
set(_java_libarch "ppc64" "ppc")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(powerpc|ppc)")
set(_java_libarch "ppc")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^sparc")
# Both flavours can run on the same processor
set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}" "sparc" "sparcv9")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^(parisc|hppa)")
set(_java_libarch "parisc" "parisc64")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^s390")
# s390 binaries can run on s390x machines
set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}" "s390" "s390x")
elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "^sh")
set(_java_libarch "sh")
else()
set(_java_libarch "${CMAKE_SYSTEM_PROCESSOR}")
endif()
# Append default list architectures if CMAKE_SYSTEM_PROCESSOR was empty or
# system is non-Linux (where the code above has not been well tested)
if(NOT _java_libarch OR NOT (CMAKE_SYSTEM_NAME MATCHES "Linux"))
list(APPEND _java_libarch "i386" "amd64" "ppc")
endif()
# Sometimes ${CMAKE_SYSTEM_PROCESSOR} is added to the list to prefer
# current value to a hardcoded list. Remove possible duplicates.
list(REMOVE_DUPLICATES _java_libarch)
foreach(_path ${ARGN})
if(_path MATCHES "{libarch}")
foreach(_libarch ${_java_libarch})
string(REPLACE "{libarch}" "${_libarch}" _newpath "${_path}")
list(APPEND ${_var} "${_newpath}")
endforeach()
else()
list(APPEND ${_var} "${_path}")
endif()
endforeach()
endmacro()
#include(${CMAKE_CURRENT_LIST_DIR}/CMakeFindJavaCommon.cmake)
INCLUDE (CMakeFindJavaCommon)
# Save CMAKE_FIND_FRAMEWORK
if(DEFINED CMAKE_FIND_FRAMEWORK)
set(_JNI_CMAKE_FIND_FRAMEWORK ${CMAKE_FIND_FRAMEWORK})
else()
unset(_JNI_CMAKE_FIND_FRAMEWORK)
endif()
if(_JAVA_HOME_EXPLICIT)
set(CMAKE_FIND_FRAMEWORK NEVER)
endif()
set(JAVA_AWT_LIBRARY_DIRECTORIES)
if(_JAVA_HOME)
JAVA_APPEND_LIBRARY_DIRECTORIES(JAVA_AWT_LIBRARY_DIRECTORIES
${_JAVA_HOME}/jre/lib/{libarch}
${_JAVA_HOME}/jre/lib
${_JAVA_HOME}/lib/{libarch}
${_JAVA_HOME}/lib
${_JAVA_HOME}
)
endif()
get_filename_component(java_install_version
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit;CurrentVersion]" NAME)
list(APPEND JAVA_AWT_LIBRARY_DIRECTORIES
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.4;JavaHome]/lib"
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/lib"
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\${java_install_version};JavaHome]/lib"
)
JAVA_APPEND_LIBRARY_DIRECTORIES(JAVA_AWT_LIBRARY_DIRECTORIES
/usr/java/lib
/usr/java/jre/lib
/usr/lib
/usr/lib64
/usr/local/lib
/usr/local/lib64
/usr/lib/jvm/java/lib
/usr/lib64/jvm/java/lib
/usr/lib/java/jre/lib/{libarch}
/usr/lib64/java/jre/lib/{libarch}
/usr/lib/jvm/jre/lib/{libarch}
/usr/lib64/jvm/jre/lib/{libarch}
/usr/local/lib/java/jre/lib/{libarch}
/usr/local/share/java/jre/lib/{libarch}
/usr/lib/j2sdk1.4-sun/jre/lib/{libarch}
/usr/lib/j2sdk1.5-sun/jre/lib/{libarch}
/opt/sun-jdk-1.5.0.04/jre/lib/{libarch}
/usr/lib/jvm/java-6-sun/jre/lib/{libarch}
/usr/lib/jvm/java-1.5.0-sun/jre/lib/{libarch}
/usr/lib/jvm/java-6-sun-1.6.0.00/jre/lib/{libarch} # can this one be removed according to #8821 ? Alex
/usr/lib/jvm/java-6-openjdk/jre/lib/{libarch}
/usr/lib/jvm/java-7-openjdk/jre/lib/{libarch}
/usr/lib/jvm/java-7-openjdk-{libarch}/jre/lib/{libarch}
/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0/jre/lib/{libarch} # fedora
# Debian specific paths for default JVM
/usr/lib/jvm/default-java/jre/lib/{libarch}
/usr/lib/jvm/default-java/jre/lib
/usr/lib/jvm/default-java/lib
# OpenBSD specific paths for default JVM
/usr/local/jdk-1.7.0/jre/lib/{libarch}
/usr/local/jre-1.7.0/lib/{libarch}
/usr/local/jdk-1.6.0/jre/lib/{libarch}
/usr/local/jre-1.6.0/lib/{libarch}
# SuSE specific paths for default JVM
/usr/lib64/jvm/java/jre/lib/{libarch}
/usr/lib64/jvm/jre/lib/{libarch}
)
set(JAVA_JVM_LIBRARY_DIRECTORIES)
foreach(dir ${JAVA_AWT_LIBRARY_DIRECTORIES})
list(APPEND JAVA_JVM_LIBRARY_DIRECTORIES
"${dir}"
"${dir}/client"
"${dir}/server"
# IBM SDK, Java Technology Edition, specific paths
"${dir}/j9vm"
"${dir}/default"
)
endforeach()
set(JAVA_AWT_INCLUDE_DIRECTORIES)
if(_JAVA_HOME)
list(APPEND JAVA_AWT_INCLUDE_DIRECTORIES ${_JAVA_HOME}/include)
endif()
list(APPEND JAVA_AWT_INCLUDE_DIRECTORIES
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.4;JavaHome]/include"
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.3;JavaHome]/include"
"[HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\${java_install_version};JavaHome]/include"
${_JAVA_HOME}/include
/usr/include
/usr/java/include
/usr/local/include
/usr/lib/java/include
/usr/lib64/java/include
/usr/local/lib/java/include
/usr/lib/jvm/java/include
/usr/lib64/jvm/java/include
/usr/lib/jvm/java-6-sun/include
/usr/lib/jvm/java-1.5.0-sun/include
/usr/lib/jvm/java-6-sun-1.6.0.00/include # can this one be removed according to #8821 ? Alex
/usr/lib/jvm/java-6-openjdk/include
/usr/lib/jvm/java-7-openjdk/include
/usr/lib/jvm/java-7-openjdk-i386/include
/usr/lib/jvm/java-7-openjdk-amd64/include
/usr/lib64/jvm/java-7-openjdk/include
/usr/lib64/jvm/java-7-openjdk-amd64/include
/usr/local/share/java/include
/usr/lib/j2sdk1.4-sun/include
/usr/lib/j2sdk1.5-sun/include
/opt/sun-jdk-1.5.0.04/include
# Debian specific path for default JVM
/usr/lib/jvm/default-java/include
# OpenBSD specific path for default JVM
/usr/local/jdk-1.7.0/include
/usr/local/jdk-1.6.0/include
# SuSE specific paths for default JVM
/usr/lib64/jvm/java/include
)
foreach(JAVA_PROG "${JAVA_RUNTIME}" "${JAVA_COMPILE}" "${JAVA_ARCHIVE}")
get_filename_component(jpath "${JAVA_PROG}" PATH)
foreach(JAVA_INC_PATH ../include ../java/include ../share/java/include)
if(EXISTS ${jpath}/${JAVA_INC_PATH})
list(APPEND JAVA_AWT_INCLUDE_DIRECTORIES "${jpath}/${JAVA_INC_PATH}")
endif()
endforeach()
foreach(JAVA_LIB_PATH
../lib ../jre/lib ../jre/lib/i386
../java/lib ../java/jre/lib ../java/jre/lib/i386
../share/java/lib ../share/java/jre/lib ../share/java/jre/lib/i386)
if(EXISTS ${jpath}/${JAVA_LIB_PATH})
list(APPEND JAVA_AWT_LIBRARY_DIRECTORIES "${jpath}/${JAVA_LIB_PATH}")
endif()
endforeach()
endforeach()
if(APPLE)
if(CMAKE_FIND_FRAMEWORK STREQUAL "ONLY")
set(_JNI_SEARCHES FRAMEWORK)
elseif(CMAKE_FIND_FRAMEWORK STREQUAL "NEVER")
set(_JNI_SEARCHES NORMAL)
elseif(CMAKE_FIND_FRAMEWORK STREQUAL "LAST")
set(_JNI_SEARCHES NORMAL FRAMEWORK)
else()
set(_JNI_SEARCHES FRAMEWORK NORMAL)
endif()
set(_JNI_FRAMEWORK_JVM NAMES JavaVM)
set(_JNI_FRAMEWORK_JAWT "${_JNI_FRAMEWORK_JVM}")
else()
set(_JNI_SEARCHES NORMAL)
endif()
set(_JNI_NORMAL_JVM
NAMES jvm
PATHS ${JAVA_JVM_LIBRARY_DIRECTORIES}
)
set(_JNI_NORMAL_JAWT
NAMES jawt
PATHS ${JAVA_AWT_LIBRARY_DIRECTORIES}
)
foreach(search ${_JNI_SEARCHES})
find_library(JAVA_JVM_LIBRARY ${_JNI_${search}_JVM})
find_library(JAVA_AWT_LIBRARY ${_JNI_${search}_JAWT})
if(JAVA_JVM_LIBRARY)
break()
endif()
endforeach()
unset(_JNI_SEARCHES)
unset(_JNI_FRAMEWORK_JVM)
unset(_JNI_FRAMEWORK_JAWT)
unset(_JNI_NORMAL_JVM)
unset(_JNI_NORMAL_JAWT)
# Find headers matching the library.
if("${JAVA_JVM_LIBRARY};${JAVA_AWT_LIBRARY};" MATCHES "(/JavaVM.framework|-framework JavaVM);")
set(CMAKE_FIND_FRAMEWORK ONLY)
else()
set(CMAKE_FIND_FRAMEWORK NEVER)
endif()
# add in the include path
find_path(JAVA_INCLUDE_PATH jni.h
${JAVA_AWT_INCLUDE_DIRECTORIES}
)
find_path(JAVA_INCLUDE_PATH2 jni_md.h
${JAVA_INCLUDE_PATH}
${JAVA_INCLUDE_PATH}/darwin
${JAVA_INCLUDE_PATH}/win32
${JAVA_INCLUDE_PATH}/linux
${JAVA_INCLUDE_PATH}/freebsd
${JAVA_INCLUDE_PATH}/openbsd
${JAVA_INCLUDE_PATH}/solaris
${JAVA_INCLUDE_PATH}/hp-ux
${JAVA_INCLUDE_PATH}/alpha
)
find_path(JAVA_AWT_INCLUDE_PATH jawt.h
${JAVA_INCLUDE_PATH}
)
# Restore CMAKE_FIND_FRAMEWORK
if(DEFINED _JNI_CMAKE_FIND_FRAMEWORK)
set(CMAKE_FIND_FRAMEWORK ${_JNI_CMAKE_FIND_FRAMEWORK})
unset(_JNI_CMAKE_FIND_FRAMEWORK)
else()
unset(CMAKE_FIND_FRAMEWORK)
endif()
#include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
INCLUDE (FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(JNI DEFAULT_MSG JAVA_AWT_LIBRARY JAVA_JVM_LIBRARY
JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
mark_as_advanced(
JAVA_AWT_LIBRARY
JAVA_JVM_LIBRARY
JAVA_AWT_INCLUDE_PATH
JAVA_INCLUDE_PATH
JAVA_INCLUDE_PATH2
)
set(JNI_LIBRARIES
${JAVA_AWT_LIBRARY}
${JAVA_JVM_LIBRARY}
)
set(JNI_INCLUDE_DIRS
${JAVA_INCLUDE_PATH}
${JAVA_INCLUDE_PATH2}
${JAVA_AWT_INCLUDE_PATH}
)
message ("JNI_LIBRARIES=${JNI_LIBRARIES}")
message ("JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}")
+1
View File
@@ -9,6 +9,7 @@ It was built with the following options:
-- @LIB_TYPE@ C/C++/Fortran libraries
-- SZIP (encoder enabled) and ZLIB
-- @LIB_TYPE@ HDF5 tools
-- Java
The contents of this directory are:
+1290
View File
@@ -0,0 +1,1290 @@
#.rst:
# UseJava
# -------
#
# Use Module for Java
#
# This file provides functions for Java. It is assumed that
# FindJava.cmake has already been loaded. See FindJava.cmake for
# information on how to load Java into your CMake project.
#
# ::
#
# add_jar(target_name
# [SOURCES] source1 [source2 ...] [resource1 ...]
# [INCLUDE_JARS jar1 [jar2 ...]]
# [ENTRY_POINT entry]
# [VERSION version]
# [OUTPUT_NAME name]
# [OUTPUT_DIR dir]
# )
#
# This command creates a <target_name>.jar. It compiles the given
# source files (source) and adds the given resource files (resource) to
# the jar file. Source files can be java files or listing files
# (prefixed by '@'). If only resource files are given then just a jar file
# is created. The list of include jars are added to the classpath when
# compiling the java sources and also to the dependencies of the target.
# INCLUDE_JARS also accepts other target names created by add_jar. For
# backwards compatibility, jar files listed as sources are ignored (as
# they have been since the first version of this module).
#
# The default OUTPUT_DIR can also be changed by setting the variable
# CMAKE_JAVA_TARGET_OUTPUT_DIR.
#
# Additional instructions:
#
# ::
#
# To add compile flags to the target you can set these flags with
# the following variable:
#
#
#
# ::
#
# set(CMAKE_JAVA_COMPILE_FLAGS -nowarn)
#
#
#
# ::
#
# To add a path or a jar file to the class path you can do this
# with the CMAKE_JAVA_INCLUDE_PATH variable.
#
#
#
# ::
#
# set(CMAKE_JAVA_INCLUDE_PATH /usr/share/java/shibboleet.jar)
#
#
#
# ::
#
# To use a different output name for the target you can set it with:
#
#
#
# ::
#
# add_jar(foobar foobar.java OUTPUT_NAME shibboleet.jar)
#
#
#
# ::
#
# To use a different output directory than CMAKE_CURRENT_BINARY_DIR
# you can set it with:
#
#
#
# ::
#
# add_jar(foobar foobar.java OUTPUT_DIR ${PROJECT_BINARY_DIR}/bin)
#
#
#
# ::
#
# To define an entry point in your jar you can set it with the ENTRY_POINT
# named argument:
#
#
#
# ::
#
# add_jar(example ENTRY_POINT com/examples/MyProject/Main)
#
#
#
# ::
#
# To define a custom manifest for the jar, you can set it with the manifest
# named argument:
#
#
#
# ::
#
# add_jar(example MANIFEST /path/to/manifest)
#
#
#
# ::
#
# To add a VERSION to the target output name you can set it using
# the VERSION named argument to add_jar. This will create a jar file with the
# name shibboleet-1.0.0.jar and will create a symlink shibboleet.jar
# pointing to the jar with the version information.
#
#
#
# ::
#
# add_jar(shibboleet shibbotleet.java VERSION 1.2.0)
#
#
#
# ::
#
# If the target is a JNI library, utilize the following commands to
# create a JNI symbolic link:
#
#
#
# ::
#
# set(CMAKE_JNI_TARGET TRUE)
# add_jar(shibboleet shibbotleet.java VERSION 1.2.0)
# install_jar(shibboleet ${LIB_INSTALL_DIR}/shibboleet)
# install_jni_symlink(shibboleet ${JAVA_LIB_INSTALL_DIR})
#
#
#
# ::
#
# If a single target needs to produce more than one jar from its
# java source code, to prevent the accumulation of duplicate class
# files in subsequent jars, set/reset CMAKE_JAR_CLASSES_PREFIX prior
# to calling the add_jar() function:
#
#
#
# ::
#
# set(CMAKE_JAR_CLASSES_PREFIX com/redhat/foo)
# add_jar(foo foo.java)
#
#
#
# ::
#
# set(CMAKE_JAR_CLASSES_PREFIX com/redhat/bar)
# add_jar(bar bar.java)
#
#
#
# Target Properties:
#
# ::
#
# The add_jar() functions sets some target properties. You can get these
# properties with the
# get_property(TARGET <target_name> PROPERTY <propery_name>)
# command.
#
#
#
# ::
#
# INSTALL_FILES The files which should be installed. This is used by
# install_jar().
# JNI_SYMLINK The JNI symlink which should be installed.
# This is used by install_jni_symlink().
# JAR_FILE The location of the jar file so that you can include
# it.
# CLASS_DIR The directory where the class files can be found. For
# example to use them with javah.
#
# ::
#
# find_jar(<VAR>
# name | NAMES name1 [name2 ...]
# [PATHS path1 [path2 ... ENV var]]
# [VERSIONS version1 [version2]]
# [DOC "cache documentation string"]
# )
#
# This command is used to find a full path to the named jar. A cache
# entry named by <VAR> is created to stor the result of this command.
# If the full path to a jar is found the result is stored in the
# variable and the search will not repeated unless the variable is
# cleared. If nothing is found, the result will be <VAR>-NOTFOUND, and
# the search will be attempted again next time find_jar is invoked with
# the same variable. The name of the full path to a file that is
# searched for is specified by the names listed after NAMES argument.
# Additional search locations can be specified after the PATHS argument.
# If you require special a version of a jar file you can specify it with
# the VERSIONS argument. The argument after DOC will be used for the
# documentation string in the cache.
#
# ::
#
# install_jar(target_name destination)
# install_jar(target_name DESTINATION destination [COMPONENT component])
#
# This command installs the TARGET_NAME files to the given DESTINATION.
# It should be called in the same scope as add_jar() or it will fail.
#
# ::
#
# install_jni_symlink(target_name destination)
# install_jni_symlink(target_name DESTINATION destination [COMPONENT component])
#
# This command installs the TARGET_NAME JNI symlinks to the given
# DESTINATION. It should be called in the same scope as add_jar() or it
# will fail.
#
# ::
#
# create_javadoc(<VAR>
# PACKAGES pkg1 [pkg2 ...]
# [SOURCEPATH <sourcepath>]
# [CLASSPATH <classpath>]
# [INSTALLPATH <install path>]
# [DOCTITLE "the documentation title"]
# [WINDOWTITLE "the title of the document"]
# [AUTHOR TRUE|FALSE]
# [USE TRUE|FALSE]
# [VERSION TRUE|FALSE]
# )
#
# Create java documentation based on files or packages. For more
# details please read the javadoc manpage.
#
# There are two main signatures for create_javadoc. The first signature
# works with package names on a path with source files:
#
# ::
#
# Example:
# create_javadoc(my_example_doc
# PACKAGES com.exmaple.foo com.example.bar
# SOURCEPATH "${CMAKE_CURRENT_SOURCE_DIR}"
# CLASSPATH ${CMAKE_JAVA_INCLUDE_PATH}
# WINDOWTITLE "My example"
# DOCTITLE "<h1>My example</h1>"
# AUTHOR TRUE
# USE TRUE
# VERSION TRUE
# )
#
#
#
# The second signature for create_javadoc works on a given list of
# files.
#
# ::
#
# create_javadoc(<VAR>
# FILES file1 [file2 ...]
# [CLASSPATH <classpath>]
# [INSTALLPATH <install path>]
# [DOCTITLE "the documentation title"]
# [WINDOWTITLE "the title of the document"]
# [AUTHOR TRUE|FALSE]
# [USE TRUE|FALSE]
# [VERSION TRUE|FALSE]
# )
#
#
#
# Example:
#
# ::
#
# create_javadoc(my_example_doc
# FILES ${example_SRCS}
# CLASSPATH ${CMAKE_JAVA_INCLUDE_PATH}
# WINDOWTITLE "My example"
# DOCTITLE "<h1>My example</h1>"
# AUTHOR TRUE
# USE TRUE
# VERSION TRUE
# )
#
#
#
# Both signatures share most of the options. These options are the same
# as what you can find in the javadoc manpage. Please look at the
# manpage for CLASSPATH, DOCTITLE, WINDOWTITLE, AUTHOR, USE and VERSION.
#
# The documentation will be by default installed to
#
# ::
#
# ${CMAKE_INSTALL_PREFIX}/share/javadoc/<VAR>
#
#
#
# if you don't set the INSTALLPATH.
#
# ::
#
# create_javah(TARGET <target>
# GENERATED_FILES <VAR>
# CLASSES <class>...
# [CLASSPATH <classpath>...]
# [DEPENDS <depend>...]
# [OUTPUT_NAME <path>|OUTPUT_DIR <path>]
# )
#
# Create C header files from java classes. These files provide the connective glue
# that allow your Java and C code to interact.
#
# There are two main signatures for create_javah. The first signature
# returns generated files throught variable specified by GENERATED_FILES option:
#
# ::
#
# Example:
# Create_javah(GENERATED_FILES files_headers
# CLASSES org.cmake.HelloWorld
# CLASSPATH hello.jar
# )
#
#
#
# The second signature for create_javah creates a target which encapsulates
# header files generation.
#
# ::
#
# Example:
# Create_javah(TARGET target_headers
# CLASSES org.cmake.HelloWorld
# CLASSPATH hello.jar
# )
#
#
#
# Both signatures share same options.
#
# ``CLASSES <class>...``
# Specifies Java classes used to generate headers.
#
# ``CLASSPATH <classpath>...``
# Specifies various paths to look up classes. Here .class files, jar files or targets
# created by command add_jar can be used.
#
# ``DEPENDS <depend>...``
# Targets on which the javah target depends
#
# ``OUTPUT_NAME <path>``
# Concatenates the resulting header files for all the classes listed by option CLASSES
# into <path>. Same behavior as option '-o' of javah tool.
#
# ``OUTPUT_DIR <path>``
# Sets the directory where the header files will be generated. Same behavior as option
# '-d' of javah tool. If not specified, ${CMAKE_CURRENT_BINARY_DIR} is used as output directory.
#=============================================================================
# Copyright 2013 OpenGamma Ltd. <graham@opengamma.com>
# Copyright 2010-2011 Andreas schneider <asn@redhat.com>
# Copyright 2010-2013 Kitware, Inc.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
include(CMakeParseArguments)
function (__java_copy_file src dest comment)
add_custom_command(
OUTPUT ${dest}
COMMAND cmake -E copy_if_different
ARGS ${src}
${dest}
DEPENDS ${src}
COMMENT ${comment})
endfunction ()
# define helper scripts
set(_JAVA_CLASS_FILELIST_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/UseJavaClassFilelist.cmake)
set(_JAVA_SYMLINK_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/UseJavaSymlinks.cmake)
function(add_jar _TARGET_NAME)
cmake_parse_arguments(_add_jar
""
"VERSION;OUTPUT_DIR;OUTPUT_NAME;ENTRY_POINT;MANIFEST"
"SOURCES;INCLUDE_JARS"
${ARGN}
)
# In CMake < 2.8.12, add_jar used variables which were set prior to calling
# add_jar for customizing the behavior of add_jar. In order to be backwards
# compatible, check if any of those variables are set, and use them to
# initialize values of the named arguments. (Giving the corresponding named
# argument will override the value set here.)
#
# New features should use named arguments only.
if(NOT DEFINED _add_jar_VERSION AND DEFINED CMAKE_JAVA_TARGET_VERSION)
set(_add_jar_VERSION "${CMAKE_JAVA_TARGET_VERSION}")
endif()
if(NOT DEFINED _add_jar_OUTPUT_DIR AND DEFINED CMAKE_JAVA_TARGET_OUTPUT_DIR)
set(_add_jar_OUTPUT_DIR "${CMAKE_JAVA_TARGET_OUTPUT_DIR}")
endif()
if(NOT DEFINED _add_jar_OUTPUT_NAME AND DEFINED CMAKE_JAVA_TARGET_OUTPUT_NAME)
set(_add_jar_OUTPUT_NAME "${CMAKE_JAVA_TARGET_OUTPUT_NAME}")
# reset
set(CMAKE_JAVA_TARGET_OUTPUT_NAME)
endif()
if(NOT DEFINED _add_jar_ENTRY_POINT AND DEFINED CMAKE_JAVA_JAR_ENTRY_POINT)
set(_add_jar_ENTRY_POINT "${CMAKE_JAVA_JAR_ENTRY_POINT}")
endif()
set(_JAVA_SOURCE_FILES ${_add_jar_SOURCES} ${_add_jar_UNPARSED_ARGUMENTS})
if (NOT DEFINED _add_jar_OUTPUT_DIR)
set(_add_jar_OUTPUT_DIR ${CMAKE_CURRENT_BINARY_DIR})
endif()
if (_add_jar_ENTRY_POINT)
set(_ENTRY_POINT_OPTION e)
set(_ENTRY_POINT_VALUE ${_add_jar_ENTRY_POINT})
endif ()
if (_add_jar_MANIFEST)
set(_MANIFEST_OPTION m)
set(_MANIFEST_VALUE ${_add_jar_MANIFEST})
endif ()
if (LIBRARY_OUTPUT_PATH)
set(CMAKE_JAVA_LIBRARY_OUTPUT_PATH ${LIBRARY_OUTPUT_PATH})
else ()
set(CMAKE_JAVA_LIBRARY_OUTPUT_PATH ${_add_jar_OUTPUT_DIR})
endif ()
set(CMAKE_JAVA_INCLUDE_PATH
${CMAKE_JAVA_INCLUDE_PATH}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_JAVA_OBJECT_OUTPUT_PATH}
${CMAKE_JAVA_LIBRARY_OUTPUT_PATH}
)
if (CMAKE_HOST_WIN32 AND NOT CYGWIN AND CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
set(CMAKE_JAVA_INCLUDE_FLAG_SEP ";")
else ()
set(CMAKE_JAVA_INCLUDE_FLAG_SEP ":")
endif()
foreach (JAVA_INCLUDE_DIR ${CMAKE_JAVA_INCLUDE_PATH})
set(CMAKE_JAVA_INCLUDE_PATH_FINAL "${CMAKE_JAVA_INCLUDE_PATH_FINAL}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${JAVA_INCLUDE_DIR}")
endforeach()
set(CMAKE_JAVA_CLASS_OUTPUT_PATH "${_add_jar_OUTPUT_DIR}${CMAKE_FILES_DIRECTORY}/${_TARGET_NAME}.dir")
set(_JAVA_TARGET_OUTPUT_NAME "${_TARGET_NAME}.jar")
if (_add_jar_OUTPUT_NAME AND _add_jar_VERSION)
set(_JAVA_TARGET_OUTPUT_NAME "${_add_jar_OUTPUT_NAME}-${_add_jar_VERSION}.jar")
set(_JAVA_TARGET_OUTPUT_LINK "${_add_jar_OUTPUT_NAME}.jar")
elseif (_add_jar_VERSION)
set(_JAVA_TARGET_OUTPUT_NAME "${_TARGET_NAME}-${_add_jar_VERSION}.jar")
set(_JAVA_TARGET_OUTPUT_LINK "${_TARGET_NAME}.jar")
elseif (_add_jar_OUTPUT_NAME)
set(_JAVA_TARGET_OUTPUT_NAME "${_add_jar_OUTPUT_NAME}.jar")
endif ()
set(_JAVA_CLASS_FILES)
set(_JAVA_COMPILE_FILES)
set(_JAVA_COMPILE_FILELISTS)
set(_JAVA_DEPENDS)
set(_JAVA_COMPILE_DEPENDS)
set(_JAVA_RESOURCE_FILES)
set(_JAVA_RESOURCE_FILES_RELATIVE)
foreach(_JAVA_SOURCE_FILE ${_JAVA_SOURCE_FILES})
get_filename_component(_JAVA_EXT ${_JAVA_SOURCE_FILE} EXT)
get_filename_component(_JAVA_FILE ${_JAVA_SOURCE_FILE} NAME_WE)
get_filename_component(_JAVA_PATH ${_JAVA_SOURCE_FILE} PATH)
get_filename_component(_JAVA_FULL ${_JAVA_SOURCE_FILE} ABSOLUTE)
if (_JAVA_SOURCE_FILE MATCHES "^@(.+)$")
get_filename_component(_JAVA_FULL ${CMAKE_MATCH_1} ABSOLUTE)
list(APPEND _JAVA_COMPILE_FILELISTS ${_JAVA_FULL})
elseif (_JAVA_EXT MATCHES ".java")
file(RELATIVE_PATH _JAVA_REL_BINARY_PATH ${_add_jar_OUTPUT_DIR} ${_JAVA_FULL})
file(RELATIVE_PATH _JAVA_REL_SOURCE_PATH ${CMAKE_CURRENT_SOURCE_DIR} ${_JAVA_FULL})
string(LENGTH ${_JAVA_REL_BINARY_PATH} _BIN_LEN)
string(LENGTH ${_JAVA_REL_SOURCE_PATH} _SRC_LEN)
if (${_BIN_LEN} LESS ${_SRC_LEN})
set(_JAVA_REL_PATH ${_JAVA_REL_BINARY_PATH})
else ()
set(_JAVA_REL_PATH ${_JAVA_REL_SOURCE_PATH})
endif ()
get_filename_component(_JAVA_REL_PATH ${_JAVA_REL_PATH} PATH)
list(APPEND _JAVA_COMPILE_FILES ${_JAVA_SOURCE_FILE})
set(_JAVA_CLASS_FILE "${CMAKE_JAVA_CLASS_OUTPUT_PATH}/${_JAVA_REL_PATH}/${_JAVA_FILE}.class")
set(_JAVA_CLASS_FILES ${_JAVA_CLASS_FILES} ${_JAVA_CLASS_FILE})
elseif (_JAVA_EXT MATCHES ".jar"
OR _JAVA_EXT MATCHES ".war"
OR _JAVA_EXT MATCHES ".ear"
OR _JAVA_EXT MATCHES ".sar")
# Ignored for backward compatibility
elseif (_JAVA_EXT STREQUAL "")
list(APPEND CMAKE_JAVA_INCLUDE_PATH ${JAVA_JAR_TARGET_${_JAVA_SOURCE_FILE}} ${JAVA_JAR_TARGET_${_JAVA_SOURCE_FILE}_CLASSPATH})
list(APPEND _JAVA_DEPENDS ${JAVA_JAR_TARGET_${_JAVA_SOURCE_FILE}})
else ()
__java_copy_file(${CMAKE_CURRENT_SOURCE_DIR}/${_JAVA_SOURCE_FILE}
${CMAKE_JAVA_CLASS_OUTPUT_PATH}/${_JAVA_SOURCE_FILE}
"Copying ${_JAVA_SOURCE_FILE} to the build directory")
list(APPEND _JAVA_RESOURCE_FILES ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/${_JAVA_SOURCE_FILE})
list(APPEND _JAVA_RESOURCE_FILES_RELATIVE ${_JAVA_SOURCE_FILE})
endif ()
endforeach()
foreach(_JAVA_INCLUDE_JAR ${_add_jar_INCLUDE_JARS})
if (TARGET ${_JAVA_INCLUDE_JAR})
get_target_property(_JAVA_JAR_PATH ${_JAVA_INCLUDE_JAR} JAR_FILE)
if (_JAVA_JAR_PATH)
set(CMAKE_JAVA_INCLUDE_PATH_FINAL "${CMAKE_JAVA_INCLUDE_PATH_FINAL}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${_JAVA_JAR_PATH}")
list(APPEND CMAKE_JAVA_INCLUDE_PATH ${_JAVA_JAR_PATH})
list(APPEND _JAVA_DEPENDS ${_JAVA_INCLUDE_JAR})
list(APPEND _JAVA_COMPILE_DEPENDS ${_JAVA_INCLUDE_JAR})
else ()
message(SEND_ERROR "add_jar: INCLUDE_JARS target ${_JAVA_INCLUDE_JAR} is not a jar")
endif ()
else ()
set(CMAKE_JAVA_INCLUDE_PATH_FINAL "${CMAKE_JAVA_INCLUDE_PATH_FINAL}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${_JAVA_INCLUDE_JAR}")
list(APPEND CMAKE_JAVA_INCLUDE_PATH "${_JAVA_INCLUDE_JAR}")
list(APPEND _JAVA_DEPENDS "${_JAVA_INCLUDE_JAR}")
list(APPEND _JAVA_COMPILE_DEPENDS "${_JAVA_INCLUDE_JAR}")
endif ()
endforeach()
# create an empty java_class_filelist
if (NOT EXISTS ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist)
file(WRITE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist "")
endif()
if (_JAVA_COMPILE_FILES OR _JAVA_COMPILE_FILELISTS)
set (_JAVA_SOURCES_FILELISTS)
if (_JAVA_COMPILE_FILES)
# Create the list of files to compile.
set(_JAVA_SOURCES_FILE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_sources)
string(REPLACE ";" "\"\n\"" _JAVA_COMPILE_STRING "\"${_JAVA_COMPILE_FILES}\"")
file(WRITE ${_JAVA_SOURCES_FILE} ${_JAVA_COMPILE_STRING})
list (APPEND _JAVA_SOURCES_FILELISTS "@${_JAVA_SOURCES_FILE}")
endif()
if (_JAVA_COMPILE_FILELISTS)
foreach (_JAVA_FILELIST IN LISTS _JAVA_COMPILE_FILELISTS)
list (APPEND _JAVA_SOURCES_FILELISTS "@${_JAVA_FILELIST}")
endforeach()
endif()
# Compile the java files and create a list of class files
add_custom_command(
# NOTE: this command generates an artificial dependency file
OUTPUT ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME}
COMMAND ${Java_JAVAC_EXECUTABLE}
${CMAKE_JAVA_COMPILE_FLAGS}
-classpath "${CMAKE_JAVA_INCLUDE_PATH_FINAL}"
-d ${CMAKE_JAVA_CLASS_OUTPUT_PATH}
${_JAVA_SOURCES_FILELISTS}
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME}
DEPENDS ${_JAVA_COMPILE_FILES} ${_JAVA_COMPILE_FILELISTS} ${_JAVA_COMPILE_DEPENDS}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Building Java objects for ${_TARGET_NAME}.jar"
)
add_custom_command(
OUTPUT ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist
COMMAND ${CMAKE_COMMAND}
-DCMAKE_JAVA_CLASS_OUTPUT_PATH=${CMAKE_JAVA_CLASS_OUTPUT_PATH}
-DCMAKE_JAR_CLASSES_PREFIX="${CMAKE_JAR_CLASSES_PREFIX}"
-P ${_JAVA_CLASS_FILELIST_SCRIPT}
DEPENDS ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_compiled_${_TARGET_NAME}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
endif ()
# create the jar file
set(_JAVA_JAR_OUTPUT_PATH
${_add_jar_OUTPUT_DIR}/${_JAVA_TARGET_OUTPUT_NAME})
if (CMAKE_JNI_TARGET)
add_custom_command(
OUTPUT ${_JAVA_JAR_OUTPUT_PATH}
COMMAND ${Java_JAR_EXECUTABLE}
-cf${_ENTRY_POINT_OPTION}${_MANIFEST_OPTION} ${_JAVA_JAR_OUTPUT_PATH} ${_ENTRY_POINT_VALUE} ${_MANIFEST_VALUE}
${_JAVA_RESOURCE_FILES_RELATIVE} @java_class_filelist
COMMAND ${CMAKE_COMMAND}
-D_JAVA_TARGET_DIR=${_add_jar_OUTPUT_DIR}
-D_JAVA_TARGET_OUTPUT_NAME=${_JAVA_TARGET_OUTPUT_NAME}
-D_JAVA_TARGET_OUTPUT_LINK=${_JAVA_TARGET_OUTPUT_LINK}
-P ${_JAVA_SYMLINK_SCRIPT}
COMMAND ${CMAKE_COMMAND}
-D_JAVA_TARGET_DIR=${_add_jar_OUTPUT_DIR}
-D_JAVA_TARGET_OUTPUT_NAME=${_JAVA_JAR_OUTPUT_PATH}
-D_JAVA_TARGET_OUTPUT_LINK=${_JAVA_TARGET_OUTPUT_LINK}
-P ${_JAVA_SYMLINK_SCRIPT}
DEPENDS ${_JAVA_RESOURCE_FILES} ${_JAVA_DEPENDS} ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist
WORKING_DIRECTORY ${CMAKE_JAVA_CLASS_OUTPUT_PATH}
COMMENT "Creating Java archive ${_JAVA_TARGET_OUTPUT_NAME}"
)
else ()
add_custom_command(
OUTPUT ${_JAVA_JAR_OUTPUT_PATH}
COMMAND ${Java_JAR_EXECUTABLE}
-cf${_ENTRY_POINT_OPTION}${_MANIFEST_OPTION} ${_JAVA_JAR_OUTPUT_PATH} ${_ENTRY_POINT_VALUE} ${_MANIFEST_VALUE}
${_JAVA_RESOURCE_FILES_RELATIVE} @java_class_filelist
COMMAND ${CMAKE_COMMAND}
-D_JAVA_TARGET_DIR=${_add_jar_OUTPUT_DIR}
-D_JAVA_TARGET_OUTPUT_NAME=${_JAVA_TARGET_OUTPUT_NAME}
-D_JAVA_TARGET_OUTPUT_LINK=${_JAVA_TARGET_OUTPUT_LINK}
-P ${_JAVA_SYMLINK_SCRIPT}
WORKING_DIRECTORY ${CMAKE_JAVA_CLASS_OUTPUT_PATH}
DEPENDS ${_JAVA_RESOURCE_FILES} ${_JAVA_DEPENDS} ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist
COMMENT "Creating Java archive ${_JAVA_TARGET_OUTPUT_NAME}"
)
endif ()
# Add the target and make sure we have the latest resource files.
add_custom_target(${_TARGET_NAME} ALL DEPENDS ${_JAVA_JAR_OUTPUT_PATH})
set_property(
TARGET
${_TARGET_NAME}
PROPERTY
INSTALL_FILES
${_JAVA_JAR_OUTPUT_PATH}
)
if (_JAVA_TARGET_OUTPUT_LINK)
set_property(
TARGET
${_TARGET_NAME}
PROPERTY
INSTALL_FILES
${_JAVA_JAR_OUTPUT_PATH}
${_add_jar_OUTPUT_DIR}/${_JAVA_TARGET_OUTPUT_LINK}
)
if (CMAKE_JNI_TARGET)
set_property(
TARGET
${_TARGET_NAME}
PROPERTY
JNI_SYMLINK
${_add_jar_OUTPUT_DIR}/${_JAVA_TARGET_OUTPUT_LINK}
)
endif ()
endif ()
set_property(
TARGET
${_TARGET_NAME}
PROPERTY
JAR_FILE
${_JAVA_JAR_OUTPUT_PATH}
)
set_property(
TARGET
${_TARGET_NAME}
PROPERTY
CLASSDIR
${CMAKE_JAVA_CLASS_OUTPUT_PATH}
)
endfunction()
function(INSTALL_JAR _TARGET_NAME)
if (ARGC EQUAL 2)
set (_DESTINATION ${ARGV1})
else()
cmake_parse_arguments(_install_jar
""
"DESTINATION;COMPONENT"
""
${ARGN})
if (_install_jar_DESTINATION)
set (_DESTINATION ${_install_jar_DESTINATION})
else()
message(SEND_ERROR "install_jar: ${_TARGET_NAME}: DESTINATION must be specified.")
endif()
if (_install_jar_COMPONENT)
set (_COMPONENT COMPONENT ${_install_jar_COMPONENT})
endif()
endif()
get_property(__FILES
TARGET
${_TARGET_NAME}
PROPERTY
INSTALL_FILES
)
if (__FILES)
install(
FILES
${__FILES}
DESTINATION
${_DESTINATION}
${_COMPONENT}
)
else ()
message(SEND_ERROR "install_jar: The target ${_TARGET_NAME} is not known in this scope.")
endif ()
endfunction()
function(INSTALL_JNI_SYMLINK _TARGET_NAME)
if (ARGC EQUAL 2)
set (_DESTINATION ${ARGV1})
else()
cmake_parse_arguments(_install_jni_symlink
""
"DESTINATION;COMPONENT"
""
${ARGN})
if (_install_jni_symlink_DESTINATION)
set (_DESTINATION ${_install_jni_symlink_DESTINATION})
else()
message(SEND_ERROR "install_jni_symlink: ${_TARGET_NAME}: DESTINATION must be specified.")
endif()
if (_install_jni_symlink_COMPONENT)
set (_COMPONENT COMPONENT ${_install_jni_symlink_COMPONENT})
endif()
endif()
get_property(__SYMLINK
TARGET
${_TARGET_NAME}
PROPERTY
JNI_SYMLINK
)
if (__SYMLINK)
install(
FILES
${__SYMLINK}
DESTINATION
${_DESTINATION}
${_COMPONENT}
)
else ()
message(SEND_ERROR "install_jni_symlink: The target ${_TARGET_NAME} is not known in this scope.")
endif ()
endfunction()
function (find_jar VARIABLE)
set(_jar_names)
set(_jar_files)
set(_jar_versions)
set(_jar_paths
/usr/share/java/
/usr/local/share/java/
${Java_JAR_PATHS})
set(_jar_doc "NOTSET")
set(_state "name")
foreach (arg ${ARGN})
if (${_state} STREQUAL "name")
if (${arg} STREQUAL "VERSIONS")
set(_state "versions")
elseif (${arg} STREQUAL "NAMES")
set(_state "names")
elseif (${arg} STREQUAL "PATHS")
set(_state "paths")
elseif (${arg} STREQUAL "DOC")
set(_state "doc")
else ()
set(_jar_names ${arg})
if (_jar_doc STREQUAL "NOTSET")
set(_jar_doc "Finding ${arg} jar")
endif ()
endif ()
elseif (${_state} STREQUAL "versions")
if (${arg} STREQUAL "NAMES")
set(_state "names")
elseif (${arg} STREQUAL "PATHS")
set(_state "paths")
elseif (${arg} STREQUAL "DOC")
set(_state "doc")
else ()
set(_jar_versions ${_jar_versions} ${arg})
endif ()
elseif (${_state} STREQUAL "names")
if (${arg} STREQUAL "VERSIONS")
set(_state "versions")
elseif (${arg} STREQUAL "PATHS")
set(_state "paths")
elseif (${arg} STREQUAL "DOC")
set(_state "doc")
else ()
set(_jar_names ${_jar_names} ${arg})
if (_jar_doc STREQUAL "NOTSET")
set(_jar_doc "Finding ${arg} jar")
endif ()
endif ()
elseif (${_state} STREQUAL "paths")
if (${arg} STREQUAL "VERSIONS")
set(_state "versions")
elseif (${arg} STREQUAL "NAMES")
set(_state "names")
elseif (${arg} STREQUAL "DOC")
set(_state "doc")
else ()
set(_jar_paths ${_jar_paths} ${arg})
endif ()
elseif (${_state} STREQUAL "doc")
if (${arg} STREQUAL "VERSIONS")
set(_state "versions")
elseif (${arg} STREQUAL "NAMES")
set(_state "names")
elseif (${arg} STREQUAL "PATHS")
set(_state "paths")
else ()
set(_jar_doc ${arg})
endif ()
endif ()
endforeach ()
if (NOT _jar_names)
message(FATAL_ERROR "find_jar: No name to search for given")
endif ()
foreach (jar_name ${_jar_names})
foreach (version ${_jar_versions})
set(_jar_files ${_jar_files} ${jar_name}-${version}.jar)
endforeach ()
set(_jar_files ${_jar_files} ${jar_name}.jar)
endforeach ()
find_file(${VARIABLE}
NAMES ${_jar_files}
PATHS ${_jar_paths}
DOC ${_jar_doc}
NO_DEFAULT_PATH)
endfunction ()
function(create_javadoc _target)
set(_javadoc_packages)
set(_javadoc_files)
set(_javadoc_sourcepath)
set(_javadoc_classpath)
set(_javadoc_installpath "${CMAKE_INSTALL_PREFIX}/share/javadoc")
set(_javadoc_doctitle)
set(_javadoc_windowtitle)
set(_javadoc_author FALSE)
set(_javadoc_version FALSE)
set(_javadoc_use FALSE)
set(_state "package")
foreach (arg ${ARGN})
if (${_state} STREQUAL "package")
if (${arg} STREQUAL "PACKAGES")
set(_state "packages")
elseif (${arg} STREQUAL "FILES")
set(_state "files")
elseif (${arg} STREQUAL "SOURCEPATH")
set(_state "sourcepath")
elseif (${arg} STREQUAL "CLASSPATH")
set(_state "classpath")
elseif (${arg} STREQUAL "INSTALLPATH")
set(_state "installpath")
elseif (${arg} STREQUAL "DOCTITLE")
set(_state "doctitle")
elseif (${arg} STREQUAL "WINDOWTITLE")
set(_state "windowtitle")
elseif (${arg} STREQUAL "AUTHOR")
set(_state "author")
elseif (${arg} STREQUAL "USE")
set(_state "use")
elseif (${arg} STREQUAL "VERSION")
set(_state "version")
else ()
set(_javadoc_packages ${arg})
set(_state "packages")
endif ()
elseif (${_state} STREQUAL "packages")
if (${arg} STREQUAL "FILES")
set(_state "files")
elseif (${arg} STREQUAL "SOURCEPATH")
set(_state "sourcepath")
elseif (${arg} STREQUAL "CLASSPATH")
set(_state "classpath")
elseif (${arg} STREQUAL "INSTALLPATH")
set(_state "installpath")
elseif (${arg} STREQUAL "DOCTITLE")
set(_state "doctitle")
elseif (${arg} STREQUAL "WINDOWTITLE")
set(_state "windowtitle")
elseif (${arg} STREQUAL "AUTHOR")
set(_state "author")
elseif (${arg} STREQUAL "USE")
set(_state "use")
elseif (${arg} STREQUAL "VERSION")
set(_state "version")
else ()
list(APPEND _javadoc_packages ${arg})
endif ()
elseif (${_state} STREQUAL "files")
if (${arg} STREQUAL "PACKAGES")
set(_state "packages")
elseif (${arg} STREQUAL "SOURCEPATH")
set(_state "sourcepath")
elseif (${arg} STREQUAL "CLASSPATH")
set(_state "classpath")
elseif (${arg} STREQUAL "INSTALLPATH")
set(_state "installpath")
elseif (${arg} STREQUAL "DOCTITLE")
set(_state "doctitle")
elseif (${arg} STREQUAL "WINDOWTITLE")
set(_state "windowtitle")
elseif (${arg} STREQUAL "AUTHOR")
set(_state "author")
elseif (${arg} STREQUAL "USE")
set(_state "use")
elseif (${arg} STREQUAL "VERSION")
set(_state "version")
else ()
list(APPEND _javadoc_files ${arg})
endif ()
elseif (${_state} STREQUAL "sourcepath")
if (${arg} STREQUAL "PACKAGES")
set(_state "packages")
elseif (${arg} STREQUAL "FILES")
set(_state "files")
elseif (${arg} STREQUAL "CLASSPATH")
set(_state "classpath")
elseif (${arg} STREQUAL "INSTALLPATH")
set(_state "installpath")
elseif (${arg} STREQUAL "DOCTITLE")
set(_state "doctitle")
elseif (${arg} STREQUAL "WINDOWTITLE")
set(_state "windowtitle")
elseif (${arg} STREQUAL "AUTHOR")
set(_state "author")
elseif (${arg} STREQUAL "USE")
set(_state "use")
elseif (${arg} STREQUAL "VERSION")
set(_state "version")
else ()
list(APPEND _javadoc_sourcepath ${arg})
endif ()
elseif (${_state} STREQUAL "classpath")
if (${arg} STREQUAL "PACKAGES")
set(_state "packages")
elseif (${arg} STREQUAL "FILES")
set(_state "files")
elseif (${arg} STREQUAL "SOURCEPATH")
set(_state "sourcepath")
elseif (${arg} STREQUAL "INSTALLPATH")
set(_state "installpath")
elseif (${arg} STREQUAL "DOCTITLE")
set(_state "doctitle")
elseif (${arg} STREQUAL "WINDOWTITLE")
set(_state "windowtitle")
elseif (${arg} STREQUAL "AUTHOR")
set(_state "author")
elseif (${arg} STREQUAL "USE")
set(_state "use")
elseif (${arg} STREQUAL "VERSION")
set(_state "version")
else ()
list(APPEND _javadoc_classpath ${arg})
endif ()
elseif (${_state} STREQUAL "installpath")
if (${arg} STREQUAL "PACKAGES")
set(_state "packages")
elseif (${arg} STREQUAL "FILES")
set(_state "files")
elseif (${arg} STREQUAL "SOURCEPATH")
set(_state "sourcepath")
elseif (${arg} STREQUAL "DOCTITLE")
set(_state "doctitle")
elseif (${arg} STREQUAL "WINDOWTITLE")
set(_state "windowtitle")
elseif (${arg} STREQUAL "AUTHOR")
set(_state "author")
elseif (${arg} STREQUAL "USE")
set(_state "use")
elseif (${arg} STREQUAL "VERSION")
set(_state "version")
else ()
set(_javadoc_installpath ${arg})
endif ()
elseif (${_state} STREQUAL "doctitle")
if (${arg} STREQUAL "PACKAGES")
set(_state "packages")
elseif (${arg} STREQUAL "FILES")
set(_state "files")
elseif (${arg} STREQUAL "SOURCEPATH")
set(_state "sourcepath")
elseif (${arg} STREQUAL "INSTALLPATH")
set(_state "installpath")
elseif (${arg} STREQUAL "CLASSPATH")
set(_state "classpath")
elseif (${arg} STREQUAL "WINDOWTITLE")
set(_state "windowtitle")
elseif (${arg} STREQUAL "AUTHOR")
set(_state "author")
elseif (${arg} STREQUAL "USE")
set(_state "use")
elseif (${arg} STREQUAL "VERSION")
set(_state "version")
else ()
set(_javadoc_doctitle ${arg})
endif ()
elseif (${_state} STREQUAL "windowtitle")
if (${arg} STREQUAL "PACKAGES")
set(_state "packages")
elseif (${arg} STREQUAL "FILES")
set(_state "files")
elseif (${arg} STREQUAL "SOURCEPATH")
set(_state "sourcepath")
elseif (${arg} STREQUAL "CLASSPATH")
set(_state "classpath")
elseif (${arg} STREQUAL "INSTALLPATH")
set(_state "installpath")
elseif (${arg} STREQUAL "DOCTITLE")
set(_state "doctitle")
elseif (${arg} STREQUAL "AUTHOR")
set(_state "author")
elseif (${arg} STREQUAL "USE")
set(_state "use")
elseif (${arg} STREQUAL "VERSION")
set(_state "version")
else ()
set(_javadoc_windowtitle ${arg})
endif ()
elseif (${_state} STREQUAL "author")
if (${arg} STREQUAL "PACKAGES")
set(_state "packages")
elseif (${arg} STREQUAL "FILES")
set(_state "files")
elseif (${arg} STREQUAL "SOURCEPATH")
set(_state "sourcepath")
elseif (${arg} STREQUAL "CLASSPATH")
set(_state "classpath")
elseif (${arg} STREQUAL "INSTALLPATH")
set(_state "installpath")
elseif (${arg} STREQUAL "DOCTITLE")
set(_state "doctitle")
elseif (${arg} STREQUAL "WINDOWTITLE")
set(_state "windowtitle")
elseif (${arg} STREQUAL "AUTHOR")
set(_state "author")
elseif (${arg} STREQUAL "USE")
set(_state "use")
elseif (${arg} STREQUAL "VERSION")
set(_state "version")
else ()
set(_javadoc_author ${arg})
endif ()
elseif (${_state} STREQUAL "use")
if (${arg} STREQUAL "PACKAGES")
set(_state "packages")
elseif (${arg} STREQUAL "FILES")
set(_state "files")
elseif (${arg} STREQUAL "SOURCEPATH")
set(_state "sourcepath")
elseif (${arg} STREQUAL "CLASSPATH")
set(_state "classpath")
elseif (${arg} STREQUAL "INSTALLPATH")
set(_state "installpath")
elseif (${arg} STREQUAL "DOCTITLE")
set(_state "doctitle")
elseif (${arg} STREQUAL "WINDOWTITLE")
set(_state "windowtitle")
elseif (${arg} STREQUAL "AUTHOR")
set(_state "author")
elseif (${arg} STREQUAL "USE")
set(_state "use")
elseif (${arg} STREQUAL "VERSION")
set(_state "version")
else ()
set(_javadoc_use ${arg})
endif ()
elseif (${_state} STREQUAL "version")
if (${arg} STREQUAL "PACKAGES")
set(_state "packages")
elseif (${arg} STREQUAL "FILES")
set(_state "files")
elseif (${arg} STREQUAL "SOURCEPATH")
set(_state "sourcepath")
elseif (${arg} STREQUAL "CLASSPATH")
set(_state "classpath")
elseif (${arg} STREQUAL "INSTALLPATH")
set(_state "installpath")
elseif (${arg} STREQUAL "DOCTITLE")
set(_state "doctitle")
elseif (${arg} STREQUAL "WINDOWTITLE")
set(_state "windowtitle")
elseif (${arg} STREQUAL "AUTHOR")
set(_state "author")
elseif (${arg} STREQUAL "USE")
set(_state "use")
elseif (${arg} STREQUAL "VERSION")
set(_state "version")
else ()
set(_javadoc_version ${arg})
endif ()
endif ()
endforeach ()
set(_javadoc_builddir ${CMAKE_CURRENT_BINARY_DIR}/javadoc/${_target})
set(_javadoc_options -d ${_javadoc_builddir})
if (_javadoc_sourcepath)
set(_start TRUE)
foreach(_path ${_javadoc_sourcepath})
if (_start)
set(_sourcepath ${_path})
set(_start FALSE)
else ()
set(_sourcepath ${_sourcepath}:${_path})
endif ()
endforeach()
set(_javadoc_options ${_javadoc_options} -sourcepath ${_sourcepath})
endif ()
if (_javadoc_classpath)
set(_start TRUE)
foreach(_path ${_javadoc_classpath})
if (_start)
set(_classpath ${_path})
set(_start FALSE)
else ()
set(_classpath ${_classpath}:${_path})
endif ()
endforeach()
set(_javadoc_options ${_javadoc_options} -classpath "${_classpath}")
endif ()
if (_javadoc_doctitle)
set(_javadoc_options ${_javadoc_options} -doctitle '${_javadoc_doctitle}')
endif ()
if (_javadoc_windowtitle)
set(_javadoc_options ${_javadoc_options} -windowtitle '${_javadoc_windowtitle}')
endif ()
if (_javadoc_author)
set(_javadoc_options ${_javadoc_options} -author)
endif ()
if (_javadoc_use)
set(_javadoc_options ${_javadoc_options} -use)
endif ()
if (_javadoc_version)
set(_javadoc_options ${_javadoc_options} -version)
endif ()
add_custom_target(${_target}_javadoc ALL
COMMAND ${Java_JAVADOC_EXECUTABLE} ${_javadoc_options}
${_javadoc_files}
${_javadoc_packages}
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
)
install(
DIRECTORY ${_javadoc_builddir}
DESTINATION ${_javadoc_installpath}
)
endfunction()
function (create_javah)
cmake_parse_arguments(_create_javah
""
"TARGET;GENERATED_FILES;OUTPUT_NAME;OUTPUT_DIR"
"CLASSES;CLASSPATH;DEPENDS"
${ARGN})
# ckeck parameters
if (NOT _create_javah_TARGET AND NOT _create_javah_GENERATED_FILES)
message (FATAL_ERROR "create_javah: TARGET or GENERATED_FILES must be specified.")
endif()
if (_create_javah_OUTPUT_NAME AND _create_javah_OUTPUT_DIR)
message (FATAL_ERROR "create_javah: OUTPUT_NAME and OUTPUT_DIR are mutually exclusive.")
endif()
if (NOT _create_javah_CLASSES)
message (FATAL_ERROR "create_javah: CLASSES is a required parameter.")
endif()
set (_output_files)
if (WIN32 AND NOT CYGWIN AND CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
set(_classpath_sep ";")
else ()
set(_classpath_sep ":")
endif()
# handle javah options
set (_javah_options)
if (_create_javah_CLASSPATH)
# CLASSPATH can specify directories, jar files or targets created with add_jar command
set (_classpath)
foreach (_path IN LISTS _create_javah_CLASSPATH)
if (TARGET ${_path})
get_target_property (_jar_path ${_path} JAR_FILE)
if (_jar_path)
list (APPEND _classpath "${_jar_path}")
list (APPEND _create_javah_DEPENDS "${_path}")
else()
message(SEND_ERROR "create_javah: CLASSPATH target ${_path} is not a jar.")
endif()
elseif (EXISTS "${_path}")
list (APPEND _classpath "${_path}")
if (NOT IS_DIRECTORY "${_path}")
list (APPEND _create_javah_DEPENDS "${_path}")
endif()
else()
message(SEND_ERROR "create_javah: CLASSPATH entry ${_path} does not exist.")
endif()
endforeach()
string (REPLACE ";" "${_classpath_sep}" _classpath "${_classpath}")
list (APPEND _javah_options -classpath ${_classpath})
endif()
if (_create_javah_OUTPUT_DIR)
list (APPEND _javah_options -d "${_create_javah_OUTPUT_DIR}")
endif()
if (_create_javah_OUTPUT_NAME)
list (APPEND _javah_options -o "${_create_javah_OUTPUT_NAME}")
set (_output_files "${_create_javah_OUTPUT_NAME}")
get_filename_component (_create_javah_OUTPUT_DIR "${_create_javah_OUTPUT_NAME}" DIRECTORY)
get_filename_component (_create_javah_OUTPUT_DIR "${_create_javah_OUTPUT_DIR}" ABSOLUTE)
endif()
if (NOT _create_javah_OUTPUT_DIR)
set (_create_javah_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}")
endif()
if (NOT _create_javah_OUTPUT_NAME)
# compute output names
foreach (_class IN LISTS _create_javah_CLASSES)
string (REPLACE "." "_" _c_header "${_class}")
set (_c_header "${_create_javah_OUTPUT_DIR}/${_c_header}.h")
list (APPEND _output_files "${_c_header}")
endforeach()
endif()
# finalize custom command arguments
if (_create_javah_DEPENDS)
list (INSERT _create_javah_DEPENDS 0 DEPENDS)
endif()
add_custom_command (OUTPUT ${_output_files}
COMMAND "${Java_JAVAH_EXECUTABLE}" ${_javah_options} -jni ${_create_javah_CLASSES}
${_create_javah_DEPENDS}
WORKING_DIRECTORY ${_create_javah_OUTPUT_DIR}
COMMENT "Building C header files from classes...")
if (_create_javah_TARGET)
add_custom_target (${_create_javah_TARGET} ALL DEPENDS ${_output_files})
endif()
if (_create_javah_GENERATED_FILES)
set (${_create_javah_GENERATED_FILES} ${_output_files} PARENT_SCOPE)
endif()
endfunction()
+58
View File
@@ -0,0 +1,58 @@
#.rst:
# UseJavaClassFilelist
# --------------------
#
#
#
#
#
# This script create a list of compiled Java class files to be added to
# a jar file. This avoids including cmake files which get created in
# the binary directory.
#=============================================================================
# Copyright 2010-2011 Andreas schneider <asn@redhat.com>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
if (CMAKE_JAVA_CLASS_OUTPUT_PATH)
if (EXISTS "${CMAKE_JAVA_CLASS_OUTPUT_PATH}")
set(_JAVA_GLOBBED_FILES)
if (CMAKE_JAR_CLASSES_PREFIX)
foreach(JAR_CLASS_PREFIX ${CMAKE_JAR_CLASSES_PREFIX})
message(STATUS "JAR_CLASS_PREFIX: ${JAR_CLASS_PREFIX}")
file(GLOB_RECURSE _JAVA_GLOBBED_TMP_FILES "${CMAKE_JAVA_CLASS_OUTPUT_PATH}/${JAR_CLASS_PREFIX}/*.class")
if (_JAVA_GLOBBED_TMP_FILES)
list(APPEND _JAVA_GLOBBED_FILES ${_JAVA_GLOBBED_TMP_FILES})
endif ()
endforeach()
else()
file(GLOB_RECURSE _JAVA_GLOBBED_FILES "${CMAKE_JAVA_CLASS_OUTPUT_PATH}/*.class")
endif ()
set(_JAVA_CLASS_FILES)
# file(GLOB_RECURSE foo RELATIVE) is broken so we need this.
foreach(_JAVA_GLOBBED_FILE ${_JAVA_GLOBBED_FILES})
file(RELATIVE_PATH _JAVA_CLASS_FILE ${CMAKE_JAVA_CLASS_OUTPUT_PATH} ${_JAVA_GLOBBED_FILE})
set(_JAVA_CLASS_FILES ${_JAVA_CLASS_FILES}${_JAVA_CLASS_FILE}\n)
endforeach()
# write to file
file(WRITE ${CMAKE_JAVA_CLASS_OUTPUT_PATH}/java_class_filelist ${_JAVA_CLASS_FILES})
else ()
message(SEND_ERROR "FATAL: Java class output path doesn't exist")
endif ()
else ()
message(SEND_ERROR "FATAL: Can't find CMAKE_JAVA_CLASS_OUTPUT_PATH")
endif ()
+38
View File
@@ -0,0 +1,38 @@
#.rst:
# UseJavaSymlinks
# ---------------
#
#
#
#
#
# Helper script for UseJava.cmake
#=============================================================================
# Copyright 2010-2011 Andreas schneider <asn@redhat.com>
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)
if (UNIX AND _JAVA_TARGET_OUTPUT_LINK)
if (_JAVA_TARGET_OUTPUT_NAME)
find_program(LN_EXECUTABLE
NAMES
ln
)
execute_process(
COMMAND ${LN_EXECUTABLE} -sf "${_JAVA_TARGET_OUTPUT_NAME}" "${_JAVA_TARGET_OUTPUT_LINK}"
WORKING_DIRECTORY ${_JAVA_TARGET_DIR}
)
else ()
message(SEND_ERROR "FATAL: Can't find _JAVA_TARGET_OUTPUT_NAME")
endif ()
endif ()
+14
View File
@@ -14,6 +14,7 @@ set (${HDF5_PACKAGE_NAME}_VALID_COMPONENTS
HL
CXX_HL
Fortran_HL
Java
Tools
)
@@ -23,6 +24,7 @@ set (${HDF5_PACKAGE_NAME}_VALID_COMPONENTS
set (${HDF5_PACKAGE_NAME}_ENABLE_PARALLEL @HDF5_ENABLE_PARALLEL@)
set (${HDF5_PACKAGE_NAME}_BUILD_FORTRAN @HDF5_BUILD_FORTRAN@)
set (${HDF5_PACKAGE_NAME}_BUILD_CPP_LIB @HDF5_BUILD_CPP_LIB@)
set (${HDF5_PACKAGE_NAME}_BUILD_JAVA @HDF5_BUILD_JAVA@)
set (${HDF5_PACKAGE_NAME}_BUILD_TOOLS @HDF5_BUILD_TOOLS@)
set (${HDF5_PACKAGE_NAME}_BUILD_HL_LIB @HDF5_BUILD_HL_LIB@)
set (${HDF5_PACKAGE_NAME}_ENABLE_Z_LIB_SUPPORT @HDF5_ENABLE_Z_LIB_SUPPORT@)
@@ -40,6 +42,16 @@ if (${HDF5_PACKAGE_NAME}_ENABLE_PARALLEL)
set (${HDF5_PACKAGE_NAME}_MPI_C_LIBRARIES "@MPI_C_LIBRARIES@")
endif ()
if (${HDF5_PACKAGE_NAME}_BUILD_JAVA)
set (${HDF5_PACKAGE_NAME}_JAVA_INCLUDE_DIRS
@PACKAGE_CURRENT_BUILD_DIR@/lib/jarhdf5-@HDF5_VERSION_STRING@.jar
@PACKAGE_CURRENT_BUILD_DIR@/lib/slf4j-api-1.7.5.jar
@PACKAGE_CURRENT_BUILD_DIR@/lib/slf4j-nop-1.7.5.jar
)
set (${HDF5_PACKAGE_NAME}_JAVA_LIBRARY "@PACKAGE_CURRENT_BUILD_DIR@/lib")
set (${HDF5_PACKAGE_NAME}_JAVA_LIBRARIES "${${HDF5_PACKAGE_NAME}_JAVA_LIBRARY}")
endif()
#-----------------------------------------------------------------------------
# Directories
#-----------------------------------------------------------------------------
@@ -123,6 +135,8 @@ foreach (libtype IN LISTS ${HDF5_PACKAGE_NAME}_LIB_TYPE)
set (hdf5_comp "hdf5_hl")
elseif (${comp} STREQUAL "CXX_HL")
set (hdf5_comp "hdf5_hl_cpp")
elseif (${comp} STREQUAL "Java")
set (hdf5_comp "hdf5_java")
elseif (${comp} STREQUAL "Tools")
set (hdf5_comp "hdf5_tools")
elseif (${comp} STREQUAL "Fortran")
+212
View File
@@ -0,0 +1,212 @@
# runTest.cmake executes a command and captures the output in a file. File is then compared
# against a reference file. Exit status of command can also be compared.
cmake_policy(SET CMP0007 NEW)
# arguments checking
if (NOT TEST_TESTER)
message (FATAL_ERROR "Require TEST_TESTER to be defined")
endif (NOT TEST_TESTER)
if (NOT TEST_PROGRAM)
message (FATAL_ERROR "Require TEST_PROGRAM to be defined")
endif (NOT TEST_PROGRAM)
if (NOT TEST_LIBRARY_DIRECTORY)
message (STATUS "Require TEST_LIBRARY_DIRECTORY to be defined")
endif (NOT TEST_LIBRARY_DIRECTORY)
if (NOT TEST_FOLDER)
message ( FATAL_ERROR "Require TEST_FOLDER to be defined")
endif (NOT TEST_FOLDER)
if (NOT TEST_OUTPUT)
message (FATAL_ERROR "Require TEST_OUTPUT to be defined")
endif (NOT TEST_OUTPUT)
if (NOT TEST_CLASSPATH)
message (STATUS "Require TEST_CLASSPATH to be defined")
endif (NOT TEST_CLASSPATH)
if (NOT TEST_REFERENCE)
message (FATAL_ERROR "Require TEST_REFERENCE to be defined")
endif (NOT TEST_REFERENCE)
if (NOT TEST_ERRREF)
set (ERROR_APPEND 1)
endif (NOT TEST_ERRREF)
if (NOT TEST_LOG_LEVEL)
set (LOG_LEVEL "info")
else (NOT TEST_LOG_LEVEL)
set (LOG_LEVEL "${TEST_LOG_LEVEL}")
endif (NOT TEST_LOG_LEVEL)
message (STATUS "COMMAND: ${TEST_TESTER} -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=${LOG_LEVEL} -Djava.library.path=\"${TEST_LIBRARY_DIRECTORY}\" -cp \"${TEST_CLASSPATH}\" ${TEST_ARGS} ${TEST_PROGRAM} ${ARGN}")
if (WIN32 AND NOT MINGW)
set (ENV{PATH} "$ENV{PATH}\\;${TEST_LIBRARY_DIRECTORY}")
endif (WIN32 AND NOT MINGW)
# run the test program, capture the stdout/stderr and the result var
execute_process (
COMMAND ${TEST_TESTER} -Xmx1024M
-Dorg.slf4j.simpleLogger.defaultLogLevel=${LOG_LEVEL}
-Djava.library.path=${TEST_LIBRARY_DIRECTORY}
-cp "${TEST_CLASSPATH}" ${TEST_ARGS} ${TEST_PROGRAM}
${ARGN}
WORKING_DIRECTORY ${TEST_FOLDER}
RESULT_VARIABLE TEST_RESULT
OUTPUT_FILE ${TEST_OUTPUT}
ERROR_FILE ${TEST_OUTPUT}.err
ERROR_VARIABLE TEST_ERROR
)
message (STATUS "COMMAND Result: ${TEST_RESULT}")
if (EXISTS ${TEST_FOLDER}/${TEST_OUTPUT}.err)
file (READ ${TEST_FOLDER}/${TEST_OUTPUT}.err TEST_STREAM)
if (TEST_MASK_FILE)
STRING(REGEX REPLACE "CurrentDir is [^\n]+\n" "CurrentDir is (dir name)\n" TEST_STREAM "${TEST_STREAM}")
endif (TEST_MASK_FILE)
if (ERROR_APPEND)
file (APPEND ${TEST_FOLDER}/${TEST_OUTPUT} "${TEST_STREAM}")
else (ERROR_APPEND)
file (WRITE ${TEST_FOLDER}/${TEST_OUTPUT}.err "${TEST_STREAM}")
endif (ERROR_APPEND)
endif (EXISTS ${TEST_FOLDER}/${TEST_OUTPUT}.err)
if (TEST_MASK_ERROR)
if (NOT TEST_ERRREF)
file (READ ${TEST_FOLDER}/${TEST_OUTPUT} TEST_STREAM)
else (NOT TEST_ERRREF)
file (READ ${TEST_FOLDER}/${TEST_OUTPUT}.err TEST_STREAM)
endif (NOT TEST_ERRREF)
string (REGEX REPLACE "Time:[^\n]+\n" "Time: XXXX\n" TEST_STREAM "${TEST_STREAM}")
string (REGEX REPLACE "thread [0-9]*:" "thread (IDs):" TEST_STREAM "${TEST_STREAM}")
string (REGEX REPLACE ": ([^\n]*)[.]c " ": (file name) " TEST_STREAM "${TEST_STREAM}")
string (REGEX REPLACE " line [0-9]*" " line (number)" TEST_STREAM "${TEST_STREAM}")
#string (REGEX REPLACE "v[1-9]*[.][0-9]*[.]" "version (number)." TEST_STREAM "${TEST_STREAM}")
string (REGEX REPLACE "HDF5 .[1-9]*[.][0-9]*[.][0-9]*[^)]*" "HDF5 (version (number)" TEST_STREAM "${TEST_STREAM}")
string (REGEX REPLACE "H5Eget_auto[1-2]*" "H5Eget_auto(1 or 2)" TEST_STREAM "${TEST_STREAM}")
string (REGEX REPLACE "H5Eset_auto[1-2]*" "H5Eset_auto(1 or 2)" TEST_STREAM "${TEST_STREAM}")
if (NOT TEST_ERRREF)
file (WRITE ${TEST_FOLDER}/${TEST_OUTPUT} "${TEST_STREAM}")
else (NOT TEST_ERRREF)
file (WRITE ${TEST_FOLDER}/${TEST_OUTPUT}.err "${TEST_STREAM}")
endif (NOT TEST_ERRREF)
endif (TEST_MASK_ERROR)
# if the return value is !=0 bail out
if (NOT ${TEST_RESULT} STREQUAL ${TEST_EXPECT})
message (STATUS "ERROR OUTPUT: ${TEST_STREAM}")
message (FATAL_ERROR "Failed: Test program ${TEST_PROGRAM} exited != 0.\n${TEST_ERROR}")
endif (NOT ${TEST_RESULT} STREQUAL ${TEST_EXPECT})
message (STATUS "COMMAND Error: ${TEST_ERROR}")
if (NOT TEST_SKIP_COMPARE)
if (WIN32 AND NOT MINGW)
file (READ ${TEST_FOLDER}/${TEST_REFERENCE} TEST_STREAM)
file (WRITE ${TEST_FOLDER}/${TEST_REFERENCE} "${TEST_STREAM}")
endif (WIN32 AND NOT MINGW)
# now compare the output with the reference
execute_process (
COMMAND ${CMAKE_COMMAND} -E compare_files ${TEST_FOLDER}/${TEST_OUTPUT} ${TEST_FOLDER}/${TEST_REFERENCE}
RESULT_VARIABLE TEST_RESULT
)
if (NOT ${TEST_RESULT} STREQUAL 0)
set (TEST_RESULT 0)
file (STRINGS ${TEST_FOLDER}/${TEST_OUTPUT} test_act)
list (LENGTH test_act len_act)
file (STRINGS ${TEST_FOLDER}/${TEST_REFERENCE} test_ref)
list (LENGTH test_ref len_ref)
if (NOT ${len_act} STREQUAL "0")
MATH (EXPR _FP_LEN "${len_ref} - 1")
foreach (line RANGE 0 ${_FP_LEN})
list (GET test_act ${line} str_act)
list (GET test_ref ${line} str_ref)
if (NOT "${str_act}" STREQUAL "${str_ref}")
if (NOT "${str_act}" STREQUAL "")
set (TEST_RESULT 1)
message ("line = ${line}\n***ACTUAL: ${str_act}\n****REFER: ${str_ref}\n")
endif (NOT "${str_act}" STREQUAL "")
endif (NOT "${str_act}" STREQUAL "${str_ref}")
endforeach (line RANGE 0 ${_FP_LEN})
endif (NOT ${len_act} STREQUAL "0")
if (NOT ${len_act} STREQUAL ${len_ref})
set (TEST_RESULT 1)
endif (NOT ${len_act} STREQUAL ${len_ref})
endif (NOT ${TEST_RESULT} STREQUAL 0)
message (STATUS "COMPARE Result: ${TEST_RESULT}")
# again, if return value is !=0 scream and shout
if (NOT ${TEST_RESULT} STREQUAL 0)
message (FATAL_ERROR "Failed: The output of ${TEST_OUTPUT} did not match ${TEST_REFERENCE}")
endif (NOT ${TEST_RESULT} STREQUAL 0)
if (TEST_ERRREF)
if (WIN32 AND NOT MINGW)
file (READ ${TEST_FOLDER}/${TEST_ERRREF} TEST_STREAM)
file (WRITE ${TEST_FOLDER}/${TEST_ERRREF} "${TEST_STREAM}")
endif (WIN32 AND NOT MINGW)
# now compare the error output with the error reference
execute_process (
COMMAND ${CMAKE_COMMAND} -E compare_files ${TEST_FOLDER}/${TEST_OUTPUT}.err ${TEST_FOLDER}/${TEST_ERRREF}
RESULT_VARIABLE TEST_RESULT
)
if (NOT ${TEST_RESULT} STREQUAL 0)
set (TEST_RESULT 0)
file (STRINGS ${TEST_FOLDER}/${TEST_OUTPUT}.err test_act)
list (LENGTH test_act len_act)
file (STRINGS ${TEST_FOLDER}/${TEST_ERRREF} test_ref)
list (LENGTH test_ref len_ref)
MATH (EXPR _FP_LEN "${len_ref} - 1")
if (NOT ${len_act} STREQUAL "0")
MATH (EXPR _FP_LEN "${len_ref} - 1")
foreach (line RANGE 0 ${_FP_LEN})
list (GET test_act ${line} str_act)
list (GET test_ref ${line} str_ref)
if (NOT "${str_act}" STREQUAL "${str_ref}")
if (NOT "${str_act}" STREQUAL "")
set (TEST_RESULT 1)
message ("line = ${line}\n***ACTUAL: ${str_act}\n****REFER: ${str_ref}\n")
endif (NOT "${str_act}" STREQUAL "")
endif (NOT "${str_act}" STREQUAL "${str_ref}")
endforeach (line RANGE 0 ${_FP_LEN})
endif (NOT ${len_act} STREQUAL "0")
if (NOT ${len_act} STREQUAL ${len_ref})
set (TEST_RESULT 1)
endif (NOT ${len_act} STREQUAL ${len_ref})
endif (NOT ${TEST_RESULT} STREQUAL 0)
message (STATUS "COMPARE Result: ${TEST_RESULT}")
# again, if return value is !=0 scream and shout
if (NOT ${TEST_RESULT} STREQUAL 0)
message (FATAL_ERROR "Failed: The error output of ${TEST_OUTPUT}.err did not match ${TEST_ERRREF}")
endif (NOT ${TEST_RESULT} STREQUAL 0)
endif (TEST_ERRREF)
endif (NOT TEST_SKIP_COMPARE)
if (TEST_GREP_COMPARE)
# now grep the output with the reference
file (READ ${TEST_FOLDER}/${TEST_OUTPUT} TEST_STREAM)
# TEST_REFERENCE should always be matched
string (REGEX MATCH "${TEST_REFERENCE}" TEST_MATCH ${TEST_STREAM})
string (COMPARE EQUAL "${TEST_REFERENCE}" "${TEST_MATCH}" TEST_RESULT)
if (${TEST_RESULT} STREQUAL "0")
message (FATAL_ERROR "Failed: The output of ${TEST_PROGRAM} did not contain ${TEST_REFERENCE}")
endif (${TEST_RESULT} STREQUAL "0")
string (REGEX MATCH "${TEST_FILTER}" TEST_MATCH ${TEST_STREAM})
if (${TEST_EXPECT} STREQUAL "1")
# TEST_EXPECT (1) interperts TEST_FILTER as NOT to match
string (LENGTH "${TEST_MATCH}" TEST_RESULT)
if (NOT ${TEST_RESULT} STREQUAL "0")
message (FATAL_ERROR "Failed: The output of ${TEST_PROGRAM} did contain ${TEST_FILTER}")
endif (NOT ${TEST_RESULT} STREQUAL "0")
endif (${TEST_EXPECT} STREQUAL "0")
endif (TEST_GREP_COMPARE)
# everything went fine...
message ("${TEST_PROGRAM} Passed")
+34 -22
View File
@@ -1,43 +1,50 @@
SUMMARY OF THE HDF5 CONFIGURATION
=================================
SUMMARY OF THE HDF5 CONFIGURATION
=================================
General Information:
-------------------
HDF5 Version: @HDF5_PACKAGE_VERSION_STRING@
Configured on: @CONFIG_DATE@
Configured by: @CMAKE_GENERATOR@
Configure mode: CMAKE @CMAKE_VERSION@
Host system: @CMAKE_HOST_SYSTEM@
Uname information: @CMAKE_SYSTEM_NAME@
Byte sex: @BYTESEX@
Libraries: @BUILD_NAME_EXT@
Installation point: @CMAKE_INSTALL_PREFIX@
Compiling Options:
------------------
Compilation Mode: @CMAKE_BUILD_TYPE@
C Compiler: @CMAKE_C_COMPILER@
CFLAGS: @CMAKE_C_FLAGS@
H5_CFLAGS: @H5_CFLAGS@
AM_CFLAGS: @AM_CFLAGS@
CPPFLAGS: @CPPFLAGS@
H5_CPPFLAGS: @H5_CPPFLAGS@
AM_CPPFLAGS: @AM_CPPFLAGS@
Shared C Library: @H5_ENABLE_SHARED_LIB@
Static C Library: @H5_ENABLE_STATIC_LIB@
Build Mode: @CMAKE_BUILD_TYPE@
Debugging Symbols: @SYMBOLS@
Asserts: @ASSERTS@
Profiling: @PROFILING@
Optimization Level: @OPTIMIZATION@
Linking Options:
----------------
Libraries: @BUILD_NAME_EXT@
Statically Linked Executables: @BUILD_STATIC_EXECS@
LDFLAGS: @CMAKE_SHARED_LINKER_FLAGS@
H5_LDFLAGS: @H5_LDFLAGS@
AM_LDFLAGS: @AM_LDFLAGS@
Extra libraries: @LINK_LIBS@
Archiver: @CMAKE_AR@
Ranlib: @CMAKE_RANLIB@
Debugged Packages: @DEBUG_PKG@
API Tracing: @HDF5_ENABLE_TRACE@
Languages:
----------
C: yes
C Compiler: @CMAKE_C_COMPILER@ @CMAKE_C_COMPILER_VERSION@
CPPFLAGS: @CPPFLAGS@
H5_CPPFLAGS: @H5_CPPFLAGS@
AM_CPPFLAGS: @AM_CPPFLAGS@
CFLAGS: @CMAKE_C_FLAGS@
H5_CFLAGS: @H5_CFLAGS@
AM_CFLAGS: @AM_CFLAGS@
Shared C Library: @H5_ENABLE_SHARED_LIB@
Static C Library: YES
Fortran: @HDF5_BUILD_FORTRAN@
@BUILD_FORTRAN_CONDITIONAL_TRUE@ Fortran Compiler: @CMAKE_Fortran_COMPILER@
@BUILD_FORTRAN_CONDITIONAL_TRUE@ Fortran Compiler: @CMAKE_Fortran_COMPILER@ @CMAKE_Fortran_COMPILER_VERSION@
@BUILD_FORTRAN_CONDITIONAL_TRUE@ Fortran Flags: @CMAKE_Fortran_FLAGS@
@BUILD_FORTRAN_CONDITIONAL_TRUE@ H5 Fortran Flags: @H5_FCFLAGS@
@BUILD_FORTRAN_CONDITIONAL_TRUE@ AM Fortran Flags: @AM_FCFLAGS@
@@ -45,27 +52,32 @@ Languages:
@BUILD_FORTRAN_CONDITIONAL_TRUE@ Static Fortran Library: YES
C++: @HDF5_BUILD_CPP_LIB@
@BUILD_CXX_CONDITIONAL_TRUE@ C++ Compiler: @CMAKE_CXX_COMPILER@
@BUILD_CXX_CONDITIONAL_TRUE@ C++ Compiler: @CMAKE_CXX_COMPILER@ @CMAKE_CXX_COMPILER_VERSION@
@BUILD_CXX_CONDITIONAL_TRUE@ C++ Flags: @CMAKE_CXX_FLAGS@
@BUILD_CXX_CONDITIONAL_TRUE@ H5 C++ Flags: @H5_CXXFLAGS@
@BUILD_CXX_CONDITIONAL_TRUE@ AM C++ Flags: @AM_CXXFLAGS@
@BUILD_CXX_CONDITIONAL_TRUE@ Shared C++ Library: @H5_ENABLE_SHARED_LIB@
@BUILD_CXX_CONDITIONAL_TRUE@ Static C++ Library: YES
JAVA: @HDF5_BUILD_JAVA@
@BUILD_JAVA_CONDITIONAL_TRUE@ JAVA Compiler: @CMAKE_Java_COMPILER@ @Java_VERSION@
Features:
---------
Parallel HDF5: @HDF5_ENABLE_PARALLEL@
High Level library: @HDF5_BUILD_HL_LIB@
High-level library: @HDF5_BUILD_HL_LIB@
Threadsafety: @HDF5_ENABLE_THREADSAFE@
Default API Mapping: @DEFAULT_API_VERSION@
With Deprecated Public Symbols: @HDF5_ENABLE_DEPRECATED_SYMBOLS@
Default API mapping: @DEFAULT_API_VERSION@
With deprecated public symbols: @HDF5_ENABLE_DEPRECATED_SYMBOLS@
I/O filters (external): @EXTERNAL_FILTERS@
MPE: @H5_HAVE_LIBLMPE@
Direct VFD: @H5_HAVE_DIRECT@
dmalloc: @H5_HAVE_LIBDMALLOC@
Clear file buffers before write: @HDF5_Enable_Clear_File_Buffers@
Packages w/ extra debug output: @INTERNAL_DEBUG_OUTPUT@
API Tracing: @HDF5_ENABLE_TRACE@
Using memory checker: @HDF5_ENABLE_USING_MEMCHECKER@
Memory allocation sanity checks: @HDF5_MEMORY_ALLOC_SANITY_CHECK@
Metadata trace file: @METADATATRACEFILE@
Function Stack Tracing: @HDF5_ENABLE_CODESTACK@
Strict File Format Checks: @HDF5_STRICT_FORMAT_CHECKS@
Optimization Instrumentation: @HDF5_Enable_Instrument@
+1
View File
@@ -37,6 +37,7 @@ LIBH5TEST=$(top_builddir)/test/libh5test.la
LIBH5F=$(top_builddir)/fortran/src/libhdf5_fortran.la
LIBH5FTEST=$(top_builddir)/fortran/test/libh5test_fortran.la
LIBH5CPP=$(top_builddir)/c++/src/libhdf5_cpp.la
LIBH5JNI=$(top_builddir)/java/src/jni/libhdf5_java.la
LIBH5TOOLS=$(top_builddir)/tools/lib/libh5tools.la
LIBH5_HL=$(top_builddir)/hl/src/libhdf5_hl.la
LIBH5F_HL=$(top_builddir)/hl/fortran/src/libhdf5hl_fortran.la
+105 -1
View File
@@ -100,6 +100,7 @@ AC_CONFIG_COMMANDS([pubconf], [
AC_CANONICAL_HOST
AC_SUBST([CPPFLAGS])
AC_SUBST([JNIFLAGS])
## H5_CFLAGS (and company) are for CFLAGS that should be used on HDF5, but
## not exported to h5cc (or h5fc, etc.)
@@ -107,6 +108,9 @@ AC_SUBST([H5_CFLAGS])
AC_SUBST([H5_CPPFLAGS])
AC_SUBST([H5_FCFLAGS])
AC_SUBST([H5_CXXFLAGS])
AC_SUBST([H5_JNIFLAGS])
AC_SUBST([H5_JAVACFLAGS])
AC_SUBST([H5_JAVAFLAGS])
AC_SUBST([H5_LDFLAGS])
## AM_CFLAGS (and company) are for CFLAGS that should be used on HDF5,
@@ -115,6 +119,9 @@ AC_SUBST([AM_CFLAGS])
AC_SUBST([AM_FCFLAGS])
AC_SUBST([AM_CXXFLAGS])
AC_SUBST([AM_CPPFLAGS])
AC_SUBST([AM_JNIFLAGS])
AC_SUBST([AM_JAVACFLAGS])
AC_SUBST([AM_JAVAFLAGS])
AC_SUBST([AM_LDFLAGS])
## Make sure flags are initialized.
@@ -122,11 +129,17 @@ AM_CFLAGS="${AM_CFLAGS}"
AM_CXXFLAGS="${AM_CXXFLAGS}"
AM_FCFLAGS="${AM_FCFLAGS}"
AM_CPPFLAGS="${AM_CPPFLAGS}"
AM_JNIFLAGS="${AM_JNIFLAGS}"
AM_JAVACFLAGS="${AM_JAVACFLAGS}"
AM_JAVAFLAGS="${AM_JAVAFLAGS}"
AM_LDFLAGS="${AM_LDFLAGS}"
CFLAGS="${CFLAGS}"
CXXFLAGS="${CXXFLAGS}"
FCFLAGS="${FCFLAGS}"
CPPFLAGS="${CPPFLAGS}"
JNIFLAGS="${JNIFLAGS}"
JAVACFLAGS="${JAVACFLAGS}"
JAVAFLAGS="${JAVAFLAGS}"
LDFLAGS="${LDFLAGS}"
## Configure may need to alter any of the *FLAGS variables in order for
@@ -135,6 +148,8 @@ LDFLAGS="${LDFLAGS}"
saved_user_CFLAGS="$CFLAGS"
saved_user_CXXFLAGS="$CXXFLAGS"
saved_user_FCFLAGS="$FCFLAGS"
saved_user_JAVACFLAGS="$JAVACFLAGS"
saved_user_JAVAFLAGS="$JAVAFLAGS"
saved_user_LDFLAGS="$LDFLAGS"
saved_user_CPPFLAGS="$CPPFLAGS"
@@ -326,6 +341,8 @@ esac
## reset this value at the end of configure, to preserve the user's settings.
CFLAGS="${AM_CFLAGS} ${CFLAGS}"
FCFLAGS="${AM_FCFLAGS} ${FCFLAGS}"
JAVACFLAGS="${AM_JAVACFLAGS} ${JAVACFLAGS}"
JAVAFLAGS="${AM_JAVAFLAGS} ${JAVAFLAGS}"
CXXFLAGS="${AM_CXXFLAGS} ${CXXFLAGS}"
CPPFLAGS="${AM_CPPFLAGS} ${CPPFLAGS}"
LDFLAGS="${AM_LDFLAGS} ${LDFLAGS}"
@@ -834,6 +851,55 @@ case "`uname`" in
;;
esac
## ----------------------------------------------------------------------
## Check if they would like the Java native interface (JNI) compiled
##
AC_SUBST([H5_CLASSPATH]) H5_CLASSPATH=""
AC_MSG_CHECKING([if Java JNI interface enabled])
AC_ARG_ENABLE([java],
[AS_HELP_STRING([--enable-java],
[Compile the Java JNI interface [default=no]])],
[HDF_JAVA=$enableval],
[HDF_JAVA=no])
if test "X$HDF_JAVA" = "Xyes" && test "X${enable_shared}" != "Xno"; then
echo "yes"
if test "X$CLASSPATH" = "X"; then
H5_CLASSPATH=".:$srcdir/java/lib"
else
H5_CLASSPATH=".:$CLASSPATH:$srcdir/java/lib"
fi
## Checks for programs.
AX_JAVA_OPTIONS
H5_JAVACFLAGS=$JAVACFLAGS
H5_JAVAFLAGS=$JAVAFLAGS
AX_PROG_JAVAC
AX_PROG_JAVA
AX_PROG_JAR
AX_PROG_JAVADOC
## Find the include directories needed for building JNI code
AX_JNI_INCLUDE_DIR()
for JNI_INCLUDE_DIR in $JNI_INCLUDE_DIRS
do
JNIFLAGS="$JNIFLAGS -I$JNI_INCLUDE_DIR"
done
## Find junit for testing the JNI code
AX_CHECK_CLASSPATH()
CLASSPATH_ENV=$H5_CLASSPATH
AX_CHECK_JUNIT()
AX_CHECK_JAVA_HOME
AC_MSG_RESULT([yes])
else
if test "X${enable_shared}" = "Xno"; then
AC_MSG_ERROR([Java requires shared libraries to be built])
fi
HDF_JAVA="no"
AC_MSG_RESULT([no])
fi
## ----------------------------------------------------------------------
## Fortran libraries are not currently supported on Mac. Disable them.
## (this is overridable with --enable-unsupported).
@@ -3071,7 +3137,7 @@ CXX_NOFLAGS=`echo $CXX | sed 's/ -.*//'`
if `echo $CXX_NOFLAGS | grep ^/ >/dev/null 2>&1`; then
CXX_VERSION="$CXX"
else
CXX_VERSION="$FC";
CXX_VERSION="$CXX";
for x in `echo $PATH | sed -e 's/:/ /g'`; do
if test -x $x/$CXX_NOFLAGS; then
CXX_VERSION="$x/$CXX"
@@ -3083,6 +3149,27 @@ if test -n "$cxx_version_info"; then
CXX_VERSION="$CXX_VERSION ( $cxx_version_info)"
fi
AC_SUBST([JAVA_VERSION])
## Strip anything that looks like a flag off of $JAVA
JAVA_NOFLAGS=`echo $JAVA | sed 's/ -.*//'`
if `echo $JAVA_NOFLAGS | grep ^/ >/dev/null 2>&1`; then
JAVA_VERSION="$JAVA"
else
JAVA_VERSION="$JAVA";
for x in `echo $PATH | sed -e 's/:/ /g'`; do
if test -x $x/$JAVA_NOFLAGS; then
JAVA_VERSION="$x/$JAVA"
break
fi
done
fi
java_version_info=`$JAVA -version 2>&1 |\
grep 'version' | sed -e 's/version "//' | sed -e 's/"//'`
if test -n "$java_version_info"; then
JAVA_VERSION="$JAVA_VERSION ( $java_version_info)"
fi
## ----------------------------------------------------------------------
## Where is the root of the source tree. Give an absolute address so
## we can find it no matter which directory of the distribution is our
@@ -3296,6 +3383,8 @@ CFLAGS="$saved_user_CFLAGS"
FCFLAGS="$saved_user_FCFLAGS"
CXXFLAGS="$saved_user_CXXFLAGS"
CPPFLAGS="$saved_user_CPPFLAGS"
JAVACFLAGS="$saved_user_JAVACFLAGS"
JAVAFLAGS="$saved_user_JAVAFLAGS"
LDFLAGS="$saved_user_LDFLAGS"
@@ -3306,6 +3395,7 @@ LDFLAGS="$saved_user_LDFLAGS"
AM_CONDITIONAL([BUILD_CXX_CONDITIONAL], [test "X$HDF_CXX" = "Xyes"])
AM_CONDITIONAL([BUILD_PARALLEL_CONDITIONAL], [test -n "$TESTPARALLEL"])
AM_CONDITIONAL([BUILD_FORTRAN_CONDITIONAL], [test "X$HDF_FORTRAN" = "Xyes"])
AM_CONDITIONAL([BUILD_JAVA_CONDITIONAL], [test "X$HDF_JAVA" = "Xyes"])
AM_CONDITIONAL([BUILD_HDF5_HL_CONDITIONAL], [test "X$HDF5_HL" = "Xyes"])
@@ -3451,6 +3541,20 @@ AC_CONFIG_FILES([src/libhdf5.settings
fortran/examples/Makefile
fortran/examples/run-fortran-ex.sh
fortran/examples/testh5fc.sh
java/Makefile
java/src/Makefile
java/src/jni/Makefile
java/test/Makefile
java/test/junit.sh
java/examples/Makefile
java/examples/intro/Makefile
java/examples/intro/runExample.sh
java/examples/datasets/Makefile
java/examples/datasets/runExample.sh
java/examples/datatypes/Makefile
java/examples/datatypes/runExample.sh
java/examples/groups/Makefile
java/examples/groups/runExample.sh
hl/Makefile
hl/src/Makefile
hl/test/Makefile
+2 -2
View File
@@ -139,7 +139,7 @@ if (BUILD_SHARED_LIBS AND NOT SKIP_HDF5_FORTRAN_SHARED)
TARGET_C_PROPERTIES (${HDF5_F90_C_LIBSH_TARGET} SHARED " " " ")
target_link_libraries (${HDF5_F90_C_LIBSH_TARGET} ${HDF5_LIBSH_TARGET} ${LINK_SHARED_LIBS})
set_global_variable (HDF5_LIBRARIES_TO_EXPORT "${HDF5_LIBRARIES_TO_EXPORT};${HDF5_F90_C_LIBSH_TARGET}")
H5_SET_LIB_OPTIONS (${HDF5_F90_C_LIBSH_TARGET} ${HDF5_F90_C_LIB_NAME} SHARED)
H5_SET_LIB_OPTIONS (${HDF5_F90_C_LIBSH_TARGET} ${HDF5_F90_C_LIB_NAME} SHARED ${HDF5_F_PACKAGE_SOVERSION})
set_target_properties (${HDF5_F90_C_LIBSH_TARGET} PROPERTIES
FOLDER libraries/fortran
LINKER_LANGUAGE C
@@ -235,7 +235,7 @@ if (BUILD_SHARED_LIBS AND NOT SKIP_HDF5_FORTRAN_SHARED)
target_link_libraries (${HDF5_F90_LIBSH_TARGET} ${MPI_Fortran_LIBRARIES})
endif (H5_HAVE_PARALLEL AND MPI_Fortran_FOUND)
set_global_variable (HDF5_LIBRARIES_TO_EXPORT "${HDF5_LIBRARIES_TO_EXPORT};${HDF5_F90_LIBSH_TARGET}")
H5_SET_LIB_OPTIONS (${HDF5_F90_LIBSH_TARGET} ${HDF5_F90_LIB_NAME} SHARED)
H5_SET_LIB_OPTIONS (${HDF5_F90_LIBSH_TARGET} ${HDF5_F90_LIB_NAME} SHARED ${HDF5_F_PACKAGE_SOVERSION})
set_target_properties (${HDF5_F90_LIBSH_TARGET} PROPERTIES
FOLDER libraries/fortran
LINKER_LANGUAGE Fortran
+2 -2
View File
@@ -65,7 +65,7 @@ if (BUILD_SHARED_LIBS AND NOT SKIP_HDF5_FORTRAN_SHARED)
${HDF5_F90_C_LIBSH_TARGET}
${HDF5_TEST_LIBSH_TARGET}
)
H5_SET_LIB_OPTIONS (${HDF5_F90_C_TEST_LIBSH_TARGET} ${HDF5_F90_C_TEST_LIB_NAME} SHARED)
H5_SET_LIB_OPTIONS (${HDF5_F90_C_TEST_LIBSH_TARGET} ${HDF5_F90_C_TEST_LIB_NAME} SHARED ${HDF5_PACKAGE_SOVERSION})
set_target_properties (${HDF5_F90_C_TEST_LIBSH_TARGET} PROPERTIES
FOLDER libraries/test/fortran
LINKER_LANGUAGE C
@@ -128,7 +128,7 @@ if (BUILD_SHARED_LIBS AND NOT SKIP_HDF5_FORTRAN_SHARED)
${HDF5_F90_LIBSH_TARGET}
${HDF5_LIBSH_TARGET}
)
H5_SET_LIB_OPTIONS (${HDF5_F90_TEST_LIBSH_TARGET} ${HDF5_F90_TEST_LIB_NAME} SHARED)
H5_SET_LIB_OPTIONS (${HDF5_F90_TEST_LIBSH_TARGET} ${HDF5_F90_TEST_LIB_NAME} SHARED ${HDF5_PACKAGE_SOVERSION})
target_include_directories (${HDF5_F90_TEST_LIBSH_TARGET} PRIVATE ${CMAKE_Fortran_MODULE_DIRECTORY}/shared)
set_target_properties (${HDF5_F90_TEST_LIBSH_TARGET} PROPERTIES
FOLDER libraries/test/fortran
+1 -1
View File
@@ -34,7 +34,7 @@ if (BUILD_SHARED_LIBS)
${HDF5_LIBSH_TARGET}
)
set_global_variable (HDF5_LIBRARIES_TO_EXPORT "${HDF5_LIBRARIES_TO_EXPORT};${HDF5_HL_CPP_LIBSH_TARGET}")
H5_SET_LIB_OPTIONS (${HDF5_HL_CPP_LIBSH_TARGET} ${HDF5_HL_CPP_LIB_NAME} SHARED)
H5_SET_LIB_OPTIONS (${HDF5_HL_CPP_LIBSH_TARGET} ${HDF5_HL_CPP_LIB_NAME} SHARED ${HDF5_HL_CXX_PACKAGE_SOVERSION})
set_target_properties (${HDF5_HL_CPP_LIBSH_TARGET} PROPERTIES
FOLDER libraries/hl
COMPILE_DEFINITIONS "H5_BUILT_AS_DYNAMIC_LIB"
+2 -2
View File
@@ -91,7 +91,7 @@ if (BUILD_SHARED_LIBS AND NOT SKIP_HDF5_FORTRAN_SHARED)
TARGET_C_PROPERTIES (${HDF5_HL_F90_C_LIBSH_TARGET} SHARED " " " ")
target_link_libraries (${HDF5_HL_F90_C_LIBSH_TARGET} ${HDF5_F90_C_LIBSH_TARGET} ${HDF5_HL_LIBSH_TARGET})
set_global_variable (HDF5_LIBRARIES_TO_EXPORT "${HDF5_LIBRARIES_TO_EXPORT};${HDF5_HL_F90_C_LIBSH_TARGET}")
H5_SET_LIB_OPTIONS (${HDF5_HL_F90_C_LIBSH_TARGET} ${HDF5_HL_F90_C_LIB_NAME} SHARED)
H5_SET_LIB_OPTIONS (${HDF5_HL_F90_C_LIBSH_TARGET} ${HDF5_HL_F90_C_LIB_NAME} SHARED ${HDF5_HL_F_PACKAGE_SOVERSION})
set_target_properties (${HDF5_HL_F90_C_LIBSH_TARGET} PROPERTIES
FOLDER libraries/hl/fortran
LINKER_LANGUAGE C
@@ -163,7 +163,7 @@ if (BUILD_SHARED_LIBS AND NOT SKIP_HDF5_FORTRAN_SHARED)
TARGET_FORTRAN_PROPERTIES (${HDF5_HL_F90_LIBSH_TARGET} SHARED " " ${SHARED_LINK_FLAGS})
target_link_libraries (${HDF5_HL_F90_LIBSH_TARGET} ${HDF5_HL_F90_C_LIBSH_TARGET} ${HDF5_F90_LIBSH_TARGET})
set_global_variable (HDF5_LIBRARIES_TO_EXPORT "${HDF5_LIBRARIES_TO_EXPORT};${HDF5_HL_F90_LIBSH_TARGET}")
H5_SET_LIB_OPTIONS (${HDF5_HL_F90_LIBSH_TARGET} ${HDF5_HL_F90_LIB_NAME} SHARED)
H5_SET_LIB_OPTIONS (${HDF5_HL_F90_LIBSH_TARGET} ${HDF5_HL_F90_LIB_NAME} SHARED ${HDF5_HL_F_PACKAGE_SOVERSION})
set_target_properties (${HDF5_HL_F90_LIBSH_TARGET} PROPERTIES
FOLDER libraries/hl/fortran
LINKER_LANGUAGE Fortran
+1 -1
View File
@@ -42,7 +42,7 @@ if (BUILD_SHARED_LIBS)
add_library (${HDF5_HL_LIBSH_TARGET} SHARED ${HL_SRCS} ${HL_HEADERS})
TARGET_C_PROPERTIES (${HDF5_HL_LIBSH_TARGET} SHARED " " " ")
target_link_libraries (${HDF5_HL_LIBSH_TARGET} ${HDF5_LIBSH_TARGET})
H5_SET_LIB_OPTIONS (${HDF5_HL_LIBSH_TARGET} ${HDF5_HL_LIB_NAME} SHARED)
H5_SET_LIB_OPTIONS (${HDF5_HL_LIBSH_TARGET} ${HDF5_HL_LIB_NAME} SHARED ${HDF5_HL_PACKAGE_SOVERSION})
set_target_properties (${HDF5_HL_LIBSH_TARGET} PROPERTIES
FOLDER libraries/hl
COMPILE_DEFINITIONS "H5_BUILT_AS_DYNAMIC_LIB"
+77
View File
@@ -0,0 +1,77 @@
cmake_minimum_required(VERSION 3.1.0)
PROJECT ( HDF5_JAVA C Java )
set (CMAKE_MODULE_PATH "${HDF_RESOURCES_DIR};${HDF_RESOURCES_EXT_DIR}")
find_package (Java)
#-----------------------------------------------------------------------------
# Include some macros for reusable code
#-----------------------------------------------------------------------------
include (${HDF_RESOURCES_DIR}/UseJava.cmake)
message (STATUS "JAVA: JAVA_HOME=$ENV{JAVA_HOME} JAVA_ROOT=$ENV{JAVA_ROOT}")
find_package (JNI)
INCLUDE_DIRECTORIES ( ${JNI_INCLUDE_DIRS} )
#-----------------------------------------------------------------------------
# Include the main src and config directories
#-----------------------------------------------------------------------------
set (HDF5_JAVA_INCLUDE_DIRECTORIES
${HDF5_JAVA_JNI_SRC_DIR}
${JAVA_INCLUDE_PATH}
${JAVA_INCLUDE_PATH2}
)
INCLUDE_DIRECTORIES (${HDF5_JAVA_INCLUDE_DIRECTORIES})
set (CMAKE_JAVA_INCLUDE_PATH "")
#-----------------------------------------------------------------------------
# Traverse source subdirectory
#-----------------------------------------------------------------------------
add_subdirectory (${HDF5_JAVA_SOURCE_DIR}/src ${HDF5_JAVA_BINARY_DIR}/src)
#-----------------------------------------------------------------------------
# Build the Java Examples
#-----------------------------------------------------------------------------
if (HDF5_BUILD_EXAMPLES)
add_subdirectory (${HDF5_JAVA_SOURCE_DIR}/examples ${HDF5_JAVA_BINARY_DIR}/examples)
endif (HDF5_BUILD_EXAMPLES)
#-----------------------------------------------------------------------------
# Testing
#-----------------------------------------------------------------------------
if (BUILD_TESTING)
add_subdirectory (${HDF5_JAVA_SOURCE_DIR}/test ${HDF5_JAVA_BINARY_DIR}/test)
endif (BUILD_TESTING)
#-----------------------------------------------------------------------------
# Add Required Jar(s)
#-----------------------------------------------------------------------------
install (
FILES
${HDF5_JAVA_LOGGING_JAR}
${HDF5_JAVA_LOGGING_NOP_JAR}
${HDF5_JAVA_LOGGING_SIMPLE_JAR}
DESTINATION ${HDF5_INSTALL_JAR_DIR}
COMPONENT libraries
)
#-----------------------------------------------------------------------------
# Option to include jre
#-----------------------------------------------------------------------------
option (HDF5_JAVA_PACK_JRE "Package a JRE installer directory" OFF)
if (HDF5_JAVA_PACK_JRE)
if (WIN32)
install (
DIRECTORY "C:/Program Files/Java/jre8"
DESTINATION ${HDF5_INSTALL_BIN_DIR}
USE_SOURCE_PERMISSIONS
)
else (WIN32)
install (
DIRECTORY "/usr/lib/jvm/jre"
DESTINATION ${HDF5_INSTALL_BIN_DIR}
USE_SOURCE_PERMISSIONS
)
endif (WIN32)
endif (HDF5_JAVA_PACK_JRE)
+16
View File
@@ -0,0 +1,16 @@
Copyright by The HDF Group and
The Board of Trustees of the University of Illinois.
All rights reserved.
The files and subdirectories in this directory are part of HDF5.
The full HDF5 copyright notice, including terms governing use,
modification, and redistribution, is contained in the files COPYING
and Copyright.html. COPYING can be found at the root of the source
code distribution tree; Copyright.html can be found at the root
level of an installed copy of the electronic HDF5 document set and
is linked from the top-level documents page. It can also be found
at http://www.hdfgroup.org/HDF5/doc/Copyright.html. If you do not
have access to either file, you may request a copy from
help@hdfgroup.org.
+38
View File
@@ -0,0 +1,38 @@
#
# Copyright by The HDF Group.
# Copyright by the Board of Trustees of the University of Illinois.
# All rights reserved.
#
# This file is part of HDF5. The full HDF5 copyright notice, including
# terms governing use, modification, and redistribution, is contained in
# the files COPYING and Copyright.html. COPYING can be found at the root
# of the source code distribution tree; Copyright.html can be found at the
# root level of an installed copy of the electronic HDF5 document set and
# is linked from the top-level documents page. It can also be found at
# http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have
# access to either file, you may request a copy from help@hdfgroup.org.
#
#
# This makefile mostly just reinvokes make in the various subdirectories
# but does so in the correct order. You can alternatively invoke make from
# each subdirectory manually.
##
## Makefile.am
## Run automake to generate a Makefile.in from this file.
##
#
# HDF5 Java native interface (JNI) Library Makefile(.in)
include $(top_srcdir)/config/commence.am
## Only recurse into subdirectories if the Java (JNI) interface is enabled.
if BUILD_JAVA_CONDITIONAL
# Mark this directory as part of the JNI API
JAVA_API=yes
SUBDIRS=src test examples
endif
include $(top_srcdir)/config/conclude.am
+7
View File
@@ -0,0 +1,7 @@
cmake_minimum_required (VERSION 3.1.0)
PROJECT (HDFJAVA_EXAMPLES)
add_subdirectory (${HDFJAVA_EXAMPLES_SOURCE_DIR}/datasets datasets)
add_subdirectory (${HDFJAVA_EXAMPLES_SOURCE_DIR}/datatypes datatypes)
add_subdirectory (${HDFJAVA_EXAMPLES_SOURCE_DIR}/groups groups)
add_subdirectory (${HDFJAVA_EXAMPLES_SOURCE_DIR}/intro intro)
+31
View File
@@ -0,0 +1,31 @@
#
# Copyright by The HDF Group.
# Copyright by the Board of Trustees of the University of Illinois.
# All rights reserved.
#
# This file is part of HDF5. The full HDF5 copyright notice, including
# terms governing use, modification, and redistribution, is contained in
# the files COPYING and Copyright.html. COPYING can be found at the root
# of the source code distribution tree; Copyright.html can be found at the
# root level of an installed copy of the electronic HDF5 document set and
# is linked from the top-level documents page. It can also be found at
# http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have
# access to either file, you may request a copy from help@hdfgroup.org.
#
#
# This makefile mostly just reinvokes make in the various subdirectories
# but does so in the correct order. You can alternatively invoke make from
# each subdirectory manually.
##
## Makefile.am
## Run automake to generate a Makefile.in from this file.
##
#
# HDF5 Java Library Examples Makefile(.in)
include $(top_srcdir)/config/commence.am
## Only recurse into subdirectories if the Java (JNI) interface is enabled.
SUBDIRS=intro groups datasets datatypes
include $(top_srcdir)/config/conclude.am
+121
View File
@@ -0,0 +1,121 @@
cmake_minimum_required (VERSION 3.1.0)
PROJECT (HDFJAVA_EXAMPLES_DATASETS Java)
set (CMAKE_VERBOSE_MAKEFILE 1)
INCLUDE_DIRECTORIES (
${HDF5_JAVA_JNI_BINARY_DIR}
${HDF5_JAVA_HDF5_LIB_DIR}
)
set (HDF_JAVA_EXAMPLES
H5Ex_D_Alloc
H5Ex_D_Checksum
H5Ex_D_Chunk
H5Ex_D_Compact
H5Ex_D_External
H5Ex_D_FillValue
H5Ex_D_Gzip
H5Ex_D_Hyperslab
H5Ex_D_ReadWrite
H5Ex_D_Shuffle
H5Ex_D_Szip
H5Ex_D_UnlimitedAdd
H5Ex_D_UnlimitedGzip
H5Ex_D_UnlimitedMod
H5Ex_D_Nbit
H5Ex_D_Transform
H5Ex_D_Sofloat
H5Ex_D_Soint
)
if (WIN32)
set (CMAKE_JAVA_INCLUDE_FLAG_SEP ";")
else (WIN32)
set (CMAKE_JAVA_INCLUDE_FLAG_SEP ":")
endif (WIN32)
set (CMAKE_JAVA_INCLUDE_PATH "${HDF5_JAVA_JARS}")
set (CMAKE_JAVA_CLASSPATH ".")
foreach (CMAKE_INCLUDE_PATH ${CMAKE_JAVA_INCLUDE_PATH})
set (CMAKE_JAVA_CLASSPATH "${CMAKE_JAVA_CLASSPATH}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${CMAKE_INCLUDE_PATH}")
endforeach (CMAKE_INCLUDE_PATH)
foreach (example ${HDF_JAVA_EXAMPLES})
file (WRITE ${PROJECT_BINARY_DIR}/${example}_Manifest.txt
"Main-Class: examples.datasets.${example}
"
)
add_jar (${example} MANIFEST ${PROJECT_BINARY_DIR}/${example}_Manifest.txt ${example}.java)
get_target_property (${example}_JAR_FILE ${example} JAR_FILE)
# install_jar (${example} ${HJAVA_INSTALL_DATA_DIR}/examples examples)
get_target_property (${example}_CLASSPATH ${example} CLASSDIR)
add_dependencies (${example} ${HDF5_JAVA_HDF5_LIB_TARGET})
endforeach (example ${HDF_JAVA_EXAMPLES})
set (CMAKE_JAVA_INCLUDE_PATH "${HDF5_JAVA_JARS};${HDF5_JAVA_LOGGING_JAR};${HDF5_JAVA_LOGGING_NOP_JAR}")
set (CMAKE_JAVA_CLASSPATH ".")
foreach (HDFJAVA_JAR ${CMAKE_JAVA_INCLUDE_PATH})
set (CMAKE_JAVA_CLASSPATH "${CMAKE_JAVA_CLASSPATH}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${HDFJAVA_JAR}")
endforeach (HDFJAVA_JAR)
MACRO (ADD_H5_TEST resultfile resultcode)
add_test (
NAME JAVA_datasets-${resultfile}
COMMAND "${CMAKE_COMMAND}"
-D "TEST_TESTER=${CMAKE_Java_RUNTIME};${CMAKE_Java_RUNTIME_FLAGS}"
-D "TEST_CLASSPATH:STRING=${CMAKE_JAVA_CLASSPATH}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${${resultfile}_JAR_FILE}"
-D "TEST_ARGS:STRING=${ARGN}"
-D "TEST_PROGRAM=examples.datasets.${resultfile}"
-D "TEST_LIBRARY_DIRECTORY=${CMAKE_TEST_OUTPUT_DIRECTORY}"
-D "TEST_FOLDER=${HDFJAVA_EXAMPLES_BINARY_DIR}"
-D "TEST_OUTPUT=datasets/${resultfile}.out"
-D "TEST_EXPECT=${resultcode}"
-D "TEST_REFERENCE=datasets/${resultfile}.txt"
-P "${HDF_RESOURCES_DIR}/jrunTest.cmake"
)
if (NOT "${last_test}" STREQUAL "")
set_tests_properties (JAVA_datasets-${resultfile} PROPERTIES DEPENDS ${last_test})
endif (NOT "${last_test}" STREQUAL "")
set (last_test "JAVA_datasets-${resultfile}")
ENDMACRO (ADD_H5_TEST file)
if (BUILD_TESTING)
foreach (example ${HDF_JAVA_EXAMPLES})
if (${example} STREQUAL "H5Ex_D_External")
add_test (
NAME JAVA_datasets-${example}-clearall-objects
COMMAND ${CMAKE_COMMAND}
-E remove
${HDFJAVA_EXAMPLES_BINARY_DIR}/${example}.h5
${HDFJAVA_EXAMPLES_BINARY_DIR}/${example}.data
${example}.out
${example}.out.err
)
else (${example} STREQUAL "H5Ex_D_External")
add_test (
NAME JAVA_datasets-${example}-clearall-objects
COMMAND ${CMAKE_COMMAND}
-E remove
${HDFJAVA_EXAMPLES_BINARY_DIR}/${example}.h5
${example}.out
${example}.out.err
)
endif (${example} STREQUAL "H5Ex_D_External")
if (NOT "${last_test}" STREQUAL "")
set_tests_properties (JAVA_datasets-${example}-clearall-objects PROPERTIES DEPENDS ${last_test})
endif (NOT "${last_test}" STREQUAL "")
add_test (
NAME JAVA_datasets-${example}-copy-objects
COMMAND ${CMAKE_COMMAND}
-E copy_if_different
${HDFJAVA_EXAMPLES_SOURCE_DIR}/testfiles/examples.datasets.${example}.txt
${HDFJAVA_EXAMPLES_DATASETS_BINARY_DIR}/${example}.txt
)
set_tests_properties (JAVA_datasets-${example}-copy-objects PROPERTIES DEPENDS JAVA_datasets-${example}-clearall-objects)
set (last_test "JAVA_datasets-${example}-copy-objects")
ADD_H5_TEST (${example} 0)
endforeach (example ${HDF_JAVA_EXAMPLES})
endif (BUILD_TESTING)
+301
View File
@@ -0,0 +1,301 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to set the space allocation time
for a dataset. The program first creates two datasets,
one with the default allocation time (late) and one with
early allocation time, and displays whether each has been
allocated and their allocation size. Next, it writes data
to the datasets, and again displays whether each has been
allocated and their allocation size.
************************************************************/
package examples.datasets;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_D_Alloc {
private static String FILENAME = "H5Ex_D_Alloc.h5";
private static String DATASETNAME1 = "DS1";
private static String DATASETNAME2 = "DS2";
private static final int DIM_X = 4;
private static final int DIM_Y = 7;
private static final int FILLVAL = 99;
private static final int RANK = 2;
// Values for the status of space allocation
enum H5D_space_status {
H5D_SPACE_STATUS_ERROR(-1), H5D_SPACE_STATUS_NOT_ALLOCATED(0), H5D_SPACE_STATUS_PART_ALLOCATED(1), H5D_SPACE_STATUS_ALLOCATED(
2);
private static final Map<Integer, H5D_space_status> lookup = new HashMap<Integer, H5D_space_status>();
static {
for (H5D_space_status s : EnumSet.allOf(H5D_space_status.class))
lookup.put(s.getCode(), s);
}
private int code;
H5D_space_status(int space_status) {
this.code = space_status;
}
public int getCode() {
return this.code;
}
public static H5D_space_status get(int code) {
return lookup.get(code);
}
}
private static void allocation() {
long file_id = -1;
long filespace_id = -1;
long dataset_id1 = -1;
long dataset_id2 = -1;
long dcpl_id = -1;
long[] dims = { DIM_X, DIM_Y };
int[][] dset_data = new int[DIM_X][DIM_Y];
int space_status = 0;
long storage_size = 0;
// Initialize the dataset.
for (int indx = 0; indx < DIM_X; indx++)
for (int jndx = 0; jndx < DIM_Y; jndx++)
dset_data[indx][jndx] = FILLVAL;
// Create a file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
try {
filespace_id = H5.H5Screate_simple(RANK, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset creation property list, and set the chunk size.
try {
dcpl_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_CREATE);
}
catch (Exception e) {
e.printStackTrace();
}
// Set the allocation time to "early". This way we can be sure
// that reading from the dataset immediately after creation will
// return the fill value.
try {
if (dcpl_id >= 0)
H5.H5Pset_alloc_time(dcpl_id, HDF5Constants.H5D_ALLOC_TIME_EARLY);
}
catch (Exception e) {
e.printStackTrace();
}
System.out.println("Creating datasets...");
System.out.println(DATASETNAME1 + " has allocation time H5D_ALLOC_TIME_LATE");
System.out.println(DATASETNAME2 + " has allocation time H5D_ALLOC_TIME_EARLY");
System.out.println();
// Create the dataset using the dataset default creation property list.
try {
if ((file_id >= 0) && (filespace_id >= 0))
dataset_id1 = H5.H5Dcreate(file_id, DATASETNAME1, HDF5Constants.H5T_NATIVE_INT, filespace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset using the dataset creation property list.
try {
if ((file_id >= 0) && (filespace_id >= 0) && (dcpl_id >= 0))
dataset_id2 = H5.H5Dcreate(file_id, DATASETNAME2, HDF5Constants.H5T_NATIVE_INT, filespace_id,
HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Retrieve and print space status and storage size for dset1.
try {
if (dataset_id1 >= 0)
space_status = H5.H5Dget_space_status(dataset_id1);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id1 >= 0)
storage_size = H5.H5Dget_storage_size(dataset_id1);
}
catch (Exception e) {
e.printStackTrace();
}
String the_space = " ";
if (H5D_space_status.get(space_status) != H5D_space_status.H5D_SPACE_STATUS_ALLOCATED)
the_space += "not ";
System.out.println("Space for " + DATASETNAME1 + " has" + the_space + "been allocated.");
System.out.println("Storage size for " + DATASETNAME1 + " is: " + storage_size + " bytes.");
// Retrieve and print space status and storage size for dset2.
try {
if (dataset_id2 >= 0)
space_status = H5.H5Dget_space_status(dataset_id2);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id2 >= 0)
storage_size = H5.H5Dget_storage_size(dataset_id2);
}
catch (Exception e) {
e.printStackTrace();
}
the_space = " ";
if (H5D_space_status.get(space_status) != H5D_space_status.H5D_SPACE_STATUS_ALLOCATED)
the_space += "not ";
System.out.println("Space for " + DATASETNAME2 + " has" + the_space + "been allocated.");
System.out.println("Storage size for " + DATASETNAME2 + " is: " + storage_size + " bytes.");
System.out.println();
System.out.println("Writing data...");
System.out.println();
// Write the data to the datasets.
try {
if (dataset_id1 >= 0)
H5.H5Dwrite(dataset_id1, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data[0]);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id2 >= 0)
H5.H5Dwrite(dataset_id2, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data[0]);
}
catch (Exception e) {
e.printStackTrace();
}
// Retrieve and print space status and storage size for dset1.
try {
if (dataset_id1 >= 0)
space_status = H5.H5Dget_space_status(dataset_id1);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id1 >= 0)
storage_size = H5.H5Dget_storage_size(dataset_id1);
}
catch (Exception e) {
e.printStackTrace();
}
the_space = " ";
if (H5D_space_status.get(space_status) != H5D_space_status.H5D_SPACE_STATUS_ALLOCATED)
the_space += "not ";
System.out.println("Space for " + DATASETNAME1 + " has" + the_space + "been allocated.");
System.out.println("Storage size for " + DATASETNAME1 + " is: " + storage_size + " bytes.");
// Retrieve and print space status and storage size for dset2.
try {
if (dataset_id2 >= 0)
space_status = H5.H5Dget_space_status(dataset_id2);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id2 >= 0)
storage_size = H5.H5Dget_storage_size(dataset_id2);
}
catch (Exception e) {
e.printStackTrace();
}
the_space = " ";
if (H5D_space_status.get(space_status) != H5D_space_status.H5D_SPACE_STATUS_ALLOCATED)
the_space += "not ";
System.out.println("Space for " + DATASETNAME2 + " has" + the_space + "been allocated.");
System.out.println("Storage size for " + DATASETNAME2 + " is: " + storage_size + " bytes.");
System.out.println();
// End access to the dataset and release resources used by it.
try {
if (dcpl_id >= 0)
H5.H5Pclose(dcpl_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id1 >= 0)
H5.H5Dclose(dataset_id1);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id2 >= 0)
H5.H5Dclose(dataset_id2);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (filespace_id >= 0)
H5.H5Sclose(filespace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_D_Alloc.allocation();
}
}
+347
View File
@@ -0,0 +1,347 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to read and write data to a dataset
using the Fletcher32 checksum filter. The program first
checks if the Fletcher32 filter is available, then if it
is it writes integers to a dataset using Fletcher32, then
closes the file. Next, it reopens the file, reads back
the data, checks if the filter detected an error and
outputs the type of filter and the maximum value in the
dataset to the screen.
************************************************************/
package examples.datasets;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_D_Checksum {
private static String FILENAME = "H5Ex_D_Checksum.h5";
private static String DATASETNAME = "DS1";
private static final int DIM_X = 32;
private static final int DIM_Y = 64;
private static final int CHUNK_X = 4;
private static final int CHUNK_Y = 8;
private static final int RANK = 2;
private static final int NDIMS = 2;
// Values for the status of space allocation
enum H5Z_filter {
H5Z_FILTER_ERROR(-1), H5Z_FILTER_NONE(0), H5Z_FILTER_DEFLATE(1), H5Z_FILTER_SHUFFLE(2), H5Z_FILTER_FLETCHER32(3), H5Z_FILTER_SZIP(
4), H5Z_FILTER_NBIT(5), H5Z_FILTER_SCALEOFFSET(6), H5Z_FILTER_RESERVED(256), H5Z_FILTER_MAX(65535);
private static final Map<Integer, H5Z_filter> lookup = new HashMap<Integer, H5Z_filter>();
static {
for (H5Z_filter s : EnumSet.allOf(H5Z_filter.class))
lookup.put(s.getCode(), s);
}
private int code;
H5Z_filter(int layout_type) {
this.code = layout_type;
}
public int getCode() {
return this.code;
}
public static H5Z_filter get(int code) {
return lookup.get(code);
}
}
private static boolean checkFletcher32Filter() {
try {
int available = H5.H5Zfilter_avail(H5Z_filter.H5Z_FILTER_FLETCHER32.getCode());
if (available == 0) {
System.out.println("N-Bit filter not available.");
return false;
}
}
catch (Exception e) {
e.printStackTrace();
}
try {
int filter_info = H5.H5Zget_filter_info(HDF5Constants.H5Z_FILTER_FLETCHER32);
if (((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) == 0)
|| ((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) == 0)) {
System.out.println("N-Bit filter not available for encoding and decoding.");
return false;
}
}
catch (Exception e) {
e.printStackTrace();
}
return true;
}
private static void writeChecksum() {
long file_id = -1;
long filespace_id = -1;
long dataset_id = -1;
long dcpl_id = -1;
long[] dims = { DIM_X, DIM_Y };
long[] chunk_dims = { CHUNK_X, CHUNK_Y };
int[][] dset_data = new int[DIM_X][DIM_Y];
// Initialize data.
for (int indx = 0; indx < DIM_X; indx++)
for (int jndx = 0; jndx < DIM_Y; jndx++)
dset_data[indx][jndx] = indx * jndx - jndx;
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
try {
filespace_id = H5.H5Screate_simple(RANK, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset creation property list, add the N-Bit filter.
try {
dcpl_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_CREATE);
if (dcpl_id >= 0) {
H5.H5Pset_fletcher32(dcpl_id);
// Set the chunk size.
H5.H5Pset_chunk(dcpl_id, NDIMS, chunk_dims);
}
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset.
try {
if ((file_id >= 0) && (filespace_id >= 0) && (dcpl_id >= 0))
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, filespace_id,
HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the data to the dataset.
try {
if (dataset_id >= 0)
H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (dcpl_id >= 0)
H5.H5Pclose(dcpl_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (filespace_id >= 0)
H5.H5Sclose(filespace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void readChecksum() {
long file_id = -1;
long dataset_id = -1;
long dcpl_id = -1;
int[][] dset_data = new int[DIM_X][DIM_Y];
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Retrieve the dataset creation property list.
try {
if (dataset_id >= 0)
dcpl_id = H5.H5Dget_create_plist(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Retrieve and print the filter type. Here we only retrieve the
// first filter because we know that we only added one filter.
try {
if (dcpl_id >= 0) {
// Java lib requires a valid filter_name object and cd_values
int[] flags = { 0 };
long[] cd_nelmts = { 1 };
int[] cd_values = { 0 };
String[] filter_name = { "" };
int[] filter_config = { 0 };
int filter_type = -1;
filter_type = H5
.H5Pget_filter(dcpl_id, 0, flags, cd_nelmts, cd_values, 120, filter_name, filter_config);
System.out.print("Filter type is: ");
switch (H5Z_filter.get(filter_type)) {
case H5Z_FILTER_DEFLATE:
System.out.println("H5Z_FILTER_DEFLATE");
break;
case H5Z_FILTER_SHUFFLE:
System.out.println("H5Z_FILTER_SHUFFLE");
break;
case H5Z_FILTER_FLETCHER32:
System.out.println("H5Z_FILTER_FLETCHER32");
break;
case H5Z_FILTER_SZIP:
System.out.println("H5Z_FILTER_SZIP");
break;
default:
System.out.println("H5Z_FILTER_ERROR");
}
System.out.println();
}
}
catch (Exception e) {
e.printStackTrace();
}
// Read the data using the default properties.
try {
if (dataset_id >= 0) {
int status = H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL,
HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data);
// Check if the read was successful. Normally we do not perform
// error checking in these examples for the sake of clarity, but in
// this case we will make an exception because this is how the
// fletcher32 checksum filter reports data errors.
if (status < 0) {
System.out.print("Dataset read failed!");
try {
if (dcpl_id >= 0)
H5.H5Pclose(dcpl_id);
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
return;
}
}
}
catch (Exception e) {
e.printStackTrace();
}
// Find the maximum value in the dataset, to verify that it was read
// correctly.
int max = dset_data[0][0];
for (int indx = 0; indx < DIM_X; indx++) {
for (int jndx = 0; jndx < DIM_Y; jndx++)
if (max < dset_data[indx][jndx])
max = dset_data[indx][jndx];
}
// Print the maximum value.
System.out.println("Maximum value in " + DATASETNAME + " is: " + max);
// End access to the dataset and release resources used by it.
try {
if (dcpl_id >= 0)
H5.H5Pclose(dcpl_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
// Check if the Fletcher32 filter is available and can be used for
// both encoding and decoding. Normally we do not perform error
// checking in these examples for the sake of clarity, but in this
// case we will make an exception because this filter is an
// optional part of the hdf5 library.
// size to be the current size.
if (H5Ex_D_Checksum.checkFletcher32Filter()) {
H5Ex_D_Checksum.writeChecksum();
H5Ex_D_Checksum.readChecksum();
}
}
}
+366
View File
@@ -0,0 +1,366 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to create a chunked dataset. The
program first writes integers in a hyperslab selection to
a chunked dataset with dataspace dimensions of DIM_XxDIM_Y
and chunk size of CHUNK_XxCHUNK_Y, then closes the file.
Next, it reopens the file, reads back the data, and
outputs it to the screen. Finally it reads the data again
using a different hyperslab selection, and outputs
the result to the screen.
************************************************************/
package examples.datasets;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_D_Chunk {
private static String FILENAME = "H5Ex_D_Chunk.h5";
private static String DATASETNAME = "DS1";
private static final int DIM_X = 6;
private static final int DIM_Y = 8;
private static final int CHUNK_X = 4;
private static final int CHUNK_Y = 4;
private static final int RANK = 2;
private static final int NDIMS = 2;
// Values for the status of space allocation
enum H5D_layout {
H5D_LAYOUT_ERROR(-1), H5D_COMPACT(0), H5D_CONTIGUOUS(1), H5D_CHUNKED(2), H5D_NLAYOUTS(3);
private static final Map<Integer, H5D_layout> lookup = new HashMap<Integer, H5D_layout>();
static {
for (H5D_layout s : EnumSet.allOf(H5D_layout.class))
lookup.put(s.getCode(), s);
}
private int code;
H5D_layout(int layout_type) {
this.code = layout_type;
}
public int getCode() {
return this.code;
}
public static H5D_layout get(int code) {
return lookup.get(code);
}
}
private static void writeChunk() {
long file_id = -1;
long filespace_id = -1;
long dataset_id = -1;
long dcpl_id = -1;
long[] dims = { DIM_X, DIM_Y };
long[] chunk_dims = { CHUNK_X, CHUNK_Y };
int[][] dset_data = new int[DIM_X][DIM_Y];
// Initialize data to "1", to make it easier to see the selections.
for (int indx = 0; indx < DIM_X; indx++)
for (int jndx = 0; jndx < DIM_Y; jndx++)
dset_data[indx][jndx] = 1;
// Print the data to the screen.
System.out.println("Original Data:");
for (int indx = 0; indx < DIM_X; indx++) {
System.out.print(" [ ");
for (int jndx = 0; jndx < DIM_Y; jndx++)
System.out.print(dset_data[indx][jndx] + " ");
System.out.println("]");
}
System.out.println();
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
try {
filespace_id = H5.H5Screate_simple(RANK, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset creation property list.
try {
dcpl_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_CREATE);
}
catch (Exception e) {
e.printStackTrace();
}
// Set the chunk size.
try {
if (dcpl_id >= 0)
H5.H5Pset_chunk(dcpl_id, NDIMS, chunk_dims);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the chunked dataset.
try {
if ((file_id >= 0) && (filespace_id >= 0) && (dcpl_id >= 0))
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, filespace_id,
HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Define and select the first part of the hyperslab selection.
long[] start = { 0, 0 };
long[] stride = { 3, 3 };
long[] count = { 2, 3 };
long[] block = { 2, 2 };
try {
if ((filespace_id >= 0))
H5.H5Sselect_hyperslab(filespace_id, HDF5Constants.H5S_SELECT_SET, start, stride, count, block);
}
catch (Exception e) {
e.printStackTrace();
}
// Define and select the second part of the hyperslab selection,
// which is subtracted from the first selection by the use of
// H5S_SELECT_NOTB
block[0] = 1;
block[1] = 1;
try {
if ((filespace_id >= 0)) {
H5.H5Sselect_hyperslab(filespace_id, HDF5Constants.H5S_SELECT_NOTB, start, stride, count, block);
// Write the data to the dataset.
if (dataset_id >= 0)
H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, filespace_id,
HDF5Constants.H5P_DEFAULT, dset_data);
}
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (dcpl_id >= 0)
H5.H5Pclose(dcpl_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (filespace_id >= 0)
H5.H5Sclose(filespace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void readChunk() {
long file_id = -1;
long filespace_id = -1;
long dataset_id = -1;
long dcpl_id = -1;
int[][] dset_data = new int[DIM_X][DIM_Y];
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Retrieve the dataset creation property list.
try {
if (dataset_id >= 0)
dcpl_id = H5.H5Dget_create_plist(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Print the storage layout.
try {
if (dcpl_id >= 0) {
int layout_type = H5.H5Pget_layout(dcpl_id);
System.out.print("Storage layout for " + DATASETNAME + " is: ");
switch (H5D_layout.get(layout_type)) {
case H5D_COMPACT:
System.out.println("H5D_COMPACT");
break;
case H5D_CONTIGUOUS:
System.out.println("H5D_CONTIGUOUS");
break;
case H5D_CHUNKED:
System.out.println("H5D_CHUNKED");
break;
case H5D_LAYOUT_ERROR:
break;
case H5D_NLAYOUTS:
break;
default:
break;
}
System.out.println();
}
}
catch (Exception e) {
e.printStackTrace();
}
// Read the data using the default properties.
try {
if (dataset_id >= 0)
H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
System.out.println("Data as written to disk by hyberslabs:");
for (int indx = 0; indx < DIM_X; indx++) {
System.out.print(" [ ");
for (int jndx = 0; jndx < DIM_Y; jndx++)
System.out.print(dset_data[indx][jndx] + " ");
System.out.println("]");
}
System.out.println();
// Initialize the read array.
for (int indx = 0; indx < DIM_X; indx++)
for (int jndx = 0; jndx < DIM_Y; jndx++)
dset_data[indx][jndx] = 0;
// Define and select the hyperslab to use for reading.
try {
if (dataset_id >= 0) {
filespace_id = H5.H5Dget_space(dataset_id);
long[] start = { 0, 1 };
long[] stride = { 4, 4 };
long[] count = { 2, 2 };
long[] block = { 2, 3 };
if (filespace_id >= 0) {
H5.H5Sselect_hyperslab(filespace_id, HDF5Constants.H5S_SELECT_SET, start, stride, count, block);
// Read the data using the previously defined hyperslab.
if ((dataset_id >= 0) && (filespace_id >= 0))
H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, filespace_id,
HDF5Constants.H5P_DEFAULT, dset_data);
}
}
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
System.out.println("Data as read from disk by hyberslab:");
for (int indx = 0; indx < DIM_X; indx++) {
System.out.print(" [ ");
for (int jndx = 0; jndx < DIM_Y; jndx++)
System.out.print(dset_data[indx][jndx] + " ");
System.out.println("]");
}
System.out.println();
// End access to the dataset and release resources used by it.
try {
if (dcpl_id >= 0)
H5.H5Pclose(dcpl_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (filespace_id >= 0)
H5.H5Sclose(filespace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_D_Chunk.writeChunk();
H5Ex_D_Chunk.readChunk();
}
}
+289
View File
@@ -0,0 +1,289 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to read and write data to a compact
dataset. The program first writes integers to a compact
dataset with dataspace dimensions of DIM_XxDIM_Y, then
closes the file. Next, it reopens the file, reads back
the data, and outputs it to the screen.
************************************************************/
package examples.datasets;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_D_Compact {
private static String FILENAME = "H5Ex_D_Compact.h5";
private static String DATASETNAME = "DS1";
private static final int DIM_X = 4;
private static final int DIM_Y = 7;
private static final int RANK = 2;
// Values for the status of space allocation
enum H5D_layout {
H5D_LAYOUT_ERROR(-1), H5D_COMPACT(0), H5D_CONTIGUOUS(1), H5D_CHUNKED(2), H5D_NLAYOUTS(3);
private static final Map<Integer, H5D_layout> lookup = new HashMap<Integer, H5D_layout>();
static {
for (H5D_layout s : EnumSet.allOf(H5D_layout.class))
lookup.put(s.getCode(), s);
}
private int code;
H5D_layout(int layout_type) {
this.code = layout_type;
}
public int getCode() {
return this.code;
}
public static H5D_layout get(int code) {
return lookup.get(code);
}
}
private static void writeCompact() {
long file_id = -1;
long filespace_id = -1;
long dataset_id = -1;
long dcpl_id = -1;
long[] dims = { DIM_X, DIM_Y };
int[][] dset_data = new int[DIM_X][DIM_Y];
// Initialize data.
for (int indx = 0; indx < DIM_X; indx++)
for (int jndx = 0; jndx < DIM_Y; jndx++)
dset_data[indx][jndx] = indx * jndx - jndx;
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
try {
filespace_id = H5.H5Screate_simple(RANK, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset creation property list.
try {
dcpl_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_CREATE);
}
catch (Exception e) {
e.printStackTrace();
}
// Set the layout to compact.
try {
if (dcpl_id >= 0)
H5.H5Pset_layout(dcpl_id, H5D_layout.H5D_COMPACT.getCode());
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset. We will use all default properties for this example.
try {
if ((file_id >= 0) && (filespace_id >= 0) && (dcpl_id >= 0))
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, filespace_id,
HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the data to the dataset.
try {
if (dataset_id >= 0)
H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (dcpl_id >= 0)
H5.H5Pclose(dcpl_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (filespace_id >= 0)
H5.H5Sclose(filespace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void readCompact() {
long file_id = -1;
long filespace_id = -1;
long dataset_id = -1;
long dcpl_id = -1;
int[][] dset_data = new int[DIM_X][DIM_Y];
// Open file and dataset using the default properties.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Retrieve the dataset creation property list.
try {
if (dataset_id >= 0)
dcpl_id = H5.H5Dget_create_plist(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Print the storage layout.
try {
if (dcpl_id >= 0) {
int layout_type = H5.H5Pget_layout(dcpl_id);
System.out.print("Storage layout for " + DATASETNAME + " is: ");
switch (H5D_layout.get(layout_type)) {
case H5D_COMPACT:
System.out.println("H5D_COMPACT");
break;
case H5D_CONTIGUOUS:
System.out.println("H5D_CONTIGUOUS");
break;
case H5D_CHUNKED:
System.out.println("H5D_CHUNKED");
break;
case H5D_LAYOUT_ERROR:
break;
case H5D_NLAYOUTS:
break;
default:
break;
}
System.out.println();
}
}
catch (Exception e) {
e.printStackTrace();
}
// Read the data using the default properties.
try {
if (dataset_id >= 0)
H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
System.out.println("Data for " + DATASETNAME + " is: ");
for (int indx = 0; indx < DIM_X; indx++) {
System.out.print(" [ ");
for (int jndx = 0; jndx < DIM_Y; jndx++)
System.out.print(dset_data[indx][jndx] + " ");
System.out.println("]");
}
System.out.println();
// End access to the dataset and release resources used by it.
try {
if (dcpl_id >= 0)
H5.H5Pclose(dcpl_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (filespace_id >= 0)
H5.H5Sclose(filespace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_D_Compact.writeCompact();
H5Ex_D_Compact.readCompact();
}
}
+238
View File
@@ -0,0 +1,238 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to read and write data to an
external dataset. The program first writes integers to an
external dataset with dataspace dimensions of DIM_XxDIM_Y,
then closes the file. Next, it reopens the file, reads
back the data, and outputs the name of the external data
file and the data to the screen.
************************************************************/
package examples.datasets;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_D_External {
private static String FILENAME = "H5Ex_D_External.h5";
private static String EXTERNALNAME = "H5Ex_D_External.data";
private static String DATASETNAME = "DS1";
private static final int DIM_X = 4;
private static final int DIM_Y = 7;
private static final int RANK = 2;
private static final int NAME_BUF_SIZE = 32;
private static void writeExternal() {
long file_id = -1;
long dcpl_id = -1;
long filespace_id = -1;
long dataset_id = -1;
long[] dims = { DIM_X, DIM_Y };
int[][] dset_data = new int[DIM_X][DIM_Y];
// Initialize the dataset.
for (int indx = 0; indx < DIM_X; indx++)
for (int jndx = 0; jndx < DIM_Y; jndx++)
dset_data[indx][jndx] = indx * jndx - jndx;
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
try {
filespace_id = H5.H5Screate_simple(RANK, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset creation property list.
try {
dcpl_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_CREATE);
}
catch (Exception e) {
e.printStackTrace();
}
// set the external file.
try {
if (dcpl_id >= 0)
H5.H5Pset_external(dcpl_id, EXTERNALNAME, 0, HDF5Constants.H5F_UNLIMITED);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the HDF5Constants.dataset.
try {
if ((file_id >= 0) && (filespace_id >= 0) && (dcpl_id >= 0))
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, filespace_id,
HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the dataset.
try {
H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (filespace_id >= 0)
H5.H5Sclose(filespace_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dcpl_id >= 0)
H5.H5Pclose(dcpl_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void readExternal() {
long file_id = -1;
long dcpl_id = -1;
long dataset_id = -1;
int[][] dset_data = new int[DIM_X][DIM_Y];
String[] Xname = new String[1];
// Open file using the default properties.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDWR, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open dataset using the default properties.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Retrieve the dataset creation property list.
try {
if (dataset_id >= 0)
dcpl_id = H5.H5Dget_create_plist(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Retrieve and print the name of the external file.
long[] Xsize = new long[NAME_BUF_SIZE];
try {
if (dcpl_id >= 0)
H5.H5Pget_external(dcpl_id, 0, Xsize.length, Xname, Xsize);
}
catch (Exception e) {
e.printStackTrace();
}
System.out.println(DATASETNAME + " is stored in file: " + Xname[0]);
// Read the data using the default properties.
try {
if (dataset_id >= 0)
H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
System.out.println(DATASETNAME + ":");
for (int indx = 0; indx < DIM_X; indx++) {
System.out.print(" [ ");
for (int jndx = 0; jndx < DIM_Y; jndx++)
System.out.print(dset_data[indx][jndx] + " ");
System.out.println("]");
}
System.out.println();
// Close the dataset.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dcpl_id >= 0)
H5.H5Pclose(dcpl_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_D_External.writeExternal();
H5Ex_D_External.readExternal();
}
}
@@ -0,0 +1,246 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to set the fill value for a
dataset. The program first sets the fill value to
FILLVAL, creates a dataset with dimensions of DIM_XxDIM_Y,
reads from the uninitialized dataset, and outputs the
contents to the screen. Next, it writes integers to the
dataset, reads the data back, and outputs it to the
screen. Finally it extends the dataset, reads from it,
and outputs the result to the screen.
************************************************************/
package examples.datasets;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_D_FillValue {
private static String FILENAME = "H5Ex_D_FillValue.h5";
private static String DATASETNAME = "ExtendibleArray";
private static final int DIM_X = 4;
private static final int DIM_Y = 7;
private static final int EDIM_X = 6;
private static final int EDIM_Y = 10;
private static final int CHUNK_X = 4;
private static final int CHUNK_Y = 4;
private static final int RANK = 2;
private static final int NDIMS = 2;
private static final int FILLVAL = 99;
private static void fillValue() {
long file_id = -1;
long dcpl_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long[] dims = { DIM_X, DIM_Y };
long[] extdims = { EDIM_X, EDIM_Y };
long[] chunk_dims = { CHUNK_X, CHUNK_Y };
long[] maxdims = { HDF5Constants.H5S_UNLIMITED, HDF5Constants.H5S_UNLIMITED };
int[][] write_dset_data = new int[DIM_X][DIM_Y];
int[][] read_dset_data = new int[DIM_X][DIM_Y];
int[][] extend_dset_data = new int[EDIM_X][EDIM_Y];
// Initialize the dataset.
for (int indx = 0; indx < DIM_X; indx++)
for (int jndx = 0; jndx < DIM_Y; jndx++)
write_dset_data[indx][jndx] = indx * jndx - jndx;
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace with unlimited dimensions.
try {
dataspace_id = H5.H5Screate_simple(RANK, dims, maxdims);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset creation property list.
try {
dcpl_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_CREATE);
}
catch (Exception e) {
e.printStackTrace();
}
// Set the chunk size.
try {
if (dcpl_id >= 0)
H5.H5Pset_chunk(dcpl_id, NDIMS, chunk_dims);
}
catch (Exception e) {
e.printStackTrace();
}
// Set the fill value for the dataset
try {
int[] fill_value = { FILLVAL };
if (dcpl_id >= 0)
H5.H5Pset_fill_value(dcpl_id, HDF5Constants.H5T_NATIVE_INT, fill_value);
}
catch (Exception e) {
e.printStackTrace();
}
// Set the allocation time to "early". This way we can be sure
// that reading from the dataset immediately after creation will
// return the fill value.
try {
if (dcpl_id >= 0)
H5.H5Pset_alloc_time(dcpl_id, HDF5Constants.H5D_ALLOC_TIME_EARLY);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset using the dataset creation property list.
try {
if ((file_id >= 0) && (dataspace_id >= 0) && (dcpl_id >= 0))
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, dataspace_id,
HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Read values from the dataset, which has not been written to yet.
try {
if (dataset_id >= 0)
H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, read_dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
System.out.println("Dataset before being written to:");
for (int indx = 0; indx < DIM_X; indx++) {
System.out.print(" [ ");
for (int jndx = 0; jndx < DIM_Y; jndx++)
System.out.print(read_dset_data[indx][jndx] + " ");
System.out.println("]");
}
System.out.println();
// Write the data to the dataset.
try {
if (dataset_id >= 0)
H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, write_dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Read the data back.
try {
if (dataset_id >= 0)
H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, read_dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
System.out.println("Dataset after being written to:");
for (int indx = 0; indx < DIM_X; indx++) {
System.out.print(" [ ");
for (int jndx = 0; jndx < DIM_Y; jndx++)
System.out.print(read_dset_data[indx][jndx] + " ");
System.out.println("]");
}
System.out.println();
// Extend the dataset.
try {
if (dataset_id >= 0)
H5.H5Dset_extent(dataset_id, extdims);
}
catch (Exception e) {
e.printStackTrace();
}
// Read from the extended dataset.
try {
if (dataset_id >= 0)
H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, extend_dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
System.out.println("Dataset after extension:");
for (int indx = 0; indx < EDIM_X; indx++) {
System.out.print(" [ ");
for (int jndx = 0; jndx < EDIM_Y; jndx++)
System.out.print(extend_dset_data[indx][jndx] + " ");
System.out.println("]");
}
System.out.println();
// End access to the dataset and release resources used by it.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dcpl_id >= 0)
H5.H5Pclose(dcpl_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_D_FillValue.fillValue();
}
}
+336
View File
@@ -0,0 +1,336 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to read and write data to a dataset
using gzip compression (also called zlib or deflate). The
program first checks if gzip compression is available,
then if it is it writes integers to a dataset using gzip,
then closes the file. Next, it reopens the file, reads
back the data, and outputs the type of compression and the
maximum value in the dataset to the screen.
************************************************************/
package examples.datasets;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_D_Gzip {
private static String FILENAME = "H5Ex_D_Gzip.h5";
private static String DATASETNAME = "DS1";
private static final int DIM_X = 32;
private static final int DIM_Y = 64;
private static final int CHUNK_X = 4;
private static final int CHUNK_Y = 8;
private static final int RANK = 2;
private static final int NDIMS = 2;
// Values for the status of space allocation
enum H5Z_filter {
H5Z_FILTER_ERROR(HDF5Constants.H5Z_FILTER_ERROR), H5Z_FILTER_NONE(HDF5Constants.H5Z_FILTER_NONE), H5Z_FILTER_DEFLATE(
HDF5Constants.H5Z_FILTER_DEFLATE), H5Z_FILTER_SHUFFLE(HDF5Constants.H5Z_FILTER_SHUFFLE), H5Z_FILTER_FLETCHER32(
HDF5Constants.H5Z_FILTER_FLETCHER32), H5Z_FILTER_SZIP(HDF5Constants.H5Z_FILTER_SZIP), H5Z_FILTER_NBIT(
HDF5Constants.H5Z_FILTER_NBIT), H5Z_FILTER_SCALEOFFSET(HDF5Constants.H5Z_FILTER_SCALEOFFSET), H5Z_FILTER_RESERVED(
HDF5Constants.H5Z_FILTER_RESERVED), H5Z_FILTER_MAX(HDF5Constants.H5Z_FILTER_MAX);
private static final Map<Integer, H5Z_filter> lookup = new HashMap<Integer, H5Z_filter>();
static {
for (H5Z_filter s : EnumSet.allOf(H5Z_filter.class))
lookup.put(s.getCode(), s);
}
private int code;
H5Z_filter(int layout_type) {
this.code = layout_type;
}
public int getCode() {
return this.code;
}
public static H5Z_filter get(int code) {
return lookup.get(code);
}
}
private static boolean checkGzipFilter() {
try {
int available = H5.H5Zfilter_avail(HDF5Constants.H5Z_FILTER_DEFLATE);
if (available == 0) {
System.out.println("gzip filter not available.");
return false;
}
}
catch (Exception e) {
e.printStackTrace();
}
try {
int filter_info = H5.H5Zget_filter_info(HDF5Constants.H5Z_FILTER_DEFLATE);
if (((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) == 0)
|| ((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) == 0)) {
System.out.println("gzip filter not available for encoding and decoding.");
return false;
}
}
catch (Exception e) {
e.printStackTrace();
}
return true;
}
private static void writeGzip() {
long file_id = -1;
long filespace_id = -1;
long dataset_id = -1;
long dcpl_id = -1;
long[] dims = { DIM_X, DIM_Y };
long[] chunk_dims = { CHUNK_X, CHUNK_Y };
int[][] dset_data = new int[DIM_X][DIM_Y];
// Initialize data.
for (int indx = 0; indx < DIM_X; indx++)
for (int jndx = 0; jndx < DIM_Y; jndx++)
dset_data[indx][jndx] = indx * jndx - jndx;
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
try {
filespace_id = H5.H5Screate_simple(RANK, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset creation property list, add the gzip compression
// filter.
try {
dcpl_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_CREATE);
if (dcpl_id >= 0) {
H5.H5Pset_deflate(dcpl_id, 9);
// Set the chunk size.
H5.H5Pset_chunk(dcpl_id, NDIMS, chunk_dims);
}
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset.
try {
if ((file_id >= 0) && (filespace_id >= 0) && (dcpl_id >= 0))
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, filespace_id,
HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the data to the dataset.
try {
if (dataset_id >= 0)
H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (dcpl_id >= 0)
H5.H5Pclose(dcpl_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (filespace_id >= 0)
H5.H5Sclose(filespace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void readGzip() {
long file_id = -1;
long dataset_id = -1;
long dcpl_id = -1;
int[][] dset_data = new int[DIM_X][DIM_Y];
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Retrieve the dataset creation property list.
try {
if (dataset_id >= 0)
dcpl_id = H5.H5Dget_create_plist(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Retrieve and print the filter type. Here we only retrieve the
// first filter because we know that we only added one filter.
try {
if (dcpl_id >= 0) {
// Java lib requires a valid filter_name object and cd_values
int[] flags = { 0 };
long[] cd_nelmts = { 1 };
int[] cd_values = { 0 };
String[] filter_name = { "" };
int[] filter_config = { 0 };
int filter_type = -1;
filter_type = H5
.H5Pget_filter(dcpl_id, 0, flags, cd_nelmts, cd_values, 120, filter_name, filter_config);
System.out.print("Filter type is: ");
switch (H5Z_filter.get(filter_type)) {
case H5Z_FILTER_DEFLATE:
System.out.println("H5Z_FILTER_DEFLATE");
break;
case H5Z_FILTER_SHUFFLE:
System.out.println("H5Z_FILTER_SHUFFLE");
break;
case H5Z_FILTER_FLETCHER32:
System.out.println("H5Z_FILTER_FLETCHER32");
break;
case H5Z_FILTER_SZIP:
System.out.println("H5Z_FILTER_SZIP");
break;
case H5Z_FILTER_NBIT:
System.out.println("H5Z_FILTER_NBIT");
break;
case H5Z_FILTER_SCALEOFFSET:
System.out.println("H5Z_FILTER_SCALEOFFSET");
break;
default:
System.out.println("H5Z_FILTER_ERROR");
}
System.out.println();
}
}
catch (Exception e) {
e.printStackTrace();
}
// Read the data using the default properties.
try {
if (dataset_id >= 0) {
H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
}
catch (Exception e) {
e.printStackTrace();
}
// Find the maximum value in the dataset, to verify that it was read
// correctly.
int max = dset_data[0][0];
for (int indx = 0; indx < DIM_X; indx++) {
for (int jndx = 0; jndx < DIM_Y; jndx++)
if (max < dset_data[indx][jndx])
max = dset_data[indx][jndx];
}
// Print the maximum value.
System.out.println("Maximum value in " + DATASETNAME + " is: " + max);
// End access to the dataset and release resources used by it.
try {
if (dcpl_id >= 0)
H5.H5Pclose(dcpl_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
// Check if gzip compression is available and can be used for both
// compression and decompression. Normally we do not perform error
// checking in these examples for the sake of clarity, but in this
// case we will make an exception because this filter is an
// optional part of the hdf5 library.
if (H5Ex_D_Gzip.checkGzipFilter()) {
H5Ex_D_Gzip.writeGzip();
H5Ex_D_Gzip.readGzip();
}
}
}
@@ -0,0 +1,269 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to read and write data to a
dataset by hyberslabs. The program first writes integers
in a hyperslab selection to a dataset with dataspace
dimensions of DIM_XxDIM_Y, then closes the file. Next, it
reopens the file, reads back the data, and outputs it to
the screen. Finally it reads the data again using a
different hyperslab selection, and outputs the result to
the screen.
************************************************************/
package examples.datasets;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_D_Hyperslab {
private static String FILENAME = "H5Ex_D_Hyperslab.h5";
private static String DATASETNAME = "DS1";
private static final int DIM_X = 6;
private static final int DIM_Y = 8;
private static final int RANK = 2;
private static void writeHyperslab() {
long file_id = -1;
long filespace_id = -1;
long dataset_id = -1;
long[] dims = { DIM_X, DIM_Y };
int[][] dset_data = new int[DIM_X][DIM_Y];
// Initialize data to "1", to make it easier to see the selections.
for (int indx = 0; indx < DIM_X; indx++)
for (int jndx = 0; jndx < DIM_Y; jndx++)
dset_data[indx][jndx] = 1;
// Print the data to the screen.
System.out.println("Original Data:");
for (int indx = 0; indx < DIM_X; indx++) {
System.out.print(" [ ");
for (int jndx = 0; jndx < DIM_Y; jndx++)
System.out.print(dset_data[indx][jndx] + " ");
System.out.println("]");
}
System.out.println();
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
try {
filespace_id = H5.H5Screate_simple(RANK, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset. We will use all default properties for this example.
try {
if ((file_id >= 0) && (filespace_id >= 0))
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, filespace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Define and select the first part of the hyperslab selection.
long[] start = { 0, 0 };
long[] stride = { 3, 3 };
long[] count = { 2, 3 };
long[] block = { 2, 2 };
try {
if ((filespace_id >= 0))
H5.H5Sselect_hyperslab(filespace_id, HDF5Constants.H5S_SELECT_SET, start, stride, count, block);
}
catch (Exception e) {
e.printStackTrace();
}
// Define and select the second part of the hyperslab selection,
// which is subtracted from the first selection by the use of
// H5S_SELECT_NOTB
block[0] = 1;
block[1] = 1;
try {
if ((filespace_id >= 0)) {
H5.H5Sselect_hyperslab(filespace_id, HDF5Constants.H5S_SELECT_NOTB, start, stride, count, block);
// Write the data to the dataset.
if (dataset_id >= 0)
H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, filespace_id,
HDF5Constants.H5P_DEFAULT, dset_data);
}
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (filespace_id >= 0)
H5.H5Sclose(filespace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void readHyperslab() {
long file_id = -1;
long filespace_id = -1;
long dataset_id = -1;
long dcpl_id = -1;
int[][] dset_data = new int[DIM_X][DIM_Y];
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Read the data using the default properties.
try {
if (dataset_id >= 0)
H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
System.out.println("Data as written to disk by hyberslabs:");
for (int indx = 0; indx < DIM_X; indx++) {
System.out.print(" [ ");
for (int jndx = 0; jndx < DIM_Y; jndx++)
System.out.print(dset_data[indx][jndx] + " ");
System.out.println("]");
}
System.out.println();
// Initialize the read array.
for (int indx = 0; indx < DIM_X; indx++)
for (int jndx = 0; jndx < DIM_Y; jndx++)
dset_data[indx][jndx] = 0;
// Define and select the hyperslab to use for reading.
try {
if (dataset_id >= 0) {
filespace_id = H5.H5Dget_space(dataset_id);
long[] start = { 0, 1 };
long[] stride = { 4, 4 };
long[] count = { 2, 2 };
long[] block = { 2, 3 };
if (filespace_id >= 0) {
H5.H5Sselect_hyperslab(filespace_id, HDF5Constants.H5S_SELECT_SET, start, stride, count, block);
// Read the data using the previously defined hyperslab.
if ((dataset_id >= 0) && (filespace_id >= 0))
H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, filespace_id,
HDF5Constants.H5P_DEFAULT, dset_data);
}
}
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
System.out.println("Data as read from disk by hyberslab:");
for (int indx = 0; indx < DIM_X; indx++) {
System.out.print(" [ ");
for (int jndx = 0; jndx < DIM_Y; jndx++)
System.out.print(dset_data[indx][jndx] + " ");
System.out.println("]");
}
System.out.println();
// End access to the dataset and release resources used by it.
try {
if (dcpl_id >= 0)
H5.H5Pclose(dcpl_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (filespace_id >= 0)
H5.H5Sclose(filespace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_D_Hyperslab.writeHyperslab();
H5Ex_D_Hyperslab.readHyperslab();
}
}
+305
View File
@@ -0,0 +1,305 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to read and write data to a dataset
using the N-Bit filter. The program first checks if the
N-Bit filter is available, then if it is it writes integers
to a dataset using N-Bit, then closes the file. Next, it
reopens the file, reads back the data, and outputs the type
of filter and the maximum value in the dataset to the screen.
************************************************************/
package examples.datasets;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_D_Nbit {
private static String FILENAME = "H5Ex_D_Nbit.h5";
private static String DATASETNAME = "DS1";
private static final int DIM_X = 32;
private static final int DIM_Y = 64;
private static final int CHUNK_X = 4;
private static final int CHUNK_Y = 8;
private static final int RANK = 2;
private static final int NDIMS = 2;
// Values for the status of space allocation
enum H5Z_filter {
H5Z_FILTER_ERROR(HDF5Constants.H5Z_FILTER_ERROR), H5Z_FILTER_NONE(HDF5Constants.H5Z_FILTER_NONE), H5Z_FILTER_DEFLATE(
HDF5Constants.H5Z_FILTER_DEFLATE), H5Z_FILTER_SHUFFLE(HDF5Constants.H5Z_FILTER_SHUFFLE), H5Z_FILTER_FLETCHER32(
HDF5Constants.H5Z_FILTER_FLETCHER32), H5Z_FILTER_SZIP(HDF5Constants.H5Z_FILTER_SZIP), H5Z_FILTER_NBIT(
HDF5Constants.H5Z_FILTER_NBIT), H5Z_FILTER_SCALEOFFSET(HDF5Constants.H5Z_FILTER_SCALEOFFSET), H5Z_FILTER_RESERVED(
HDF5Constants.H5Z_FILTER_RESERVED), H5Z_FILTER_MAX(HDF5Constants.H5Z_FILTER_MAX);
private static final Map<Integer, H5Z_filter> lookup = new HashMap<Integer, H5Z_filter>();
static {
for (H5Z_filter s : EnumSet.allOf(H5Z_filter.class))
lookup.put(s.getCode(), s);
}
private int code;
H5Z_filter(int layout_type) {
this.code = layout_type;
}
public int getCode() {
return this.code;
}
public static H5Z_filter get(int code) {
return lookup.get(code);
}
}
private static boolean checkNbitFilter() {
try {
// Check if N-Bit compression is available and can be used for both compression and decompression.
int available = H5.H5Zfilter_avail(HDF5Constants.H5Z_FILTER_NBIT);
if (available == 0) {
System.out.println("N-Bit filter not available.");
return false;
}
}
catch (Exception e) {
e.printStackTrace();
}
try {
int filter_info = H5.H5Zget_filter_info(HDF5Constants.H5Z_FILTER_NBIT);
if (((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) == 0)
|| ((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) == 0)) {
System.out.println("N-Bit filter not available for encoding and decoding.");
return false;
}
}
catch (Exception e) {
e.printStackTrace();
}
return true;
}
private static void writeData() throws Exception {
long file_id = -1;
long filespace_id = -1;
long dataset_id = -1;
long dtype_id = -1;
long dcpl_id = -1;
long[] dims = { DIM_X, DIM_Y };
long[] chunk_dims = { CHUNK_X, CHUNK_Y };
int[][] dset_data = new int[DIM_X][DIM_Y];
// Initialize data.
for (int indx = 0; indx < DIM_X; indx++)
for (int jndx = 0; jndx < DIM_Y; jndx++)
dset_data[indx][jndx] = indx * jndx - jndx;
try {
// Create a new file using the default properties.
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
filespace_id = H5.H5Screate_simple(RANK, dims, null);
// Create the datatype to use with the N-Bit filter. It has an uncompressed size of 32 bits,
// but will have a size of 16 bits after being packed by the N-Bit filter.
dtype_id = H5.H5Tcopy(HDF5Constants.H5T_STD_I32LE);
H5.H5Tset_precision(dtype_id, 16);
H5.H5Tset_offset(dtype_id, 5);
// Create the dataset creation property list, add the N-Bit filter and set the chunk size.
dcpl_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_CREATE);
H5.H5Pset_nbit(dcpl_id);
H5.H5Pset_chunk(dcpl_id, NDIMS, chunk_dims);
// Create the dataset.
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, dtype_id, filespace_id, HDF5Constants.H5P_DEFAULT, dcpl_id,
HDF5Constants.H5P_DEFAULT);
// Write the data to the dataset.
H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
finally {
// Close and release resources.
if (dcpl_id >= 0)
H5.H5Pclose(dcpl_id);
if (dtype_id >= 0)
H5.H5Tclose(dtype_id);
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
if (filespace_id >= 0)
H5.H5Sclose(filespace_id);
if (file_id >= 0)
H5.H5Fclose(file_id);
}
}
private static void readData() throws Exception {
long file_id = -1;
long dataset_id = -1;
long dcpl_id = -1;
int[][] dset_data = new int[DIM_X][DIM_Y];
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Retrieve the dataset creation property list.
try {
if (dataset_id >= 0)
dcpl_id = H5.H5Dget_create_plist(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Retrieve and print the filter type. Here we only retrieve the
// first filter because we know that we only added one filter.
try {
if (dcpl_id >= 0) {
// Java lib requires a valid filter_name object and cd_values
int[] flags = { 0 };
long[] cd_nelmts = { 1 };
int[] cd_values = { 0 };
String[] filter_name = { "" };
int[] filter_config = { 0 };
int filter_type = -1;
filter_type = H5
.H5Pget_filter(dcpl_id, 0, flags, cd_nelmts, cd_values, 120, filter_name, filter_config);
System.out.print("Filter type is: ");
switch (H5Z_filter.get(filter_type)) {
case H5Z_FILTER_DEFLATE:
System.out.println("H5Z_FILTER_DEFLATE");
break;
case H5Z_FILTER_SHUFFLE:
System.out.println("H5Z_FILTER_SHUFFLE");
break;
case H5Z_FILTER_FLETCHER32:
System.out.println("H5Z_FILTER_FLETCHER32");
break;
case H5Z_FILTER_SZIP:
System.out.println("H5Z_FILTER_SZIP");
break;
case H5Z_FILTER_NBIT:
System.out.println("H5Z_FILTER_NBIT");
break;
case H5Z_FILTER_SCALEOFFSET:
System.out.println("H5Z_FILTER_SCALEOFFSET");
break;
default:
System.out.println("H5Z_FILTER_ERROR");
}
System.out.println();
}
}
catch (Exception e) {
e.printStackTrace();
}
// Read the data using the default properties.
try {
if (dataset_id >= 0) {
int status = H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL,
HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data);
// Check if the read was successful.
if (status < 0)
System.out.print("Dataset read failed!");
}
}
catch (Exception e) {
e.printStackTrace();
}
// Find the maximum value in the dataset, to verify that it was read
// correctly.
int max = dset_data[0][0];
for (int indx = 0; indx < DIM_X; indx++) {
for (int jndx = 0; jndx < DIM_Y; jndx++)
if (max < dset_data[indx][jndx])
max = dset_data[indx][jndx];
}
// Print the maximum value.
System.out.println("Maximum value in " + DATASETNAME + " is: " + max);
// End access to the dataset and release resources used by it.
try {
if (dcpl_id >= 0)
H5.H5Pclose(dcpl_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
/*
* Check if N-Bit compression is available and can be used for both compression and decompression. Normally we
* do not perform error checking in these examples for the sake of clarity, but in this case we will make an
* exception because this filter is an optional part of the hdf5 library.
*/
try {
if (H5Ex_D_Nbit.checkNbitFilter()) {
H5Ex_D_Nbit.writeData();
H5Ex_D_Nbit.readData();
}
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
@@ -0,0 +1,179 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to read and write data to a
dataset. The program first writes integers to a dataset
with dataspace dimensions of DIM_XxDIM_Y, then closes the
file. Next, it reopens the file, reads back the data, and
outputs it to the screen.
************************************************************/
package examples.datasets;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_D_ReadWrite {
private static String FILENAME = "H5Ex_D_ReadWrite.h5";
private static String DATASETNAME = "DS1";
private static final int DIM_X = 4;
private static final int DIM_Y = 7;
private static final int RANK = 2;
private static void WriteDataset() {
long file_id = -1;
long filespace_id = -1;
long dataset_id = -1;
long[] dims = { DIM_X, DIM_Y };
int[][] dset_data = new int[DIM_X][DIM_Y];
// Initialize data.
for (int indx = 0; indx < DIM_X; indx++)
for (int jndx = 0; jndx < DIM_Y; jndx++)
dset_data[indx][jndx] = indx * jndx - jndx;
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
try {
filespace_id = H5.H5Screate_simple(RANK, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset. We will use all default properties for this example.
try {
if ((file_id >= 0) && (filespace_id >= 0))
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, filespace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the data to the dataset.
try {
if (dataset_id >= 0)
H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (filespace_id >= 0)
H5.H5Sclose(filespace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void ReadDataset() {
long file_id = -1;
long dataset_id = -1;
int[][] dset_data = new int[DIM_X][DIM_Y];
// Open file using the default properties.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDWR, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open dataset using the default properties.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Read the data using the default properties.
try {
if (dataset_id >= 0)
H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
System.out.println(DATASETNAME + ":");
for (int indx = 0; indx < DIM_X; indx++) {
System.out.print(" [ ");
for (int jndx = 0; jndx < DIM_Y; jndx++)
System.out.print(dset_data[indx][jndx] + " ");
System.out.println("]");
}
System.out.println();
// Close the dataset.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_D_ReadWrite.WriteDataset();
H5Ex_D_ReadWrite.ReadDataset();
}
}
+373
View File
@@ -0,0 +1,373 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to read and write data to a dataset
using the shuffle filter with gzip compression. The
program first checks if the shuffle and gzip filters are
available, then if they are it writes integers to a
dataset using shuffle+gzip, then closes the file. Next,
it reopens the file, reads back the data, and outputs the
types of filters and the maximum value in the dataset to
the screen.
************************************************************/
package examples.datasets;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_D_Shuffle {
private static String FILENAME = "H5Ex_D_Shuffle.h5";
private static String DATASETNAME = "DS1";
private static final int DIM_X = 32;
private static final int DIM_Y = 64;
private static final int CHUNK_X = 4;
private static final int CHUNK_Y = 8;
private static final int RANK = 2;
private static final int NDIMS = 2;
// Values for the status of space allocation
enum H5Z_filter {
H5Z_FILTER_ERROR(HDF5Constants.H5Z_FILTER_ERROR), H5Z_FILTER_NONE(HDF5Constants.H5Z_FILTER_NONE), H5Z_FILTER_DEFLATE(
HDF5Constants.H5Z_FILTER_DEFLATE), H5Z_FILTER_SHUFFLE(HDF5Constants.H5Z_FILTER_SHUFFLE), H5Z_FILTER_FLETCHER32(
HDF5Constants.H5Z_FILTER_FLETCHER32), H5Z_FILTER_SZIP(HDF5Constants.H5Z_FILTER_SZIP), H5Z_FILTER_NBIT(
HDF5Constants.H5Z_FILTER_NBIT), H5Z_FILTER_SCALEOFFSET(HDF5Constants.H5Z_FILTER_SCALEOFFSET), H5Z_FILTER_RESERVED(
HDF5Constants.H5Z_FILTER_RESERVED), H5Z_FILTER_MAX(HDF5Constants.H5Z_FILTER_MAX);
private static final Map<Integer, H5Z_filter> lookup = new HashMap<Integer, H5Z_filter>();
static {
for (H5Z_filter s : EnumSet.allOf(H5Z_filter.class))
lookup.put(s.getCode(), s);
}
private int code;
H5Z_filter(int layout_type) {
this.code = layout_type;
}
public int getCode() {
return this.code;
}
public static H5Z_filter get(int code) {
return lookup.get(code);
}
}
private static boolean checkGzipFilter() {
try {
int available = H5.H5Zfilter_avail(HDF5Constants.H5Z_FILTER_DEFLATE);
if (available == 0) {
System.out.println("gzip filter not available.");
return false;
}
}
catch (Exception e) {
e.printStackTrace();
}
try {
int filter_info = H5.H5Zget_filter_info(HDF5Constants.H5Z_FILTER_DEFLATE);
if (((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) == 0)
|| ((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) == 0)) {
System.out.println("gzip filter not available for encoding and decoding.");
return false;
}
}
catch (Exception e) {
e.printStackTrace();
}
return true;
}
private static boolean checkShuffleFilter() {
try {
int available = H5.H5Zfilter_avail(HDF5Constants.H5Z_FILTER_SHUFFLE);
if (available == 0) {
System.out.println("Shuffle filter not available.");
return false;
}
}
catch (Exception e) {
e.printStackTrace();
}
try {
int filter_info = H5.H5Zget_filter_info(HDF5Constants.H5Z_FILTER_SHUFFLE);
if (((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) == 0)
|| ((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) == 0)) {
System.out.println("Shuffle filter not available for encoding and decoding.");
return false;
}
}
catch (Exception e) {
e.printStackTrace();
}
return true;
}
private static void writeShuffle() {
long file_id = -1;
long filespace_id = -1;
long dataset_id = -1;
long dcpl_id = -1;
long[] dims = { DIM_X, DIM_Y };
long[] chunk_dims = { CHUNK_X, CHUNK_Y };
int[][] dset_data = new int[DIM_X][DIM_Y];
// Initialize data.
for (int indx = 0; indx < DIM_X; indx++)
for (int jndx = 0; jndx < DIM_Y; jndx++)
dset_data[indx][jndx] = indx * jndx - jndx;
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
try {
filespace_id = H5.H5Screate_simple(RANK, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset creation property list, add the shuffle
// filter and the gzip compression filter.
// The order in which the filters are added here is significant -
// we will see much greater results when the shuffle is applied
// first. The order in which the filters are added to the property
// list is the order in which they will be invoked when writing
// data.
try {
dcpl_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_CREATE);
if (dcpl_id >= 0) {
H5.H5Pset_shuffle(dcpl_id);
H5.H5Pset_deflate(dcpl_id, 9);
// Set the chunk size.
H5.H5Pset_chunk(dcpl_id, NDIMS, chunk_dims);
}
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset.
try {
if ((file_id >= 0) && (filespace_id >= 0) && (dcpl_id >= 0))
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, filespace_id,
HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the data to the dataset.
try {
if (dataset_id >= 0)
H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (dcpl_id >= 0)
H5.H5Pclose(dcpl_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (filespace_id >= 0)
H5.H5Sclose(filespace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void readShuffle() {
long file_id = -1;
long dataset_id = -1;
long dcpl_id = -1;
int[][] dset_data = new int[DIM_X][DIM_Y];
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Retrieve the dataset creation property list.
try {
if (dataset_id >= 0)
dcpl_id = H5.H5Dget_create_plist(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Retrieve the number of filters, and retrieve and print the
// type of each.
try {
if (dcpl_id >= 0) {
int nfilters = H5.H5Pget_nfilters(dcpl_id);
for (int indx = 0; indx < nfilters; indx++) {
// Java lib requires a valid filter_name object and cd_values
int[] flags = { 0 };
long[] cd_nelmts = { 1 };
int[] cd_values = { 0 };
String[] filter_name = { "" };
int[] filter_config = { 0 };
int filter_type = -1;
filter_type = H5.H5Pget_filter(dcpl_id, indx, flags, cd_nelmts, cd_values, 120, filter_name,
filter_config);
System.out.print("Filter " + indx + ": Type is: ");
switch (H5Z_filter.get(filter_type)) {
case H5Z_FILTER_DEFLATE:
System.out.println("H5Z_FILTER_DEFLATE");
break;
case H5Z_FILTER_SHUFFLE:
System.out.println("H5Z_FILTER_SHUFFLE");
break;
case H5Z_FILTER_FLETCHER32:
System.out.println("H5Z_FILTER_FLETCHER32");
break;
case H5Z_FILTER_SZIP:
System.out.println("H5Z_FILTER_SZIP");
break;
case H5Z_FILTER_NBIT:
System.out.println("H5Z_FILTER_NBIT");
break;
case H5Z_FILTER_SCALEOFFSET:
System.out.println("H5Z_FILTER_SCALEOFFSET");
break;
default:
System.out.println("H5Z_FILTER_ERROR");
}
System.out.println();
}
}
}
catch (Exception e) {
e.printStackTrace();
}
// Read the data using the default properties.
try {
if (dataset_id >= 0) {
H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
}
catch (Exception e) {
e.printStackTrace();
}
// Find the maximum value in the dataset, to verify that it was read
// correctly.
int max = dset_data[0][0];
for (int indx = 0; indx < DIM_X; indx++) {
for (int jndx = 0; jndx < DIM_Y; jndx++)
if (max < dset_data[indx][jndx])
max = dset_data[indx][jndx];
}
// Print the maximum value.
System.out.println("Maximum value in " + DATASETNAME + " is: " + max);
// End access to the dataset and release resources used by it.
try {
if (dcpl_id >= 0)
H5.H5Pclose(dcpl_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
// Check if gzip compression is available and can be used for both
// compression and decompression. Normally we do not perform error
// checking in these examples for the sake of clarity, but in this
// case we will make an exception because this filter is an
// optional part of the hdf5 library.
// Similarly, check for availability of the shuffle filter.
if (H5Ex_D_Shuffle.checkGzipFilter() && H5Ex_D_Shuffle.checkShuffleFilter()) {
H5Ex_D_Shuffle.writeShuffle();
H5Ex_D_Shuffle.readShuffle();
}
}
}
+356
View File
@@ -0,0 +1,356 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to read and write data to a dataset
using the Scale-Offset filter. The program first checks
if the Scale-Offset filter is available, then if it is it
writes floating point numbers to a dataset using
Scale-Offset, then closes the file Next, it reopens the
file, reads back the data, and outputs the type of filter
and the maximum value in the dataset to the screen.
************************************************************/
package examples.datasets;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_D_Sofloat {
private static String FILENAME = "H5Ex_D_Sofloat.h5";
private static String DATASETNAME = "DS1";
private static final int DIM_X = 32;
private static final int DIM_Y = 64;
private static final int CHUNK_X = 4;
private static final int CHUNK_Y = 8;
private static final int RANK = 2;
private static final int NDIMS = 2;
// Values for the status of space allocation
enum H5Z_filter {
H5Z_FILTER_ERROR(HDF5Constants.H5Z_FILTER_ERROR), H5Z_FILTER_NONE(HDF5Constants.H5Z_FILTER_NONE), H5Z_FILTER_DEFLATE(
HDF5Constants.H5Z_FILTER_DEFLATE), H5Z_FILTER_SHUFFLE(HDF5Constants.H5Z_FILTER_SHUFFLE), H5Z_FILTER_FLETCHER32(
HDF5Constants.H5Z_FILTER_FLETCHER32), H5Z_FILTER_SZIP(HDF5Constants.H5Z_FILTER_SZIP), H5Z_FILTER_NBIT(
HDF5Constants.H5Z_FILTER_NBIT), H5Z_FILTER_SCALEOFFSET(HDF5Constants.H5Z_FILTER_SCALEOFFSET), H5Z_FILTER_RESERVED(
HDF5Constants.H5Z_FILTER_RESERVED), H5Z_FILTER_MAX(HDF5Constants.H5Z_FILTER_MAX);
private static final Map<Integer, H5Z_filter> lookup = new HashMap<Integer, H5Z_filter>();
static {
for (H5Z_filter s : EnumSet.allOf(H5Z_filter.class))
lookup.put(s.getCode(), s);
}
private int code;
H5Z_filter(int layout_type) {
this.code = layout_type;
}
public int getCode() {
return this.code;
}
public static H5Z_filter get(int code) {
return lookup.get(code);
}
}
private static boolean checkScaleoffsetFilter() {
try {
int available = H5.H5Zfilter_avail(HDF5Constants.H5Z_FILTER_SCALEOFFSET);
if (available == 0) {
System.out.println("Scale-Offset filter not available.");
return false;
}
}
catch (Exception e) {
e.printStackTrace();
}
try {
int filter_info = H5.H5Zget_filter_info(HDF5Constants.H5Z_FILTER_SCALEOFFSET);
if (((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) == 0)
|| ((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) == 0)) {
System.out.println("Scale-Offset filter not available for encoding and decoding.");
return false;
}
}
catch (Exception e) {
e.printStackTrace();
}
return true;
}
private static void writeData() {
long file_id = -1;
long filespace_id = -1;
long dataset_id = -1;
long dcpl_id = -1;
long[] dims = { DIM_X, DIM_Y };
long[] chunk_dims = { CHUNK_X, CHUNK_Y };
double[][] dset_data = new double[DIM_X][DIM_Y];
// Initialize data.
for (int indx = 0; indx < DIM_X; indx++)
for (int jndx = 0; jndx < DIM_Y; jndx++) {
double x = indx;
double y = jndx;
dset_data[indx][jndx] = (x + 1) / (y + 0.3) + y;
}
// Find the maximum value in the dataset, to verify that it was read correctly.
double max = dset_data[0][0];
double min = dset_data[0][0];
for (int indx = 0; indx < DIM_X; indx++)
for (int jndx = 0; jndx < DIM_Y; jndx++) {
if (max < dset_data[indx][jndx])
max = dset_data[indx][jndx];
if (min > dset_data[indx][jndx])
min = dset_data[indx][jndx];
}
// Print the maximum value.
System.out.println("Maximum value in write buffer is: " + max);
System.out.println("Minimum value in write buffer is: " + min);
// Create a new file using the default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
try {
filespace_id = H5.H5Screate_simple(RANK, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset creation property list, add the Scale-Offset
// filter and set the chunk size.
try {
dcpl_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_CREATE);
if (dcpl_id >= 0) {
H5.H5Pset_scaleoffset(dcpl_id, HDF5Constants.H5Z_SO_FLOAT_DSCALE, 2);
H5.H5Pset_chunk(dcpl_id, NDIMS, chunk_dims);
}
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset.
try {
if ((file_id >= 0) && (filespace_id >= 0) && (dcpl_id >= 0))
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_IEEE_F64LE, filespace_id,
HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the data to the dataset.
try {
if (dataset_id >= 0)
H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_DOUBLE, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Close and release resources.
try {
if (dcpl_id >= 0)
H5.H5Pclose(dcpl_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (filespace_id >= 0)
H5.H5Sclose(filespace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close file
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void readData() {
long file_id = -1;
long dataset_id = -1;
long dcpl_id = -1;
double[][] dset_data = new double[DIM_X][DIM_Y];
// Open file using the default properties.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open dataset using the default properties.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Retrieve dataset creation property list.
try {
if (dataset_id >= 0)
dcpl_id = H5.H5Dget_create_plist(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Retrieve and print the filter type. Here we only retrieve the
// first filter because we know that we only added one filter.
try {
if (dcpl_id >= 0) {
// Java lib requires a valid filter_name object and cd_values
int[] flags = { 0 };
long[] cd_nelmts = { 1 };
int[] cd_values = { 0 };
String[] filter_name = { "" };
int[] filter_config = { 0 };
int filter_type = -1;
filter_type = H5
.H5Pget_filter(dcpl_id, 0, flags, cd_nelmts, cd_values, 120, filter_name, filter_config);
System.out.print("Filter type is: ");
switch (H5Z_filter.get(filter_type)) {
case H5Z_FILTER_DEFLATE:
System.out.println("H5Z_FILTER_DEFLATE");
break;
case H5Z_FILTER_SHUFFLE:
System.out.println("H5Z_FILTER_SHUFFLE");
break;
case H5Z_FILTER_FLETCHER32:
System.out.println("H5Z_FILTER_FLETCHER32");
break;
case H5Z_FILTER_SZIP:
System.out.println("H5Z_FILTER_SZIP");
break;
case H5Z_FILTER_NBIT:
System.out.println("H5Z_FILTER_NBIT");
break;
case H5Z_FILTER_SCALEOFFSET:
System.out.println("H5Z_FILTER_SCALEOFFSET");
break;
default:
System.out.println("H5Z_FILTER_ERROR");
}
System.out.println();
}
}
catch (Exception e) {
e.printStackTrace();
}
// Read the data using the default properties.
try {
if (dataset_id >= 0)
H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_DOUBLE, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Find the maximum value in the dataset, to verify that it was read correctly.
double max = dset_data[0][0];
double min = dset_data[0][0];
for (int indx = 0; indx < DIM_X; indx++)
for (int jndx = 0; jndx < DIM_Y; jndx++) {
if (max < dset_data[indx][jndx])
max = dset_data[indx][jndx];
if (min > dset_data[indx][jndx])
min = dset_data[indx][jndx];
}
// Print the maximum value.
System.out.println("Maximum value in " + DATASETNAME + " is: " + max);
System.out.println("Minimum value in " + DATASETNAME + " is: " + min);
// End access to the dataset and release resources used by it.
try {
if (dcpl_id >= 0)
H5.H5Pclose(dcpl_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
// Check if Scale-Offset compression is available and can be used
// for both compression and decompression. Normally we do not
// perform error checking in these examples for the sake of
// clarity, but in this case we will make an exception because this
// filter is an optional part of the hdf5 library.
if (H5Ex_D_Sofloat.checkScaleoffsetFilter()) {
H5Ex_D_Sofloat.writeData();
H5Ex_D_Sofloat.readData();
}
}
}
+335
View File
@@ -0,0 +1,335 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to read and write data to a dataset
using the Scale-Offset filter. The program first checks
if the Scale-Offset filter is available, then if it is it
writes integers to a dataset using Scale-Offset, then
closes the file Next, it reopens the file, reads back the
data, and outputs the type of filter and the maximum value
in the dataset to the screen.
************************************************************/
package examples.datasets;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_D_Soint {
private static String FILENAME = "H5Ex_D_Soint.h5";
private static String DATASETNAME = "DS1";
private static final int DIM_X = 32;
private static final int DIM_Y = 64;
private static final int CHUNK_X = 4;
private static final int CHUNK_Y = 8;
private static final int RANK = 2;
private static final int NDIMS = 2;
// Values for the status of space allocation
enum H5Z_filter {
H5Z_FILTER_ERROR(HDF5Constants.H5Z_FILTER_ERROR), H5Z_FILTER_NONE(HDF5Constants.H5Z_FILTER_NONE), H5Z_FILTER_DEFLATE(
HDF5Constants.H5Z_FILTER_DEFLATE), H5Z_FILTER_SHUFFLE(HDF5Constants.H5Z_FILTER_SHUFFLE), H5Z_FILTER_FLETCHER32(
HDF5Constants.H5Z_FILTER_FLETCHER32), H5Z_FILTER_SZIP(HDF5Constants.H5Z_FILTER_SZIP), H5Z_FILTER_NBIT(
HDF5Constants.H5Z_FILTER_NBIT), H5Z_FILTER_SCALEOFFSET(HDF5Constants.H5Z_FILTER_SCALEOFFSET), H5Z_FILTER_RESERVED(
HDF5Constants.H5Z_FILTER_RESERVED), H5Z_FILTER_MAX(HDF5Constants.H5Z_FILTER_MAX);
private static final Map<Integer, H5Z_filter> lookup = new HashMap<Integer, H5Z_filter>();
static {
for (H5Z_filter s : EnumSet.allOf(H5Z_filter.class))
lookup.put(s.getCode(), s);
}
private int code;
H5Z_filter(int layout_type) {
this.code = layout_type;
}
public int getCode() {
return this.code;
}
public static H5Z_filter get(int code) {
return lookup.get(code);
}
}
private static boolean checkScaleoffsetFilter() {
try {
int available = H5.H5Zfilter_avail(HDF5Constants.H5Z_FILTER_SCALEOFFSET);
if (available == 0) {
System.out.println("Scale-Offset filter not available.");
return false;
}
}
catch (Exception e) {
e.printStackTrace();
}
try {
int filter_info = H5.H5Zget_filter_info(HDF5Constants.H5Z_FILTER_SCALEOFFSET);
if (((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) == 0)
|| ((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) == 0)) {
System.out.println("Scale-Offset filter not available for encoding and decoding.");
return false;
}
}
catch (Exception e) {
e.printStackTrace();
}
return true;
}
private static void writeData() {
long file_id = -1;
long filespace_id = -1;
long dataset_id = -1;
long dcpl_id = -1;
long[] dims = { DIM_X, DIM_Y };
long[] chunk_dims = { CHUNK_X, CHUNK_Y };
int[][] dset_data = new int[DIM_X][DIM_Y];
// Initialize data.
for (int indx = 0; indx < DIM_X; indx++)
for (int jndx = 0; jndx < DIM_Y; jndx++)
dset_data[indx][jndx] = indx * jndx - jndx;
// Create a new file using the default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum size to be the current size.
try {
filespace_id = H5.H5Screate_simple(RANK, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset creation property list, add the Scale-Offset
// filter and set the chunk size.
try {
dcpl_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_CREATE);
if (dcpl_id >= 0) {
H5.H5Pset_scaleoffset(dcpl_id, HDF5Constants.H5Z_SO_INT, HDF5Constants.H5Z_SO_INT_MINBITS_DEFAULT);
H5.H5Pset_chunk(dcpl_id, NDIMS, chunk_dims);
}
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset.
try {
if ((file_id >= 0) && (filespace_id >= 0) && (dcpl_id >= 0))
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, filespace_id,
HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the data to the dataset.
try {
if (dataset_id >= 0)
H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Close and release resources.
try {
if (dcpl_id >= 0)
H5.H5Pclose(dcpl_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (filespace_id >= 0)
H5.H5Sclose(filespace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close file
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void readData() {
long file_id = -1;
long dataset_id = -1;
long dcpl_id = -1;
int[][] dset_data = new int[DIM_X][DIM_Y];
// Open file using the default properties.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open dataset using the default properties.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Retrieve dataset creation property list.
try {
if (dataset_id >= 0)
dcpl_id = H5.H5Dget_create_plist(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Retrieve and print the filter type. Here we only retrieve the
// first filter because we know that we only added one filter.
try {
if (dcpl_id >= 0) {
// Java lib requires a valid filter_name object and cd_values
int[] flags = { 0 };
long[] cd_nelmts = { 1 };
int[] cd_values = { 0 };
String[] filter_name = { "" };
int[] filter_config = { 0 };
int filter_type = -1;
filter_type = H5
.H5Pget_filter(dcpl_id, 0, flags, cd_nelmts, cd_values, 120, filter_name, filter_config);
System.out.print("Filter type is: ");
switch (H5Z_filter.get(filter_type)) {
case H5Z_FILTER_DEFLATE:
System.out.println("H5Z_FILTER_DEFLATE");
break;
case H5Z_FILTER_SHUFFLE:
System.out.println("H5Z_FILTER_SHUFFLE");
break;
case H5Z_FILTER_FLETCHER32:
System.out.println("H5Z_FILTER_FLETCHER32");
break;
case H5Z_FILTER_SZIP:
System.out.println("H5Z_FILTER_SZIP");
break;
case H5Z_FILTER_NBIT:
System.out.println("H5Z_FILTER_NBIT");
break;
case H5Z_FILTER_SCALEOFFSET:
System.out.println("H5Z_FILTER_SCALEOFFSET");
break;
default:
System.out.println("H5Z_FILTER_ERROR");
}
System.out.println();
}
}
catch (Exception e) {
e.printStackTrace();
}
// Read the data using the default properties.
try {
if (dataset_id >= 0)
H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Find the maximum value in the dataset, to verify that it was read correctly.
int max = dset_data[0][0];
for (int indx = 0; indx < DIM_X; indx++)
for (int jndx = 0; jndx < DIM_Y; jndx++) {
if (max < dset_data[indx][jndx])
max = dset_data[indx][jndx];
}
// Print the maximum value.
System.out.println("Maximum value in " + DATASETNAME + " is: " + max);
// End access to the dataset and release resources used by it.
try {
if (dcpl_id >= 0)
H5.H5Pclose(dcpl_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
// Check if Scale-Offset compression is available and can be used
// for both compression and decompression. Normally we do not
// perform error checking in these examples for the sake of
// clarity, but in this case we will make an exception because this
// filter is an optional part of the hdf5 library.
if (H5Ex_D_Soint.checkScaleoffsetFilter()) {
H5Ex_D_Soint.writeData();
H5Ex_D_Soint.readData();
}
}
}
+337
View File
@@ -0,0 +1,337 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to read and write data to a dataset
using szip compression. The program first checks if
szip compression is available, then if it is it writes
integers to a dataset using szip, then closes the file.
Next, it reopens the file, reads back the data, and
outputs the type of compression and the maximum value in
the dataset to the screen.
************************************************************/
package examples.datasets;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_D_Szip {
private static String FILENAME = "H5Ex_D_Szip.h5";
private static String DATASETNAME = "DS1";
private static final int DIM_X = 32;
private static final int DIM_Y = 64;
private static final int CHUNK_X = 4;
private static final int CHUNK_Y = 8;
private static final int RANK = 2;
private static final int NDIMS = 2;
// Values for the status of space allocation
enum H5Z_filter {
H5Z_FILTER_ERROR(HDF5Constants.H5Z_FILTER_ERROR), H5Z_FILTER_NONE(HDF5Constants.H5Z_FILTER_NONE), H5Z_FILTER_DEFLATE(
HDF5Constants.H5Z_FILTER_DEFLATE), H5Z_FILTER_SHUFFLE(HDF5Constants.H5Z_FILTER_SHUFFLE), H5Z_FILTER_FLETCHER32(
HDF5Constants.H5Z_FILTER_FLETCHER32), H5Z_FILTER_SZIP(HDF5Constants.H5Z_FILTER_SZIP), H5Z_FILTER_NBIT(
HDF5Constants.H5Z_FILTER_NBIT), H5Z_FILTER_SCALEOFFSET(HDF5Constants.H5Z_FILTER_SCALEOFFSET), H5Z_FILTER_RESERVED(
HDF5Constants.H5Z_FILTER_RESERVED), H5Z_FILTER_MAX(HDF5Constants.H5Z_FILTER_MAX);
private static final Map<Integer, H5Z_filter> lookup = new HashMap<Integer, H5Z_filter>();
static {
for (H5Z_filter s : EnumSet.allOf(H5Z_filter.class))
lookup.put(s.getCode(), s);
}
private int code;
H5Z_filter(int layout_type) {
this.code = layout_type;
}
public int getCode() {
return this.code;
}
public static H5Z_filter get(int code) {
return lookup.get(code);
}
}
private static boolean checkSzipFilter() {
try {
int available = H5.H5Zfilter_avail(HDF5Constants.H5Z_FILTER_SZIP);
if (available == 0) {
System.out.println("szip filter not available.");
return false;
}
}
catch (Exception e) {
e.printStackTrace();
}
try {
int filter_info = H5.H5Zget_filter_info(HDF5Constants.H5Z_FILTER_SZIP);
if (((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) == 0)
|| ((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) == 0)) {
System.out.println("szip filter not available for encoding and decoding.");
return false;
}
}
catch (Exception e) {
e.printStackTrace();
}
return true;
}
private static void writeSzip() {
long file_id = -1;
long filespace_id = -1;
long dataset_id = -1;
long dcpl_id = -1;
long[] dims = { DIM_X, DIM_Y };
long[] chunk_dims = { CHUNK_X, CHUNK_Y };
int[][] dset_data = new int[DIM_X][DIM_Y];
// Initialize data.
for (int indx = 0; indx < DIM_X; indx++)
for (int jndx = 0; jndx < DIM_Y; jndx++)
dset_data[indx][jndx] = indx * jndx - jndx;
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
try {
filespace_id = H5.H5Screate_simple(RANK, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset creation property list, add the szip compression
// filter.
try {
dcpl_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_CREATE);
if (dcpl_id >= 0) {
H5.H5Pset_szip(dcpl_id, HDF5Constants.H5_SZIP_NN_OPTION_MASK, 8);
// Set the chunk size.
H5.H5Pset_chunk(dcpl_id, NDIMS, chunk_dims);
}
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset.
try {
if ((file_id >= 0) && (filespace_id >= 0) && (dcpl_id >= 0))
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, filespace_id,
HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the data to the dataset.
try {
if (dataset_id >= 0)
H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (dcpl_id >= 0)
H5.H5Pclose(dcpl_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (filespace_id >= 0)
H5.H5Sclose(filespace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void readSzip() {
long file_id = -1;
long dataset_id = -1;
long dcpl_id = -1;
int[][] dset_data = new int[DIM_X][DIM_Y];
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Retrieve the dataset creation property list.
try {
if (dataset_id >= 0)
dcpl_id = H5.H5Dget_create_plist(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Retrieve and print the filter type. Here we only retrieve the
// first filter because we know that we only added one filter.
try {
if (dcpl_id >= 0) {
// Java lib requires a valid filter_name object and cd_values
int[] flags = { 0 };
long[] cd_nelmts = { 1 };
int[] cd_values = { 0 };
String[] filter_name = { "" };
int[] filter_config = { 0 };
int filter_type = -1;
filter_type = H5
.H5Pget_filter(dcpl_id, 0, flags, cd_nelmts, cd_values, 120, filter_name, filter_config);
System.out.print("Filter type is: ");
switch (H5Z_filter.get(filter_type)) {
case H5Z_FILTER_DEFLATE:
System.out.println("H5Z_FILTER_DEFLATE");
break;
case H5Z_FILTER_SHUFFLE:
System.out.println("H5Z_FILTER_SHUFFLE");
break;
case H5Z_FILTER_FLETCHER32:
System.out.println("H5Z_FILTER_FLETCHER32");
break;
case H5Z_FILTER_SZIP:
System.out.println("H5Z_FILTER_SZIP");
break;
case H5Z_FILTER_NBIT:
System.out.println("H5Z_FILTER_NBIT");
break;
case H5Z_FILTER_SCALEOFFSET:
System.out.println("H5Z_FILTER_SCALEOFFSET");
break;
default:
System.out.println("H5Z_FILTER_ERROR");
}
System.out.println();
}
}
catch (Exception e) {
e.printStackTrace();
}
// Read the data using the default properties.
try {
if (dataset_id >= 0) {
H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
}
catch (Exception e) {
e.printStackTrace();
}
// Find the maximum value in the dataset, to verify that it was read
// correctly.
int max = dset_data[0][0];
for (int indx = 0; indx < DIM_X; indx++) {
for (int jndx = 0; jndx < DIM_Y; jndx++)
if (max < dset_data[indx][jndx])
max = dset_data[indx][jndx];
}
// Print the maximum value.
System.out.println("Maximum value in " + DATASETNAME + " is: " + max);
// End access to the dataset and release resources used by it.
try {
if (dcpl_id >= 0)
H5.H5Pclose(dcpl_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
// Check if gzip compression is available and can be used for both
// compression and decompression. Normally we do not perform error
// checking in these examples for the sake of clarity, but in this
// case we will make an exception because this filter is an
// optional part of the hdf5 library.
if (H5Ex_D_Szip.checkSzipFilter()) {
H5Ex_D_Szip.writeSzip();
H5Ex_D_Szip.readSzip();
}
}
}
@@ -0,0 +1,250 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to read and write data to a dataset
using a data transform expression. The program first
writes integers to a dataset using the transform
expression TRANSFORM, then closes the file. Next, it
reopens the file, reads back the data without a transform,
and outputs the data to the screen. Finally it reads the
data using the transform expression RTRANSFORM and outputs
the results to the screen.
************************************************************/
package examples.datasets;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_D_Transform {
private static String FILE = "H5Ex_D_Transform.h5";
private static String DATASET = "DS1";
private static final int DIM_X = 4;
private static final int DIM_Y = 7;
private static String TRANSFORM = "x+1";
private static String RTRANSFORM = "x-1";
private static void writeData() {
long file_id = -1;
long filespace_id = -1;
long dataset_id = -1;
long dxpl_id = -1;
long[] dims = { DIM_X, DIM_Y };
int[][] dset_data = new int[DIM_X][DIM_Y];
// Initialize data.
for (int i = 0; i < DIM_X; i++)
for (int j = 0; j < DIM_Y; j++)
dset_data[i][j] = i * j - j;
// Output the data to the screen.
System.out.println("Original Data:");
for (int i = 0; i < DIM_X; i++) {
System.out.print(" [");
for (int j = 0; j < DIM_Y; j++)
System.out.print(" " + dset_data[i][j] + " ");
System.out.println("]");
}
// Create a new file using the default properties.
try {
file_id = H5.H5Fcreate(FILE, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
try {
filespace_id = H5.H5Screate_simple(2, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset transfer property list and define the transform expression.
try {
dxpl_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_XFER);
if (dxpl_id >= 0)
H5.H5Pset_data_transform(dxpl_id, TRANSFORM);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset using the default properties. Unfortunately we must save as
// a native type or the transform operation will fail.
try {
if ((file_id >= 0) && (filespace_id >= 0))
dataset_id = H5.H5Dcreate(file_id, DATASET, HDF5Constants.H5T_NATIVE_INT, filespace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the data to the dataset using the dataset transfer property list.
try {
if ((dataset_id >= 0) && (dxpl_id >= 0))
H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
dxpl_id, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (dxpl_id >= 0)
H5.H5Pclose(dxpl_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (filespace_id >= 0)
H5.H5Sclose(filespace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void readData() {
long file_id = -1;
long dataset_id = -1;
long dxpl_id = -1;
int[][] dset_data = new int[DIM_X][DIM_Y];
// Open an existing file using the default properties.
try {
file_id = H5.H5Fopen(FILE, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset using the default properties.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASET, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Read the data using the default properties.
try {
if (dataset_id >= 0)
H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
System.out.println("Data as written with transform '" + TRANSFORM + "'");
for (int i = 0; i < DIM_X; i++) {
System.out.print(" [");
for (int j = 0; j < DIM_Y; j++)
System.out.print(" " + dset_data[i][j] + " ");
System.out.println("]");
}
// Create the dataset transfer property list and define the transform expression.
try {
dxpl_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_XFER);
if (dxpl_id >= 0)
H5.H5Pset_data_transform(dxpl_id, RTRANSFORM);
}
catch (Exception e) {
e.printStackTrace();
}
// Read the data using the dataset transfer property list.
try {
if ((dataset_id >= 0) && (dxpl_id >= 0))
H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
dxpl_id, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
System.out.println("Data as written with transform '" + TRANSFORM + "' and read with transform '"
+ RTRANSFORM + "'");
for (int i = 0; i < DIM_X; i++) {
System.out.print(" [");
for (int j = 0; j < DIM_Y; j++)
System.out.print(" " + dset_data[i][j] + " ");
System.out.println("]");
}
// Close and release resources.
try {
if (dxpl_id >= 0)
H5.H5Pclose(dxpl_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_D_Transform.writeData();
H5Ex_D_Transform.readData();
}
}
@@ -0,0 +1,393 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to create and extend an unlimited
dataset. The program first writes integers to a dataset
with dataspace dimensions of DIM_XxDIM_Y, then closes the
file. Next, it reopens the file, reads back the data,
outputs it to the screen, extends the dataset, and writes
new data to the extended portions of the dataset. Finally
it reopens the file again, reads back the data, and
outputs it to the screen.
************************************************************/
package examples.datasets;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_D_UnlimitedAdd {
private static String FILENAME = "H5Ex_D_UnlimitedAdd.h5";
private static String DATASETNAME = "DS1";
private static final int DIM_X = 4;
private static final int DIM_Y = 7;
private static final int EDIM_X = 6;
private static final int EDIM_Y = 10;
private static final int CHUNK_X = 4;
private static final int CHUNK_Y = 4;
private static final int RANK = 2;
private static final int NDIMS = 2;
private static void writeUnlimited() {
long file_id = -1;
long dcpl_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long[] dims = { DIM_X, DIM_Y };
long[] chunk_dims = { CHUNK_X, CHUNK_Y };
long[] maxdims = { HDF5Constants.H5S_UNLIMITED, HDF5Constants.H5S_UNLIMITED };
int[][] dset_data = new int[DIM_X][DIM_Y];
// Initialize the dataset.
for (int indx = 0; indx < DIM_X; indx++)
for (int jndx = 0; jndx < DIM_Y; jndx++)
dset_data[indx][jndx] = indx * jndx - jndx;
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace with unlimited dimensions.
try {
dataspace_id = H5.H5Screate_simple(RANK, dims, maxdims);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset creation property list.
try {
dcpl_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_CREATE);
}
catch (Exception e) {
e.printStackTrace();
}
// Set the chunk size.
try {
if (dcpl_id >= 0)
H5.H5Pset_chunk(dcpl_id, NDIMS, chunk_dims);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the unlimited dataset.
try {
if ((file_id >= 0) && (dataspace_id >= 0) && (dcpl_id >= 0))
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, dataspace_id,
HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the data to the dataset.
try {
if (dataset_id >= 0)
H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dcpl_id >= 0)
H5.H5Pclose(dcpl_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void extendUnlimited() {
long file_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long[] dims = { DIM_X, DIM_Y };
long[] extdims = { EDIM_X, EDIM_Y };
long[] start = { 0, 0 };
long[] count = new long[2];
int[][] dset_data;
int[][] extend_dset_data = new int[EDIM_X][EDIM_Y];
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDWR, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Get dataspace and allocate memory for read buffer. This is a
// two dimensional dataset so the dynamic allocation must be done
// in steps.
try {
if (dataset_id >= 0)
dataspace_id = H5.H5Dget_space(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sget_simple_extent_dims(dataspace_id, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Allocate array of pointers to rows.
dset_data = new int[(int) dims[0]][(int) dims[1]];
// Read the data using the default properties.
try {
if (dataset_id >= 0)
H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
System.out.println("Dataset before extension:");
for (int indx = 0; indx < DIM_X; indx++) {
System.out.print(" [ ");
for (int jndx = 0; jndx < DIM_Y; jndx++)
System.out.print(dset_data[indx][jndx] + " ");
System.out.println("]");
}
System.out.println();
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Extend the dataset.
try {
if (dataset_id >= 0)
H5.H5Dset_extent(dataset_id, extdims);
}
catch (Exception e) {
e.printStackTrace();
}
// Retrieve the dataspace for the newly extended dataset.
try {
if (dataset_id >= 0)
dataspace_id = H5.H5Dget_space(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Initialize data for writing to the extended dataset.
for (int indx = 0; indx < EDIM_X; indx++)
for (int jndx = 0; jndx < EDIM_Y; jndx++)
extend_dset_data[indx][jndx] = jndx;
// Select the entire dataspace.
try {
if (dataspace_id >= 0) {
H5.H5Sselect_all(dataspace_id);
// Subtract a hyperslab reflecting the original dimensions from the
// selection. The selection now contains only the newly extended
// portions of the dataset.
count[0] = dims[0];
count[1] = dims[1];
H5.H5Sselect_hyperslab(dataspace_id, HDF5Constants.H5S_SELECT_NOTB, start, null, count, null);
// Write the data to the selected portion of the dataset.
if (dataset_id >= 0)
H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, dataspace_id,
HDF5Constants.H5P_DEFAULT, extend_dset_data);
}
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void readUnlimited() {
long file_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long[] dims = { DIM_X, DIM_Y };
int[][] dset_data;
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Get dataspace and allocate memory for the read buffer as before.
try {
if (dataset_id >= 0)
dataspace_id = H5.H5Dget_space(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sget_simple_extent_dims(dataspace_id, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Allocate array of pointers to rows.
dset_data = new int[(int) dims[0]][(int) dims[1]];
// Read the data using the default properties.
try {
if (dataset_id >= 0)
H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
System.out.println("Dataset after extension:");
for (int indx = 0; indx < dims[0]; indx++) {
System.out.print(" [ ");
for (int jndx = 0; jndx < dims[1]; jndx++)
System.out.print(dset_data[indx][jndx] + " ");
System.out.println("]");
}
System.out.println();
// End access to the dataset and release resources used by it.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_D_UnlimitedAdd.writeUnlimited();
H5Ex_D_UnlimitedAdd.extendUnlimited();
H5Ex_D_UnlimitedAdd.readUnlimited();
}
}
@@ -0,0 +1,504 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to create and extend an unlimited
dataset with gzip compression. The program first writes
integers to a gzip compressed dataset with dataspace
dimensions of DIM_XxDIM_Y, then closes the file. Next, it
reopens the file, reads back the data, outputs it to the
screen, extends the dataset, and writes new data to the
extended portions of the dataset. Finally it reopens the
file again, reads back the data, and outputs it to the
screen.
************************************************************/
package examples.datasets;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_D_UnlimitedGzip {
private static String FILENAME = "H5Ex_D_UnlimitedGzip.h5";
private static String DATASETNAME = "DS1";
private static final int DIM_X = 4;
private static final int DIM_Y = 7;
private static final int EDIM_X = 6;
private static final int EDIM_Y = 10;
private static final int CHUNK_X = 4;
private static final int CHUNK_Y = 4;
private static final int RANK = 2;
private static final int NDIMS = 2;
// Values for the status of space allocation
enum H5Z_filter {
H5Z_FILTER_ERROR(HDF5Constants.H5Z_FILTER_ERROR), H5Z_FILTER_NONE(HDF5Constants.H5Z_FILTER_NONE), H5Z_FILTER_DEFLATE(
HDF5Constants.H5Z_FILTER_DEFLATE), H5Z_FILTER_SHUFFLE(HDF5Constants.H5Z_FILTER_SHUFFLE), H5Z_FILTER_FLETCHER32(
HDF5Constants.H5Z_FILTER_FLETCHER32), H5Z_FILTER_SZIP(HDF5Constants.H5Z_FILTER_SZIP), H5Z_FILTER_NBIT(
HDF5Constants.H5Z_FILTER_NBIT), H5Z_FILTER_SCALEOFFSET(HDF5Constants.H5Z_FILTER_SCALEOFFSET), H5Z_FILTER_RESERVED(
HDF5Constants.H5Z_FILTER_RESERVED), H5Z_FILTER_MAX(HDF5Constants.H5Z_FILTER_MAX);
private static final Map<Integer, H5Z_filter> lookup = new HashMap<Integer, H5Z_filter>();
static {
for (H5Z_filter s : EnumSet.allOf(H5Z_filter.class))
lookup.put(s.getCode(), s);
}
private int code;
H5Z_filter(int layout_type) {
this.code = layout_type;
}
public int getCode() {
return this.code;
}
public static H5Z_filter get(int code) {
return lookup.get(code);
}
}
private static boolean checkGzipFilter() {
try {
int available = H5.H5Zfilter_avail(HDF5Constants.H5Z_FILTER_DEFLATE);
if (available == 0) {
System.out.println("gzip filter not available.");
return false;
}
}
catch (Exception e) {
e.printStackTrace();
}
try {
int filter_info = H5.H5Zget_filter_info(HDF5Constants.H5Z_FILTER_DEFLATE);
if (((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_ENCODE_ENABLED) == 0)
|| ((filter_info & HDF5Constants.H5Z_FILTER_CONFIG_DECODE_ENABLED) == 0)) {
System.out.println("gzip filter not available for encoding and decoding.");
return false;
}
}
catch (Exception e) {
e.printStackTrace();
}
return true;
}
private static void writeUnlimited() {
long file_id = -1;
long dcpl_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long[] dims = { DIM_X, DIM_Y };
long[] chunk_dims = { CHUNK_X, CHUNK_Y };
long[] maxdims = { HDF5Constants.H5S_UNLIMITED, HDF5Constants.H5S_UNLIMITED };
int[][] dset_data = new int[DIM_X][DIM_Y];
// Initialize the dataset.
for (int indx = 0; indx < DIM_X; indx++)
for (int jndx = 0; jndx < DIM_Y; jndx++)
dset_data[indx][jndx] = indx * jndx - jndx;
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace with unlimited dimensions.
try {
dataspace_id = H5.H5Screate_simple(RANK, dims, maxdims);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset creation property list, add the gzip compression
// filter.
try {
dcpl_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_CREATE);
if (dcpl_id >= 0) {
H5.H5Pset_deflate(dcpl_id, 9);
// Set the chunk size.
H5.H5Pset_chunk(dcpl_id, NDIMS, chunk_dims);
}
}
catch (Exception e) {
e.printStackTrace();
}
// Create the unlimited dataset.
try {
if ((file_id >= 0) && (dataspace_id >= 0) && (dcpl_id >= 0))
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, dataspace_id,
HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the data to the dataset.
try {
if (dataset_id >= 0)
H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dcpl_id >= 0)
H5.H5Pclose(dcpl_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void extendUnlimited() {
long file_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long[] dims = { DIM_X, DIM_Y };
long[] extdims = { EDIM_X, EDIM_Y };
long[] start = { 0, 0 };
long[] count = new long[2];
int[][] dset_data;
int[][] extend_dset_data = new int[EDIM_X][EDIM_Y];
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDWR, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Get dataspace and allocate memory for read buffer. This is a
// two dimensional dataset so the dynamic allocation must be done
// in steps.
try {
if (dataset_id >= 0)
dataspace_id = H5.H5Dget_space(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sget_simple_extent_dims(dataspace_id, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Allocate array of pointers to rows.
dset_data = new int[(int) dims[0]][(int) dims[1]];
// Read the data using the default properties.
try {
if (dataset_id >= 0)
H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
System.out.println("Dataset before extension:");
for (int indx = 0; indx < DIM_X; indx++) {
System.out.print(" [ ");
for (int jndx = 0; jndx < DIM_Y; jndx++)
System.out.print(dset_data[indx][jndx] + " ");
System.out.println("]");
}
System.out.println();
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Extend the dataset.
try {
if (dataset_id >= 0)
H5.H5Dset_extent(dataset_id, extdims);
}
catch (Exception e) {
e.printStackTrace();
}
// Retrieve the dataspace for the newly extended dataset.
try {
if (dataset_id >= 0)
dataspace_id = H5.H5Dget_space(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Initialize data for writing to the extended dataset.
for (int indx = 0; indx < EDIM_X; indx++)
for (int jndx = 0; jndx < EDIM_Y; jndx++)
extend_dset_data[indx][jndx] = jndx;
// Select the entire dataspace.
try {
if (dataspace_id >= 0) {
H5.H5Sselect_all(dataspace_id);
// Subtract a hyperslab reflecting the original dimensions from the
// selection. The selection now contains only the newly extended
// portions of the dataset.
count[0] = dims[0];
count[1] = dims[1];
H5.H5Sselect_hyperslab(dataspace_id, HDF5Constants.H5S_SELECT_NOTB, start, null, count, null);
// Write the data to the selected portion of the dataset.
if (dataset_id >= 0)
H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, dataspace_id,
HDF5Constants.H5P_DEFAULT, extend_dset_data);
}
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void readUnlimited() {
long file_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long dcpl_id = -1;
long[] dims = { DIM_X, DIM_Y };
int[][] dset_data;
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Retrieve the dataset creation property list.
try {
if (dataset_id >= 0)
dcpl_id = H5.H5Dget_create_plist(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Retrieve and print the filter type. Here we only retrieve the
// first filter because we know that we only added one filter.
try {
if (dcpl_id >= 0) {
// Java lib requires a valid filter_name object and cd_values
int[] flags = { 0 };
long[] cd_nelmts = { 1 };
int[] cd_values = { 0 };
String[] filter_name = { "" };
int[] filter_config = { 0 };
int filter_type = -1;
filter_type = H5
.H5Pget_filter(dcpl_id, 0, flags, cd_nelmts, cd_values, 120, filter_name, filter_config);
System.out.print("Filter type is: ");
switch (H5Z_filter.get(filter_type)) {
case H5Z_FILTER_DEFLATE:
System.out.println("H5Z_FILTER_DEFLATE");
break;
case H5Z_FILTER_SHUFFLE:
System.out.println("H5Z_FILTER_SHUFFLE");
break;
case H5Z_FILTER_FLETCHER32:
System.out.println("H5Z_FILTER_FLETCHER32");
break;
case H5Z_FILTER_SZIP:
System.out.println("H5Z_FILTER_SZIP");
break;
default:
System.out.println("H5Z_FILTER_ERROR");
}
System.out.println();
}
}
catch (Exception e) {
e.printStackTrace();
}
// Get dataspace and allocate memory for the read buffer as before.
try {
if (dataset_id >= 0)
dataspace_id = H5.H5Dget_space(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sget_simple_extent_dims(dataspace_id, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Allocate array of pointers to rows.
dset_data = new int[(int) dims[0]][(int) dims[1]];
// Read the data using the default properties.
try {
if (dataset_id >= 0)
H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
System.out.println("Dataset after extension:");
for (int indx = 0; indx < dims[0]; indx++) {
System.out.print(" [ ");
for (int jndx = 0; jndx < dims[1]; jndx++)
System.out.print(dset_data[indx][jndx] + " ");
System.out.println("]");
}
System.out.println();
// End access to the dataset and release resources used by it.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
// Check if gzip compression is available and can be used for both
// compression and decompression. Normally we do not perform error
// checking in these examples for the sake of clarity, but in this
// case we will make an exception because this filter is an
// optional part of the hdf5 library.
if (H5Ex_D_UnlimitedGzip.checkGzipFilter()) {
H5Ex_D_UnlimitedGzip.writeUnlimited();
H5Ex_D_UnlimitedGzip.extendUnlimited();
H5Ex_D_UnlimitedGzip.readUnlimited();
}
}
}
@@ -0,0 +1,379 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to create and extend an unlimited
dataset. The program first writes integers to a dataset
with dataspace dimensions of DIM_XxDIM_Y, then closes the
file. Next, it reopens the file, reads back the data,
outputs it to the screen, extends the dataset, and writes
new data to the entire extended dataset. Finally it
reopens the file again, reads back the data, and utputs it
to the screen.
************************************************************/
package examples.datasets;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_D_UnlimitedMod {
private static String FILENAME = "H5Ex_D_UnlimitedMod.h5";
private static String DATASETNAME = "DS1";
private static final int DIM_X = 4;
private static final int DIM_Y = 7;
private static final int EDIM_X = 6;
private static final int EDIM_Y = 10;
private static final int CHUNK_X = 4;
private static final int CHUNK_Y = 4;
private static final int RANK = 2;
private static final int NDIMS = 2;
private static void writeUnlimited() {
long file_id = -1;
long dcpl_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long[] dims = { DIM_X, DIM_Y };
long[] chunk_dims = { CHUNK_X, CHUNK_Y };
long[] maxdims = { HDF5Constants.H5S_UNLIMITED, HDF5Constants.H5S_UNLIMITED };
int[][] dset_data = new int[DIM_X][DIM_Y];
// Initialize the dataset.
for (int indx = 0; indx < DIM_X; indx++)
for (int jndx = 0; jndx < DIM_Y; jndx++)
dset_data[indx][jndx] = indx * jndx - jndx;
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace with unlimited dimensions.
try {
dataspace_id = H5.H5Screate_simple(RANK, dims, maxdims);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset creation property list.
try {
dcpl_id = H5.H5Pcreate(HDF5Constants.H5P_DATASET_CREATE);
}
catch (Exception e) {
e.printStackTrace();
}
// Set the chunk size.
try {
if (dcpl_id >= 0)
H5.H5Pset_chunk(dcpl_id, NDIMS, chunk_dims);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the unlimited dataset.
try {
if ((file_id >= 0) && (dataspace_id >= 0) && (dcpl_id >= 0))
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, dataspace_id,
HDF5Constants.H5P_DEFAULT, dcpl_id, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the data to the dataset.
try {
if (dataset_id >= 0)
H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dcpl_id >= 0)
H5.H5Pclose(dcpl_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void extendUnlimited() {
long file_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long[] dims = { DIM_X, DIM_Y };
long[] extdims = { EDIM_X, EDIM_Y };
int[][] dset_data;
int[][] extend_dset_data = new int[EDIM_X][EDIM_Y];
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDWR, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Get dataspace and allocate memory for read buffer. This is a
// two dimensional dataset so the dynamic allocation must be done
// in steps.
try {
if (dataset_id >= 0)
dataspace_id = H5.H5Dget_space(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sget_simple_extent_dims(dataspace_id, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Allocate array of pointers to rows.
dset_data = new int[(int) dims[0]][(int) dims[1]];
// Read the data using the default properties.
try {
if (dataset_id >= 0)
H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
System.out.println("Dataset before extension:");
for (int indx = 0; indx < DIM_X; indx++) {
System.out.print(" [ ");
for (int jndx = 0; jndx < DIM_Y; jndx++)
System.out.print(dset_data[indx][jndx] + " ");
System.out.println("]");
}
System.out.println();
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Extend the dataset.
try {
if (dataset_id >= 0)
H5.H5Dset_extent(dataset_id, extdims);
}
catch (Exception e) {
e.printStackTrace();
}
// Retrieve the dataspace for the newly extended dataset.
try {
if (dataset_id >= 0)
dataspace_id = H5.H5Dget_space(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Initialize data for writing to the extended dataset.
for (int indx = 0; indx < EDIM_X; indx++)
for (int jndx = 0; jndx < EDIM_Y; jndx++)
extend_dset_data[indx][jndx] = jndx;
// Write the data tto the extended dataset.
try {
if ((dataspace_id >= 0) && (dataset_id >= 0))
H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, dataspace_id,
HDF5Constants.H5P_DEFAULT, extend_dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void readUnlimited() {
long file_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long[] dims = { DIM_X, DIM_Y };
int[][] dset_data;
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Get dataspace and allocate memory for the read buffer as before.
try {
if (dataset_id >= 0)
dataspace_id = H5.H5Dget_space(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sget_simple_extent_dims(dataspace_id, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Allocate array of pointers to rows.
dset_data = new int[(int) dims[0]][(int) dims[1]];
// Read the data using the default properties.
try {
if (dataset_id >= 0)
H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
System.out.println("Dataset after extension:");
for (int indx = 0; indx < dims[0]; indx++) {
System.out.print(" [ ");
for (int jndx = 0; jndx < dims[1]; jndx++)
System.out.print(dset_data[indx][jndx] + " ");
System.out.println("]");
}
System.out.println();
// End access to the dataset and release resources used by it.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_D_UnlimitedMod.writeUnlimited();
H5Ex_D_UnlimitedMod.extendUnlimited();
H5Ex_D_UnlimitedMod.readUnlimited();
}
}
+78
View File
@@ -0,0 +1,78 @@
#
# Copyright by The HDF Group.
# Copyright by the Board of Trustees of the University of Illinois.
# All rights reserved.
#
# This file is part of HDF5. The full HDF5 copyright notice, including
# terms governing use, modification, and redistribution, is contained in
# the files COPYING and Copyright.html. COPYING can be found at the root
# of the source code distribution tree; Copyright.html can be found at the
# root level of an installed copy of the electronic HDF5 document set and
# is linked from the top-level documents page. It can also be found at
# http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have
# access to either file, you may request a copy from help@hdfgroup.org.
##
## Makefile.am
## Run automake to generate a Makefile.in from this file.
##
#
# HDF5 Java Library Examples Makefile(.in)
include $(top_srcdir)/config/commence.am
# Mark this directory as part of the JNI API
JAVA_API=yes
JAVAROOT = .classes
classes:
$(MKDIR_P) $(@D)/$(JAVAROOT)
pkgpath = examples/datasets
hdfjarfile = jar$(PACKAGE_TARNAME)-$(PACKAGE_VERSION).jar
CLASSPATH_ENV=CLASSPATH=.:$(JAVAROOT):$(top_builddir)/java/src/$(hdfjarfile):$(top_srcdir)/java/lib/slf4j-api-1.7.5.jar:$(top_srcdir)/java/lib/ext/slf4j-simple-1.7.5.jar:$$CLASSPATH
jarfile = jar$(PACKAGE_TARNAME)datasets.jar
AM_JAVACFLAGS = $(H5_JAVACFLAGS) -deprecation
TESTPACKAGE =
noinst_JAVA = \
H5Ex_D_Alloc.java \
H5Ex_D_Checksum.java \
H5Ex_D_Chunk.java \
H5Ex_D_Compact.java \
H5Ex_D_External.java \
H5Ex_D_FillValue.java \
H5Ex_D_Gzip.java \
H5Ex_D_Hyperslab.java \
H5Ex_D_ReadWrite.java \
H5Ex_D_Shuffle.java \
H5Ex_D_Szip.java \
H5Ex_D_UnlimitedAdd.java \
H5Ex_D_UnlimitedGzip.java \
H5Ex_D_UnlimitedMod.java \
H5Ex_D_Nbit.java \
H5Ex_D_Transform.java \
H5Ex_D_Sofloat.java \
H5Ex_D_Soint.java
$(jarfile): classnoinst.stamp classes
$(JAR) cvf $@ -C $(JAVAROOT)/ $(pkgpath)
noinst_DATA = $(jarfile)
.PHONY: classes
check_SCRIPTS = runExample.sh
TEST_SCRIPT = $(check_SCRIPTS)
CLEANFILES = classnoinst.stamp $(jarfile) $(JAVAROOT)/$(pkgpath)/*.class runExample.sh
clean:
rm -rf $(JAVAROOT)
rm -f $(jarfile)
rm -f classnoinst.stamp
include $(top_srcdir)/config/conclude.am
+413
View File
@@ -0,0 +1,413 @@
#! /bin/sh
#
# Copyright by The HDF Group.
# Copyright by the Board of Trustees of the University of Illinois.
# All rights reserved.
#
# This file is part of HDF5. The full HDF5 copyright notice, including
# terms governing use, modification, and redistribution, is contained in
# the files COPYING and Copyright.html. COPYING can be found at the root
# of the source code distribution tree; Copyright.html can be found at the
# root level of an installed copy of the electronic HDF5 document set and
# is linked from the top-level documents page. It can also be found at
# http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have
# access to either file, you may request a copy from help@hdfgroup.org.
#
top_builddir=@top_builddir@
top_srcdir=@top_srcdir@
srcdir=@srcdir@
USE_FILTER_SZIP="@USE_FILTER_SZIP@"
USE_FILTER_DEFLATE="@USE_FILTER_DEFLATE@"
TESTNAME=EX_Datasets
EXIT_SUCCESS=0
EXIT_FAILURE=1
# Set up default variable values if not supplied by the user.
RM='rm -rf'
CMP='cmp'
DIFF='diff -c'
CP='cp'
DIRNAME='dirname'
LS='ls'
AWK='awk'
nerrors=0
# where the libs exist
HDFLIB_HOME="$top_srcdir/java/lib"
BLDLIBDIR="./lib"
BLDDIR="."
HDFTEST_HOME="$top_srcdir/java/examples/datasets"
JARFILE=jar@PACKAGE_TARNAME@-@PACKAGE_VERSION@.jar
TESTJARFILE=jar@PACKAGE_TARNAME@datasets.jar
test -d $BLDLIBDIR || mkdir -p $BLDLIBDIR
######################################################################
# library files
# --------------------------------------------------------------------
# All the library files copy from source directory to test directory
# NOTE: Keep this framework to add/remove test files.
# This list are also used for checking exist.
# Comment '#' without space can be used.
# --------------------------------------------------------------------
LIST_LIBRARY_FILES="
$HDFLIB_HOME/slf4j-api-1.7.5.jar
$HDFLIB_HOME/ext/slf4j-simple-1.7.5.jar
$top_builddir/src/.libs/libhdf5.*
$top_builddir/java/src/jni/.libs/libhdf5_java.*
$top_builddir/java/src/$JARFILE
"
LIST_DATA_FILES="
$HDFTEST_HOME/../testfiles/examples.datasets.H5Ex_D_Alloc.txt
$HDFTEST_HOME/../testfiles/examples.datasets.H5Ex_D_Checksum.txt
$HDFTEST_HOME/../testfiles/examples.datasets.H5Ex_D_Chunk.txt
$HDFTEST_HOME/../testfiles/examples.datasets.H5Ex_D_Compact.txt
$HDFTEST_HOME/../testfiles/examples.datasets.H5Ex_D_External.txt
$HDFTEST_HOME/../testfiles/examples.datasets.H5Ex_D_FillValue.txt
$HDFTEST_HOME/../testfiles/examples.datasets.H5Ex_D_Gzip.txt
$HDFTEST_HOME/../testfiles/examples.datasets.H5Ex_D_Hyperslab.txt
$HDFTEST_HOME/../testfiles/examples.datasets.H5Ex_D_ReadWrite.txt
$HDFTEST_HOME/../testfiles/examples.datasets.H5Ex_D_Shuffle.txt
$HDFTEST_HOME/../testfiles/examples.datasets.H5Ex_D_Szip.txt
$HDFTEST_HOME/../testfiles/examples.datasets.H5Ex_D_UnlimitedAdd.txt
$HDFTEST_HOME/../testfiles/examples.datasets.H5Ex_D_UnlimitedGzip.txt
$HDFTEST_HOME/../testfiles/examples.datasets.H5Ex_D_UnlimitedMod.txt
$HDFTEST_HOME/../testfiles/examples.datasets.H5Ex_D_Nbit.txt
$HDFTEST_HOME/../testfiles/examples.datasets.H5Ex_D_Transform.txt
$HDFTEST_HOME/../testfiles/examples.datasets.H5Ex_D_Sofloat.txt
$HDFTEST_HOME/../testfiles/examples.datasets.H5Ex_D_Soint.txt
"
#
# copy files from source dirs to test dir
#
COPY_LIBFILES="$LIST_LIBRARY_FILES"
COPY_LIBFILES_TO_BLDLIBDIR()
{
# copy test files. Used -f to make sure get a new copy
for tstfile in $COPY_LIBFILES
do
# ignore '#' comment
echo $tstfile | tr -d ' ' | grep '^#' > /dev/null
RET=$?
if [ $RET -eq 1 ]; then
# skip cp if srcdir is same as destdir
# this occurs when build/test performed in source dir and
# make cp fail
SDIR=`$DIRNAME $tstfile`
INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'`
INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'`
if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then
$CP -f $tstfile $BLDLIBDIR
if [ $? -ne 0 ]; then
echo "Error: FAILED to copy $tstfile ."
# Comment out this to CREATE expected file
exit $EXIT_FAILURE
fi
fi
fi
done
}
CLEAN_LIBFILES_AND_BLDLIBDIR()
{
# skip rm if srcdir is same as destdir
# this occurs when build/test performed in source dir and
# make cp fail
SDIR=`$DIRNAME $tstfile`
INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'`
INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'`
if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then
$RM $BLDLIBDIR
fi
}
COPY_DATAFILES="$LIST_DATA_FILES"
COPY_DATAFILES_TO_BLDDIR()
{
# copy test files. Used -f to make sure get a new copy
for tstfile in $COPY_DATAFILES
do
# ignore '#' comment
echo $tstfile | tr -d ' ' | grep '^#' > /dev/null
RET=$?
if [ $RET -eq 1 ]; then
# skip cp if srcdir is same as destdir
# this occurs when build/test performed in source dir and
# make cp fail
SDIR=`$DIRNAME $tstfile`
INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'`
INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'`
if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then
$CP -f $tstfile $BLDDIR
if [ $? -ne 0 ]; then
echo "Error: FAILED to copy $tstfile ."
# Comment out this to CREATE expected file
exit $EXIT_FAILURE
fi
fi
fi
done
}
CLEAN_DATAFILES_AND_BLDDIR()
{
# skip rm if srcdir is same as destdir
# this occurs when build/test performed in source dir and
# make cp fail
SDIR=`$DIRNAME $tstfile`
INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'`
INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'`
if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then
$RM $BLDDIR/*.txt
$RM $BLDDIR/*.out
fi
}
# Print a line-line message left justified in a field of 70 characters
# beginning with the word "Testing".
#
TESTING() {
SPACES=" "
echo "Testing $* $SPACES" | cut -c1-70 | tr -d '\012'
}
# where Java is installed (requires jdk1.7.x)
JAVAEXE=@JAVA@
JAVAEXEFLAGS=@H5_JAVAFLAGS@
###############################################################################
# DO NOT MODIFY BELOW THIS LINE
###############################################################################
# prepare for test
COPY_LIBFILES_TO_BLDLIBDIR
COPY_DATAFILES_TO_BLDDIR
CPATH=".:"$BLDLIBDIR"/"$JARFILE":"$BLDLIBDIR"/slf4j-api-1.7.5.jar:"$BLDLIBDIR"/slf4j-simple-1.7.5.jar:"$TESTJARFILE""
TEST=/usr/bin/test
if [ ! -x /usr/bin/test ]
then
TEST=`which test`
fi
if $TEST -z "$CLASSPATH"; then
CLASSPATH=""
fi
CLASSPATH=$CPATH":"$CLASSPATH
export CLASSPATH
if $TEST -n "$JAVAPATH" ; then
PATH=$JAVAPATH":"$PATH
export PATH
fi
if $TEST -e /bin/uname; then
os_name=`/bin/uname -s`
elif $TEST -e /usr/bin/uname; then
os_name=`/usr/bin/uname -s`
else
os_name=unknown
fi
if $TEST -z "$LD_LIBRARY_PATH" ; then
LD_LIBRARY_PATH=""
fi
case $os_name in
Darwin)
DYLD_LIBRARY_PATH=$BLDLIBDIR:$DYLD_LIBRARY_PATH
export DYLD_LIBRARY_PATH
LD_LIBRARY_PATH=$DYLD_LIBRARY_PATH
;;
*)
LD_LIBRARY_PATH=$BLDLIBDIR:$LD_LIBRARY_PATH
;;
esac
export LD_LIBRARY_PATH
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_Alloc"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_Alloc > H5Ex_D_Alloc.out)
if diff H5Ex_D_Alloc.out examples.datasets.H5Ex_D_Alloc.txt > /dev/null; then
echo " PASSED datasets.H5Ex_D_Alloc"
else
echo "**FAILED** datasets.H5Ex_D_Alloc"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_Checksum"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_Checksum > H5Ex_D_Checksum.out)
if diff H5Ex_D_Checksum.out examples.datasets.H5Ex_D_Checksum.txt > /dev/null; then
echo " PASSED datasets.H5Ex_D_Checksum"
else
echo "**FAILED** datasets.H5Ex_D_Checksum"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_Chunk"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_Chunk > H5Ex_D_Chunk.out)
if diff H5Ex_D_Chunk.out examples.datasets.H5Ex_D_Chunk.txt > /dev/null; then
echo " PASSED datasets.H5Ex_D_Chunk"
else
echo "**FAILED** datasets.H5Ex_D_Chunk"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_Compact"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_Compact > H5Ex_D_Compact.out)
if diff H5Ex_D_Compact.out examples.datasets.H5Ex_D_Compact.txt > /dev/null; then
echo " PASSED datasets.H5Ex_D_Compact"
else
echo "**FAILED** datasets.H5Ex_D_Compact"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_External"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_External > H5Ex_D_External.out)
if diff H5Ex_D_External.out examples.datasets.H5Ex_D_External.txt > /dev/null; then
echo " PASSED datasets.H5Ex_D_External"
else
echo "**FAILED** datasets.H5Ex_D_External"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_FillValue"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_FillValue > H5Ex_D_FillValue.out)
if diff H5Ex_D_FillValue.out examples.datasets.H5Ex_D_FillValue.txt > /dev/null; then
echo " PASSED datasets.H5Ex_D_FillValue"
else
echo "**FAILED** datasets.H5Ex_D_FillValue"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_Gzip"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_Gzip > H5Ex_D_Gzip.out)
if diff H5Ex_D_Gzip.out examples.datasets.H5Ex_D_Gzip.txt > /dev/null; then
echo " PASSED datasets.H5Ex_D_Gzip"
else
echo "**FAILED** datasets.H5Ex_D_Gzip"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_Hyperslab"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_Hyperslab > H5Ex_D_Hyperslab.out)
if diff H5Ex_D_Hyperslab.out examples.datasets.H5Ex_D_Hyperslab.txt > /dev/null; then
echo " PASSED datasets.H5Ex_D_Hyperslab"
else
echo "**FAILED** datasets.H5Ex_D_Hyperslab"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_ReadWrite"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_ReadWrite > H5Ex_D_ReadWrite.out)
if diff H5Ex_D_ReadWrite.out examples.datasets.H5Ex_D_ReadWrite.txt > /dev/null; then
echo " PASSED datasets.H5Ex_D_ReadWrite"
else
echo "**FAILED** datasets.H5Ex_D_ReadWrite"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_Shuffle"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_Shuffle > H5Ex_D_Shuffle.out)
if diff H5Ex_D_Shuffle.out examples.datasets.H5Ex_D_Shuffle.txt > /dev/null; then
echo " PASSED datasets.H5Ex_D_Shuffle"
else
echo "**FAILED** datasets.H5Ex_D_Shuffle"
nerrors="`expr $nerrors + 1`"
fi
if test $USE_FILTER_SZIP = "yes"; then
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_Szip"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_Szip > H5Ex_D_Szip.out)
if diff H5Ex_D_Szip.out examples.datasets.H5Ex_D_Szip.txt > /dev/null; then
echo " PASSED datasets.H5Ex_D_Szip"
else
echo "**FAILED** datasets.H5Ex_D_Szip"
nerrors="`expr $nerrors + 1`"
fi
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_UnlimitedAdd"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_UnlimitedAdd > H5Ex_D_UnlimitedAdd.out)
if diff H5Ex_D_UnlimitedAdd.out examples.datasets.H5Ex_D_UnlimitedAdd.txt > /dev/null; then
echo " PASSED datasets.H5Ex_D_UnlimitedAdd"
else
echo "**FAILED** datasets.H5Ex_D_UnlimitedAdd"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_UnlimitedGzip"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_UnlimitedGzip > H5Ex_D_UnlimitedGzip.out)
if diff H5Ex_D_External.out examples.datasets.H5Ex_D_External.txt > /dev/null; then
echo " PASSED datasets.H5Ex_D_UnlimitedGzip"
else
echo "**FAILED** datasets.H5Ex_D_UnlimitedGzip"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_UnlimitedMod"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_UnlimitedMod > H5Ex_D_UnlimitedMod.out)
if diff H5Ex_D_UnlimitedMod.out examples.datasets.H5Ex_D_UnlimitedMod.txt > /dev/null; then
echo " PASSED datasets.H5Ex_D_UnlimitedMod"
else
echo "**FAILED** datasets.H5Ex_D_UnlimitedMod"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_Nbit"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_Nbit > H5Ex_D_Nbit.out)
if diff H5Ex_D_Nbit.out examples.datasets.H5Ex_D_Nbit.txt > /dev/null; then
echo " PASSED datasets.H5Ex_D_Nbit"
else
echo "**FAILED** datasets.H5Ex_D_Nbit"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_Transform"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_Transform > H5Ex_D_Transform.out)
if diff H5Ex_D_Transform.out examples.datasets.H5Ex_D_Transform.txt > /dev/null; then
echo " PASSED datasets.H5Ex_D_Transform"
else
echo "**FAILED** datasets.H5Ex_D_Transform"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_Sofloat"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_Sofloat > H5Ex_D_Sofloat.out)
if diff H5Ex_D_Sofloat.out examples.datasets.H5Ex_D_Sofloat.txt > /dev/null; then
echo " PASSED datasets.H5Ex_D_Sofloat"
else
echo "**FAILED** datasets.H5Ex_D_Sofloat"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_Soint"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datasets.H5Ex_D_Soint > H5Ex_D_Soint.out)
if diff H5Ex_D_Soint.out examples.datasets.H5Ex_D_Soint.txt > /dev/null; then
echo " PASSED datasets.H5Ex_D_Soint"
else
echo "**FAILED** datasets.H5Ex_D_Soint"
nerrors="`expr $nerrors + 1`"
fi
# Clean up temporary files/directories
CLEAN_LIBFILES_AND_BLDLIBDIR
CLEAN_DATAFILES_AND_BLDDIR
# Report test results and exit
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
+109
View File
@@ -0,0 +1,109 @@
cmake_minimum_required (VERSION 3.1.0)
PROJECT (HDFJAVA_EXAMPLES_DATATYPES Java)
set (CMAKE_VERBOSE_MAKEFILE 1)
INCLUDE_DIRECTORIES (
${HDF5_JAVA_JNI_BINARY_DIR}
${HDF5_JAVA_HDF5_LIB_DIR}
)
set (HDF_JAVA_EXAMPLES
H5Ex_T_Array
H5Ex_T_ArrayAttribute
H5Ex_T_Bit
H5Ex_T_BitAttribute
H5Ex_T_Commit
H5Ex_T_Compound
H5Ex_T_CompoundAttribute
H5Ex_T_Float
H5Ex_T_FloatAttribute
H5Ex_T_Integer
H5Ex_T_IntegerAttribute
H5Ex_T_ObjectReference
H5Ex_T_ObjectReferenceAttribute
H5Ex_T_Opaque
H5Ex_T_OpaqueAttribute
H5Ex_T_String
H5Ex_T_StringAttribute
H5Ex_T_VLString
)
if (WIN32)
set (CMAKE_JAVA_INCLUDE_FLAG_SEP ";")
else (WIN32)
set (CMAKE_JAVA_INCLUDE_FLAG_SEP ":")
endif (WIN32)
set (CMAKE_JAVA_INCLUDE_PATH "${HDF5_JAVA_JARS}")
set (CMAKE_JAVA_CLASSPATH ".")
foreach (CMAKE_INCLUDE_PATH ${CMAKE_JAVA_INCLUDE_PATH})
set (CMAKE_JAVA_CLASSPATH "${CMAKE_JAVA_CLASSPATH}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${CMAKE_INCLUDE_PATH}")
endforeach (CMAKE_INCLUDE_PATH)
foreach (example ${HDF_JAVA_EXAMPLES})
file (WRITE ${PROJECT_BINARY_DIR}/${example}_Manifest.txt
"Main-Class: examples.datatypes.${example}
"
)
add_jar (${example} MANIFEST ${PROJECT_BINARY_DIR}/${example}_Manifest.txt ${example}.java)
get_target_property (${example}_JAR_FILE ${example} JAR_FILE)
# install_jar (${example} ${HJAVA_INSTALL_DATA_DIR}/examples examples)
get_target_property (${example}_CLASSPATH ${example} CLASSDIR)
add_dependencies (${example} ${HDF5_JAVA_HDF5_LIB_TARGET})
endforeach (example ${HDF_JAVA_EXAMPLES})
set (CMAKE_JAVA_INCLUDE_PATH "${HDF5_JAVA_JARS};${HDF5_JAVA_LOGGING_JAR};${HDF5_JAVA_LOGGING_NOP_JAR}")
set (CMAKE_JAVA_CLASSPATH ".")
foreach (HDFJAVA_JAR ${CMAKE_JAVA_INCLUDE_PATH})
set (CMAKE_JAVA_CLASSPATH "${CMAKE_JAVA_CLASSPATH}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${HDFJAVA_JAR}")
endforeach (HDFJAVA_JAR)
MACRO (ADD_H5_TEST resultfile resultcode)
add_test (
NAME JAVA_datatypes-${resultfile}
COMMAND "${CMAKE_COMMAND}"
-D "TEST_TESTER=${CMAKE_Java_RUNTIME};${CMAKE_Java_RUNTIME_FLAGS}"
-D "TEST_PROGRAM=examples.datatypes.${resultfile}"
-D "TEST_ARGS:STRING=${ARGN}"
-D "TEST_CLASSPATH:STRING=${CMAKE_JAVA_CLASSPATH}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${${resultfile}_JAR_FILE}"
-D "TEST_LIBRARY_DIRECTORY=${CMAKE_TEST_OUTPUT_DIRECTORY}"
-D "TEST_FOLDER=${HDFJAVA_EXAMPLES_BINARY_DIR}"
-D "TEST_OUTPUT=datatypes/${resultfile}.out"
-D "TEST_EXPECT=${resultcode}"
-D "TEST_REFERENCE=datatypes/${resultfile}.txt"
-P "${HDF_RESOURCES_DIR}/jrunTest.cmake"
)
if (NOT "${last_test}" STREQUAL "")
set_tests_properties (JAVA_datatypes-${resultfile} PROPERTIES DEPENDS ${last_test})
endif (NOT "${last_test}" STREQUAL "")
set (last_test "JAVA_datatypes-${resultfile}")
ENDMACRO (ADD_H5_TEST file)
if (BUILD_TESTING)
foreach (example ${HDF_JAVA_EXAMPLES})
add_test (
NAME JAVA_datatypes-${example}-clearall-objects
COMMAND ${CMAKE_COMMAND}
-E remove
${HDFJAVA_EXAMPLES_BINARY_DIR}/${example}.h5
${example}.out
${example}.out.err
)
if (NOT "${last_test}" STREQUAL "")
set_tests_properties (JAVA_datatypes-${example}-clearall-objects PROPERTIES DEPENDS ${last_test})
endif (NOT "${last_test}" STREQUAL "")
add_test (
NAME JAVA_datatypes-${example}-copy-objects
COMMAND ${CMAKE_COMMAND}
-E copy_if_different
${HDFJAVA_EXAMPLES_SOURCE_DIR}/testfiles/examples.datatypes.${example}.txt
${HDFJAVA_EXAMPLES_DATATYPES_BINARY_DIR}/${example}.txt
)
set_tests_properties (JAVA_datatypes-${example}-copy-objects PROPERTIES DEPENDS JAVA_datatypes-${example}-clearall-objects)
set (last_test "JAVA_datatypes-${example}-copy-objects")
ADD_H5_TEST (${example} 0)
endforeach (example ${HDF_JAVA_EXAMPLES})
endif (BUILD_TESTING)
+282
View File
@@ -0,0 +1,282 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to read and write array datatypes
to a dataset. The program first writes integers arrays of
dimension ADIM0xADIM1 to a dataset with a dataspace of
DIM0, then closes the file. Next, it reopens the file,
reads back the data, and outputs it to the screen.
************************************************************/
package examples.datatypes;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_T_Array {
private static String FILENAME = "H5Ex_T_Array.h5";
private static String DATASETNAME = "DS1";
private static final int DIM0 = 4;
private static final int ADIM0 = 3;
private static final int ADIM1 = 5;
private static final int RANK = 1;
private static final int NDIMS = 2;
private static void CreateDataset() {
long file_id = -1;
long filetype_id = -1;
long memtype_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long[] dims = { DIM0 };
long[] adims = { ADIM0, ADIM1 };
int[][][] dset_data = new int[DIM0][ADIM0][ADIM1];
// Initialize data. indx is the element in the dataspace, jndx and kndx the
// elements within the array datatype.
for (int indx = 0; indx < DIM0; indx++)
for (int jndx = 0; jndx < ADIM0; jndx++)
for (int kndx = 0; kndx < ADIM1; kndx++)
dset_data[indx][jndx][kndx] = indx * jndx - jndx * kndx + indx * kndx;
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create array datatypes for file.
try {
filetype_id = H5.H5Tarray_create(HDF5Constants.H5T_STD_I64LE, NDIMS, adims);
}
catch (Exception e) {
e.printStackTrace();
}
// Create array datatypes for memory.
try {
memtype_id = H5.H5Tarray_create(HDF5Constants.H5T_NATIVE_INT, NDIMS, adims);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
try {
dataspace_id = H5.H5Screate_simple(RANK, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset.
try {
if ((file_id >= 0) && (dataspace_id >= 0) && (filetype_id >= 0))
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, filetype_id, dataspace_id, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the dataset.
try {
if ((dataset_id >= 0) && (memtype_id >= 0))
H5.H5Dwrite(dataset_id, memtype_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the file type.
try {
if (filetype_id >= 0)
H5.H5Tclose(filetype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the mem type.
try {
if (memtype_id >= 0)
H5.H5Tclose(memtype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void ReadDataset() {
long file_id = -1;
long filetype_id = -1;
long memtype_id = -1;
long dataset_id = -1;
long[] dims = { DIM0 };
long[] adims = { ADIM0, ADIM1 };
int[][][] dset_data;
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Get the datatype.
try {
if (dataset_id >= 0)
filetype_id = H5.H5Dget_type(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Get the datatype's dimensions.
try {
if (filetype_id >= 0)
H5.H5Tget_array_dims(filetype_id, adims);
}
catch (Exception e) {
e.printStackTrace();
}
// Allocate array of pointers to two-dimensional arrays (the
// elements of the dataset.
dset_data = new int[(int) dims[0]][(int) (adims[0])][(int) (adims[1])];
// Create array datatypes for memory.
try {
memtype_id = H5.H5Tarray_create(HDF5Constants.H5T_NATIVE_INT, 2, adims);
}
catch (Exception e) {
e.printStackTrace();
}
// Read data.
try {
if ((dataset_id >= 0) && (memtype_id >= 0))
H5.H5Dread(dataset_id, memtype_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
for (int indx = 0; indx < dims[0]; indx++) {
System.out.println(DATASETNAME + " [" + indx + "]:");
for (int jndx = 0; jndx < adims[0]; jndx++) {
System.out.print(" [");
for (int kndx = 0; kndx < adims[1]; kndx++)
System.out.print(dset_data[indx][jndx][kndx] + " ");
System.out.println("]");
}
System.out.println();
}
System.out.println();
// End access to the dataset and release resources used by it.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the file type.
try {
if (filetype_id >= 0)
H5.H5Tclose(filetype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the mem type.
try {
if (memtype_id >= 0)
H5.H5Tclose(memtype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_T_Array.CreateDataset();
// Now we begin the read section of this example. Here we assume
// the dataset and array have the same name and rank, but can have
// any size. Therefore we must allocate a new array to read in
// data using malloc().
H5Ex_T_Array.ReadDataset();
}
}
@@ -0,0 +1,322 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to read and write array datatypes
to an attribute. The program first writes integers arrays
of dimension ADIM0xADIM1 to an attribute with a dataspace
of DIM0, then closes the file. Next, it reopens the
file, reads back the data, and outputs it to the screen.
************************************************************/
package examples.datatypes;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_T_ArrayAttribute {
private static String FILENAME = "H5Ex_T_ArrayAttribute.h5";
private static String DATASETNAME = "DS1";
private static String ATTRIBUTENAME = "A1";
private static final int DIM0 = 4;
private static final int ADIM0 = 3;
private static final int ADIM1 = 5;
private static final int RANK = 1;
private static final int NDIMS = 2;
private static void CreateDataset() {
long file_id = -1;
long filetype_id = -1;
long memtype_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long attribute_id = -1;
long[] dims = { DIM0 };
long[] adims = { ADIM0, ADIM1 };
int[][][] dset_data = new int[DIM0][ADIM0][ADIM1];
// Initialize data. indx is the element in the dataspace, jndx and kndx the
// elements within the array datatype.
for (int indx = 0; indx < DIM0; indx++)
for (int jndx = 0; jndx < ADIM0; jndx++)
for (int kndx = 0; kndx < ADIM1; kndx++)
dset_data[indx][jndx][kndx] = indx * jndx - jndx * kndx + indx * kndx;
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create array datatypes for file.
try {
filetype_id = H5.H5Tarray_create(HDF5Constants.H5T_STD_I64LE, NDIMS, adims);
}
catch (Exception e) {
e.printStackTrace();
}
// Create array datatypes for memory.
try {
memtype_id = H5.H5Tarray_create(HDF5Constants.H5T_NATIVE_INT, NDIMS, adims);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataset with a scalar dataspace.
try {
dataspace_id = H5.H5Screate(HDF5Constants.H5S_SCALAR);
if (dataspace_id >= 0) {
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, dataspace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
H5.H5Sclose(dataspace_id);
dataspace_id = -1;
}
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
try {
dataspace_id = H5.H5Screate_simple(RANK, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the attribute and write the array data to it.
try {
if ((dataset_id >= 0) && (dataspace_id >= 0) && (filetype_id >= 0))
attribute_id = H5.H5Acreate(dataset_id, ATTRIBUTENAME, filetype_id, dataspace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the dataset.
try {
if ((attribute_id >= 0) && (memtype_id >= 0))
H5.H5Awrite(attribute_id, memtype_id, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (attribute_id >= 0)
H5.H5Aclose(attribute_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the file type.
try {
if (filetype_id >= 0)
H5.H5Tclose(filetype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the mem type.
try {
if (memtype_id >= 0)
H5.H5Tclose(memtype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void ReadDataset() {
long file_id = -1;
long filetype_id = -1;
long memtype_id = -1;
long dataset_id = -1;
long attribute_id = -1;
long[] dims = { DIM0 };
long[] adims = { ADIM0, ADIM1 };
int[][][] dset_data;
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
attribute_id = H5.H5Aopen_by_name(dataset_id, ".", ATTRIBUTENAME, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Get the datatype.
try {
if (attribute_id >= 0)
filetype_id = H5.H5Aget_type(attribute_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Get the datatype's dimensions.
try {
if (filetype_id >= 0)
H5.H5Tget_array_dims(filetype_id, adims);
}
catch (Exception e) {
e.printStackTrace();
}
// Allocate array of pointers to two-dimensional arrays (the
// elements of the dataset.
dset_data = new int[(int) dims[0]][(int) (adims[0])][(int) (adims[1])];
// Create array datatypes for memory.
try {
memtype_id = H5.H5Tarray_create(HDF5Constants.H5T_NATIVE_INT, 2, adims);
}
catch (Exception e) {
e.printStackTrace();
}
// Read data.
try {
if ((attribute_id >= 0) && (memtype_id >= 0))
H5.H5Aread(attribute_id, memtype_id, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
for (int indx = 0; indx < dims[0]; indx++) {
System.out.println(ATTRIBUTENAME + " [" + indx + "]:");
for (int jndx = 0; jndx < adims[0]; jndx++) {
System.out.print(" [");
for (int kndx = 0; kndx < adims[1]; kndx++)
System.out.print(dset_data[indx][jndx][kndx] + " ");
System.out.println("]");
}
System.out.println();
}
System.out.println();
// End access to the dataset and release resources used by it.
try {
if (attribute_id >= 0)
H5.H5Aclose(attribute_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the file type.
try {
if (filetype_id >= 0)
H5.H5Tclose(filetype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the mem type.
try {
if (memtype_id >= 0)
H5.H5Tclose(memtype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_T_ArrayAttribute.CreateDataset();
// Now we begin the read section of this example. Here we assume
// the dataset and array have the same name and rank, but can have
// any size. Therefore we must allocate a new array to read in
// data using malloc().
H5Ex_T_ArrayAttribute.ReadDataset();
}
}
+227
View File
@@ -0,0 +1,227 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to read and write bitfield
datatypes to a dataset. The program first writes bit
fields to a dataset with a dataspace of DIM0xDIM1, then
closes the file. Next, it reopens the file, reads back
the data, and outputs it to the screen.
************************************************************/
package examples.datatypes;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_T_Bit {
private static String FILENAME = "H5Ex_T_Bit.h5";
private static String DATASETNAME = "DS1";
private static final int DIM0 = 4;
private static final int DIM1 = 7;
private static final int RANK = 2;
private static void CreateDataset() {
long file_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long[] dims = { DIM0, DIM1 };
int[][] dset_data = new int[DIM0][DIM1];
// Initialize data.
for (int indx = 0; indx < DIM0; indx++)
for (int jndx = 0; jndx < DIM1; jndx++) {
dset_data[indx][jndx] = 0;
dset_data[indx][jndx] |= (indx * jndx - jndx) & 0x03; /* Field "A" */
dset_data[indx][jndx] |= (indx & 0x03) << 2; /* Field "B" */
dset_data[indx][jndx] |= (jndx & 0x03) << 4; /* Field "C" */
dset_data[indx][jndx] |= ((indx + jndx) & 0x03) << 6; /* Field "D" */
}
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
try {
dataspace_id = H5.H5Screate_simple(RANK, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset.
try {
if ((file_id >= 0) && (dataspace_id >= 0))
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_B8BE, dataspace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the bitfield data to the dataset.
try {
if (dataset_id >= 0)
H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_B8, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void ReadDataset() {
long file_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long[] dims = { DIM0, DIM1 };
int[][] dset_data;
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Get dataspace and allocate memory for read buffer.
try {
if (dataset_id >= 0)
dataspace_id = H5.H5Dget_space(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sget_simple_extent_dims(dataspace_id, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Allocate array of pointers to two-dimensional arrays (the
// elements of the dataset.
dset_data = new int[(int) dims[0]][(int) (dims[1])];
// Read data.
try {
if (dataset_id >= 0)
H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_B8, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
System.out.println(DATASETNAME + ":");
for (int indx = 0; indx < dims[0]; indx++) {
System.out.print(" [");
for (int jndx = 0; jndx < dims[1]; jndx++) {
System.out.print("{" + (dset_data[indx][jndx] & 0x03) + ", ");
System.out.print(((dset_data[indx][jndx] >> 2) & 0x03) + ", ");
System.out.print(((dset_data[indx][jndx] >> 4) & 0x03) + ", ");
System.out.print(((dset_data[indx][jndx] >> 6) & 0x03) + "}");
}
System.out.println("]");
}
System.out.println();
// End access to the dataset and release resources used by it.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_T_Bit.CreateDataset();
// Now we begin the read section of this example. Here we assume
// the dataset and array have the same name and rank, but can have
// any size. Therefore we must allocate a new array to read in
// data using malloc().
H5Ex_T_Bit.ReadDataset();
}
}
@@ -0,0 +1,267 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to read and write bitfield
datatypes to an attribute. The program first writes bit
fields to an attribute with a dataspace of DIM0xDIM1, then
closes the file. Next, it reopens the file, reads back
the data, and outputs it to the screen.
************************************************************/
package examples.datatypes;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_T_BitAttribute {
private static String FILENAME = "H5Ex_T_BitAttribute.h5";
private static String DATASETNAME = "DS1";
private static String ATTRIBUTENAME = "A1";
private static final int DIM0 = 4;
private static final int DIM1 = 7;
private static final int RANK = 2;
private static void CreateDataset() {
long file_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long attribute_id = -1;
long[] dims = { DIM0, DIM1 };
int[][] dset_data = new int[DIM0][DIM1];
// Initialize data.
for (int indx = 0; indx < DIM0; indx++)
for (int jndx = 0; jndx < DIM1; jndx++) {
dset_data[indx][jndx] = 0;
dset_data[indx][jndx] |= (indx * jndx - jndx) & 0x03; /* Field "A" */
dset_data[indx][jndx] |= (indx & 0x03) << 2; /* Field "B" */
dset_data[indx][jndx] |= (jndx & 0x03) << 4; /* Field "C" */
dset_data[indx][jndx] |= ((indx + jndx) & 0x03) << 6; /* Field "D" */
}
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataset with a scalar dataspace.
try {
dataspace_id = H5.H5Screate(HDF5Constants.H5S_SCALAR);
if (dataspace_id >= 0) {
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, dataspace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
H5.H5Sclose(dataspace_id);
dataspace_id = -1;
}
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
try {
dataspace_id = H5.H5Screate_simple(RANK, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the attribute and write the array data to it.
try {
if ((dataset_id >= 0) && (dataspace_id >= 0))
attribute_id = H5.H5Acreate(dataset_id, ATTRIBUTENAME, HDF5Constants.H5T_STD_B8BE, dataspace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the dataset.
try {
if (attribute_id >= 0)
H5.H5Awrite(attribute_id, HDF5Constants.H5T_NATIVE_B8, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (attribute_id >= 0)
H5.H5Aclose(attribute_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void ReadDataset() {
long file_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long attribute_id = -1;
long[] dims = { DIM0, DIM1 };
int[][] dset_data;
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
attribute_id = H5.H5Aopen_by_name(dataset_id, ".", ATTRIBUTENAME, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Get dataspace and allocate memory for read buffer.
try {
if (attribute_id >= 0)
dataspace_id = H5.H5Aget_space(attribute_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sget_simple_extent_dims(dataspace_id, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Allocate array of pointers to two-dimensional arrays (the
// elements of the dataset.
dset_data = new int[(int) dims[0]][(int) (dims[1])];
// Read data.
try {
if (attribute_id >= 0)
H5.H5Aread(attribute_id, HDF5Constants.H5T_NATIVE_B8, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
System.out.println(ATTRIBUTENAME + ":");
for (int indx = 0; indx < dims[0]; indx++) {
System.out.print(" [");
for (int jndx = 0; jndx < dims[1]; jndx++) {
System.out.print("{" + (dset_data[indx][jndx] & 0x03) + ", ");
System.out.print(((dset_data[indx][jndx] >> 2) & 0x03) + ", ");
System.out.print(((dset_data[indx][jndx] >> 4) & 0x03) + ", ");
System.out.print(((dset_data[indx][jndx] >> 6) & 0x03) + "}");
}
System.out.println("]");
}
System.out.println();
// End access to the dataset and release resources used by it.
try {
if (attribute_id >= 0)
H5.H5Aclose(attribute_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_T_BitAttribute.CreateDataset();
// Now we begin the read section of this example. Here we assume
// the dataset and array have the same name and rank, but can have
// any size. Therefore we must allocate a new array to read in
// data using malloc().
H5Ex_T_BitAttribute.ReadDataset();
}
}
+265
View File
@@ -0,0 +1,265 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to commit a named datatype to a
file, and read back that datatype. The program first
defines a compound datatype, commits it to a file, then
closes the file. Next, it reopens the file, opens the
datatype, and outputs the names of its fields to the
screen.
************************************************************/
package examples.datatypes;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
public class H5Ex_T_Commit {
private static String FILENAME = "H5Ex_T_Commit.h5";
private static String DATATYPENAME = "Sensor_Type";
protected static final int INTEGERSIZE = 4;
protected static final int DOUBLESIZE = 8;
protected final static int MAXSTRINGSIZE = 80;
// Values for the various classes of datatypes
enum H5T_class {
H5T_NO_CLASS(HDF5Constants.H5T_NO_CLASS), // error
H5T_INTEGER(HDF5Constants.H5T_INTEGER), // integer types
H5T_FLOAT(HDF5Constants.H5T_FLOAT), // floating-point types
H5T_TIME(HDF5Constants.H5T_TIME), // date and time types
H5T_STRING(HDF5Constants.H5T_STRING), // character string types
H5T_BITFIELD(HDF5Constants.H5T_BITFIELD), // bit field types
H5T_OPAQUE(HDF5Constants.H5T_OPAQUE), // opaque types
H5T_COMPOUND(HDF5Constants.H5T_COMPOUND), // compound types
H5T_REFERENCE(HDF5Constants.H5T_REFERENCE), // reference types
H5T_ENUM(HDF5Constants.H5T_ENUM), // enumeration types
H5T_VLEN(HDF5Constants.H5T_VLEN), // Variable-Length types
H5T_ARRAY(HDF5Constants.H5T_ARRAY), // Array types
H5T_NCLASSES(11); // this must be last
private static final Map<Long, H5T_class> lookup = new HashMap<Long, H5T_class>();
static {
for (H5T_class s : EnumSet.allOf(H5T_class.class))
lookup.put(s.getCode(), s);
}
private long code;
H5T_class(long layout_type) {
this.code = layout_type;
}
public long getCode() {
return this.code;
}
public static H5T_class get(long typeclass_id) {
return lookup.get(typeclass_id);
}
}
// The supporting Sensor_Datatype class.
private static class Sensor_Datatype {
static int numberMembers = 4;
static int[] memberDims = { 1, 1, 1, 1 };
String[] memberNames = { "Serial number", "Location", "Temperature (F)", "Pressure (inHg)" };
long[] memberFileTypes = { HDF5Constants.H5T_STD_I32BE, HDF5Constants.H5T_C_S1, HDF5Constants.H5T_IEEE_F64BE,
HDF5Constants.H5T_IEEE_F64BE };
static int[] memberStorage = { INTEGERSIZE, MAXSTRINGSIZE, DOUBLESIZE, DOUBLESIZE };
// Data size is the storage size for the members not the object.
static long getDataSize() {
long data_size = 0;
for (int indx = 0; indx < numberMembers; indx++)
data_size += memberStorage[indx] * memberDims[indx];
return data_size;
}
static int getOffset(int memberItem) {
int data_offset = 0;
for (int indx = 0; indx < memberItem; indx++)
data_offset += memberStorage[indx];
return data_offset;
}
}
private static void CreateDataType() {
long file_id = -1;
long strtype_id = -1;
long filetype_id = -1;
Sensor_Datatype datatypes = new Sensor_Datatype();
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create string datatype.
try {
strtype_id = H5.H5Tcopy(HDF5Constants.H5T_C_S1);
if (strtype_id >= 0)
H5.H5Tset_size(strtype_id, MAXSTRINGSIZE);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the compound datatype for the file. Because the standard
// types we are using for the file may have different sizes than
// the corresponding native types, we must manually calculate the
// offset of each member.
try {
filetype_id = H5.H5Tcreate(HDF5Constants.H5T_COMPOUND, Sensor_Datatype.getDataSize());
if (filetype_id >= 0) {
for (int indx = 0; indx < Sensor_Datatype.numberMembers; indx++) {
long type_id = datatypes.memberFileTypes[indx];
if (type_id == HDF5Constants.H5T_C_S1)
type_id = strtype_id;
H5.H5Tinsert(filetype_id, datatypes.memberNames[indx], Sensor_Datatype.getOffset(indx), type_id);
}
}
}
catch (Exception e) {
e.printStackTrace();
}
// Commit the compound datatype to the file, creating a named datatype.
try {
if ((file_id >= 0) && (filetype_id >= 0))
H5.H5Tcommit(file_id, DATATYPENAME, filetype_id, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the file type.
try {
if (filetype_id >= 0)
H5.H5Tclose(filetype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the str type.
try {
if (strtype_id >= 0)
H5.H5Tclose(strtype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void ReadDataType() {
long file_id = -1;
long typeclass_id = -1;
long filetype_id = -1;
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open named datatype.
try {
if (file_id >= 0)
filetype_id = H5.H5Topen(file_id, DATATYPENAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
System.out.println("Named datatype: " + DATATYPENAME + ":");
// Get datatype class. If it isn't compound, we won't print anything.
try {
if (filetype_id >= 0)
typeclass_id = H5.H5Tget_class(filetype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Read data.
try {
if (H5T_class.get(typeclass_id) == H5T_class.H5T_COMPOUND) {
System.out.println(" Class: H5T_COMPOUND");
int nmembs = H5.H5Tget_nmembers(filetype_id);
// Iterate over compound datatype members.
for (int indx = 0; indx < nmembs; indx++) {
String member_name = H5.H5Tget_member_name(filetype_id, indx);
System.out.println(" " + member_name);
}
}
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the mem type.
try {
if (filetype_id >= 0)
H5.H5Tclose(filetype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_T_Commit.CreateDataType();
// Now we begin the read section of this example. Here we assume
// the dataset and array have the same name and rank, but can have
// any size. Therefore we must allocate a new array to read in
// data using malloc().
H5Ex_T_Commit.ReadDataType();
}
}
@@ -0,0 +1,443 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to read and write compound
datatypes to a dataset. The program first writes
compound structures to a dataset with a dataspace of DIM0,
then closes the file. Next, it reopens the file, reads
back the data, and outputs it to the screen.
************************************************************/
package examples.datatypes;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.Charset;
public class H5Ex_T_Compound {
private static String FILENAME = "H5Ex_T_Compound.h5";
private static String DATASETNAME = "DS1";
private static final int DIM0 = 4;
private static final int RANK = 1;
protected static final int INTEGERSIZE = 4;
protected static final int DOUBLESIZE = 8;
protected final static int MAXSTRINGSIZE = 80;
static class Sensor_Datatype {
static int numberMembers = 4;
static int[] memberDims = { 1, 1, 1, 1 };
static String[] memberNames = { "Serial number", "Location", "Temperature (F)", "Pressure (inHg)" };
static long[] memberMemTypes = { HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5T_C_S1,
HDF5Constants.H5T_NATIVE_DOUBLE, HDF5Constants.H5T_NATIVE_DOUBLE };
static long[] memberFileTypes = { HDF5Constants.H5T_STD_I32BE, HDF5Constants.H5T_C_S1,
HDF5Constants.H5T_IEEE_F64BE, HDF5Constants.H5T_IEEE_F64BE };
static int[] memberStorage = { INTEGERSIZE, MAXSTRINGSIZE, DOUBLESIZE, DOUBLESIZE };
// Data size is the storage size for the members.
static long getTotalDataSize() {
long data_size = 0;
for (int indx = 0; indx < numberMembers; indx++)
data_size += memberStorage[indx] * memberDims[indx];
return DIM0 * data_size;
}
static long getDataSize() {
long data_size = 0;
for (int indx = 0; indx < numberMembers; indx++)
data_size += memberStorage[indx] * memberDims[indx];
return data_size;
}
static int getOffset(int memberItem) {
int data_offset = 0;
for (int indx = 0; indx < memberItem; indx++)
data_offset += memberStorage[indx];
return data_offset;
}
}
static class Sensor {
public int serial_no;
public String location;
public double temperature;
public double pressure;
Sensor(int serial_no, String location, double temperature, double pressure) {
this.serial_no = serial_no;
this.location = location;
this.temperature = temperature;
this.pressure = pressure;
}
Sensor(ByteBuffer databuf, int dbposition) {
readBuffer(databuf, dbposition);
}
void writeBuffer(ByteBuffer databuf, int dbposition) {
databuf.putInt(dbposition + Sensor_Datatype.getOffset(0), serial_no);
byte[] temp_str = location.getBytes(Charset.forName("UTF-8"));
int arraylen = (temp_str.length > MAXSTRINGSIZE) ? MAXSTRINGSIZE : temp_str.length;
for (int ndx = 0; ndx < arraylen; ndx++)
databuf.put(dbposition + Sensor_Datatype.getOffset(1) + ndx, temp_str[ndx]);
for (int ndx = arraylen; ndx < MAXSTRINGSIZE; ndx++)
databuf.put(dbposition + Sensor_Datatype.getOffset(1) + arraylen, (byte) 0);
databuf.putDouble(dbposition + Sensor_Datatype.getOffset(2), temperature);
databuf.putDouble(dbposition + Sensor_Datatype.getOffset(3), pressure);
}
void readBuffer(ByteBuffer databuf, int dbposition) {
this.serial_no = databuf.getInt(dbposition + Sensor_Datatype.getOffset(0));
ByteBuffer stringbuf = databuf.duplicate();
stringbuf.position(dbposition + Sensor_Datatype.getOffset(1));
stringbuf.limit(dbposition + Sensor_Datatype.getOffset(1) + MAXSTRINGSIZE);
byte[] bytearr = new byte[stringbuf.remaining()];
stringbuf.get(bytearr);
this.location = new String(bytearr, Charset.forName("UTF-8")).trim();
this.temperature = databuf.getDouble(dbposition + Sensor_Datatype.getOffset(2));
this.pressure = databuf.getDouble(dbposition + Sensor_Datatype.getOffset(3));
}
@Override
public String toString() {
return String.format("Serial number : " + serial_no + "%n" +
"Location : " + location + "%n" +
"Temperature (F) : " + temperature + "%n" +
"Pressure (inHg) : " + pressure + "%n");
}
}
private static void CreateDataset() {
long file_id = -1;
long strtype_id = -1;
long memtype_id = -1;
long filetype_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long[] dims = { DIM0 };
Sensor[] object_data = new Sensor[DIM0];
byte[] dset_data = null;
// Initialize data.
object_data[0] = new Sensor(1153, new String("Exterior (static)"), 53.23, 24.57);
object_data[1] = new Sensor(1184, new String("Intake"), 55.12, 22.95);
object_data[2] = new Sensor(1027, new String("Intake manifold"), 103.55, 31.23);
object_data[3] = new Sensor(1313, new String("Exhaust manifold"), 1252.89, 84.11);
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create string datatype.
try {
strtype_id = H5.H5Tcopy(HDF5Constants.H5T_C_S1);
if (strtype_id >= 0)
H5.H5Tset_size(strtype_id, MAXSTRINGSIZE);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the compound datatype for memory.
try {
memtype_id = H5.H5Tcreate(HDF5Constants.H5T_COMPOUND, Sensor_Datatype.getDataSize());
if (memtype_id >= 0) {
for (int indx = 0; indx < Sensor_Datatype.numberMembers; indx++) {
long type_id = Sensor_Datatype.memberMemTypes[indx];
if (type_id == HDF5Constants.H5T_C_S1)
type_id = strtype_id;
H5.H5Tinsert(memtype_id, Sensor_Datatype.memberNames[indx], Sensor_Datatype.getOffset(indx),
type_id);
}
}
}
catch (Exception e) {
e.printStackTrace();
}
// Create the compound datatype for the file. Because the standard
// types we are using for the file may have different sizes than
// the corresponding native types, we must manually calculate the
// offset of each member.
try {
filetype_id = H5.H5Tcreate(HDF5Constants.H5T_COMPOUND, Sensor_Datatype.getDataSize());
if (filetype_id >= 0) {
for (int indx = 0; indx < Sensor_Datatype.numberMembers; indx++) {
long type_id = Sensor_Datatype.memberFileTypes[indx];
if (type_id == HDF5Constants.H5T_C_S1)
type_id = strtype_id;
H5.H5Tinsert(filetype_id, Sensor_Datatype.memberNames[indx], Sensor_Datatype.getOffset(indx),
type_id);
}
}
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
try {
dataspace_id = H5.H5Screate_simple(RANK, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset.
try {
if ((file_id >= 0) && (dataspace_id >= 0) && (filetype_id >= 0))
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, filetype_id, dataspace_id, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the compound data to the dataset.
// allocate memory for read buffer.
dset_data = new byte[(int)dims[0] * (int)Sensor_Datatype.getDataSize()];
ByteBuffer outBuf = ByteBuffer.wrap(dset_data);
outBuf.order(ByteOrder.nativeOrder());
for (int indx = 0; indx < (int) dims[0]; indx++) {
object_data[indx].writeBuffer(outBuf, indx * (int)Sensor_Datatype.getDataSize());
}
try {
if ((dataset_id >= 0) && (memtype_id >= 0))
H5.H5Dwrite(dataset_id, memtype_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the file type.
try {
if (filetype_id >= 0)
H5.H5Tclose(filetype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the mem type.
try {
if (memtype_id >= 0)
H5.H5Tclose(memtype_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (strtype_id >= 0)
H5.H5Tclose(strtype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void ReadDataset() {
long file_id = -1;
long strtype_id = -1;
long memtype_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long[] dims = { DIM0 };
Sensor[] object_data2;
byte[] dset_data;
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Get dataspace and allocate memory for read buffer.
try {
if (dataset_id >= 0)
dataspace_id = H5.H5Dget_space(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sget_simple_extent_dims(dataspace_id, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create string datatype.
try {
strtype_id = H5.H5Tcopy(HDF5Constants.H5T_C_S1);
if (strtype_id >= 0)
H5.H5Tset_size(strtype_id, MAXSTRINGSIZE);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the compound datatype for memory.
try {
memtype_id = H5.H5Tcreate(HDF5Constants.H5T_COMPOUND, Sensor_Datatype.getDataSize());
if (memtype_id >= 0) {
for (int indx = 0; indx < Sensor_Datatype.numberMembers; indx++) {
long type_id = Sensor_Datatype.memberMemTypes[indx];
if (type_id == HDF5Constants.H5T_C_S1)
type_id = strtype_id;
H5.H5Tinsert(memtype_id, Sensor_Datatype.memberNames[indx], Sensor_Datatype.getOffset(indx),
type_id);
}
}
}
catch (Exception e) {
e.printStackTrace();
}
// allocate memory for read buffer.
dset_data = new byte[(int) dims[0] * (int)Sensor_Datatype.getDataSize()];
object_data2 = new Sensor[(int) dims[0]];
// Read data.
try {
if ((dataset_id >= 0) && (memtype_id >= 0))
H5.H5Dread(dataset_id, memtype_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
ByteBuffer inBuf = ByteBuffer.wrap(dset_data);
inBuf.order(ByteOrder.nativeOrder());
for (int indx = 0; indx < (int) dims[0]; indx++) {
object_data2[indx] = new Sensor(inBuf, indx * (int)Sensor_Datatype.getDataSize());
}
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
for (int indx = 0; indx < dims[0]; indx++) {
System.out.println(DATASETNAME + " [" + indx + "]:");
System.out.println(object_data2[indx].toString());
}
System.out.println();
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the mem type.
try {
if (memtype_id >= 0)
H5.H5Tclose(memtype_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (strtype_id >= 0)
H5.H5Tclose(strtype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_T_Compound.CreateDataset();
// Now we begin the read section of this example. Here we assume
// the dataset and array have the same name and rank, but can have
// any size. Therefore we must allocate a new array to read in
// data using malloc().
H5Ex_T_Compound.ReadDataset();
}
}
@@ -0,0 +1,486 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to read and write compound
datatypes to an attribute. The program first writes
compound structures to an attribute with a dataspace of
DIM0, then closes the file. Next, it reopens the file,
reads back the data, and outputs it to the screen.
************************************************************/
package examples.datatypes;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.Charset;
public class H5Ex_T_CompoundAttribute {
private static String FILENAME = "H5Ex_T_CompoundAttribute.h5";
private static String DATASETNAME = "DS1";
private static String ATTRIBUTENAME = "A1";
private static final int DIM0 = 4;
private static final int RANK = 1;
protected static final int INTEGERSIZE = 4;
protected static final int DOUBLESIZE = 8;
protected final static int MAXSTRINGSIZE = 80;
// Using Java Externalization will add a two-byte object header in
// the stream, which needs to be called out in the datatypes.
static class Sensor_Datatype {
static int numberMembers = 4;
static int[] memberDims = { 1, 1, 1, 1 };
static String[] memberNames = { "Serial number", "Location", "Temperature (F)", "Pressure (inHg)" };
static long[] memberMemTypes = { HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5T_C_S1,
HDF5Constants.H5T_NATIVE_DOUBLE, HDF5Constants.H5T_NATIVE_DOUBLE };
static long[] memberFileTypes = { HDF5Constants.H5T_STD_I32BE, HDF5Constants.H5T_C_S1,
HDF5Constants.H5T_IEEE_F64BE, HDF5Constants.H5T_IEEE_F64BE };
static int[] memberStorage = { INTEGERSIZE, MAXSTRINGSIZE, DOUBLESIZE, DOUBLESIZE };
// Data size is the storage size for the members not the object.
static long getTotalDataSize() {
long data_size = 0;
for (int indx = 0; indx < numberMembers; indx++)
data_size += memberStorage[indx] * memberDims[indx];
return DIM0 * data_size;
}
static long getDataSize() {
long data_size = 0;
for (int indx = 0; indx < numberMembers; indx++)
data_size += memberStorage[indx] * memberDims[indx];
return data_size;
}
static int getOffset(int memberItem) {
int data_offset = 0;
for (int indx = 0; indx < memberItem; indx++)
data_offset += memberStorage[indx];
return data_offset;
}
}
static class Sensor {
public int serial_no;
public String location;
public double temperature;
public double pressure;
Sensor(int serial_no, String location, double temperature, double pressure) {
this.serial_no = serial_no;
this.location = location;
this.temperature = temperature;
this.pressure = pressure;
}
Sensor(ByteBuffer databuf, int dbposition) {
readBuffer(databuf, dbposition);
}
void writeBuffer(ByteBuffer databuf, int dbposition) {
databuf.putInt(dbposition + Sensor_Datatype.getOffset(0), serial_no);
byte[] temp_str = location.getBytes(Charset.forName("UTF-8"));
int arraylen = (temp_str.length > MAXSTRINGSIZE) ? MAXSTRINGSIZE : temp_str.length;
for (int ndx = 0; ndx < arraylen; ndx++)
databuf.put(dbposition + Sensor_Datatype.getOffset(1) + ndx, temp_str[ndx]);
for (int ndx = arraylen; ndx < MAXSTRINGSIZE; ndx++)
databuf.put(dbposition + Sensor_Datatype.getOffset(1) + arraylen, (byte) 0);
databuf.putDouble(dbposition + Sensor_Datatype.getOffset(2), temperature);
databuf.putDouble(dbposition + Sensor_Datatype.getOffset(3), pressure);
}
void readBuffer(ByteBuffer databuf, int dbposition) {
this.serial_no = databuf.getInt(dbposition + Sensor_Datatype.getOffset(0));
ByteBuffer stringbuf = databuf.duplicate();
stringbuf.position(dbposition + Sensor_Datatype.getOffset(1));
stringbuf.limit(dbposition + Sensor_Datatype.getOffset(1) + MAXSTRINGSIZE);
byte[] bytearr = new byte[stringbuf.remaining()];
stringbuf.get(bytearr);
this.location = new String(bytearr, Charset.forName("UTF-8")).trim();
this.temperature = databuf.getDouble(dbposition + Sensor_Datatype.getOffset(2));
this.pressure = databuf.getDouble(dbposition + Sensor_Datatype.getOffset(3));
}
@Override
public String toString() {
return String.format("Serial number : " + serial_no + "%n" +
"Location : " + location + "%n" +
"Temperature (F) : " + temperature + "%n" +
"Pressure (inHg) : " + pressure + "%n");
}
}
private static void CreateDataset() {
long file_id = -1;
long strtype_id = -1;
long memtype_id = -1;
long filetype_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long attribute_id = -1;
long[] dims = { DIM0 };
Sensor[] object_data = new Sensor[DIM0];
byte[] dset_data = null;
// Initialize data.
object_data[0] = new Sensor(1153, new String("Exterior (static)"), 53.23, 24.57);
object_data[1] = new Sensor(1184, new String("Intake"), 55.12, 22.95);
object_data[2] = new Sensor(1027, new String("Intake manifold"), 103.55, 31.23);
object_data[3] = new Sensor(1313, new String("Exhaust manifold"), 1252.89, 84.11);
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create string datatype.
try {
strtype_id = H5.H5Tcopy(HDF5Constants.H5T_C_S1);
if (strtype_id >= 0)
H5.H5Tset_size(strtype_id, MAXSTRINGSIZE);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the compound datatype for memory.
try {
memtype_id = H5.H5Tcreate(HDF5Constants.H5T_COMPOUND, Sensor_Datatype.getDataSize());
if (memtype_id >= 0) {
for (int indx = 0; indx < Sensor_Datatype.numberMembers; indx++) {
long type_id = Sensor_Datatype.memberMemTypes[indx];
if (type_id == HDF5Constants.H5T_C_S1)
type_id = strtype_id;
H5.H5Tinsert(memtype_id, Sensor_Datatype.memberNames[indx], Sensor_Datatype.getOffset(indx),
type_id);
}
}
}
catch (Exception e) {
e.printStackTrace();
}
// Create the compound datatype for the file. Because the standard
// types we are using for the file may have different sizes than
// the corresponding native types, we must manually calculate the
// offset of each member.
try {
filetype_id = H5.H5Tcreate(HDF5Constants.H5T_COMPOUND, Sensor_Datatype.getDataSize());
if (filetype_id >= 0) {
for (int indx = 0; indx < Sensor_Datatype.numberMembers; indx++) {
long type_id = Sensor_Datatype.memberFileTypes[indx];
if (type_id == HDF5Constants.H5T_C_S1)
type_id = strtype_id;
H5.H5Tinsert(filetype_id, Sensor_Datatype.memberNames[indx], Sensor_Datatype.getOffset(indx),
type_id);
}
}
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataset with a scalar dataspace.
try {
dataspace_id = H5.H5Screate(HDF5Constants.H5S_SCALAR);
if (dataspace_id >= 0) {
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, dataspace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
H5.H5Sclose(dataspace_id);
dataspace_id = -1;
}
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
try {
dataspace_id = H5.H5Screate_simple(RANK, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the attribute.
try {
if ((dataset_id >= 0) && (dataspace_id >= 0) && (filetype_id >= 0))
attribute_id = H5.H5Acreate(dataset_id, ATTRIBUTENAME, filetype_id, dataspace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the compound data.
dset_data = new byte[(int) dims[0] * (int)Sensor_Datatype.getDataSize()];
ByteBuffer outBuf = ByteBuffer.wrap(dset_data);
outBuf.order(ByteOrder.nativeOrder());
for (int indx = 0; indx < (int) dims[0]; indx++) {
object_data[indx].writeBuffer(outBuf, indx * (int)Sensor_Datatype.getDataSize());
}
try {
if ((attribute_id >= 0) && (memtype_id >= 0))
H5.H5Awrite(attribute_id, memtype_id, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (attribute_id >= 0)
H5.H5Aclose(attribute_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the file type.
try {
if (filetype_id >= 0)
H5.H5Tclose(filetype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the mem type.
try {
if (memtype_id >= 0)
H5.H5Tclose(memtype_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (strtype_id >= 0)
H5.H5Tclose(strtype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void ReadDataset() {
long file_id = -1;
long strtype_id = -1;
long memtype_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long attribute_id = -1;
long[] dims = { DIM0 };
Sensor[] object_data2;
byte[] dset_data;
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
attribute_id = H5.H5Aopen_by_name(dataset_id, ".", ATTRIBUTENAME, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Get dataspace and allocate memory for read buffer. This is a
// three dimensional dataset when the array datatype is included so
// the dynamic allocation must be done in steps.
try {
if (attribute_id >= 0)
dataspace_id = H5.H5Aget_space(attribute_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sget_simple_extent_dims(dataspace_id, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create string datatype.
try {
strtype_id = H5.H5Tcopy(HDF5Constants.H5T_C_S1);
if (strtype_id >= 0)
H5.H5Tset_size(strtype_id, MAXSTRINGSIZE);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the compound datatype for memory.
try {
memtype_id = H5.H5Tcreate(HDF5Constants.H5T_COMPOUND, Sensor_Datatype.getDataSize());
if (memtype_id >= 0) {
for (int indx = 0; indx < Sensor_Datatype.numberMembers; indx++) {
long type_id = Sensor_Datatype.memberMemTypes[indx];
if (type_id == HDF5Constants.H5T_C_S1)
type_id = strtype_id;
H5.H5Tinsert(memtype_id, Sensor_Datatype.memberNames[indx], Sensor_Datatype.getOffset(indx),
type_id);
}
}
}
catch (Exception e) {
e.printStackTrace();
}
// allocate memory for read buffer.
dset_data = new byte[(int) dims[0] * (int)Sensor_Datatype.getDataSize()];
object_data2 = new Sensor[(int) dims[0]];
// Read data.
try {
if ((attribute_id >= 0) && (memtype_id >= 0))
H5.H5Aread(attribute_id, memtype_id, dset_data);
ByteBuffer inBuf = ByteBuffer.wrap(dset_data);
inBuf.order(ByteOrder.nativeOrder());
for (int indx = 0; indx < (int) dims[0]; indx++) {
object_data2[indx] = new Sensor(inBuf, indx * (int)Sensor_Datatype.getDataSize());
}
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
for (int indx = 0; indx < dims[0]; indx++) {
System.out.println(ATTRIBUTENAME + " [" + indx + "]:");
System.out.println(object_data2[indx].toString());
}
System.out.println();
try {
if (attribute_id >= 0)
H5.H5Aclose(attribute_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the mem type.
try {
if (memtype_id >= 0)
H5.H5Tclose(memtype_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (strtype_id >= 0)
H5.H5Tclose(strtype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_T_CompoundAttribute.CreateDataset();
// Now we begin the read section of this example. Here we assume
// the dataset and array have the same name and rank, but can have
// any size. Therefore we must allocate a new array to read in
// data using malloc().
H5Ex_T_CompoundAttribute.ReadDataset();
}
}
+227
View File
@@ -0,0 +1,227 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to read and write integer datatypes
to a dataset. The program first writes integers to a
dataset with a dataspace of DIM0xDIM1, then closes the
file. Next, it reopens the file, reads back the data, and
outputs it to the screen.
************************************************************/
package examples.datatypes;
import java.text.DecimalFormat;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_T_Float {
private static String FILENAME = "H5Ex_T_Float.h5";
private static String DATASETNAME = "DS1";
private static final int DIM0 = 4;
private static final int DIM1 = 7;
private static final int RANK = 2;
private static void CreateDataset() {
long file_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long[] dims = { DIM0, DIM1 };
double[][] dset_data = new double[DIM0][DIM1];
// Initialize data.
for (int indx = 0; indx < DIM0; indx++)
for (int jndx = 0; jndx < DIM1; jndx++) {
dset_data[indx][jndx] = indx / (jndx + 0.5) + jndx;
}
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
try {
dataspace_id = H5.H5Screate_simple(RANK, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset and write the floating point data to it. In
// this example we will save the data as 64 bit little endian IEEE
// floating point numbers, regardless of the native type. The HDF5
// library automatically converts between different floating point
// types.
try {
if ((file_id >= 0) && (dataspace_id >= 0))
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_IEEE_F64LE, dataspace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the data to the dataset.
try {
if (dataset_id >= 0)
H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_DOUBLE, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void ReadDataset() {
long file_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long[] dims = { DIM0, DIM1 };
double[][] dset_data;
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Get dataspace and allocate memory for read buffer.
try {
if (dataset_id >= 0)
dataspace_id = H5.H5Dget_space(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sget_simple_extent_dims(dataspace_id, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Allocate array of pointers to two-dimensional arrays (the
// elements of the dataset.
dset_data = new double[(int) dims[0]][(int) (dims[1])];
// Read data.
try {
if (dataset_id >= 0)
H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_DOUBLE, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
DecimalFormat df = new DecimalFormat("#,##0.0000");
System.out.println(DATASETNAME + ":");
for (int indx = 0; indx < dims[0]; indx++) {
System.out.print(" [");
for (int jndx = 0; jndx < dims[1]; jndx++) {
System.out.print(" " + df.format(dset_data[indx][jndx]));
}
System.out.println("]");
}
System.out.println();
// End access to the dataset and release resources used by it.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_T_Float.CreateDataset();
// Now we begin the read section of this example. Here we assume
// the dataset and array have the same name and rank, but can have
// any size. Therefore we must allocate a new array to read in
// data using malloc().
H5Ex_T_Float.ReadDataset();
}
}
@@ -0,0 +1,263 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to read and write floating point
datatypes to an attribute. The program first writes
floating point numbers to an attribute with a dataspace of
DIM0xDIM1, then closes the file. Next, it reopens the
file, reads back the data, and outputs it to the screen.
************************************************************/
package examples.datatypes;
import java.text.DecimalFormat;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_T_FloatAttribute {
private static String FILENAME = "H5Ex_T_FloatAttribute.h5";
private static String DATASETNAME = "DS1";
private static String ATTRIBUTENAME = "A1";
private static final int DIM0 = 4;
private static final int DIM1 = 7;
private static final int RANK = 2;
private static void CreateDataset() {
long file_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long attribute_id = -1;
long[] dims = { DIM0, DIM1 };
double[][] dset_data = new double[DIM0][DIM1];
// Initialize data.
for (int indx = 0; indx < DIM0; indx++)
for (int jndx = 0; jndx < DIM1; jndx++) {
dset_data[indx][jndx] = indx / (jndx + 0.5) + jndx;
}
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataset with a scalar dataspace.
try {
dataspace_id = H5.H5Screate(HDF5Constants.H5S_SCALAR);
if (dataspace_id >= 0) {
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, dataspace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
H5.H5Sclose(dataspace_id);
dataspace_id = -1;
}
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
try {
dataspace_id = H5.H5Screate_simple(RANK, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the attribute and write the array data to it.
try {
if ((dataset_id >= 0) && (dataspace_id >= 0))
attribute_id = H5.H5Acreate(dataset_id, ATTRIBUTENAME, HDF5Constants.H5T_IEEE_F64LE, dataspace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the dataset.
try {
if (attribute_id >= 0)
H5.H5Awrite(attribute_id, HDF5Constants.H5T_NATIVE_DOUBLE, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (attribute_id >= 0)
H5.H5Aclose(attribute_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void ReadDataset() {
long file_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long attribute_id = -1;
long[] dims = { DIM0, DIM1 };
double[][] dset_data;
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
attribute_id = H5.H5Aopen_by_name(dataset_id, ".", ATTRIBUTENAME, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Get dataspace and allocate memory for read buffer.
try {
if (attribute_id >= 0)
dataspace_id = H5.H5Aget_space(attribute_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sget_simple_extent_dims(dataspace_id, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Allocate array of pointers to two-dimensional arrays (the
// elements of the dataset.
dset_data = new double[(int) dims[0]][(int) (dims[1])];
// Read data.
try {
if (attribute_id >= 0)
H5.H5Aread(attribute_id, HDF5Constants.H5T_NATIVE_DOUBLE, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
DecimalFormat df = new DecimalFormat("#,##0.0000");
System.out.println(ATTRIBUTENAME + ":");
for (int indx = 0; indx < dims[0]; indx++) {
System.out.print(" [");
for (int jndx = 0; jndx < dims[1]; jndx++) {
System.out.print(" " + df.format(dset_data[indx][jndx]));
}
System.out.println("]");
}
System.out.println();
// End access to the dataset and release resources used by it.
try {
if (attribute_id >= 0)
H5.H5Aclose(attribute_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_T_FloatAttribute.CreateDataset();
// Now we begin the read section of this example. Here we assume
// the dataset and array have the same name and rank, but can have
// any size. Therefore we must allocate a new array to read in
// data using malloc().
H5Ex_T_FloatAttribute.ReadDataset();
}
}
+226
View File
@@ -0,0 +1,226 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to read and write integer datatypes
to a dataset. The program first writes integers to a
dataset with a dataspace of DIM0xDIM1, then closes the
file. Next, it reopens the file, reads back the data, and
outputs it to the screen.
************************************************************/
package examples.datatypes;
import java.text.DecimalFormat;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_T_Integer {
private static String FILENAME = "H5Ex_T_Integer.h5";
private static String DATASETNAME = "DS1";
private static final int DIM0 = 4;
private static final int DIM1 = 7;
private static final int RANK = 2;
private static void CreateDataset() {
long file_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long[] dims = { DIM0, DIM1 };
int[][] dset_data = new int[DIM0][DIM1];
// Initialize data.
for (int indx = 0; indx < DIM0; indx++)
for (int jndx = 0; jndx < DIM1; jndx++) {
dset_data[indx][jndx] = indx * jndx - jndx;
}
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
try {
dataspace_id = H5.H5Screate_simple(RANK, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset and write the integer data to it. In this
// example we will save the data as 64 bit big endian integers,
// regardless of the native integer type. The HDF5 library
// automatically converts between different integer types.
try {
if ((file_id >= 0) && (dataspace_id >= 0))
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I64BE, dataspace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the data to the dataset.
try {
if (dataset_id >= 0)
H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void ReadDataset() {
long file_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long[] dims = { DIM0, DIM1 };
int[][] dset_data;
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Get dataspace and allocate memory for read buffer.
try {
if (dataset_id >= 0)
dataspace_id = H5.H5Dget_space(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sget_simple_extent_dims(dataspace_id, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Allocate array of pointers to two-dimensional arrays (the
// elements of the dataset.
dset_data = new int[(int) dims[0]][(int) (dims[1])];
// Read data.
try {
if (dataset_id >= 0)
H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
DecimalFormat df = new DecimalFormat("#,##0");
System.out.println(DATASETNAME + ":");
for (int indx = 0; indx < dims[0]; indx++) {
System.out.print(" [");
for (int jndx = 0; jndx < dims[1]; jndx++) {
System.out.print(" " + df.format(dset_data[indx][jndx]));
}
System.out.println("]");
}
System.out.println();
// End access to the dataset and release resources used by it.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_T_Integer.CreateDataset();
// Now we begin the read section of this example. Here we assume
// the dataset and array have the same name and rank, but can have
// any size. Therefore we must allocate a new array to read in
// data using malloc().
H5Ex_T_Integer.ReadDataset();
}
}
@@ -0,0 +1,263 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to read and write integer datatypes
to an attribute. The program first writes integers to an
attribute with a dataspace of DIM0xDIM1, then closes the
file. Next, it reopens the file, reads back the data, and
outputs it to the screen.
************************************************************/
package examples.datatypes;
import java.text.DecimalFormat;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_T_IntegerAttribute {
private static String FILENAME = "H5Ex_T_IntegerAttribute.h5";
private static String DATASETNAME = "DS1";
private static String ATTRIBUTENAME = "A1";
private static final int DIM0 = 4;
private static final int DIM1 = 7;
private static final int RANK = 2;
private static void CreateDataset() {
long file_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long attribute_id = -1;
long[] dims = { DIM0, DIM1 };
int[][] dset_data = new int[DIM0][DIM1];
// Initialize data.
for (int indx = 0; indx < DIM0; indx++)
for (int jndx = 0; jndx < DIM1; jndx++) {
dset_data[indx][jndx] = indx * jndx - jndx;
}
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataset with a scalar dataspace.
try {
dataspace_id = H5.H5Screate(HDF5Constants.H5S_SCALAR);
if (dataspace_id >= 0) {
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, dataspace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
H5.H5Sclose(dataspace_id);
dataspace_id = -1;
}
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
try {
dataspace_id = H5.H5Screate_simple(RANK, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the attribute and write the array data to it.
try {
if ((dataset_id >= 0) && (dataspace_id >= 0))
attribute_id = H5.H5Acreate(dataset_id, ATTRIBUTENAME, HDF5Constants.H5T_STD_I64BE, dataspace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the dataset.
try {
if (attribute_id >= 0)
H5.H5Awrite(attribute_id, HDF5Constants.H5T_NATIVE_INT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (attribute_id >= 0)
H5.H5Aclose(attribute_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void ReadDataset() {
long file_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long attribute_id = -1;
long[] dims = { DIM0, DIM1 };
int[][] dset_data;
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
attribute_id = H5.H5Aopen_by_name(dataset_id, ".", ATTRIBUTENAME, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Get dataspace and allocate memory for read buffer.
try {
if (attribute_id >= 0)
dataspace_id = H5.H5Aget_space(attribute_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sget_simple_extent_dims(dataspace_id, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Allocate array of pointers to two-dimensional arrays (the
// elements of the dataset.
dset_data = new int[(int) dims[0]][(int) (dims[1])];
// Read data.
try {
if (attribute_id >= 0)
H5.H5Aread(attribute_id, HDF5Constants.H5T_NATIVE_INT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
DecimalFormat df = new DecimalFormat("#,##0");
System.out.println(ATTRIBUTENAME + ":");
for (int indx = 0; indx < dims[0]; indx++) {
System.out.print(" [");
for (int jndx = 0; jndx < dims[1]; jndx++) {
System.out.print(" " + df.format(dset_data[indx][jndx]));
}
System.out.println("]");
}
System.out.println();
// End access to the dataset and release resources used by it.
try {
if (attribute_id >= 0)
H5.H5Aclose(attribute_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_T_IntegerAttribute.CreateDataset();
// Now we begin the read section of this example. Here we assume
// the dataset and array have the same name and rank, but can have
// any size. Therefore we must allocate a new array to read in
// data using malloc().
H5Ex_T_IntegerAttribute.ReadDataset();
}
}
@@ -0,0 +1,347 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to read and write object references
to a dataset. The program first creates objects in the
file and writes references to those objects to a dataset
with a dataspace of DIM0, then closes the file. Next, it
reopens the file, dereferences the references, and outputs
the names of their targets to the screen.
************************************************************/
package examples.datatypes;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_T_ObjectReference {
private static String FILENAME = "H5Ex_T_ObjectReference.h5";
private static String DATASETNAME = "DS1";
private static String DATASETNAME2 = "DS2";
private static String GROUPNAME = "G1";
private static final int DIM0 = 2;
private static final int RANK = 1;
// Values for the status of space allocation
enum H5G_obj {
H5G_UNKNOWN(HDF5Constants.H5O_TYPE_UNKNOWN), /* Unknown object type */
H5G_GROUP(HDF5Constants.H5O_TYPE_GROUP), /* Object is a group */
H5G_DATASET(HDF5Constants.H5O_TYPE_DATASET), /* Object is a dataset */
H5G_TYPE(HDF5Constants.H5O_TYPE_NAMED_DATATYPE); /* Object is a named data type */
private static final Map<Integer, H5G_obj> lookup = new HashMap<Integer, H5G_obj>();
static {
for (H5G_obj s : EnumSet.allOf(H5G_obj.class))
lookup.put(s.getCode(), s);
}
private int code;
H5G_obj(int layout_type) {
this.code = layout_type;
}
public int getCode() {
return this.code;
}
public static H5G_obj get(int code) {
return lookup.get(code);
}
}
private static void writeObjRef() {
long file_id = -1;
long dataspace_id = -1;
long filespace_id = -1;
long group_id = -1;
long dataset_id = -1;
long[] dims = { DIM0 };
byte[][] dset_data = new byte[DIM0][8];
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataset with a scalar dataspace.
try {
dataspace_id = H5.H5Screate(HDF5Constants.H5S_SCALAR);
if ((file_id >= 0) && (dataspace_id >= 0)) {
dataset_id = H5.H5Dcreate(file_id, DATASETNAME2, HDF5Constants.H5T_STD_I32LE, dataspace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
dataset_id = -1;
H5.H5Sclose(dataspace_id);
dataspace_id = -1;
}
}
catch (Exception e) {
e.printStackTrace();
}
// Create a group in the file.
try {
if (file_id >= 0)
group_id = H5.H5Gcreate(file_id, GROUPNAME, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
if (group_id >= 0)
H5.H5Gclose(group_id);
group_id = -1;
}
catch (Exception e) {
e.printStackTrace();
}
// Create references to the previously created objects. Passing -1
// as space_id causes this parameter to be ignored. Other values
// besides valid dataspaces result in an error.
try {
if (file_id >= 0) {
byte rbuf0[] = H5.H5Rcreate(file_id, GROUPNAME, HDF5Constants.H5R_OBJECT, -1);
byte rbuf1[] = H5.H5Rcreate(file_id, DATASETNAME2, HDF5Constants.H5R_OBJECT, -1);
for (int indx = 0; indx < 8; indx++) {
dset_data[0][indx] = rbuf0[indx];
dset_data[1][indx] = rbuf1[indx];
}
}
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
try {
filespace_id = H5.H5Screate_simple(RANK, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset.
try {
if ((file_id >= 0) && (filespace_id >= 0))
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_REF_OBJ, filespace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the object references to it.
try {
if (dataset_id >= 0)
H5.H5Dwrite(dataset_id, HDF5Constants.H5T_STD_REF_OBJ, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (filespace_id >= 0)
H5.H5Sclose(filespace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void readObjRef() {
long file_id = -1;
long dataset_id = -1;
long dataspace_id = -1;
int object_type = -1;
long object_id = -1;
long[] dims = { DIM0 };
byte[][] dset_data;
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Get dataspace and allocate memory for read buffer.
try {
if (dataset_id >= 0)
dataspace_id = H5.H5Dget_space(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sget_simple_extent_dims(dataspace_id, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Allocate array of pointers to two-dimensional arrays (the
// elements of the dataset.
dset_data = new byte[(int)dims[0]][8];
// Read the data using the default properties.
try {
if (dataset_id >= 0) {
H5.H5Dread(dataset_id, HDF5Constants.H5T_STD_REF_OBJ, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
for (int indx = 0; indx < dims[0]; indx++) {
System.out.println(DATASETNAME + "[" + indx + "]:");
System.out.print(" ->");
// Open the referenced object, get its name and type.
try {
if (dataset_id >= 0) {
object_id = H5.H5Rdereference(dataset_id, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5R_OBJECT, dset_data[indx]);
object_type = H5.H5Rget_obj_type(dataset_id, HDF5Constants.H5R_OBJECT, dset_data[indx]);
}
String[] obj_name = new String[1];
long name_size = 1;
if (object_type >= 0) {
// Get the length of the name and retrieve the name.
name_size = 1 + H5.H5Iget_name(object_id, obj_name, name_size);
}
if ((object_id >= 0) && (object_type >= -1)) {
switch (H5G_obj.get(object_type)) {
case H5G_GROUP:
System.out.print("H5G_GROUP");
try {
if (object_id >= 0)
H5.H5Gclose(object_id);
}
catch (Exception e) {
e.printStackTrace();
}
break;
case H5G_DATASET:
System.out.print("H5G_DATASET");
try {
if (object_id >= 0)
H5.H5Dclose(object_id);
}
catch (Exception e) {
e.printStackTrace();
}
break;
case H5G_TYPE:
System.out.print("H5G_TYPE");
try {
if (object_id >= 0)
H5.H5Tclose(object_id);
}
catch (Exception e) {
e.printStackTrace();
}
break;
default:
System.out.print("UNHANDLED");
}
}
// Print the name.
if (name_size > 1)
System.out.println(": " + obj_name[0]);
}
catch (Exception e) {
e.printStackTrace();
}
}
// End access to the dataset and release resources used by it.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
// Check if gzip compression is available and can be used for both
// compression and decompression. Normally we do not perform error
// checking in these examples for the sake of clarity, but in this
// case we will make an exception because this filter is an
// optional part of the hdf5 library.
H5Ex_T_ObjectReference.writeObjRef();
H5Ex_T_ObjectReference.readObjRef();
}
}
@@ -0,0 +1,389 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to read and write object references
to an attribute. The program first creates objects in the
file and writes references to those objects to an
attribute with a dataspace of DIM0, then closes the file.
Next, it reopens the file, dereferences the references,
and outputs the names of their targets to the screen.
************************************************************/
package examples.datatypes;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_T_ObjectReferenceAttribute {
private static String FILENAME = "H5Ex_T_ObjectReferenceAttribute.h5";
private static String DATASETNAME = "DS1";
private static String ATTRIBUTENAME = "A1";
private static String DATASETNAME2 = "DS2";
private static String GROUPNAME = "G1";
private static final int DIM0 = 2;
private static final int RANK = 1;
// Values for the status of space allocation
enum H5G_obj {
H5G_UNKNOWN(HDF5Constants.H5O_TYPE_UNKNOWN), /* Unknown object type */
H5G_GROUP(HDF5Constants.H5O_TYPE_GROUP), /* Object is a group */
H5G_DATASET(HDF5Constants.H5O_TYPE_DATASET), /* Object is a dataset */
H5G_TYPE(HDF5Constants.H5O_TYPE_NAMED_DATATYPE); /* Object is a named data type */
private static final Map<Integer, H5G_obj> lookup = new HashMap<Integer, H5G_obj>();
static {
for (H5G_obj s : EnumSet.allOf(H5G_obj.class))
lookup.put(s.getCode(), s);
}
private int code;
H5G_obj(int layout_type) {
this.code = layout_type;
}
public int getCode() {
return this.code;
}
public static H5G_obj get(int code) {
return lookup.get(code);
}
}
private static void CreateDataset() {
long file_id = -1;
long dataspace_id = -1;
long group_id = -1;
long dataset_id = -1;
long attribute_id = -1;
long[] dims = { DIM0 };
byte[][] dset_data = new byte[DIM0][8];
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataset with a scalar dataspace.
try {
dataspace_id = H5.H5Screate(HDF5Constants.H5S_SCALAR);
if (dataspace_id >= 0) {
dataset_id = H5.H5Dcreate(file_id, DATASETNAME2, HDF5Constants.H5T_STD_I32LE, dataspace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
dataset_id = -1;
H5.H5Sclose(dataspace_id);
dataspace_id = -1;
}
}
catch (Exception e) {
e.printStackTrace();
}
// Create a group in the file.
try {
if (file_id >= 0)
group_id = H5.H5Gcreate(file_id, GROUPNAME, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
if (group_id >= 0)
H5.H5Gclose(group_id);
group_id = -1;
}
catch (Exception e) {
e.printStackTrace();
}
// Create references to the previously created objects. Passing -1
// as space_id causes this parameter to be ignored. Other values
// besides valid dataspaces result in an error.
try {
if (file_id >= 0) {
byte rbuf0[] = H5.H5Rcreate(file_id, GROUPNAME, HDF5Constants.H5R_OBJECT, -1);
byte rbuf1[] = H5.H5Rcreate(file_id, DATASETNAME2, HDF5Constants.H5R_OBJECT, -1);
for (int indx = 0; indx < 8; indx++) {
dset_data[0][indx] = rbuf0[indx];
dset_data[1][indx] = rbuf1[indx];
}
}
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataset with a scalar dataspace to serve as the parent
// for the attribute.
try {
dataspace_id = H5.H5Screate(HDF5Constants.H5S_SCALAR);
if (dataspace_id >= 0) {
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, dataspace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
H5.H5Sclose(dataspace_id);
dataspace_id = -1;
}
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
try {
dataspace_id = H5.H5Screate_simple(RANK, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the attribute and write the array data to it.
try {
if ((dataset_id >= 0) && (dataspace_id >= 0))
attribute_id = H5.H5Acreate(dataset_id, ATTRIBUTENAME, HDF5Constants.H5T_STD_REF_OBJ, dataspace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the dataset.
try {
if (attribute_id >= 0)
H5.H5Awrite(attribute_id, HDF5Constants.H5T_STD_REF_OBJ, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (attribute_id >= 0)
H5.H5Aclose(attribute_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void ReadDataset() {
long file_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long attribute_id = -1;
int object_type = -1;
long object_id = -1;
long[] dims = { DIM0 };
byte[][] dset_data;
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
attribute_id = H5.H5Aopen_by_name(dataset_id, ".", ATTRIBUTENAME, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Get dataspace and allocate memory for read buffer.
try {
if (attribute_id >= 0)
dataspace_id = H5.H5Aget_space(attribute_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sget_simple_extent_dims(dataspace_id, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Allocate array of pointers to two-dimensional arrays (the
// elements of the dataset.
dset_data = new byte[(int) dims[0]][8];
// Read data.
try {
if (attribute_id >= 0)
H5.H5Aread(attribute_id, HDF5Constants.H5T_STD_REF_OBJ, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
for (int indx = 0; indx < dims[0]; indx++) {
System.out.println(ATTRIBUTENAME + "[" + indx + "]:");
System.out.print(" ->");
// Open the referenced object, get its name and type.
try {
if (dataset_id >= 0) {
object_id = H5.H5Rdereference(dataset_id, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5R_OBJECT, dset_data[indx]);
object_type = H5.H5Rget_obj_type(dataset_id, HDF5Constants.H5R_OBJECT, dset_data[indx]);
}
String[] obj_name = new String[1];
long name_size = 1;
if (object_type >= 0) {
// Get the length of the name and retrieve the name.
name_size = 1 + H5.H5Iget_name(object_id, obj_name, name_size);
}
if ((object_id >= 0) && (object_type >= -1)) {
switch (H5G_obj.get(object_type)) {
case H5G_GROUP:
System.out.print("H5G_GROUP");
try {
if (object_id >= 0)
H5.H5Gclose(object_id);
}
catch (Exception e) {
e.printStackTrace();
}
break;
case H5G_DATASET:
System.out.print("H5G_DATASET");
try {
if (object_id >= 0)
H5.H5Dclose(object_id);
}
catch (Exception e) {
e.printStackTrace();
}
break;
case H5G_TYPE:
System.out.print("H5G_TYPE");
try {
if (object_id >= 0)
H5.H5Tclose(object_id);
}
catch (Exception e) {
e.printStackTrace();
}
break;
default:
System.out.print("UNHANDLED");
}
}
// Print the name.
if (name_size > 1)
System.out.println(": " + obj_name[0]);
}
catch (Exception e) {
e.printStackTrace();
}
}
// End access to the dataset and release resources used by it.
try {
if (attribute_id >= 0)
H5.H5Aclose(attribute_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_T_ObjectReferenceAttribute.CreateDataset();
// Now we begin the read section of this example. Here we assume
// the dataset and array have the same name and rank, but can have
// any size. Therefore we must allocate a new array to read in
// data using malloc().
H5Ex_T_ObjectReferenceAttribute.ReadDataset();
}
}
+270
View File
@@ -0,0 +1,270 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to read and write opaque datatypes
to a dataset. The program first writes opaque data to a
dataset with a dataspace of DIM0, then closes the file.
Next, it reopens the file, reads back the data, and
outputs it to the screen.
************************************************************/
package examples.datatypes;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_T_Opaque {
private static String FILENAME = "H5Ex_T_Opaque.h5";
private static String DATASETNAME = "DS1";
private static final int DIM0 = 4;
private static final int LEN = 7;
private static final int RANK = 1;
private static void CreateDataset() {
long file_id = -1;
long dataspace_id = -1;
long datatype_id = -1;
long dataset_id = -1;
long[] dims = { DIM0 };
byte[] dset_data = new byte[DIM0 * LEN];
byte[] str_data = { 'O', 'P', 'A', 'Q', 'U', 'E' };
// Initialize data.
for (int indx = 0; indx < DIM0; indx++) {
for (int jndx = 0; jndx < LEN - 1; jndx++)
dset_data[jndx + indx * LEN] = str_data[jndx];
dset_data[LEN - 1 + indx * LEN] = (byte) (indx + '0');
}
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create opaque datatype and set the tag to something appropriate.
// For this example we will write and view the data as a character
// array.
try {
datatype_id = H5.H5Tcreate(HDF5Constants.H5T_OPAQUE, (long)LEN);
if (datatype_id >= 0)
H5.H5Tset_tag(datatype_id, "Character array");
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
try {
dataspace_id = H5.H5Screate_simple(RANK, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset and write the integer data to it. In this
// example we will save the data as 64 bit big endian integers,
// regardless of the native integer type. The HDF5 library
// automatically converts between different integer types.
try {
if ((file_id >= 0) && (datatype_id >= 0) && (dataspace_id >= 0))
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, datatype_id, dataspace_id, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the opaque data to the dataset.
try {
if ((dataset_id >= 0) && (datatype_id >= 0))
H5.H5Dwrite(dataset_id, datatype_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (datatype_id >= 0)
H5.H5Tclose(datatype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void ReadDataset() {
long file_id = -1;
long datatype_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long type_len = -1;
long[] dims = { DIM0 };
byte[] dset_data;
String tag_name = null;
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Get datatype and properties for the datatype.
try {
if (dataset_id >= 0)
datatype_id = H5.H5Dget_type(dataset_id);
if (datatype_id >= 0) {
type_len = H5.H5Tget_size(datatype_id);
tag_name = H5.H5Tget_tag(datatype_id);
}
}
catch (Exception e) {
e.printStackTrace();
}
// Get dataspace and allocate memory for read buffer.
try {
if (dataset_id >= 0)
dataspace_id = H5.H5Dget_space(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sget_simple_extent_dims(dataspace_id, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Allocate buffer.
dset_data = new byte[(int) (dims[0] * type_len)];
// Read data.
try {
if ((dataset_id >= 0) && (datatype_id >= 0))
H5.H5Dread(dataset_id, datatype_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
System.out.println("Datatype tag for " + DATASETNAME + " is: \"" + tag_name + "\"");
for (int indx = 0; indx < dims[0]; indx++) {
System.out.print(DATASETNAME + "[" + indx + "]: ");
for (int jndx = 0; jndx < type_len; jndx++) {
char temp = (char) dset_data[jndx + indx * (int)type_len];
System.out.print(temp);
}
System.out.println("");
}
System.out.println();
// End access to the dataset and release resources used by it.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (datatype_id >= 0)
H5.H5Tclose(datatype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_T_Opaque.CreateDataset();
// Now we begin the read section of this example. Here we assume
// the dataset and array have the same name and rank, but can have
// any size. Therefore we must allocate a new array to read in
// data using malloc().
H5Ex_T_Opaque.ReadDataset();
}
}
@@ -0,0 +1,307 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to read and write opaque datatypes
to an attribute. The program first writes opaque data to
an attribute with a dataspace of DIM0, then closes the
file. Next, it reopens the file, reads back the data, and
outputs it to the screen.
************************************************************/
package examples.datatypes;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_T_OpaqueAttribute {
private static String FILENAME = "H5Ex_T_OpaqueAttribute.h5";
private static String DATASETNAME = "DS1";
private static String ATTRIBUTENAME = "A1";
private static final int DIM0 = 4;
private static final int LEN = 7;
private static final int RANK = 1;
private static void CreateDataset() {
long file_id = -1;
long dataspace_id = -1;
long datatype_id = -1;
long dataset_id = -1;
long attribute_id = -1;
long[] dims = { DIM0 };
byte[] dset_data = new byte[DIM0 * LEN];
byte[] str_data = { 'O', 'P', 'A', 'Q', 'U', 'E' };
// Initialize data.
for (int indx = 0; indx < DIM0; indx++) {
for (int jndx = 0; jndx < LEN - 1; jndx++)
dset_data[jndx + indx * LEN] = str_data[jndx];
dset_data[LEN - 1 + indx * LEN] = (byte) (indx + '0');
}
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataset with a scalar dataspace.
try {
dataspace_id = H5.H5Screate(HDF5Constants.H5S_SCALAR);
if (dataspace_id >= 0) {
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, dataspace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
H5.H5Sclose(dataspace_id);
dataspace_id = -1;
}
}
catch (Exception e) {
e.printStackTrace();
}
// Create opaque datatype and set the tag to something appropriate.
// For this example we will write and view the data as a character
// array.
try {
datatype_id = H5.H5Tcreate(HDF5Constants.H5T_OPAQUE, (long)LEN);
if (datatype_id >= 0)
H5.H5Tset_tag(datatype_id, "Character array");
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
try {
dataspace_id = H5.H5Screate_simple(RANK, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the attribute and write the array data to it.
try {
if ((dataset_id >= 0) && (datatype_id >= 0) && (dataspace_id >= 0))
attribute_id = H5.H5Acreate(dataset_id, ATTRIBUTENAME, datatype_id, dataspace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the dataset.
try {
if ((attribute_id >= 0) && (datatype_id >= 0))
H5.H5Awrite(attribute_id, datatype_id, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (attribute_id >= 0)
H5.H5Aclose(attribute_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (datatype_id >= 0)
H5.H5Tclose(datatype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void ReadDataset() {
long file_id = -1;
long datatype_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long attribute_id = -1;
long type_len = -1;
long[] dims = { DIM0 };
byte[] dset_data;
String tag_name = null;
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
attribute_id = H5.H5Aopen_by_name(dataset_id, ".", ATTRIBUTENAME, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Get datatype and properties for the datatype.
try {
if (attribute_id >= 0)
datatype_id = H5.H5Aget_type(attribute_id);
if (datatype_id >= 0) {
type_len = H5.H5Tget_size(datatype_id);
tag_name = H5.H5Tget_tag(datatype_id);
}
}
catch (Exception e) {
e.printStackTrace();
}
// Get dataspace and allocate memory for read buffer.
try {
if (attribute_id >= 0)
dataspace_id = H5.H5Aget_space(attribute_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sget_simple_extent_dims(dataspace_id, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Allocate buffer.
dset_data = new byte[(int) (dims[0] * type_len)];
// Read data.
try {
if ((attribute_id >= 0) && (datatype_id >= 0))
H5.H5Aread(attribute_id, datatype_id, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
System.out.println("Datatype tag for " + ATTRIBUTENAME + " is: \"" + tag_name + "\"");
for (int indx = 0; indx < dims[0]; indx++) {
System.out.print(ATTRIBUTENAME + "[" + indx + "]: ");
for (int jndx = 0; jndx < type_len; jndx++) {
char temp = (char) dset_data[jndx + indx * (int)type_len];
System.out.print(temp);
}
System.out.println("");
}
System.out.println();
// End access to the dataset and release resources used by it.
try {
if (attribute_id >= 0)
H5.H5Aclose(attribute_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (datatype_id >= 0)
H5.H5Tclose(datatype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_T_OpaqueAttribute.CreateDataset();
// Now we begin the read section of this example. Here we assume
// the dataset and array have the same name and rank, but can have
// any size. Therefore we must allocate a new array to read in
// data using malloc().
H5Ex_T_OpaqueAttribute.ReadDataset();
}
}
+311
View File
@@ -0,0 +1,311 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to read and write string datatypes
to a dataset. The program first writes strings to a
dataset with a dataspace of DIM0, then closes the file.
Next, it reopens the file, reads back the data, and
outputs it to the screen.
************************************************************/
package examples.datatypes;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_T_String {
private static String FILENAME = "H5Ex_T_String.h5";
private static String DATASETNAME = "DS1";
private static final int DIM0 = 4;
private static final int SDIM = 8;
private static final int RANK = 1;
private static void CreateDataset() {
long file_id = -1;
long memtype_id = -1;
long filetype_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long[] dims = { DIM0 };
byte[][] dset_data = new byte[DIM0][SDIM];
StringBuffer[] str_data = { new StringBuffer("Parting"), new StringBuffer("is such"),
new StringBuffer("sweet"), new StringBuffer("sorrow.") };
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create file and memory datatypes. For this example we will save
// the strings as FORTRAN strings, therefore they do not need space
// for the null terminator in the file.
try {
filetype_id = H5.H5Tcopy(HDF5Constants.H5T_FORTRAN_S1);
if (filetype_id >= 0)
H5.H5Tset_size(filetype_id, SDIM - 1);
}
catch (Exception e) {
e.printStackTrace();
}
try {
memtype_id = H5.H5Tcopy(HDF5Constants.H5T_C_S1);
if (memtype_id >= 0)
H5.H5Tset_size(memtype_id, SDIM);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
try {
dataspace_id = H5.H5Screate_simple(RANK, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset and write the string data to it.
try {
if ((file_id >= 0) && (filetype_id >= 0) && (dataspace_id >= 0))
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, filetype_id, dataspace_id, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the data to the dataset.
try {
for (int indx = 0; indx < DIM0; indx++) {
for (int jndx = 0; jndx < SDIM; jndx++) {
if (jndx < str_data[indx].length())
dset_data[indx][jndx] = (byte) str_data[indx].charAt(jndx);
else
dset_data[indx][jndx] = 0;
}
}
if ((dataset_id >= 0) && (memtype_id >= 0))
H5.H5Dwrite(dataset_id, memtype_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the file type.
try {
if (filetype_id >= 0)
H5.H5Tclose(filetype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the mem type.
try {
if (memtype_id >= 0)
H5.H5Tclose(memtype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void ReadDataset() {
long file_id = -1;
long filetype_id = -1;
long memtype_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long sdim = 0;
long[] dims = { DIM0 };
byte[][] dset_data;
StringBuffer[] str_data;
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Get the datatype and its size.
try {
if (dataset_id >= 0)
filetype_id = H5.H5Dget_type(dataset_id);
if (filetype_id >= 0) {
sdim = H5.H5Tget_size(filetype_id);
sdim++; // Make room for null terminator
}
}
catch (Exception e) {
e.printStackTrace();
}
// Get dataspace and allocate memory for read buffer.
try {
if (dataset_id >= 0)
dataspace_id = H5.H5Dget_space(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sget_simple_extent_dims(dataspace_id, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Allocate space for data.
dset_data = new byte[(int) dims[0]][(int)sdim];
str_data = new StringBuffer[(int) dims[0]];
// Create the memory datatype.
try {
memtype_id = H5.H5Tcopy(HDF5Constants.H5T_C_S1);
if (memtype_id >= 0)
H5.H5Tset_size(memtype_id, sdim);
}
catch (Exception e) {
e.printStackTrace();
}
// Read data.
try {
if ((dataset_id >= 0) && (memtype_id >= 0))
H5.H5Dread(dataset_id, memtype_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
byte[] tempbuf = new byte[(int)sdim];
for (int indx = 0; indx < (int) dims[0]; indx++) {
for (int jndx = 0; jndx < sdim; jndx++) {
tempbuf[jndx] = dset_data[indx][jndx];
}
str_data[indx] = new StringBuffer(new String(tempbuf).trim());
}
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
for (int indx = 0; indx < dims[0]; indx++) {
System.out.println(DATASETNAME + " [" + indx + "]: " + str_data[indx]);
}
System.out.println();
// End access to the dataset and release resources used by it.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the file type.
try {
if (filetype_id >= 0)
H5.H5Tclose(filetype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the mem type.
try {
if (memtype_id >= 0)
H5.H5Tclose(memtype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_T_String.CreateDataset();
// Now we begin the read section of this example. Here we assume
// the dataset and array have the same name and rank, but can have
// any size. Therefore we must allocate a new array to read in
// data using malloc().
H5Ex_T_String.ReadDataset();
}
}
@@ -0,0 +1,351 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to read and write string datatypes
to an attribute. The program first writes strings to an
attribute with a dataspace of DIM0, then closes the file.
Next, it reopens the file, reads back the data, and
outputs it to the screen.
************************************************************/
package examples.datatypes;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_T_StringAttribute {
private static String FILENAME = "H5Ex_T_StringAttribute.h5";
private static String DATASETNAME = "DS1";
private static String ATTRIBUTENAME = "A1";
private static final int DIM0 = 4;
private static final int SDIM = 8;
private static final int RANK = 1;
private static void CreateDataset() {
long file_id = -1;
long memtype_id = -1;
long filetype_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long attribute_id = -1;
long[] dims = { DIM0 };
byte[][] dset_data = new byte[DIM0][SDIM];
StringBuffer[] str_data = { new StringBuffer("Parting"), new StringBuffer("is such"),
new StringBuffer("sweet"), new StringBuffer("sorrow.") };
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create file and memory datatypes. For this example we will save
// the strings as FORTRAN strings, therefore they do not need space
// for the null terminator in the file.
try {
filetype_id = H5.H5Tcopy(HDF5Constants.H5T_FORTRAN_S1);
if (filetype_id >= 0)
H5.H5Tset_size(filetype_id, SDIM - 1);
}
catch (Exception e) {
e.printStackTrace();
}
try {
memtype_id = H5.H5Tcopy(HDF5Constants.H5T_C_S1);
if (memtype_id >= 0)
H5.H5Tset_size(memtype_id, SDIM);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataset with a scalar dataspace.
try {
dataspace_id = H5.H5Screate(HDF5Constants.H5S_SCALAR);
if (dataspace_id >= 0) {
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, dataspace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
H5.H5Sclose(dataspace_id);
dataspace_id = -1;
}
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
try {
dataspace_id = H5.H5Screate_simple(RANK, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the attribute.
try {
if ((dataset_id >= 0) && (dataspace_id >= 0) && (filetype_id >= 0))
attribute_id = H5.H5Acreate(dataset_id, ATTRIBUTENAME, filetype_id, dataspace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the data to the dataset.
try {
for (int indx = 0; indx < DIM0; indx++) {
for (int jndx = 0; jndx < SDIM; jndx++) {
if (jndx < str_data[indx].length())
dset_data[indx][jndx] = (byte) str_data[indx].charAt(jndx);
else
dset_data[indx][jndx] = 0;
}
}
if ((attribute_id >= 0) && (memtype_id >= 0))
H5.H5Awrite(attribute_id, memtype_id, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (attribute_id >= 0)
H5.H5Aclose(attribute_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the file type.
try {
if (filetype_id >= 0)
H5.H5Tclose(filetype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the mem type.
try {
if (memtype_id >= 0)
H5.H5Tclose(memtype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void ReadDataset() {
long file_id = -1;
long filetype_id = -1;
long memtype_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long attribute_id = -1;
long sdim = 0;
long[] dims = { DIM0 };
byte[][] dset_data;
StringBuffer[] str_data;
// Open an existing file.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing dataset.
try {
if (file_id >= 0)
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
attribute_id = H5.H5Aopen_by_name(dataset_id, ".", ATTRIBUTENAME, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Get the datatype and its size.
try {
if (attribute_id >= 0)
filetype_id = H5.H5Aget_type(attribute_id);
if (filetype_id >= 0) {
sdim = H5.H5Tget_size(filetype_id);
sdim++; // Make room for null terminator
}
}
catch (Exception e) {
e.printStackTrace();
}
// Get dataspace and allocate memory for read buffer.
try {
if (attribute_id >= 0)
dataspace_id = H5.H5Aget_space(attribute_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataspace_id >= 0)
H5.H5Sget_simple_extent_dims(dataspace_id, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Allocate space for data.
dset_data = new byte[(int) dims[0]][(int)sdim];
str_data = new StringBuffer[(int) dims[0]];
// Create the memory datatype.
try {
memtype_id = H5.H5Tcopy(HDF5Constants.H5T_C_S1);
if (memtype_id >= 0)
H5.H5Tset_size(memtype_id, sdim);
}
catch (Exception e) {
e.printStackTrace();
}
// Read data.
try {
if ((attribute_id >= 0) && (memtype_id >= 0))
H5.H5Aread(attribute_id, memtype_id, dset_data);
byte[] tempbuf = new byte[(int)sdim];
for (int indx = 0; indx < (int) dims[0]; indx++) {
for (int jndx = 0; jndx < sdim; jndx++) {
tempbuf[jndx] = dset_data[indx][jndx];
}
str_data[indx] = new StringBuffer(new String(tempbuf).trim());
}
}
catch (Exception e) {
e.printStackTrace();
}
// Output the data to the screen.
for (int indx = 0; indx < dims[0]; indx++) {
System.out.println(DATASETNAME + " [" + indx + "]: " + str_data[indx]);
}
System.out.println();
// End access to the dataset and release resources used by it.
try {
if (attribute_id >= 0)
H5.H5Aclose(attribute_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the file type.
try {
if (filetype_id >= 0)
H5.H5Tclose(filetype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the mem type.
try {
if (memtype_id >= 0)
H5.H5Tclose(memtype_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_T_StringAttribute.CreateDataset();
// Now we begin the read section of this example. Here we assume
// the dataset and array have the same name and rank, but can have
// any size. Therefore we must allocate a new array to read in
// data using malloc().
H5Ex_T_StringAttribute.ReadDataset();
}
}
@@ -0,0 +1,138 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
Creating and writing a VL string to a file.
************************************************************/
package examples.datatypes;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_T_VLString
{
private static String FILENAME = "H5Ex_T_VLString.h5";
private static String DATASETNAME = "DS1";
private static void createDataset() {
long file_id = -1;
long type_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
int rank = 1;
String[] str_data = { "Parting", "is such", "sweet", "sorrow." };
long[] dims = { str_data.length };
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
try {
type_id = H5.H5Tcopy(HDF5Constants.H5T_C_S1);
H5.H5Tset_size(type_id, HDF5Constants.H5T_VARIABLE);
}
catch (Exception e) {
e.printStackTrace();
}
// Create dataspace. Setting maximum size to NULL sets the maximum
// size to be the current size.
try {
dataspace_id = H5.H5Screate_simple(rank, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset and write the string data to it.
try {
if ((file_id >= 0) && (type_id >= 0) && (dataspace_id >= 0)) {
dataset_id = H5.H5Dcreate(file_id, DATASETNAME, type_id, dataspace_id, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
}
catch (Exception e) {
e.printStackTrace();
}
// Write the data to the dataset.
try {
if (dataset_id >= 0)
H5.H5Dwrite_VLStrings(dataset_id, type_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, str_data);
}
catch (Exception e) {
e.printStackTrace();
}
try {
H5.H5Sclose(dataspace_id);
H5.H5Tclose(type_id);
H5.H5Dclose(dataset_id);
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
private static void readDataset() {
long file_id = -1;
long type_id = -1;
long dataset_id = -1;
String[] str_data = { "", "", "", "" };
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
try {
dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
type_id = H5.H5Dget_type(dataset_id);
H5.H5Dread_VLStrings(dataset_id, type_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT,
str_data);
}
catch (Exception e) {
e.printStackTrace();
}
for (int indx = 0; indx < str_data.length; indx++)
System.out.println(DATASETNAME + " [" + indx + "]: " + str_data[indx]);
try {
H5.H5Tclose(type_id);
H5.H5Dclose(dataset_id);
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_T_VLString.createDataset();
H5Ex_T_VLString.readDataset();
}
}
+78
View File
@@ -0,0 +1,78 @@
#
# Copyright by The HDF Group.
# Copyright by the Board of Trustees of the University of Illinois.
# All rights reserved.
#
# This file is part of HDF5. The full HDF5 copyright notice, including
# terms governing use, modification, and redistribution, is contained in
# the files COPYING and Copyright.html. COPYING can be found at the root
# of the source code distribution tree; Copyright.html can be found at the
# root level of an installed copy of the electronic HDF5 document set and
# is linked from the top-level documents page. It can also be found at
# http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have
# access to either file, you may request a copy from help@hdfgroup.org.
##
## Makefile.am
## Run automake to generate a Makefile.in from this file.
##
#
# HDF5 Java Library Examples Makefile(.in)
include $(top_srcdir)/config/commence.am
# Mark this directory as part of the JNI API
JAVA_API=yes
JAVAROOT = .classes
classes:
$(MKDIR_P) $(@D)/$(JAVAROOT)
pkgpath = examples/datatypes
hdfjarfile = jar$(PACKAGE_TARNAME)-$(PACKAGE_VERSION).jar
CLASSPATH_ENV=CLASSPATH=.:$(JAVAROOT):$(top_builddir)/java/src/$(hdfjarfile):$(top_srcdir)/java/lib/slf4j-api-1.7.5.jar:$(top_srcdir)/java/lib/ext/slf4j-simple-1.7.5.jar:$$CLASSPATH
jarfile = jar$(PACKAGE_TARNAME)datatypes.jar
AM_JAVACFLAGS = $(H5_JAVACFLAGS) -deprecation
TESTPACKAGE =
noinst_JAVA = \
H5Ex_T_Array.java \
H5Ex_T_ArrayAttribute.java \
H5Ex_T_Bit.java \
H5Ex_T_BitAttribute.java \
H5Ex_T_Commit.java \
H5Ex_T_Compound.java \
H5Ex_T_CompoundAttribute.java \
H5Ex_T_Float.java \
H5Ex_T_FloatAttribute.java \
H5Ex_T_Integer.java \
H5Ex_T_IntegerAttribute.java \
H5Ex_T_ObjectReference.java \
H5Ex_T_ObjectReferenceAttribute.java \
H5Ex_T_Opaque.java \
H5Ex_T_OpaqueAttribute.java \
H5Ex_T_String.java \
H5Ex_T_StringAttribute.java \
H5Ex_T_VLString.java
$(jarfile): classnoinst.stamp classes
$(JAR) cvf $@ -C $(JAVAROOT)/ $(pkgpath)
noinst_DATA = $(jarfile)
.PHONY: classes
check_SCRIPTS = runExample.sh
TEST_SCRIPT = $(check_SCRIPTS)
CLEANFILES = classnoinst.stamp $(jarfile) $(JAVAROOT)/$(pkgpath)/*.class runExample.sh
clean:
rm -rf $(JAVAROOT)
rm -f $(jarfile)
rm -f classnoinst.stamp
include $(top_srcdir)/config/conclude.am
+408
View File
@@ -0,0 +1,408 @@
#! /bin/sh
#
# Copyright by The HDF Group.
# Copyright by the Board of Trustees of the University of Illinois.
# All rights reserved.
#
# This file is part of HDF5. The full HDF5 copyright notice, including
# terms governing use, modification, and redistribution, is contained in
# the files COPYING and Copyright.html. COPYING can be found at the root
# of the source code distribution tree; Copyright.html can be found at the
# root level of an installed copy of the electronic HDF5 document set and
# is linked from the top-level documents page. It can also be found at
# http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have
# access to either file, you may request a copy from help@hdfgroup.org.
#
top_builddir=@top_builddir@
top_srcdir=@top_srcdir@
srcdir=@srcdir@
TESTNAME=EX_Datatypes
EXIT_SUCCESS=0
EXIT_FAILURE=1
# Set up default variable values if not supplied by the user.
RM='rm -rf'
CMP='cmp'
DIFF='diff -c'
CP='cp'
DIRNAME='dirname'
LS='ls'
AWK='awk'
nerrors=0
# where the libs exist
HDFLIB_HOME="$top_srcdir/java/lib"
BLDLIBDIR="./lib"
BLDDIR="."
HDFTEST_HOME="$top_srcdir/java/examples/datatypes"
JARFILE=jar@PACKAGE_TARNAME@-@PACKAGE_VERSION@.jar
TESTJARFILE=jar@PACKAGE_TARNAME@datatypes.jar
test -d $BLDLIBDIR || mkdir -p $BLDLIBDIR
######################################################################
# library files
# --------------------------------------------------------------------
# All the library files copy from source directory to test directory
# NOTE: Keep this framework to add/remove test files.
# This list are also used for checking exist.
# Comment '#' without space can be used.
# --------------------------------------------------------------------
LIST_LIBRARY_FILES="
$HDFLIB_HOME/slf4j-api-1.7.5.jar
$HDFLIB_HOME/ext/slf4j-simple-1.7.5.jar
$top_builddir/src/.libs/libhdf5.*
$top_builddir/java/src/jni/.libs/libhdf5_java.*
$top_builddir/java/src/$JARFILE
"
LIST_DATA_FILES="
$HDFTEST_HOME/../testfiles/examples.datatypes.H5Ex_T_Array.txt
$HDFTEST_HOME/../testfiles/examples.datatypes.H5Ex_T_ArrayAttribute.txt
$HDFTEST_HOME/../testfiles/examples.datatypes.H5Ex_T_Bit.txt
$HDFTEST_HOME/../testfiles/examples.datatypes.H5Ex_T_BitAttribute.txt
$HDFTEST_HOME/../testfiles/examples.datatypes.H5Ex_T_Commit.txt
$HDFTEST_HOME/../testfiles/examples.datatypes.H5Ex_T_Compound.txt
$HDFTEST_HOME/../testfiles/examples.datatypes.H5Ex_T_CompoundAttribute.txt
$HDFTEST_HOME/../testfiles/examples.datatypes.H5Ex_T_Float.txt
$HDFTEST_HOME/../testfiles/examples.datatypes.H5Ex_T_FloatAttribute.txt
$HDFTEST_HOME/../testfiles/examples.datatypes.H5Ex_T_Integer.txt
$HDFTEST_HOME/../testfiles/examples.datatypes.H5Ex_T_IntegerAttribute.txt
$HDFTEST_HOME/../testfiles/examples.datatypes.H5Ex_T_ObjectReference.txt
$HDFTEST_HOME/../testfiles/examples.datatypes.H5Ex_T_ObjectReferenceAttribute.txt
$HDFTEST_HOME/../testfiles/examples.datatypes.H5Ex_T_Opaque.txt
$HDFTEST_HOME/../testfiles/examples.datatypes.H5Ex_T_OpaqueAttribute.txt
$HDFTEST_HOME/../testfiles/examples.datatypes.H5Ex_T_String.txt
$HDFTEST_HOME/../testfiles/examples.datatypes.H5Ex_T_StringAttribute.txt
$HDFTEST_HOME/../testfiles/examples.datatypes.H5Ex_T_VLString.txt
"
#
# copy files from source dirs to test dir
#
COPY_LIBFILES="$LIST_LIBRARY_FILES"
COPY_LIBFILES_TO_BLDLIBDIR()
{
# copy test files. Used -f to make sure get a new copy
for tstfile in $COPY_LIBFILES
do
# ignore '#' comment
echo $tstfile | tr -d ' ' | grep '^#' > /dev/null
RET=$?
if [ $RET -eq 1 ]; then
# skip cp if srcdir is same as destdir
# this occurs when build/test performed in source dir and
# make cp fail
SDIR=`$DIRNAME $tstfile`
INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'`
INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'`
if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then
$CP -f $tstfile $BLDLIBDIR
if [ $? -ne 0 ]; then
echo "Error: FAILED to copy $tstfile ."
# Comment out this to CREATE expected file
exit $EXIT_FAILURE
fi
fi
fi
done
}
CLEAN_LIBFILES_AND_BLDLIBDIR()
{
# skip rm if srcdir is same as destdir
# this occurs when build/test performed in source dir and
# make cp fail
SDIR=`$DIRNAME $tstfile`
INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'`
INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'`
if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then
$RM $BLDLIBDIR
fi
}
COPY_DATAFILES="$LIST_DATA_FILES"
COPY_DATAFILES_TO_BLDDIR()
{
# copy test files. Used -f to make sure get a new copy
for tstfile in $COPY_DATAFILES
do
# ignore '#' comment
echo $tstfile | tr -d ' ' | grep '^#' > /dev/null
RET=$?
if [ $RET -eq 1 ]; then
# skip cp if srcdir is same as destdir
# this occurs when build/test performed in source dir and
# make cp fail
SDIR=`$DIRNAME $tstfile`
INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'`
INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'`
if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then
$CP -f $tstfile $BLDDIR
if [ $? -ne 0 ]; then
echo "Error: FAILED to copy $tstfile ."
# Comment out this to CREATE expected file
exit $EXIT_FAILURE
fi
fi
fi
done
}
CLEAN_DATAFILES_AND_BLDDIR()
{
# skip rm if srcdir is same as destdir
# this occurs when build/test performed in source dir and
# make cp fail
SDIR=`$DIRNAME $tstfile`
INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'`
INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'`
if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then
$RM $BLDDIR/*.txt
$RM $BLDDIR/*.out
fi
}
# Print a line-line message left justified in a field of 70 characters
# beginning with the word "Testing".
#
TESTING() {
SPACES=" "
echo "Testing $* $SPACES" | cut -c1-70 | tr -d '\012'
}
# where Java is installed (requires jdk1.7.x)
JAVAEXE=@JAVA@
JAVAEXEFLAGS=@H5_JAVAFLAGS@
###############################################################################
# DO NOT MODIFY BELOW THIS LINE
###############################################################################
# prepare for test
COPY_LIBFILES_TO_BLDLIBDIR
COPY_DATAFILES_TO_BLDDIR
CPATH=".:"$BLDLIBDIR"/"$JARFILE":"$BLDLIBDIR"/slf4j-api-1.7.5.jar:"$BLDLIBDIR"/slf4j-simple-1.7.5.jar:"$TESTJARFILE""
TEST=/usr/bin/test
if [ ! -x /usr/bin/test ]
then
TEST=`which test`
fi
if $TEST -z "$CLASSPATH"; then
CLASSPATH=""
fi
CLASSPATH=$CPATH":"$CLASSPATH
export CLASSPATH
if $TEST -n "$JAVAPATH" ; then
PATH=$JAVAPATH":"$PATH
export PATH
fi
if $TEST -e /bin/uname; then
os_name=`/bin/uname -s`
elif $TEST -e /usr/bin/uname; then
os_name=`/usr/bin/uname -s`
else
os_name=unknown
fi
if $TEST -z "$LD_LIBRARY_PATH" ; then
LD_LIBRARY_PATH=""
fi
case $os_name in
Darwin)
DYLD_LIBRARY_PATH=$BLDLIBDIR:$DYLD_LIBRARY_PATH
export DYLD_LIBRARY_PATH
LD_LIBRARY_PATH=$DYLD_LIBRARY_PATH
;;
*)
LD_LIBRARY_PATH=$BLDLIBDIR:$LD_LIBRARY_PATH
;;
esac
export LD_LIBRARY_PATH
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_Array"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_Array > H5Ex_T_Array.out)
if diff H5Ex_T_Array.out examples.datatypes.H5Ex_T_Array.txt > /dev/null; then
echo " PASSED datatypes.H5Ex_T_Array"
else
echo "**FAILED** datatypes.H5Ex_T_Array"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_ArrayAttribute"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_ArrayAttribute > H5Ex_T_ArrayAttribute.out)
if diff H5Ex_T_ArrayAttribute.out examples.datatypes.H5Ex_T_ArrayAttribute.txt > /dev/null; then
echo " PASSED datatypes.H5Ex_T_ArrayAttribute"
else
echo "**FAILED** datatypes.H5Ex_T_ArrayAttribute"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_Bit"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_Bit > H5Ex_T_Bit.out)
if diff H5Ex_T_Bit.out examples.datatypes.H5Ex_T_Bit.txt > /dev/null; then
echo " PASSED datatypes.H5Ex_T_Bit"
else
echo "**FAILED** datatypes.H5Ex_T_Bit"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_BitAttribute"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_BitAttribute > H5Ex_T_BitAttribute.out)
if diff H5Ex_T_BitAttribute.out examples.datatypes.H5Ex_T_BitAttribute.txt > /dev/null; then
echo " PASSED datatypes.H5Ex_T_BitAttribute"
else
echo "**FAILED** datatypes.H5Ex_T_BitAttribute"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_Commit"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_Commit > H5Ex_T_Commit.out)
if diff H5Ex_T_Commit.out examples.datatypes.H5Ex_T_Commit.txt > /dev/null; then
echo " PASSED datatypes.H5Ex_T_Commit"
else
echo "**FAILED** datatypes.H5Ex_T_Commit"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_Compound"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_Compound > H5Ex_T_Compound.out)
if diff H5Ex_T_Compound.out examples.datatypes.H5Ex_T_Compound.txt > /dev/null; then
echo " PASSED datatypes.H5Ex_T_Compound"
else
echo "**FAILED** datatypes.H5Ex_T_Compound"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_CompoundAttribute"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_CompoundAttribute > H5Ex_T_CompoundAttribute.out)
if diff H5Ex_T_CompoundAttribute.out examples.datatypes.H5Ex_T_CompoundAttribute.txt > /dev/null; then
echo " PASSED datatypes.H5Ex_T_CompoundAttribute"
else
echo "**FAILED** datatypes.H5Ex_T_CompoundAttribute"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_Float"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_Float > H5Ex_T_Float.out)
if diff H5Ex_T_Float.out examples.datatypes.H5Ex_T_Float.txt > /dev/null; then
echo " PASSED datatypes.H5Ex_T_Float"
else
echo "**FAILED** datatypes.H5Ex_T_Float"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_FloatAttribute"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_FloatAttribute > H5Ex_T_FloatAttribute.out)
if diff H5Ex_T_FloatAttribute.out examples.datatypes.H5Ex_T_FloatAttribute.txt > /dev/null; then
echo " PASSED datatypes.H5Ex_T_FloatAttribute"
else
echo "**FAILED** datatypes.H5Ex_T_FloatAttribute"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_Integer"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_Integer > H5Ex_T_Integer.out)
if diff H5Ex_T_Integer.out examples.datatypes.H5Ex_T_Integer.txt > /dev/null; then
echo " PASSED datatypes.H5Ex_T_Integer"
else
echo "**FAILED** datatypes.H5Ex_T_Integer"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_IntegerAttribute"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_IntegerAttribute > H5Ex_T_IntegerAttribute.out)
if diff H5Ex_T_IntegerAttribute.out examples.datatypes.H5Ex_T_IntegerAttribute.txt > /dev/null; then
echo " PASSED datatypes.H5Ex_T_IntegerAttribute"
else
echo "**FAILED** datatypes.H5Ex_T_IntegerAttribute"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_ObjectReference"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_ObjectReference > H5Ex_T_ObjectReference.out)
if diff H5Ex_T_ObjectReference.out examples.datatypes.H5Ex_T_ObjectReference.txt > /dev/null; then
echo " PASSED datatypes.H5Ex_T_ObjectReference"
else
echo "**FAILED** datatypes.H5Ex_T_ObjectReference"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_ObjectReferenceAttribute"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_ObjectReferenceAttribute > H5Ex_T_ObjectReferenceAttribute.out)
if diff H5Ex_T_ObjectReferenceAttribute.out examples.datatypes.H5Ex_T_ObjectReferenceAttribute.txt > /dev/null; then
echo " PASSED datatypes.H5Ex_T_ObjectReferenceAttribute"
else
echo "**FAILED** datatypes.H5Ex_T_ObjectReferenceAttribute"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_Opaque"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_Opaque > H5Ex_T_Opaque.out)
if diff H5Ex_T_Opaque.out examples.datatypes.H5Ex_T_Opaque.txt > /dev/null; then
echo " PASSED datatypes.H5Ex_T_Opaque"
else
echo "**FAILED** datatypes.H5Ex_T_Opaque"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_OpaqueAttribute"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_OpaqueAttribute > H5Ex_T_OpaqueAttribute.out)
if diff H5Ex_T_OpaqueAttribute.out examples.datatypes.H5Ex_T_OpaqueAttribute.txt > /dev/null; then
echo " PASSED datatypes.H5Ex_T_OpaqueAttribute"
else
echo "**FAILED** datatypes.H5Ex_T_OpaqueAttribute"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_String"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_String > H5Ex_T_String.out)
if diff H5Ex_T_String.out examples.datatypes.H5Ex_T_String.txt > /dev/null; then
echo " PASSED datatypes.H5Ex_T_String"
else
echo "**FAILED** datatypes.H5Ex_T_String"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_StringAttribute"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_StringAttribute > H5Ex_T_StringAttribute.out)
if diff H5Ex_T_StringAttribute.out examples.datatypes.H5Ex_T_StringAttribute.txt > /dev/null; then
echo " PASSED datatypes.H5Ex_T_StringAttribute"
else
echo "**FAILED** datatypes.H5Ex_T_StringAttribute"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_VLString"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_VLString > H5Ex_T_VLString.out)
if diff H5Ex_T_VLString.out examples.datatypes.H5Ex_T_VLString.txt > /dev/null; then
echo " PASSED datatypes.H5Ex_T_VLString"
else
echo "**FAILED** datatypes.H5Ex_T_VLString"
nerrors="`expr $nerrors + 1`"
fi
# Clean up temporary files/directories
CLEAN_LIBFILES_AND_BLDLIBDIR
CLEAN_DATAFILES_AND_BLDDIR
# Report test results and exit
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
+138
View File
@@ -0,0 +1,138 @@
cmake_minimum_required (VERSION 3.1.0)
PROJECT (HDFJAVA_EXAMPLES_GROUPS Java)
set (CMAKE_VERBOSE_MAKEFILE 1)
INCLUDE_DIRECTORIES (
${HDF5_JAVA_JNI_BINARY_DIR}
${HDF5_JAVA_HDF5_LIB_DIR}
)
set (HDF_JAVA_EXAMPLES
H5Ex_G_Create
H5Ex_G_Iterate
H5Ex_G_Compact
H5Ex_G_Corder
H5Ex_G_Intermediate
H5Ex_G_Phase
H5Ex_G_Visit
)
if (WIN32)
set (CMAKE_JAVA_INCLUDE_FLAG_SEP ";")
else (WIN32)
set (CMAKE_JAVA_INCLUDE_FLAG_SEP ":")
endif (WIN32)
set (CMAKE_JAVA_INCLUDE_PATH "${HDF5_JAVA_JARS}")
set (CMAKE_JAVA_CLASSPATH ".")
foreach (CMAKE_INCLUDE_PATH ${CMAKE_JAVA_INCLUDE_PATH})
set (CMAKE_JAVA_CLASSPATH "${CMAKE_JAVA_CLASSPATH}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${CMAKE_INCLUDE_PATH}")
endforeach (CMAKE_INCLUDE_PATH)
foreach (example ${HDF_JAVA_EXAMPLES})
file (WRITE ${PROJECT_BINARY_DIR}/${example}_Manifest.txt
"Main-Class: examples.groups.${example}
"
)
add_jar (${example} MANIFEST ${PROJECT_BINARY_DIR}/${example}_Manifest.txt ${example}.java)
get_target_property (${example}_JAR_FILE ${example} JAR_FILE)
# install_jar (${example} ${HJAVA_INSTALL_DATA_DIR}/examples examples)
get_target_property (${example}_CLASSPATH ${example} CLASSDIR)
add_dependencies (${example} ${HDF5_JAVA_HDF5_LIB_TARGET})
endforeach (example ${HDF_JAVA_EXAMPLES})
set (CMAKE_JAVA_INCLUDE_PATH "${HDF5_JAVA_JARS};${HDF5_JAVA_LOGGING_JAR};${HDF5_JAVA_LOGGING_NOP_JAR}")
set (CMAKE_JAVA_CLASSPATH ".")
foreach (HDFJAVA_JAR ${CMAKE_JAVA_INCLUDE_PATH})
set (CMAKE_JAVA_CLASSPATH "${CMAKE_JAVA_CLASSPATH}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${HDFJAVA_JAR}")
endforeach (HDFJAVA_JAR)
set (HDF_JAVA_TEST_FILES
h5ex_g_iterate.h5
h5ex_g_visit.h5
)
foreach (h5_file ${HDF_JAVA_TEST_FILES})
set (dest "${PROJECT_BINARY_DIR}/${h5_file}")
#message (STATUS " Copying ${h5_file}")
add_custom_command (
TARGET H5Ex_G_Visit
POST_BUILD
COMMAND ${CMAKE_COMMAND}
ARGS -E copy_if_different ${PROJECT_SOURCE_DIR}/${h5_file} ${dest}
)
endforeach (h5_file ${HDF_JAVA_TEST_FILES})
MACRO (ADD_H5_TEST resultfile resultcode)
add_test (
NAME JAVA_groups-${resultfile}
COMMAND "${CMAKE_COMMAND}"
-D "TEST_TESTER=${CMAKE_Java_RUNTIME};${CMAKE_Java_RUNTIME_FLAGS}"
-D "TEST_PROGRAM=examples.groups.${resultfile}"
-D "TEST_ARGS:STRING=${ARGN}"
-D "TEST_CLASSPATH:STRING=${CMAKE_JAVA_CLASSPATH}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${${resultfile}_JAR_FILE}"
-D "TEST_LIBRARY_DIRECTORY=${CMAKE_TEST_OUTPUT_DIRECTORY}"
-D "TEST_FOLDER=${HDFJAVA_EXAMPLES_BINARY_DIR}"
-D "TEST_OUTPUT=groups/${resultfile}.out"
-D "TEST_EXPECT=${resultcode}"
-D "TEST_REFERENCE=groups/${resultfile}.txt"
-P "${HDF_RESOURCES_DIR}/jrunTest.cmake"
)
if (NOT "${last_test}" STREQUAL "")
set_tests_properties (JAVA_groups-${resultfile} PROPERTIES DEPENDS ${last_test})
endif (NOT "${last_test}" STREQUAL "")
set (last_test "JAVA_groups-${resultfile}")
ENDMACRO (ADD_H5_TEST file)
if (BUILD_TESTING)
foreach (example ${HDF_JAVA_EXAMPLES})
add_test (
NAME JAVA_groups-${example}-clearall-objects
COMMAND ${CMAKE_COMMAND}
-E remove
${example}.out
${example}.out.err
)
if (NOT "${last_test}" STREQUAL "")
set_tests_properties (JAVA_groups-${example}-clearall-objects PROPERTIES DEPENDS ${last_test})
endif (NOT "${last_test}" STREQUAL "")
set (last_test "JAVA_groups-${example}-clearall-objects")
if (NOT ${example} STREQUAL "H5Ex_G_Iterate" AND NOT ${example} STREQUAL "H5Ex_G_Visit")
if (${example} STREQUAL "H5Ex_G_Compact")
add_test (
NAME JAVA_groups-${example}-clearall-h5s
COMMAND ${CMAKE_COMMAND}
-E remove
${HDFJAVA_EXAMPLES_BINARY_DIR}/${example}1.h5
${HDFJAVA_EXAMPLES_BINARY_DIR}/${example}2.h5
)
else (${example} STREQUAL "H5Ex_G_Compact")
add_test (
NAME JAVA_groups-${example}-clearall-h5s
COMMAND ${CMAKE_COMMAND}
-E remove
${HDFJAVA_EXAMPLES_BINARY_DIR}/${example}.h5
)
endif (${example} STREQUAL "H5Ex_G_Compact")
if (NOT "${last_test}" STREQUAL "")
set_tests_properties (JAVA_groups-${example}-clearall-h5s PROPERTIES DEPENDS ${last_test})
endif (NOT "${last_test}" STREQUAL "")
set (last_test "JAVA_groups-${example}-clearall-h5s")
endif (NOT ${example} STREQUAL "H5Ex_G_Iterate" AND NOT ${example} STREQUAL "H5Ex_G_Visit")
add_test (
NAME JAVA_groups-${example}-copy-objects
COMMAND ${CMAKE_COMMAND}
-E copy_if_different
${HDFJAVA_EXAMPLES_SOURCE_DIR}/testfiles/examples.groups.${example}.txt
${HDFJAVA_EXAMPLES_GROUPS_BINARY_DIR}/${example}.txt
)
if (NOT "${last_test}" STREQUAL "")
set_tests_properties (JAVA_groups-${example}-copy-objects PROPERTIES DEPENDS ${last_test})
endif (NOT "${last_test}" STREQUAL "")
set (last_test "JAVA_groups-${example}-copy-objects")
ADD_H5_TEST (${example} 0)
endforeach (example ${HDF_JAVA_EXAMPLES})
endif (BUILD_TESTING)
+266
View File
@@ -0,0 +1,266 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
Creating a file and print the storage layout.
************************************************************/
package examples.groups;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
import hdf.hdf5lib.structs.H5G_info_t;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
public class H5Ex_G_Compact {
private static final String FILE1 = "H5Ex_G_Compact1.h5";
private static final String FILE2 = "H5Ex_G_Compact2.h5";
private static final String GROUP = "G1";
enum H5G_storage {
H5G_STORAGE_TYPE_UNKNOWN(-1),
H5G_STORAGE_TYPE_SYMBOL_TABLE(0),
H5G_STORAGE_TYPE_COMPACT(1),
H5G_STORAGE_TYPE_DENSE(2);
private static final Map<Integer, H5G_storage> lookup = new HashMap<Integer, H5G_storage>();
static {
for (H5G_storage s : EnumSet.allOf(H5G_storage.class))
lookup.put(s.getCode(), s);
}
private int code;
H5G_storage(int layout_type) {
this.code = layout_type;
}
public int getCode() {
return this.code;
}
public static H5G_storage get(int code) {
return lookup.get(code);
}
}
public static void CreateGroup() {
long file_id = -1;
long group_id = -1;
long fapl_id = -1;
H5G_info_t ginfo;
long size;
// Create file 1. This file will use original format groups.
try {
file_id = H5.H5Fcreate (FILE1, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create a group in the file1.
try {
if(file_id >= 0)
group_id = H5.H5Gcreate(file_id, GROUP, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Obtain the group info and print the group storage type.
try {
if(group_id >= 0) {
ginfo = H5.H5Gget_info(group_id);
System.out.print("Group storage type for " + FILE1 + " is: ");
switch (H5G_storage.get(ginfo.storage_type)) {
case H5G_STORAGE_TYPE_COMPACT:
System.out.println("H5G_STORAGE_TYPE_COMPACT"); // New compact format
break;
case H5G_STORAGE_TYPE_DENSE:
System.out.println("H5G_STORAGE_TYPE_DENSE"); // New dense (indexed) format
break;
case H5G_STORAGE_TYPE_SYMBOL_TABLE:
System.out.println("H5G_STORAGE_TYPE_SYMBOL_TABLE"); // Original format
break;
case H5G_STORAGE_TYPE_UNKNOWN:
System.out.println("H5G_STORAGE_TYPE_UNKNOWN");
break;
default:
System.out.println("Storage Type Invalid");
break;
}
}
}
catch (Exception e) {
e.printStackTrace();
}
// Close the group.
try {
if (group_id >= 0)
H5.H5Gclose(group_id);
}
catch (Exception e) {
e.printStackTrace();
}
// close the file 1.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Re-open file 1. Need to get the correct file size.
try {
file_id = H5.H5Fopen(FILE1, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Obtain and print the file size.
try {
if (file_id >= 0) {
size = H5.H5Fget_filesize(file_id);
System.out.println("File size for " + FILE1 + " is: " + size + " bytes");
}
}
catch (Exception e) {
e.printStackTrace();
}
// Close FILE1.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Set file access property list to allow the latest file format.
// This will allow the library to create new compact format groups.
try {
fapl_id = H5.H5Pcreate(HDF5Constants.H5P_FILE_ACCESS);
if (fapl_id >= 0)
H5.H5Pset_libver_bounds(fapl_id, HDF5Constants.H5F_LIBVER_LATEST, HDF5Constants.H5F_LIBVER_LATEST);
}
catch (Exception e) {
e.printStackTrace();
}
System.out.println();
// Create file 2 using the new file access property list.
try {
file_id = H5.H5Fcreate(FILE2, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, fapl_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Create group in file2.
try {
if(file_id >= 0)
group_id = H5.H5Gcreate(file_id, GROUP, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Obtain the group info and print the group storage type.
try {
if (group_id >= 0) {
ginfo = H5.H5Gget_info(group_id);
System.out.print("Group storage type for " + FILE2 + " is: ");
switch (H5G_storage.get(ginfo.storage_type)) {
case H5G_STORAGE_TYPE_COMPACT:
System.out.println("H5G_STORAGE_TYPE_COMPACT"); // New compact format
break;
case H5G_STORAGE_TYPE_DENSE:
System.out.println("H5G_STORAGE_TYPE_DENSE"); // New dense (indexed) format
break;
case H5G_STORAGE_TYPE_SYMBOL_TABLE:
System.out.println("H5G_STORAGE_TYPE_SYMBOL_TABLE"); // Original format
break;
case H5G_STORAGE_TYPE_UNKNOWN:
System.out.println("H5G_STORAGE_TYPE_UNKNOWN");
break;
default:
System.out.println("Storage Type Invalid");
break;
}
}
}
catch (Exception e) {
e.printStackTrace();
}
// Close the group.
try {
if (group_id >= 0)
H5.H5Gclose(group_id);
}
catch (Exception e) {
e.printStackTrace();
}
// close the file 2.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Re-open file 2. Needed to get the correct file size.
try {
file_id = H5.H5Fopen(FILE2, HDF5Constants.H5F_ACC_RDONLY, fapl_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Obtain and print the file size.
try {
if (file_id >= 0) {
size = H5.H5Fget_filesize(file_id);
System.out.println("File size for " + FILE2 + " is: " + size + " bytes");
}
}
catch (Exception e) {
e.printStackTrace();
}
// Close FILE2.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_G_Compact.CreateGroup();
}
}
+121
View File
@@ -0,0 +1,121 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
Creating a file with creation properties and traverse the
groups in alpabetical and creation order.
************************************************************/
package examples.groups;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
import hdf.hdf5lib.structs.H5G_info_t;
public class H5Ex_G_Corder {
private static String FILE = "H5Ex_G_Corder.h5";
private static void CreateGroup() throws Exception {
long file_id = -1;
long group_id = -1;
long subgroup_id = -1;
long gcpl_id = -1;
int status;
H5G_info_t ginfo;
int i;
String name;
try {
// Create a new file using default properties.
file_id = H5.H5Fcreate(FILE, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
// Create group creation property list and enable link creation order tracking.
gcpl_id = H5.H5Pcreate(HDF5Constants.H5P_GROUP_CREATE);
status = H5.H5Pset_link_creation_order(gcpl_id, HDF5Constants.H5P_CRT_ORDER_TRACKED
+ HDF5Constants.H5P_CRT_ORDER_INDEXED);
// Create primary group using the property list.
if (status >= 0)
group_id = H5.H5Gcreate(file_id, "index_group", HDF5Constants.H5P_DEFAULT, gcpl_id,
HDF5Constants.H5P_DEFAULT);
try {
/*
* Create subgroups in the primary group. These will be tracked by creation order. Note that these
* groups do not have to have the creation order tracking property set.
*/
subgroup_id = H5.H5Gcreate(group_id, "H", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
status = H5.H5Gclose(subgroup_id);
subgroup_id = H5.H5Gcreate(group_id, "D", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
status = H5.H5Gclose(subgroup_id);
subgroup_id = H5.H5Gcreate(group_id, "F", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
status = H5.H5Gclose(subgroup_id);
subgroup_id = H5.H5Gcreate(group_id, "5", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
status = H5.H5Gclose(subgroup_id);
// Get group info.
ginfo = H5.H5Gget_info(group_id);
// Traverse links in the primary group using alphabetical indices (H5_INDEX_NAME).
System.out.println("Traversing group using alphabetical indices:");
for (i = 0; i < ginfo.nlinks; i++) {
// Retrieve the name of the ith link in a group
name = H5.H5Lget_name_by_idx(group_id, ".", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC,
i, HDF5Constants.H5P_DEFAULT);
System.out.println("Index " + i + ": " + name);
}
// Traverse links in the primary group by creation order (H5_INDEX_CRT_ORDER).
System.out.println("Traversing group using creation order indices:");
for (i = 0; i < ginfo.nlinks; i++) {
// Retrieve the name of the ith link in a group
name = H5.H5Lget_name_by_idx(group_id, ".", HDF5Constants.H5_INDEX_CRT_ORDER,
HDF5Constants.H5_ITER_INC, i, HDF5Constants.H5P_DEFAULT);
System.out.println("Index " + i + ": " + name);
}
}
catch (Exception e) {
e.printStackTrace();
}
}
catch (Exception e) {
e.printStackTrace();
}
finally {
// Close and release resources.
if (gcpl_id >= 0)
H5.H5Pclose(gcpl_id);
if (group_id >= 0)
H5.H5Gclose(group_id);
if (file_id >= 0)
H5.H5Fclose(file_id);
}
}
public static void main(String[] args) {
try {
H5Ex_G_Corder.CreateGroup();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
}
+94
View File
@@ -0,0 +1,94 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to create, open, and close a group.
************************************************************/
package examples.groups;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5Ex_G_Create {
private static String FILENAME = "H5Ex_G_Create.h5";
private static String GROUPNAME = "G1";
private static void CreateGroup() {
long file_id = -1;
long group_id = -1;
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create a group in the file.
try {
if (file_id >= 0)
group_id = H5.H5Gcreate(file_id, "/" + GROUPNAME, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the group. The handle "group" can no longer be used.
try {
if (group_id >= 0)
H5.H5Gclose(group_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Re-open the group, obtaining a new handle.
try {
if (file_id >= 0)
group_id = H5.H5Gopen(file_id, "/" + GROUPNAME, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the group.
try {
if (group_id >= 0)
H5.H5Gclose(group_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_G_Create.CreateGroup();
}
}
@@ -0,0 +1,125 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to create intermediate groups with
a single call to H5Gcreate.
************************************************************/
package examples.groups;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
import hdf.hdf5lib.callbacks.H5O_iterate_cb;
import hdf.hdf5lib.callbacks.H5O_iterate_t;
import hdf.hdf5lib.structs.H5O_info_t;
import java.util.ArrayList;
public class H5Ex_G_Intermediate {
private static String FILE = "H5Ex_G_Intermediate.h5";
private void CreateGroup() throws Exception {
long file_id = -1;
long group_id = -1;
long gcpl_id = -1;
try {
// Create a new file_id using the default properties.
file_id = H5.H5Fcreate(FILE, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
// Create group_id creation property list and set it to allow creation of intermediate group_ids.
gcpl_id = H5.H5Pcreate(HDF5Constants.H5P_LINK_CREATE);
H5.H5Pset_create_intermediate_group(gcpl_id, true);
/*
* Create the group_id /G1/G2/G3. Note that /G1 and /G1/G2 do not exist yet. This call would cause an error
* if we did not use the previously created property list.
*/
group_id = H5
.H5Gcreate(file_id, "/G1/G2/G3", gcpl_id, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
// Print all the objects in the file_ids to show that intermediate group_ids have been created.
System.out.println("Objects in the file_id:");
// H5O_iterate_t iter_data = null;
H5O_iterate_t iter_data = new H5O_iter_data();
H5O_iterate_cb iter_cb = new H5O_iter_callback();
H5.H5Ovisit(file_id, HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_NATIVE, iter_cb, iter_data);
}
catch (Exception e) {
e.printStackTrace();
}
finally {
// Close and release resources.
if (gcpl_id >= 0)
H5.H5Pclose(gcpl_id);
if (group_id >= 0)
H5.H5Gclose(group_id);
if (file_id >= 0)
H5.H5Fclose(file_id);
}
}
public static void main(String[] args) {
try {
(new H5Ex_G_Intermediate()).CreateGroup();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
private class idata {
public String link_name = null;
public int link_type = -1;
idata(String name, int type) {
this.link_name = name;
this.link_type = type;
}
}
private class H5O_iter_data implements H5O_iterate_t {
public ArrayList<idata> iterdata = new ArrayList<idata>();
}
private class H5O_iter_callback implements H5O_iterate_cb {
public int callback(long group, String name, H5O_info_t info, H5O_iterate_t op_data) {
idata id = new idata(name, info.type);
((H5O_iter_data) op_data).iterdata.add(id);
System.out.print("/"); /* Print root group in object path */
// Check if the current object is the root group, and if not print the full path name and type.
if (name.charAt(0) == '.') /* Root group, do not print '.' */
System.out.println(" (Group)");
else if (info.type == HDF5Constants.H5O_TYPE_GROUP)
System.out.println(name + " (Group)");
else if (info.type == HDF5Constants.H5O_TYPE_DATASET)
System.out.println(name + " (Dataset)");
else if (info.type == HDF5Constants.H5O_TYPE_NAMED_DATATYPE)
System.out.println(name + " (Datatype)");
else
System.out.println(name + " (Unknown)");
return 0;
}
}
}
+119
View File
@@ -0,0 +1,119 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to iterate over group members using
H5Gget_obj_info_all.
************************************************************/
package examples.groups;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
public class H5Ex_G_Iterate {
private static String FILENAME = "groups/h5ex_g_iterate.h5";
private static String DATASETNAME = "/";
enum H5O_type {
H5O_TYPE_UNKNOWN(-1), // Unknown object type
H5O_TYPE_GROUP(0), // Object is a group
H5O_TYPE_DATASET(1), // Object is a dataset
H5O_TYPE_NAMED_DATATYPE(2), // Object is a named data type
H5O_TYPE_NTYPES(3); // Number of different object types
private static final Map<Integer, H5O_type> lookup = new HashMap<Integer, H5O_type>();
static {
for (H5O_type s : EnumSet.allOf(H5O_type.class))
lookup.put(s.getCode(), s);
}
private int code;
H5O_type(int layout_type) {
this.code = layout_type;
}
public int getCode() {
return this.code;
}
public static H5O_type get(int code) {
return lookup.get(code);
}
}
private static void do_iterate() {
long file_id = -1;
// Open a file using default properties.
try {
file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Begin iteration.
System.out.println("Objects in root group:");
try {
if (file_id >= 0) {
int count = (int) H5.H5Gn_members(file_id, DATASETNAME);
String[] oname = new String[count];
int[] otype = new int[count];
int[] ltype = new int[count];
long[] orefs = new long[count];
H5.H5Gget_obj_info_all(file_id, DATASETNAME, oname, otype, ltype, orefs, HDF5Constants.H5_INDEX_NAME);
// Get type of the object and display its name and type.
for (int indx = 0; indx < otype.length; indx++) {
switch (H5O_type.get(otype[indx])) {
case H5O_TYPE_GROUP:
System.out.println(" Group: " + oname[indx]);
break;
case H5O_TYPE_DATASET:
System.out.println(" Dataset: " + oname[indx]);
break;
case H5O_TYPE_NAMED_DATATYPE:
System.out.println(" Datatype: " + oname[indx]);
break;
default:
System.out.println(" Unknown: " + oname[indx]);
}
}
}
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_G_Iterate.do_iterate();
}
}
+241
View File
@@ -0,0 +1,241 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to set the conditions for
conversion between compact and dense (indexed) groups.
************************************************************/
package examples.groups;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
import hdf.hdf5lib.structs.H5G_info_t;
import java.util.EnumSet;
import java.util.HashMap;
import java.util.Map;
public class H5Ex_G_Phase {
private static String FILE = "H5Ex_G_Phase.h5";
private static int MAX_GROUPS = 7;
private static int MAX_COMPACT = 5;
private static int MIN_DENSE = 3;
enum H5G_storage {
H5G_STORAGE_TYPE_UNKNOWN(-1),
H5G_STORAGE_TYPE_SYMBOL_TABLE(0),
H5G_STORAGE_TYPE_COMPACT(1),
H5G_STORAGE_TYPE_DENSE(2);
private static final Map<Integer, H5G_storage> lookup = new HashMap<Integer, H5G_storage>();
static {
for (H5G_storage s : EnumSet.allOf(H5G_storage.class))
lookup.put(s.getCode(), s);
}
private int code;
H5G_storage(int layout_type) {
this.code = layout_type;
}
public int getCode() {
return this.code;
}
public static H5G_storage get(int code) {
return lookup.get(code);
}
}
private static void CreateGroup() {
long file_id = -1;
long group_id = -1;
long subgroup_id = -1;
long fapl_id = -1;
long gcpl_id = -1;
H5G_info_t ginfo;
String name = "G0"; // Name of subgroup_id
int i;
// Set file access property list to allow the latest file format.This will allow the library to create new
// format groups.
try {
fapl_id = H5.H5Pcreate(HDF5Constants.H5P_FILE_ACCESS);
if (fapl_id >= 0)
H5.H5Pset_libver_bounds(fapl_id, HDF5Constants.H5F_LIBVER_LATEST, HDF5Constants.H5F_LIBVER_LATEST);
}
catch (Exception e) {
e.printStackTrace();
}
// Create group access property list and set the phase change conditions.
try {
gcpl_id = H5.H5Pcreate(HDF5Constants.H5P_GROUP_CREATE);
if (gcpl_id >= 0)
H5.H5Pset_link_phase_change(gcpl_id, MAX_COMPACT, MIN_DENSE);
}
catch (Exception e) {
e.printStackTrace();
}
// Create a new file using the default properties.
try {
if (fapl_id >= 0)
file_id = H5.H5Fcreate(FILE, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, fapl_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Create primary group.
try {
if ((file_id >= 0) && (gcpl_id >= 0))
group_id = H5.H5Gcreate(file_id, name, HDF5Constants.H5P_DEFAULT, gcpl_id, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Add subgroups to "group" one at a time, print the storage type for "group" after each subgroup is created.
for (i = 1; i <= MAX_GROUPS; i++) {
// Define the subgroup name and create the subgroup.
char append = (char) (((char) i) + '0');
name = name + append; /* G1, G2, G3 etc. */
try {
if (group_id >= 0) {
subgroup_id = H5.H5Gcreate(group_id, name, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
H5.H5Gclose(subgroup_id);
}
}
catch (Exception e) {
e.printStackTrace();
}
// Obtain the group info and print the group storage type
try {
if (group_id >= 0) {
ginfo = H5.H5Gget_info(group_id);
System.out.print(ginfo.nlinks + " Group" + (ginfo.nlinks == 1 ? " " : "s") + ": Storage type is ");
switch (H5G_storage.get(ginfo.storage_type)) {
case H5G_STORAGE_TYPE_COMPACT:
System.out.println("H5G_STORAGE_TYPE_COMPACT"); // New compact format
break;
case H5G_STORAGE_TYPE_DENSE:
System.out.println("H5G_STORAGE_TYPE_DENSE"); // New dense (indexed) format
break;
case H5G_STORAGE_TYPE_SYMBOL_TABLE:
System.out.println("H5G_STORAGE_TYPE_SYMBOL_TABLE"); // Original format
break;
case H5G_STORAGE_TYPE_UNKNOWN:
System.out.println("H5G_STORAGE_TYPE_UNKNOWN");
break;
default:
System.out.println("Storage Type Invalid");
break;
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}
System.out.println();
// Delete subgroups one at a time, print the storage type for "group" after each subgroup is deleted.
for (i = MAX_GROUPS; i >= 1; i--) {
// Define the subgroup name and delete the subgroup.
try {
H5.H5Ldelete(group_id, name, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
name = name.substring(0, i + 1);
// Obtain the group info and print the group storage type
try {
if (group_id >= 0) {
ginfo = H5.H5Gget_info(group_id);
System.out.print(ginfo.nlinks + " Group" + (ginfo.nlinks == 1 ? " " : "s") + ": Storage type is ");
switch (H5G_storage.get(ginfo.storage_type)) {
case H5G_STORAGE_TYPE_COMPACT:
System.out.println("H5G_STORAGE_TYPE_COMPACT"); // New compact format
break;
case H5G_STORAGE_TYPE_DENSE:
System.out.println("H5G_STORAGE_TYPE_DENSE"); // New dense (indexed) format
break;
case H5G_STORAGE_TYPE_SYMBOL_TABLE:
System.out.println("H5G_STORAGE_TYPE_SYMBOL_TABLE"); // Original format
break;
case H5G_STORAGE_TYPE_UNKNOWN:
System.out.println("H5G_STORAGE_TYPE_UNKNOWN");
break;
default:
System.out.println("Storage Type Invalid");
break;
}
}
}
catch (Exception e) {
e.printStackTrace();
}
}
// Close and release resources
try {
if (fapl_id >= 0)
H5.H5Pclose(fapl_id);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (gcpl_id >= 0)
H5.H5Pclose(gcpl_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the group
try {
if (group_id >= 0)
H5.H5Gclose(group_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_G_Phase.CreateGroup();
}
}
+167
View File
@@ -0,0 +1,167 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows a way to recursively traverse the file
using H5Literate. The method shown here guarantees that
the recursion will not enter an infinite loop, but does
not prevent objects from being visited more than once.
The program prints the directory structure of the file
specified in FILE. The default file used by this example
implements the structure described in the User's Guide,
chapter 4, figure 26.
************************************************************/
package examples.groups;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
import hdf.hdf5lib.callbacks.H5L_iterate_cb;
import hdf.hdf5lib.callbacks.H5L_iterate_t;
import hdf.hdf5lib.structs.H5L_info_t;
import hdf.hdf5lib.structs.H5O_info_t;
import examples.groups.H5Ex_G_Iterate.H5O_type;
class opdata implements H5L_iterate_t {
int recurs;
opdata prev;
long addr;
}
public class H5Ex_G_Traverse {
private static String FILE = "h5ex_g_traverse.h5";
public static H5L_iterate_cb iter_cb = new H5L_iter_callbackT();
private static void OpenGroup() {
long file_id = -1;
H5O_info_t infobuf;
opdata od = new opdata();
// Open file and initialize the operator data structure.
try {
file_id = H5.H5Fopen(FILE, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
if (file_id >= 0) {
infobuf = H5.H5Oget_info(file_id);
od.recurs = 0;
od.prev = null;
od.addr = infobuf.addr;
}
}
catch (Exception e) {
e.printStackTrace();
}
// Print the root group and formatting, begin iteration.
try {
System.out.println("/ {");
// H5L_iterate_cb iter_cb = new H5L_iter_callbackT();
H5.H5Literate(file_id, HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_NATIVE, 0L, iter_cb, od);
System.out.println("}");
}
catch (Exception e) {
e.printStackTrace();
}
// Close and release resources.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5Ex_G_Traverse.OpenGroup();
}
}
class H5L_iter_callbackT implements H5L_iterate_cb {
public int callback(long group, String name, H5L_info_t info, H5L_iterate_t op_data) {
H5O_info_t infobuf;
int return_val = 0;
opdata od = (opdata) op_data; // Type conversion
int spaces = 2 * (od.recurs + 1); // Number of white spaces to prepend to output.
// Get type of the object and display its name and type.
// The name of the object is passed to this function by the Library.
try {
infobuf = H5.H5Oget_info_by_name(group, name, HDF5Constants.H5P_DEFAULT);
for (int i = 0; i < spaces; i++)
System.out.print(" "); // Format output.
switch (H5O_type.get(infobuf.type)) {
case H5O_TYPE_GROUP:
System.out.println("Group: " + name + " { ");
// Check group address against linked list of operator
// data structures. We will always run the check, as the
// reference count cannot be relied upon if there are
// symbolic links, and H5Oget_info_by_name always follows
// symbolic links. Alternatively we could use H5Lget_info
// and never recurse on groups discovered by symbolic
// links, however it could still fail if an object's
// reference count was manually manipulated with
// H5Odecr_refcount.
if (group_check(od, infobuf.addr)) {
for (int i = 0; i < spaces; i++)
System.out.print(" ");
System.out.println(" Warning: Loop detected!");
}
else {
// Initialize new object of type opdata and begin
// recursive iteration on the discovered
// group. The new opdata is given a pointer to the
// current one.
opdata nextod = new opdata();
nextod.recurs = od.recurs + 1;
nextod.prev = od;
nextod.addr = infobuf.addr;
H5L_iterate_cb iter_cb2 = new H5L_iter_callbackT();
return_val = H5.H5Literate_by_name(group, name, HDF5Constants.H5_INDEX_NAME,
HDF5Constants.H5_ITER_NATIVE, 0L, iter_cb2, nextod, HDF5Constants.H5P_DEFAULT);
}
for (int i = 0; i < spaces; i++)
System.out.print(" ");
System.out.println("}");
break;
case H5O_TYPE_DATASET:
System.out.println("Dataset: " + name);
break;
case H5O_TYPE_NAMED_DATATYPE:
System.out.println("Datatype: " + name);
break;
default:
System.out.println("Unknown: " + name);
}
}
catch (Exception e) {
e.printStackTrace();
}
return return_val;
}
public boolean group_check(opdata od, long target_addr) {
if (od.addr == target_addr)
return true; // Addresses match
else if (od.recurs == 0)
return false; // Root group reached with no matches
else
return group_check(od.prev, target_addr); // Recursively examine the next node
}
}
+152
View File
@@ -0,0 +1,152 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
This example shows how to recursively traverse a file
using H5Ovisit and H5Lvisit. The program prints all of
the objects in the file specified in FILE, then prints all
of the links in that file. The default file used by this
example implements the structure described in the User's
Guide, chapter 4, figure 26.
************************************************************/
package examples.groups;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
import hdf.hdf5lib.callbacks.H5L_iterate_cb;
import hdf.hdf5lib.callbacks.H5L_iterate_t;
import hdf.hdf5lib.callbacks.H5O_iterate_cb;
import hdf.hdf5lib.callbacks.H5O_iterate_t;
import hdf.hdf5lib.structs.H5L_info_t;
import hdf.hdf5lib.structs.H5O_info_t;
import java.util.ArrayList;
public class H5Ex_G_Visit {
private static String FILE = "groups/h5ex_g_visit.h5";
public static void main(String[] args) {
try {
(new H5Ex_G_Visit()).VisitGroup();
}
catch (Exception ex) {
ex.printStackTrace();
}
}
private void VisitGroup() throws Exception {
long file_id = -1;
try {
// Open file
file_id = H5.H5Fopen(FILE, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
// Begin iteration using H5Ovisit
System.out.println("Objects in the file:");
H5O_iterate_t iter_data = new H5O_iter_data();
H5O_iterate_cb iter_cb = new H5O_iter_callback();
H5.H5Ovisit(file_id, HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_NATIVE, iter_cb, iter_data);
System.out.println();
// Repeat the same process using H5Lvisit
H5L_iterate_t iter_data2 = new H5L_iter_data();
H5L_iterate_cb iter_cb2 = new H5L_iter_callback();
System.out.println("Links in the file:");
H5.H5Lvisit(file_id, HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_NATIVE, iter_cb2, iter_data2);
}
catch (Exception e) {
e.printStackTrace();
}
finally {
// Close and release resources.
if (file_id >= 0)
H5.H5Fclose(file_id);
}
}
/************************************************************
* Operator function for H5Lvisit. This function simply retrieves the info for the object the current link points
* to, and calls the operator function for H5Ovisit.
************************************************************/
private class idata {
public String link_name = null;
public int link_type = -1;
idata(String name, int type) {
this.link_name = name;
this.link_type = type;
}
}
private class H5L_iter_data implements H5L_iterate_t {
public ArrayList<idata> iterdata = new ArrayList<idata>();
}
private class H5L_iter_callback implements H5L_iterate_cb {
public int callback(long group, String name, H5L_info_t info, H5L_iterate_t op_data) {
idata id = new idata(name, info.type);
((H5L_iter_data) op_data).iterdata.add(id);
H5O_info_t infobuf;
int ret = 0;
try {
// Get type of the object and display its name and type. The name of the object is passed to this
// function by the Library.
infobuf = H5.H5Oget_info_by_name(group, name, HDF5Constants.H5P_DEFAULT);
H5O_iterate_cb iter_cbO = new H5O_iter_callback();
H5O_iterate_t iter_dataO = new H5O_iter_data();
ret = iter_cbO.callback(group, name, infobuf, iter_dataO);
}
catch (Exception e) {
e.printStackTrace();
}
return ret;
}
}
private class H5O_iter_data implements H5O_iterate_t {
public ArrayList<idata> iterdata = new ArrayList<idata>();
}
private class H5O_iter_callback implements H5O_iterate_cb {
public int callback(long group, String name, H5O_info_t info, H5O_iterate_t op_data) {
idata id = new idata(name, info.type);
((H5O_iter_data) op_data).iterdata.add(id);
System.out.print("/"); /* Print root group in object path */
// Check if the current object is the root group, and if not print the full path name and type.
if (name.charAt(0) == '.') /* Root group, do not print '.' */
System.out.println(" (Group)");
else if (info.type == HDF5Constants.H5O_TYPE_GROUP)
System.out.println(name + " (Group)");
else if (info.type == HDF5Constants.H5O_TYPE_DATASET)
System.out.println(name + " (Dataset)");
else if (info.type == HDF5Constants.H5O_TYPE_NAMED_DATATYPE)
System.out.println(name + " (Datatype)");
else
System.out.println(name + " (Unknown)");
return 0;
}
}
}
+68
View File
@@ -0,0 +1,68 @@
#
# Copyright by The HDF Group.
# Copyright by the Board of Trustees of the University of Illinois.
# All rights reserved.
#
# This file is part of HDF5. The full HDF5 copyright notice, including
# terms governing use, modification, and redistribution, is contained in
# the files COPYING and Copyright.html. COPYING can be found at the root
# of the source code distribution tree; Copyright.html can be found at the
# root level of an installed copy of the electronic HDF5 document set and
# is linked from the top-level documents page. It can also be found at
# http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have
# access to either file, you may request a copy from help@hdfgroup.org.
##
## Makefile.am
## Run automake to generate a Makefile.in from this file.
##
#
# HDF5 Java Library Examples Makefile(.in)
include $(top_srcdir)/config/commence.am
# Mark this directory as part of the JNI API
JAVA_API=yes
JAVAROOT = .classes
classes:
$(MKDIR_P) $(@D)/$(JAVAROOT)
pkgpath = examples/groups
hdfjarfile = jar$(PACKAGE_TARNAME)-$(PACKAGE_VERSION).jar
CLASSPATH_ENV=CLASSPATH=.:$(JAVAROOT):$(top_builddir)/java/src/$(hdfjarfile):$(top_srcdir)/java/lib/slf4j-api-1.7.5.jar:$(top_srcdir)/java/lib/ext/slf4j-simple-1.7.5.jar:$$CLASSPATH
jarfile = jar$(PACKAGE_TARNAME)groups.jar
AM_JAVACFLAGS = $(H5_JAVACFLAGS) -deprecation
TESTPACKAGE =
noinst_JAVA = \
H5Ex_G_Create.java \
H5Ex_G_Iterate.java \
H5Ex_G_Compact.java \
H5Ex_G_Corder.java \
H5Ex_G_Intermediate.java \
H5Ex_G_Phase.java \
H5Ex_G_Visit.java
$(jarfile): classnoinst.stamp classes
$(JAR) cvf $@ -C $(JAVAROOT)/ $(pkgpath)
noinst_DATA = $(jarfile)
.PHONY: classes
check_SCRIPTS = runExample.sh
TEST_SCRIPT = $(check_SCRIPTS)
CLEANFILES = classnoinst.stamp $(jarfile) $(JAVAROOT)/$(pkgpath)/*.class runExample.sh
clean:
rm -rf $(JAVAROOT)
rm -f $(jarfile)
rm -f classnoinst.stamp
include $(top_srcdir)/config/conclude.am
Binary file not shown.
Binary file not shown.
+349
View File
@@ -0,0 +1,349 @@
#! /bin/sh
#
# Copyright by The HDF Group.
# Copyright by the Board of Trustees of the University of Illinois.
# All rights reserved.
#
# This file is part of HDF5. The full HDF5 copyright notice, including
# terms governing use, modification, and redistribution, is contained in
# the files COPYING and Copyright.html. COPYING can be found at the root
# of the source code distribution tree; Copyright.html can be found at the
# root level of an installed copy of the electronic HDF5 document set and
# is linked from the top-level documents page. It can also be found at
# http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have
# access to either file, you may request a copy from help@hdfgroup.org.
#
top_builddir=@top_builddir@
top_srcdir=@top_srcdir@
srcdir=@srcdir@
TESTNAME=EX_Groups
EXIT_SUCCESS=0
EXIT_FAILURE=1
# Set up default variable values if not supplied by the user.
RM='rm -rf'
CMP='cmp'
DIFF='diff -c'
CP='cp'
DIRNAME='dirname'
LS='ls'
AWK='awk'
nerrors=0
# where the libs exist
HDFLIB_HOME="$top_srcdir/java/lib"
BLDLIBDIR="./lib"
BLDREFDIR="./groups"
BLDDIR="."
HDFTEST_HOME="$top_srcdir/java/examples/groups"
JARFILE=jar@PACKAGE_TARNAME@-@PACKAGE_VERSION@.jar
TESTJARFILE=jar@PACKAGE_TARNAME@groups.jar
test -d $BLDLIBDIR || mkdir -p $BLDLIBDIR
test -d $BLDREFDIR || mkdir -p $BLDREFDIR
######################################################################
# library files
# --------------------------------------------------------------------
# All the library files copy from source directory to test directory
# NOTE: Keep this framework to add/remove test files.
# This list are also used for checking exist.
# Comment '#' without space can be used.
# --------------------------------------------------------------------
LIST_LIBRARY_FILES="
$HDFLIB_HOME/slf4j-api-1.7.5.jar
$HDFLIB_HOME/ext/slf4j-simple-1.7.5.jar
$top_builddir/src/.libs/libhdf5.*
$top_builddir/java/src/jni/.libs/libhdf5_java.*
$top_builddir/java/src/$JARFILE
"
LIST_REF_FILES="
$HDFTEST_HOME/h5ex_g_iterate.h5
$HDFTEST_HOME/h5ex_g_visit.h5
"
LIST_DATA_FILES="
$HDFTEST_HOME/../testfiles/examples.groups.H5Ex_G_Create.txt
$HDFTEST_HOME/../testfiles/examples.groups.H5Ex_G_Iterate.txt
$HDFTEST_HOME/../testfiles/examples.groups.H5Ex_G_Compact.txt
$HDFTEST_HOME/../testfiles/examples.groups.H5Ex_G_Corder.txt
$HDFTEST_HOME/../testfiles/examples.groups.H5Ex_G_Intermediate.txt
$HDFTEST_HOME/../testfiles/examples.groups.H5Ex_G_Phase.txt
$HDFTEST_HOME/../testfiles/examples.groups.H5Ex_G_Visit.txt
"
#
# copy files from source dirs to test dir
#
COPY_LIBFILES="$LIST_LIBRARY_FILES"
COPY_LIBFILES_TO_BLDLIBDIR()
{
# copy test files. Used -f to make sure get a new copy
for tstfile in $COPY_LIBFILES
do
# ignore '#' comment
echo $tstfile | tr -d ' ' | grep '^#' > /dev/null
RET=$?
if [ $RET -eq 1 ]; then
# skip cp if srcdir is same as destdir
# this occurs when build/test performed in source dir and
# make cp fail
SDIR=`$DIRNAME $tstfile`
INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'`
INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'`
if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then
$CP -f $tstfile $BLDLIBDIR
if [ $? -ne 0 ]; then
echo "Error: FAILED to copy $tstfile ."
# Comment out this to CREATE expected file
exit $EXIT_FAILURE
fi
fi
fi
done
}
CLEAN_LIBFILES_AND_BLDLIBDIR()
{
# skip rm if srcdir is same as destdir
# this occurs when build/test performed in source dir and
# make cp fail
SDIR=`$DIRNAME $tstfile`
INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'`
INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'`
if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then
$RM $BLDLIBDIR
fi
}
COPY_DATAFILES="$LIST_DATA_FILES"
COPY_DATAFILES_TO_BLDDIR()
{
# copy test files. Used -f to make sure get a new copy
for tstfile in $COPY_DATAFILES
do
# ignore '#' comment
echo $tstfile | tr -d ' ' | grep '^#' > /dev/null
RET=$?
if [ $RET -eq 1 ]; then
# skip cp if srcdir is same as destdir
# this occurs when build/test performed in source dir and
# make cp fail
SDIR=`$DIRNAME $tstfile`
INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'`
INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'`
if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then
$CP -f $tstfile $BLDDIR
if [ $? -ne 0 ]; then
echo "Error: FAILED to copy $tstfile ."
# Comment out this to CREATE expected file
exit $EXIT_FAILURE
fi
fi
fi
done
}
CLEAN_DATAFILES_AND_BLDDIR()
{
# skip rm if srcdir is same as destdir
# this occurs when build/test performed in source dir and
# make cp fail
SDIR=`$DIRNAME $tstfile`
INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'`
INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'`
if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then
$RM $BLDDIR/*.txt
$RM $BLDDIR/*.out
fi
}
COPY_REFFILES="$LIST_REF_FILES"
COPY_REFFILES_TO_BLDREFDIR()
{
# copy test files. Used -f to make sure get a new copy
for tstfile in $COPY_REFFILES
do
# ignore '#' comment
echo $tstfile | tr -d ' ' | grep '^#' > /dev/null
RET=$?
if [ $RET -eq 1 ]; then
# skip cp if srcdir is same as destdir
# this occurs when build/test performed in source dir and
# make cp fail
SDIR=`$DIRNAME $tstfile`
INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'`
INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'`
if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then
$CP -f $tstfile $BLDREFDIR
if [ $? -ne 0 ]; then
echo "Error: FAILED to copy $tstfile ."
# Comment out this to CREATE expected file
exit $EXIT_FAILURE
fi
fi
fi
done
}
CLEAN_REFFILES_AND_BLDREFDIR()
{
# skip rm if srcdir is same as destdir
# this occurs when build/test performed in source dir and
# make cp fail
SDIR=`$DIRNAME $tstfile`
INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'`
INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'`
if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then
$RM $BLDREFDIR
fi
}
# Print a line-line message left justified in a field of 70 characters
# beginning with the word "Testing".
#
TESTING() {
SPACES=" "
echo "Testing $* $SPACES" | cut -c1-70 | tr -d '\012'
}
# where Java is installed (requires jdk1.7.x)
JAVAEXE=@JAVA@
JAVAEXEFLAGS=@H5_JAVAFLAGS@
###############################################################################
# DO NOT MODIFY BELOW THIS LINE
###############################################################################
# prepare for test
COPY_LIBFILES_TO_BLDLIBDIR
COPY_DATAFILES_TO_BLDDIR
COPY_REFFILES_TO_BLDREFDIR
CPATH=".:"$BLDLIBDIR"/"$JARFILE":"$BLDLIBDIR"/slf4j-api-1.7.5.jar:"$BLDLIBDIR"/slf4j-simple-1.7.5.jar:"$TESTJARFILE""
TEST=/usr/bin/test
if [ ! -x /usr/bin/test ]
then
TEST=`which test`
fi
if $TEST -z "$CLASSPATH"; then
CLASSPATH=""
fi
CLASSPATH=$CPATH":"$CLASSPATH
export CLASSPATH
if $TEST -n "$JAVAPATH" ; then
PATH=$JAVAPATH":"$PATH
export PATH
fi
if $TEST -e /bin/uname; then
os_name=`/bin/uname -s`
elif $TEST -e /usr/bin/uname; then
os_name=`/usr/bin/uname -s`
else
os_name=unknown
fi
if $TEST -z "$LD_LIBRARY_PATH" ; then
LD_LIBRARY_PATH=""
fi
case $os_name in
Darwin)
DYLD_LIBRARY_PATH=$BLDLIBDIR:$DYLD_LIBRARY_PATH
export DYLD_LIBRARY_PATH
LD_LIBRARY_PATH=$DYLD_LIBRARY_PATH
;;
*)
LD_LIBRARY_PATH=$BLDLIBDIR:$LD_LIBRARY_PATH
;;
esac
export LD_LIBRARY_PATH
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.groups.H5Ex_G_Create"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.groups.H5Ex_G_Create > H5Ex_G_Create.out)
if diff H5Ex_G_Create.out examples.groups.H5Ex_G_Create.txt > /dev/null; then
echo " PASSED groups.H5Ex_G_Create"
else
echo "**FAILED** groups.H5Ex_G_Create"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.groups.H5Ex_G_Iterate"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.groups.H5Ex_G_Iterate > H5Ex_G_Iterate.out)
if diff H5Ex_G_Iterate.out examples.groups.H5Ex_G_Iterate.txt > /dev/null; then
echo " PASSED groups.H5Ex_G_Iterate"
else
echo "**FAILED** groups.H5Ex_G_Iterate"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.groups.H5Ex_G_Compact"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.groups.H5Ex_G_Compact > H5Ex_G_Compact.out)
if diff H5Ex_G_Compact.out examples.groups.H5Ex_G_Compact.txt > /dev/null; then
echo " PASSED groups.H5Ex_G_Compact"
else
echo "**FAILED** groups.H5Ex_G_Compact"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.groups.H5Ex_G_Corder"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.groups.H5Ex_G_Corder > H5Ex_G_Corder.out)
if diff H5Ex_G_Corder.out examples.groups.H5Ex_G_Corder.txt > /dev/null; then
echo " PASSED groups.H5Ex_G_Corder"
else
echo "**FAILED** groups.H5Ex_G_Corder"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.groups.H5Ex_G_Intermediate"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.groups.H5Ex_G_Intermediate > H5Ex_G_Intermediate.out)
if diff H5Ex_G_Intermediate.out examples.groups.H5Ex_G_Intermediate.txt > /dev/null; then
echo " PASSED groups.H5Ex_G_Intermediate"
else
echo "**FAILED** groups.H5Ex_G_Intermediate"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.groups.H5Ex_G_Phase"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.groups.H5Ex_G_Phase > H5Ex_G_Phase.out)
if diff H5Ex_G_Phase.out examples.groups.H5Ex_G_Phase.txt > /dev/null; then
echo " PASSED groups.H5Ex_G_Phase"
else
echo "**FAILED** groups.H5Ex_G_Phase"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.groups.H5Ex_G_Visit"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.groups.H5Ex_G_Visit > H5Ex_G_Visit.out)
if diff H5Ex_G_Visit.out examples.groups.H5Ex_G_Visit.txt > /dev/null; then
echo " PASSED groups.H5Ex_G_Visit"
else
echo "**FAILED** groups.H5Ex_G_Visit"
nerrors="`expr $nerrors + 1`"
fi
# Clean up temporary files/directories
CLEAN_LIBFILES_AND_BLDLIBDIR
CLEAN_DATAFILES_AND_BLDDIR
CLEAN_REFFILES_AND_BLDREFDIR
# Report test results and exit
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
+112
View File
@@ -0,0 +1,112 @@
cmake_minimum_required (VERSION 3.1.0)
PROJECT (HDFJAVA_EXAMPLES_INTRO Java)
set (CMAKE_VERBOSE_MAKEFILE 1)
INCLUDE_DIRECTORIES (
${HDF5_JAVA_JNI_BINARY_DIR}
${HDF5_JAVA_HDF5_LIB_DIR}
)
set (HDF_JAVA_EXAMPLES
H5_CreateAttribute
H5_CreateDataset
H5_CreateFile
H5_CreateGroup
H5_CreateGroupAbsoluteRelative
H5_CreateGroupDataset
H5_ReadWrite
)
if (WIN32)
set (CMAKE_JAVA_INCLUDE_FLAG_SEP ";")
else (WIN32)
set (CMAKE_JAVA_INCLUDE_FLAG_SEP ":")
endif (WIN32)
set (CMAKE_JAVA_INCLUDE_PATH "${HDF5_JAVA_JARS}")
set (CMAKE_JAVA_CLASSPATH ".")
foreach (CMAKE_INCLUDE_PATH ${CMAKE_JAVA_INCLUDE_PATH})
set (CMAKE_JAVA_CLASSPATH "${CMAKE_JAVA_CLASSPATH}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${CMAKE_INCLUDE_PATH}")
endforeach (CMAKE_INCLUDE_PATH)
foreach (example ${HDF_JAVA_EXAMPLES})
file (WRITE ${PROJECT_BINARY_DIR}/${example}_Manifest.txt
"Main-Class: examples.intro.${example}
"
)
add_jar (${example} MANIFEST ${PROJECT_BINARY_DIR}/${example}_Manifest.txt ${example}.java)
get_target_property (${example}_JAR_FILE ${example} JAR_FILE)
# install_jar (${example} ${HJAVA_INSTALL_DATA_DIR}/examples examples)
get_target_property (${example}_CLASSPATH ${example} CLASSDIR)
add_dependencies (${example} ${HDF5_JAVA_HDF5_LIB_TARGET})
endforeach (example ${HDF_JAVA_EXAMPLES})
set (CMAKE_JAVA_INCLUDE_PATH "${HDF5_JAVA_JARS};${HDF5_JAVA_LOGGING_JAR};${HDF5_JAVA_LOGGING_NOP_JAR}")
set (CMAKE_JAVA_CLASSPATH ".")
foreach (HDFJAVA_JAR ${CMAKE_JAVA_INCLUDE_PATH})
set (CMAKE_JAVA_CLASSPATH "${CMAKE_JAVA_CLASSPATH}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${HDFJAVA_JAR}")
endforeach (HDFJAVA_JAR)
foreach (example ${HDF_JAVA_OBJECT_EXAMPLES})
file (WRITE ${PROJECT_BINARY_DIR}/${example}_Manifest.txt
"Main-Class: examples.intro.${example}
"
)
add_jar (${example} MANIFEST ${PROJECT_BINARY_DIR}/${example}_Manifest.txt ${example}.java)
get_target_property (${example}_JAR_FILE ${example} JAR_FILE)
# install_jar (${example} ${HJAVA_INSTALL_DATA_DIR}/examples examples)
get_target_property (${example}_CLASSPATH ${example} CLASSDIR)
add_dependencies (${example} ${HDFJAVA_H5_LIB_TARGET})
endforeach (example ${HDF_JAVA_OBJECT_EXAMPLES})
MACRO (ADD_H5_TEST resultfile resultcode)
add_test (
NAME JAVA_intro-${resultfile}
COMMAND "${CMAKE_COMMAND}"
-D "TEST_TESTER=${CMAKE_Java_RUNTIME};${CMAKE_Java_RUNTIME_FLAGS}"
-D "TEST_PROGRAM=examples.intro.${resultfile}"
-D "TEST_ARGS:STRING=${ARGN}"
-D "TEST_CLASSPATH:STRING=${CMAKE_JAVA_CLASSPATH}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${${resultfile}_JAR_FILE}"
-D "TEST_LIBRARY_DIRECTORY=${CMAKE_TEST_OUTPUT_DIRECTORY}"
-D "TEST_FOLDER=${HDFJAVA_EXAMPLES_BINARY_DIR}"
-D "TEST_OUTPUT=intro/${resultfile}.out"
-D "TEST_EXPECT=${resultcode}"
-D "TEST_REFERENCE=intro/${resultfile}.txt"
-P "${HDF_RESOURCES_DIR}/jrunTest.cmake"
)
if (NOT "${last_test}" STREQUAL "")
set_tests_properties (JAVA_intro-${resultfile} PROPERTIES DEPENDS ${last_test})
endif (NOT "${last_test}" STREQUAL "")
set (last_test "JAVA_intro-${resultfile}")
ENDMACRO (ADD_H5_TEST file)
if (BUILD_TESTING)
foreach (example ${HDF_JAVA_EXAMPLES})
add_test (
NAME JAVA_intro-${example}-clearall-objects
COMMAND ${CMAKE_COMMAND}
-E remove
${HDFJAVA_EXAMPLES_BINARY_DIR}/${example}.h5
${example}.out
${example}.out.err
)
if (NOT "${last_test}" STREQUAL "")
set_tests_properties (JAVA_intro-${example}-clearall-objects PROPERTIES DEPENDS ${last_test})
endif (NOT "${last_test}" STREQUAL "")
add_test (
NAME JAVA_intro-${example}-copy-objects
COMMAND ${CMAKE_COMMAND}
-E copy_if_different
${HDFJAVA_EXAMPLES_SOURCE_DIR}/testfiles/examples.intro.${example}.txt
${HDFJAVA_EXAMPLES_INTRO_BINARY_DIR}/${example}.txt
)
set_tests_properties (JAVA_intro-${example}-copy-objects PROPERTIES DEPENDS JAVA_intro-${example}-clearall-objects)
set (last_test "JAVA_intro-${example}-copy-objects")
ADD_H5_TEST (${example} 0)
endforeach (example ${HDF_JAVA_EXAMPLES})
endif (BUILD_TESTING)
+145
View File
@@ -0,0 +1,145 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
Creating a dataset attribute.
************************************************************/
package examples.intro;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5_CreateAttribute {
private static String FILENAME = "H5_CreateAttribute.h5";
private static String DATASETNAME = "dset";
private static final int DIM_X = 4;
private static final int DIM_Y = 6;
private static String DATASETATTRIBUTE = "Units";
private static void CreateDatasetAttribute() {
long file_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long attribute_id = -1;
long[] dims1 = { DIM_X, DIM_Y };
long[] dims = { 2 };
int[] attr_data = { 100, 200 };
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the data space for the dataset.
try {
dataspace_id = H5.H5Screate_simple(2, dims1, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset.
try {
if ((file_id >= 0) && (dataspace_id >= 0))
dataset_id = H5.H5Dcreate(file_id, "/" + DATASETNAME, HDF5Constants.H5T_STD_I32BE, dataspace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the data space for the attribute.
try {
dataspace_id = H5.H5Screate_simple(1, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create a dataset attribute.
try {
if ((dataset_id >= 0) && (dataspace_id >= 0))
attribute_id = H5.H5Acreate(dataset_id, DATASETATTRIBUTE, HDF5Constants.H5T_STD_I32BE, dataspace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the attribute data.
try {
if (attribute_id >= 0)
H5.H5Awrite(attribute_id, HDF5Constants.H5T_NATIVE_INT, attr_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the attribute.
try {
if (attribute_id >= 0)
H5.H5Aclose(attribute_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the dataspace.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close to the dataset.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5_CreateAttribute.CreateDatasetAttribute();
}
}
+97
View File
@@ -0,0 +1,97 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
Creating and closing a dataset.
************************************************************/
package examples.intro;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5_CreateDataset {
private static String FILENAME = "H5_CreateDataset.h5";
private static String DATASETNAME = "dset";
private static final int DIM_X = 4;
private static final int DIM_Y = 6;
private static void CreateDataset() {
long file_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long[] dims = { DIM_X, DIM_Y };
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the data space for the dataset.
try {
dataspace_id = H5.H5Screate_simple(2, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset.
try {
if ((file_id >= 0) && (dataspace_id >= 0))
dataset_id = H5.H5Dcreate(file_id, "/" + DATASETNAME, HDF5Constants.H5T_STD_I32BE, dataspace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// End access to the dataset and release resources used by it.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Terminate access to the data space.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5_CreateDataset.CreateDataset();
}
}
+55
View File
@@ -0,0 +1,55 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
Creating and closing a file.
************************************************************/
package examples.intro;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5_CreateFile {
static final String FILENAME = "H5_CreateFile.h5";
private static void CreateFile() {
long file_id = -1;
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5_CreateFile.CreateFile();
}
}
+76
View File
@@ -0,0 +1,76 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
Creating and closing a group.
************************************************************/
package examples.intro;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5_CreateGroup {
private static String FILENAME = "H5_CreateGroup.h5";
private static String GROUPNAME = "MyGroup";
private static void CreateGroup() {
long file_id = -1;
long group_id = -1;
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create a group in the file.
try {
if (file_id >= 0)
group_id = H5.H5Gcreate(file_id, "/" + GROUPNAME, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the group.
try {
if (group_id >= 0)
H5.H5Gclose(group_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5_CreateGroup.CreateGroup();
}
}
@@ -0,0 +1,118 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
Creating groups using absolute and relative names.
************************************************************/
package examples.intro;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5_CreateGroupAbsoluteRelative {
private static String FILENAME = "H5_CreateGroupAbsoluteRelative.h5";
private static String GROUPNAME = "MyGroup";
private static String GROUPNAME_A = "GroupA";
private static String GROUPNAME_B = "GroupB";
private static void CreateGroupAbsoluteAndRelative() {
long file_id = -1;
long group1_id = -1;
long group2_id = -1;
long group3_id = -1;
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create a group named "/MyGroup" in the file.
try {
if (file_id >= 0)
group1_id = H5.H5Gcreate(file_id, "/" + GROUPNAME, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create group "Group_A" in group "MyGroup" using absolute name.
try {
if (file_id >= 0)
group2_id = H5.H5Gcreate(file_id, "/" + GROUPNAME + "/" + GROUPNAME_A, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create group "Group_B" in group "MyGroup" using relative name.
try {
if (group1_id >= 0)
group3_id = H5.H5Gcreate(group1_id, GROUPNAME_B, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the group3.
try {
if (group3_id >= 0)
H5.H5Gclose(group3_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the group2.
try {
if (group2_id >= 0)
H5.H5Gclose(group2_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the group1.
try {
if (group1_id >= 0)
H5.H5Gclose(group1_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5_CreateGroupAbsoluteRelative.CreateGroupAbsoluteAndRelative();
}
}
@@ -0,0 +1,207 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
Create two datasets within groups.
************************************************************/
package examples.intro;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5_CreateGroupDataset {
private static String FILENAME = "H5_CreateGroupDataset.h5";
private static String GROUPNAME = "MyGroup";
private static String GROUPNAME_A = "GroupA";
private static String DATASETNAME1 = "dset1";
private static String DATASETNAME2 = "dset2";
private static final int DIM1_X = 3;
private static final int DIM1_Y = 3;
private static final int DIM2_X = 2;
private static final int DIM2_Y = 10;
private static void h5_crtgrpd() {
long file_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long group_id = -1;
long group1_id = -1;
long group2_id = -1;
int[][] dset1_data = new int[DIM1_X][DIM1_Y];
int[][] dset2_data = new int[DIM2_X][DIM2_Y];
long[] dims1 = { DIM1_X, DIM1_Y };
long[] dims2 = { DIM2_X, DIM2_Y };
// Initialize the first dataset.
for (int indx = 0; indx < DIM1_X; indx++)
for (int jndx = 0; jndx < DIM1_Y; jndx++)
dset1_data[indx][jndx] = jndx + 1;
// Initialize the second dataset.
for (int indx = 0; indx < DIM2_X; indx++)
for (int jndx = 0; jndx < DIM2_Y; jndx++)
dset2_data[indx][jndx] = jndx + 1;
// Create a file.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
// Create a group named "/MyGroup" in the file.
if (file_id >= 0) {
group1_id = H5.H5Gcreate(file_id, "/" + GROUPNAME, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
// Create group "Group_A" in group "MyGroup" using absolute name.
if (group1_id >= 0) {
group2_id = H5.H5Gcreate(file_id, "/" + GROUPNAME + "/" + GROUPNAME_A, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
if (group2_id >= 0)
H5.H5Gclose(group2_id);
}
if (group1_id >= 0)
H5.H5Gclose(group1_id);
}
}
catch (Exception e) {
e.printStackTrace();
}
// Create the data space for the first dataset.
try {
dataspace_id = H5.H5Screate_simple(2, dims1, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset in group "MyGroup".
try {
if ((file_id >= 0) && (dataspace_id >= 0))
dataset_id = H5.H5Dcreate(file_id, "/" + GROUPNAME + "/" + DATASETNAME1, HDF5Constants.H5T_STD_I32BE,
dataspace_id, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the first dataset.
try {
if (dataset_id >= 0)
H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset1_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the data space for the first dataset.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
dataspace_id = -1;
}
catch (Exception e) {
e.printStackTrace();
}
// Close the first dataset.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
dataset_id = -1;
}
catch (Exception e) {
e.printStackTrace();
}
// Open an existing group of the specified file.
try {
if (file_id >= 0)
group_id = H5.H5Gopen(file_id, "/" + GROUPNAME + "/" + GROUPNAME_A, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the data space for the second dataset.
try {
dataspace_id = H5.H5Screate_simple(2, dims2, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the second dataset in group "Group_A".
try {
if ((group_id >= 0) && (dataspace_id >= 0))
dataset_id = H5.H5Dcreate(group_id, DATASETNAME2, HDF5Constants.H5T_STD_I32BE, dataspace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the second dataset.
try {
if (dataset_id >= 0)
H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset2_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the data space for the second dataset.
try {
if (dataspace_id >= 0)
H5.H5Sclose(dataspace_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the second dataset.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the group.
try {
if (group_id >= 0)
H5.H5Gclose(group_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5_CreateGroupDataset.h5_crtgrpd();
}
}
+112
View File
@@ -0,0 +1,112 @@
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* Copyright by the Board of Trustees of the University of Illinois. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/************************************************************
Writing and reading an existing dataset.
************************************************************/
package examples.intro;
import hdf.hdf5lib.H5;
import hdf.hdf5lib.HDF5Constants;
public class H5_ReadWrite {
private static String FILENAME = "H5_ReadWrite.h5";
private static String DATASETNAME = "dset";
private static final int DIM_X = 4;
private static final int DIM_Y = 6;
private static void ReadWriteDataset() {
long file_id = -1;
long dataspace_id = -1;
long dataset_id = -1;
long[] dims = { DIM_X, DIM_Y };
int[][] dset_data = new int[DIM_X][DIM_Y];
// Initialize the dataset.
for (int indx = 0; indx < DIM_X; indx++)
for (int jndx = 0; jndx < DIM_Y; jndx++)
dset_data[indx][jndx] = indx * 6 + jndx + 1;
// Create a new file using default properties.
try {
file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the data space for the dataset.
try {
dataspace_id = H5.H5Screate_simple(2, dims, null);
}
catch (Exception e) {
e.printStackTrace();
}
// Create the dataset.
try {
if ((file_id >= 0) && (dataspace_id >= 0))
dataset_id = H5.H5Dcreate(file_id, "/" + DATASETNAME, HDF5Constants.H5T_STD_I32BE, dataspace_id,
HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
}
catch (Exception e) {
e.printStackTrace();
}
// Write the dataset.
try {
if (dataset_id >= 0)
H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
try {
if (dataset_id >= 0)
H5.H5Dread(dataset_id, HDF5Constants.H5T_NATIVE_INT, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL,
HDF5Constants.H5P_DEFAULT, dset_data);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the dataset.
try {
if (dataset_id >= 0)
H5.H5Dclose(dataset_id);
}
catch (Exception e) {
e.printStackTrace();
}
// Close the file.
try {
if (file_id >= 0)
H5.H5Fclose(file_id);
}
catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
H5_ReadWrite.ReadWriteDataset();
}
}
+67
View File
@@ -0,0 +1,67 @@
#
# Copyright by The HDF Group.
# Copyright by the Board of Trustees of the University of Illinois.
# All rights reserved.
#
# This file is part of HDF5. The full HDF5 copyright notice, including
# terms governing use, modification, and redistribution, is contained in
# the files COPYING and Copyright.html. COPYING can be found at the root
# of the source code distribution tree; Copyright.html can be found at the
# root level of an installed copy of the electronic HDF5 document set and
# is linked from the top-level documents page. It can also be found at
# http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have
# access to either file, you may request a copy from help@hdfgroup.org.
##
## Makefile.am
## Run automake to generate a Makefile.in from this file.
##
#
# HDF5 Java Library Examples Makefile(.in)
include $(top_srcdir)/config/commence.am
# Mark this directory as part of the JNI API
JAVA_API=yes
JAVAROOT = .classes
classes:
$(MKDIR_P) $(@D)/$(JAVAROOT)
pkgpath = examples/intro
hdfjarfile = jar$(PACKAGE_TARNAME)-$(PACKAGE_VERSION).jar
CLASSPATH_ENV=CLASSPATH=.:$(JAVAROOT):$(top_builddir)/java/src/$(hdfjarfile):$(top_srcdir)/java/lib/slf4j-api-1.7.5.jar:$(top_srcdir)/java/lib/ext/slf4j-simple-1.7.5.jar:$$CLASSPATH
jarfile = jar$(PACKAGE_TARNAME)intro.jar
AM_JAVACFLAGS = $(H5_JAVACFLAGS) -deprecation
TESTPACKAGE =
noinst_JAVA = \
H5_CreateAttribute.java \
H5_CreateDataset.java \
H5_CreateFile.java \
H5_CreateGroup.java \
H5_CreateGroupAbsoluteRelative.java \
H5_CreateGroupDataset.java \
H5_ReadWrite.java
$(jarfile): classnoinst.stamp classes
$(JAR) cvf $@ -C $(JAVAROOT)/ $(pkgpath)
noinst_DATA = $(jarfile)
.PHONY: classes
check_SCRIPTS = runExample.sh
TEST_SCRIPT = $(check_SCRIPTS)
CLEANFILES = classnoinst.stamp $(jarfile) $(JAVAROOT)/$(pkgpath)/*.class runExample.sh
clean:
rm -rf $(JAVAROOT)
rm -f $(jarfile)
rm -f classnoinst.stamp
include $(top_srcdir)/config/conclude.am
+298
View File
@@ -0,0 +1,298 @@
#! /bin/sh
#
# Copyright by The HDF Group.
# Copyright by the Board of Trustees of the University of Illinois.
# All rights reserved.
#
# This file is part of HDF5. The full HDF5 copyright notice, including
# terms governing use, modification, and redistribution, is contained in
# the files COPYING and Copyright.html. COPYING can be found at the root
# of the source code distribution tree; Copyright.html can be found at the
# root level of an installed copy of the electronic HDF5 document set and
# is linked from the top-level documents page. It can also be found at
# http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have
# access to either file, you may request a copy from help@hdfgroup.org.
#
top_builddir=@top_builddir@
top_srcdir=@top_srcdir@
srcdir=@srcdir@
TESTNAME=EX_Intro
EXIT_SUCCESS=0
EXIT_FAILURE=1
# Set up default variable values if not supplied by the user.
RM='rm -rf'
CMP='cmp'
DIFF='diff -c'
CP='cp'
DIRNAME='dirname'
LS='ls'
AWK='awk'
nerrors=0
# where the libs exist
HDFLIB_HOME="$top_srcdir/java/lib"
BLDLIBDIR="./lib"
BLDDIR="."
HDFTEST_HOME="$top_srcdir/java/examples/intro"
JARFILE=jar@PACKAGE_TARNAME@-@PACKAGE_VERSION@.jar
TESTJARFILE=jar@PACKAGE_TARNAME@intro.jar
test -d $BLDLIBDIR || mkdir -p $BLDLIBDIR
######################################################################
# library files
# --------------------------------------------------------------------
# All the library files copy from source directory to test directory
# NOTE: Keep this framework to add/remove test files.
# This list are also used for checking exist.
# Comment '#' without space can be used.
# --------------------------------------------------------------------
LIST_LIBRARY_FILES="
$HDFLIB_HOME/slf4j-api-1.7.5.jar
$HDFLIB_HOME/ext/slf4j-simple-1.7.5.jar
$top_builddir/src/.libs/libhdf5.*
$top_builddir/java/src/jni/.libs/libhdf5_java.*
$top_builddir/java/src/$JARFILE
"
LIST_DATA_FILES="
$HDFTEST_HOME/../testfiles/examples.intro.H5_CreateDataset.txt
$HDFTEST_HOME/../testfiles/examples.intro.H5_CreateAttribute.txt
$HDFTEST_HOME/../testfiles/examples.intro.H5_CreateFile.txt
$HDFTEST_HOME/../testfiles/examples.intro.H5_CreateGroup.txt
$HDFTEST_HOME/../testfiles/examples.intro.H5_CreateGroupAbsoluteRelative.txt
$HDFTEST_HOME/../testfiles/examples.intro.H5_CreateGroupDataset.txt
$HDFTEST_HOME/../testfiles/examples.intro.H5_ReadWrite.txt
"
#
# copy files from source dirs to test dir
#
COPY_LIBFILES="$LIST_LIBRARY_FILES"
COPY_LIBFILES_TO_BLDLIBDIR()
{
# copy test files. Used -f to make sure get a new copy
for tstfile in $COPY_LIBFILES
do
# ignore '#' comment
echo $tstfile | tr -d ' ' | grep '^#' > /dev/null
RET=$?
if [ $RET -eq 1 ]; then
# skip cp if srcdir is same as destdir
# this occurs when build/test performed in source dir and
# make cp fail
SDIR=`$DIRNAME $tstfile`
INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'`
INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'`
if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then
$CP -f $tstfile $BLDLIBDIR
if [ $? -ne 0 ]; then
echo "Error: FAILED to copy $tstfile ."
# Comment out this to CREATE expected file
exit $EXIT_FAILURE
fi
fi
fi
done
}
CLEAN_LIBFILES_AND_BLDLIBDIR()
{
# skip rm if srcdir is same as destdir
# this occurs when build/test performed in source dir and
# make cp fail
SDIR=`$DIRNAME $tstfile`
INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'`
INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'`
if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then
$RM $BLDLIBDIR
fi
}
COPY_DATAFILES="$LIST_DATA_FILES"
COPY_DATAFILES_TO_BLDDIR()
{
# copy test files. Used -f to make sure get a new copy
for tstfile in $COPY_DATAFILES
do
# ignore '#' comment
echo $tstfile | tr -d ' ' | grep '^#' > /dev/null
RET=$?
if [ $RET -eq 1 ]; then
# skip cp if srcdir is same as destdir
# this occurs when build/test performed in source dir and
# make cp fail
SDIR=`$DIRNAME $tstfile`
INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'`
INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'`
if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then
$CP -f $tstfile $BLDDIR
if [ $? -ne 0 ]; then
echo "Error: FAILED to copy $tstfile ."
# Comment out this to CREATE expected file
exit $EXIT_FAILURE
fi
fi
fi
done
}
CLEAN_DATAFILES_AND_BLDDIR()
{
# skip rm if srcdir is same as destdir
# this occurs when build/test performed in source dir and
# make cp fail
SDIR=`$DIRNAME $tstfile`
INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'`
INODE_DDIR=`$LS -i -d $TESTDIR | $AWK -F' ' '{print $1}'`
if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then
$RM $BLDDIR/*.txt
$RM $BLDDIR/*.out
fi
}
# Print a line-line message left justified in a field of 70 characters
# beginning with the word "Testing".
#
TESTING() {
SPACES=" "
echo "Testing $* $SPACES" | cut -c1-70 | tr -d '\012'
}
# where Java is installed (requires jdk1.7.x)
JAVAEXE=@JAVA@
JAVAEXEFLAGS=@H5_JAVAFLAGS@
###############################################################################
# DO NOT MODIFY BELOW THIS LINE
###############################################################################
# prepare for test
COPY_LIBFILES_TO_BLDLIBDIR
COPY_DATAFILES_TO_BLDDIR
CPATH=".:"$BLDLIBDIR"/"$JARFILE":"$BLDLIBDIR"/slf4j-api-1.7.5.jar:"$BLDLIBDIR"/slf4j-simple-1.7.5.jar:"$TESTJARFILE""
TEST=/usr/bin/test
if [ ! -x /usr/bin/test ]
then
TEST=`which test`
fi
if $TEST -z "$CLASSPATH"; then
CLASSPATH=""
fi
CLASSPATH=$CPATH":"$CLASSPATH
export CLASSPATH
if $TEST -n "$JAVAPATH" ; then
PATH=$JAVAPATH":"$PATH
export PATH
fi
if $TEST -e /bin/uname; then
os_name=`/bin/uname -s`
elif $TEST -e /usr/bin/uname; then
os_name=`/usr/bin/uname -s`
else
os_name=unknown
fi
if $TEST -z "$LD_LIBRARY_PATH" ; then
LD_LIBRARY_PATH=""
fi
case $os_name in
Darwin)
DYLD_LIBRARY_PATH=$BLDLIBDIR:$DYLD_LIBRARY_PATH
export DYLD_LIBRARY_PATH
LD_LIBRARY_PATH=$DYLD_LIBRARY_PATH
;;
*)
LD_LIBRARY_PATH=$BLDLIBDIR:$LD_LIBRARY_PATH
;;
esac
export LD_LIBRARY_PATH
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.intro.H5_CreateDataset"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.intro.H5_CreateDataset > H5_CreateDataset.out)
if diff H5_CreateDataset.out examples.intro.H5_CreateDataset.txt > /dev/null; then
echo " PASSED intro.H5_CreateDataset"
else
echo "**FAILED** intro.H5_CreateDataset"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.intro.H5_CreateAttribute"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.intro.H5_CreateAttribute > H5_CreateAttribute.out)
if diff H5_CreateAttribute.out examples.intro.H5_CreateAttribute.txt > /dev/null; then
echo " PASSED intro.H5_CreateAttribute"
else
echo "**FAILED** intro.H5_CreateAttribute"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.intro.H5_CreateFile"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.intro.H5_CreateFile > H5_CreateFile.out)
if diff H5_CreateFile.out examples.intro.H5_CreateFile.txt > /dev/null; then
echo " PASSED intro.H5_CreateFile"
else
echo "**FAILED** intro.H5_CreateFile"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.intro.H5_CreateGroup"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.intro.H5_CreateGroup > H5_CreateGroup.out)
if diff H5_CreateGroup.out examples.intro.H5_CreateGroup.txt > /dev/null; then
echo " PASSED intro.H5_CreateGroup"
else
echo "**FAILED** intro.H5_CreateGroup"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.intro.H5_CreateGroupAbsoluteRelative"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.intro.H5_CreateGroupAbsoluteRelative > H5_CreateGroupAbsoluteRelative.out)
if diff H5_CreateGroupAbsoluteRelative.out examples.intro.H5_CreateGroupAbsoluteRelative.txt > /dev/null; then
echo " PASSED intro.H5_CreateGroupAbsoluteRelative"
else
echo "**FAILED** intro.H5_CreateGroupAbsoluteRelative"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.intro.H5_CreateGroupDataset"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.intro.H5_CreateGroupDataset > H5_CreateGroupDataset.out)
if diff H5_CreateGroupDataset.out examples.intro.H5_CreateGroupDataset.txt > /dev/null; then
echo " PASSED intro.H5_CreateGroupDataset"
else
echo "**FAILED** intro.H5_CreateGroupDataset"
nerrors="`expr $nerrors + 1`"
fi
echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.intro.H5_ReadWrite"
($JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Dorg.slf4j.simpleLogger.defaultLog=trace -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.intro.H5_ReadWrite > H5_ReadWrite.out)
if diff H5_ReadWrite.out examples.intro.H5_ReadWrite.txt > /dev/null; then
echo " PASSED intro.H5_ReadWrite"
else
echo "**FAILED** intro.H5_ReadWrite"
nerrors="`expr $nerrors + 1`"
fi
# Clean up temporary files/directories
CLEAN_LIBFILES_AND_BLDLIBDIR
CLEAN_DATAFILES_AND_BLDDIR
# Report test results and exit
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
@@ -0,0 +1,16 @@
Creating datasets...
DS1 has allocation time H5D_ALLOC_TIME_LATE
DS2 has allocation time H5D_ALLOC_TIME_EARLY
Space for DS1 has not been allocated.
Storage size for DS1 is: 0 bytes.
Space for DS2 has been allocated.
Storage size for DS2 is: 112 bytes.
Writing data...
Space for DS1 has been allocated.
Storage size for DS1 is: 112 bytes.
Space for DS2 has been allocated.
Storage size for DS2 is: 112 bytes.
@@ -0,0 +1,3 @@
Filter type is: H5Z_FILTER_FLETCHER32
Maximum value in DS1 is: 1890
@@ -0,0 +1,26 @@
Original Data:
[ 1 1 1 1 1 1 1 1 ]
[ 1 1 1 1 1 1 1 1 ]
[ 1 1 1 1 1 1 1 1 ]
[ 1 1 1 1 1 1 1 1 ]
[ 1 1 1 1 1 1 1 1 ]
[ 1 1 1 1 1 1 1 1 ]
Storage layout for DS1 is: H5D_CHUNKED
Data as written to disk by hyberslabs:
[ 0 1 0 0 1 0 0 1 ]
[ 1 1 0 1 1 0 1 1 ]
[ 0 0 0 0 0 0 0 0 ]
[ 0 1 0 0 1 0 0 1 ]
[ 1 1 0 1 1 0 1 1 ]
[ 0 0 0 0 0 0 0 0 ]
Data as read from disk by hyberslab:
[ 0 1 0 0 0 0 0 1 ]
[ 0 1 0 1 0 0 1 1 ]
[ 0 0 0 0 0 0 0 0 ]
[ 0 0 0 0 0 0 0 0 ]
[ 0 1 0 1 0 0 1 1 ]
[ 0 0 0 0 0 0 0 0 ]
@@ -0,0 +1,8 @@
Storage layout for DS1 is: H5D_COMPACT
Data for DS1 is:
[ 0 -1 -2 -3 -4 -5 -6 ]
[ 0 0 0 0 0 0 0 ]
[ 0 1 2 3 4 5 6 ]
[ 0 2 4 6 8 10 12 ]
@@ -0,0 +1,7 @@
DS1 is stored in file: H5Ex_D_External.data
DS1:
[ 0 -1 -2 -3 -4 -5 -6 ]
[ 0 0 0 0 0 0 0 ]
[ 0 1 2 3 4 5 6 ]
[ 0 2 4 6 8 10 12 ]
@@ -0,0 +1,20 @@
Dataset before being written to:
[ 99 99 99 99 99 99 99 ]
[ 99 99 99 99 99 99 99 ]
[ 99 99 99 99 99 99 99 ]
[ 99 99 99 99 99 99 99 ]
Dataset after being written to:
[ 0 -1 -2 -3 -4 -5 -6 ]
[ 0 0 0 0 0 0 0 ]
[ 0 1 2 3 4 5 6 ]
[ 0 2 4 6 8 10 12 ]
Dataset after extension:
[ 0 -1 -2 -3 -4 -5 -6 99 99 99 ]
[ 0 0 0 0 0 0 0 99 99 99 ]
[ 0 1 2 3 4 5 6 99 99 99 ]
[ 0 2 4 6 8 10 12 99 99 99 ]
[ 99 99 99 99 99 99 99 99 99 99 ]
[ 99 99 99 99 99 99 99 99 99 99 ]
@@ -0,0 +1,3 @@
Filter type is: H5Z_FILTER_DEFLATE
Maximum value in DS1 is: 1890
@@ -0,0 +1,24 @@
Original Data:
[ 1 1 1 1 1 1 1 1 ]
[ 1 1 1 1 1 1 1 1 ]
[ 1 1 1 1 1 1 1 1 ]
[ 1 1 1 1 1 1 1 1 ]
[ 1 1 1 1 1 1 1 1 ]
[ 1 1 1 1 1 1 1 1 ]
Data as written to disk by hyberslabs:
[ 0 1 0 0 1 0 0 1 ]
[ 1 1 0 1 1 0 1 1 ]
[ 0 0 0 0 0 0 0 0 ]
[ 0 1 0 0 1 0 0 1 ]
[ 1 1 0 1 1 0 1 1 ]
[ 0 0 0 0 0 0 0 0 ]
Data as read from disk by hyberslab:
[ 0 1 0 0 0 0 0 1 ]
[ 0 1 0 1 0 0 1 1 ]
[ 0 0 0 0 0 0 0 0 ]
[ 0 0 0 0 0 0 0 0 ]
[ 0 1 0 1 0 0 1 1 ]
[ 0 0 0 0 0 0 0 0 ]
@@ -0,0 +1,3 @@
Filter type is: H5Z_FILTER_NBIT
Maximum value in DS1 is: 1890

Some files were not shown because too many files have changed in this diff Show More