File: H5Ex_G_Corder.java

package info (click to toggle)
jhdf 2.11.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 39,996 kB
  • ctags: 17,959
  • sloc: java: 100,416; ansic: 24,920; sh: 2,256; makefile: 957; cpp: 48
file content (95 lines) | stat: -rw-r--r-- 3,452 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package examples.groups;

import ncsa.hdf.hdf5lib.H5;
import ncsa.hdf.hdf5lib.HDF5Constants;
import ncsa.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 {
		int      file_id = -1;
		int      group_id = -1;
		int      subgroup_id = -1;
		int      gcpl_id = -1;        
		int      status;
		H5G_info_t  ginfo;  
		int      i;                                  
		String   name;                             

		try {
			// Create a new file using default properties.
			file_id = H5.H5Fcreate (FILE, HDF5Constants.H5F_ACC_TRUNC, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);

			// Create group creation property list and enable link creation order tracking.
			gcpl_id = H5.H5Pcreate (HDF5Constants.H5P_GROUP_CREATE);
			status = H5.H5Pset_link_creation_order(gcpl_id, HDF5Constants.H5P_CRT_ORDER_TRACKED + HDF5Constants.H5P_CRT_ORDER_INDEXED);

			// Create primary group using the property list.
			if (status >= 0)
				group_id = H5.H5Gcreate(file_id, "index_group", HDF5Constants.H5P_DEFAULT, gcpl_id, HDF5Constants.H5P_DEFAULT);

			try {
				/*
				 * Create subgroups in the primary group.  These will be tracked
				 * by creation order.  Note that these groups do not have to have
				 * the creation order tracking property set.
				 */
				subgroup_id = H5.H5Gcreate(group_id, "H", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
				status = H5.H5Gclose(subgroup_id);
				subgroup_id = H5.H5Gcreate(group_id, "D", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
				status = H5.H5Gclose(subgroup_id);
				subgroup_id = H5.H5Gcreate(group_id, "F", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
				status = H5.H5Gclose(subgroup_id);
				subgroup_id = H5.H5Gcreate(group_id, "5", HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT, HDF5Constants.H5P_DEFAULT);
				status = H5.H5Gclose(subgroup_id);

				// Get group info.
				ginfo= H5.H5Gget_info(group_id);

				//Traverse links in the primary group using alphabetical indices (H5_INDEX_NAME).
				System.out.println("Traversing group using alphabetical indices:");
				for (i=0; i<ginfo.nlinks; i++) {
					//Retrieve the name of the ith link in a group
					name = H5.H5Lget_name_by_idx(group_id, ".", HDF5Constants.H5_INDEX_NAME, HDF5Constants.H5_ITER_INC, i, HDF5Constants.H5P_DEFAULT);
					System.out.println("Index " + i + ": " + name);
				}

				//Traverse links in the primary group by creation order (H5_INDEX_CRT_ORDER).
				System.out.println("Traversing group using creation order indices:");
				for (i=0; i<ginfo.nlinks; i++) {
					//Retrieve the name of the ith link in a group
					name = H5.H5Lget_name_by_idx(group_id, ".", HDF5Constants.H5_INDEX_CRT_ORDER, HDF5Constants.H5_ITER_INC, i, HDF5Constants.H5P_DEFAULT);
					System.out.println("Index " + i + ": " + name);
				}

			}
			catch (Exception e) {
				e.printStackTrace();
			}
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		finally {
			// Close and release resources.
			if (gcpl_id >= 0)
				H5.H5Pclose (gcpl_id);
			if (group_id >= 0)
				H5.H5Gclose (group_id);
			if (file_id >= 0)
				H5.H5Fclose (file_id);
		}
	}

	public static void main(String[] args) {
		try {
			H5Ex_G_Corder.CreateGroup();
		}
		catch(Exception ex) {
			ex.printStackTrace();
		}
	}

}