Skip to content
Snippets Groups Projects
Commit a8184ff1 authored by Stéphane Poirier's avatar Stéphane Poirier
Browse files

Fixed: dataset reading failure in case of string type

parent 6e694d43
No related branches found
No related tags found
1 merge request!2HDF5 1.14.3
......@@ -2300,6 +2300,44 @@ public:
}
}
//--------------------------------------------------------------------------
std::size_t get_in_mem_data_size(hid_t dataset_id) const
{
// Get the data type of this attribute
H5Identifier mem_type_id = H5Dget_type(dataset_id);
if( !mem_type_id.is_valid() )
throw ImplException("H5Dget_type failed",
"nxcpp::NexusFileImpl::get_in_mem_data_size");
// Get the data type's size by first getting its native type then getting
// the native type's size.
H5Identifier native_type = H5Tget_native_type(mem_type_id, H5T_DIR_DEFAULT);
if( !native_type.is_valid() )
throw ImplException("H5Tget_native_type failed",
"nxcpp::NexusFileImpl::get_in_mem_data_size");
std::size_t type_size = H5Tget_size(native_type);
if (type_size == 0)
throw ImplException("H5Tget_size failed",
"nxcpp::NexusFileImpl::get_in_mem_data_size");
// Get number of elements of the attribute by first getting its dataspace
// then getting the number of elements in the dataspace
H5Identifier space_id = H5Dget_space(dataset_id);
if( !space_id.is_valid() )
throw ImplException("H5Aget_space failed",
"nxcpp::NexusFileImpl::get_in_mem_data_size");
hssize_t num_elements = H5Sget_simple_extent_npoints(space_id);
if( num_elements < 0 )
throw ImplException("H5Sget_simple_extent_npoints failed",
"nxcpp::NexusFileImpl::get_in_mem_data_size");
// Calculate and return the size of the data
return type_size * static_cast<size_t>(num_elements);
}
//--------------------------------------------------------------------------
void GetDataSetInfo(const std::string& name, NexusDataSetInfo* dataSetInfo)
{
......@@ -2317,22 +2355,15 @@ public:
if( H5Tget_class(type_id) == H5T_STRING )
{
std::string buf;
char *buf_p;
herr_t ret_value = H5Dread(dataset_id, type_id, space_id, H5S_ALL, H5P_DEFAULT, buf_p);
if( ret_value < 0 )
throw ImplException("H5Dread failed", "nxcpp::NexusFileImpl::GetDataSetInfo");
buf = buf_p;
free(buf_p);
std::size_t size = get_in_mem_data_size(dataset_id.get());
if( 0 == rank )
{
dataDims.push_back( (int)buf.size() );
dataDims.push_back((int)size);
rank = 1;
}
else
dataDims.front() = (int)buf.size(); // update true size
dataDims.front() = (int)size; // update true size
}
// update nexus dataset info
dataSetInfo->Clear();
......@@ -2342,7 +2373,8 @@ public:
dataSetInfo->SetInfo(h5Data2nexusData(type_id), rank);
dataSetInfo->SetTotalDim(rank, dataSetInfo->DimArray());
}
NEXUS_CATCH("Unable to get dataset information", "nxcpp::NexusFileImpl::GetDataSetInfo");
NEXUS_CATCH("Unable to get dataset information",
"nxcpp::NexusFileImpl::GetDataSetInfo");
}
/* CPPAPI
void GetDataSetInfo(const std::string& name, NexusDataSetInfo* dataSetInfo)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment