public static H5O.info_t GroupInfo(long groupId) { H5O.info_t info = new H5O.info_t(); var gid = H5O.get_info(groupId, ref info); return(info); }
public void H5Oget_info_by_idxTest2() { H5O.info_t info = new H5O.info_t(); Assert.IsFalse( H5O.get_info_by_idx(Utilities.RandomInvalidHandle(), "A", H5.index_t.NAME, H5.iter_order_t.NATIVE, 44, ref info) >= 0); }
public static double ReadAttribute(string file, string dataSetOrGroup, string attribute) { double attr = Double.NaN; try { H5FileId fileId = H5F.open(file, H5F.OpenMode.ACC_RDONLY); H5ObjectInfo objectInfo = H5O.getInfoByName(fileId, dataSetOrGroup); H5GroupId groupId = null; H5DataSetId dataSetId = null; H5AttributeId attrId; if (objectInfo.objectType == H5ObjectType.GROUP) { groupId = H5G.open(fileId, dataSetOrGroup); attrId = H5A.open(groupId, attribute); } else { dataSetId = H5D.open(fileId, dataSetOrGroup); attrId = H5A.open(dataSetId, attribute); } H5DataTypeId attrTypeId = H5A.getType(attrId); double[] dAttrs = new double[] { }; if (H5T.equal(attrTypeId, H5T.copy(H5T.H5Type.NATIVE_FLOAT))) { float[] fAttrs = new float[H5S.getSimpleExtentNPoints(H5A.getSpace(attrId))]; H5A.read(attrId, attrTypeId, new H5Array <float>(fAttrs)); dAttrs = (from f in fAttrs select(double) f).ToArray(); } else if (H5T.equal(attrTypeId, H5T.copy(H5T.H5Type.NATIVE_DOUBLE))) { dAttrs = new double[H5S.getSimpleExtentNPoints(H5A.getSpace(attrId))]; H5A.read(attrId, attrTypeId, new H5Array <double>(dAttrs)); } H5T.close(attrTypeId); H5A.close(attrId); if (groupId != null) { H5G.close(groupId); } if (dataSetId != null) { H5D.close(dataSetId); } H5F.close(fileId); return((double)dAttrs[0]); } catch (HDFException e) { Console.WriteLine("Error: Unhandled HDF5 exception"); Console.WriteLine(e.Message); } return(attr); }
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); }
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 H5Oexists_by_nameTest1() { Assert.IsTrue(H5L.create_soft("/oh my", m_v0_test_file, "AA") >= 0); hid_t gid = H5G.create(m_v0_test_file, "A/B/C", m_lcpl); Assert.IsTrue(gid >= 0); Assert.IsTrue(H5O.exists_by_name(m_v0_test_file, "A/B") > 0); Assert.IsTrue(H5O.exists_by_name(m_v0_test_file, "AA") == 0); Assert.IsTrue( H5O.exists_by_name(m_v0_test_file, "A/B/Caesar") < 0); Assert.IsTrue(H5G.close(gid) >= 0); Assert.IsTrue(H5L.create_soft("/oh my", m_v2_test_file, "AA") >= 0); gid = H5G.create(m_v2_test_file, "A/B/C", m_lcpl); Assert.IsTrue(gid >= 0); Assert.IsTrue(H5O.exists_by_name(m_v2_test_file, "A/B") > 0); Assert.IsTrue(H5O.exists_by_name(m_v2_test_file, "AA") == 0); Assert.IsTrue( H5O.exists_by_name(m_v2_test_file, "A/B/Caesar") < 0); Assert.IsTrue(H5G.close(gid) >= 0); }
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 H5OvisitTest1() { Assert.IsTrue(H5G.create(m_v0_test_file, "A/B/C/D", m_lcpl) >= 0); Assert.IsTrue( H5L.create_hard(m_v0_test_file, "A/B/C/D", m_v0_test_file, "shortcut") >= 0); Assert.IsTrue(H5G.create(m_v2_test_file, "A/B/C/D", m_lcpl) >= 0); Assert.IsTrue( H5L.create_hard(m_v2_test_file, "A/B/C/D", m_v2_test_file, "shortcut") >= 0); ArrayList al = new ArrayList(); GCHandle hnd = GCHandle.Alloc(al); IntPtr op_data = (IntPtr)hnd; // the callback is defined in H5LTest.cs H5O.iterate_t cb = DelegateMethod; Assert.IsTrue(H5O.visit(m_v0_test_file, H5.index_t.NAME, H5.iter_order_t.NATIVE, cb, op_data) >= 0); // we should have 5 elements in the array list Assert.IsTrue(al.Count == 5); Assert.IsTrue(H5O.visit(m_v2_test_file, H5.index_t.NAME, H5.iter_order_t.NATIVE, cb, op_data) >= 0); // we should have 10 (5 + 5) elements in the array list Assert.IsTrue(al.Count == 10); hnd.Free(); }
public void H5OvisitTest2() { string path = String.Join("/", m_utf8strings); Assert.IsTrue(H5G.create(m_v0_test_file, Encoding.UTF8.GetBytes(path), m_lcpl_utf8) >= 0); Assert.IsTrue(H5G.create(m_v2_test_file, Encoding.UTF8.GetBytes(path), m_lcpl_utf8) >= 0); ArrayList al = new ArrayList(); GCHandle hnd = GCHandle.Alloc(al); IntPtr op_data = (IntPtr)hnd; // the callback is defined in H5LTest.cs H5O.iterate_t cb = DelegateMethod; Assert.IsTrue(H5O.visit(m_v0_test_file, H5.index_t.NAME, H5.iter_order_t.NATIVE, cb, op_data) >= 0); // we should have 6 elements in the array list Assert.IsTrue(al.Count == 6); Assert.IsTrue(H5O.visit(m_v2_test_file, H5.index_t.NAME, H5.iter_order_t.NATIVE, cb, op_data) >= 0); // we should have 12 (6 + 6) elements in the array list Assert.IsTrue(al.Count == 12); hnd.Free(); }
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); }
public void H5Oget_info_by_idxTest1() { Assert.IsTrue( H5G.close(H5G.create(m_v0_test_file, "A")) >= 0); Assert.IsTrue( H5G.close(H5G.create(m_v0_test_file, "AA")) >= 0); Assert.IsTrue( H5G.close(H5G.create(m_v0_test_file, "AAA")) >= 0); Assert.IsTrue( H5G.close(H5G.create(m_v0_test_file, "AAAA")) >= 0); H5O.info_t info = new H5O.info_t(); Assert.IsTrue(H5O.get_info_by_idx(m_v0_test_file, ".", H5.index_t.NAME, H5.iter_order_t.NATIVE, 2, ref info) >= 0); Assert.IsTrue(info.type == H5O.type_t.GROUP); Assert.IsTrue( H5G.close(H5G.create(m_v2_test_file, "A")) >= 0); Assert.IsTrue( H5G.close(H5G.create(m_v2_test_file, "AA")) >= 0); Assert.IsTrue( H5G.close(H5G.create(m_v2_test_file, "AAA")) >= 0); Assert.IsTrue( H5G.close(H5G.create(m_v2_test_file, "AAAA")) >= 0); info = new H5O.info_t(); Assert.IsTrue(H5O.get_info_by_idx(m_v2_test_file, ".", H5.index_t.NAME, H5.iter_order_t.NATIVE, 2, ref info) >= 0); Assert.IsTrue(info.type == H5O.type_t.GROUP); }
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); }
/// <summary> /// Add an attribute and write the values to the file /// </summary> /// <typeparam name="T"></typeparam> /// <param name="_name"></param> /// <param name="_value"></param> /// <returns></returns> public Hdf5Attribute Add <T>(string _name, T _value) { if (Exists(_name)) { throw new Hdf5AttributeAlreadyExistException(); } //If the parent is the file, then just create the attribute (file already open). if (ParentObject.Id.Equals(ParentObject.FileId)) { return(AttributeHelper.CreateAttributeAddToList(ParentObject.Id, this, _name, _value)); } Hdf5Attribute attribute = null; //Otherwise open the object and then call the function. var id = H5O.open(ParentObject.FileId.Value, ParentObject.Path.FullPath).ToId(); if (id.Value > 0) { attribute = AttributeHelper.CreateAttributeAddToList(id, this, _name, _value); H5O.close(id.Value); } return(attribute); }
// Function used with H5L.iterate protected H5IterationResult Op_Func(H5GroupId id, string objectName, H5LinkInfo info, Object param) { H5ObjectInfo objInfo = H5O.getInfoByName(id, objectName); string groupName = (string)param; switch (objInfo.objectType) { case H5ObjectType.DATASET: OnHdfObjInfoFound(objectName, HdfObjectType.Dataset, groupName); break; case H5ObjectType.GROUP: GetHdfObjInfo(objectName); break; case H5ObjectType.NAMED_DATATYPE: break; case H5ObjectType.UNKNOWN: break; } return(H5IterationResult.SUCCESS); }
public static bool GroupExists(hid_t hid, string groupName) { if (string.IsNullOrEmpty(groupName)) { throw new ArgumentException("groupName"); } var exists = H5L.exists(hid, groupName); if (exists < 0) { throw new HDF5Exception("H5L.exists failed"); } if (exists == 0) { return(false); } var objectId = H5O.open(hid, groupName); if (objectId < 0) { throw new HDF5Exception("H5O.open failed"); } var result = GroupExists(objectId); H5O.close(objectId); return(result); }
public static void Write1DArray <T>(Hdf5Dataset _dataset, T[] _array) { if (_dataset.Dataspace.NumberOfDimensions != 1) { throw new Hdf5ArrayDimensionsMismatchException(); } if ((ulong)_array.Length != _dataset.Dataspace.DimensionProperties[0].CurrentSize) { throw new Hdf5ArraySizeMismatchException(); } var datasetId = H5O.open(_dataset.FileId.Value, _dataset.Path.FullPath).ToId(); GCHandle arrayHandle = GCHandle.Alloc(_array, GCHandleType.Pinned); var typeId = H5T.copy(_dataset.DataType.NativeType.Value).ToId(); int result = H5D.write( datasetId.Value, typeId.Value, H5S.ALL, H5S.ALL, H5P.DEFAULT, arrayHandle.AddrOfPinnedObject()); arrayHandle.Free(); H5T.close(typeId.Value); H5O.close(datasetId.Value); FileHelper.FlushToFile(_dataset.FileId); }
public static ulong NumberOfAttributes(int groupId, string groupName) { H5O.info_t info = new H5O.info_t(); var gid = H5O.get_info(groupId, ref info); return(info.num_attrs); }
public void H5OcopyTest2() { Assert.IsTrue(H5L.create_soft("/my/fantastic/path", m_v0_test_file, "A") >= 0); Assert.IsTrue(H5O.copy(m_v0_test_file, ".", m_v2_test_file, "C/B/A_copy", H5P.DEFAULT, m_lcpl) >= 0); }
public void H5OcloseTest4() { hid_t space = H5S.create(H5S.class_t.SCALAR); Assert.IsTrue(space >= 0); Assert.IsTrue(H5O.close(space) < 0); Assert.IsTrue(H5S.close(space) >= 0); }
public void H5Odisable_mdc_flushesTestSWMR2() { hid_t grp = H5G.create(m_v3_test_file_no_swmr, "/A/B/C", m_lcpl); Assert.IsTrue(grp >= 0); Assert.IsTrue(H5O.disable_mdc_flushes(grp) >= 0); Assert.IsTrue(H5G.flush(grp) >= 0); Assert.IsTrue(H5G.close(grp) >= 0); }
public void H5OcloseTest1() { hid_t gid = H5G.create(m_v0_test_file, "A"); Assert.IsTrue(gid >= 0); Assert.IsTrue(H5O.close(gid) >= 0); gid = H5G.create(m_v2_test_file, "A"); Assert.IsTrue(gid >= 0); Assert.IsTrue(H5O.close(gid) >= 0); }
public void H5Oopen_by_idxTest2() { Assert.IsFalse( H5O.open_by_idx(Utilities.RandomInvalidHandle(), ".", H5.index_t.NAME, H5.iter_order_t.NATIVE, 44) >= 0); Assert.IsFalse( H5O.open_by_idx(m_v2_class_file, ".", H5.index_t.NAME, H5.iter_order_t.NATIVE, hsize_t.MaxValue) >= 0); }
public static Dictionary <H5I.type_t, List <string> > IterateObject2(hid_t hid) { var objects = new Dictionary <H5I.type_t, List <string> >(); H5O.visit(hid, H5.index_t.NAME, H5.iter_order_t.INC, new H5O.iterate_t( delegate(hid_t objectId, IntPtr namePtr, ref H5O.info_t info, IntPtr data) { var objectName = Marshal.PtrToStringAnsi(namePtr); switch (H5I.get_type(objectId)) { case H5I.type_t.GROUP: if (!objects.ContainsKey(H5I.type_t.GROUP)) { objects[H5I.type_t.GROUP] = new List <string>(); } objects[H5I.type_t.GROUP].Add(objectName); break; case H5I.type_t.DATASET: if (!objects.ContainsKey(H5I.type_t.DATASET)) { objects[H5I.type_t.DATASET] = new List <string>(); } objects[H5I.type_t.DATASET].Add(objectName); break; case H5I.type_t.DATATYPE: if (!objects.ContainsKey(H5I.type_t.DATATYPE)) { objects[H5I.type_t.DATATYPE] = new List <string>(); } objects[H5I.type_t.DATATYPE].Add(objectName); break; case H5I.type_t.ATTR: if (!objects.ContainsKey(H5I.type_t.ATTR)) { objects[H5I.type_t.ATTR] = new List <string>(); } objects[H5I.type_t.ATTR].Add(objectName); break; default: break; } return(0); }), IntPtr.Zero); return(objects); }
public void H5RdereferenceTest4() { byte[] path = Encoding.UTF8.GetBytes(String.Join("/", m_utf8strings)); // make room for the trailling \0 byte[] name = new byte[path.Length + 1]; Array.Copy(path, name, path.Length); hsize_t[] dims = new hsize_t[] { 10, 20 }; hid_t space = H5S.create_simple(2, dims, null); Assert.IsTrue(space >= 0); hid_t dset = H5D.create(m_v2_test_file, name, H5T.STD_I32LE, space, m_lcpl_utf8); H5O.info_t info = new H5O.info_t(); Assert.IsTrue(H5O.get_info(dset, ref info) >= 0); haddr_t address = info.addr; Assert.IsTrue(H5D.close(dset) >= 0); Assert.IsTrue(dset >= 0); hsize_t[] start = { 5, 10 }; hsize_t[] count = { 1, 1 }; hsize_t[] block = { 2, 4 }; Assert.IsTrue( H5S.select_hyperslab(space, H5S.seloper_t.SET, start, null, count, block) >= 0); byte[] refer = new byte[H5R.DSET_REG_REF_BUF_SIZE]; GCHandle hnd = GCHandle.Alloc(refer, GCHandleType.Pinned); Assert.IsTrue( H5R.create(hnd.AddrOfPinnedObject(), m_v2_test_file, name, H5R.type_t.DATASET_REGION, space) >= 0); #if HDF5_VER1_10 dset = H5R.dereference(m_v2_test_file, H5P.DEFAULT, H5R.type_t.DATASET_REGION, hnd.AddrOfPinnedObject()); #else dset = H5R.dereference(m_v2_test_file, H5R.type_t.DATASET_REGION, hnd.AddrOfPinnedObject()); #endif Assert.IsTrue(dset >= 0); hnd.Free(); Assert.IsTrue(H5O.get_info(dset, ref info) >= 0); Assert.IsTrue(address == info.addr); Assert.IsTrue(H5D.close(dset) >= 0); Assert.IsTrue(H5S.close(space) >= 0); }
public void H5OcopyTest1() { hid_t gid = H5G.create(m_v0_test_file, "A/B/C", m_lcpl); Assert.IsTrue(gid >= 0); Assert.IsTrue( H5O.copy(m_v0_test_file, "A", m_v2_test_file, "A_copy") >= 0); Assert.IsTrue(H5L.exists(m_v2_test_file, "A_copy/B/C") > 0); Assert.IsTrue(H5G.close(gid) >= 0); }
public void H5OopenTest1() { Assert.IsTrue( H5G.close(H5G.create(m_v0_test_file, "A/B/C", m_lcpl)) >= 0); hid_t obj = H5O.open(m_v0_test_file, "A/B"); Assert.IsTrue(obj >= 0); Assert.IsTrue(H5O.close(obj) >= 0); Assert.IsTrue( H5G.close(H5G.create(m_v2_test_file, "A/B/C", m_lcpl)) >= 0); obj = H5O.open(m_v2_test_file, "A/B"); Assert.IsTrue(obj >= 0); Assert.IsTrue(H5O.close(obj) >= 0); }
public void H5OlinkTest1() { hid_t gid = H5G.create_anon(m_v0_test_file); Assert.IsTrue(gid >= 0); Assert.IsTrue(H5O.link(gid, m_v0_test_file, "A/B/C", m_lcpl) >= 0); Assert.IsTrue(H5G.close(gid) >= 0); gid = H5G.create_anon(m_v2_test_file); Assert.IsTrue(gid >= 0); Assert.IsTrue(H5O.link(gid, m_v2_test_file, "A/B/C", m_lcpl) >= 0); Assert.IsTrue(H5G.close(gid) >= 0); }
/// <summary> /// Update the attribute and write the values to the file /// </summary> /// <param name="_attribute"></param> public void Update(Hdf5Attribute _attribute) { //If the parent is the file, then just update the attribute (file already open). if (ParentObject.Id.Equals(ParentObject.FileId)) { AttributeHelper.UpdateAttribute(ParentObject.Id, _attribute); } //Otherwise open the object and then update the attribute. var id = H5O.open(ParentObject.FileId.Value, ParentObject.Path.FullPath).ToId(); if (id.Value > 0) { AttributeHelper.UpdateAttribute(id, _attribute); H5O.close(id.Value); } }
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); }
public void H5Odecr_refcountTest1() { hid_t gid = H5G.create(m_v0_test_file, "A/B/C", m_lcpl); Assert.IsTrue(gid >= 0); // Don't try this at home! Assert.IsTrue(H5O.decr_refcount(gid) >= 0); Assert.IsTrue(H5G.close(gid) >= 0); gid = H5G.create(m_v2_test_file, "A/B/C", m_lcpl); Assert.IsTrue(gid >= 0); // Don't try this at home! Assert.IsTrue(H5O.decr_refcount(gid) >= 0); Assert.IsTrue(H5G.close(gid) >= 0); }