Repository navigation
Expand file tree
/
Copy pathTestHDF5Misc.java
More file actions
executable file
·109 lines (96 loc) · 3.34 KB
/
Copy pathTestHDF5Misc.java
File metadata and controls
executable file
·109 lines (96 loc) · 3.34 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// @(#) Sandia: $Header$
// @(#) Sandia: $Source$
// @(#) Sandia: $Revision$
// @(#) Sandia: $Author$
// @(#) Sandia: $Date$
//
// Copyright 2006 Sandia National Laboratories. All rights reserved.
import java.util.List;
import ncsa.hdf.object.CompoundDS;
import ncsa.hdf.object.Dataset;
import ncsa.hdf.object.Group;
import ncsa.hdf.object.HObject;
import ncsa.hdf.object.h5.H5File;
public class TestHDF5Misc
{
public static void main (String[] args) throws Exception
{
H5File file = new H5File("./TestHDF5Misc.h5", H5File.READ);
testGetMemberList(file);
testGetPath(file);
testIsRoot(file);
}
/**
* This is a bug. The objects that are returned by the
* 'Group.getMemberList()' method don't appear to be initialized
* properly. The objects returned are typed correctly (the list
* returned seems to contain 'Group', 'CompoundDS', or 'Dataset' objects),
* but not all the methods available for these classes seem
* to work propertly.
*/
public static void testGetMemberList (H5File file) throws Exception
{
Group group = (Group)file.get("/");
printHObject(group);
}
private static void printHObject (HObject hObject) throws Exception
{
if (hObject instanceof Group) printHObject((Group)hObject);
if (hObject instanceof CompoundDS) printHObject((CompoundDS)hObject);
if (hObject instanceof Dataset) printHObject((Dataset)hObject);
}
private static void printHObject (Group group) throws Exception
{
List<HObject> list = (List<HObject>)group.getMemberList();
for (HObject hObject : list)
{
System.out.println(
hObject.getPath() + hObject.getName() + " : " + hObject.getClass().getName());
try
{
printHObject(hObject);
}
catch (Exception e)
{
System.out.println(e);
}
}
}
private static void printHObject (CompoundDS compoundDS) throws Exception
{
System.out.println(compoundDS.getData());
}
private static void printHObject (Dataset dataset) throws Exception
{
System.out.println(dataset.getData());
}
/**
* This is probably not a bug, but is inconvenient. Normally, if you
* have an HObject, you could use 'getPath() + getName()' to obtain
* the full path, but the root HObject is a special case because 'getPath()'
* returns a null object, rather than an empty string. So, you have
* to check if your HObject is the root. See next method!
*/
public static void testGetPath (H5File file) throws Exception
{
HObject hObject = file.get("/");
System.out.println("Next line should print '':");
System.out.println(hObject.getPath());
}
/**
* This is a bug. The 'Group.isRoot()' operation operation seems
* to return 'true' no matter what...
*/
public static void testIsRoot (H5File file) throws Exception
{
Group group = (Group)file.get("/");
System.out.println("Next line should print 'true':");
System.out.println(group.isRoot());
group = (Group)file.get("/Group0");
System.out.println("Next line should print 'false':");
System.out.println(group.isRoot());
group = (Group)file.get("/Group0/SubGroup0");
System.out.println("Next line should print 'false':");
System.out.println(group.isRoot());
}
}