Q: An IDL user asks: How do I use IDL to check the type of an NetCDF file, for example, NetCDF-4 (HDF5) or "classic" (NetCDF-3)? A: As of IDL 8.7.2, IDL doesn't have a simple built-in routine to distinguish between NetCDF-4 and NetCDF -3 files. However, custom IDL code might allow this, for example: ; <...> file = 'mydata.nc' print, '>>> File: '+file ; All NetCDF-4 files are HDF5 (but not always vice versa) if H5F_IS_HDF5(file) then begin print, '>>> HDF5 file!!!' ; Catch error from attempting to parse non-NetCDF-4 compliant HDF5 file catch, errstat if errstat ne 0 then begin print, '>>> File: ' + file help, data data = !null print, '>>> ERROR: Not NetCDF-4 compatible!!!' message, /reset GOTO, DONE endif ; parse HDF5 file to confirm NetCDF compliance data = ncdf_parse(file) help, data data = !null print, '>>> NetCDF-4 compatible.' endif else begin nc3 = NCDF_IS_NCDF(file) ? '' : 'NOT' print, '>>> '+nc3+' NetCDF-3 compatible.' endelse DONE: print, 'done. ; <...> See also the NetCDF provider's library documentation FAQ section for other tips on distinguishing between different types of NetCDF files. Another option might be to spawn the "ncdump" NetCDF-4 command line utility (e.g., "ncdump -k") (NetCDF command line utilities can be obtained from the NetCDF library provider's web site) to query a NetCDF file's type.
|