diff options
Diffstat (limited to 'java/examples/datatypes')
21 files changed, 0 insertions, 6000 deletions
diff --git a/java/examples/datatypes/CMakeLists.txt b/java/examples/datatypes/CMakeLists.txt deleted file mode 100644 index 5860429..0000000 --- a/java/examples/datatypes/CMakeLists.txt +++ /dev/null @@ -1,116 +0,0 @@ -cmake_minimum_required (VERSION 3.18) -project (HDFJAVA_EXAMPLES_DATATYPES Java) - -set (CMAKE_VERBOSE_MAKEFILE 1) - -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 () - set (CMAKE_JAVA_INCLUDE_FLAG_SEP ":") -endif () - -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 () - -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}) - - #----------------------------------------------------------------------------- - # Add Target to clang-format - #----------------------------------------------------------------------------- - if (HDF5_ENABLE_FORMATTERS) - clang_format (HDF5_JAVA_${example}_SRC_FORMAT ${example}.java) - endif () -endforeach () - -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 () - -if (BUILD_TESTING AND HDF5_TEST_EXAMPLES AND HDF5_TEST_SERIAL) - get_property (target_name TARGET ${HDF5_JAVA_JNI_LIB_TARGET} PROPERTY OUTPUT_NAME) - set (CMD_ARGS "-Dhdf.hdf5lib.H5.loadLibraryName=${target_name}$<$<OR:$<CONFIG:Debug>,$<CONFIG:Developer>>:${CMAKE_DEBUG_POSTFIX}>;") - - set (last_test "") - foreach (example ${HDF_JAVA_EXAMPLES}) - add_test ( - NAME JAVA_datatypes-${example}-clear-objects - COMMAND ${CMAKE_COMMAND} -E remove - ${HDFJAVA_EXAMPLES_BINARY_DIR}/${example}.h5 - ) - if (last_test) - set_tests_properties (JAVA_datatypes-${example}-clear-objects PROPERTIES DEPENDS ${last_test}) - endif () - - 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}-clear-objects) - add_test ( - NAME JAVA_datatypes-${example} - COMMAND "${CMAKE_COMMAND}" - -D "TEST_TESTER=${CMAKE_Java_RUNTIME};${CMAKE_Java_RUNTIME_FLAGS}" - -D "TEST_PROGRAM=examples.datatypes.${example}" - -D "TEST_ARGS:STRING=${CMD_ARGS}" - -D "TEST_CLASSPATH:STRING=${CMAKE_JAVA_CLASSPATH}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${${example}_JAR_FILE}" - -D "TEST_LIBRARY_DIRECTORY=${CMAKE_TEST_OUTPUT_DIRECTORY}" - -D "TEST_FOLDER=${HDFJAVA_EXAMPLES_BINARY_DIR}" - -D "TEST_OUTPUT=datatypes/${example}.out" - -D "TEST_EXPECT=0" - -D "TEST_REFERENCE=datatypes/${example}.txt" - -P "${HDF_RESOURCES_DIR}/jrunTest.cmake" - ) - set_tests_properties (JAVA_datatypes-${example} PROPERTIES - DEPENDS JAVA_datatypes-${example}-copy-objects - ) - - add_test ( - NAME JAVA_datatypes-${example}-clean-objects - COMMAND ${CMAKE_COMMAND} -E remove - ${HDFJAVA_EXAMPLES_BINARY_DIR}/${example}.h5 - ) - set_tests_properties (JAVA_datatypes-${example}-clean-objects PROPERTIES - DEPENDS JAVA_datatypes-${example} - ) - set (last_test "JAVA_datatypes-${example}-clean-objects") - endforeach () -endif () diff --git a/java/examples/datatypes/H5Ex_T_Array.java b/java/examples/datatypes/H5Ex_T_Array.java deleted file mode 100644 index 4e9de2a..0000000 --- a/java/examples/datatypes/H5Ex_T_Array.java +++ /dev/null @@ -1,280 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the COPYING file, which can be found at the root of the source code * - * distribution tree, or in https://www.hdfgroup.org/licenses. * - * If you do not have access to either file, you may request a copy from * - * help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/************************************************************ - This example shows how to read 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 = HDF5Constants.H5I_INVALID_HID; - long filetype_id = HDF5Constants.H5I_INVALID_HID; - long memtype_id = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - 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 = HDF5Constants.H5I_INVALID_HID; - long filetype_id = HDF5Constants.H5I_INVALID_HID; - long memtype_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - 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(); - } -} diff --git a/java/examples/datatypes/H5Ex_T_ArrayAttribute.java b/java/examples/datatypes/H5Ex_T_ArrayAttribute.java deleted file mode 100644 index 45b44c1..0000000 --- a/java/examples/datatypes/H5Ex_T_ArrayAttribute.java +++ /dev/null @@ -1,320 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the COPYING file, which can be found at the root of the source code * - * distribution tree, or in https://www.hdfgroup.org/licenses. * - * If you do not have access to either file, you may request a copy from * - * help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/************************************************************ - This example shows how to read 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 = HDF5Constants.H5I_INVALID_HID; - long filetype_id = HDF5Constants.H5I_INVALID_HID; - long memtype_id = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long attribute_id = HDF5Constants.H5I_INVALID_HID; - 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 = HDF5Constants.H5I_INVALID_HID; - } - } - 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 = HDF5Constants.H5I_INVALID_HID; - long filetype_id = HDF5Constants.H5I_INVALID_HID; - long memtype_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long attribute_id = HDF5Constants.H5I_INVALID_HID; - 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(); - } -} diff --git a/java/examples/datatypes/H5Ex_T_Bit.java b/java/examples/datatypes/H5Ex_T_Bit.java deleted file mode 100644 index 6d1a253..0000000 --- a/java/examples/datatypes/H5Ex_T_Bit.java +++ /dev/null @@ -1,225 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the COPYING file, which can be found at the root of the source code * - * distribution tree, or in https://www.hdfgroup.org/licenses. * - * If you do not have access to either file, you may request a copy from * - * help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/************************************************************ - This example shows how to read 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 = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - 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 = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - 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(); - } -} diff --git a/java/examples/datatypes/H5Ex_T_BitAttribute.java b/java/examples/datatypes/H5Ex_T_BitAttribute.java deleted file mode 100644 index 3ad643a..0000000 --- a/java/examples/datatypes/H5Ex_T_BitAttribute.java +++ /dev/null @@ -1,266 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the COPYING file, which can be found at the root of the source code * - * distribution tree, or in https://www.hdfgroup.org/licenses. * - * If you do not have access to either file, you may request a copy from * - * help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/************************************************************ - This example shows how to read 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 = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long attribute_id = HDF5Constants.H5I_INVALID_HID; - 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 = HDF5Constants.H5I_INVALID_HID; - } - } - 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 = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long attribute_id = HDF5Constants.H5I_INVALID_HID; - 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(); - } -} diff --git a/java/examples/datatypes/H5Ex_T_Commit.java b/java/examples/datatypes/H5Ex_T_Commit.java deleted file mode 100644 index 44586ef..0000000 --- a/java/examples/datatypes/H5Ex_T_Commit.java +++ /dev/null @@ -1,260 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the COPYING file, which can be found at the root of the source code * - * distribution tree, or in https://www.hdfgroup.org/licenses. * - * If you do not have access to either file, you may request a copy from * - * help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/************************************************************ - This example shows how to 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 java.util.EnumSet; -import java.util.HashMap; -import java.util.Map; - -import hdf.hdf5lib.H5; -import hdf.hdf5lib.HDF5Constants; - -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 = HDF5Constants.H5I_INVALID_HID; - long strtype_id = HDF5Constants.H5I_INVALID_HID; - long filetype_id = HDF5Constants.H5I_INVALID_HID; - 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 = HDF5Constants.H5I_INVALID_HID; - long typeclass_id = HDF5Constants.H5I_INVALID_HID; - long filetype_id = HDF5Constants.H5I_INVALID_HID; - - // 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(); - } -} diff --git a/java/examples/datatypes/H5Ex_T_Compound.java b/java/examples/datatypes/H5Ex_T_Compound.java deleted file mode 100644 index 7a46bcf..0000000 --- a/java/examples/datatypes/H5Ex_T_Compound.java +++ /dev/null @@ -1,462 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the COPYING file, which can be found at the root of the source code * - * distribution tree, or in https://www.hdfgroup.org/licenses. * - * If you do not have access to either file, you may request a copy from * - * help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/************************************************************ - This example shows how to read 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 java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import hdf.hdf5lib.H5; -import hdf.hdf5lib.HDF5Constants; - -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(List data) - { - this.serial_no = (int)data.get(0); - this.location = (String)data.get(1); - this.temperature = (double)data.get(2); - this.pressure = (double)data.get(3); - } - - 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)); - } - - List get() - { - List data = new ArrayList<>(); - data.add(this.serial_no); - data.add(this.location); - data.add(this.temperature); - data.add(this.pressure); - return data; - } - - void put(List data) - { - this.serial_no = (int)data.get(0); - this.location = (String)data.get(1); - this.temperature = (double)data.get(2); - this.pressure = (double)data.get(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 = HDF5Constants.H5I_INVALID_HID; - long strtype_id = HDF5Constants.H5I_INVALID_HID; - long memtype_id = HDF5Constants.H5I_INVALID_HID; - long filetype_id = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = {DIM0}; - ArrayList[] object_data = new ArrayList[DIM0]; - byte[] dset_data = null; - - // Initialize data. - object_data[0] = (ArrayList) new Sensor(1153, new String("Exterior (static)"), 53.23, 24.57).get(); - object_data[1] = (ArrayList) new Sensor(1184, new String("Intake"), 55.12, 22.95).get(); - object_data[2] = (ArrayList) new Sensor(1027, new String("Intake manifold"), 103.55, 31.23).get(); - object_data[3] = (ArrayList) new Sensor(1313, new String("Exhaust manifold"), 1252.89, 84.11).get(); - - // 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. - try { - if ((dataset_id >= 0) && (memtype_id >= 0)) - H5.H5DwriteVL(dataset_id, memtype_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, (Object[])object_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 = HDF5Constants.H5I_INVALID_HID; - long strtype_id = HDF5Constants.H5I_INVALID_HID; - long memtype_id = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = {DIM0}; - Sensor[] object_data2 = new Sensor[(int)dims[0]]; - - // 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(); - } - - ArrayList[] object_data = new ArrayList[(int)dims[0]]; - - // Read data. - try { - if ((dataset_id >= 0) && (memtype_id >= 0)) - H5.H5DreadVL(dataset_id, memtype_id, HDF5Constants.H5S_ALL, HDF5Constants.H5S_ALL, - HDF5Constants.H5P_DEFAULT, (Object[])object_data); - - for (int indx = 0; indx < (int)dims[0]; indx++) { - object_data2[indx] = new Sensor(object_data[indx]); - } - } - 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(); - } -} diff --git a/java/examples/datatypes/H5Ex_T_CompoundAttribute.java b/java/examples/datatypes/H5Ex_T_CompoundAttribute.java deleted file mode 100644 index 93e15fd..0000000 --- a/java/examples/datatypes/H5Ex_T_CompoundAttribute.java +++ /dev/null @@ -1,504 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the COPYING file, which can be found at the root of the source code * - * distribution tree, or in https://www.hdfgroup.org/licenses. * - * If you do not have access to either file, you may request a copy from * - * help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/************************************************************ - This example shows how to read 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 java.nio.ByteBuffer; -import java.nio.ByteOrder; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import hdf.hdf5lib.H5; -import hdf.hdf5lib.HDF5Constants; - -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; - - 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(List data) - { - this.serial_no = (int)data.get(0); - this.location = (String)data.get(1); - this.temperature = (double)data.get(2); - this.pressure = (double)data.get(3); - } - - 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)); - } - - List get() - { - List data = new ArrayList<>(); - data.add(this.serial_no); - data.add(this.location); - data.add(this.temperature); - data.add(this.pressure); - return data; - } - - void put(List data) - { - this.serial_no = (int)data.get(0); - this.location = (String)data.get(1); - this.temperature = (double)data.get(2); - this.pressure = (double)data.get(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 = HDF5Constants.H5I_INVALID_HID; - long strtype_id = HDF5Constants.H5I_INVALID_HID; - long memtype_id = HDF5Constants.H5I_INVALID_HID; - long filetype_id = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long attribute_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = {DIM0}; - ArrayList[] object_data = new ArrayList[DIM0]; - byte[] dset_data = null; - - // Initialize data. - object_data[0] = (ArrayList) new Sensor(1153, new String("Exterior (static)"), 53.23, 24.57).get(); - object_data[1] = (ArrayList) new Sensor(1184, new String("Intake"), 55.12, 22.95).get(); - object_data[2] = (ArrayList) new Sensor(1027, new String("Intake manifold"), 103.55, 31.23).get(); - object_data[3] = (ArrayList) new Sensor(1313, new String("Exhaust manifold"), 1252.89, 84.11).get(); - - // 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 = HDF5Constants.H5I_INVALID_HID; - } - } - 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. - try { - if ((attribute_id >= 0) && (memtype_id >= 0)) - H5.H5AwriteVL(attribute_id, memtype_id, (Object[])object_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 = HDF5Constants.H5I_INVALID_HID; - long strtype_id = HDF5Constants.H5I_INVALID_HID; - long memtype_id = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long attribute_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = {DIM0}; - Sensor[] object_data2 = new Sensor[(int)dims[0]]; - - // 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(); - } - - ArrayList[] object_data = new ArrayList[(int)dims[0]]; - - // Read data. - try { - if ((attribute_id >= 0) && (memtype_id >= 0)) - H5.H5AreadVL(attribute_id, memtype_id, (Object[])object_data); - - for (int indx = 0; indx < (int)dims[0]; indx++) { - object_data2[indx] = new Sensor(object_data[indx]); - } - } - 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(); - } -} diff --git a/java/examples/datatypes/H5Ex_T_Float.java b/java/examples/datatypes/H5Ex_T_Float.java deleted file mode 100644 index 9ca099e..0000000 --- a/java/examples/datatypes/H5Ex_T_Float.java +++ /dev/null @@ -1,227 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the COPYING file, which can be found at the root of the source code * - * distribution tree, or in https://www.hdfgroup.org/licenses. * - * If you do not have access to either file, you may request a copy from * - * help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/************************************************************ - This example shows how to read 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 java.text.DecimalFormatSymbols; -import java.util.Locale; - -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 = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - 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 = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - 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", new DecimalFormatSymbols(Locale.US)); - 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(); - } -} diff --git a/java/examples/datatypes/H5Ex_T_FloatAttribute.java b/java/examples/datatypes/H5Ex_T_FloatAttribute.java deleted file mode 100644 index 426c4dd..0000000 --- a/java/examples/datatypes/H5Ex_T_FloatAttribute.java +++ /dev/null @@ -1,264 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the COPYING file, which can be found at the root of the source code * - * distribution tree, or in https://www.hdfgroup.org/licenses. * - * If you do not have access to either file, you may request a copy from * - * help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/************************************************************ - This example shows how to read 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 java.text.DecimalFormatSymbols; -import java.util.Locale; - -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 = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long attribute_id = HDF5Constants.H5I_INVALID_HID; - 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 = HDF5Constants.H5I_INVALID_HID; - } - } - 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 = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long attribute_id = HDF5Constants.H5I_INVALID_HID; - 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", new DecimalFormatSymbols(Locale.US)); - 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(); - } -} diff --git a/java/examples/datatypes/H5Ex_T_Integer.java b/java/examples/datatypes/H5Ex_T_Integer.java deleted file mode 100644 index 919ea7e..0000000 --- a/java/examples/datatypes/H5Ex_T_Integer.java +++ /dev/null @@ -1,224 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the COPYING file, which can be found at the root of the source code * - * distribution tree, or in https://www.hdfgroup.org/licenses. * - * If you do not have access to either file, you may request a copy from * - * help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/************************************************************ - This example shows how to read 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 = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - 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 = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - 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(); - } -} diff --git a/java/examples/datatypes/H5Ex_T_IntegerAttribute.java b/java/examples/datatypes/H5Ex_T_IntegerAttribute.java deleted file mode 100644 index 4ec98c4..0000000 --- a/java/examples/datatypes/H5Ex_T_IntegerAttribute.java +++ /dev/null @@ -1,262 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the COPYING file, which can be found at the root of the source code * - * distribution tree, or in https://www.hdfgroup.org/licenses. * - * If you do not have access to either file, you may request a copy from * - * help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/************************************************************ - This example shows how to read 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 = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long attribute_id = HDF5Constants.H5I_INVALID_HID; - 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 = HDF5Constants.H5I_INVALID_HID; - } - } - 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 = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long attribute_id = HDF5Constants.H5I_INVALID_HID; - 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(); - } -} diff --git a/java/examples/datatypes/H5Ex_T_ObjectReference.java b/java/examples/datatypes/H5Ex_T_ObjectReference.java deleted file mode 100644 index 9220d8f..0000000 --- a/java/examples/datatypes/H5Ex_T_ObjectReference.java +++ /dev/null @@ -1,329 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the COPYING file, which can be found at the root of the source code * - * distribution tree, or in https://www.hdfgroup.org/licenses. * - * If you do not have access to either file, you may request a copy from * - * help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/************************************************************ - This example shows how to read 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 = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long filespace_id = HDF5Constants.H5I_INVALID_HID; - long group_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = {DIM0}; - byte[][] dset_data = new byte[DIM0][HDF5Constants.H5R_REF_BUF_SIZE]; - - // 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 = HDF5Constants.H5I_INVALID_HID; - H5.H5Sclose(dataspace_id); - dataspace_id = HDF5Constants.H5I_INVALID_HID; - } - } - 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 = HDF5Constants.H5I_INVALID_HID; - } - catch (Exception e) { - e.printStackTrace(); - } - - try { - if (file_id >= 0) { - try { - dset_data[0] = H5.H5Rcreate_object(file_id, GROUPNAME, HDF5Constants.H5P_DEFAULT); - } - catch (Throwable err) { - err.printStackTrace(); - } - - try { - dset_data[1] = H5.H5Rcreate_object(file_id, DATASETNAME2, HDF5Constants.H5P_DEFAULT); - } - catch (Throwable err) { - err.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, 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, HDF5Constants.H5S_ALL, - HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); - } - catch (Exception e) { - e.printStackTrace(); - } - } - catch (Exception ex) { - ex.printStackTrace(); - } - finally { - try { - H5.H5Rdestroy(dset_data[1]); - } - catch (Exception ex) { - } - try { - H5.H5Rdestroy(dset_data[0]); - } - catch (Exception ex) { - } - } - - // 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 = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - int object_type = -1; - long object_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = {DIM0}; - byte[][] dset_data = new byte[DIM0][HDF5Constants.H5R_REF_BUF_SIZE]; - - // Open an existing file. - try { - file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT); - - // Open an existing dataset. - try { - dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT); - - try { - // Get dataspace and allocate memory for read buffer. - dataspace_id = H5.H5Dget_space(dataset_id); - H5.H5Sget_simple_extent_dims(dataspace_id, dims, null); - - // Read data. - H5.H5Dread(dataset_id, HDF5Constants.H5T_STD_REF, HDF5Constants.H5S_ALL, - HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data); - - // 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 { - object_id = H5.H5Ropen_object(dset_data[indx], HDF5Constants.H5P_DEFAULT, - HDF5Constants.H5P_DEFAULT); - try { - object_type = H5.H5Rget_obj_type3(dset_data[indx], HDF5Constants.H5R_OBJECT); - String obj_name = null; - if (object_type >= 0) { - // Get the name. - obj_name = H5.H5Iget_name(object_id); - } - if ((object_id >= 0) && (object_type >= -1)) { - switch (H5G_obj.get(object_type)) { - case H5G_GROUP: - System.out.print("H5G_GROUP"); - break; - case H5G_DATASET: - System.out.print("H5G_DATASET"); - break; - case H5G_TYPE: - System.out.print("H5G_TYPE"); - break; - default: - System.out.print("UNHANDLED"); - } - } - // Print the name. - System.out.println(": " + obj_name); - } - catch (Exception e) { - e.printStackTrace(); - } - finally { - try { - H5.H5Oclose(object_id); - } - catch (Exception e) { - } - } - } - catch (Exception e4) { - e4.printStackTrace(); - } - finally { - try { - H5.H5Rdestroy(dset_data[indx]); - } - catch (Exception e4) { - } - } - } // end for - } - catch (Exception e3) { - e3.printStackTrace(); - } - finally { - try { - H5.H5Sclose(dataspace_id); - } - catch (Exception e3) { - } - } - } - catch (Exception e2) { - e2.printStackTrace(); - } - finally { - try { - H5.H5Dclose(dataset_id); - } - catch (Exception e2) { - } - } - } - catch (Exception e1) { - e1.printStackTrace(); - } - finally { - try { - H5.H5Fclose(file_id); - } - catch (Exception e1) { - } - } - } - - 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(); - } -} diff --git a/java/examples/datatypes/H5Ex_T_ObjectReferenceAttribute.java b/java/examples/datatypes/H5Ex_T_ObjectReferenceAttribute.java deleted file mode 100644 index be84e51..0000000 --- a/java/examples/datatypes/H5Ex_T_ObjectReferenceAttribute.java +++ /dev/null @@ -1,367 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the COPYING file, which can be found at the root of the source code * - * distribution tree, or in https://www.hdfgroup.org/licenses. * - * If you do not have access to either file, you may request a copy from * - * help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/************************************************************ - This example shows how to read 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 = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long group_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long attribute_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = {DIM0}; - byte[][] dset_data = new byte[DIM0][HDF5Constants.H5R_REF_BUF_SIZE]; - - // 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 = HDF5Constants.H5I_INVALID_HID; - H5.H5Sclose(dataspace_id); - dataspace_id = HDF5Constants.H5I_INVALID_HID; - } - } - 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 = HDF5Constants.H5I_INVALID_HID; - } - catch (Exception e) { - e.printStackTrace(); - } - - try { - if (file_id >= 0) { - try { - dset_data[0] = H5.H5Rcreate_object(file_id, GROUPNAME, HDF5Constants.H5P_DEFAULT); - } - catch (Throwable err) { - err.printStackTrace(); - } - - try { - dset_data[1] = H5.H5Rcreate_object(file_id, DATASETNAME2, HDF5Constants.H5P_DEFAULT); - } - catch (Throwable err) { - err.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 = HDF5Constants.H5I_INVALID_HID; - } - } - 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, 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, dset_data); - } - catch (Exception e) { - e.printStackTrace(); - } - } - catch (Exception ex) { - ex.printStackTrace(); - } - finally { - try { - H5.H5Rdestroy(dset_data[1]); - } - catch (Exception ex) { - } - try { - H5.H5Rdestroy(dset_data[0]); - } - catch (Exception ex) { - } - } - - // 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(); - } - - 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 = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long attribute_id = HDF5Constants.H5I_INVALID_HID; - int object_type = -1; - long object_id = HDF5Constants.H5I_INVALID_HID; - long[] dims = {DIM0}; - byte[][] dset_data = new byte[DIM0][HDF5Constants.H5R_REF_BUF_SIZE]; - - // Open an existing file. - try { - file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT); - - // Open an existing dataset. - try { - dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT); - - try { - attribute_id = H5.H5Aopen_by_name(dataset_id, ".", ATTRIBUTENAME, - HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); - - // Get dataspace and allocate memory for read buffer. - try { - dataspace_id = H5.H5Aget_space(attribute_id); - H5.H5Sget_simple_extent_dims(dataspace_id, dims, null); - - // Read data. - H5.H5Aread(attribute_id, HDF5Constants.H5T_STD_REF, dset_data); - - // 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 { - object_id = H5.H5Ropen_object(dset_data[indx], HDF5Constants.H5P_DEFAULT, - HDF5Constants.H5P_DEFAULT); - try { - object_type = - H5.H5Rget_obj_type3(dset_data[indx], HDF5Constants.H5R_OBJECT); - String obj_name = null; - if (object_type >= 0) { - // Get the name. - obj_name = H5.H5Iget_name(object_id); - } - if ((object_id >= 0) && (object_type >= -1)) { - switch (H5G_obj.get(object_type)) { - case H5G_GROUP: - System.out.print("H5G_GROUP"); - break; - case H5G_DATASET: - System.out.print("H5G_DATASET"); - break; - case H5G_TYPE: - System.out.print("H5G_TYPE"); - break; - default: - System.out.print("UNHANDLED"); - } - } - // Print the name. - System.out.println(": " + obj_name); - } - catch (Exception e) { - e.printStackTrace(); - } - finally { - try { - H5.H5Oclose(object_id); - } - catch (Exception e) { - } - } - } - catch (Exception e5) { - e5.printStackTrace(); - } - finally { - try { - H5.H5Rdestroy(dset_data[indx]); - } - catch (Exception e5) { - } - } - } // end for - } - catch (Exception e4) { - e4.printStackTrace(); - } - finally { - try { - H5.H5Sclose(dataspace_id); - } - catch (Exception e3) { - } - } - } - catch (Exception e3) { - e3.printStackTrace(); - } - finally { - try { - H5.H5Aclose(attribute_id); - } - catch (Exception e4) { - } - } - } - catch (Exception e2) { - e2.printStackTrace(); - } - finally { - try { - H5.H5Dclose(dataset_id); - } - catch (Exception e2) { - } - } - } - catch (Exception e1) { - e1.printStackTrace(); - } - finally { - try { - H5.H5Fclose(file_id); - } - catch (Exception e1) { - } - } - } - - 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(); - } -} diff --git a/java/examples/datatypes/H5Ex_T_Opaque.java b/java/examples/datatypes/H5Ex_T_Opaque.java deleted file mode 100644 index 419a5c8..0000000 --- a/java/examples/datatypes/H5Ex_T_Opaque.java +++ /dev/null @@ -1,268 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the COPYING file, which can be found at the root of the source code * - * distribution tree, or in https://www.hdfgroup.org/licenses. * - * If you do not have access to either file, you may request a copy from * - * help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/************************************************************ - This example shows how to read 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 = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long datatype_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - 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 = HDF5Constants.H5I_INVALID_HID; - long datatype_id = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long type_len = HDF5Constants.H5I_INVALID_HID; - 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(); - } -} diff --git a/java/examples/datatypes/H5Ex_T_OpaqueAttribute.java b/java/examples/datatypes/H5Ex_T_OpaqueAttribute.java deleted file mode 100644 index b8a15a6..0000000 --- a/java/examples/datatypes/H5Ex_T_OpaqueAttribute.java +++ /dev/null @@ -1,305 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the COPYING file, which can be found at the root of the source code * - * distribution tree, or in https://www.hdfgroup.org/licenses. * - * If you do not have access to either file, you may request a copy from * - * help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/************************************************************ - This example shows how to read 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 = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long datatype_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long attribute_id = HDF5Constants.H5I_INVALID_HID; - 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 = HDF5Constants.H5I_INVALID_HID; - } - } - 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 = HDF5Constants.H5I_INVALID_HID; - long datatype_id = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long attribute_id = HDF5Constants.H5I_INVALID_HID; - 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(); - } -} diff --git a/java/examples/datatypes/H5Ex_T_String.java b/java/examples/datatypes/H5Ex_T_String.java deleted file mode 100644 index a69a70b..0000000 --- a/java/examples/datatypes/H5Ex_T_String.java +++ /dev/null @@ -1,309 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the COPYING file, which can be found at the root of the source code * - * distribution tree, or in https://www.hdfgroup.org/licenses. * - * If you do not have access to either file, you may request a copy from * - * help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/************************************************************ - This example shows how to read 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 = HDF5Constants.H5I_INVALID_HID; - long memtype_id = HDF5Constants.H5I_INVALID_HID; - long filetype_id = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - 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 = HDF5Constants.H5I_INVALID_HID; - long filetype_id = HDF5Constants.H5I_INVALID_HID; - long memtype_id = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - 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(); - } -} diff --git a/java/examples/datatypes/H5Ex_T_StringAttribute.java b/java/examples/datatypes/H5Ex_T_StringAttribute.java deleted file mode 100644 index 46c1038..0000000 --- a/java/examples/datatypes/H5Ex_T_StringAttribute.java +++ /dev/null @@ -1,349 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the COPYING file, which can be found at the root of the source code * - * distribution tree, or in https://www.hdfgroup.org/licenses. * - * If you do not have access to either file, you may request a copy from * - * help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/************************************************************ - This example shows how to read 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 = HDF5Constants.H5I_INVALID_HID; - long memtype_id = HDF5Constants.H5I_INVALID_HID; - long filetype_id = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long attribute_id = HDF5Constants.H5I_INVALID_HID; - 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 = HDF5Constants.H5I_INVALID_HID; - } - } - 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 = HDF5Constants.H5I_INVALID_HID; - long filetype_id = HDF5Constants.H5I_INVALID_HID; - long memtype_id = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - long attribute_id = HDF5Constants.H5I_INVALID_HID; - 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(); - } -} diff --git a/java/examples/datatypes/H5Ex_T_VLString.java b/java/examples/datatypes/H5Ex_T_VLString.java deleted file mode 100644 index a9288a4..0000000 --- a/java/examples/datatypes/H5Ex_T_VLString.java +++ /dev/null @@ -1,137 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * Copyright by The HDF Group. * - * All rights reserved. * - * * - * This file is part of HDF5. The full HDF5 copyright notice, including * - * terms governing use, modification, and redistribution, is contained in * - * the COPYING file, which can be found at the root of the source code * - * distribution tree, or in https://www.hdfgroup.org/licenses. * - * If you do not have access to either file, you may request a copy from * - * help@hdfgroup.org. * - * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/************************************************************ - 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 = HDF5Constants.H5I_INVALID_HID; - long type_id = HDF5Constants.H5I_INVALID_HID; - long dataspace_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - 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.H5DwriteVL(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 = HDF5Constants.H5I_INVALID_HID; - long type_id = HDF5Constants.H5I_INVALID_HID; - long dataset_id = HDF5Constants.H5I_INVALID_HID; - 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.H5DreadVL(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(); - } -} diff --git a/java/examples/datatypes/JavaDatatypeExample.sh.in b/java/examples/datatypes/JavaDatatypeExample.sh.in deleted file mode 100644 index fc4a627..0000000 --- a/java/examples/datatypes/JavaDatatypeExample.sh.in +++ /dev/null @@ -1,451 +0,0 @@ -#! /bin/sh -# -# Copyright by The HDF Group. -# All rights reserved. -# -# This file is part of HDF5. The full HDF5 copyright notice, including -# terms governing use, modification, and redistribution, is contained in -# the COPYING file, which can be found at the root of the source code -# distribution tree, or in https://www.hdfgroup.org/licenses. -# If you do not have access to either file, you may request a copy from -# help@hdfgroup.org. -# - -top_builddir=@top_builddir@ -top_srcdir=@top_srcdir@ -srcdir=@srcdir@ -IS_DARWIN="@H5_IS_DARWIN@" - -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' -BASENAME='basename' -LS='ls' -AWK='awk' - -nerrors=0 - -# where the libs exist -HDFLIB_HOME="$top_srcdir/java/lib" -BLDDIR="." -BLDLIBDIR="$BLDDIR/testlibs" -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=" -$top_builddir/src/.libs/libhdf5.* -$top_builddir/java/src/jni/.libs/libhdf5_java.* -$top_builddir/java/src/$JARFILE -" -LIST_JAR_TESTFILES=" -$HDFLIB_HOME/slf4j-api-2.0.6.jar -$HDFLIB_HOME/ext/slf4j-simple-2.0.6.jar -" -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_JARTESTFILES="$LIST_JAR_TESTFILES" - -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 $BLDLIBDIR | $AWK -F' ' '{print $1}'` - if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then - $CP -fR $tstfile $BLDLIBDIR - if [ $? -ne 0 ]; then - echo "Error: FAILED to copy $tstfile ." - - # Comment out this to CREATE expected file - exit $EXIT_FAILURE - fi - BNAME=`$BASENAME $tstfile` - if [ "$BNAME" = "libhdf5_java.dylib" ]; then - COPIED_LIBHDF5_JAVA=1 - fi - fi - fi - done - if [[ "$IS_DARWIN" = "yes" ]] && [[ $COPIED_LIBHDF5_JAVA -eq 1 ]]; then - (cd $BLDLIBDIR; \ - install_name_tool -add_rpath @loader_path libhdf5_java.dylib; \ - exist_path=` otool -l libhdf5_java.dylib | grep libhdf5 | grep -v java | awk '{print $2}'`; \ - echo $exist_path; \ - install_name_tool -change $exist_path @rpath/libhdf5.dylib libhdf5_java.dylib) - fi - # copy jar files. Used -f to make sure get a new copy - for tstfile in $COPY_JARTESTFILES - 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 $BLDLIBDIR | $AWK -F' ' '{print $1}'` - if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then - $CP -fR $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=$HDFLIB_HOME - INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'` - INODE_DDIR=`$LS -i -d $BLDLIBDIR | $AWK -F' ' '{print $1}'` - if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then - $RM -rf $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 $BLDDIR | $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() -{ - $RM $BLDDIR/examples.datatypes.H5Ex_T_*.txt - $RM $BLDDIR/H5Ex_T_*.out - $RM $BLDDIR/H5Ex_T_*.h5 -} - -# 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-2.0.6.jar:"$BLDLIBDIR"/slf4j-simple-2.0.6.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 - *) - 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" -TESTING examples.datatypes.H5Ex_T_Array -($RUNSERIAL $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" -TESTING examples.datatypes.H5Ex_T_ArrayAttribute -($RUNSERIAL $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" -TESTING examples.datatypes.H5Ex_T_Bit -($RUNSERIAL $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" -TESTING examples.datatypes.H5Ex_T_BitAttribute -($RUNSERIAL $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" -TESTING examples.datasets.H5Ex_T_Commit -($RUNSERIAL $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" -TESTING examples.datatypes.H5Ex_T_Compound -($RUNSERIAL $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" -TESTING examples.datatypes.H5Ex_T_CompoundAttribute -($RUNSERIAL $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" -TESTING examples.datatypes.H5Ex_T_Float -($RUNSERIAL $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" -TESTING examples.datatypes.H5Ex_T_FloatAttribute -($RUNSERIAL $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" -TESTING examples.datatypes.H5Ex_T_Integer -($RUNSERIAL $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" -TESTING examples.datatypes.H5Ex_T_IntegerAttribute -($RUNSERIAL $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" -TESTING examples.datatypes.H5Ex_T_ObjectReference -($RUNSERIAL $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" -TESTING examples.datatypes.H5Ex_T_ObjectReferenceAttribute -($RUNSERIAL $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" -TESTING examples.datatypes.H5Ex_T_Opaque -($RUNSERIAL $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" -TESTING examples.datatypes.H5Ex_T_OpaqueAttribute -($RUNSERIAL $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" -TESTING examples.datatypes.H5Ex_T_String -($RUNSERIAL $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" -TESTING examples.datatypes.H5Ex_T_StringAttribute -($RUNSERIAL $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" -TESTING examples.datatypes.H5Ex_T_VLString -($RUNSERIAL $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 diff --git a/java/examples/datatypes/Makefile.am b/java/examples/datatypes/Makefile.am deleted file mode 100644 index 12e5cb8..0000000 --- a/java/examples/datatypes/Makefile.am +++ /dev/null @@ -1,75 +0,0 @@ -# -# Copyright by The HDF Group. -# All rights reserved. -# -# This file is part of HDF5. The full HDF5 copyright notice, including -# terms governing use, modification, and redistribution, is contained in -# the COPYING file, which can be found at the root of the source code -# distribution tree, or in https://www.hdfgroup.org/licenses. -# If you do not have access to either file, you may request a copy from -# help@hdfgroup.org. -## -## Makefile.am -## Run automake to generate a Makefile.in from this file. -## -# -# HDF5 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: - test -d $(@D)/$(JAVAROOT) || $(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-2.0.6.jar:$(top_srcdir)/java/lib/ext/slf4j-simple-2.0.6.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 = JavaDatatypeExample.sh -TEST_SCRIPT = $(check_SCRIPTS) - -CLEANFILES = classnoinst.stamp $(jarfile) $(JAVAROOT)/$(pkgpath)/*.class JavaDatatypeExample.sh - -clean: - rm -rf $(JAVAROOT)/* - rm -f $(jarfile) - rm -f classnoinst.stamp - -include $(top_srcdir)/config/conclude.am |