Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 461
The Quantum Physicist Avatar asked Jul 11 '15 09:07

The Quantum Physicist


People also ask

How do I check my 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.

What is an HDF5 file?

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.


1 Answers

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')
like image 198
user14717 Avatar answered Oct 17 '22 22:10

user14717