Hi,
I have been trying to work on using the C++ API's provided for HDF5. I
have been facing few issues on this. It would be really helpful, in case
if anyone can guide/point me in the right path.
Issues are with reading/writing multi-dimensional dataset of string
datatype.
Reading/Writing a String Dataset (1 dims,1*1, String length:100) Versus
Reading/Writing String Dataset(1 dims, 1*4, String length:Variable)
···
-----------------------------------------------------------------------------------------------
Reading/Writing a String Dataset (1 dims,1*1, String length:100)
const H5std_string FILE_NAME( "string.h5");
const H5std_string DSET_STR_NAME( "string" );
const int SPACE1_DIM1 = 1;
const int SPACE1_RANK = 1;
const int MAX_LEN = 100;
const char *data_out= "test write";
char *data_in;
hsize_t dims1[] = {SPACE1_DIM1};
H5File file( FILE_NAME, H5F_ACC_TRUNC );
DataSpace sid1(SPACE1_RANK, dims1);
StrType tid1(0, MAX_LEN);
DataSet dataset= file.createDataSet(DSET_STR_NAME, tid1,
sid1);
dataset.write((void*)data_out, tid1);
dataset.close();
dataset = file.openDataSet(DSET_STR_NAME);
DataType dtype = dataset.getDataType();
data_in= new char[MAX_LEN];
memset(data_in,'\0',sizeof(data_in));
dataset.read(data_in, tid1);
cout << data_in << endl;
RESULT: Works good, prints the output as "test write" (earlier
written/read value)
-----------------------------------------------------------------------------------------------
Writing String Dataset - Array(2 dims, 1*4, String length:100)
const H5std_string FILE_NAME( "string.h5");
const H5std_string DSET_STR_NAME( "string" );
const int SPACE1_DIM1 = 4;
const int SPACE1_RANK = 1;
char *data_out[4]={"hello1","hello2","hello3","hello4"};
char *data_in[4];
hsize_t dims1[] = {SPACE1_DIM1};
H5File file( FILE_NAME, H5F_ACC_RDWR );
DataSpace sid1(SPACE1_RANK, dims1);
StrType tid1(0, MAX_LEN);
DataSet dataset= file.createDataSet(DSET_STR_NAME, tid1,
sid1);
dataset.write((void*)wdata, tid1);
RESULT: This writes un-initialized data to the file. However, on replacing
the line
"StrType tid1(0, MAX_LEN);" with "StrType tid1(0, H5T_VARIABLE);", the
dataset string array gets stored to the file.
Either ways, am finding it difficult to read back the string dataset
(array data)to a char* array. Can somebody recommend a way to get this
data read back.
Thanks
Anish Anto