2012-12-04 2 views
4

HDF5 API를 사용하고 있으며 가변 길이 문자열로 데이터 집합을 만들려고합니다. I 정적 하드 코딩 된 크기를 사용 하였다 char[256]HDF5 : 문자열이있는 데이터 집합 만들기

struct dataX 
{ 
    std::string data; 
}; 

구조체이다.
하지만 나는 HDF5 Doc를 읽은 후 동적이기를 바란다. 나는 H5T_VARIABLE을 찾았고 다음과 같이 사용했다. 그러나 여전히 실패한다.

H5Dcreate은 음수 값 (오류)을 반환합니다.

hid_t mem_type; 
mem_type = H5Tcopy(H5T_C_S1); 
H5Tset_size(mem_type,H5T_VARIABLE); 

/* Create the memory data type. */ 
if ((mem_type_id = H5Tcreate (H5T_COMPOUND, mem_type)) < 0) { 
    return -1; 
} 
/* Insert fields. */ 
if (H5Tinsert(mem_type_id, "field", 0, mem_type_id) < 0) { 
    return -1; 
} 

/* Create a simple data space with unlimited size */ 
// hsize_t dims[1]={0}; 
// hsize_t maxdimsk[1]={ H5S_UNLIMITED }; 
if ((sid = H5Screate_simple(1, dims, maxdims)) < 0){ 
    return -1; 
} 

/* Modify dataset creation properties, i.e. enable chunking */ 
plist_id = H5Pcreate (H5P_DATASET_CREATE); 
//chunk==1 
if (H5Pset_chunk (plist_id, 1, chunk) < 0){ 
    return -1; 
} 

H5Pset_alloc_time(plist_id, H5D_ALLOC_TIME_EARLY) 
/* Set the fill value using a struct as the data type. */ 
// fill_data=0 
if (fill_data) 
{ 
    if (H5Pset_fill_value(plist_id, mem_type_id, fill_data) < 0){ 
    LOG_ERROR << "cannot fill value " << LOG_ENDL; 
    return -1; 
    } 
} 
else { 
    if (H5Pset_fill_time(plist_id, H5D_FILL_TIME_NEVER) < 0) { 
    LOG_ERROR << "error" << LOG_ENDL; 
    } 
} 

/* Create the dataset. */ 
did = H5Dcreate(loc_id, dset_name, mem_type_id, sid, plist_id) 

는 어쩌면 경우가 그저 잘되기를 쓰기 전에 메모리를 할당하지만 ... 그것을하지 않았다 생각, H5D_ALLOC_TIME_LATE했습니다.

이제 막혔어. 어떻게해야할지 모르겠다.

내가 뭔가를 놓쳤습니까?

답변

1

귀하의 mem_type_id 이중 무효 : H5Tcreate의 두 번째 인수가 복합 데이터 타입 H5Tinsert에서

  • 의 크기 여야합니다

    • 는, 마지막 인수는 삽입 된 필드의 데이터 유형이어야합니다. 여기 mem_type_id 대신에 mem_type을 의미하는 것 같습니다.

    가변 길이 문자열을 쓰려면 무엇을하고 있는지 알지 못합니다. 복합 유형을 만들거나 특별한 속성 목록을 설정할 필요가 없습니다. 기본적으로 3 번째 줄은 유효한 가변 길이 문자열 데이터 형식 (mem_type)을 생성하기에 충분합니다. 그런 다음 간단한 데이터 공간을 만든 다음 데이터 집합을 만듭니다.

    this example을 보시면 매우 간단합니다.