HDF: HDF Fundamentals

Please, help us to better serve our user community by answering the following short survey: https://www.hdfgroup.org/website-survey/

| HDF 4.4.0 API Reference |

Loading...
Searching...
No Matches
HDF Fundamentals

Navigate back: Contents / HDF User Guide

# HDF Fundamentals

## Chapter Overview

This chapter provides necessary information for the creation and manipulation of HDF files. It includes an overview of the HDF file format, basic operations on HDF files, and programming language issues pertaining to the use of Fortran and ANSI C in HDF programming.

## HDF File Format

An HDF file contains a file header, at least one data descriptor block, and zero or more data elements as depicted in Figure 2a.

The Physical Layout of an HDF File Containing One Data Object

The file header identifies the file as an HDF file. A data descriptor block contains a number of data descriptors. A data descriptor and a data element together form a data object, which is the basic conglomerate structure for encapsulating data in the HDF file. Each of these terms is described in the following sections.

### File Header

The first component of an HDF file is the file header, which takes up the first four bytes of the HDF file. Specifically, it consists of four one-byte values that are ASCII representations of control characters: the first is a control-N, the second is a control-C , the third is a control-S and the fourth is a control-A (^N^C^S^A).

Note that, on some machines, the order of bytes in the file header might be swapped when the header is written to an HDF file, causing these characters to be written in little-endian order. To maintain the portability of HDF file header data when developing software for such machines, this byte swapping must be counteracted by ensuring the characters are read and written in the desired order.

### Data Object

A data object is comprised of a data descriptor and a data element. The data descriptor consists of information about the type, location, and size of the data element. The data element contains the actual data. This organization of HDF data makes HDF files self-describing. Figure 2b shows two examples of data objects.

Two Data Objects

#### Data Descriptor

All data descriptors are twelve bytes long and contain four fields, as depicted in Figure 2c. These fields are: a 16-bit tag, a 16-bit reference number, a 32-bit data offset and a 32-bit data length.

The Contents of a Data Descriptor

#### Tag

A tag is the data descriptor field that identifies the type of data stored in the corresponding data element. A tag is a 16-bit unsigned integer between 1 and 65,535, and is associated with a mnemonic name to promote ease to use and the readability of user programs.

If a data descriptor has no corresponding data element, the value of its tag is DFTAG_NULL (or 0).

Tags are assigned by The HDF Group as part of the HDF specification. The following are the ranges of tag values and their descriptions:

- 1 to 32,767 - Tags reserved for HDF Group use
- 32,768 to 64,999 - User-definable tags
- 65,000 to 65,535 - Tags reserved for expansion of the HDF specification

A list of commonly-used tags and their descriptions is included in Reserved HDF Tags of this document.

#### Reference Number

For each occurrence of a tag in an HDF file, a unique reference number is assigned by the library with the tag in the data descriptor. A reference number is a 16-bit unsigned integer and can not be changed during the life of the data object that the reference number specifies.

The combination of a tag and a reference number uniquely identifies the corresponding data object in the file.

Reference numbers are not necessarily assigned consecutively, so it cannot be assumed that the value of a reference number has any meaning beyond providing a way of distinguishing among objects with the same tag. While application programmers may find it convenient to impart some additional meaning to reference numbers in their code, it is emphasized that the HDF library will not internally recognize any such meaning.

#### Data Offset and Length

The data offset field points to the location of the data element in the file by storing the number of bytes from the beginning of the file to the beginning of the data element. The length field contains the size of the data element in bytes. The data offset and the length are both 32-bit signed integers. This results in a file-size limit of 2 gigabytes.

#### Data Elements

The data element is the raw data portion of a data object.

### Data Descriptor Block

Data descriptors are physically stored in a linked list of blocks called data descriptor blocks. The relationship between the data descriptor block to the other components of an HDF file is illustrated in Figure 2a on page 7. The individual components of a data descriptor block are depicted in Figure 2d on page 10. Each data descriptor in a data descriptor block is assumed to be associated with a data element unless it contains the tag DFTAG_NULL (or 0),which indicates that there is no associated data element. By default, a data descriptor block contains 16 (defined as DEF_NDDS) data descriptors. The user may reset this limit when creating the HDF file. Refer to Section 2.3.2 on page 11 for more details.

