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?
hdf5 file on your computer. Open this file in HDFView. If you click on the name of the HDF5 file in the left hand window of HDFView, you can view metadata for the file. This will be located in the bottom window of the application.
The Hierarchical Data Format version 5 (HDF5), is an open source file format that supports large, complex, heterogeneous data. HDF5 uses a "file directory" like structure that allows you to organize data within the file in many different structured ways, as you might do with files on your computer.
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With