netCDF Import to Mathematica, perhaps via HDF or HDF5 file
Mark Hadfield
m.hadfield at niwa.co.nz
Wed May 31 16:57:07 MDT 2006
James D. Hanson wrote:
>
> Do anyone know of a netCDF to HDF or HDF5 file converter?
I am dealing with something like this at the moment (but for Tecplot,
not Mathematica) and the best way I have found so far is a combination
of the netCDF ncdump utility and the HDF4 ncgen utility.
To elaborate somewhat, the netCDF library from Unidata contains
utilities ncdump and ncgen to convert between the netCDF binary format
and a text format called CDL. The HDF4 library from NCSA also contains
utilities ncdump and ncgen that do the same thing, but this time the
underlying binary file format is HDF. It is a little tricky to install
both, because by default the HDF commands will overwrite the netCDF
commands or vice versa. On my system I've modified the insttallation
process and called the HDF versions hdf_ncdump and hdf_ncgen.
The procedure is
ncdump -l 80 foo.nc > foo.cdl
# Edit CDL file with a text editor to work around various
# problems encountered by hdf_ncgen
hdf_ncgen -b -o foo.hdf foo.cdl
The need to edit the CDL file arises because hdf_ncgen cannot read
everything that ncdump can write. The "-l 80" option above is intended
to work around one of hdf_ncgen's limitations: a maximum line length of
80 characters. When hdf_ncgen encounters a problem, it halts and prints
out the relevant line number in the CDL file. The error message will not
necessarily make much sense, but when you go to that line you will
usually find that problem is reasonably obvious and easily corrected. In
the past I have had to strip out attributes containing zero-length
strings, remove netCDF fill values (represented in CDL as an underscore)
and replace NaNs with finite floating-point values. (NaNs are illegal in
netCDF anyway, though some platforms allow them.)
This is all rather klunky and I would be keen to know of a better way.
There is a Windows executable called ncdf2hdf from Fortner Software
(RIP) that does the conversion. However the HDF files that it generates
seem to lack some of the structure that is available in the ones
produced by the route above, and this affects the way they look to the
Tecplot import filter.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: m.hadfield.vcf
Type: text/x-vcard
Size: 248 bytes
Desc: not available
Url : http://mailman.unidata.ucar.edu/mailing_lists/archives/netcdfgroup/attachments/20060601/40b70dbf/attachment.vcf
More information about the netcdfgroup
mailing list