The HDF_DF24_LASTREF function returns the reference number of the most recently read or written 24-bit image in an HDF file.
h=HDF_OPEN('myhdf.hdf') ; Open an HDF file.
PRINT, HDF_DF24_LASTREF() ; IDL prints 0, meaning that the call was successful, but no reference number was available.
a = BINDGEN(3,100,100) ; Create a 3D array, representing a 24-bit image.
HDF_DF24_ADDIMAGE, 'myhdf.hdf', a ; Write the 24-bit image to the file.
PRINT, HDF_DF24_LASTREF() ; IDL prints a reference number for the last operation (for example, 2). Note the reference number is not simply a 1-based "image number"--the reference number could easily be "2" or "3", etc.
HDF_DF24_ADDIMAGE, 'myhdf.hdf', a ; Write another image to the file.
PRINT, HDF_DF24_LASTREF() ; Print the last reference number.
PRINT, HDF_DF24_NIMAGES('myhdf.hdf') ; IDL prints "2" because we've written two images to the file.