讀取從HDF5 H5T_STRING所以我有一個包含一個數據集HDF5文件:如何用C
DATASET "updateDateTime" {DATATYPE H5T_STRING{
STRSIZE 24;
STRPAD H5T_STR_NULLPAD;
CSET H5T_CSET_ASCII;
CTYPE H5T_C_S1;
}
DATASPACE SIMPLE{ (5)/(5) }
DATA{
(0) : "2015-05-12\000\000\000\000\000\000\000\000\000\000\000\000\000\000",
(1) : "2015-05-13\000\000\000\000\000\000\000\000\000\000\000\000\000\000",
(2) : "2015-05-14\000\000\000\000\000\000\000\000\000\000\000\000\000\000",
(3) : "2015-05-15\000\000\000\000\000\000\000\000\000\000\000\000\000\000",
(4) : "2015-05-16\000\000\000\000\000\000\000\000\000\000\000\000\000\000"
}
我想讀用C此數據集,但我不能找到一個妥善的例子(我HDF5新手)。具體來說,我無法確定在閱讀時使用哪個H5T_NATIVE_ *。下面是代碼,我現在:
hid_t time_ds = H5Dopen(grp, "updateDateTime", H5P_DEFAULT);
auto time_shape = get_dataset_shape(time_ds);
char** time_str = (char **)malloc(time_shape[0] * sizeof(char *)); // TODO: memeory allocation correct??
status = H5Dread(time_ds, H5T_NATIVE_CHAR, H5S_ALL, H5S_ALL, H5P_DEFAULT,
time_str);
/*do my stuff*/
free(time_str);
status = H5Dclose(time_ds);
當你執行這段代碼,會發生什麼? – arboreal84
那麼,time_str沒有填充數據後H5Dread()@ arboreal84 –