如何从HDF5文件读取属性?
问题描述:
我正在使用由ch.systemsx.cisd.hdf5.HDF5Factory(JHDF5)
提供的库来读取HDF5文件。他们的文档链接不能很好地工作,我不知道该如何解决这个问题。如何从HDF5文件读取属性?
有没有人在这里知道如何使用上面的java库从HDF5文件读取属性值?
答
经过大量的试验和错误发现了一个解决方案。请在下面找到代码以从HDF5文件中读取属性值。
nwbFile - HDF5文件的名称(应该打开)。 attributeName:属性的名称。 路径 - 需要读取属性的文件中的节点路径。
DataFormat dataset = (Dataset) FileFormat.findObject(nwbFile, path);
List<Attribute> attributes = dataset.getMetadata();
for(Attribute a : attributes)
{
if(a.getName().equals(attributeName))
{
Object obj = a.getValue();
if (obj instanceof double[])
{
Double d = ((double[]) obj)[0];
return d.toString();
}
else if (obj instanceof String[])
{
return ((String[]) obj)[0];
}
}
}
此链接可以帮助你:https://www.hdfgroup.org/ftp/HDF5/hdf-java/current/src/unpacked/examples/groups/H5Ex_G_Traverse.java – Aajan