Language/Format: C
Application type(s): Data Conversion
Related project(s): Megha-Tropiques


This package contains some data format conversion tools for HDF4 files :

  • hdf2raw : write a HDF4 SDS to a binary file
  • raw2hdf : write a 2D binary data to a HDF4 file
  • ncf2hdf : convert a NETCDF file to an HDF one



This tool extracts the data of a SDS in an HDF file, and writes it out to a binary file

hdf2raw  [OPTIONS]  -isds=<SDS-number> -of=<dest-file> <src-filei>
    <src-file>  : the input HDF4 file
    <SDS-number> : the index of the SDS to dump ( starting from 0 )
    <dest-file> : destination file ( directory path included )
      -v     verbose mode
             overwrite the output file if already existent


This tool writes the data of a binary file to a 2D HDF’s SDS

raw2hdf [-v] [-append]  -size=<width>x<heighti> -type=<data_type> -of=<dest-file> <src-file>
    <src-file>   : the input HDF4 file
      -v     verbose mode
             append the data at the end of the HDF file
      -size  size of the binary data array (<width>x<height>)
      -type  type of the read binary data. Allowed types : float64|float32|int32|uint32|int16|uint16|int8|uint8|char8|uchar8
      -isds  Index of the sds to read (starting at 0)
      -of    full output file name (path included)


ncf2hdf transforms NetCDF_file to an HDF file. It is possible to select only some SDS to extract and to deal with “dimensions” SDS either as standard SDS, or as coordinate vectors.

If NetCDF input file name has a known suffix (“nc”, “ncf” ou “netcdf”, any case), HDF output file has the same basename with the “hdf” suffix. Otherwise, HDF output file name is built by adding the “hdf” suffix at the end of NetCDF input file name.

ncf2hdf [-v] [-d] [-s sds1[,sds2,...]] <NetCDF_file>
    <NetCDF-file>   : the input NETCDF file
      -v     Displays some details about conversion on standard output.
      -d     Deals with &quot;dimension&quot; SDS as standard SDS; the default is to deal with &quot;dimension&quot; SDS as coordinate vectors.
      -s     The  HDF  output file will only contain specified SDS. One or more SDS must be specified by name in the comma-delimited list without space following this option.


Sources can be downloaded here :


Package can be browsed here :





First, set the pathes to the HDF4 library by defining the environment variables

  • HDFINC=<HDF4-includes-directory> , where <HDF4-includes-directory> contains the HDF4 includes : hdf.h, mfhdf.h…
  • HDFLIB=<HDF4-libraries-directory>, where <HDF4-libraries-directory> contains the HDF4 libraries : libdf.a ( or ), libmfhdf.a ( or )

If you are using the bash shell, this can be done via the export command :

> export HDFINC=<HDF4-includes-directory>
> export HDFLIB=<HDF4-libraries-directory>

Of course, replace <HDF4-includes-directory> and <HDF4-libraries-directory> by the real paths on your system.


Build the application by running

> ./configure --prefix=<install-root-dir>
> make
> make install

If successfull, the tools will be situed in the <install-root-dir>/bin directory.


Copyright (C) 2010 Icare – Site web ICARE

Bruno SIX,
Nicolas PASCAL,

This program is a free software; you can redistribute it and/or modify it under the terms of the CeCILL Public License as published by (License version 2 or later).

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the CeCILL Public License for more details.

You should have received a copy of the CeCILL Public License along with this program; if not, please contact

For any questions or concerns regarding this program, or general information about the ICARE Project, please email to

Author(s): Bruno Six, Jacques Descloitres, Nicolas Pascal (ICARE)