[netcdfgroup] Detecting netCDF versus HDF5


Hi Ward

As you know, Data Explorer is going to be a general purpose data reader for many formats, including HDF5 and netCDF.

Here

http://www.space-research.org/


Regarding the handling of both HDF5 and netCDF, it seems there is a potential issue, which is, how to tell if any HDF5 file was saved by the HDF5 API or by the netCDF API?

It seems to me that this is not possible. Is this correct?

netCDF uses an internal function NC_check_file_type to examine the first few bytes of a file, and for example for any HDF5 file the test is

/* Look at the magic number */
   /* Ignore the first byte for HDF */
   if(magic[1] == 'H' && magic[2] == 'D' && magic[3] == 'F') {
     *filetype = FT_HDF;
     *version = 5;

The problem is that this test works for any HDF5 file and for any netCDF file, which makes it impossible to tell which is which.

Which makes it impossible for any general purpose data reader to decide to use the netCDF API or the HDF5 API.

I have a possible solution for this , but before going any further, I would just like to confirm that

1)      Is indeed not possible

2) See if you have a solid workaround for this, excluding the dumb ones, for example deciding on a extension .nc or .h5, or traversing the HDF5 file to see if it's non netCDF conforming one. Yes, to further complicate things, it is possible that the above test says OK for a HDF5 file, but then the read by the netCDF API fails because the file is a HDF5 non netCDF conformant

Thanks

----------------------
Pedro Vicente
pedro.vicente@xxxxxxxxxxxxxxxxxx
http://www.space-research.org/