I am attempting to read a data set with the following data type:
String,
Length=variable
padding= H5T_STR_NULLTERM
cset = H5T_CSET_UTF8
… according to HDFView version 3
The actual data as displayed by HDFView is “Aluminum” but when I attempt to read it I get 5 bytes worth of junk.
Here is the code that I used to read the data:
inline herr_t readStringDataset(hid_t locationID, const std::string& datasetName, char* data)
{
H5SUPPORT_MUTEX_LOCK()
hid_t datasetID; // dataset id
hid_t typeID; // type id
herr_t error = 0;
herr_t returnError = 0;
datasetID = H5Dopen(locationID, datasetName.c_str(), H5P_DEFAULT);
if(datasetID < 0)
{
std::cout << "H5Lite.cpp::readStringDataset(" << __LINE__ << ") Error opening Dataset at locationID (" << locationID << ") with object name (" << datasetName << ")" << std::endl;
return -1;
}
typeID = H5Dget_type(datasetID);
if(typeID >= 0)
{
error = H5Dread(datasetID, typeID, H5S_ALL, H5S_ALL, H5P_DEFAULT, data);
if(error < 0)
{
std::cout << "Error Reading string dataset." << std::endl;
returnError = error;
}
CloseH5T(typeID, error, returnError);
}
CloseH5D(datasetID, error, returnError, datasetName);
return returnError;
}
Any help would be appreciated.
–
Mike Jackson