diff options
author | Allen Byrne <50328838+byrnHDF@users.noreply.github.com> | 2022-04-19 18:08:09 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-19 18:08:09 (GMT) |
commit | 03c3a5469542688a52d5a20242d2334408f8ba33 (patch) | |
tree | 46e30ea4aa99b68279fe80c9ad56b1a6bbfcfe7c /java/examples/groups | |
parent | 32ef796e470da3e4de364d8dc469b03f5f6fafdc (diff) | |
download | hdf5-03c3a5469542688a52d5a20242d2334408f8ba33.zip hdf5-03c3a5469542688a52d5a20242d2334408f8ba33.tar.gz hdf5-03c3a5469542688a52d5a20242d2334408f8ba33.tar.bz2 |
Develop clang format java (#1653)
Diffstat (limited to 'java/examples/groups')
-rw-r--r-- | java/examples/groups/CMakeLists.txt | 7 | ||||
-rw-r--r-- | java/examples/groups/H5Ex_G_Compact.java | 52 | ||||
-rw-r--r-- | java/examples/groups/H5Ex_G_Corder.java | 56 | ||||
-rw-r--r-- | java/examples/groups/H5Ex_G_Create.java | 19 | ||||
-rw-r--r-- | java/examples/groups/H5Ex_G_Intermediate.java | 42 | ||||
-rw-r--r-- | java/examples/groups/H5Ex_G_Iterate.java | 52 | ||||
-rw-r--r-- | java/examples/groups/H5Ex_G_Phase.java | 73 | ||||
-rw-r--r-- | java/examples/groups/H5Ex_G_Traverse.java | 45 | ||||
-rw-r--r-- | java/examples/groups/H5Ex_G_Visit.java | 53 |
9 files changed, 202 insertions, 197 deletions
diff --git a/java/examples/groups/CMakeLists.txt b/java/examples/groups/CMakeLists.txt index 6483f91..9f20abf 100644 --- a/java/examples/groups/CMakeLists.txt +++ b/java/examples/groups/CMakeLists.txt @@ -36,6 +36,13 @@ foreach (example ${HDF_JAVA_EXAMPLES}) # install_jar (${example} ${HJAVA_INSTALL_DATA_DIR}/examples examples) get_target_property (${example}_CLASSPATH ${example} CLASSDIR) add_dependencies (${example} ${HDF5_JAVA_HDF5_LIB_TARGET}) + + #----------------------------------------------------------------------------- + # Add Target to clang-format + #----------------------------------------------------------------------------- + if (HDF5_ENABLE_FORMATTERS) + clang_format (HDF5_JAVA_${example}_SRC_FORMAT ${example}.java) + endif () endforeach () set (CMAKE_JAVA_INCLUDE_PATH "${HDF5_JAVA_JARS};${HDF5_JAVA_LOGGING_JAR};${HDF5_JAVA_LOGGING_NOP_JAR}") diff --git a/java/examples/groups/H5Ex_G_Compact.java b/java/examples/groups/H5Ex_G_Compact.java index 313c9c7..2c6535a 100644 --- a/java/examples/groups/H5Ex_G_Compact.java +++ b/java/examples/groups/H5Ex_G_Compact.java @@ -16,14 +16,14 @@ package examples.groups; -import hdf.hdf5lib.H5; -import hdf.hdf5lib.HDF5Constants; -import hdf.hdf5lib.structs.H5G_info_t; - import java.util.EnumSet; import java.util.HashMap; import java.util.Map; +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"; @@ -38,44 +38,42 @@ public class H5Ex_G_Compact { private static final Map<Integer, H5G_storage> lookup = new HashMap<Integer, H5G_storage>(); - static { + 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; - } + H5G_storage(int layout_type) { this.code = layout_type; } - public int getCode() { - return this.code; - } + public int getCode() { return this.code; } - public static H5G_storage get(int code) { - return lookup.get(code); - } + public static H5G_storage get(int code) { return lookup.get(code); } } - public static void CreateGroup() { - long file_id = HDF5Constants.H5I_INVALID_HID; + 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; + 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); + 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); + 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(); @@ -83,7 +81,7 @@ public class H5Ex_G_Compact { // Obtain the group info and print the group storage type. try { - if(group_id >= 0) { + 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)) { @@ -160,7 +158,8 @@ public class H5Ex_G_Compact { 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); + H5.H5Pset_libver_bounds(fapl_id, HDF5Constants.H5F_LIBVER_LATEST, + HDF5Constants.H5F_LIBVER_LATEST); } catch (Exception e) { e.printStackTrace(); @@ -175,8 +174,9 @@ public class H5Ex_G_Compact { } // 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); + 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(); @@ -257,7 +257,5 @@ public class H5Ex_G_Compact { } } - public static void main(String[] args) { - H5Ex_G_Compact.CreateGroup(); - } + public static void main(String[] args) { H5Ex_G_Compact.CreateGroup(); } } diff --git a/java/examples/groups/H5Ex_G_Corder.java b/java/examples/groups/H5Ex_G_Corder.java index 4fa5aa2..86a790d 100644 --- a/java/examples/groups/H5Ex_G_Corder.java +++ b/java/examples/groups/H5Ex_G_Corder.java @@ -23,11 +23,12 @@ 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; + 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; + long gcpl_id = HDF5Constants.H5I_INVALID_HID; int status; H5G_info_t ginfo; int i; @@ -36,35 +37,35 @@ public class H5Ex_G_Corder { try { // Create a new file using default properties. file_id = H5.H5Fcreate(FILE, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, - 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); + 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); + 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. + * 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); + 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); @@ -73,8 +74,8 @@ public class H5Ex_G_Corder { 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); + 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); } @@ -83,10 +84,9 @@ public class H5Ex_G_Corder { 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); + HDF5Constants.H5_ITER_INC, i, HDF5Constants.H5P_DEFAULT); System.out.println("Index " + i + ": " + name); } - } catch (Exception e) { e.printStackTrace(); @@ -106,7 +106,8 @@ public class H5Ex_G_Corder { } } - public static void main(String[] args) { + public static void main(String[] args) + { try { H5Ex_G_Corder.CreateGroup(); } @@ -114,5 +115,4 @@ public class H5Ex_G_Corder { ex.printStackTrace(); } } - } diff --git a/java/examples/groups/H5Ex_G_Create.java b/java/examples/groups/H5Ex_G_Create.java index 9304538..51804b9 100644 --- a/java/examples/groups/H5Ex_G_Create.java +++ b/java/examples/groups/H5Ex_G_Create.java @@ -20,17 +20,18 @@ import hdf.hdf5lib.H5; import hdf.hdf5lib.HDF5Constants; public class H5Ex_G_Create { - private static String FILENAME = "H5Ex_G_Create.h5"; + private static String FILENAME = "H5Ex_G_Create.h5"; private static String GROUPNAME = "G1"; - private static void CreateGroup() { - long file_id = HDF5Constants.H5I_INVALID_HID; + 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); + HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -39,8 +40,8 @@ public class H5Ex_G_Create { // 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); + group_id = H5.H5Gcreate(file_id, "/" + GROUPNAME, HDF5Constants.H5P_DEFAULT, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); } catch (Exception e) { e.printStackTrace(); @@ -81,11 +82,7 @@ public class H5Ex_G_Create { catch (Exception e) { e.printStackTrace(); } - - } - - public static void main(String[] args) { - H5Ex_G_Create.CreateGroup(); } + public static void main(String[] args) { H5Ex_G_Create.CreateGroup(); } } diff --git a/java/examples/groups/H5Ex_G_Intermediate.java b/java/examples/groups/H5Ex_G_Intermediate.java index ad0290c..e638fd0 100644 --- a/java/examples/groups/H5Ex_G_Intermediate.java +++ b/java/examples/groups/H5Ex_G_Intermediate.java @@ -16,47 +16,49 @@ ************************************************************/ package examples.groups; +import java.util.ArrayList; + import hdf.hdf5lib.H5; import hdf.hdf5lib.HDF5Constants; -import hdf.hdf5lib.callbacks.H5O_iterate_t; import hdf.hdf5lib.callbacks.H5O_iterate_opdata_t; +import hdf.hdf5lib.callbacks.H5O_iterate_t; import hdf.hdf5lib.structs.H5O_info_t; -import java.util.ArrayList; - public class H5Ex_G_Intermediate { private static String FILE = "H5Ex_G_Intermediate.h5"; - private void CreateGroup() throws Exception { + private void CreateGroup() throws Exception + { - long file_id = HDF5Constants.H5I_INVALID_HID; + long file_id = HDF5Constants.H5I_INVALID_HID; long group_id = HDF5Constants.H5I_INVALID_HID; - long gcpl_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); + 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. + * 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); + 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(); + 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); + H5.H5Ovisit(file_id, HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_NATIVE, iter_cb, + iter_data); } catch (Exception e) { e.printStackTrace(); @@ -72,7 +74,8 @@ public class H5Ex_G_Intermediate { } } - public static void main(String[] args) { + public static void main(String[] args) + { try { (new H5Ex_G_Intermediate()).CreateGroup(); } @@ -83,9 +86,10 @@ public class H5Ex_G_Intermediate { private class idata { public String link_name = null; - public int link_type = -1; + public int link_type = -1; - idata(String name, int type) { + idata(String name, int type) + { this.link_name = name; this.link_type = type; } @@ -96,9 +100,10 @@ public class H5Ex_G_Intermediate { } 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) { + 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); + ((H5O_iter_data)op_data).iterdata.add(id); System.out.print("/"); /* Print root group in object path */ @@ -118,5 +123,4 @@ public class H5Ex_G_Intermediate { return 0; } } - } diff --git a/java/examples/groups/H5Ex_G_Iterate.java b/java/examples/groups/H5Ex_G_Iterate.java index 6caecac..24cbb0a 100644 --- a/java/examples/groups/H5Ex_G_Iterate.java +++ b/java/examples/groups/H5Ex_G_Iterate.java @@ -16,47 +16,43 @@ ************************************************************/ package examples.groups; -import hdf.hdf5lib.H5; -import hdf.hdf5lib.HDF5Constants; -import hdf.hdf5lib.structs.H5O_token_t; - 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 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_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 + H5O_TYPE_NTYPES(3); // Number of different object types private static final Map<Integer, H5O_type> lookup = new HashMap<Integer, H5O_type>(); - static { + 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; - } + H5O_type(int layout_type) { this.code = layout_type; } - public int getCode() { - return this.code; - } + public int getCode() { return this.code; } - public static H5O_type get(int code) { - return lookup.get(code); - } + public static H5O_type get(int code) { return lookup.get(code); } } - private static void do_iterate() { + private static void do_iterate() + { long file_id = HDF5Constants.H5I_INVALID_HID; // Open a file using default properties. @@ -71,12 +67,13 @@ public class H5Ex_G_Iterate { 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]; + 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); + 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++) { @@ -110,8 +107,5 @@ public class H5Ex_G_Iterate { } } - public static void main(String[] args) { - H5Ex_G_Iterate.do_iterate(); - } - + public static void main(String[] args) { H5Ex_G_Iterate.do_iterate(); } } diff --git a/java/examples/groups/H5Ex_G_Phase.java b/java/examples/groups/H5Ex_G_Phase.java index 67a2f53..7a3fba3 100644 --- a/java/examples/groups/H5Ex_G_Phase.java +++ b/java/examples/groups/H5Ex_G_Phase.java @@ -16,19 +16,19 @@ ************************************************************/ package examples.groups; -import hdf.hdf5lib.H5; -import hdf.hdf5lib.HDF5Constants; -import hdf.hdf5lib.structs.H5G_info_t; - import java.util.EnumSet; import java.util.HashMap; import java.util.Map; +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 String FILE = "H5Ex_G_Phase.h5"; + private static int MAX_GROUPS = 7; private static int MAX_COMPACT = 5; - private static int MIN_DENSE = 3; + private static int MIN_DENSE = 3; enum H5G_storage { H5G_STORAGE_TYPE_UNKNOWN(-1), @@ -38,42 +38,39 @@ public class H5Ex_G_Phase { private static final Map<Integer, H5G_storage> lookup = new HashMap<Integer, H5G_storage>(); - static { + 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; - } + H5G_storage(int layout_type) { this.code = layout_type; } - public int getCode() { - return this.code; - } + public int getCode() { return this.code; } - public static H5G_storage get(int code) { - return lookup.get(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; + 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; + 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. + // 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); + H5.H5Pset_libver_bounds(fapl_id, HDF5Constants.H5F_LIBVER_LATEST, + HDF5Constants.H5F_LIBVER_LATEST); } catch (Exception e) { e.printStackTrace(); @@ -101,21 +98,23 @@ public class H5Ex_G_Phase { // 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); + 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. + // 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. */ + 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); + subgroup_id = H5.H5Gcreate(group_id, name, HDF5Constants.H5P_DEFAULT, + HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT); H5.H5Gclose(subgroup_id); } } @@ -127,7 +126,8 @@ public class H5Ex_G_Phase { try { if (group_id >= 0) { ginfo = H5.H5Gget_info(group_id); - System.out.print(ginfo.nlinks + " Group" + (ginfo.nlinks == 1 ? " " : "s") + ": Storage type is "); + 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 @@ -169,7 +169,8 @@ public class H5Ex_G_Phase { try { if (group_id >= 0) { ginfo = H5.H5Gget_info(group_id); - System.out.print(ginfo.nlinks + " Group" + (ginfo.nlinks == 1 ? " " : "s") + ": Storage type is "); + 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 @@ -228,11 +229,7 @@ public class H5Ex_G_Phase { catch (Exception e) { e.printStackTrace(); } - - } - - public static void main(String[] args) { - H5Ex_G_Phase.CreateGroup(); } + public static void main(String[] args) { H5Ex_G_Phase.CreateGroup(); } } diff --git a/java/examples/groups/H5Ex_G_Traverse.java b/java/examples/groups/H5Ex_G_Traverse.java index c5b6373..cd60f6b 100644 --- a/java/examples/groups/H5Ex_G_Traverse.java +++ b/java/examples/groups/H5Ex_G_Traverse.java @@ -24,10 +24,11 @@ package examples.groups; import hdf.hdf5lib.H5; import hdf.hdf5lib.HDF5Constants; -import hdf.hdf5lib.callbacks.H5L_iterate_t; 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 { @@ -38,10 +39,11 @@ class opdata implements H5L_iterate_opdata_t { public class H5Ex_G_Traverse { - private static String FILE = "h5ex_g_traverse.h5"; + private static String FILE = "h5ex_g_traverse.h5"; public static H5L_iterate_t iter_cb = new H5L_iter_callbackT(); - private static void OpenGroup() { + private static void OpenGroup() + { long file_id = HDF5Constants.H5I_INVALID_HID; H5O_info_t infobuf; opdata od = new opdata(); @@ -50,9 +52,9 @@ public class H5Ex_G_Traverse { 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; + infobuf = H5.H5Oget_info(file_id); + od.recurs = 0; + od.prev = null; od.obj_token = infobuf.token; } } @@ -64,7 +66,8 @@ public class H5Ex_G_Traverse { 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); + H5.H5Literate(file_id, HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_NATIVE, 0L, iter_cb, + od); System.out.println("}"); } catch (Exception e) { @@ -81,18 +84,17 @@ public class H5Ex_G_Traverse { } } - public static void main(String[] args) { - H5Ex_G_Traverse.OpenGroup(); - } + 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) { + 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. + 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. @@ -123,13 +125,14 @@ class H5L_iter_callbackT implements H5L_iterate_t { // 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; + 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); + 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(" "); @@ -152,7 +155,8 @@ class H5L_iter_callbackT implements H5L_iterate_t { return return_val; } - public boolean group_check(opdata od, H5O_token_t target_token) { + 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) @@ -160,5 +164,4 @@ class H5L_iter_callbackT implements H5L_iterate_t { else return group_check(od.prev, target_token); // Recursively examine the next node } - } diff --git a/java/examples/groups/H5Ex_G_Visit.java b/java/examples/groups/H5Ex_G_Visit.java index 790be80..d14ded6 100644 --- a/java/examples/groups/H5Ex_G_Visit.java +++ b/java/examples/groups/H5Ex_G_Visit.java @@ -20,22 +20,23 @@ ************************************************************/ package examples.groups; +import java.util.ArrayList; + import hdf.hdf5lib.H5; import hdf.hdf5lib.HDF5Constants; -import hdf.hdf5lib.callbacks.H5L_iterate_t; import hdf.hdf5lib.callbacks.H5L_iterate_opdata_t; -import hdf.hdf5lib.callbacks.H5O_iterate_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; -import java.util.ArrayList; - public class H5Ex_G_Visit { private static String FILE = "groups/h5ex_g_visit.h5"; - public static void main(String[] args) { + public static void main(String[] args) + { try { (new H5Ex_G_Visit()).VisitGroup(); } @@ -44,7 +45,8 @@ public class H5Ex_G_Visit { } } - private void VisitGroup() throws Exception { + private void VisitGroup() throws Exception + { long file_id = HDF5Constants.H5I_INVALID_HID; @@ -55,15 +57,16 @@ public class H5Ex_G_Visit { // 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); + 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(); + 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); - + H5.H5Lvisit(file_id, HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_NATIVE, iter_cb2, + iter_data2); } catch (Exception e) { e.printStackTrace(); @@ -76,15 +79,16 @@ public class H5Ex_G_Visit { } /************************************************************ - * 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. + * 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; + public int link_type = -1; - idata(String name, int type) { + idata(String name, int type) + { this.link_name = name; this.link_type = type; } @@ -95,20 +99,21 @@ public class H5Ex_G_Visit { } 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) { + 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); + ((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); + // 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); + ret = iter_cbO.callback(group, name, infobuf, iter_dataO); } catch (Exception e) { e.printStackTrace(); @@ -123,9 +128,10 @@ public class H5Ex_G_Visit { } 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) { + 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); + ((H5O_iter_data)op_data).iterdata.add(id); System.out.print("/"); /* Print root group in object path */ @@ -145,5 +151,4 @@ public class H5Ex_G_Visit { return 0; } } - } |