[gdal-dev] GDAL with netCDF4 support

Maarten Plieger plieger at knmi.nl
Wed May 14 10:30:41 EDT 2008


Hello,

I have tried to build GDAL with netCDF4 support. I have used the 
hdf5-1.8.0-snap5 and netcdf-4.0-beta2 libraries to do this.
(netCDF4 is actually internally HDF5, which is explained here: 
http://www.unidata.ucar.edu/software/netcdf/netcdf-4/ )
/
/To use the netCDF4 API it needs to be compiled with the latest HDF5 
API, which is 1.8.0/
/HDF 1.8  is a completely new API and some functions have changed, 
causing the HDF5 driver in GDAL to complain.  There are backward 
compatible functions available in this API, therefore I have replaced 
the HDF1.8 functions by adding in hdfdataset.h:
- #define H5Gopen H5Gopen1
- #define H5Dopen H5Dopen1
- #define H5Aiterate H5Aiterate1
This is of course a 'dirty' method but it works for me right now. GDAL 
was build with success.

Now I am able to write netCDF4 files with GDAL.
Now we come to another error: The netCDF4 driver does not recognize its 
own written netCDF files, because they are actually HDF5 files. 
Re-Opening the dataset in the CreateCopy function therefore fails. And 
when doing 'gdalinfo' on these files the HDF5 driver pops up.

I adjusted the netCDF driver to recognize the netCDF4 files.
In 'netCDFdataset.cpp' at line 1308: I added " && 
!((nc_inq_libvers()[0]=='4')&&EQUALN((const char 
*)poOpenInfo->pabyHeader+1,"HDF",3))) ". This line checks for the 
netCDF4 library ('4')  and for a 'HDF' header.
This makes sure that in case of the netCDF4 library, HDF files are also 
picked up by this driver.

Now it is possible to read and write netCDF4 files with GDAL.

The reason I want to use netCDF4 is because I want to write HDF5 files 
supporting CF-conventions with the Web Coverage Service of UMN 
Mapserver. I also would like to add a lot more metadata.
Is something like this done before? What would be the best way to add 
our custom metadata, is it by adjusting the driver?

I thought it would be nice to share this experiment with you...

Cheers,
Maarten Plieger


  


More information about the gdal-dev mailing list