This page follows the HDF4 library’s own headers in
hdf/src:
the file layout described in hfile_priv.h, the tags in
htags.h, the number types in hntdefs.h and the encoding
macros in hdf_priv.h, all read 2026-11-12. Numbers are big-endian (the
library’s encode macros write the high byte first).
Layout
| Item | Size | Fields |
|---|---|---|
| Magic | 4 | 0E 03 13 01 (^N^C^S^A). |
| DD block header | 6 | Number of descriptors in the block (2), offset of the next DD block (4, 0 for the last). |
| Data descriptor | 12 | Tag (2), reference number (2), offset of the data (4), length (4). |
The first DD block follows the magic; the library’s default is 16 descriptors per
block. A tag and reference number together name one object; tag 1
(DFTAG_NULL) marks an unused descriptor. Offsets and lengths are
unsigned 32-bit numbers. Tags 1 to 16,383 are the library’s ordinary tags, 16,384 to
32,767 its special tags, 32,768 to 64,999 user tags, and 65,000 and up reserved.
Number types
| Code | Type | Code | Type |
|---|---|---|---|
| 3 | DFNT_UCHAR8 | 22 | DFNT_INT16 |
| 4 | DFNT_CHAR8 | 23 | DFNT_UINT16 |
| 5 | DFNT_FLOAT32 | 24 | DFNT_INT32 |
| 6 | DFNT_FLOAT64 | 25 | DFNT_UINT32 |
| 20 | DFNT_INT8 | 26 | DFNT_INT64 |
| 21 | DFNT_UINT8 | 27 | DFNT_UINT64 |
The base values are the standard HDF format (DFNT_HDF, 0). Adding
0x1000 means the machine’s native format, 0x2000 a custom
format and 0x4000 little-endian.
Special elements
When a data element is stored in an unusual way (linked blocks, an external file,
compression, chunking), its descriptor’s tag has 0x4000 added and its
data starts with a 2-byte special type: 1 linked blocks, 2 external file, 3
compressed, 4 variable-length linked blocks, 5 chunked (and, inside the library,
6 buffered and 7 compressed raster). The rest describes where and how the real
data is stored.