The HDF_DFR8_LASTREF function returns the reference number of the most recently read or written 8-bit image in a Hierarchical Data Format file.
h = HDF_OPEN('myhdf.hdf') ; Open an hdf file.
PRINT, HDF_DFR8_LASTREF() ; IDL prints "0", meaning that the call was successful, but no reference number was available.
a = BINDGEN(100,100) ; Create a 2D array representing an 8-bit image.
HDF_DFR8_ADDIMAGE, 'myhdf.hdf', a ; Write the image to the file.
PRINT, HDF_DFR8_LASTREF() ; IDL prints the reference number for the last 8-bit image operation (for example, "2"). Note the reference number is not simply a 1-based `image number'--it could easily be "2" or "3" for the first operation on the file.
HDF_DFR8_ADDIMAGE, 'myhdf.hdf', a ; Add another image.
PRINT, HDF_DFR8_NIMAGES('myhdf.hdf') ; IDL prints "2", because we've put two 8-bit images in the file.