Check if HDF5 files are correct

As per the example given here, I have a file loaded into memory as a string with a valid handler. This was done with H5LTopen_file_image()

.

Now my question is, how can I check that this is a valid HDF5 file? I only found a program called H5check, which has complex source code. So I'm wondering if there is a simple function with a simple return value to make sure everything in the handler hid_t

is a valid HDF5 file?

+3


source to share


1 answer


In C ++:

    std::string filename = "foo.h5";
    if(!H5::H5File::isHdf5(filename.c_str()))
    {
        std::string err_msg = filename + " is not an HDF5 file.\n";
        throw std::logic_error(err_msg);
    }

      



In Python use

import h5py
if not h5py.is_hdf5('foo.h5'):
    raise ValueError('Not an hdf5 file')

      

0


source







All Articles