summaryrefslogtreecommitdiffstats
path: root/HDF5Examples/JAVA/H5T
diff options
context:
space:
mode:
authorAllen Byrne <50328838+byrnHDF@users.noreply.github.com>2023-11-27 21:30:15 (GMT)
committerGitHub <noreply@github.com>2023-11-27 21:30:15 (GMT)
commitfc88fcde1091cf12c1e88c783a14ee0f1cffe31c (patch)
tree91b88b62cd30ed37ee9227e43989e95035be43c3 /HDF5Examples/JAVA/H5T
parenta067bf71f57723d2dfca7dfe2ffd9ea502eccd4f (diff)
downloadhdf5-fc88fcde1091cf12c1e88c783a14ee0f1cffe31c.zip
hdf5-fc88fcde1091cf12c1e88c783a14ee0f1cffe31c.tar.gz
hdf5-fc88fcde1091cf12c1e88c783a14ee0f1cffe31c.tar.bz2
Develop merge examples (#3851)
* Merge examples repo into library * Change grepTest to be more fault-tolerant * Update examples macro file * Exclude all Fortran examples from doxygen
Diffstat (limited to 'HDF5Examples/JAVA/H5T')
-rw-r--r--HDF5Examples/JAVA/H5T/110/H5Ex_T_ObjectReference.java341
-rw-r--r--HDF5Examples/JAVA/H5T/110/H5Ex_T_ObjectReferenceAttribute.java381
-rw-r--r--HDF5Examples/JAVA/H5T/CMakeLists.txt92
-rw-r--r--HDF5Examples/JAVA/H5T/H5Ex_T_Array.java278
-rw-r--r--HDF5Examples/JAVA/H5T/H5Ex_T_ArrayAttribute.java318
-rw-r--r--HDF5Examples/JAVA/H5T/H5Ex_T_Bit.java223
-rw-r--r--HDF5Examples/JAVA/H5T/H5Ex_T_BitAttribute.java264
-rw-r--r--HDF5Examples/JAVA/H5T/H5Ex_T_Commit.java258
-rw-r--r--HDF5Examples/JAVA/H5T/H5Ex_T_Compound.java460
-rw-r--r--HDF5Examples/JAVA/H5T/H5Ex_T_CompoundAttribute.java502
-rw-r--r--HDF5Examples/JAVA/H5T/H5Ex_T_Float.java225
-rw-r--r--HDF5Examples/JAVA/H5T/H5Ex_T_FloatAttribute.java262
-rw-r--r--HDF5Examples/JAVA/H5T/H5Ex_T_Integer.java222
-rw-r--r--HDF5Examples/JAVA/H5T/H5Ex_T_IntegerAttribute.java260
-rw-r--r--HDF5Examples/JAVA/H5T/H5Ex_T_ObjectReference.java323
-rw-r--r--HDF5Examples/JAVA/H5T/H5Ex_T_ObjectReferenceAttribute.java366
-rw-r--r--HDF5Examples/JAVA/H5T/H5Ex_T_Opaque.java266
-rw-r--r--HDF5Examples/JAVA/H5T/H5Ex_T_OpaqueAttribute.java303
-rw-r--r--HDF5Examples/JAVA/H5T/H5Ex_T_RegionReference.java315
-rw-r--r--HDF5Examples/JAVA/H5T/H5Ex_T_RegionReferenceAttribute.java340
-rw-r--r--HDF5Examples/JAVA/H5T/H5Ex_T_String.java307
-rw-r--r--HDF5Examples/JAVA/H5T/H5Ex_T_StringAttribute.java347
-rw-r--r--HDF5Examples/JAVA/H5T/H5Ex_T_VLString.java135
-rw-r--r--HDF5Examples/JAVA/H5T/JavaDatatypeExample.sh.in447
-rw-r--r--HDF5Examples/JAVA/H5T/Java_sourcefiles.cmake36
-rw-r--r--HDF5Examples/JAVA/H5T/Makefile.am75
-rw-r--r--HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_Array.txt21
-rw-r--r--HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_ArrayAttribute.txt21
-rw-r--r--HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_Bit.txt6
-rw-r--r--HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_BitAttribute.txt6
-rw-r--r--HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_Commit.txt6
-rw-r--r--HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_Compound.txt25
-rw-r--r--HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_CompoundAttribute.txt25
-rw-r--r--HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_Float.txt6
-rw-r--r--HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_FloatAttribute.txt6
-rw-r--r--HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_Integer.txt6
-rw-r--r--HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_IntegerAttribute.txt6
-rw-r--r--HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_ObjectReference.txt4
-rw-r--r--HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_ObjectReferenceAttribute.txt4
-rw-r--r--HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_Opaque.txt6
-rw-r--r--HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_OpaqueAttribute.txt6
-rw-r--r--HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_RegionReference.txt4
-rw-r--r--HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_RegionReferenceAttribute.txt4
-rw-r--r--HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_String.txt5
-rw-r--r--HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_StringAttribute.txt5
-rw-r--r--HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_VLString.txt4
46 files changed, 7522 insertions, 0 deletions
diff --git a/HDF5Examples/JAVA/H5T/110/H5Ex_T_ObjectReference.java b/HDF5Examples/JAVA/H5T/110/H5Ex_T_ObjectReference.java
new file mode 100644
index 0000000..0e147d8
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/110/H5Ex_T_ObjectReference.java
@@ -0,0 +1,341 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Copyright by The HDF Group. *
+ * All rights reserved. *
+ * *
+ * This file is part of HDF5. The full HDF5 copyright notice, including *
+ * terms governing use, modification, and redistribution, is contained in *
+ * the COPYING file, which can be found at the root of the source code *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
+ * If you do not have access to either file, you may request a copy from *
+ * help@hdfgroup.org. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/************************************************************
+ This 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.
+ ************************************************************/
+
+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][8];
+
+ // Create a new file using default properties.
+ try {
+ file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Create dataset with a scalar dataspace.
+ try {
+ dataspace_id = H5.H5Screate(HDF5Constants.H5S_SCALAR);
+ if ((file_id >= 0) && (dataspace_id >= 0)) {
+ dataset_id = H5.H5Dcreate(file_id, DATASETNAME2, HDF5Constants.H5T_STD_I32LE, dataspace_id,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ if (dataset_id >= 0)
+ H5.H5Dclose(dataset_id);
+ dataset_id = 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();
+ }
+
+ // Create references to the previously created objects. Passing -1
+ // as space_id causes this parameter to be ignored. Other values
+ // besides valid dataspaces result in an error.
+ try {
+ if (file_id >= 0) {
+ byte rbuf0[] = H5.H5Rcreate(file_id, GROUPNAME, HDF5Constants.H5R_OBJECT, -1);
+ byte rbuf1[] = H5.H5Rcreate(file_id, DATASETNAME2, HDF5Constants.H5R_OBJECT, -1);
+ for (int indx = 0; indx < 8; indx++) {
+ dset_data[0][indx] = rbuf0[indx];
+ dset_data[1][indx] = rbuf1[indx];
+ }
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Create dataspace. Setting maximum size to NULL sets the maximum
+ // size to be the current size.
+ try {
+ filespace_id = H5.H5Screate_simple(RANK, dims, null);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Create the dataset.
+ try {
+ if ((file_id >= 0) && (filespace_id >= 0))
+ dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_REF_OBJ, filespace_id,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Write the object references to it.
+ try {
+ if (dataset_id >= 0)
+ H5.H5Dwrite(dataset_id, HDF5Constants.H5T_STD_REF_OBJ, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // End access to the dataset and release resources used by it.
+
+ try {
+ if (dataset_id >= 0)
+ H5.H5Dclose(dataset_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ try {
+ if (filespace_id >= 0)
+ H5.H5Sclose(filespace_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Close the file.
+ try {
+ if (file_id >= 0)
+ H5.H5Fclose(file_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private static void readObjRef()
+ {
+ long file_id = 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;
+
+ // Open an existing file.
+ try {
+ file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Open an existing dataset.
+ try {
+ if (file_id >= 0)
+ dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Get dataspace and allocate memory for read buffer.
+ try {
+ if (dataset_id >= 0)
+ dataspace_id = H5.H5Dget_space(dataset_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ try {
+ if (dataspace_id >= 0)
+ H5.H5Sget_simple_extent_dims(dataspace_id, dims, null);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Allocate array of pointers to two-dimensional arrays (the
+ // elements of the dataset.
+ dset_data = new byte[(int)dims[0]][8];
+
+ // Read the data using the default properties.
+ try {
+ if (dataset_id >= 0) {
+ H5.H5Dread(dataset_id, HDF5Constants.H5T_STD_REF_OBJ, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data);
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Output the data to the screen.
+ for (int indx = 0; indx < dims[0]; indx++) {
+ System.out.println(DATASETNAME + "[" + indx + "]:");
+ System.out.print(" ->");
+ // Open the referenced object, get its name and type.
+ try {
+ if (dataset_id >= 0) {
+ object_id = H5.H5Rdereference(dataset_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5R_OBJECT, dset_data[indx]);
+ object_type = H5.H5Rget_obj_type(dataset_id, HDF5Constants.H5R_OBJECT, dset_data[indx]);
+ }
+ String obj_name = null;
+ if (object_type >= 0) {
+ // Get the length of the name and retrieve 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");
+ try {
+ if (object_id >= 0)
+ H5.H5Gclose(object_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ break;
+ case H5G_DATASET:
+ System.out.print("H5G_DATASET");
+ try {
+ if (object_id >= 0)
+ H5.H5Dclose(object_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ break;
+ case H5G_TYPE:
+ System.out.print("H5G_TYPE");
+ try {
+ if (object_id >= 0)
+ H5.H5Tclose(object_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ break;
+ default:
+ System.out.print("UNHANDLED");
+ }
+ }
+ // Print the name.
+ System.out.println(": " + obj_name);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ // End access to the dataset and release resources used by it.
+ try {
+ if (dataspace_id >= 0)
+ H5.H5Sclose(dataspace_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ try {
+ if (dataset_id >= 0)
+ H5.H5Dclose(dataset_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Close the file.
+ try {
+ if (file_id >= 0)
+ H5.H5Fclose(file_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ // Check if gzip compression is available and can be used for both
+ // compression and decompression. Normally we do not perform error
+ // checking in these examples for the sake of clarity, but in this
+ // case we will make an exception because this filter is an
+ // optional part of the hdf5 library.
+ H5Ex_T_ObjectReference.writeObjRef();
+ H5Ex_T_ObjectReference.readObjRef();
+ }
+}
diff --git a/HDF5Examples/JAVA/H5T/110/H5Ex_T_ObjectReferenceAttribute.java b/HDF5Examples/JAVA/H5T/110/H5Ex_T_ObjectReferenceAttribute.java
new file mode 100644
index 0000000..9818dba
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/110/H5Ex_T_ObjectReferenceAttribute.java
@@ -0,0 +1,381 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.
+ ************************************************************/
+
+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][8];
+
+ // Create a new file using default properties.
+ try {
+ file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Create dataset with a scalar dataspace.
+ try {
+ dataspace_id = H5.H5Screate(HDF5Constants.H5S_SCALAR);
+ if (dataspace_id >= 0) {
+ dataset_id = H5.H5Dcreate(file_id, DATASETNAME2, HDF5Constants.H5T_STD_I32LE, dataspace_id,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ if (dataset_id >= 0)
+ H5.H5Dclose(dataset_id);
+ dataset_id = 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();
+ }
+
+ // Create references to the previously created objects. Passing -1
+ // as space_id causes this parameter to be ignored. Other values
+ // besides valid dataspaces result in an error.
+ try {
+ if (file_id >= 0) {
+ byte rbuf0[] = H5.H5Rcreate(file_id, GROUPNAME, HDF5Constants.H5R_OBJECT, -1);
+ byte rbuf1[] = H5.H5Rcreate(file_id, DATASETNAME2, HDF5Constants.H5R_OBJECT, -1);
+ for (int indx = 0; indx < 8; indx++) {
+ dset_data[0][indx] = rbuf0[indx];
+ dset_data[1][indx] = rbuf1[indx];
+ }
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Create dataset with a scalar dataspace to serve as the parent
+ // for the attribute.
+ try {
+ dataspace_id = H5.H5Screate(HDF5Constants.H5S_SCALAR);
+ if (dataspace_id >= 0) {
+ dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, dataspace_id,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ H5.H5Sclose(dataspace_id);
+ dataspace_id = 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_OBJ, dataspace_id,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Write the dataset.
+ try {
+ if (attribute_id >= 0)
+ H5.H5Awrite(attribute_id, HDF5Constants.H5T_STD_REF_OBJ, dset_data);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // End access to the dataset and release resources used by it.
+ try {
+ if (attribute_id >= 0)
+ H5.H5Aclose(attribute_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ try {
+ if (dataset_id >= 0)
+ H5.H5Dclose(dataset_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Terminate access to the data space.
+ try {
+ if (dataspace_id >= 0)
+ H5.H5Sclose(dataspace_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Close the file.
+ try {
+ if (file_id >= 0)
+ H5.H5Fclose(file_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ private static void ReadDataset()
+ {
+ long file_id = 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;
+
+ // Open an existing file.
+ try {
+ file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Open an existing dataset.
+ try {
+ if (file_id >= 0)
+ dataset_id = H5.H5Dopen(file_id, DATASETNAME, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ try {
+ if (dataset_id >= 0)
+ attribute_id = H5.H5Aopen_by_name(dataset_id, ".", ATTRIBUTENAME, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Get dataspace and allocate memory for read buffer.
+ try {
+ if (attribute_id >= 0)
+ dataspace_id = H5.H5Aget_space(attribute_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ try {
+ if (dataspace_id >= 0)
+ H5.H5Sget_simple_extent_dims(dataspace_id, dims, null);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Allocate array of pointers to two-dimensional arrays (the
+ // elements of the dataset.
+ dset_data = new byte[(int)dims[0]][8];
+
+ // Read data.
+ try {
+ if (attribute_id >= 0)
+ H5.H5Aread(attribute_id, HDF5Constants.H5T_STD_REF_OBJ, dset_data);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Output the data to the screen.
+ for (int indx = 0; indx < dims[0]; indx++) {
+ System.out.println(ATTRIBUTENAME + "[" + indx + "]:");
+ System.out.print(" ->");
+ // Open the referenced object, get its name and type.
+ try {
+ if (dataset_id >= 0) {
+ object_id = H5.H5Rdereference(dataset_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5R_OBJECT, dset_data[indx]);
+ object_type = H5.H5Rget_obj_type(dataset_id, HDF5Constants.H5R_OBJECT, dset_data[indx]);
+ }
+ String obj_name = null;
+ if (object_type >= 0) {
+ // Get the length of the name and retrieve 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");
+ try {
+ if (object_id >= 0)
+ H5.H5Gclose(object_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ break;
+ case H5G_DATASET:
+ System.out.print("H5G_DATASET");
+ try {
+ if (object_id >= 0)
+ H5.H5Dclose(object_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ break;
+ case H5G_TYPE:
+ System.out.print("H5G_TYPE");
+ try {
+ if (object_id >= 0)
+ H5.H5Tclose(object_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ break;
+ default:
+ System.out.print("UNHANDLED");
+ }
+ }
+ // Print the name.
+ System.out.println(": " + obj_name);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ // End access to the dataset and release resources used by it.
+ try {
+ if (attribute_id >= 0)
+ H5.H5Aclose(attribute_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ try {
+ if (dataset_id >= 0)
+ H5.H5Dclose(dataset_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Terminate access to the data space.
+ try {
+ if (dataspace_id >= 0)
+ H5.H5Sclose(dataspace_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Close the file.
+ try {
+ if (file_id >= 0)
+ H5.H5Fclose(file_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ H5Ex_T_ObjectReferenceAttribute.CreateDataset();
+ // Now we begin the read section of this example. Here we assume
+ // the dataset and array have the same name and rank, but can have
+ // any size. Therefore we must allocate a new array to read in
+ // data using malloc().
+ H5Ex_T_ObjectReferenceAttribute.ReadDataset();
+ }
+}
diff --git a/HDF5Examples/JAVA/H5T/CMakeLists.txt b/HDF5Examples/JAVA/H5T/CMakeLists.txt
new file mode 100644
index 0000000..a779a53
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/CMakeLists.txt
@@ -0,0 +1,92 @@
+cmake_minimum_required (VERSION 3.18)
+project (HDF5Examples_JAVA_H5T Java)
+
+set (CMAKE_VERBOSE_MAKEFILE 1)
+
+INCLUDE_DIRECTORIES (
+ ${HDFJAVA_LIB_DIR}
+ ${JAVA_INCLUDE_PATH}
+ ${JAVA_INCLUDE_PATH2}
+)
+
+#-----------------------------------------------------------------------------
+# Define Sources
+#-----------------------------------------------------------------------------
+include (Java_sourcefiles.cmake)
+
+if (WIN32)
+ set (CMAKE_JAVA_INCLUDE_FLAG_SEP ";")
+else ()
+ set (CMAKE_JAVA_INCLUDE_FLAG_SEP ":")
+endif ()
+
+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 (HCP_JAR ${CMAKE_JAVA_INCLUDE_PATH})
+ get_filename_component (_HCP_FILE ${HCP_JAR} NAME)
+ set (HDFJAVA_CLASSJARS "${_HCP_FILE} ${HDFJAVA_CLASSJARS}")
+endforeach ()
+
+foreach (example ${HDF_JAVA_EXAMPLES})
+ get_filename_component (example_name ${example} NAME_WE)
+ file (WRITE ${PROJECT_BINARY_DIR}/Manifest.txt
+ "Main-Class: ${example_name}
+Class-Path: ${HDFJAVA_CLASSJARS}
+"
+ )
+ add_jar (${EXAMPLE_VARNAME}_${example_name} SOURCES ${example} MANIFEST ${PROJECT_BINARY_DIR}/Manifest.txt)
+ get_target_property (${EXAMPLE_VARNAME}_${example_name}_JAR_FILE ${EXAMPLE_VARNAME}_${example_name} JAR_FILE)
+endforeach ()
+
+if (H5EX_BUILD_TESTING)
+ macro (ADD_H5_TEST resultfile resultcode)
+ add_test (
+ NAME ${EXAMPLE_VARNAME}_jnative-h5-${resultfile}
+ COMMAND "${CMAKE_COMMAND}"
+ -D "TEST_TESTER=${CMAKE_Java_RUNTIME}"
+ -D "TEST_PROGRAM=${resultfile}"
+ -D "TEST_ARGS:STRING=${ARGN}"
+ -D "TEST_CLASSPATH:STRING=${CMAKE_JAVA_CLASSPATH}${CMAKE_JAVA_INCLUDE_FLAG_SEP}${${EXAMPLE_VARNAME}_${resultfile}_JAR_FILE}"
+ -D "TEST_LIBRARY_DIRECTORY=${CMAKE_TEST_LIB_DIRECTORY}"
+ -D "TEST_FOLDER=${PROJECT_BINARY_DIR}"
+ -D "TEST_OUTPUT=${PROJECT_BINARY_DIR}/${resultfile}.out"
+ -D "TEST_REFERENCE=${resultfile}.txt"
+ -D "TEST_EXPECT=${resultcode}"
+ -D "TEST_SKIP_COMPARE=TRUE"
+ -P "${${EXAMPLE_PACKAGE_NAME}_RESOURCES_DIR}/jrunTest.cmake"
+ )
+ if (NOT "${last_test}" STREQUAL "")
+ set_tests_properties (${EXAMPLE_VARNAME}_jnative-h5-${resultfile} PROPERTIES DEPENDS ${last_test})
+ endif ()
+ set (last_test "${EXAMPLE_VARNAME}_jnative-h5-${resultfile}")
+ endmacro ()
+
+ foreach (example ${HDF_JAVA_EXAMPLES})
+ get_filename_component (example_name ${example} NAME_WE)
+ add_test (
+ NAME ${EXAMPLE_VARNAME}_jnative-h5-${example_name}-clearall-objects
+ COMMAND ${CMAKE_COMMAND}
+ -E remove
+ ${PROJECT_BINARY_DIR}/${example_name}.h5
+ ${example_name}.out
+ ${example_name}.out.err
+ )
+ if (NOT "${last_test}" STREQUAL "")
+ set_tests_properties (${EXAMPLE_VARNAME}_jnative-h5-${example_name}-clearall-objects PROPERTIES DEPENDS ${last_test})
+ endif ()
+ add_test (
+ NAME ${EXAMPLE_VARNAME}_jnative-h5-${example_name}-copy-objects
+ COMMAND ${CMAKE_COMMAND}
+ -E copy_if_different
+ ${PROJECT_SOURCE_DIR}/tfiles/110/${example_name}.txt
+ ${PROJECT_BINARY_DIR}/${example_name}.txt
+ )
+ set_tests_properties (${EXAMPLE_VARNAME}_jnative-h5-${example_name}-copy-objects PROPERTIES DEPENDS ${EXAMPLE_VARNAME}_jnative-h5-${example_name}-clearall-objects)
+ set (last_test "${EXAMPLE_VARNAME}_jnative-h5-${example_name}-copy-objects")
+ ADD_H5_TEST (${example_name} 0)
+ endforeach ()
+
+endif ()
diff --git a/HDF5Examples/JAVA/H5T/H5Ex_T_Array.java b/HDF5Examples/JAVA/H5T/H5Ex_T_Array.java
new file mode 100644
index 0000000..489367b
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/H5Ex_T_Array.java
@@ -0,0 +1,278 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.
+ ************************************************************/
+
+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/HDF5Examples/JAVA/H5T/H5Ex_T_ArrayAttribute.java b/HDF5Examples/JAVA/H5T/H5Ex_T_ArrayAttribute.java
new file mode 100644
index 0000000..9a2aca5
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/H5Ex_T_ArrayAttribute.java
@@ -0,0 +1,318 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.
+ ************************************************************/
+
+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/HDF5Examples/JAVA/H5T/H5Ex_T_Bit.java b/HDF5Examples/JAVA/H5T/H5Ex_T_Bit.java
new file mode 100644
index 0000000..54a467e
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/H5Ex_T_Bit.java
@@ -0,0 +1,223 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.
+ ************************************************************/
+
+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/HDF5Examples/JAVA/H5T/H5Ex_T_BitAttribute.java b/HDF5Examples/JAVA/H5T/H5Ex_T_BitAttribute.java
new file mode 100644
index 0000000..5be1b91
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/H5Ex_T_BitAttribute.java
@@ -0,0 +1,264 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.
+ ************************************************************/
+
+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/HDF5Examples/JAVA/H5T/H5Ex_T_Commit.java b/HDF5Examples/JAVA/H5T/H5Ex_T_Commit.java
new file mode 100644
index 0000000..cd26a96
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/H5Ex_T_Commit.java
@@ -0,0 +1,258 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.
+ ************************************************************/
+
+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/HDF5Examples/JAVA/H5T/H5Ex_T_Compound.java b/HDF5Examples/JAVA/H5T/H5Ex_T_Compound.java
new file mode 100644
index 0000000..21aeabc
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/H5Ex_T_Compound.java
@@ -0,0 +1,460 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.
+ ************************************************************/
+
+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/HDF5Examples/JAVA/H5T/H5Ex_T_CompoundAttribute.java b/HDF5Examples/JAVA/H5T/H5Ex_T_CompoundAttribute.java
new file mode 100644
index 0000000..a33faee
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/H5Ex_T_CompoundAttribute.java
@@ -0,0 +1,502 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.
+ ************************************************************/
+
+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/HDF5Examples/JAVA/H5T/H5Ex_T_Float.java b/HDF5Examples/JAVA/H5T/H5Ex_T_Float.java
new file mode 100644
index 0000000..e062588
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/H5Ex_T_Float.java
@@ -0,0 +1,225 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.
+ ************************************************************/
+
+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/HDF5Examples/JAVA/H5T/H5Ex_T_FloatAttribute.java b/HDF5Examples/JAVA/H5T/H5Ex_T_FloatAttribute.java
new file mode 100644
index 0000000..ffb8467
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/H5Ex_T_FloatAttribute.java
@@ -0,0 +1,262 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.
+ ************************************************************/
+
+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/HDF5Examples/JAVA/H5T/H5Ex_T_Integer.java b/HDF5Examples/JAVA/H5T/H5Ex_T_Integer.java
new file mode 100644
index 0000000..afae2b0
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/H5Ex_T_Integer.java
@@ -0,0 +1,222 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.
+ ************************************************************/
+
+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/HDF5Examples/JAVA/H5T/H5Ex_T_IntegerAttribute.java b/HDF5Examples/JAVA/H5T/H5Ex_T_IntegerAttribute.java
new file mode 100644
index 0000000..be4a878
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/H5Ex_T_IntegerAttribute.java
@@ -0,0 +1,260 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.
+ ************************************************************/
+
+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/HDF5Examples/JAVA/H5T/H5Ex_T_ObjectReference.java b/HDF5Examples/JAVA/H5T/H5Ex_T_ObjectReference.java
new file mode 100644
index 0000000..2b61794
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/H5Ex_T_ObjectReference.java
@@ -0,0 +1,323 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.
+ ************************************************************/
+
+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)
+ {
+ H5Ex_T_ObjectReference.writeObjRef();
+ H5Ex_T_ObjectReference.readObjRef();
+ }
+}
diff --git a/HDF5Examples/JAVA/H5T/H5Ex_T_ObjectReferenceAttribute.java b/HDF5Examples/JAVA/H5T/H5Ex_T_ObjectReferenceAttribute.java
new file mode 100644
index 0000000..d2117bd
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/H5Ex_T_ObjectReferenceAttribute.java
@@ -0,0 +1,366 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.
+ ************************************************************/
+
+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/HDF5Examples/JAVA/H5T/H5Ex_T_Opaque.java b/HDF5Examples/JAVA/H5T/H5Ex_T_Opaque.java
new file mode 100644
index 0000000..c9628d6
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/H5Ex_T_Opaque.java
@@ -0,0 +1,266 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.
+ ************************************************************/
+
+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/HDF5Examples/JAVA/H5T/H5Ex_T_OpaqueAttribute.java b/HDF5Examples/JAVA/H5T/H5Ex_T_OpaqueAttribute.java
new file mode 100644
index 0000000..02f7bd5
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/H5Ex_T_OpaqueAttribute.java
@@ -0,0 +1,303 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.
+ ************************************************************/
+
+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/HDF5Examples/JAVA/H5T/H5Ex_T_RegionReference.java b/HDF5Examples/JAVA/H5T/H5Ex_T_RegionReference.java
new file mode 100644
index 0000000..0c7f6ab
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/H5Ex_T_RegionReference.java
@@ -0,0 +1,315 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.
+ ************************************************************/
+
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.Map;
+
+import hdf.hdf5lib.H5;
+import hdf.hdf5lib.HDF5Constants;
+
+public class H5Ex_T_RegionReference {
+ private static String FILENAME = "H5Ex_T_RegionReference.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 DS2DIM0 = 3;
+ private static final int DS2DIM1 = 16;
+ private static final int RANK = 1;
+
+ private static void writeRegRef()
+ {
+ 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};
+ long[] dims2 = {DS2DIM0, DS2DIM1};
+ // data buffer for writing region reference
+ byte[][] dset_data = new byte[DIM0][HDF5Constants.H5R_REF_BUF_SIZE];
+ // data buffer for writing dataset
+ byte[][] write_data = new byte[DS2DIM0][DS2DIM1];
+ StringBuffer[] str_data = {new StringBuffer("The quick brown"), new StringBuffer("fox jumps over "),
+ new StringBuffer("the 5 lazy dogs")};
+
+ // 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 character data.
+ try {
+ dataspace_id = H5.H5Screate_simple(2, dims2, null);
+ if ((file_id >= 0) && (dataspace_id >= 0)) {
+ dataset_id = H5.H5Dcreate(file_id, DATASETNAME2, HDF5Constants.H5T_STD_I8LE, dataspace_id,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ for (int indx = 0; indx < DS2DIM0; indx++) {
+ for (int jndx = 0; jndx < DS2DIM1; jndx++) {
+ if (jndx < str_data[indx].length())
+ write_data[indx][jndx] = (byte)str_data[indx].charAt(jndx);
+ else
+ write_data[indx][jndx] = 0;
+ }
+ }
+ H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_CHAR, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, write_data);
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Create reference to a list of elements in dset2.
+ try {
+ long[][] coords = {{0, 1}, {2, 11}, {1, 0}, {2, 4}};
+
+ H5.H5Sselect_elements(dataspace_id, HDF5Constants.H5S_SELECT_SET, 4, coords);
+ if (file_id >= 0)
+ dset_data[0] =
+ H5.H5Rcreate_region(file_id, DATASETNAME2, dataspace_id, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+
+ // Create reference to a hyperslab in dset2.
+ try {
+ long[] start = {0, 0}; // Starting location of hyperslab
+ long[] stride = {2, 11}; // Stride of hyperslab
+ long[] count = {2, 2}; // Element count of hyperslab
+ long[] block = {1, 3}; // Block size of hyperslab
+
+ H5.H5Sselect_hyperslab(dataspace_id, HDF5Constants.H5S_SELECT_SET, start, stride, count, block);
+ if (file_id >= 0)
+ dset_data[1] =
+ H5.H5Rcreate_region(file_id, DATASETNAME2, dataspace_id, HDF5Constants.H5P_DEFAULT);
+ ;
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ try {
+ H5.H5Sclose(dataspace_id);
+ }
+ catch (Exception e) {
+ }
+
+ // Create the dataset and write the region references to it.
+ try {
+ dataspace_id = H5.H5Screate_simple(1, dims, null);
+ if ((file_id >= 0) && (dataspace_id >= 0)) {
+ dataset_id = H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_REF, dataspace_id,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ H5.H5Dwrite(dataset_id, HDF5Constants.H5T_STD_REF, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, dset_data);
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ try {
+ H5.H5Rdestroy(dset_data[0]);
+ }
+ catch (Exception ex) {
+ }
+
+ try {
+ H5.H5Rdestroy(dset_data[1]);
+ }
+ catch (Exception ex) {
+ }
+
+ // End access to the dataset and release resources used by it.
+ try {
+ H5.H5Sclose(dataspace_id);
+ }
+ catch (Exception e) {
+ }
+
+ 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 readRegRef()
+ {
+ 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 region_id = HDF5Constants.H5I_INVALID_HID;
+ long[] dims = {DIM0};
+ byte[][] dset_data = new byte[DIM0][HDF5Constants.H5R_REF_BUF_SIZE];
+ StringBuffer str_data;
+
+ // 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.
+ try {
+ object_id = H5.H5Ropen_object(dset_data[indx], HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ try {
+ String obj_name = H5.H5Iget_name(object_id);
+
+ region_id = H5.H5Ropen_region(dset_data[indx], HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ if ((object_id >= 0) && (region_id >= 0)) {
+ try {
+ long reg_npoints = H5.H5Sget_select_npoints(region_id);
+ long[] dims2 = new long[1];
+ dims2[0] = (int)reg_npoints;
+ dataspace_id = H5.H5Screate_simple(1, dims2, null);
+
+ // Read data.
+ byte[] refbuf = new byte[(int)reg_npoints + 1];
+ H5.H5Dread(object_id, HDF5Constants.H5T_NATIVE_CHAR, dataspace_id,
+ region_id, HDF5Constants.H5P_DEFAULT, refbuf);
+ refbuf[(int)reg_npoints] = 0;
+ str_data = new StringBuffer(new String(refbuf).trim());
+
+ System.out.println(" " + obj_name + ": " + str_data);
+ }
+ catch (Throwable err2) {
+ err2.printStackTrace();
+ }
+ }
+ }
+ catch (Throwable err1) {
+ err1.printStackTrace();
+ }
+ finally {
+ try {
+ H5.H5Sclose(region_id);
+ }
+ catch (Exception ex) {
+ }
+ }
+ }
+ catch (Throwable err0) {
+ err0.printStackTrace();
+ }
+ finally {
+ try {
+ H5.H5Dclose(object_id);
+ }
+ catch (Exception ex) {
+ }
+ }
+ try {
+ H5.H5Rdestroy(dset_data[indx]);
+ }
+ catch (Exception e4) {
+ }
+ } // end for
+ }
+ catch (Exception e4) {
+ e4.printStackTrace();
+ }
+ finally {
+ try {
+ H5.H5Sclose(dataspace_id);
+ for (int indx = 0; indx < dims[0]; indx++)
+ H5.H5Rdestroy(dset_data[indx]);
+ }
+ catch (Exception e4) {
+ }
+ }
+ }
+ catch (Exception e3) {
+ e3.printStackTrace();
+ }
+ finally {
+ try {
+ H5.H5Dclose(dataset_id);
+ }
+ catch (Exception e3) {
+ }
+ }
+ }
+ catch (Exception e2) {
+ e2.printStackTrace();
+ }
+ finally {
+ try {
+ H5.H5Fclose(file_id);
+ }
+ catch (Exception e2) {
+ }
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ H5Ex_T_RegionReference.writeRegRef();
+ H5Ex_T_RegionReference.readRegRef();
+ }
+}
diff --git a/HDF5Examples/JAVA/H5T/H5Ex_T_RegionReferenceAttribute.java b/HDF5Examples/JAVA/H5T/H5Ex_T_RegionReferenceAttribute.java
new file mode 100644
index 0000000..f09f15f
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/H5Ex_T_RegionReferenceAttribute.java
@@ -0,0 +1,340 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.
+ ************************************************************/
+
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.Map;
+
+import hdf.hdf5lib.H5;
+import hdf.hdf5lib.HDF5Constants;
+
+public class H5Ex_T_RegionReferenceAttribute {
+ private static String FILENAME = "H5Ex_T_RegionReferenceAttribute.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 DS2DIM0 = 3;
+ private static final int DS2DIM1 = 16;
+ private static final int RANK = 1;
+
+ private static void writeRegRef()
+ {
+ 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 attribute_id = HDF5Constants.H5I_INVALID_HID;
+ long[] dims = {DIM0};
+ long[] dims2 = {DS2DIM0, DS2DIM1};
+ // data buffer for writing region reference
+ byte[][] dset_data = new byte[DIM0][HDF5Constants.H5R_REF_BUF_SIZE];
+ // data buffer for writing dataset
+ byte[][] write_data = new byte[DS2DIM0][DS2DIM1];
+ StringBuffer[] str_data = {new StringBuffer("The quick brown"), new StringBuffer("fox jumps over "),
+ new StringBuffer("the 5 lazy dogs")};
+
+ // 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 character data.
+ try {
+ dataspace_id = H5.H5Screate_simple(2, dims2, null);
+ if ((file_id >= 0) && (dataspace_id >= 0)) {
+ dataset_id = H5.H5Dcreate(file_id, DATASETNAME2, HDF5Constants.H5T_STD_I8LE, dataspace_id,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ for (int indx = 0; indx < DS2DIM0; indx++) {
+ for (int jndx = 0; jndx < DS2DIM1; jndx++) {
+ if (jndx < str_data[indx].length())
+ write_data[indx][jndx] = (byte)str_data[indx].charAt(jndx);
+ else
+ write_data[indx][jndx] = 0;
+ }
+ }
+ H5.H5Dwrite(dataset_id, HDF5Constants.H5T_NATIVE_CHAR, HDF5Constants.H5S_ALL,
+ HDF5Constants.H5S_ALL, HDF5Constants.H5P_DEFAULT, write_data);
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Create reference to a list of elements in dset2.
+ try {
+ long[][] coords = {{0, 1}, {2, 11}, {1, 0}, {2, 4}};
+
+ H5.H5Sselect_elements(dataspace_id, HDF5Constants.H5S_SELECT_SET, 4, coords);
+ if (file_id >= 0)
+ dset_data[0] =
+ H5.H5Rcreate_region(file_id, DATASETNAME2, dataspace_id, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+
+ // Create reference to a hyperslab in dset2.
+ try {
+ long[] start = {0, 0}; // Starting location of hyperslab
+ long[] stride = {2, 11}; // Stride of hyperslab
+ long[] count = {2, 2}; // Element count of hyperslab
+ long[] block = {1, 3}; // Block size of hyperslab
+
+ H5.H5Sselect_hyperslab(dataspace_id, HDF5Constants.H5S_SELECT_SET, start, stride, count, block);
+ if (file_id >= 0)
+ dset_data[1] =
+ H5.H5Rcreate_region(file_id, DATASETNAME2, dataspace_id, HDF5Constants.H5P_DEFAULT);
+ ;
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ try {
+ H5.H5Sclose(dataspace_id);
+ }
+ catch (Exception e) {
+ }
+
+ // Create dataset with a null dataspace to serve as the parent for the attribute.
+ try {
+ dataspace_id = H5.H5Screate(HDF5Constants.H5S_NULL);
+ dataset_id =
+ H5.H5Dcreate(file_id, DATASETNAME, HDF5Constants.H5T_STD_I32LE, dataspace_id,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ try {
+ H5.H5Sclose(dataspace_id);
+ }
+ catch (Exception e) {
+ }
+
+ // Create the attribute and write the region references to it.
+ try {
+ dataspace_id = H5.H5Screate_simple(1, dims, null);
+ if ((file_id >= 0) && (attribute_id >= 0)) {
+ attribute_id = H5.H5Acreate(file_id, ATTRIBUTENAME, HDF5Constants.H5T_STD_REF, dataspace_id,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ H5.H5Awrite(attribute_id, HDF5Constants.H5T_STD_REF, dset_data);
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ try {
+ H5.H5Rdestroy(dset_data[0]);
+ }
+ catch (Exception ex) {
+ }
+
+ try {
+ H5.H5Rdestroy(dset_data[1]);
+ }
+ catch (Exception ex) {
+ }
+
+ // End access to theattribute, dataset and release resources used by it.
+ try {
+ H5.H5Sclose(dataspace_id);
+ }
+ catch (Exception e) {
+ }
+
+ 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 (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 readRegRef()
+ {
+ long file_id = HDF5Constants.H5I_INVALID_HID;
+ long dataset_id = HDF5Constants.H5I_INVALID_HID;
+ long dataspace_id = HDF5Constants.H5I_INVALID_HID;
+ long attribute_id = HDF5Constants.H5I_INVALID_HID;
+ int object_type = -1;
+ long object_id = HDF5Constants.H5I_INVALID_HID;
+ long region_id = HDF5Constants.H5I_INVALID_HID;
+ long[] dims = {DIM0};
+ byte[][] dset_data = new byte[DIM0][HDF5Constants.H5R_REF_BUF_SIZE];
+ StringBuffer str_data;
+
+ // Open an existing file.
+ try {
+ file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
+
+ // Open an existing attribute.
+ try {
+ attribute_id = H5.H5Aopen(file_id, ATTRIBUTENAME, HDF5Constants.H5P_DEFAULT);
+
+ try {
+ // Get dataspace and allocate memory for read buffer.
+ dataspace_id = H5.H5Aget_space(attribute_id);
+ H5.H5Sget_simple_extent_dims(attribute_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(DATASETNAME + "[" + indx + "]:");
+ System.out.print(" ->");
+ // Open the referenced object.
+ try {
+ object_id = H5.H5Ropen_object(dset_data[indx], HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ try {
+ String obj_name = H5.H5Iget_name(object_id);
+
+ region_id = H5.H5Ropen_region(dset_data[indx], HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ if ((object_id >= 0) && (region_id >= 0)) {
+ try {
+ long reg_npoints = H5.H5Sget_select_npoints(region_id);
+ long[] dims2 = new long[1];
+ dims2[0] = (int)reg_npoints;
+ dataspace_id = H5.H5Screate_simple(1, dims2, null);
+
+ // Read data.
+ byte[] refbuf = new byte[(int)reg_npoints + 1];
+ H5.H5Dread(object_id, HDF5Constants.H5T_NATIVE_CHAR, dataspace_id,
+ region_id, HDF5Constants.H5P_DEFAULT, refbuf);
+ refbuf[(int)reg_npoints] = 0;
+ str_data = new StringBuffer(new String(refbuf).trim());
+
+ System.out.println(" " + obj_name + ": " + str_data);
+ }
+ catch (Throwable err2) {
+ err2.printStackTrace();
+ }
+ }
+ }
+ catch (Throwable err1) {
+ err1.printStackTrace();
+ }
+ finally {
+ try {
+ H5.H5Sclose(region_id);
+ }
+ catch (Exception ex) {
+ }
+ }
+ }
+ catch (Throwable err0) {
+ err0.printStackTrace();
+ }
+ finally {
+ try {
+ H5.H5Dclose(object_id);
+ }
+ catch (Exception ex) {
+ }
+ }
+ try {
+ H5.H5Rdestroy(dset_data[indx]);
+ }
+ catch (Exception e4) {
+ }
+ } // end for
+ }
+ catch (Exception e4) {
+ e4.printStackTrace();
+ }
+ finally {
+ try {
+ H5.H5Sclose(dataspace_id);
+ for (int indx = 0; indx < dims[0]; indx++)
+ H5.H5Rdestroy(dset_data[indx]);
+ }
+ catch (Exception e4) {
+ }
+ }
+ }
+ catch (Exception e3) {
+ e3.printStackTrace();
+ }
+ finally {
+ try {
+ H5.H5Aclose(attribute_id);
+ }
+ catch (Exception e3) {
+ }
+ }
+ }
+ catch (Exception e2) {
+ e2.printStackTrace();
+ }
+ finally {
+ try {
+ H5.H5Fclose(file_id);
+ }
+ catch (Exception e2) {
+ }
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ H5Ex_T_RegionReferenceAttribute.writeRegRef();
+ H5Ex_T_RegionReferenceAttribute.readRegRef();
+ }
+}
diff --git a/HDF5Examples/JAVA/H5T/H5Ex_T_String.java b/HDF5Examples/JAVA/H5T/H5Ex_T_String.java
new file mode 100644
index 0000000..fa16464
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/H5Ex_T_String.java
@@ -0,0 +1,307 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.
+ ************************************************************/
+
+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/HDF5Examples/JAVA/H5T/H5Ex_T_StringAttribute.java b/HDF5Examples/JAVA/H5T/H5Ex_T_StringAttribute.java
new file mode 100644
index 0000000..62f4aa0
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/H5Ex_T_StringAttribute.java
@@ -0,0 +1,347 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.
+ ************************************************************/
+
+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/HDF5Examples/JAVA/H5T/H5Ex_T_VLString.java b/HDF5Examples/JAVA/H5T/H5Ex_T_VLString.java
new file mode 100644
index 0000000..d4d74e7
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/H5Ex_T_VLString.java
@@ -0,0 +1,135 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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.
+ ************************************************************/
+
+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/HDF5Examples/JAVA/H5T/JavaDatatypeExample.sh.in b/HDF5Examples/JAVA/H5T/JavaDatatypeExample.sh.in
new file mode 100644
index 0000000..7683798
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/JavaDatatypeExample.sh.in
@@ -0,0 +1,447 @@
+#! /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_DATA_FILES="
+$HDFTEST_HOME/../tfiles/examples.datatypes.H5Ex_T_Array.txt
+$HDFTEST_HOME/../tfiles/examples.datatypes.H5Ex_T_ArrayAttribute.txt
+$HDFTEST_HOME/../tfiles/examples.datatypes.H5Ex_T_Bit.txt
+$HDFTEST_HOME/../tfiles/examples.datatypes.H5Ex_T_BitAttribute.txt
+$HDFTEST_HOME/../tfiles/examples.datatypes.H5Ex_T_Commit.txt
+$HDFTEST_HOME/../tfiles/examples.datatypes.H5Ex_T_Compound.txt
+$HDFTEST_HOME/../tfiles/examples.datatypes.H5Ex_T_CompoundAttribute.txt
+$HDFTEST_HOME/../tfiles/examples.datatypes.H5Ex_T_Float.txt
+$HDFTEST_HOME/../tfiles/examples.datatypes.H5Ex_T_FloatAttribute.txt
+$HDFTEST_HOME/../tfiles/examples.datatypes.H5Ex_T_Integer.txt
+$HDFTEST_HOME/../tfiles/examples.datatypes.H5Ex_T_IntegerAttribute.txt
+$HDFTEST_HOME/../tfiles/examples.datatypes.H5Ex_T_ObjectReference.txt
+$HDFTEST_HOME/../tfiles/examples.datatypes.H5Ex_T_ObjectReferenceAttribute.txt
+$HDFTEST_HOME/../tfiles/examples.datatypes.H5Ex_T_Opaque.txt
+$HDFTEST_HOME/../tfiles/examples.datatypes.H5Ex_T_OpaqueAttribute.txt
+$HDFTEST_HOME/../tfiles/examples.datatypes.H5Ex_T_String.txt
+$HDFTEST_HOME/../tfiles/examples.datatypes.H5Ex_T_StringAttribute.txt
+$HDFTEST_HOME/../tfiles/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":"$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 -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_Array"
+TESTING examples.datatypes.H5Ex_T_Array
+($RUNSERIAL $JAVAEXE $JAVAEXEFLAGS -Xmx1024M -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 -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_ArrayAttribute"
+TESTING examples.datatypes.H5Ex_T_ArrayAttribute
+($RUNSERIAL $JAVAEXE $JAVAEXEFLAGS -Xmx1024M -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 -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_Bit"
+TESTING examples.datatypes.H5Ex_T_Bit
+($RUNSERIAL $JAVAEXE $JAVAEXEFLAGS -Xmx1024M -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 -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_BitAttribute"
+TESTING examples.datatypes.H5Ex_T_BitAttribute
+($RUNSERIAL $JAVAEXE $JAVAEXEFLAGS -Xmx1024M -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 -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_Commit"
+TESTING examples.datasets.H5Ex_T_Commit
+($RUNSERIAL $JAVAEXE $JAVAEXEFLAGS -Xmx1024M -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 -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_Compound"
+TESTING examples.datatypes.H5Ex_T_Compound
+($RUNSERIAL $JAVAEXE $JAVAEXEFLAGS -Xmx1024M -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 -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_CompoundAttribute"
+TESTING examples.datatypes.H5Ex_T_CompoundAttribute
+($RUNSERIAL $JAVAEXE $JAVAEXEFLAGS -Xmx1024M -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 -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_Float"
+TESTING examples.datatypes.H5Ex_T_Float
+($RUNSERIAL $JAVAEXE $JAVAEXEFLAGS -Xmx1024M -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 -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_FloatAttribute"
+TESTING examples.datatypes.H5Ex_T_FloatAttribute
+($RUNSERIAL $JAVAEXE $JAVAEXEFLAGS -Xmx1024M -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 -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_Integer"
+TESTING examples.datatypes.H5Ex_T_Integer
+($RUNSERIAL $JAVAEXE $JAVAEXEFLAGS -Xmx1024M -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 -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_IntegerAttribute"
+TESTING examples.datatypes.H5Ex_T_IntegerAttribute
+($RUNSERIAL $JAVAEXE $JAVAEXEFLAGS -Xmx1024M -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 -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_ObjectReference"
+TESTING examples.datatypes.H5Ex_T_ObjectReference
+($RUNSERIAL $JAVAEXE $JAVAEXEFLAGS -Xmx1024M -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 -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_ObjectReferenceAttribute"
+TESTING examples.datatypes.H5Ex_T_ObjectReferenceAttribute
+($RUNSERIAL $JAVAEXE $JAVAEXEFLAGS -Xmx1024M -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 -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_Opaque"
+TESTING examples.datatypes.H5Ex_T_Opaque
+($RUNSERIAL $JAVAEXE $JAVAEXEFLAGS -Xmx1024M -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 -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_OpaqueAttribute"
+TESTING examples.datatypes.H5Ex_T_OpaqueAttribute
+($RUNSERIAL $JAVAEXE $JAVAEXEFLAGS -Xmx1024M -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 -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_String"
+TESTING examples.datatypes.H5Ex_T_String
+($RUNSERIAL $JAVAEXE $JAVAEXEFLAGS -Xmx1024M -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 -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_StringAttribute"
+TESTING examples.datatypes.H5Ex_T_StringAttribute
+($RUNSERIAL $JAVAEXE $JAVAEXEFLAGS -Xmx1024M -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 -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.datatypes.H5Ex_T_VLString"
+TESTING examples.datatypes.H5Ex_T_VLString
+($RUNSERIAL $JAVAEXE $JAVAEXEFLAGS -Xmx1024M -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/HDF5Examples/JAVA/H5T/Java_sourcefiles.cmake b/HDF5Examples/JAVA/H5T/Java_sourcefiles.cmake
new file mode 100644
index 0000000..43e90c2
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/Java_sourcefiles.cmake
@@ -0,0 +1,36 @@
+#-----------------------------------------------------------------------------
+# Define Sources, one file per application
+#-----------------------------------------------------------------------------
+set (HDF_JAVA_EXAMPLES
+ 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_Opaque.java
+ H5Ex_T_OpaqueAttribute.java
+ H5Ex_T_String.java
+ H5Ex_T_StringAttribute.java
+ H5Ex_T_VLString.java
+)
+if (${H5_LIBVER_DIR} GREATER 18)
+ if (${H5_LIBVER_DIR} EQUAL 110)
+ set (HDF_JAVA_EXAMPLES ${HDF_JAVA_EXAMPLES}
+ 110/H5Ex_T_ObjectReference.java
+ 110/H5Ex_T_ObjectReferenceAttribute.java
+ )
+ else ()
+ set (HDF_JAVA_EXAMPLES ${HDF_JAVA_EXAMPLES}
+ H5Ex_T_ObjectReference.java
+ H5Ex_T_ObjectReferenceAttribute.java
+ H5Ex_T_RegionReference.java
+ H5Ex_T_RegionReferenceAttribute.java
+ )
+ endif ()
+endif ()
diff --git a/HDF5Examples/JAVA/H5T/Makefile.am b/HDF5Examples/JAVA/H5T/Makefile.am
new file mode 100644
index 0000000..2e744ab
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/Makefile.am
@@ -0,0 +1,75 @@
+#
+# 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):$$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
diff --git a/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_Array.txt b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_Array.txt
new file mode 100644
index 0000000..7bcd8fa
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_Array.txt
@@ -0,0 +1,21 @@
+DS1 [0]:
+ [0 0 0 0 0 ]
+ [0 -1 -2 -3 -4 ]
+ [0 -2 -4 -6 -8 ]
+
+DS1 [1]:
+ [0 1 2 3 4 ]
+ [1 1 1 1 1 ]
+ [2 1 0 -1 -2 ]
+
+DS1 [2]:
+ [0 2 4 6 8 ]
+ [2 3 4 5 6 ]
+ [4 4 4 4 4 ]
+
+DS1 [3]:
+ [0 3 6 9 12 ]
+ [3 5 7 9 11 ]
+ [6 7 8 9 10 ]
+
+
diff --git a/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_ArrayAttribute.txt b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_ArrayAttribute.txt
new file mode 100644
index 0000000..7d27c0b
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_ArrayAttribute.txt
@@ -0,0 +1,21 @@
+A1 [0]:
+ [0 0 0 0 0 ]
+ [0 -1 -2 -3 -4 ]
+ [0 -2 -4 -6 -8 ]
+
+A1 [1]:
+ [0 1 2 3 4 ]
+ [1 1 1 1 1 ]
+ [2 1 0 -1 -2 ]
+
+A1 [2]:
+ [0 2 4 6 8 ]
+ [2 3 4 5 6 ]
+ [4 4 4 4 4 ]
+
+A1 [3]:
+ [0 3 6 9 12 ]
+ [3 5 7 9 11 ]
+ [6 7 8 9 10 ]
+
+
diff --git a/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_Bit.txt b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_Bit.txt
new file mode 100644
index 0000000..57769b2
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_Bit.txt
@@ -0,0 +1,6 @@
+DS1:
+ [{0, 0, 0, 0}{3, 0, 1, 1}{2, 0, 2, 2}{1, 0, 3, 3}{0, 0, 0, 0}{3, 0, 1, 1}{2, 0, 2, 2}]
+ [{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}]
+ [{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}]
+ [{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}]
+
diff --git a/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_BitAttribute.txt b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_BitAttribute.txt
new file mode 100644
index 0000000..683bc7f
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_BitAttribute.txt
@@ -0,0 +1,6 @@
+A1:
+ [{0, 0, 0, 0}{3, 0, 1, 1}{2, 0, 2, 2}{1, 0, 3, 3}{0, 0, 0, 0}{3, 0, 1, 1}{2, 0, 2, 2}]
+ [{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}]
+ [{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}]
+ [{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}{0, 0, 0, 0}]
+
diff --git a/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_Commit.txt b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_Commit.txt
new file mode 100644
index 0000000..e6d0bef
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_Commit.txt
@@ -0,0 +1,6 @@
+Named datatype: Sensor_Type:
+ Class: H5T_COMPOUND
+ Serial number
+ Location
+ Temperature (F)
+ Pressure (inHg)
diff --git a/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_Compound.txt b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_Compound.txt
new file mode 100644
index 0000000..0505c78
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_Compound.txt
@@ -0,0 +1,25 @@
+DS1 [0]:
+Serial number : 1153
+Location : Exterior (static)
+Temperature (F) : 53.23
+Pressure (inHg) : 24.57
+
+DS1 [1]:
+Serial number : 1184
+Location : Intake
+Temperature (F) : 55.12
+Pressure (inHg) : 22.95
+
+DS1 [2]:
+Serial number : 1027
+Location : Intake manifold
+Temperature (F) : 103.55
+Pressure (inHg) : 31.23
+
+DS1 [3]:
+Serial number : 1313
+Location : Exhaust manifold
+Temperature (F) : 1252.89
+Pressure (inHg) : 84.11
+
+
diff --git a/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_CompoundAttribute.txt b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_CompoundAttribute.txt
new file mode 100644
index 0000000..dd77f8d
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_CompoundAttribute.txt
@@ -0,0 +1,25 @@
+A1 [0]:
+Serial number : 1153
+Location : Exterior (static)
+Temperature (F) : 53.23
+Pressure (inHg) : 24.57
+
+A1 [1]:
+Serial number : 1184
+Location : Intake
+Temperature (F) : 55.12
+Pressure (inHg) : 22.95
+
+A1 [2]:
+Serial number : 1027
+Location : Intake manifold
+Temperature (F) : 103.55
+Pressure (inHg) : 31.23
+
+A1 [3]:
+Serial number : 1313
+Location : Exhaust manifold
+Temperature (F) : 1252.89
+Pressure (inHg) : 84.11
+
+
diff --git a/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_Float.txt b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_Float.txt
new file mode 100644
index 0000000..85d8ced
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_Float.txt
@@ -0,0 +1,6 @@
+DS1:
+ [ 0.0000 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000]
+ [ 2.0000 1.6667 2.4000 3.2857 4.2222 5.1818 6.1538]
+ [ 4.0000 2.3333 2.8000 3.5714 4.4444 5.3636 6.3077]
+ [ 6.0000 3.0000 3.2000 3.8571 4.6667 5.5455 6.4615]
+
diff --git a/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_FloatAttribute.txt b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_FloatAttribute.txt
new file mode 100644
index 0000000..cfa1f92
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_FloatAttribute.txt
@@ -0,0 +1,6 @@
+A1:
+ [ 0.0000 1.0000 2.0000 3.0000 4.0000 5.0000 6.0000]
+ [ 2.0000 1.6667 2.4000 3.2857 4.2222 5.1818 6.1538]
+ [ 4.0000 2.3333 2.8000 3.5714 4.4444 5.3636 6.3077]
+ [ 6.0000 3.0000 3.2000 3.8571 4.6667 5.5455 6.4615]
+
diff --git a/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_Integer.txt b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_Integer.txt
new file mode 100644
index 0000000..f686bd1
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_Integer.txt
@@ -0,0 +1,6 @@
+DS1:
+ [ 0 -1 -2 -3 -4 -5 -6]
+ [ 0 0 0 0 0 0 0]
+ [ 0 1 2 3 4 5 6]
+ [ 0 2 4 6 8 10 12]
+
diff --git a/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_IntegerAttribute.txt b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_IntegerAttribute.txt
new file mode 100644
index 0000000..dccd4a6
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_IntegerAttribute.txt
@@ -0,0 +1,6 @@
+A1:
+ [ 0 -1 -2 -3 -4 -5 -6]
+ [ 0 0 0 0 0 0 0]
+ [ 0 1 2 3 4 5 6]
+ [ 0 2 4 6 8 10 12]
+
diff --git a/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_ObjectReference.txt b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_ObjectReference.txt
new file mode 100644
index 0000000..d8afa56
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_ObjectReference.txt
@@ -0,0 +1,4 @@
+DS1[0]:
+ ->H5G_GROUP: /G1
+DS1[1]:
+ ->H5G_DATASET: /DS2
diff --git a/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_ObjectReferenceAttribute.txt b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_ObjectReferenceAttribute.txt
new file mode 100644
index 0000000..3fabd66
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_ObjectReferenceAttribute.txt
@@ -0,0 +1,4 @@
+A1[0]:
+ ->H5G_GROUP: /G1
+A1[1]:
+ ->H5G_DATASET: /DS2
diff --git a/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_Opaque.txt b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_Opaque.txt
new file mode 100644
index 0000000..fb74236
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_Opaque.txt
@@ -0,0 +1,6 @@
+Datatype tag for DS1 is: "Character array"
+DS1[0]: OPAQUE0
+DS1[1]: OPAQUE1
+DS1[2]: OPAQUE2
+DS1[3]: OPAQUE3
+
diff --git a/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_OpaqueAttribute.txt b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_OpaqueAttribute.txt
new file mode 100644
index 0000000..bc9a730
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_OpaqueAttribute.txt
@@ -0,0 +1,6 @@
+Datatype tag for A1 is: "Character array"
+A1[0]: OPAQUE0
+A1[1]: OPAQUE1
+A1[2]: OPAQUE2
+A1[3]: OPAQUE3
+
diff --git a/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_RegionReference.txt b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_RegionReference.txt
new file mode 100644
index 0000000..63c1f9e
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_RegionReference.txt
@@ -0,0 +1,4 @@
+DS1[0]:
+ -> /DS2: hdf5
+DS1[1]:
+ -> /DS2: Therowthedog
diff --git a/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_RegionReferenceAttribute.txt b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_RegionReferenceAttribute.txt
new file mode 100644
index 0000000..d50fc76
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_RegionReferenceAttribute.txt
@@ -0,0 +1,4 @@
+A1[0]:
+ -> /DS2: hdf5
+A1[1]:
+ -> /DS2: Therowthedog
diff --git a/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_String.txt b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_String.txt
new file mode 100644
index 0000000..4df6a41
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_String.txt
@@ -0,0 +1,5 @@
+DS1 [0]: Parting
+DS1 [1]: is such
+DS1 [2]: sweet
+DS1 [3]: sorrow.
+
diff --git a/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_StringAttribute.txt b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_StringAttribute.txt
new file mode 100644
index 0000000..4df6a41
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_StringAttribute.txt
@@ -0,0 +1,5 @@
+DS1 [0]: Parting
+DS1 [1]: is such
+DS1 [2]: sweet
+DS1 [3]: sorrow.
+
diff --git a/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_VLString.txt b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_VLString.txt
new file mode 100644
index 0000000..0322953
--- /dev/null
+++ b/HDF5Examples/JAVA/H5T/tfiles/110/H5Ex_T_VLString.txt
@@ -0,0 +1,4 @@
+DS1 [0]: Parting
+DS1 [1]: is such
+DS1 [2]: sweet
+DS1 [3]: sorrow.