[gdal-dev] GDAL with netCDF4 support
Frank Warmerdam
warmerdam at pobox.com
Wed May 14 10:45:28 EDT 2008
Maarten Plieger wrote:
> 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.
Maarten,
I would appreciate your filing a ticket on this issue.
> 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.
I would appreciate another ticket on this issue.
It was not actually my original thinking that the netcdf driver would
support netCDF4 files, under the assumption that the HDF5 driver could
be used so I'm not sure I want to include these changes. But it would
be appropriate to have a record of the issue, and a mechanism for those
that wish to do what you are doing.
> 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'm not aware of anyone doing what you are doing, so you are at the
very least stretching the boundaries of current support.
Best regards,
--
---------------------------------------+--------------------------------------
I set the clouds in motion - turn up | Frank Warmerdam, warmerdam at pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush | President OSGeo, http://osgeo.org
More information about the gdal-dev
mailing list