public static object GetObject(Hdf5Identifier _fileId, AbstractHdf5Object _parent, string _objectName) { Hdf5Path combinedPath = _parent.Path.Append(_objectName); object output = null; if (combinedPath != null) { string fullPath = combinedPath.FullPath; H5O.info_t gInfo = new H5O.info_t(); H5O.get_info_by_name(_fileId.Value, fullPath, ref gInfo); var id = H5O.open(_fileId.Value, fullPath).ToId(); if (id.Value > 0) { if (gInfo.type == H5O.type_t.DATASET) { output = DatasetHelper.LoadDataset(_fileId, id, fullPath); } if (gInfo.type == H5O.type_t.GROUP) { Hdf5Group group = new Hdf5Group(_fileId, id, fullPath); group.FileId = _fileId; group.LoadChildObjects(); output = group; } H5O.close(id.Value); } } return(output); }
public static bool GroupExists(hid_t groupId, string groupName) { H5O.info_t info = new H5O.info_t(); var gid = H5O.get_info_by_name(groupId, groupName, ref info, H5P.DEFAULT); return(gid == 0); }
public void H5Oget_info_by_nameTest2() { H5O.info_t info = new H5O.info_t(); Assert.IsFalse( H5O.get_info_by_name(Utilities.RandomInvalidHandle(), ".", ref info) >= 0); }
protected Dictionary <string, long> FindChildren(bool dataSets) { Dictionary <string, long> datasetNames = new Dictionary <string, long>(); Dictionary <string, long> groupNames = new Dictionary <string, long>(); var rootID = Open(); ulong dummy = 0; H5L.iterate(rootID, H5.index_t.NAME, H5.iter_order_t.INC, ref dummy, new H5L.iterate_t( delegate(long objectId, IntPtr namePtr, ref H5L.info_t info, IntPtr op_data) { string objectName = Marshal.PtrToStringAnsi(namePtr); H5O.info_t gInfo = new H5O.info_t(); H5O.get_info_by_name(objectId, objectName, ref gInfo); if (gInfo.type == H5O.type_t.DATASET) { datasetNames[objectName] = objectId; } else if (gInfo.type == H5O.type_t.GROUP) { groupNames[objectName] = objectId; } return(0); }), new IntPtr()); H5G.close(rootID); if (dataSets) { return(datasetNames); } return(groupNames); }
private string[] CollectObjects(H5O.type_t type) { const int CONTINUE = 0; int status; List <string> rv = new List <string>(); // the callback function, called for each item in the iteration #if HDF5_VER1_10 H5L.iterate_t op_fun = (long loc, IntPtr name, ref H5L.info_t info, IntPtr op_data) => #else H5L.iterate_t op_fun = (int loc, IntPtr name, ref H5L.info_t info, IntPtr op_data) => #endif { H5O.info_t oinfo = new H5O.info_t(); var bname = Marshal.PtrToStringAnsi(name); if ((status = H5O.get_info_by_name(loc, bname, ref oinfo, H5P.DEFAULT)) < 0) { return(status); } if (oinfo.type == type) { rv.Add(bname); } return(CONTINUE); }; ulong tracking_index = 0; if ((status = H5L.iterate(ID, H5.index_t.NAME, H5.iter_order_t.NATIVE, ref tracking_index, op_fun, IntPtr.Zero)) < 0) { throw new H5LibraryException($"H5Literate() returned {status}"); } return(rv.ToArray()); }
public void H5Oget_info_by_nameTest1() { Assert.IsTrue( H5G.close(H5G.create(m_v0_test_file, "A/B/C", m_lcpl)) >= 0); H5O.info_t info = new H5O.info_t(); Assert.IsTrue( H5O.get_info_by_name(m_v0_test_file, "A/B", ref info) >= 0); Assert.IsTrue(info.type == H5O.type_t.GROUP); Assert.IsTrue( H5G.close(H5G.create(m_v2_test_file, "A/B/C", m_lcpl)) >= 0); info = new H5O.info_t(); Assert.IsTrue( H5O.get_info_by_name(m_v2_test_file, "A/B", ref info) >= 0); Assert.IsTrue(info.type == H5O.type_t.GROUP); }
private void GetGroupDatasetNames(string groupName) { ulong pos = 0; List <string> groupNames = new List <string>(); Int32 groupId = H5G.open(_h5FileId, groupName); if (groupId > 0) { ArrayList al = new ArrayList(); GCHandle hnd = GCHandle.Alloc(al); IntPtr op_data = (IntPtr)hnd; H5L.iterate(groupId, H5.index_t.NAME, H5.iter_order_t.NATIVE, ref pos, delegate(int _objectId, IntPtr _namePtr, ref H5L.info_t _info, IntPtr _data) { string objectName = Marshal.PtrToStringAnsi(_namePtr); groupNames.Add(objectName); return(0); }, op_data); hnd.Free(); H5G.close(groupId); foreach (var itemName in groupNames) { //判断是不是数据集 string curPath = string.Empty; if (groupName == "/") { curPath = itemName; } else { curPath = groupName + itemName; } H5O.info_t gInfo = new H5O.info_t(); H5O.get_info_by_name(_h5FileId, curPath, ref gInfo); var objId = H5O.open(_h5FileId, curPath); if (objId > 0) { if (gInfo.type == H5O.type_t.DATASET) { _datasetNames.Add(curPath); } if (gInfo.type == H5O.type_t.GROUP) { GetGroupDatasetNames(curPath + "/"); } H5O.close(objId); } } } // H5GroupId h5GroupId = H5G.open(_h5FileId, groupName); //try //{ // long dscount = H5G.getNumObjects(h5GroupId); // for (int i = 0; i < dscount; i++) // { // string objname = H5G.getObjectNameByIndex(h5GroupId, (ulong)i); // ObjectInfo objInfo = H5G.getObjectInfo(h5GroupId, objname, false); // switch (objInfo.objectType) // { // case H5GType.DATASET: // if (objInfo.objectType == H5GType.DATASET) // { // if (groupName == "/") // _datasetNames.Add(objname); // else // _datasetNames.Add(groupName + objname); // } // break; // case H5GType.GROUP: // if (groupName == "/") // GetGroupDatasetNames(objname + "/"); // else // GetGroupDatasetNames(groupName + objname + "/"); // break; // case H5GType.LINK: // break; // case H5GType.TYPE: // break; // default: // break; // } // } //} //finally //{ // if (h5GroupId != null) // H5G.close(h5GroupId); //} }