2017-05-04 181 views
0

我試圖用C++ API將我的化合物數據類型逐個寫入我的文件。我在Win64上使用HDF5-1.8.18。HDF5 - 用Hyperslab逐一寫入/附加HDF5複合數據類型?

我想寫我的複合數據類型對象一個接一個。我有幾種化合物類型,它們不會進入「堆疊式」緩衝區,它們只是一個接一個「到達」。當我嘗試寫入選定的Hyperslab時,我的代碼失敗。

我希望我的Hyperslab從數據集中一次只選擇一個化合物數據類型的元素。在這個測試代碼中,我總是希望寫入索引3.顯然,稍後我將從靜態索引切換到計數器變量。

我的數據空間是一維的:

  • 評級= 1
  • 暗淡=數據對象的次數(例如:213)

我用寫我的數據的代碼:

H5::CompType compType = group->openCompType("tTestData"); 

H5::DataSpace fspace1 = dataset->getSpace(); 
hsize_t start[] = {3}; 
hsize_t stride[] = {1}; 
hsize_t count[] = {1}; 
hsize_t block[] = {1}; 

fspace1.selectHyperslab(H5S_SELECT_SET, count, start, stride, block); 
dataset->write(&myTestData, compType, fspace1); 

拋出的異常是:

HDF5-DIAG: Error detected in HDF5 (1.8.18) thread 0: 
    #000: ..\..\hdf5-1.8.18\src\H5Dio.c line 271 in H5Dwrite(): can't prepare for 
writing data 
    major: Dataset 
    minor: Write failed 
    #001: ..\..\hdf5-1.8.18\src\H5Dio.c line 352 in H5D__pre_write(): can't write 
data 
    major: Dataset 
    minor: Write failed 
    #002: ..\..\hdf5-1.8.18\src\H5Dio.c line 697 in H5D__write(): src and dest dat 
a spaces have different sizes 
    major: Invalid arguments to routine 
    minor: Bad value 

如何調整我的Hyperslab以便能夠一次寫入一個複合數據類型對象?似乎我需要調整我傳遞給selectHyperslab的變量,但我不確定要傳遞哪些參數?

回答

0

我發現在此期間解決這一:

//h5 is a custom Adapter class, which allows me to reuse groups, datasets etc. 
//h5 also keeps track of the count of written data objects in a dataset (used below) 
//These functions are not included in HDF5. Just encapsulate the complexity of the HDF5 lib 
H5::Group* group = h5->GetGroupPtr(); 
H5::CompType compType = group->openCompType("someCompType");  
H5::DataSet* dataset = h5->GetDataSet("someDataSet"); 


//get dataspace of our dataset 
H5::DataSpace fspace1 = dataset->getSpace(); 

//define a 1x1 (one data row) dataspace 
hsize_t dim[] = {1}; 
H5::DataSpace space(1, dim); 

//get current data offset (index) and set stride, count, block to 1 
tInt64 currentCounter = h5->GetDataSetCounter("someDataSet"); 
hsize_t start[] = {currentCounter}; 
hsize_t stride[] = {1}; 
hsize_t count[] = {1}; 
hsize_t block[] = {1}; 

//select the 1x1 hyperslab 
fspace1.selectHyperslab(H5S_SELECT_SET, count, start, stride, block); 
dataset->write(&data, compType, space, fspace1); 

//clean up used resources 
fspace1.close(); 
space.close(); 

更多信息,請參見Hyperslab documentation