I need to read a HDF5 dataset that contains a 3 x 3 array, datatype is double.
My Visual Studio 2017 Pro crashes when returning from my code below.
Stepping with debugger, this code reads the 2-dim array from the HDF5; I can read it in the debugger; but function read_double_array crashes when it returns to caller.
2ND CODE ATTEMPT FROM EXAMPLE AT STACKO ….
public static double[,] read_double_array( H5FileId fileId, string dataset_name, int dim1, int dim2 )
{
double [,] return_data = new double[ dim1, dim2 ];
try
{
H5Array<double> h5_array = new H5Array<double>( return_data );
H5DataSetId double_array_dataset = H5D.open( fileId, dataset_name );
H5D.read<double>( double_array_dataset,
new H5DataTypeId(H5T.H5Type.NATIVE_DOUBLE),
h5_array );
H5D.close(double_array_dataset);
}
catch( HDFException e )
{
Console.WriteLine( e.Message );
int aa=0;
}
return return_data;
}
MY CODE 1ST ATTEMPT, WHICH CRASHED ……………………
public static double[,] read_double_array( H5FileId fileId, string dataset_name, int dim1, int dim2 )
{
double [,] return_data = new double[ dim1, dim2 ];
try
{
H5DataSetId dataSetId = H5D.open( fileId, dataset_name );
H5D.read( dataSetId,
new H5DataTypeId( H5T.H5Type.NATIVE_DOUBLE ),
new H5Array<double>( return_data ) );
}
catch( HDFException e )
{
Console.WriteLine( e.Message );
int aa=0;
}
return return_data; <<<<<<<<<<<<<<<<<< H A N G S H E R E
}
答案 0 :(得分:0)
使自己免于严重的痛苦(由于HDF5低级实施细节),并查看HDFql。
这里提供了一种在C#中使用HDFql的解决方案,以读取名为var response = client.PostAsync(_baseEnkiWeb.ToString(), content).Result;
var soapResponse = await response.Content.ReadAsStringAsync();
的多维(大小为3x3)多维数据集,其数据类型是存储在名为dset
的HDF5文件中的两倍(假设文件和数据集已经存在):
test.h5
答案 1 :(得分:0)
我知道了。这是我的代码...
// Reads a 2-dim array of double.
// INPUT: fileId of open HDF5 file
public static bool read_double_array( H5FileId fileId, string dataset_name, int dim1, int dim2, ref double [,] output_double_array )
{
try
{
output_double_array = new double[ dim1, dim2 ];
H5Array<double> h5_array = new H5Array<double>( output_double_array );
H5DataSetId dataset = H5D.open( fileId, dataset_name);
H5D.read<double>( dataset,
new H5DataTypeId(H5T.H5Type.NATIVE_DOUBLE),
h5_array);
}
catch( HDFException e )
{
Console.WriteLine( e.Message );
return false;
}
return true;
}