What is a good way to tell a netCDF4 file from a "regular" HDF5 file? #3085
|
I was originally intending to use Even My next best idea is to check for the presence of Is a I am working with v4.9.2 if it matters. Thanks! |
Replies: 6 comments 7 replies
This mostly a good way to tell the difference. There is a couple of issues, though. |
|
There is one other possibility. There is an attribute called '_IsNetcdf4' that is backed by a program called "NC4_isnetcdf4" in "libhdf5/nc4hdf.c". The program looks for various elements of the netcdf-4/hdf5 file to decide if it was created by libnetcdf. |
|
I could simplify that by having _IsNetcdf4 include a check for _NCProperties attribute along with its current checks. |
|
In recent PR #3125, the check for the _NCProperties attribute was added to _IsNetcdf4. However, as already noted above, all netcdf-4 files created with library versions earlier than 4.4.1 (2016) do not have the _NCProperties attribute. Therefore, if I understand that PR correctly, all of these older netcdf-4 files will now read _IsNetcdf4 = "not netcdf-4". Do you have guidelines for how users should handle this apparent contradiction? Are you sure that adding the _NCProperties check is the right thing to do for the general community? Please excuse my fussing, but I think this could be trouble in some cases. |
|
Did I screw up that PR? I intended that any single test passing in IsNetCDF4 would return true. |
|
I think I came across some false positives (HDF5 files identified as netCDF files) for
The file format of these files is listed as HDF5 in the description and they have .h5 extension. Trying to look through the files' HDF5 structure, I see that they do use The Not 100% sure if it is correct or incorrect to consider these files to be valid netCDF4 files, but wanted to bring them to attention. |
There is one other possibility. There is an attribute called '_IsNetcdf4' that is backed by a program called "NC4_isnetcdf4" in "libhdf5/nc4hdf.c". The program looks for various elements of the netcdf-4/hdf5 file to decide if it was created by libnetcdf.
Currently it tests for existence of a variety of attributes, dimension names,etc in the file. It occurs to me that if the program/attribute returns false, and the file is otherwise readable by libnetcdf, then is should be a pure HDF5 file.