我正在嘗試基本的hdf5數據集讀/寫操作在C++中。HDF5奇怪的例外
#include "stdafx.h"
#include "h5cpp.h"
#include <iostream>
#include <conio.h>
#include <vector>
#include <string>
#ifndef H5_NO_NAMESPACE
using namespace H5;
#endif
const H5std_string fName("dset.h5");
const H5std_string dsName("dset");
int main()
{
try
{
int data[10];
int dataOut[10];
//Exception::dontPrint();
std::cout<<"Enter The Data : ";
for(int i = 0 ; i < 10 ; i++)
std::cin>>data[i];
H5File file(fName, H5F_ACC_TRUNC);
IntType type(H5T_NATIVE_INT);
Group *myGroup = new Group(file.createGroup("\\myGroup"));
hsize_t dim[] = {10};
DataSpace dSpace(1,dim);
DataSet dSet = myGroup->createDataSet(dsName, type, dSpace);
dSet.write(data, type);
std::cout << "Data Written\n";
dSet.read(dataOut, type);
std::cout<<"Data Read\n";
for(int i = 0 ; i < 10 ; i ++)
std::cout<<dataOut[i]<<"\n";
delete myGroup;
}
catch(Exception e)
{
e.printError();
}
_getch();
return 0;
}
輸入所有數據後,我得到異常:
HDF5-DIAG: Error detected in HDF5 (1.8.12) thread 0:
#000: ..\..\src\H5F.c line 1503 in H5Fcreate(): unable to create file
major: File accessibilty
minor: Unable to open file
#001: ..\..\src\H5F.c line 1285 in H5F_open(): unable to open file: time = Wed
Feb 12 00:02:29 2014
, name = '@╦>ÿK', tent_flags = 13
major: File accessibilty
minor: Unable to open file
#002: ..\..\src\H5FD.c line 987 in H5FD_open(): open failed
major: Virtual File Layer
minor: Unable to initialize object
#003: ..\..\src\H5FDsec2.c line 343 in H5FD_sec2_open(): unable to open file:
name = '@╦>ÿK', errno = 22, error message = 'Invalid argument', flags = 13, o_fl
ags = 302
major: File accessibilty
minor: Unable to open file
HDF5-DIAG: Error detected in HDF5 (1.8.12) thread 0:
#000: ..\..\src\H5F.c line 1503 in H5Fcreate(): unable to create file
major: File accessibilty
minor: Unable to open file
#001: ..\..\src\H5F.c line 1285 in H5F_open(): unable to open file: time = Wed
Feb 12 00:02:29 2014
, name = '@╦>ÿK', tent_flags = 13
major: File accessibilty
minor: Unable to open file
#002: ..\..\src\H5FD.c line 987 in H5FD_open(): open failed
major: Virtual File Layer
minor: Unable to initialize object
#003: ..\..\src\H5FDsec2.c line 343 in H5FD_sec2_open(): unable to open file:
name = '@╦>ÿK', errno = 22, error message = 'Invalid argument', flags = 13, o_fl
ags = 302
major: File accessibilty
minor: Unable to open file
但是,如果我硬編碼的文件名和數據集的名稱,如「abcd.h5」和「D設定」,然後,我能夠以獲得所需的輸出,但輸出後,我收到異常:
HDF5-DIAG: Error detected in HDF5 (1.8.12) thread 0:
#000: ..\..\src\H5T.c line 1765 in H5Tclose(): immutable datatype
major: Invalid arguments to routine
minor: Bad value
DataType::~DataType - H5Tclose failed
請幫我弄清楚這個問題。
只是一個樣式註釋:爲什麼你使用'myGroup'的指針?這是不必要的。 – Simon