# Read only part of large compound dataset member

**URL:** <https://forum.hdfgroup.org/t/read-only-part-of-large-compound-dataset-member/10325>\
**Category:** HDF5 Library\
**Created:** [October 19, 2022, 6:45pm UTC](https://forum.hdfgroup.org/t/read-only-part-of-large-compound-dataset-member/10325 "2022-10-19T18:45:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![marius.graefe](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/m/5f9b8f/32.png) [@marius.graefe](https://forum.hdfgroup.org/u/marius.graefe)\
**Post date:** [October 19, 2022, 6:45pm UTC](https://forum.hdfgroup.org/t/read-only-part-of-large-compound-dataset-member/10325/1 "2022-10-19T18:45:01Z")

</div>

Hello,

My h5 file has a dataset with a simple table structure with three columns and about 8000 rows. I believe it was created using the high-level H5TB set of functions.  
The members of the compound dataset (i.e. the columns of the table) are:

- 32 bit integer
- 64 bit integer
- Array [102400] of 8-bit unsigned integer

Here’s the problem: For each row, I only need to read the first ~100 bytes of the array.

With H5TBread\_fields\_index I am able to read the whole column, however that basically means reading the whole dataset and performance-wise that isn’t what I’m looking for. I tried defining my own compound datatype, my own opaque datatype, and read it via hyperslabs etc. but to no avail. H5Dread would always throw an error.

Is there a way to read this array only partially for each row?

---

<div class="post-metadata">

**Author:** ![gheber](https://forum.hdfgroup.org/user_avatar/forum.hdfgroup.org/gheber/32/1919_2.png) [@gheber](https://forum.hdfgroup.org/u/gheber)\
**Post date:** [October 19, 2022, 6:58pm UTC](https://forum.hdfgroup.org/t/read-only-part-of-large-compound-dataset-member/10325/2 "2022-10-19T18:58:44Z")

</div>

> [@marius.graefe](#):
>
> Here’s the problem: For each row, I only need to read the first ~100 bytes of the array.

If by ‘the array’ you mean the “Array [102400] of 8-bit unsigned integer”-field of the compound, that’s currently not supported. What’s in those magic “first ~100 bytes”? Can you define another adjacent field with just that signature content?

G.

---

<div class="post-metadata">

**Author:** ![marius.graefe](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/m/5f9b8f/32.png) [@marius.graefe](https://forum.hdfgroup.org/u/marius.graefe)\
**Post date:** [October 20, 2022, 12:31pm UTC](https://forum.hdfgroup.org/t/read-only-part-of-large-compound-dataset-member/10325/3 "2022-10-20T12:31:29Z")

</div>

Thanks for the quick support. I was fearing that reading a field only partially isn’t supported.

The first ~100 bytes are a header for the payload data that follows. I need to look at all the headers in a file to know what’s in it (basically index the file), so I can do “random” access to the rows later on.

I know that this would be much easier if the file structure would be designed better, e.g. by putting all the headers in their own column. But I wasn’t responsible for that part and now I have to work with what already exists.

---

<div class="post-metadata">

**Author:** ![gheber](https://forum.hdfgroup.org/user_avatar/forum.hdfgroup.org/gheber/32/1919_2.png) [@gheber](https://forum.hdfgroup.org/u/gheber)\
**Post date:** [October 20, 2022, 12:41pm UTC](https://forum.hdfgroup.org/t/read-only-part-of-large-compound-dataset-member/10325/4 "2022-10-20T12:41:53Z")

</div>

It’s a little fiddly, but you can certainly ready those bytes directly from the file (e.g., using `pread` or `readv`).  
Depending on the layout (contiguous, chunked), you can obtain the data offsets in the file and read what you need. Not pretty, but effective. If you did this repeatedly, you could keep that map on the side for reuse.

G.

---

<div class="post-metadata">

**Author:** ![marius.graefe](https://forum.hdfgroup.org/letter_avatar_proxy/v4/letter/m/5f9b8f/32.png) [@marius.graefe](https://forum.hdfgroup.org/u/marius.graefe)\
**Post date:** [October 20, 2022, 1:56pm UTC](https://forum.hdfgroup.org/t/read-only-part-of-large-compound-dataset-member/10325/5 "2022-10-20T13:56:42Z")

</div>

Hi, thanks for the suggestion. Is there a way to get the offset-into-the-file for data inside dataset fields? In my example the offset in bytes of the start of my array?

---

<div class="post-metadata">

**Author:** ![gheber](https://forum.hdfgroup.org/user_avatar/forum.hdfgroup.org/gheber/32/1919_2.png) [@gheber](https://forum.hdfgroup.org/u/gheber)\
**Post date:** [October 20, 2022, 2:05pm UTC](https://forum.hdfgroup.org/t/read-only-part-of-large-compound-dataset-member/10325/6 "2022-10-20T14:05:59Z")

</div>

- Contiguous layout: [`H5Dget_offset`](https://docs.hdfgroup.org/hdf5/develop/group___h5_d.html#title21) returns the offset of the contiguous region in the file
- Chunked layout [`H5Dget_chunk_info_by_coord`](https://docs.hdfgroup.org/hdf5/develop/group___h5_d.html#title17) returns the address of a chunk in the file. (See also [`H5Dchunk_iter`](https://docs.hdfgroup.org/hdf5/develop/group___h5_d.html#title6))

G.
