Skip to content

Commit dcaa80c

Browse files
committed
New test for h5ex_tutr.
1 parent 472550a commit dcaa80c

2 files changed

Lines changed: 22 additions & 44 deletions

File tree

src/main/java/org/hdf5javalib/examples/HDF5Examples/ReferenceRead.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private void run() {
5858
// }
5959
try {
6060
// Path filePath = getResourcePath("HDF5Examples/h5ex_t_cpxcmpd.h5");
61-
Path filePath = getResourcePath("h5ex_tutr/refer_deprec.h5");
61+
Path filePath = getResourcePath("h5ex_tutr/SDScompound.h5");
6262
System.out.println(filePath.toFile().getAbsolutePath());
6363
try (SeekableByteChannel channel = Files.newByteChannel(filePath, StandardOpenOption.READ)) {
6464
HdfFileReader reader = new HdfFileReader(channel).readFile();

src/test/java/org/hdf5javalib/examples/h5ex_tutr/H5exTutrReadTest.java

Lines changed: 21 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,6 @@ private int[][] toIntMatrix(HdfData[][] data) {
2727
return res;
2828
}
2929

30-
private double[][] toDoubleMatrix(HdfData[][] data) {
31-
double[][] res = new double[data.length][data[0].length];
32-
for (int i = 0; i < data.length; i++) {
33-
for (int j = 0; j < data[i].length; j++) {
34-
res[i][j] = data[i][j].getInstance(Double.class);
35-
}
36-
}
37-
return res;
38-
}
39-
4030
private int[] toIntArray(HdfData[] data) {
4131
int[] res = new int[data.length];
4232
for (int i = 0; i < data.length; i++) {
@@ -45,19 +35,6 @@ private int[] toIntArray(HdfData[] data) {
4535
return res;
4636
}
4737

48-
// private double[] toMixedArray(HdfData[] data) {
49-
// double[] res = new double[data.length];
50-
// for (int i = 0; i < data.length; i++) {
51-
// HdfData d = data[i];
52-
// if (d instanceof FixedPointDatatype) {
53-
// res[i] = d.getInstance(Long.class).doubleValue();
54-
// } else if (d.getDatatype() instanceof org.hdf5javalib.hdfjava.datatype.FloatingPointDatatype) {
55-
// res[i] = d.getInstance(Double.class);
56-
// }
57-
// }
58-
// return res;
59-
// }
60-
6138
private String[] toStringArray(HdfData[] data) {
6239
String[] res = new String[data.length];
6340
for (int i = 0; i < data.length; i++) {
@@ -155,15 +132,6 @@ void testRefere() throws Exception {
155132
try (SeekableByteChannel channel = ResourceLoader.loadResourceAsChannel("h5ex_tutr/refere.h5")) {
156133
HdfFileReader reader = new HdfFileReader(channel).readFile();
157134
HdfDataset dataSet = reader.getDataset("/B").orElseThrow();
158-
// TypedDataSource<HdfData> dataSource = new TypedDataSource<>(channel, reader, dataSet, HdfData.class);
159-
// HdfData[][] data = dataSource.readMatrix();
160-
// int[][] intData = toIntMatrix(data);
161-
// int[][] expected = {
162-
// {1, 1, 2, 3, 3, 4, 5, 5, 6},
163-
// {1, 2, 2, 3, 4, 4, 5, 6, 6}
164-
// };
165-
// assertArrayEquals(expected, intData);
166-
167135
dataSet = reader.getDataset("/R").orElseThrow();
168136
TypedDataSource<HdfData> dataSource = new TypedDataSource<>(channel, reader, dataSet, HdfData.class);
169137
HdfData[] data1 = dataSource.readVector();
@@ -233,17 +201,27 @@ void testSDS() throws Exception {
233201
}
234202
}
235203

236-
// @Test
237-
// void testSDScompound() throws Exception {
238-
// try (SeekableByteChannel channel = ResourceLoader.loadResourceAsChannel("h5ex_tutr/SDScompound.h5")) {
239-
// HdfFileReader reader = new HdfFileReader(channel).readFile();
240-
// HdfDataset dataSet = reader.getDataset("/ArrayOfStructures").orElseThrow();
241-
// TypedDataSource<HdfData> dataSource = new TypedDataSource<>(channel, reader, dataSet, HdfData.class);
242-
// HdfData[] data = dataSource.readVector();
243-
// double[] expected = {0, 1.0, 0.0, 1, 0.5, 1.0, 2, 1.0/3, 4.0, 3, 1.0/4, 9.0, 4, 1.0/5, 16.0, 5, 1.0/6, 25.0, 6, 1.0/7, 36.0, 7, 1.0/8, 49.0, 8, 1.0/9, 64.0, 9, 1.0/10, 81.0};
244-
// assertArrayEquals(expected, toMixedArray(data), 1e-5);
245-
// }
246-
// }
204+
private record DSCompound (Integer a_name, Double c_name, Float b_name) {}
205+
@Test
206+
void testSDScompound() throws Exception {
207+
try (SeekableByteChannel channel = ResourceLoader.loadResourceAsChannel("h5ex_tutr/SDScompound.h5")) {
208+
HdfFileReader reader = new HdfFileReader(channel).readFile();
209+
HdfDataset dataSet = reader.getDataset("/ArrayOfStructures").orElseThrow();
210+
TypedDataSource<DSCompound> dataSource = new TypedDataSource<>(channel, reader, dataSet, DSCompound.class);
211+
DSCompound[] data = dataSource.readVector();
212+
DSCompound[] expected = { new DSCompound(0, 1.0, 0.0F),
213+
new DSCompound(1, 0.5, 1.0F),
214+
new DSCompound(2, 1.0/3, 4.0F),
215+
new DSCompound(3, 1.0/4, 9.0F),
216+
new DSCompound(4, 1.0/5, 16.0F),
217+
new DSCompound(5, 1.0/6, 25.0F),
218+
new DSCompound(6, 1.0/7, 36.0F),
219+
new DSCompound(7, 1.0/8, 49.0F),
220+
new DSCompound(8, 1.0/9, 64.0F),
221+
new DSCompound(9, 1.0/10, 81.0F)};
222+
assertArrayEquals(expected, data);
223+
}
224+
}
247225

248226
@Test
249227
void testSDSextendible() throws Exception {

0 commit comments

Comments
 (0)