In addition to data descriptors, each data descriptor block contains a data descriptor header. The data descriptor header contains two fields: block size and next block. The block size field is a 16- bit unsigned integer indicating the number of data descriptors in the data descriptor block. The next block field is a 32-bit unsigned integer indicating the offset of the next data descriptor block, if one exists. The last data descriptor header in the list contains a value of 0 in its next block field.

Figure 2d illustrates the layout of a data descriptor block.

Data Descriptor Block

### Grouping Data Objects in an HDF File

Data objects containing related data in HDF files are usually grouped together by the library. These groups of data objects are called data sets. The HDF user uses the application interface to manipulate data sets in a file. As an example, an 8-bit raster image data set requires three objects: a group object identifying the members of the set, an image object containing the image data, and a dimension object indicating the size of the image.

Data objects are individually accessible even if they are included in a set, therefore data objects can belong to more than one set and sets can be included in larger groups. For example, a palette object included in one raster image set may also be a part of another raster image set if its tag and reference number are included in a data descriptor within that second set.

Additional information about data objects, including the options available for storing them, can be found in the HDF Specifications and Developer’s Guide from the HDF web site.

## Basic Operations on HDF Files Using the Multifile Interfaces

This section describes the basic file operations, some of which are required in working with HDF files using the multifile interfaces. Except for the SD interface, all applications using other multifile interfaces must explicitly use the routines Hopen and Hclose to control accesses to the HDF files. In an application using the HDF file format, the file is accessed via its identifier, referred to as file identifier. The following subsections describe the file identifier and the basic file operations common to most multifile interfaces.

### File Identifiers

The HDF programming model specifies that a data file is first explicitly created or opened by an application, manipulated, then explicitly closed by the application. A file identifier is a unique number that the HDF library assigns to an HDF file when creating or opening the file. The HDF library creates the file identifier for an HDF file when given its file name, as represented in the native file system. Interface routines use only the file identifier to access and manipulate the file. When all operations on the file are complete, the file identifier must be discarded by explicitly closing the file before terminating the application.

As every file is assigned its own identifier, the order in which files are accessed is very flexible. For example, it is valid to open a file and obtain an identifier for it, then open a second file without closing the first file or disposing of the first file identifier. The only requirement made by HDF is that all file identifiers be individually discarded before the termination of the calling program.

File identifiers created by the routine of one HDF interface can be used by the routines of any other interfaces, except SD’s.

### Opening HDF Files: Hopen

C | file_id = Hopen(filename, access_mode, num_dds_block);
FORTRAN | file_id = hopen(filename, access_mode, num_dds_block)

Hopen Parameter List

File Access Code Flags

### Closing HDF Files: Hclose

Hclose Parameter List

### Getting the HDF Library and File Versions: Hgetlibversion and Hgetfileversion

Hgetlibversion and Hgetfileversion Parameter Lists

## Determining whether a File Is an HDF File: Hishdf/hishdff

Hishdf/hishdff Parameter List

## Programming Issues

### Header File Information

### HDF Definitions

The HDF library provides several sets of definitions which can be used easily in the user applications. These sets include the definitions of the data types, the data type flags, and the limits that set various maximum values. The definitions of the data types supported by HDF are located in the hdf.h header file, and the data type flags are located in the hntdefs.h header file. Both are also included in (See Table 2F on page 14), (See Table 2G on page 15), and (See Table 2H on page 15). HDF data types are used for portability in the declaration of variables, and data type flags are used as parameters in various HDF interface routines.

#### Standard HDF Data Types

Standard HDF Data Types and Flags

#### Native Format Data Types

Native Format Data Type Definitions

#### Little-Endian Data Types

Little-Endian Format Data Type Definitions

#### Tag Definitions

#### Limit Definitions

Limit Definitions

### FORTRAN-77 and C Language Issues

HDF provides both FORTRAN-77 and C versions of most of its interface routines. In order to make the FORTRAN-77 and C versions of each routine as similar as possible, some compromises have been made in the process of simplifying the interface for both programming languages.

#### FORTRAN-77-to-C Translation

Use of a Function Call Converter to Route FORTRAN-77 HDF Calls to the C Library

#### Case Sensitivity

#### Name Length

#### Header Files

#### Data Type Specifications

Correspondence Between Fortran and HDF C Data Types

#### String and Array Specifications

#### FORTRAN-77 and ANSI C

Navigate back: Contents / HDF User Guide