简体   繁体   中英

How can I check that a file is a valid HDF5 file?

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

How can I check that a file is a valid HDF5 file?

I found only a program called H5check , which has a complicated source code. So, I'm wondering, is there a simple function with a simple return value to verify that whatever in the hid_t handler is a valid HDF5 file?

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')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM