Repository navigation
Expand file tree
/
Copy pathTestHDF5Create.java
More file actions
executable file
·92 lines (76 loc) · 2.64 KB
/
Copy pathTestHDF5Create.java
File metadata and controls
executable file
·92 lines (76 loc) · 2.64 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
// @(#) Sandia: $Header$
// @(#) Sandia: $Source$
// @(#) Sandia: $Revision$
// @(#) Sandia: $Author$
// @(#) Sandia: $Date$
//
// Copyright 2006 Sandia National Laboratories. All rights reserved.
import java.util.Date;
import java.util.Vector;
import ncsa.hdf.hdf5lib.H5;
import ncsa.hdf.hdf5lib.HDF5Constants;
import ncsa.hdf.object.Dataset;
import ncsa.hdf.object.Datatype;
import ncsa.hdf.object.Group;
import ncsa.hdf.object.h5.H5Datatype;
import ncsa.hdf.object.h5.H5File;
public class TestHDF5Create
{
public static void main (String[] args) throws Exception
{
H5File file = new H5File("./TestHDF5Create.h5", H5File.WRITE);
// get the root group
Group rootgroup = (Group)file.get("/");
if (rootgroup == null)
{
throw new Exception("Could not get group: /");
}
// make a subgroup using the current timestamp (milliseconds since epoch)
Date now = new Date();
String nowString = new Long(now.getTime()).toString();
String newGroupPath = "/" + nowString;
Group newGroup = file.createGroup(nowString, rootgroup);
if (newGroup == null)
{
throw new Exception("Could not create new group: " + newGroupPath);
}
// flush the changes
H5.H5Fflush(file.getFID(), HDF5Constants.H5F_SCOPE_GLOBAL);
// reopen the file
file = new H5File("./TestHDF5Create.h5", H5File.WRITE);
// read the subgroup
newGroup = (Group)file.get(newGroupPath);
if (newGroup == null)
{
throw new Exception("Could not get newly created group: " + newGroupPath);
}
// make a table in the new group
String newTablePath = newGroupPath + "/CreatedTable";
long[] dims = {3};
String[] memberNames = {"Column"};
Datatype[] datatypes = {
new H5Datatype(
Datatype.CLASS_STRING,
256,
Datatype.NATIVE,
Datatype.NATIVE)};
int[] memberOrders = {256};
Vector<String[]> data = new Vector<String[]>();
String[] columnValues = {"One", "Two", "Three"};
data.add(columnValues);
Dataset dataset = file.createCompoundDS(
"CreatedTable", newGroup, dims, memberNames,
datatypes, memberOrders, data);
// flush the changes
H5.H5Fflush(file.getFID(), HDF5Constants.H5F_SCOPE_GLOBAL);
// reopen the file
file = new H5File("./TestHDF5Create.h5", H5File.WRITE);
// read the new table
dataset = (Dataset)file.get(newTablePath);
if (dataset == null)
{
throw new Exception("Could not get newly created table: " + newTablePath);
}
System.out.println("OK");
}
}