Searching a HDF5 dataset

前端 未结 4 2150
情歌与酒
情歌与酒 2020-12-09 10:34

I\'m currently exploring HDF5. I\'ve read the interesting comments from the thread \"Evaluating HDF5\" and I understand that HDF5 is a solution of choice for storing the dat

4条回答
  •  无人及你
    2020-12-09 11:36

    H5Lexists was introduced for this in HDF5 1.8.0:

    http://www.hdfgroup.org/HDF5/doc/RM/RM_H5L.html#Link-Exists

    You can also iterate over the things that are in an HDF5 file with H5Literate:

    http://www.hdfgroup.org/HDF5/doc/RM/RM_H5L.html#Link-Iterate

    But you can also manually check for previous versions by trying to open a dataset. We use code like this to deal with any version of HDF5:

    bool DoesDatasetExist(const std::string& rDatasetName)
    {
    #if H5_VERS_MAJOR>=1 && H5_VERS_MINOR>=8
        // This is a nice method for testing existence, introduced in HDF5 1.8.0
        htri_t dataset_status = H5Lexists(mFileId, rDatasetName.c_str(), H5P_DEFAULT);
        return (dataset_status>0);
    #else
        bool result=false;
        // This is not a nice way of doing it because the error stack produces a load of 'HDF failed' output.
        // The "TRY" macros are a convenient way to temporarily turn the error stack off.
        H5E_BEGIN_TRY
        {
            hid_t dataset_id = H5Dopen(mFileId, rDatasetName.c_str());
            if (dataset_id>0)
            {
                H5Dclose(dataset_id);
                result = true;
            }
        }
        H5E_END_TRY;
        return result;
    #endif
    }
    

提交回复
热议问题