2014-02-11 1 views
1

C++에서 기본적인 hdf5 데이터 세트 읽기/쓰기 작업을 시도했습니다.HDF5의 이상한 예외

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"와 "DSET"와 같은 파일 이름과 데이터 세트 이름을 하드 코딩하는 경우, 다음, 나는 수 있어요 : 모든 데이터를 입력하면

#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\H5T.c line 1765 in H5Tclose(): immutable datatype 
major: Invalid arguments to routine 
minor: Bad value 
DataType::~DataType - H5Tclose failed 

이 문제를 파악에서 저를 도와주세요.

+0

그냥 스타일 주석 : 왜 'myGroup'에 대한 포인터를 사용합니까? 이것은 불필요합니다. – Simon

답변

0

두 가지 명백한 문제가 있습니다. 첫 번째 것은 다소 어쨌든 H5std_string이며 실제로는 std::string이 시스템에서 엉망이됩니다. dset.h5@╦>ÿK으로 변환 된 것으로 보입니다. 나는 틀릴 수도 있지만 그것이 그 모습입니다. 이를 위해 나는 단서가 없다. Windows 문제이고 솔직히 말해서, 약간 무서운 것이다.

두 번째 문제는 type에서 발생합니다. 소멸자는 변경할 수 없기 때문에이 개체를 파괴 할 수 없다는 불만을 제기합니다. 왜 불변입니까? 당신이 this constructor을 사용하고 있기 때문에 :

H5::IntType::IntType(const hid_t existing_id) 
단지 불변 H5T_NATIVE_INT 형식을 래핑

, 대신 this one :

H5::IntType::IntType(const PredType& pred_type) 

하는 클론H5T_NATIVE_INT 및 복제가 가변이고, 더 중요한 것은, 파괴되다. 그래서 당신은 대체해야합니다

IntType type(H5T_NATIVE_INT); 

IntType type(PredType::NATIVE_INT); 

에 의해 당신은 좋은 것입니다.

+0

'type'을 완전히 없애고'dSet.read'와'dSet.write'에서'PredType :: NATIVE_INT'를 직접 사용할 수 있습니다. – Simon