C++ 读取单值HDF5 C++;

C++ 读取单值HDF5 C++;,c++,hdf5,C++,Hdf5,情况: //File Path hid_t H5_hid_RESULTS = H5Fcreate (V_FIn_HDF5_Path.absoluteFilePath().toUtf8().constData(), H5F_ACC_RDONLY, H5P_DEFAULT, H5P_DEFAULT); //Status (Error Output?) herr_t status; //read dataset "heigth" int32_t heigth[1]; hid_t

情况:

//File Path
hid_t H5_hid_RESULTS = H5Fcreate (V_FIn_HDF5_Path.absoluteFilePath().toUtf8().constData(), H5F_ACC_RDONLY, H5P_DEFAULT, H5P_DEFAULT);

//Status (Error Output?)
herr_t status;

//read dataset "heigth"
int32_t     heigth[1];
hid_t       H5_hid_heigth = H5Dopen1(H5_hid_RESULTS, "heigth");
status = H5Dread(H5_hid_heigth, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, heigth);
qDebug() << "heigth" << heigth[0];
status = H5Dclose(H5_hid_heigth);

//Close: file
status = H5Fclose (H5_hid_RESULTS);
我试图从
.hdf5
文件中读取一个值

系统:

  • Windows 7(64位)
  • c++(MSVC17 64位)
  • Qt创建者(5.10.1)
  • HDF5(1.8.15)
我的代码:

//File Path
hid_t H5_hid_RESULTS = H5Fcreate (V_FIn_HDF5_Path.absoluteFilePath().toUtf8().constData(), H5F_ACC_RDONLY, H5P_DEFAULT, H5P_DEFAULT);

//Status (Error Output?)
herr_t status;

//read dataset "heigth"
int32_t     heigth[1];
hid_t       H5_hid_heigth = H5Dopen1(H5_hid_RESULTS, "heigth");
status = H5Dread(H5_hid_heigth, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, heigth);
qDebug() << "heigth" << heigth[0];
status = H5Dclose(H5_hid_heigth);

//Close: file
status = H5Fclose (H5_hid_RESULTS);
//文件路径
hid_t H5_hid_RESULTS=H5Fcreate(V_FIn_HDF5_Path.absoluteFilePath().toUtf8().constData(),H5F_ACC_RDONLY,H5P_默认值,H5P_默认值);
//状态(错误输出?)
她的地位;
//读取数据集“高度”
内部高度[1];
hid_t H5_hid_高度=H5Dopen1(H5_hid_结果,“高度”);
状态=H5恐惧(H5_隐藏高度、H5T_本地高度、H5S_所有、H5S_所有、H5P_默认高度、高度);

qDebug()如文件查看器所示,512的数据类型是
H5T\u NATIVE\u INT32
,而不是
H5T\u NATIVE\u INT
。换句话说,您正在尝试读取64位整数,其中只有32位整数。这应该适合您:

status = H5Dread(H5_hid_heigth, H5T_NATIVE_INT32, 
                 H5S_ALL, H5S_ALL, H5P_DEFAULT, heigth);

受此启发,我用一种完全不同但非常简单的方法解决了这个问题。基本上与链接中的代码相同,但是非常简化,所以新手对C++和HDF5可以理解:

//open file (My path is zensored, project from work)
const H5std_string  H5_Path_Results("C:/.../results.hdf5");
H5File              H5_File_Results(H5_Path_Results, H5F_ACC_RDONLY);

//open set
const H5std_string  H5_Nam_Height("height");
DataSet             H5_Set_Height = H5_File_Results.openDataSet(H5_Nam_Height);

//read set
int                 height[1];
H5_Set_Height.read(height, PredType::NATIVE_INT, H5S_ALL, H5S_ALL);
qDebug() << height[0];

//close set
H5_Set_Height.close();

//close file
H5_File_Results.close();
//打开文件(我的路径是zensored,project from work)
常量H5std_字符串H5_路径_结果(“C:/…/Results.hdf5”);
H5文件H5文件结果(H5路径结果,仅H5F附件);
//开放集
常数H5std_串H5_Nam_高度(“高度”);
数据集H5_Set_Height=H5_File_Results.openDataSet(H5_Nam_Height);
//读集
整数高度[1];
H5_Set_Height.read(高度,PredType::NATIVE_INT,H5S_ALL,H5S_ALL);
qDebug()