Skip to content

Commit 65aac63

Browse files
committed
Updates for v2 arch
1 parent d3392fb commit 65aac63

3 files changed

Lines changed: 103 additions & 94 deletions

File tree

src/main/java/org/hdf5javalib/examples/hdf5examples/HDF5Debug.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private void run() {
5555
// List all .h5 files in HDF5Examples resources directory
5656
// ATL03_20250302235544_11742607_006_01
5757
// Path dirPath = Paths.get(Objects.requireNonNull(HDF5Debug.class.getClassLoader().getResource("HDF5Examples/h5ex_g_compact2.h5")).toURI());
58-
Path dirPath = Paths.get("c:/users/karnicho/Downloads/ATL03_20250302235544_11742607_006_01.h5");
58+
Path dirPath = Paths.get("c:/users/karln/Downloads/ATL03_20250302235544_11742607_006_01.h5");
5959
processFile(dirPath);
6060
} catch (Exception e) {
6161
throw new IllegalStateException(e);
@@ -65,18 +65,21 @@ private void run() {
6565
private static void processFile(Path filePath) {
6666
try (SeekableByteChannel channel = Files.newByteChannel(filePath, StandardOpenOption.READ)) {
6767
HdfFileReader reader = new HdfFileReader(channel).readFile();
68+
6869
// for (HdfDataset dataSet : reader.getDatasets()) {
6970
// System.out.println("{} " + dataSet);
7071
//// log.info("{} ", dataSet);
7172
// HdfDisplayCountUtils.displayData(channel, dataSet, reader);
7273
//// displayScalarData(channel, dataSet, HdfFloatPoint.class, reader);
7374
// }
75+
7476
HdfDataset dataSet = reader.getDataset("/gt1l/heights/delta_time").get();
7577
System.out.println("{} " + dataSet);
7678
// System.out.println("{} " + dataSet.getObjectPath());
7779
// log.info("{} ", dataSet);
7880
HdfDisplayUtils.displayData(channel, dataSet, reader);
7981
// displayScalarData(channel, dataSet, HdfFloatPoint.class, reader);
82+
8083
} catch (Exception e) {
8184
log.error("Exception in processFile: {}", filePath, e);
8285
}

src/main/java/org/hdf5javalib/hdffile/dataobjects/messages/DataLayoutMessage.java

Lines changed: 3 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import org.hdf5javalib.hdffile.infrastructure.HdfBTreeV1;
88
import org.hdf5javalib.hdffile.infrastructure.HdfChunkBTreeEntry;
99
import org.hdf5javalib.hdfjava.HdfDataFile;
10+
import org.hdf5javalib.hdfjava.HdfFileReader;
1011
import org.hdf5javalib.utils.HdfDisplayUtils;
1112
import org.hdf5javalib.utils.HdfReadUtils;
1213

@@ -160,7 +161,8 @@ public static HdfMessage parseHeaderMessage(int flags, byte[] data, HdfDataFile
160161
8, 0, (8 * 8),
161162
hdfDataFile);
162163

163-
bTree = readBTreeFromSeekableByteChannel(hdfDataFile.getSeekableByteChannel(), chunkedDataAddress.getInstance(Long.class), numDimensions, eightByteFixedPointType, hdfDataFile);
164+
// bTree = HdfFileReader.readBTreeFromSeekableByteChannel(hdfDataFile.getSeekableByteChannel(), chunkedDataAddress.getInstance(Long.class), numDimensions, eightByteFixedPointType, hdfDataFile);
165+
bTree = HdfFileReader.readBTreeFromSeekableByteChannel(hdfDataFile.getSeekableByteChannel(), chunkedDataAddress.getInstance(Long.class), hdfDataFile);
164166
} else {
165167
bTree = null;
166168
}
@@ -198,98 +200,6 @@ public static HdfMessage parseHeaderMessage(int flags, byte[] data, HdfDataFile
198200
return new DataLayoutMessage(version, dataLayoutStorage, flags, data.length);
199201
}
200202

201-
/**
202-
* Reads an HdfTree from a file channel.
203-
*
204-
* @param fileChannel the file channel to read from
205-
* @param hdfDataFile the HDF5 file context
206-
* @return the constructed HdfTree instance
207-
* @throws IOException if an I/O error occurs or the B-Tree data is invalid
208-
*/
209-
public static HdfBTreeV1 readBTreeFromSeekableByteChannel(
210-
SeekableByteChannel fileChannel,
211-
long btreeAddress,
212-
int dimensions,
213-
FixedPointDatatype eightByteFixedPointType,
214-
HdfDataFile hdfDataFile
215-
) throws IOException, InvocationTargetException, InstantiationException, IllegalAccessException {
216-
return readFromSeekableByteChannelRecursive(fileChannel, btreeAddress, dimensions, eightByteFixedPointType, hdfDataFile, new LinkedHashMap<>());
217-
}
218-
219-
/**
220-
* Recursively reads an HdfTree from a file channel, handling cycles.
221-
*
222-
* @param fileChannel the file channel to read from
223-
* @param nodeAddress the address of the current node
224-
* @param visitedNodes a map of visited node addresses to detect cycles
225-
* @param hdfDataFile the HDF5 file context
226-
* @return the constructed HdfTree instance
227-
* @throws IOException if an I/O error occurs or the B-Tree data is invalid
228-
*/
229-
private static HdfBTreeV1 readFromSeekableByteChannelRecursive(SeekableByteChannel fileChannel,
230-
long nodeAddress,
231-
int dimensions,
232-
FixedPointDatatype eightByteFixedPointType,
233-
HdfDataFile hdfDataFile,
234-
Map<Long, HdfBTreeV1> visitedNodes
235-
) throws IOException, InvocationTargetException, InstantiationException, IllegalAccessException {
236-
if (visitedNodes.containsKey(nodeAddress)) {
237-
throw new IllegalStateException("Cycle detected or node re-visited: BTree node address "
238-
+ nodeAddress + " encountered again during recursive read.");
239-
}
240-
241-
fileChannel.position(nodeAddress);
242-
FixedPointDatatype hdfOffset = hdfDataFile.getSuperblock().getFixedPointDatatypeForOffset();
243-
final int offsetSize = hdfOffset.getSize();
244-
245-
int headerSize = BTREE_HEADER_INITIAL_SIZE + offsetSize + offsetSize;
246-
ByteBuffer headerBuffer = ByteBuffer.allocate(headerSize).order(ByteOrder.LITTLE_ENDIAN);
247-
fileChannel.read(headerBuffer);
248-
headerBuffer.flip();
249-
250-
byte[] signatureBytes = new byte[BTREE_SIGNATURE.length];
251-
headerBuffer.get(signatureBytes);
252-
if (Arrays.compare(signatureBytes, BTREE_SIGNATURE) != 0) {
253-
throw new IOException("Invalid B-tree node signature: '" + Arrays.toString(signatureBytes) + "' at position " + nodeAddress);
254-
}
255-
256-
int nodeType = Byte.toUnsignedInt(headerBuffer.get());
257-
int nodeLevel = Byte.toUnsignedInt(headerBuffer.get());
258-
int entriesUsed = Short.toUnsignedInt(headerBuffer.getShort());
259-
260-
HdfFixedPoint leftSiblingAddress = HdfReadUtils.readHdfFixedPointFromBuffer(hdfOffset, headerBuffer);
261-
HdfFixedPoint rightSiblingAddress = HdfReadUtils.readHdfFixedPointFromBuffer(hdfOffset, headerBuffer);
262-
263-
int entriesDataSize = (4 + 4 + 8*dimensions + offsetSize + offsetSize) * entriesUsed;
264-
ByteBuffer entriesBuffer = ByteBuffer.allocate(entriesDataSize).order(ByteOrder.LITTLE_ENDIAN);
265-
fileChannel.read(entriesBuffer);
266-
entriesBuffer.flip();
267-
268-
List<HdfBTreeEntryBase> entries = new ArrayList<>(entriesUsed);
269-
270-
HdfBTreeV1 currentNode = new HdfBTreeV1(nodeType, nodeLevel, entriesUsed, leftSiblingAddress, rightSiblingAddress, null, entries, hdfDataFile);
271-
visitedNodes.put(nodeAddress, currentNode);
272-
273-
// (4 + 4 + 8*dimensions + 1*length + 1*length) * entriesUsed
274-
// 4 + 4 + 8*dimensions + 8 + 8
275-
// 8 + 24 + 16
276-
// 48
277-
278-
for (int i = 0; i < entriesUsed; i++) {
279-
long sizeOfChunk = Integer.toUnsignedLong(entriesBuffer.getInt());
280-
long filterMask = Integer.toUnsignedLong(entriesBuffer.getInt());
281-
List<HdfFixedPoint> dimensionOffsets = new ArrayList<>();
282-
for (int j = 0; j < dimensions; j++) {
283-
dimensionOffsets.add(HdfReadUtils.readHdfFixedPointFromBuffer(eightByteFixedPointType, entriesBuffer));
284-
}
285-
HdfFixedPoint zeroValue = HdfReadUtils.readHdfFixedPointFromBuffer(hdfOffset, entriesBuffer);
286-
HdfFixedPoint childPointer = HdfReadUtils.readHdfFixedPointFromBuffer(hdfOffset, entriesBuffer);
287-
288-
entries.add(new HdfChunkBTreeEntry(null, childPointer, null, sizeOfChunk, filterMask, dimensionOffsets));
289-
}
290-
return currentNode;
291-
}
292-
293203

294204
/**
295205
* Returns a string representation of this DataLayoutMessage.

src/main/java/org/hdf5javalib/hdfjava/HdfFileReader.java

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,102 @@ private static HdfBTreeV1 readFromSeekableByteChannelRecursive(SeekableByteChann
663663
return currentNode;
664664
}
665665

666+
// /**
667+
// * Reads an HdfTree from a file channel.
668+
// *
669+
// * @param fileChannel the file channel to read from
670+
// * @param hdfDataFile the HDF5 file context
671+
// * @return the constructed HdfTree instance
672+
// * @throws IOException if an I/O error occurs or the B-Tree data is invalid
673+
// */
674+
// public static HdfBTreeV1 readBTreeFromSeekableByteChannel(
675+
// SeekableByteChannel fileChannel,
676+
// long btreeAddress,
677+
// int dimensions,
678+
// FixedPointDatatype eightByteFixedPointType,
679+
// HdfDataFile hdfDataFile
680+
// ) throws IOException, InvocationTargetException, InstantiationException, IllegalAccessException {
681+
// return readFromSeekableByteChannelRecursive(fileChannel, btreeAddress, dimensions, eightByteFixedPointType, hdfDataFile, new LinkedHashMap<>());
682+
// }
683+
//
684+
// /**
685+
// * Recursively reads an HdfTree from a file channel, handling cycles.
686+
// *
687+
// * @param fileChannel the file channel to read from
688+
// * @param nodeAddress the address of the current node
689+
// * @param visitedNodes a map of visited node addresses to detect cycles
690+
// * @param hdfDataFile the HDF5 file context
691+
// * @return the constructed HdfTree instance
692+
// * @throws IOException if an I/O error occurs or the B-Tree data is invalid
693+
// */
694+
// private static HdfBTreeV1 readFromSeekableByteChannelRecursive(SeekableByteChannel fileChannel,
695+
// long nodeAddress,
696+
// int dimensions,
697+
// FixedPointDatatype eightByteFixedPointType,
698+
// HdfDataFile hdfDataFile,
699+
// Map<Long, HdfBTreeV1> visitedNodes
700+
// ) throws IOException, InvocationTargetException, InstantiationException, IllegalAccessException {
701+
// if (visitedNodes.containsKey(nodeAddress)) {
702+
// throw new IllegalStateException("Cycle detected or node re-visited: BTree node address "
703+
// + nodeAddress + " encountered again during recursive read.");
704+
// }
705+
//
706+
// fileChannel.position(nodeAddress);
707+
// FixedPointDatatype hdfOffset = hdfDataFile.getSuperblock().getFixedPointDatatypeForOffset();
708+
// final int offsetSize = hdfOffset.getSize();
709+
//
710+
// int headerSize = BTREE_HEADER_INITIAL_SIZE + offsetSize + offsetSize;
711+
// ByteBuffer headerBuffer = ByteBuffer.allocate(headerSize).order(ByteOrder.LITTLE_ENDIAN);
712+
// fileChannel.read(headerBuffer);
713+
// headerBuffer.flip();
714+
//
715+
// byte[] signatureBytes = new byte[BTREE_SIGNATURE.length];
716+
// headerBuffer.get(signatureBytes);
717+
// if (Arrays.compare(signatureBytes, BTREE_SIGNATURE) != 0) {
718+
// throw new IOException("Invalid B-tree node signature: '" + Arrays.toString(signatureBytes) + "' at position " + nodeAddress);
719+
// }
720+
//
721+
// int nodeType = Byte.toUnsignedInt(headerBuffer.get());
722+
// int nodeLevel = Byte.toUnsignedInt(headerBuffer.get());
723+
// int entriesUsed = Short.toUnsignedInt(headerBuffer.getShort());
724+
//
725+
// HdfFixedPoint leftSiblingAddress = HdfReadUtils.readHdfFixedPointFromBuffer(hdfOffset, headerBuffer);
726+
// HdfFixedPoint rightSiblingAddress = HdfReadUtils.readHdfFixedPointFromBuffer(hdfOffset, headerBuffer);
727+
//
728+
// int entriesDataSize = (4 + 4 + 8*dimensions + offsetSize + offsetSize) * entriesUsed;
729+
// ByteBuffer entriesBuffer = ByteBuffer.allocate(entriesDataSize).order(ByteOrder.LITTLE_ENDIAN);
730+
// fileChannel.read(entriesBuffer);
731+
// entriesBuffer.flip();
732+
//
733+
// List<HdfBTreeEntryBase> entries = new ArrayList<>(entriesUsed);
734+
//
735+
// HdfBTreeV1 currentNode = new HdfBTreeV1(nodeType, nodeLevel, entriesUsed, leftSiblingAddress, rightSiblingAddress, null, entries, hdfDataFile);
736+
// visitedNodes.put(nodeAddress, currentNode);
737+
//
738+
// // (4 + 4 + 8*dimensions + 1*length + 1*length) * entriesUsed
739+
// // 4 + 4 + 8*dimensions + 8 + 8
740+
// // 8 + 24 + 16
741+
// // 48
742+
//
743+
// for (int i = 0; i < entriesUsed; i++) {
744+
// long sizeOfChunk = Integer.toUnsignedLong(entriesBuffer.getInt());
745+
// long filterMask = Integer.toUnsignedLong(entriesBuffer.getInt());
746+
// List<HdfFixedPoint> dimensionOffsets = new ArrayList<>();
747+
// for (int j = 0; j < dimensions; j++) {
748+
// dimensionOffsets.add(HdfReadUtils.readHdfFixedPointFromBuffer(eightByteFixedPointType, entriesBuffer));
749+
// }
750+
// HdfFixedPoint zeroValue = HdfReadUtils.readHdfFixedPointFromBuffer(hdfOffset, entriesBuffer);
751+
// HdfFixedPoint childPointer = HdfReadUtils.readHdfFixedPointFromBuffer(hdfOffset, entriesBuffer);
752+
//
753+
// if ( nodeLevel == 0 ) {
754+
// entries.add(new HdfChunkBTreeEntry(null, childPointer, null, sizeOfChunk, filterMask, dimensionOffsets));
755+
// } else {
756+
// HdfBTreeV1 bTree = readFromSeekableByteChannelRecursive(fileChannel, childPointer.getInstance(Long.class), dimensions, eightByteFixedPointType, hdfDataFile, visitedNodes);
757+
// }
758+
// }
759+
// return currentNode;
760+
// }
761+
//
666762
/**
667763
* Reads an HdfGroupSymbolTableNode from a file channel.
668764
*

0 commit comments

Comments
 (0)