summaryrefslogtreecommitdiffstats
path: root/HDF5Examples/JAVA/H5G
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/H5G
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/H5G')
-rw-r--r--HDF5Examples/JAVA/H5G/110/H5Ex_G_Intermediate.java125
-rw-r--r--HDF5Examples/JAVA/H5G/110/H5Ex_G_Iterate.java109
-rw-r--r--HDF5Examples/JAVA/H5G/110/H5Ex_G_Traverse.java166
-rw-r--r--HDF5Examples/JAVA/H5G/110/H5Ex_G_Visit.java153
-rw-r--r--HDF5Examples/JAVA/H5G/110/h5ex_g_iterate.h5bin0 -> 2928 bytes
-rw-r--r--HDF5Examples/JAVA/H5G/110/h5ex_g_visit.h5bin0 -> 6312 bytes
-rw-r--r--HDF5Examples/JAVA/H5G/CMakeLists.txt92
-rw-r--r--HDF5Examples/JAVA/H5G/H5Ex_G_Compact.java259
-rw-r--r--HDF5Examples/JAVA/H5G/H5Ex_G_Corder.java116
-rw-r--r--HDF5Examples/JAVA/H5G/H5Ex_G_Create.java86
-rw-r--r--HDF5Examples/JAVA/H5G/H5Ex_G_Intermediate.java125
-rw-r--r--HDF5Examples/JAVA/H5G/H5Ex_G_Iterate.java110
-rw-r--r--HDF5Examples/JAVA/H5G/H5Ex_G_Phase.java234
-rw-r--r--HDF5Examples/JAVA/H5G/H5Ex_G_Traverse.java166
-rw-r--r--HDF5Examples/JAVA/H5G/H5Ex_G_Visit.java153
-rw-r--r--HDF5Examples/JAVA/H5G/JavaGroupExample.sh.in377
-rw-r--r--HDF5Examples/JAVA/H5G/Java_sourcefiles.cmake24
-rw-r--r--HDF5Examples/JAVA/H5G/Makefile.am65
-rw-r--r--HDF5Examples/JAVA/H5G/h5ex_g_iterate.h5bin0 -> 2928 bytes
-rw-r--r--HDF5Examples/JAVA/H5G/h5ex_g_visit.h5bin0 -> 6312 bytes
-rw-r--r--HDF5Examples/JAVA/H5G/tfiles/110/H5Ex_G_Compact.txt5
-rw-r--r--HDF5Examples/JAVA/H5G/tfiles/110/H5Ex_G_Corder.txt10
-rw-r--r--HDF5Examples/JAVA/H5G/tfiles/110/H5Ex_G_Create.txt0
-rw-r--r--HDF5Examples/JAVA/H5G/tfiles/110/H5Ex_G_Intermediate.txt5
-rw-r--r--HDF5Examples/JAVA/H5G/tfiles/110/H5Ex_G_Iterate.txt5
-rw-r--r--HDF5Examples/JAVA/H5G/tfiles/110/H5Ex_G_Phase.txt15
-rw-r--r--HDF5Examples/JAVA/H5G/tfiles/110/H5Ex_G_Visit.txt19
27 files changed, 2419 insertions, 0 deletions
diff --git a/HDF5Examples/JAVA/H5G/110/H5Ex_G_Intermediate.java b/HDF5Examples/JAVA/H5G/110/H5Ex_G_Intermediate.java
new file mode 100644
index 0000000..cf6d1b4
--- /dev/null
+++ b/HDF5Examples/JAVA/H5G/110/H5Ex_G_Intermediate.java
@@ -0,0 +1,125 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Copyright by The HDF Group. *
+ * All rights reserved. *
+ * *
+ * This file is part of HDF5. The full HDF5 copyright notice, including *
+ * terms governing use, modification, and redistribution, is contained in *
+ * the COPYING file, which can be found at the root of the source code *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
+ * If you do not have access to either file, you may request a copy from *
+ * help@hdfgroup.org. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/************************************************************
+ This example shows how to create intermediate groups with
+ a single call to H5Gcreate.
+ ************************************************************/
+
+import java.util.ArrayList;
+
+import hdf.hdf5lib.H5;
+import hdf.hdf5lib.HDF5Constants;
+import hdf.hdf5lib.callbacks.H5O_iterate_cb;
+import hdf.hdf5lib.callbacks.H5O_iterate_t;
+import hdf.hdf5lib.structs.H5O_info_t;
+
+public class H5Ex_G_Intermediate {
+
+ private static String FILE = "H5Ex_G_Intermediate.h5";
+
+ private void CreateGroup() throws Exception
+ {
+
+ long file_id = HDF5Constants.H5I_INVALID_HID;
+ long group_id = HDF5Constants.H5I_INVALID_HID;
+ long gcpl_id = HDF5Constants.H5I_INVALID_HID;
+
+ try {
+ // Create a new file_id using the default properties.
+ file_id = H5.H5Fcreate(FILE, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+
+ // Create group_id creation property list and set it to allow creation of intermediate group_ids.
+ gcpl_id = H5.H5Pcreate(HDF5Constants.H5P_LINK_CREATE);
+ H5.H5Pset_create_intermediate_group(gcpl_id, true);
+
+ /*
+ * Create the group_id /G1/G2/G3. Note that /G1 and /G1/G2 do not exist yet. This call would cause
+ * an error if we did not use the previously created property list.
+ */
+ group_id = H5.H5Gcreate(file_id, "/G1/G2/G3", gcpl_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ // Print all the objects in the file_ids to show that intermediate group_ids have been created.
+ System.out.println("Objects in the file_id:");
+
+ // H5O_iterate_t iter_data = null;
+ H5O_iterate_t iter_data = new H5O_iter_data();
+ H5O_iterate_cb iter_cb = new H5O_iter_callback();
+
+ H5.H5Ovisit(file_id, HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_NATIVE, iter_cb,
+ iter_data);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ finally {
+ // Close and release resources.
+ if (gcpl_id >= 0)
+ H5.H5Pclose(gcpl_id);
+ if (group_id >= 0)
+ H5.H5Gclose(group_id);
+ if (file_id >= 0)
+ H5.H5Fclose(file_id);
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ try {
+ (new H5Ex_G_Intermediate()).CreateGroup();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ private class idata {
+ public String link_name = null;
+ public int link_type = -1;
+
+ idata(String name, int type)
+ {
+ this.link_name = name;
+ this.link_type = type;
+ }
+ }
+
+ private class H5O_iter_data implements H5O_iterate_t {
+ public ArrayList<idata> iterdata = new ArrayList<idata>();
+ }
+
+ private class H5O_iter_callback implements H5O_iterate_cb {
+ public int callback(long group, String name, H5O_info_t info, H5O_iterate_t op_data)
+ {
+ idata id = new idata(name, info.type);
+ ((H5O_iter_data)op_data).iterdata.add(id);
+
+ System.out.print("/"); /* Print root group in object path */
+
+ // Check if the current object is the root group, and if not print the full path name and type.
+
+ if (name.charAt(0) == '.') /* Root group, do not print '.' */
+ System.out.println(" (Group)");
+ else if (info.type == HDF5Constants.H5O_TYPE_GROUP)
+ System.out.println(name + " (Group)");
+ else if (info.type == HDF5Constants.H5O_TYPE_DATASET)
+ System.out.println(name + " (Dataset)");
+ else if (info.type == HDF5Constants.H5O_TYPE_NAMED_DATATYPE)
+ System.out.println(name + " (Datatype)");
+ else
+ System.out.println(name + " (Unknown)");
+
+ return 0;
+ }
+ }
+}
diff --git a/HDF5Examples/JAVA/H5G/110/H5Ex_G_Iterate.java b/HDF5Examples/JAVA/H5G/110/H5Ex_G_Iterate.java
new file mode 100644
index 0000000..9359483
--- /dev/null
+++ b/HDF5Examples/JAVA/H5G/110/H5Ex_G_Iterate.java
@@ -0,0 +1,109 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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 iterate over group members using
+ H5Gget_obj_info_all.
+ ************************************************************/
+
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.Map;
+
+import hdf.hdf5lib.H5;
+import hdf.hdf5lib.HDF5Constants;
+
+public class H5Ex_G_Iterate {
+ private static String FILENAME = "groups/h5ex_g_iterate.h5";
+ private static String DATASETNAME = "/";
+
+ enum H5O_type {
+ H5O_TYPE_UNKNOWN(-1), // Unknown object type
+ H5O_TYPE_GROUP(0), // Object is a group
+ H5O_TYPE_DATASET(1), // Object is a dataset
+ H5O_TYPE_NAMED_DATATYPE(2), // Object is a named data type
+ H5O_TYPE_NTYPES(3); // Number of different object types
+ private static final Map<Integer, H5O_type> lookup = new HashMap<Integer, H5O_type>();
+
+ static
+ {
+ for (H5O_type s : EnumSet.allOf(H5O_type.class))
+ lookup.put(s.getCode(), s);
+ }
+
+ private int code;
+
+ H5O_type(int layout_type) { this.code = layout_type; }
+
+ public int getCode() { return this.code; }
+
+ public static H5O_type get(int code) { return lookup.get(code); }
+ }
+
+ private static void do_iterate()
+ {
+ long file_id = HDF5Constants.H5I_INVALID_HID;
+
+ // Open a file using default properties.
+ try {
+ file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Begin iteration.
+ System.out.println("Objects in root group:");
+ try {
+ if (file_id >= 0) {
+ int count = (int)H5.H5Gn_members(file_id, DATASETNAME);
+ String[] oname = new String[count];
+ int[] otype = new int[count];
+ int[] ltype = new int[count];
+ long[] orefs = new long[count];
+ H5.H5Gget_obj_info_all(file_id, DATASETNAME, oname, otype, ltype, orefs,
+ HDF5Constants.H5_INDEX_NAME);
+
+ // Get type of the object and display its name and type.
+ for (int indx = 0; indx < otype.length; indx++) {
+ switch (H5O_type.get(otype[indx])) {
+ case H5O_TYPE_GROUP:
+ System.out.println(" Group: " + oname[indx]);
+ break;
+ case H5O_TYPE_DATASET:
+ System.out.println(" Dataset: " + oname[indx]);
+ break;
+ case H5O_TYPE_NAMED_DATATYPE:
+ System.out.println(" Datatype: " + oname[indx]);
+ break;
+ default:
+ System.out.println(" Unknown: " + oname[indx]);
+ }
+ }
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Close the file.
+ try {
+ if (file_id >= 0)
+ H5.H5Fclose(file_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static void main(String[] args) { H5Ex_G_Iterate.do_iterate(); }
+}
diff --git a/HDF5Examples/JAVA/H5G/110/H5Ex_G_Traverse.java b/HDF5Examples/JAVA/H5G/110/H5Ex_G_Traverse.java
new file mode 100644
index 0000000..0ef0e39
--- /dev/null
+++ b/HDF5Examples/JAVA/H5G/110/H5Ex_G_Traverse.java
@@ -0,0 +1,166 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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 a way to recursively traverse the file
+using H5Literate. The method shown here guarantees that
+the recursion will not enter an infinite loop, but does
+not prevent objects from being visited more than once.
+The program prints the directory structure of the file
+specified in FILE. The default file used by this example
+implements the structure described in the User Guide,
+chapter 4, figure 26.
+ ************************************************************/
+
+import hdf.hdf5lib.H5;
+import hdf.hdf5lib.HDF5Constants;
+import hdf.hdf5lib.callbacks.H5L_iterate_cb;
+import hdf.hdf5lib.callbacks.H5L_iterate_t;
+import hdf.hdf5lib.structs.H5L_info_t;
+import hdf.hdf5lib.structs.H5O_info_t;
+
+import examples.groups.H5Ex_G_Iterate.H5O_type;
+
+class opdata implements H5L_iterate_t {
+ int recurs;
+ opdata prev;
+ long addr;
+}
+
+public class H5Ex_G_Traverse {
+
+ private static String FILE = "h5ex_g_traverse.h5";
+ public static H5L_iterate_cb iter_cb = new H5L_iter_callbackT();
+
+ private static void OpenGroup()
+ {
+ long file_id = HDF5Constants.H5I_INVALID_HID;
+ H5O_info_t infobuf;
+ opdata od = new opdata();
+
+ // Open file and initialize the operator data structure.
+ try {
+ file_id = H5.H5Fopen(FILE, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
+ if (file_id >= 0) {
+ infobuf = H5.H5Oget_info(file_id);
+ od.recurs = 0;
+ od.prev = null;
+ od.addr = infobuf.addr;
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Print the root group and formatting, begin iteration.
+ try {
+ System.out.println("/ {");
+ // H5L_iterate_cb iter_cb = new H5L_iter_callbackT();
+ H5.H5Literate(file_id, HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_NATIVE, 0L, iter_cb,
+ od);
+ System.out.println("}");
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Close and release resources.
+ try {
+ if (file_id >= 0)
+ H5.H5Fclose(file_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static void main(String[] args) { H5Ex_G_Traverse.OpenGroup(); }
+}
+
+class H5L_iter_callbackT implements H5L_iterate_cb {
+ public int callback(long group, String name, H5L_info_t info, H5L_iterate_t op_data)
+ {
+
+ H5O_info_t infobuf;
+ int return_val = 0;
+ opdata od = (opdata)op_data; // Type conversion
+ int spaces = 2 * (od.recurs + 1); // Number of white spaces to prepend to output.
+
+ // Get type of the object and display its name and type.
+ // The name of the object is passed to this function by the Library.
+ try {
+ infobuf = H5.H5Oget_info_by_name(group, name, HDF5Constants.H5P_DEFAULT);
+
+ for (int i = 0; i < spaces; i++)
+ System.out.print(" "); // Format output.
+ switch (H5O_type.get(infobuf.type)) {
+ case H5O_TYPE_GROUP:
+ System.out.println("Group: " + name + " { ");
+ // Check group address against linked list of operator
+ // data structures. We will always run the check, as the
+ // reference count cannot be relied upon if there are
+ // symbolic links, and H5Oget_info_by_name always follows
+ // symbolic links. Alternatively we could use H5Lget_info
+ // and never recurse on groups discovered by symbolic
+ // links, however it could still fail if an object's
+ // reference count was manually manipulated with
+ // H5Odecr_refcount.
+ if (group_check(od, infobuf.addr)) {
+ for (int i = 0; i < spaces; i++)
+ System.out.print(" ");
+ System.out.println(" Warning: Loop detected!");
+ }
+ else {
+ // Initialize new object of type opdata and begin
+ // recursive iteration on the discovered
+ // group. The new opdata is given a pointer to the
+ // current one.
+ opdata nextod = new opdata();
+ nextod.recurs = od.recurs + 1;
+ nextod.prev = od;
+ nextod.addr = infobuf.addr;
+ H5L_iterate_cb iter_cb2 = new H5L_iter_callbackT();
+ return_val = H5.H5Literate_by_name(group, name, HDF5Constants.H5_INDEX_NAME,
+ HDF5Constants.H5_ITER_NATIVE, 0L, iter_cb2, nextod,
+ HDF5Constants.H5P_DEFAULT);
+ }
+ for (int i = 0; i < spaces; i++)
+ System.out.print(" ");
+ System.out.println("}");
+ break;
+ case H5O_TYPE_DATASET:
+ System.out.println("Dataset: " + name);
+ break;
+ case H5O_TYPE_NAMED_DATATYPE:
+ System.out.println("Datatype: " + name);
+ break;
+ default:
+ System.out.println("Unknown: " + name);
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return return_val;
+ }
+
+ public boolean group_check(opdata od, long target_addr)
+ {
+ if (od.addr == target_addr)
+ return true; // Addresses match
+ else if (od.recurs == 0)
+ return false; // Root group reached with no matches
+ else
+ return group_check(od.prev, target_addr); // Recursively examine the next node
+ }
+}
diff --git a/HDF5Examples/JAVA/H5G/110/H5Ex_G_Visit.java b/HDF5Examples/JAVA/H5G/110/H5Ex_G_Visit.java
new file mode 100644
index 0000000..8e81ff3
--- /dev/null
+++ b/HDF5Examples/JAVA/H5G/110/H5Ex_G_Visit.java
@@ -0,0 +1,153 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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 recursively traverse a file
+ using H5Ovisit and H5Lvisit. The program prints all of
+ the objects in the file specified in FILE, then prints all
+ of the links in that file. The default file used by this
+ example implements the structure described in the User
+ Guide, chapter 4, figure 26.
+ ************************************************************/
+
+import java.util.ArrayList;
+
+import hdf.hdf5lib.H5;
+import hdf.hdf5lib.HDF5Constants;
+import hdf.hdf5lib.callbacks.H5L_iterate_cb;
+import hdf.hdf5lib.callbacks.H5L_iterate_t;
+import hdf.hdf5lib.callbacks.H5O_iterate_cb;
+import hdf.hdf5lib.callbacks.H5O_iterate_t;
+import hdf.hdf5lib.structs.H5L_info_t;
+import hdf.hdf5lib.structs.H5O_info_t;
+
+public class H5Ex_G_Visit {
+
+ private static String FILE = "groups/h5ex_g_visit.h5";
+
+ public static void main(String[] args)
+ {
+ try {
+ (new H5Ex_G_Visit()).VisitGroup();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ private void VisitGroup() throws Exception
+ {
+
+ long file_id = HDF5Constants.H5I_INVALID_HID;
+
+ try {
+ // Open file
+ file_id = H5.H5Fopen(FILE, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
+
+ // Begin iteration using H5Ovisit
+ System.out.println("Objects in the file:");
+ H5O_iterate_t iter_data = new H5O_iter_data();
+ H5O_iterate_cb iter_cb = new H5O_iter_callback();
+ H5.H5Ovisit(file_id, HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_NATIVE, iter_cb,
+ iter_data);
+ System.out.println();
+ // Repeat the same process using H5Lvisit
+ H5L_iterate_t iter_data2 = new H5L_iter_data();
+ H5L_iterate_cb iter_cb2 = new H5L_iter_callback();
+ System.out.println("Links in the file:");
+ H5.H5Lvisit(file_id, HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_NATIVE, iter_cb2,
+ iter_data2);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ finally {
+ // Close and release resources.
+ if (file_id >= 0)
+ H5.H5Fclose(file_id);
+ }
+ }
+
+ /************************************************************
+ * Operator function for H5Lvisit. This function simply retrieves the info for the object the current link
+ *points to, and calls the operator function for H5Ovisit.
+ ************************************************************/
+
+ private class idata {
+ public String link_name = null;
+ public int link_type = -1;
+
+ idata(String name, int type)
+ {
+ this.link_name = name;
+ this.link_type = type;
+ }
+ }
+
+ private class H5L_iter_data implements H5L_iterate_t {
+ public ArrayList<idata> iterdata = new ArrayList<idata>();
+ }
+
+ private class H5L_iter_callback implements H5L_iterate_cb {
+ public int callback(long group, String name, H5L_info_t info, H5L_iterate_t op_data)
+ {
+
+ idata id = new idata(name, info.type);
+ ((H5L_iter_data)op_data).iterdata.add(id);
+
+ H5O_info_t infobuf;
+ int ret = 0;
+ try {
+ // Get type of the object and display its name and type. The name of the object is passed to
+ // this function by the Library.
+ infobuf = H5.H5Oget_info_by_name(group, name, HDF5Constants.H5P_DEFAULT);
+ H5O_iterate_cb iter_cbO = new H5O_iter_callback();
+ H5O_iterate_t iter_dataO = new H5O_iter_data();
+ ret = iter_cbO.callback(group, name, infobuf, iter_dataO);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return ret;
+ }
+ }
+
+ private class H5O_iter_data implements H5O_iterate_t {
+ public ArrayList<idata> iterdata = new ArrayList<idata>();
+ }
+
+ private class H5O_iter_callback implements H5O_iterate_cb {
+ public int callback(long group, String name, H5O_info_t info, H5O_iterate_t op_data)
+ {
+ idata id = new idata(name, info.type);
+ ((H5O_iter_data)op_data).iterdata.add(id);
+
+ System.out.print("/"); /* Print root group in object path */
+
+ // Check if the current object is the root group, and if not print the full path name and type.
+
+ if (name.charAt(0) == '.') /* Root group, do not print '.' */
+ System.out.println(" (Group)");
+ else if (info.type == HDF5Constants.H5O_TYPE_GROUP)
+ System.out.println(name + " (Group)");
+ else if (info.type == HDF5Constants.H5O_TYPE_DATASET)
+ System.out.println(name + " (Dataset)");
+ else if (info.type == HDF5Constants.H5O_TYPE_NAMED_DATATYPE)
+ System.out.println(name + " (Datatype)");
+ else
+ System.out.println(name + " (Unknown)");
+
+ return 0;
+ }
+ }
+}
diff --git a/HDF5Examples/JAVA/H5G/110/h5ex_g_iterate.h5 b/HDF5Examples/JAVA/H5G/110/h5ex_g_iterate.h5
new file mode 100644
index 0000000..e462703
--- /dev/null
+++ b/HDF5Examples/JAVA/H5G/110/h5ex_g_iterate.h5
Binary files differ
diff --git a/HDF5Examples/JAVA/H5G/110/h5ex_g_visit.h5 b/HDF5Examples/JAVA/H5G/110/h5ex_g_visit.h5
new file mode 100644
index 0000000..d8267b1
--- /dev/null
+++ b/HDF5Examples/JAVA/H5G/110/h5ex_g_visit.h5
Binary files differ
diff --git a/HDF5Examples/JAVA/H5G/CMakeLists.txt b/HDF5Examples/JAVA/H5G/CMakeLists.txt
new file mode 100644
index 0000000..5f47d59
--- /dev/null
+++ b/HDF5Examples/JAVA/H5G/CMakeLists.txt
@@ -0,0 +1,92 @@
+cmake_minimum_required (VERSION 3.18)
+project (HDF5Examples_JAVA_GROUPS 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/H5G/H5Ex_G_Compact.java b/HDF5Examples/JAVA/H5G/H5Ex_G_Compact.java
new file mode 100644
index 0000000..865040e
--- /dev/null
+++ b/HDF5Examples/JAVA/H5G/H5Ex_G_Compact.java
@@ -0,0 +1,259 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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 a file and print the storage layout.
+ ************************************************************/
+
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.Map;
+
+import hdf.hdf5lib.H5;
+import hdf.hdf5lib.HDF5Constants;
+import hdf.hdf5lib.structs.H5G_info_t;
+
+public class H5Ex_G_Compact {
+
+ private static final String FILE1 = "H5Ex_G_Compact1.h5";
+ private static final String FILE2 = "H5Ex_G_Compact2.h5";
+ private static final String GROUP = "G1";
+
+ enum H5G_storage {
+ H5G_STORAGE_TYPE_UNKNOWN(-1),
+ H5G_STORAGE_TYPE_SYMBOL_TABLE(0),
+ H5G_STORAGE_TYPE_COMPACT(1),
+ H5G_STORAGE_TYPE_DENSE(2);
+
+ private static final Map<Integer, H5G_storage> lookup = new HashMap<Integer, H5G_storage>();
+
+ static
+ {
+ for (H5G_storage s : EnumSet.allOf(H5G_storage.class))
+ lookup.put(s.getCode(), s);
+ }
+
+ private int code;
+
+ H5G_storage(int layout_type) { this.code = layout_type; }
+
+ public int getCode() { return this.code; }
+
+ public static H5G_storage get(int code) { return lookup.get(code); }
+ }
+
+ public static void CreateGroup()
+ {
+ long file_id = HDF5Constants.H5I_INVALID_HID;
+ long group_id = HDF5Constants.H5I_INVALID_HID;
+ long fapl_id = HDF5Constants.H5I_INVALID_HID;
+ H5G_info_t ginfo;
+ long size;
+
+ // Create file 1. This file will use original format groups.
+ try {
+ file_id = H5.H5Fcreate(FILE1, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ // Create a group in the file1.
+ try {
+ if (file_id >= 0)
+ group_id = H5.H5Gcreate(file_id, GROUP, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Obtain the group info and print the group storage type.
+ try {
+ if (group_id >= 0) {
+ ginfo = H5.H5Gget_info(group_id);
+ System.out.print("Group storage type for " + FILE1 + " is: ");
+ switch (H5G_storage.get(ginfo.storage_type)) {
+ case H5G_STORAGE_TYPE_COMPACT:
+ System.out.println("H5G_STORAGE_TYPE_COMPACT"); // New compact format
+ break;
+ case H5G_STORAGE_TYPE_DENSE:
+ System.out.println("H5G_STORAGE_TYPE_DENSE"); // New dense (indexed) format
+ break;
+ case H5G_STORAGE_TYPE_SYMBOL_TABLE:
+ System.out.println("H5G_STORAGE_TYPE_SYMBOL_TABLE"); // Original format
+ break;
+ case H5G_STORAGE_TYPE_UNKNOWN:
+ System.out.println("H5G_STORAGE_TYPE_UNKNOWN");
+ break;
+ default:
+ System.out.println("Storage Type Invalid");
+ break;
+ }
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Close the group.
+ try {
+ if (group_id >= 0)
+ H5.H5Gclose(group_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // close the file 1.
+ try {
+ if (file_id >= 0)
+ H5.H5Fclose(file_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Re-open file 1. Need to get the correct file size.
+ try {
+ file_id = H5.H5Fopen(FILE1, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Obtain and print the file size.
+ try {
+ if (file_id >= 0) {
+ size = H5.H5Fget_filesize(file_id);
+ System.out.println("File size for " + FILE1 + " is: " + size + " bytes");
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Close FILE1.
+ try {
+ if (file_id >= 0)
+ H5.H5Fclose(file_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Set file access property list to allow the latest file format.
+ // This will allow the library to create new compact format groups.
+ try {
+ fapl_id = H5.H5Pcreate(HDF5Constants.H5P_FILE_ACCESS);
+ if (fapl_id >= 0)
+ H5.H5Pset_libver_bounds(fapl_id, HDF5Constants.H5F_LIBVER_LATEST,
+ HDF5Constants.H5F_LIBVER_LATEST);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ System.out.println();
+ // Create file 2 using the new file access property list.
+ try {
+ file_id = H5.H5Fcreate(FILE2, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, fapl_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ // Create group in file2.
+ try {
+ if (file_id >= 0)
+ group_id = H5.H5Gcreate(file_id, GROUP, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Obtain the group info and print the group storage type.
+ try {
+ if (group_id >= 0) {
+ ginfo = H5.H5Gget_info(group_id);
+ System.out.print("Group storage type for " + FILE2 + " is: ");
+ switch (H5G_storage.get(ginfo.storage_type)) {
+ case H5G_STORAGE_TYPE_COMPACT:
+ System.out.println("H5G_STORAGE_TYPE_COMPACT"); // New compact format
+ break;
+ case H5G_STORAGE_TYPE_DENSE:
+ System.out.println("H5G_STORAGE_TYPE_DENSE"); // New dense (indexed) format
+ break;
+ case H5G_STORAGE_TYPE_SYMBOL_TABLE:
+ System.out.println("H5G_STORAGE_TYPE_SYMBOL_TABLE"); // Original format
+ break;
+ case H5G_STORAGE_TYPE_UNKNOWN:
+ System.out.println("H5G_STORAGE_TYPE_UNKNOWN");
+ break;
+ default:
+ System.out.println("Storage Type Invalid");
+ break;
+ }
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Close the group.
+ try {
+ if (group_id >= 0)
+ H5.H5Gclose(group_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // close the file 2.
+ try {
+ if (file_id >= 0)
+ H5.H5Fclose(file_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Re-open file 2. Needed to get the correct file size.
+ try {
+ file_id = H5.H5Fopen(FILE2, HDF5Constants.H5F_ACC_RDONLY, fapl_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Obtain and print the file size.
+ try {
+ if (file_id >= 0) {
+ size = H5.H5Fget_filesize(file_id);
+ System.out.println("File size for " + FILE2 + " is: " + size + " bytes");
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Close FILE2.
+ try {
+ if (file_id >= 0)
+ H5.H5Fclose(file_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static void main(String[] args) { H5Ex_G_Compact.CreateGroup(); }
+}
diff --git a/HDF5Examples/JAVA/H5G/H5Ex_G_Corder.java b/HDF5Examples/JAVA/H5G/H5Ex_G_Corder.java
new file mode 100644
index 0000000..23d1840
--- /dev/null
+++ b/HDF5Examples/JAVA/H5G/H5Ex_G_Corder.java
@@ -0,0 +1,116 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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 a file with creation properties and traverse the
+ groups in alphabetical and creation order.
+ ************************************************************/
+
+import hdf.hdf5lib.H5;
+import hdf.hdf5lib.HDF5Constants;
+import hdf.hdf5lib.structs.H5G_info_t;
+
+public class H5Ex_G_Corder {
+ private static String FILE = "H5Ex_G_Corder.h5";
+
+ private static void CreateGroup() throws Exception
+ {
+ long file_id = HDF5Constants.H5I_INVALID_HID;
+ long group_id = HDF5Constants.H5I_INVALID_HID;
+ long subgroup_id = HDF5Constants.H5I_INVALID_HID;
+ long gcpl_id = HDF5Constants.H5I_INVALID_HID;
+ int status;
+ H5G_info_t ginfo;
+ int i;
+ String name;
+
+ try {
+ // Create a new file using default properties.
+ file_id = H5.H5Fcreate(FILE, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+
+ // Create group creation property list and enable link creation order tracking.
+ gcpl_id = H5.H5Pcreate(HDF5Constants.H5P_GROUP_CREATE);
+ status = H5.H5Pset_link_creation_order(gcpl_id, HDF5Constants.H5P_CRT_ORDER_TRACKED +
+ HDF5Constants.H5P_CRT_ORDER_INDEXED);
+
+ // Create primary group using the property list.
+ if (status >= 0)
+ group_id = H5.H5Gcreate(file_id, "index_group", HDF5Constants.H5P_DEFAULT, gcpl_id,
+ HDF5Constants.H5P_DEFAULT);
+
+ try {
+ /*
+ * Create subgroups in the primary group. These will be tracked by creation order. Note that
+ * these groups do not have to have the creation order tracking property set.
+ */
+ subgroup_id = H5.H5Gcreate(group_id, "H", HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ status = H5.H5Gclose(subgroup_id);
+ subgroup_id = H5.H5Gcreate(group_id, "D", HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ status = H5.H5Gclose(subgroup_id);
+ subgroup_id = H5.H5Gcreate(group_id, "F", HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ status = H5.H5Gclose(subgroup_id);
+ subgroup_id = H5.H5Gcreate(group_id, "5", HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ status = H5.H5Gclose(subgroup_id);
+
+ // Get group info.
+ ginfo = H5.H5Gget_info(group_id);
+
+ // Traverse links in the primary group using alphabetical indices (H5_INDEX_NAME).
+ System.out.println("Traversing group using alphabetical indices:");
+ for (i = 0; i < ginfo.nlinks; i++) {
+ // Retrieve the name of the ith link in a group
+ name = H5.H5Lget_name_by_idx(group_id, ".", HDF5Constants.H5_INDEX_NAME,
+ HDF5Constants.H5_ITER_INC, i, HDF5Constants.H5P_DEFAULT);
+ System.out.println("Index " + i + ": " + name);
+ }
+
+ // Traverse links in the primary group by creation order (H5_INDEX_CRT_ORDER).
+ System.out.println("Traversing group using creation order indices:");
+ for (i = 0; i < ginfo.nlinks; i++) {
+ // Retrieve the name of the ith link in a group
+ name = H5.H5Lget_name_by_idx(group_id, ".", HDF5Constants.H5_INDEX_CRT_ORDER,
+ HDF5Constants.H5_ITER_INC, i, HDF5Constants.H5P_DEFAULT);
+ System.out.println("Index " + i + ": " + name);
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ finally {
+ // Close and release resources.
+ if (gcpl_id >= 0)
+ H5.H5Pclose(gcpl_id);
+ if (group_id >= 0)
+ H5.H5Gclose(group_id);
+ if (file_id >= 0)
+ H5.H5Fclose(file_id);
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ try {
+ H5Ex_G_Corder.CreateGroup();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+}
diff --git a/HDF5Examples/JAVA/H5G/H5Ex_G_Create.java b/HDF5Examples/JAVA/H5G/H5Ex_G_Create.java
new file mode 100644
index 0000000..b842af6
--- /dev/null
+++ b/HDF5Examples/JAVA/H5G/H5Ex_G_Create.java
@@ -0,0 +1,86 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Copyright by The HDF Group. *
+ * All rights reserved. *
+ * *
+ * This file is part of HDF5. The full HDF5 copyright notice, including *
+ * terms governing use, modification, and redistribution, is contained in *
+ * the COPYING file, which can be found at the root of the source code *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
+ * If you do not have access to either file, you may request a copy from *
+ * help@hdfgroup.org. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/************************************************************
+ This example shows how to create, open, and close a group.
+ ************************************************************/
+
+import hdf.hdf5lib.H5;
+import hdf.hdf5lib.HDF5Constants;
+
+public class H5Ex_G_Create {
+ private static String FILENAME = "H5Ex_G_Create.h5";
+ private static String GROUPNAME = "G1";
+
+ private static void CreateGroup()
+ {
+ long file_id = HDF5Constants.H5I_INVALID_HID;
+ long group_id = HDF5Constants.H5I_INVALID_HID;
+
+ // Create a new file using default properties.
+ try {
+ file_id = H5.H5Fcreate(FILENAME, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Create a group in the file.
+ try {
+ if (file_id >= 0)
+ group_id = H5.H5Gcreate(file_id, "/" + GROUPNAME, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Close the group. The handle "group" can no longer be used.
+ try {
+ if (group_id >= 0)
+ H5.H5Gclose(group_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Re-open the group, obtaining a new handle.
+ try {
+ if (file_id >= 0)
+ group_id = H5.H5Gopen(file_id, "/" + GROUPNAME, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Close the group.
+ try {
+ if (group_id >= 0)
+ H5.H5Gclose(group_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Close the file.
+ try {
+ if (file_id >= 0)
+ H5.H5Fclose(file_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static void main(String[] args) { H5Ex_G_Create.CreateGroup(); }
+}
diff --git a/HDF5Examples/JAVA/H5G/H5Ex_G_Intermediate.java b/HDF5Examples/JAVA/H5G/H5Ex_G_Intermediate.java
new file mode 100644
index 0000000..5461725
--- /dev/null
+++ b/HDF5Examples/JAVA/H5G/H5Ex_G_Intermediate.java
@@ -0,0 +1,125 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * Copyright by The HDF Group. *
+ * All rights reserved. *
+ * *
+ * This file is part of HDF5. The full HDF5 copyright notice, including *
+ * terms governing use, modification, and redistribution, is contained in *
+ * the COPYING file, which can be found at the root of the source code *
+ * distribution tree, or in https://www.hdfgroup.org/licenses. *
+ * If you do not have access to either file, you may request a copy from *
+ * help@hdfgroup.org. *
+ * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+
+/************************************************************
+ This example shows how to create intermediate groups with
+ a single call to H5Gcreate.
+ ************************************************************/
+
+import java.util.ArrayList;
+
+import hdf.hdf5lib.H5;
+import hdf.hdf5lib.HDF5Constants;
+import hdf.hdf5lib.callbacks.H5O_iterate_opdata_t;
+import hdf.hdf5lib.callbacks.H5O_iterate_t;
+import hdf.hdf5lib.structs.H5O_info_t;
+
+public class H5Ex_G_Intermediate {
+
+ private static String FILE = "H5Ex_G_Intermediate.h5";
+
+ private void CreateGroup() throws Exception
+ {
+
+ long file_id = HDF5Constants.H5I_INVALID_HID;
+ long group_id = HDF5Constants.H5I_INVALID_HID;
+ long gcpl_id = HDF5Constants.H5I_INVALID_HID;
+
+ try {
+ // Create a new file_id using the default properties.
+ file_id = H5.H5Fcreate(FILE, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+
+ // Create group_id creation property list and set it to allow creation of intermediate group_ids.
+ gcpl_id = H5.H5Pcreate(HDF5Constants.H5P_LINK_CREATE);
+ H5.H5Pset_create_intermediate_group(gcpl_id, true);
+
+ /*
+ * Create the group_id /G1/G2/G3. Note that /G1 and /G1/G2 do not exist yet. This call would cause
+ * an error if we did not use the previously created property list.
+ */
+ group_id = H5.H5Gcreate(file_id, "/G1/G2/G3", gcpl_id, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT);
+ // Print all the objects in the file_ids to show that intermediate group_ids have been created.
+ System.out.println("Objects in the file_id:");
+
+ // H5O_iterate_opdata_t iter_data = null;
+ H5O_iterate_opdata_t iter_data = new H5O_iter_data();
+ H5O_iterate_t iter_cb = new H5O_iter_callback();
+
+ H5.H5Ovisit(file_id, HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_NATIVE, iter_cb,
+ iter_data);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ finally {
+ // Close and release resources.
+ if (gcpl_id >= 0)
+ H5.H5Pclose(gcpl_id);
+ if (group_id >= 0)
+ H5.H5Gclose(group_id);
+ if (file_id >= 0)
+ H5.H5Fclose(file_id);
+ }
+ }
+
+ public static void main(String[] args)
+ {
+ try {
+ (new H5Ex_G_Intermediate()).CreateGroup();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ private class idata {
+ public String link_name = null;
+ public int link_type = -1;
+
+ idata(String name, int type)
+ {
+ this.link_name = name;
+ this.link_type = type;
+ }
+ }
+
+ private class H5O_iter_data implements H5O_iterate_opdata_t {
+ public ArrayList<idata> iterdata = new ArrayList<idata>();
+ }
+
+ private class H5O_iter_callback implements H5O_iterate_t {
+ public int callback(long group, String name, H5O_info_t info, H5O_iterate_opdata_t op_data)
+ {
+ idata id = new idata(name, info.type);
+ ((H5O_iter_data)op_data).iterdata.add(id);
+
+ System.out.print("/"); /* Print root group in object path */
+
+ // Check if the current object is the root group, and if not print the full path name and type.
+
+ if (name.charAt(0) == '.') /* Root group, do not print '.' */
+ System.out.println(" (Group)");
+ else if (info.type == HDF5Constants.H5O_TYPE_GROUP)
+ System.out.println(name + " (Group)");
+ else if (info.type == HDF5Constants.H5O_TYPE_DATASET)
+ System.out.println(name + " (Dataset)");
+ else if (info.type == HDF5Constants.H5O_TYPE_NAMED_DATATYPE)
+ System.out.println(name + " (Datatype)");
+ else
+ System.out.println(name + " (Unknown)");
+
+ return 0;
+ }
+ }
+}
diff --git a/HDF5Examples/JAVA/H5G/H5Ex_G_Iterate.java b/HDF5Examples/JAVA/H5G/H5Ex_G_Iterate.java
new file mode 100644
index 0000000..86d9eb4
--- /dev/null
+++ b/HDF5Examples/JAVA/H5G/H5Ex_G_Iterate.java
@@ -0,0 +1,110 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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 iterate over group members using
+ H5Gget_obj_info_all.
+ ************************************************************/
+
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.Map;
+
+import hdf.hdf5lib.H5;
+import hdf.hdf5lib.HDF5Constants;
+import hdf.hdf5lib.structs.H5O_token_t;
+
+public class H5Ex_G_Iterate {
+ private static String FILENAME = "groups/h5ex_g_iterate.h5";
+ private static String DATASETNAME = "/";
+
+ enum H5O_type {
+ H5O_TYPE_UNKNOWN(-1), // Unknown object type
+ H5O_TYPE_GROUP(0), // Object is a group
+ H5O_TYPE_DATASET(1), // Object is a dataset
+ H5O_TYPE_NAMED_DATATYPE(2), // Object is a named data type
+ H5O_TYPE_NTYPES(3); // Number of different object types
+ private static final Map<Integer, H5O_type> lookup = new HashMap<Integer, H5O_type>();
+
+ static
+ {
+ for (H5O_type s : EnumSet.allOf(H5O_type.class))
+ lookup.put(s.getCode(), s);
+ }
+
+ private int code;
+
+ H5O_type(int layout_type) { this.code = layout_type; }
+
+ public int getCode() { return this.code; }
+
+ public static H5O_type get(int code) { return lookup.get(code); }
+ }
+
+ private static void do_iterate()
+ {
+ long file_id = HDF5Constants.H5I_INVALID_HID;
+
+ // Open a file using default properties.
+ try {
+ file_id = H5.H5Fopen(FILENAME, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Begin iteration.
+ System.out.println("Objects in root group:");
+ try {
+ if (file_id >= 0) {
+ int count = (int)H5.H5Gn_members(file_id, DATASETNAME);
+ String[] oname = new String[count];
+ int[] otype = new int[count];
+ int[] ltype = new int[count];
+ H5O_token_t[] otokens = new H5O_token_t[count];
+ H5.H5Gget_obj_info_all(file_id, DATASETNAME, oname, otype, ltype, otokens,
+ HDF5Constants.H5_INDEX_NAME);
+
+ // Get type of the object and display its name and type.
+ for (int indx = 0; indx < otype.length; indx++) {
+ switch (H5O_type.get(otype[indx])) {
+ case H5O_TYPE_GROUP:
+ System.out.println(" Group: " + oname[indx]);
+ break;
+ case H5O_TYPE_DATASET:
+ System.out.println(" Dataset: " + oname[indx]);
+ break;
+ case H5O_TYPE_NAMED_DATATYPE:
+ System.out.println(" Datatype: " + oname[indx]);
+ break;
+ default:
+ System.out.println(" Unknown: " + oname[indx]);
+ }
+ }
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Close the file.
+ try {
+ if (file_id >= 0)
+ H5.H5Fclose(file_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static void main(String[] args) { H5Ex_G_Iterate.do_iterate(); }
+}
diff --git a/HDF5Examples/JAVA/H5G/H5Ex_G_Phase.java b/HDF5Examples/JAVA/H5G/H5Ex_G_Phase.java
new file mode 100644
index 0000000..b21fc09
--- /dev/null
+++ b/HDF5Examples/JAVA/H5G/H5Ex_G_Phase.java
@@ -0,0 +1,234 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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 set the conditions for
+ conversion between compact and dense (indexed) groups.
+ ************************************************************/
+
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.Map;
+
+import hdf.hdf5lib.H5;
+import hdf.hdf5lib.HDF5Constants;
+import hdf.hdf5lib.structs.H5G_info_t;
+
+public class H5Ex_G_Phase {
+ private static String FILE = "H5Ex_G_Phase.h5";
+ private static int MAX_GROUPS = 7;
+ private static int MAX_COMPACT = 5;
+ private static int MIN_DENSE = 3;
+
+ enum H5G_storage {
+ H5G_STORAGE_TYPE_UNKNOWN(-1),
+ H5G_STORAGE_TYPE_SYMBOL_TABLE(0),
+ H5G_STORAGE_TYPE_COMPACT(1),
+ H5G_STORAGE_TYPE_DENSE(2);
+
+ private static final Map<Integer, H5G_storage> lookup = new HashMap<Integer, H5G_storage>();
+
+ static
+ {
+ for (H5G_storage s : EnumSet.allOf(H5G_storage.class))
+ lookup.put(s.getCode(), s);
+ }
+
+ private int code;
+
+ H5G_storage(int layout_type) { this.code = layout_type; }
+
+ public int getCode() { return this.code; }
+
+ public static H5G_storage get(int code) { return lookup.get(code); }
+ }
+
+ private static void CreateGroup()
+ {
+ long file_id = HDF5Constants.H5I_INVALID_HID;
+ long group_id = HDF5Constants.H5I_INVALID_HID;
+ long subgroup_id = HDF5Constants.H5I_INVALID_HID;
+ long fapl_id = HDF5Constants.H5I_INVALID_HID;
+ long gcpl_id = HDF5Constants.H5I_INVALID_HID;
+ H5G_info_t ginfo;
+ String name = "G0"; // Name of subgroup_id
+ int i;
+
+ // Set file access property list to allow the latest file format.This will allow the library to create
+ // new format groups.
+ try {
+ fapl_id = H5.H5Pcreate(HDF5Constants.H5P_FILE_ACCESS);
+ if (fapl_id >= 0)
+ H5.H5Pset_libver_bounds(fapl_id, HDF5Constants.H5F_LIBVER_LATEST,
+ HDF5Constants.H5F_LIBVER_LATEST);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Create group access property list and set the phase change conditions.
+ try {
+ gcpl_id = H5.H5Pcreate(HDF5Constants.H5P_GROUP_CREATE);
+ if (gcpl_id >= 0)
+ H5.H5Pset_link_phase_change(gcpl_id, MAX_COMPACT, MIN_DENSE);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Create a new file using the default properties.
+ try {
+ if (fapl_id >= 0)
+ file_id = H5.H5Fcreate(FILE, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, fapl_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Create primary group.
+ try {
+ if ((file_id >= 0) && (gcpl_id >= 0))
+ group_id = H5.H5Gcreate(file_id, name, HDF5Constants.H5P_DEFAULT, gcpl_id,
+ HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Add subgroups to "group" one at a time, print the storage type for "group" after each subgroup is
+ // created.
+ for (i = 1; i <= MAX_GROUPS; i++) {
+ // Define the subgroup name and create the subgroup.
+ char append = (char)(((char)i) + '0');
+ name = name + append; /* G1, G2, G3 etc. */
+ try {
+ if (group_id >= 0) {
+ subgroup_id = H5.H5Gcreate(group_id, name, HDF5Constants.H5P_DEFAULT,
+ HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
+ H5.H5Gclose(subgroup_id);
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Obtain the group info and print the group storage type
+ try {
+ if (group_id >= 0) {
+ ginfo = H5.H5Gget_info(group_id);
+ System.out.print(ginfo.nlinks + " Group" + (ginfo.nlinks == 1 ? " " : "s") +
+ ": Storage type is ");
+ switch (H5G_storage.get(ginfo.storage_type)) {
+ case H5G_STORAGE_TYPE_COMPACT:
+ System.out.println("H5G_STORAGE_TYPE_COMPACT"); // New compact format
+ break;
+ case H5G_STORAGE_TYPE_DENSE:
+ System.out.println("H5G_STORAGE_TYPE_DENSE"); // New dense (indexed) format
+ break;
+ case H5G_STORAGE_TYPE_SYMBOL_TABLE:
+ System.out.println("H5G_STORAGE_TYPE_SYMBOL_TABLE"); // Original format
+ break;
+ case H5G_STORAGE_TYPE_UNKNOWN:
+ System.out.println("H5G_STORAGE_TYPE_UNKNOWN");
+ break;
+ default:
+ System.out.println("Storage Type Invalid");
+ break;
+ }
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ System.out.println();
+
+ // Delete subgroups one at a time, print the storage type for "group" after each subgroup is deleted.
+ for (i = MAX_GROUPS; i >= 1; i--) {
+ // Define the subgroup name and delete the subgroup.
+ try {
+ H5.H5Ldelete(group_id, name, HDF5Constants.H5P_DEFAULT);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ name = name.substring(0, i + 1);
+
+ // Obtain the group info and print the group storage type
+ try {
+ if (group_id >= 0) {
+ ginfo = H5.H5Gget_info(group_id);
+ System.out.print(ginfo.nlinks + " Group" + (ginfo.nlinks == 1 ? " " : "s") +
+ ": Storage type is ");
+ switch (H5G_storage.get(ginfo.storage_type)) {
+ case H5G_STORAGE_TYPE_COMPACT:
+ System.out.println("H5G_STORAGE_TYPE_COMPACT"); // New compact format
+ break;
+ case H5G_STORAGE_TYPE_DENSE:
+ System.out.println("H5G_STORAGE_TYPE_DENSE"); // New dense (indexed) format
+ break;
+ case H5G_STORAGE_TYPE_SYMBOL_TABLE:
+ System.out.println("H5G_STORAGE_TYPE_SYMBOL_TABLE"); // Original format
+ break;
+ case H5G_STORAGE_TYPE_UNKNOWN:
+ System.out.println("H5G_STORAGE_TYPE_UNKNOWN");
+ break;
+ default:
+ System.out.println("Storage Type Invalid");
+ break;
+ }
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ // Close and release resources
+ try {
+ if (fapl_id >= 0)
+ H5.H5Pclose(fapl_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ try {
+ if (gcpl_id >= 0)
+ H5.H5Pclose(gcpl_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Close the group
+ try {
+ if (group_id >= 0)
+ H5.H5Gclose(group_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Close the file
+ try {
+ if (file_id >= 0)
+ H5.H5Fclose(file_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static void main(String[] args) { H5Ex_G_Phase.CreateGroup(); }
+}
diff --git a/HDF5Examples/JAVA/H5G/H5Ex_G_Traverse.java b/HDF5Examples/JAVA/H5G/H5Ex_G_Traverse.java
new file mode 100644
index 0000000..ba1955b
--- /dev/null
+++ b/HDF5Examples/JAVA/H5G/H5Ex_G_Traverse.java
@@ -0,0 +1,166 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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 a way to recursively traverse the file
+using H5Literate. The method shown here guarantees that
+the recursion will not enter an infinite loop, but does
+not prevent objects from being visited more than once.
+The program prints the directory structure of the file
+specified in FILE. The default file used by this example
+implements the structure described in the User's Guide,
+chapter 4, figure 26.
+ ************************************************************/
+
+import hdf.hdf5lib.H5;
+import hdf.hdf5lib.HDF5Constants;
+import hdf.hdf5lib.callbacks.H5L_iterate_opdata_t;
+import hdf.hdf5lib.callbacks.H5L_iterate_t;
+import hdf.hdf5lib.structs.H5L_info_t;
+import hdf.hdf5lib.structs.H5O_info_t;
+
+import examples.groups.H5Ex_G_Iterate.H5O_type;
+
+class opdata implements H5L_iterate_opdata_t {
+ int recurs;
+ opdata prev;
+ H5O_token_t obj_token;
+}
+
+public class H5Ex_G_Traverse {
+
+ private static String FILE = "h5ex_g_traverse.h5";
+ public static H5L_iterate_t iter_cb = new H5L_iter_callbackT();
+
+ private static void OpenGroup()
+ {
+ long file_id = HDF5Constants.H5I_INVALID_HID;
+ H5O_info_t infobuf;
+ opdata od = new opdata();
+
+ // Open file and initialize the operator data structure.
+ try {
+ file_id = H5.H5Fopen(FILE, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
+ if (file_id >= 0) {
+ infobuf = H5.H5Oget_info(file_id);
+ od.recurs = 0;
+ od.prev = null;
+ od.obj_token = infobuf.token;
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Print the root group and formatting, begin iteration.
+ try {
+ System.out.println("/ {");
+ // H5L_iterate_t iter_cb = new H5L_iter_callbackT();
+ H5.H5Literate(file_id, HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_NATIVE, 0L, iter_cb,
+ od);
+ System.out.println("}");
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ // Close and release resources.
+ try {
+ if (file_id >= 0)
+ H5.H5Fclose(file_id);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public static void main(String[] args) { H5Ex_G_Traverse.OpenGroup(); }
+}
+
+class H5L_iter_callbackT implements H5L_iterate_t {
+ public int callback(long group, String name, H5L_info_t info, H5L_iterate_opdata_t op_data)
+ {
+
+ H5O_info_t infobuf;
+ int return_val = 0;
+ opdata od = (opdata)op_data; // Type conversion
+ int spaces = 2 * (od.recurs + 1); // Number of white spaces to prepend to output.
+
+ // Get type of the object and display its name and type.
+ // The name of the object is passed to this function by the Library.
+ try {
+ infobuf = H5.H5Oget_info_by_name(group, name, HDF5Constants.H5P_DEFAULT);
+
+ for (int i = 0; i < spaces; i++)
+ System.out.print(" "); // Format output.
+ switch (H5O_type.get(infobuf.type)) {
+ case H5O_TYPE_GROUP:
+ System.out.println("Group: " + name + " { ");
+ // Check group object token against linked list of operator
+ // data structures. We will always run the check, as the
+ // reference count cannot be relied upon if there are
+ // symbolic links, and H5Oget_info_by_name always follows
+ // symbolic links. Alternatively we could use H5Lget_info
+ // and never recurse on groups discovered by symbolic
+ // links, however it could still fail if an object's
+ // reference count was manually manipulated with
+ // H5Odecr_refcount.
+ if (group_check(od, infobuf.token)) {
+ for (int i = 0; i < spaces; i++)
+ System.out.print(" ");
+ System.out.println(" Warning: Loop detected!");
+ }
+ else {
+ // Initialize new object of type opdata and begin
+ // recursive iteration on the discovered
+ // group. The new opdata is given a pointer to the
+ // current one.
+ opdata nextod = new opdata();
+ nextod.recurs = od.recurs + 1;
+ nextod.prev = od;
+ nextod.obj_token = infobuf.token;
+ H5L_iterate_t iter_cb2 = new H5L_iter_callbackT();
+ return_val = H5.H5Literate_by_name(group, name, HDF5Constants.H5_INDEX_NAME,
+ HDF5Constants.H5_ITER_NATIVE, 0L, iter_cb2, nextod,
+ HDF5Constants.H5P_DEFAULT);
+ }
+ for (int i = 0; i < spaces; i++)
+ System.out.print(" ");
+ System.out.println("}");
+ break;
+ case H5O_TYPE_DATASET:
+ System.out.println("Dataset: " + name);
+ break;
+ case H5O_TYPE_NAMED_DATATYPE:
+ System.out.println("Datatype: " + name);
+ break;
+ default:
+ System.out.println("Unknown: " + name);
+ }
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return return_val;
+ }
+
+ public boolean group_check(opdata od, H5O_token_t target_token)
+ {
+ if (od.obj_token.equals(target_token))
+ return true; // Object tokens match
+ else if (od.recurs == 0)
+ return false; // Root group reached with no matches
+ else
+ return group_check(od.prev, target_token); // Recursively examine the next node
+ }
+}
diff --git a/HDF5Examples/JAVA/H5G/H5Ex_G_Visit.java b/HDF5Examples/JAVA/H5G/H5Ex_G_Visit.java
new file mode 100644
index 0000000..7d37c59
--- /dev/null
+++ b/HDF5Examples/JAVA/H5G/H5Ex_G_Visit.java
@@ -0,0 +1,153 @@
+/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+ * 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 recursively traverse a file
+ using H5Ovisit and H5Lvisit. The program prints all of
+ the objects in the file specified in FILE, then prints all
+ of the links in that file. The default file used by this
+ example implements the structure described in the User
+ Guide, chapter 4, figure 26.
+ ************************************************************/
+
+import java.util.ArrayList;
+
+import hdf.hdf5lib.H5;
+import hdf.hdf5lib.HDF5Constants;
+import hdf.hdf5lib.callbacks.H5L_iterate_opdata_t;
+import hdf.hdf5lib.callbacks.H5L_iterate_t;
+import hdf.hdf5lib.callbacks.H5O_iterate_opdata_t;
+import hdf.hdf5lib.callbacks.H5O_iterate_t;
+import hdf.hdf5lib.structs.H5L_info_t;
+import hdf.hdf5lib.structs.H5O_info_t;
+
+public class H5Ex_G_Visit {
+
+ private static String FILE = "groups/h5ex_g_visit.h5";
+
+ public static void main(String[] args)
+ {
+ try {
+ (new H5Ex_G_Visit()).VisitGroup();
+ }
+ catch (Exception ex) {
+ ex.printStackTrace();
+ }
+ }
+
+ private void VisitGroup() throws Exception
+ {
+
+ long file_id = HDF5Constants.H5I_INVALID_HID;
+
+ try {
+ // Open file
+ file_id = H5.H5Fopen(FILE, HDF5Constants.H5F_ACC_RDONLY, HDF5Constants.H5P_DEFAULT);
+
+ // Begin iteration using H5Ovisit
+ System.out.println("Objects in the file:");
+ H5O_iterate_opdata_t iter_data = new H5O_iter_data();
+ H5O_iterate_t iter_cb = new H5O_iter_callback();
+ H5.H5Ovisit(file_id, HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_NATIVE, iter_cb,
+ iter_data);
+ System.out.println();
+ // Repeat the same process using H5Lvisit
+ H5L_iterate_opdata_t iter_data2 = new H5L_iter_data();
+ H5L_iterate_t iter_cb2 = new H5L_iter_callback();
+ System.out.println("Links in the file:");
+ H5.H5Lvisit(file_id, HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_NATIVE, iter_cb2,
+ iter_data2);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+ finally {
+ // Close and release resources.
+ if (file_id >= 0)
+ H5.H5Fclose(file_id);
+ }
+ }
+
+ /************************************************************
+ * Operator function for H5Lvisit. This function simply retrieves the info for the object the current link
+ *points to, and calls the operator function for H5Ovisit.
+ ************************************************************/
+
+ private class idata {
+ public String link_name = null;
+ public int link_type = -1;
+
+ idata(String name, int type)
+ {
+ this.link_name = name;
+ this.link_type = type;
+ }
+ }
+
+ private class H5L_iter_data implements H5L_iterate_opdata_t {
+ public ArrayList<idata> iterdata = new ArrayList<idata>();
+ }
+
+ private class H5L_iter_callback implements H5L_iterate_t {
+ public int callback(long group, String name, H5L_info_t info, H5L_iterate_opdata_t op_data)
+ {
+
+ idata id = new idata(name, info.type);
+ ((H5L_iter_data)op_data).iterdata.add(id);
+
+ H5O_info_t infobuf;
+ int ret = 0;
+ try {
+ // Get type of the object and display its name and type. The name of the object is passed to
+ // this function by the Library.
+ infobuf = H5.H5Oget_info_by_name(group, name, HDF5Constants.H5P_DEFAULT);
+ H5O_iterate_t iter_cbO = new H5O_iter_callback();
+ H5O_iterate_opdata_t iter_dataO = new H5O_iter_data();
+ ret = iter_cbO.callback(group, name, infobuf, iter_dataO);
+ }
+ catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ return ret;
+ }
+ }
+
+ private class H5O_iter_data implements H5O_iterate_opdata_t {
+ public ArrayList<idata> iterdata = new ArrayList<idata>();
+ }
+
+ private class H5O_iter_callback implements H5O_iterate_t {
+ public int callback(long group, String name, H5O_info_t info, H5O_iterate_opdata_t op_data)
+ {
+ idata id = new idata(name, info.type);
+ ((H5O_iter_data)op_data).iterdata.add(id);
+
+ System.out.print("/"); /* Print root group in object path */
+
+ // Check if the current object is the root group, and if not print the full path name and type.
+
+ if (name.charAt(0) == '.') /* Root group, do not print '.' */
+ System.out.println(" (Group)");
+ else if (info.type == HDF5Constants.H5O_TYPE_GROUP)
+ System.out.println(name + " (Group)");
+ else if (info.type == HDF5Constants.H5O_TYPE_DATASET)
+ System.out.println(name + " (Dataset)");
+ else if (info.type == HDF5Constants.H5O_TYPE_NAMED_DATATYPE)
+ System.out.println(name + " (Datatype)");
+ else
+ System.out.println(name + " (Unknown)");
+
+ return 0;
+ }
+ }
+}
diff --git a/HDF5Examples/JAVA/H5G/JavaGroupExample.sh.in b/HDF5Examples/JAVA/H5G/JavaGroupExample.sh.in
new file mode 100644
index 0000000..933f35e
--- /dev/null
+++ b/HDF5Examples/JAVA/H5G/JavaGroupExample.sh.in
@@ -0,0 +1,377 @@
+#! /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_Groups
+EXIT_SUCCESS=0
+EXIT_FAILURE=1
+
+# Set up default variable values if not supplied by the user.
+RM='rm -rf'
+CMP='cmp'
+DIFF='diff -c'
+CP='cp'
+DIRNAME='dirname'
+BASENAME='basename'
+LS='ls'
+AWK='awk'
+
+nerrors=0
+
+# where the libs exist
+HDFLIB_HOME="$top_srcdir/java/lib"
+BLDDIR="."
+BLDLIBDIR="$BLDDIR/testlibs"
+BLDITERDIR="./groups"
+HDFTEST_HOME="$top_srcdir/java/examples/groups"
+JARFILE=jar@PACKAGE_TARNAME@-@PACKAGE_VERSION@.jar
+TESTJARFILE=jar@PACKAGE_TARNAME@groups.jar
+test -d $BLDLIBDIR || mkdir -p $BLDLIBDIR
+test -d $BLDITERDIR || mkdir -p $BLDITERDIR
+
+######################################################################
+# 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_ITER_FILES="
+$HDFTEST_HOME/h5ex_g_iterate.h5
+$HDFTEST_HOME/h5ex_g_visit.h5
+"
+LIST_DATA_FILES="
+$HDFTEST_HOME/../tfiles/examples.groups.H5Ex_G_Create.txt
+$HDFTEST_HOME/../tfiles/examples.groups.H5Ex_G_Iterate.txt
+$HDFTEST_HOME/../tfiles/examples.groups.H5Ex_G_Compact.txt
+$HDFTEST_HOME/../tfiles/examples.groups.H5Ex_G_Corder.txt
+$HDFTEST_HOME/../tfiles/examples.groups.H5Ex_G_Intermediate.txt
+$HDFTEST_HOME/../tfiles/examples.groups.H5Ex_G_Phase.txt
+$HDFTEST_HOME/../tfiles/examples.groups.H5Ex_G_Visit.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.groups.H5Ex_G_*.txt
+ $RM $BLDDIR/H5Ex_G_*.out
+ $RM $BLDDIR/H5Ex_G_*.h5
+}
+
+COPY_ITERFILES="$LIST_ITER_FILES"
+
+COPY_ITERFILES_TO_BLDITERDIR()
+{
+ # copy test files. Used -f to make sure get a new copy
+ for tstfile in $COPY_ITERFILES
+ 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 $BLDITERDIR | $AWK -F' ' '{print $1}'`
+ if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then
+ $CP -f $tstfile $BLDITERDIR
+ 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_ITERFILES_AND_BLDITERDIR()
+{
+ # skip rm if srcdir is same as destdir
+ # this occurs when build/test performed in source dir and
+ # make cp fail
+ SDIR=`$DIRNAME $HDFTEST_HOME/h5ex_g_iterate.h5`
+ INODE_SDIR=`$LS -i -d $SDIR | $AWK -F' ' '{print $1}'`
+ INODE_DDIR=`$LS -i -d $BLDITERDIR | $AWK -F' ' '{print $1}'`
+ if [ "$INODE_SDIR" != "$INODE_DDIR" ]; then
+ $RM $BLDITERDIR
+ fi
+}
+
+# Print a line-line message left justified in a field of 70 characters
+# beginning with the word "Testing".
+#
+TESTING() {
+ SPACES=" "
+ echo "Testing $* $SPACES" | cut -c1-70 | tr -d '\012'
+}
+
+# where Java is installed (requires jdk1.7.x)
+JAVAEXE=@JAVA@
+JAVAEXEFLAGS=@H5_JAVAFLAGS@
+
+###############################################################################
+# DO NOT MODIFY BELOW THIS LINE
+###############################################################################
+
+# prepare for test
+COPY_LIBFILES_TO_BLDLIBDIR
+COPY_DATAFILES_TO_BLDDIR
+COPY_ITERFILES_TO_BLDITERDIR
+
+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.groups.H5Ex_G_Create"
+TESTING examples.groups.H5Ex_G_Create
+($RUNSERIAL $JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.groups.H5Ex_G_Create > H5Ex_G_Create.out)
+if diff H5Ex_G_Create.out examples.groups.H5Ex_G_Create.txt > /dev/null; then
+ echo " PASSED groups.H5Ex_G_Create"
+else
+ echo "**FAILED** groups.H5Ex_G_Create"
+ nerrors="`expr $nerrors + 1`"
+fi
+
+echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.groups.H5Ex_G_Iterate"
+TESTING examples.groups.H5Ex_G_Iterate
+($RUNSERIAL $JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.groups.H5Ex_G_Iterate > H5Ex_G_Iterate.out)
+if diff H5Ex_G_Iterate.out examples.groups.H5Ex_G_Iterate.txt > /dev/null; then
+ echo " PASSED groups.H5Ex_G_Iterate"
+else
+ echo "**FAILED** groups.H5Ex_G_Iterate"
+ nerrors="`expr $nerrors + 1`"
+fi
+
+echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.groups.H5Ex_G_Compact"
+TESTING examples.groups.H5Ex_G_Compact
+($RUNSERIAL $JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.groups.H5Ex_G_Compact > H5Ex_G_Compact.out)
+if diff H5Ex_G_Compact.out examples.groups.H5Ex_G_Compact.txt > /dev/null; then
+ echo " PASSED groups.H5Ex_G_Compact"
+else
+ echo "**FAILED** groups.H5Ex_G_Compact"
+ nerrors="`expr $nerrors + 1`"
+fi
+
+echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.groups.H5Ex_G_Corder"
+TESTING examples.groups.H5Ex_G_Corder
+($RUNSERIAL $JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.groups.H5Ex_G_Corder > H5Ex_G_Corder.out)
+if diff H5Ex_G_Corder.out examples.groups.H5Ex_G_Corder.txt > /dev/null; then
+ echo " PASSED groups.H5Ex_G_Corder"
+else
+ echo "**FAILED** groups.H5Ex_G_Corder"
+ nerrors="`expr $nerrors + 1`"
+fi
+
+echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.groups.H5Ex_G_Intermediate"
+TESTING examples.groups.H5Ex_G_Intermediate
+($RUNSERIAL $JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.groups.H5Ex_G_Intermediate > H5Ex_G_Intermediate.out)
+if diff H5Ex_G_Intermediate.out examples.groups.H5Ex_G_Intermediate.txt > /dev/null; then
+ echo " PASSED groups.H5Ex_G_Intermediate"
+else
+ echo "**FAILED** groups.H5Ex_G_Intermediate"
+ nerrors="`expr $nerrors + 1`"
+fi
+
+echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.groups.H5Ex_G_Phase"
+TESTING examples.groups.H5Ex_G_Phase
+($RUNSERIAL $JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.groups.H5Ex_G_Phase > H5Ex_G_Phase.out)
+if diff H5Ex_G_Phase.out examples.groups.H5Ex_G_Phase.txt > /dev/null; then
+ echo " PASSED groups.H5Ex_G_Phase"
+else
+ echo "**FAILED** groups.H5Ex_G_Phase"
+ nerrors="`expr $nerrors + 1`"
+fi
+
+echo "$JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.groups.H5Ex_G_Visit"
+TESTING examples.groups.H5Ex_G_Visit
+($RUNSERIAL $JAVAEXE $JAVAEXEFLAGS -Xmx1024M -Djava.library.path=$BLDLIBDIR -cp $CLASSPATH examples.groups.H5Ex_G_Visit > H5Ex_G_Visit.out)
+if diff H5Ex_G_Visit.out examples.groups.H5Ex_G_Visit.txt > /dev/null; then
+ echo " PASSED groups.H5Ex_G_Visit"
+else
+ echo "**FAILED** groups.H5Ex_G_Visit"
+ nerrors="`expr $nerrors + 1`"
+fi
+
+# Clean up temporary files/directories
+CLEAN_ITERFILES_AND_BLDITERDIR
+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/H5G/Java_sourcefiles.cmake b/HDF5Examples/JAVA/H5G/Java_sourcefiles.cmake
new file mode 100644
index 0000000..d5142bd
--- /dev/null
+++ b/HDF5Examples/JAVA/H5G/Java_sourcefiles.cmake
@@ -0,0 +1,24 @@
+#-----------------------------------------------------------------------------
+# Define Sources, one file per application
+#-----------------------------------------------------------------------------
+set (HDF_JAVA_EXAMPLES
+ H5Ex_G_Create.java
+ H5Ex_G_Compact.java
+ H5Ex_G_Corder.java
+ H5Ex_G_Phase.java
+)
+if (${H5_LIBVER_DIR} GREATER 18)
+ if ((${H5_LIBVER_DIR} EQUAL 110) AND NOT (${${EXAMPLE_VARNAME}_USE_16_API} OR ${${EXAMPLE_VARNAME}_USE_18_API} OR ${${EXAMPLE_VARNAME}_USE_110_API}))
+ set (HDF_JAVA_EXAMPLES ${HDF_JAVA_EXAMPLES}
+ 110/H5Ex_G_Iterate.java
+ 110/H5Ex_G_Intermediate.java
+ 110/H5Ex_G_Visit.java
+ )
+ else ()
+ set (HDF_JAVA_EXAMPLES ${HDF_JAVA_EXAMPLES}
+ H5Ex_G_Iterate.java
+ H5Ex_G_Intermediate.java
+ H5Ex_G_Visit.java
+ )
+ endif ()
+endif ()
diff --git a/HDF5Examples/JAVA/H5G/Makefile.am b/HDF5Examples/JAVA/H5G/Makefile.am
new file mode 100644
index 0000000..d3b59cf
--- /dev/null
+++ b/HDF5Examples/JAVA/H5G/Makefile.am
@@ -0,0 +1,65 @@
+#
+# 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/groups
+hdfjarfile = jar$(PACKAGE_TARNAME)-$(PACKAGE_VERSION).jar
+CLASSPATH_ENV=CLASSPATH=.:$(JAVAROOT):$(top_builddir)/java/src/$(hdfjarfile):$$CLASSPATH
+
+jarfile = jar$(PACKAGE_TARNAME)groups.jar
+
+AM_JAVACFLAGS = $(H5_JAVACFLAGS) -deprecation
+
+TESTPACKAGE =
+
+noinst_JAVA = \
+ H5Ex_G_Create.java \
+ H5Ex_G_Iterate.java \
+ H5Ex_G_Compact.java \
+ H5Ex_G_Corder.java \
+ H5Ex_G_Intermediate.java \
+ H5Ex_G_Phase.java \
+ H5Ex_G_Visit.java
+
+
+$(jarfile): classnoinst.stamp classes
+ $(JAR) cvf $@ -C $(JAVAROOT)/ $(pkgpath)
+
+noinst_DATA = $(jarfile)
+
+.PHONY: classes
+
+check_SCRIPTS = JavaGroupExample.sh
+TEST_SCRIPT = $(check_SCRIPTS)
+
+CLEANFILES = classnoinst.stamp $(jarfile) $(JAVAROOT)/$(pkgpath)/*.class JavaGroupExample.sh
+
+clean:
+ rm -rf $(JAVAROOT)/*
+ rm -f $(jarfile)
+ rm -f classnoinst.stamp
+
+include $(top_srcdir)/config/conclude.am
diff --git a/HDF5Examples/JAVA/H5G/h5ex_g_iterate.h5 b/HDF5Examples/JAVA/H5G/h5ex_g_iterate.h5
new file mode 100644
index 0000000..e462703
--- /dev/null
+++ b/HDF5Examples/JAVA/H5G/h5ex_g_iterate.h5
Binary files differ
diff --git a/HDF5Examples/JAVA/H5G/h5ex_g_visit.h5 b/HDF5Examples/JAVA/H5G/h5ex_g_visit.h5
new file mode 100644
index 0000000..d8267b1
--- /dev/null
+++ b/HDF5Examples/JAVA/H5G/h5ex_g_visit.h5
Binary files differ
diff --git a/HDF5Examples/JAVA/H5G/tfiles/110/H5Ex_G_Compact.txt b/HDF5Examples/JAVA/H5G/tfiles/110/H5Ex_G_Compact.txt
new file mode 100644
index 0000000..0a88d3f
--- /dev/null
+++ b/HDF5Examples/JAVA/H5G/tfiles/110/H5Ex_G_Compact.txt
@@ -0,0 +1,5 @@
+Group storage type for H5Ex_G_Compact1.h5 is: H5G_STORAGE_TYPE_SYMBOL_TABLE
+File size for H5Ex_G_Compact1.h5 is: 1832 bytes
+
+Group storage type for H5Ex_G_Compact2.h5 is: H5G_STORAGE_TYPE_COMPACT
+File size for H5Ex_G_Compact2.h5 is: 342 bytes
diff --git a/HDF5Examples/JAVA/H5G/tfiles/110/H5Ex_G_Corder.txt b/HDF5Examples/JAVA/H5G/tfiles/110/H5Ex_G_Corder.txt
new file mode 100644
index 0000000..2d959fc
--- /dev/null
+++ b/HDF5Examples/JAVA/H5G/tfiles/110/H5Ex_G_Corder.txt
@@ -0,0 +1,10 @@
+Traversing group using alphabetical indices:
+Index 0: 5
+Index 1: D
+Index 2: F
+Index 3: H
+Traversing group using creation order indices:
+Index 0: H
+Index 1: D
+Index 2: F
+Index 3: 5
diff --git a/HDF5Examples/JAVA/H5G/tfiles/110/H5Ex_G_Create.txt b/HDF5Examples/JAVA/H5G/tfiles/110/H5Ex_G_Create.txt
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/HDF5Examples/JAVA/H5G/tfiles/110/H5Ex_G_Create.txt
diff --git a/HDF5Examples/JAVA/H5G/tfiles/110/H5Ex_G_Intermediate.txt b/HDF5Examples/JAVA/H5G/tfiles/110/H5Ex_G_Intermediate.txt
new file mode 100644
index 0000000..65a0fc2
--- /dev/null
+++ b/HDF5Examples/JAVA/H5G/tfiles/110/H5Ex_G_Intermediate.txt
@@ -0,0 +1,5 @@
+Objects in the file_id:
+/ (Group)
+/G1 (Group)
+/G1/G2 (Group)
+/G1/G2/G3 (Group)
diff --git a/HDF5Examples/JAVA/H5G/tfiles/110/H5Ex_G_Iterate.txt b/HDF5Examples/JAVA/H5G/tfiles/110/H5Ex_G_Iterate.txt
new file mode 100644
index 0000000..66a4ae9
--- /dev/null
+++ b/HDF5Examples/JAVA/H5G/tfiles/110/H5Ex_G_Iterate.txt
@@ -0,0 +1,5 @@
+Objects in root group:
+ Dataset: DS1
+ Datatype: DT1
+ Group: G1
+ Dataset: L1
diff --git a/HDF5Examples/JAVA/H5G/tfiles/110/H5Ex_G_Phase.txt b/HDF5Examples/JAVA/H5G/tfiles/110/H5Ex_G_Phase.txt
new file mode 100644
index 0000000..9e666d4
--- /dev/null
+++ b/HDF5Examples/JAVA/H5G/tfiles/110/H5Ex_G_Phase.txt
@@ -0,0 +1,15 @@
+1 Group : Storage type is H5G_STORAGE_TYPE_COMPACT
+2 Groups: Storage type is H5G_STORAGE_TYPE_COMPACT
+3 Groups: Storage type is H5G_STORAGE_TYPE_COMPACT
+4 Groups: Storage type is H5G_STORAGE_TYPE_COMPACT
+5 Groups: Storage type is H5G_STORAGE_TYPE_COMPACT
+6 Groups: Storage type is H5G_STORAGE_TYPE_DENSE
+7 Groups: Storage type is H5G_STORAGE_TYPE_DENSE
+
+6 Groups: Storage type is H5G_STORAGE_TYPE_DENSE
+5 Groups: Storage type is H5G_STORAGE_TYPE_DENSE
+4 Groups: Storage type is H5G_STORAGE_TYPE_DENSE
+3 Groups: Storage type is H5G_STORAGE_TYPE_DENSE
+2 Groups: Storage type is H5G_STORAGE_TYPE_COMPACT
+1 Group : Storage type is H5G_STORAGE_TYPE_COMPACT
+0 Groups: Storage type is H5G_STORAGE_TYPE_COMPACT
diff --git a/HDF5Examples/JAVA/H5G/tfiles/110/H5Ex_G_Visit.txt b/HDF5Examples/JAVA/H5G/tfiles/110/H5Ex_G_Visit.txt
new file mode 100644
index 0000000..126a588
--- /dev/null
+++ b/HDF5Examples/JAVA/H5G/tfiles/110/H5Ex_G_Visit.txt
@@ -0,0 +1,19 @@
+Objects in the file:
+/ (Group)
+/group1 (Group)
+/group1/dset1 (Dataset)
+/group1/group3 (Group)
+/group1/group3/group4 (Group)
+/group1/group3/group4/group1 (Group)
+/group1/group3/group4/group2 (Group)
+
+Links in the file:
+/group1 (Group)
+/group1/dset1 (Dataset)
+/group1/group3 (Group)
+/group1/group3/dset2 (Dataset)
+/group1/group3/group4 (Group)
+/group1/group3/group4/group1 (Group)
+/group1/group3/group4/group1/group5 (Group)
+/group1/group3/group4/group2 (Group)
+/group2 (Group)