The HDF4 CF (H4CF) conversion library can be used to access various types
of NASA
HDF4
and
HDF-EOS2
files by following CF conventions. The
CF conventions are defined
here
.
We have incorporated the knowledge and information obtained from the NASA
HDF-EOS2 and HDF4 files and the corresponding documents published by NASA
data centers into this conversion library. We also have implemented an
HDF4 to netCDF-3 conversion tool that follows CF conventions by using this
conversion library. In this web page, we will provide basic usage of the
conversion library and the HDF4 to netCDF-3 conversion tool. A set of
simple conversion library APIs will be introduced and some screenshots of
using netCDF visualization tools to access the converted netCDF files
will also be presented.
Users can download the source code package from
this link. Users should unpack the
gzipped tar archive file to a location where
source packages are usually built locally on your machine.
/usr/local/src, for example.
The H4CF conversion library requires the
HDF4
,
HDF-EOS2
and
NetCDF
external libraries. HDF4 library must be
configured with "--disable-netcdf" option. Otherwise, the
HDF4 to netCDF-CF conversion tool may not be compiled or built.
We provide two methods to build the conversion library and the HDF4
to netCDF-3 conversion tool. The first method is to set up the build
environment using a configure script, which is maintained
by the
Autoconf
system. The user should pass the paths to
the installed location of the prerequisite libraries when running the
configure script. Figure 1 shows example configuration
options. The uses should tailor the values to reflect the actual
locations on the system where the software is being installed.
--with-szlib option should be omitted. For some
systems that have already installed the zlib and the jpeg libraries,
--with-jpeg and --with-zlib can also be omitted.
In this case, one may use the following:
Makefile.
With the Makefile, one can then build the H4CF library,
the CDL Dumper and the HDF4 to NetCDF Converter utility programs
by issuing the make command.
Typing make install installs the H4CF conversion library
and the corresponding tools. BE AWARE: when you build the library,
you must type make CXXFLAGS=-O0 to ensure the correctness
of the library and the tools. Without using CXXFLAGS=-O0
the library and the tools may NOT be usable.
With the default value of the prefix variable in the above
configuration, the make command will
produce the standalone static library files:
h4cf/lib/libh4cf.a and h4cf/lib/libh4cf.la.
The C++ header files to be included by application programs which
use the H4CF library are installed into h4cf/include.
the utility programs cdldumper and h4tonccf are
installed into h4cf/bin.
For the HDF4 to netCDF-CF conversion tool h4tonccf, the
above "configure" and "make" commands will
generate a version of a tool to produce netCDF-3 files from HDF-EOS
input files. To generate netCDF-4 classic files, one should use the
following configuration command:
The second option is to use a manually created Makefile.
We have provided three template Makefiles to help users
to follow. These Makefile templates are:
src/Makefile.template to generate the h4cf conversion
library, utility/Makefile.template to generate the hdf4 to
netcdf conversion tool and internal_test/Makefile.template
to generate the cdldumper debugging tool. The user must edit the
value of the directory path to each required library in each
Makefile to conform to the system where the software is
being installed.
We also provide in the package a directory of examples:
read, read_subset, read_var_attrs
and read_file_attrs. To build these examples, modify the
examples/Makefile.template to conform to the configuration
of your system and compile them as follows:
HDF4 and HDF-EOS2 groups, variables and attributes are presented under a single, unified abstraction. When a file is opened, a pointer to the root group is returned. The user can traverse all the structures from the root group pointer. If user opens the file with CF option, the structure shown to the user is CF-compliant.
iterator
map<string,string>::const_iterator it=file_attrs.begin()
method.
The user can traverse the file variable list using the C++ STL
list
iterator
list<var*>::const_iterator var_iter = pvars.begin()
method.
The example programs employ these API methods to access the groups
of the HDF file. The sample HDF file examples/geo.hdf
used in the following examples is included in the source code
distribution.
The first example, examples/read.cpp prints the value of
each variable named "temp" in the file, where the dimensions of the
data field can be seen to be XDim=36, YDim=18 by using either the
EOS2 Dumper
or
HDFView
.
start = {0,0}, stride = {2,2} and
edge = {4,4} and prints the resulting 4-by-4
subsetted grid, which contains every second value from the
variable.
map object obtained by the
h4cf_get_file_attrs() method.
CDL Dumper usage is as follows:
.
Users can download the HDF file used in this example from
here
.
We invoke the CDL Dumper as follows:
.
NetCDF Converter usage is as follows:
to NetCDF and examine it using Unidata
IDV
. Users can download the HDF file used in
this example from
here
.
Next, we will convert a MODIS-T file from the NASA Goddard Space
Flight Center Ocean Biology Processing Group
(OBPG)
to NetCDF and examine it using
Panoply
. Users can download the HDF file used in
this example from
here
.
Finally, we will convert a file from the NASA Goddard Earth Sciences
Data and Information Center
(GESDISC)
to NetCDF and examine it using IDV. Users
can download the HDF file used in this example from
here
.