2016-03-05 122 views
0

我正在使用由ch.systemsx.cisd.hdf5.HDF5Factory(JHDF5)提供的庫來讀取HDF5文件。他們的文檔鏈接不能很好地工作,我不知道該如何解決這個問題。如何從HDF5文件讀取屬性?

有沒有人在這裏知道如何使用上面的java庫從HDF5文件讀取屬性值?

+0

此鏈接可以幫助你:https://www.hdfgroup.org/ftp/HDF5/hdf-java/current/src/unpacked/examples/groups/H5Ex_G_Traverse.java – Aajan

回答

0

經過大量的試驗和錯誤發現了一個解決方案。請在下面找到代碼以從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]; 
     } 
    } 
}