Fanning Software Consulting

Open HDF File Failure

QUESTION: If an HDF file is corrupted, or perhaps the file is just not an HDF file, the HDF_SD_START function fails with the message Unable to start the HDF-SD Interface. Moreover, it throws an error, which is dumping me out of my program. Is there a way to get a more helpful diagnostic message, or--failing that--at least behavior that I can handle more appropriately in my program?

ANSWER: Apparently we hope in vain for a more enlightened diagnostic message. The same problem exists, as I understand it, with the underlying C routine SDstart().

As for responding more appropriately, Liam Gumley offers us a FileInfo function that can be used to check if a given filename exists, has read or write permissions, and whether it is in HDF or netCDF format. It also returns the file size, in bytes. Here is an example of how the function can be used with a file that is not an HDF file:

   $ echo "Hello world" > test.hdf
   $ idl
   IDL Version 6.2 (linux x86_64 m64). (c) 2005, Research Systems, Inc.
   IDL> result = fileinfo('test.hdf')
   IDL> help, result, /structure
   ** Structure <762498>, 7 tags, length=40, data length=40, refs=1:
      NAME            STRING    'test.hdf'
      EXIST           LONG                 1
      READ            LONG                 1
      WRITE           LONG                 1
      HDF             LONG                 0
      NETCDF          LONG                 0
      SIZE            LONG                12 

Web Coyote's Guide to IDL Programming