public void H5Aget_info_by_idxTest1() { H5A.info_t info = new H5A.info_t(); hid_t att = H5A.create(m_v2_test_file, "A", H5T.IEEE_F64LE, m_space_scalar); Assert.IsTrue(att >= 0); Assert.IsTrue(H5A.close(att) >= 0); att = H5A.create(m_v2_test_file, "B", H5T.IEEE_F64LE, m_space_scalar); Assert.IsTrue(att >= 0); Assert.IsTrue(H5A.close(att) >= 0); Assert.IsTrue(H5A.get_info_by_idx(m_v2_test_file, ".", H5.index_t.NAME, H5.iter_order_t.NATIVE, 0, ref info) >= 0); Assert.IsTrue(H5A.get_info_by_idx(m_v2_test_file, ".", H5.index_t.NAME, H5.iter_order_t.NATIVE, 1, ref info) >= 0); att = H5A.create(m_v0_test_file, "A", H5T.IEEE_F64LE, m_space_scalar); Assert.IsTrue(att >= 0); Assert.IsTrue(H5A.close(att) >= 0); Assert.IsTrue(H5A.get_info_by_idx(m_v0_test_file, ".", H5.index_t.NAME, H5.iter_order_t.NATIVE, 0, ref info) >= 0); Assert.IsFalse(H5A.get_info_by_idx(m_v0_test_file, ".", H5.index_t.NAME, H5.iter_order_t.NATIVE, 1, ref info) >= 0); }
protected override void OnInitialize() { if (IOHelper.CheckLinkExists(_vdsMetaFileId, _currentPath)) { _groupId = H5G.open(_vdsMetaFileId, _currentPath); if (H5A.exists(_groupId, "unit") > 0) { _unit = IOHelper.ReadAttribute <string>(_groupId, "unit").FirstOrDefault(); } if (H5A.exists(_groupId, "transfer_function_set") > 0) { _vdsMetaTransferFunctionSet = IOHelper.ReadAttribute <hdf_transfer_function_t>(_groupId, "transfer_function_set").ToList(); } else { _vdsMetaTransferFunctionSet = new List <hdf_transfer_function_t>(); } H5G.close(_groupId); } else { _vdsMetaTransferFunctionSet = new List <hdf_transfer_function_t>(); } }
public void H5Aget_nameTest1() { size_t buf_size = IntPtr.Zero; ssize_t size = IntPtr.Zero; hid_t att = H5A.create(m_v2_test_file, "H5Aget_name", H5T.IEEE_F64LE, m_space_scalar); Assert.IsTrue(att >= 0); // pretend we don't know the size size = H5A.get_name(att, buf_size, (StringBuilder)null); Assert.IsTrue(size.ToInt32() == 11); buf_size = new IntPtr(size.ToInt32() + 1); StringBuilder nameBuilder = new StringBuilder(buf_size.ToInt32()); size = H5A.get_name(att, buf_size, nameBuilder); Assert.IsTrue(size.ToInt32() == 11); string name = nameBuilder.ToString(); // names should match Assert.AreEqual("H5Aget_name", name); // read a truncated version buf_size = new IntPtr(3); nameBuilder = new StringBuilder(3); size = H5A.get_name(att, buf_size, nameBuilder); Assert.IsTrue(size.ToInt32() == 11); name = nameBuilder.ToString(); // names won't match Assert.AreNotEqual("H5Aget_name", name); Assert.AreEqual("H5", name); Assert.IsTrue(H5A.close(att) >= 0); }
private static long GetId(long parentId, string name, long dataType, long spaceId, Hdf5ElementType type) { string normalizedName = NormalizedName(name); bool exists = ItemExists(parentId, normalizedName, type); if (exists) { LogMessage($"{normalizedName} already exists", Hdf5LogLevel.Debug); if (!Hdf5.Settings.OverrideExistingData) { if (Hdf5.Settings.ThrowOnError) { throw new Hdf5Exception($"{normalizedName} already exists"); } return(-1); } } var datasetId = -1L; switch (type) { case Hdf5ElementType.Unknown: break; case Hdf5ElementType.Group: case Hdf5ElementType.Dataset: if (exists) { H5L.delete(parentId, normalizedName); // datasetId = H5D.open(parentId, normalizedName); } datasetId = H5D.create(parentId, normalizedName, dataType, spaceId); break; case Hdf5ElementType.Attribute: if (exists) { H5A.delete(parentId, normalizedName); } datasetId = H5A.create(parentId, normalizedName, dataType, spaceId); break; default: throw new ArgumentOutOfRangeException(nameof(type), type, null); } if (datasetId == -1L) { string error = $"Unable to create dataset for {normalizedName}"; LogMessage($"{normalizedName} already exists", Hdf5LogLevel.Error); if (Hdf5.Settings.ThrowOnError) { throw new Hdf5Exception(error); } } return(datasetId); }
/// <summary> /// /// </summary> /// <param name="_objectId"></param> /// <param name="_attribute"></param> public static void UpdateAttribute(Hdf5Identifier _objectId, Hdf5Attribute _attribute) { Hdf5Identifier attributeId = H5A.open(_objectId.Value, _attribute.Name).ToId(); if (attributeId.Value > 0) { Hdf5DataType type = TypeHelper.GetDataTypeFromAttribute(attributeId); Hdf5DataTypes enumType = TypeHelper.GetDataTypesEnum(_attribute.Value.GetType()); if (type.Type == enumType) { if (enumType == Hdf5DataTypes.String) { H5A.close(attributeId.Value); DeleteAttribute(_objectId, _attribute.Name); Hdf5Attribute attribute = CreateAttribute(_objectId, _attribute.Name, _attribute.Value); if (attribute != null) { _attribute.Id = attribute.Id; _attribute.Name = attribute.Name; _attribute.Value = attribute.Value; } } else { WriteObjectValue(type, attributeId, _attribute.Value); } } else { throw new Hdf5TypeMismatchException(); } } }
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 bool Contains(string key) { return(Host.With((objId) => { long attrId = 0; try { attrId = H5A.open(objId, key); if (attrId < 0) { return false; } return true; } catch { return false; } finally { if (attrId > 0) { H5A.close(attrId); } } })); }
public static string AttributeAsString(H5AttributeId _attributeId) { H5DataTypeId dataTypeId = H5A.getType(_attributeId); bool isVariableLength = H5T.isVariableString(dataTypeId); if (isVariableLength) { // Variable length string attribute // NOTE: This section only works if the array length is 1 VariableLengthString[] value = new VariableLengthString[1]; H5A.read <VariableLengthString>(_attributeId, dataTypeId, new H5Array <VariableLengthString>(value)); return(value[0].ToString()); } else { // Make length smaller so null termination character is not read int length = (int)H5T.getSize(dataTypeId) - 1; // Fixed length string attribute byte[] valueBytes = new byte[length]; H5A.read <byte>(_attributeId, dataTypeId, new H5Array <byte>(valueBytes)); string value = System.Text.ASCIIEncoding.ASCII.GetString(valueBytes); return(value); } }
public static void UpdateCampaignInfoSet() { long vdsFileId = -1; long vdsMetaFileId = -1; long groupId = -1; lock (_lock) { try { if (File.Exists(_options.VdsFilePath)) { vdsFileId = H5F.open(_options.VdsFilePath, H5F.ACC_RDONLY); vdsMetaFileId = H5F.open(_options.VdsMetaFilePath, H5F.ACC_RDONLY); Program.CampaignInfoSet = GeneralHelper.GetCampaignInfoSet(vdsFileId, false); } else { Program.CampaignInfoSet = new List <CampaignInfo>(); } Program.CampaignDescriptionSet = Program.CampaignInfoSet.ToDictionary(campaignInfo => campaignInfo.Name, campaignInfo => { if (IOHelper.CheckLinkExists(vdsMetaFileId, campaignInfo.Name)) { try { groupId = H5G.open(vdsMetaFileId, campaignInfo.Name); if (H5A.exists(groupId, "description") > 0) { return(IOHelper.ReadAttribute <string>(groupId, "description").First()); } } finally { if (H5I.is_valid(groupId) > 0) { H5G.close(groupId); } } } return("no description available"); }); } finally { if (H5I.is_valid(vdsFileId) > 0) { H5F.close(vdsFileId); } if (H5I.is_valid(vdsMetaFileId) > 0) { H5F.close(vdsMetaFileId); } } } }
/// <summary> /// Reads the data from the specified attribute. /// </summary> /// <typeparam name="T">The data type.</typeparam> /// <param name="locationId">The location ID.</param> /// <param name="attributeName">The name of the attribute.</param> /// <returns>Returns a set of type T which represents the read data.</returns> public static T[] ReadAttribute <T>(long locationId, string attributeName) { long attributeId = -1; T[] result; try { attributeId = H5A.open(locationId, attributeName); if (H5I.is_valid(attributeId) <= 0) { throw new Exception(ErrorMessage.IOHelper_CouldNotOpenAttribute); } result = IOHelper.Read <T>(attributeId, DataContainerType.Attribute); } finally { if (H5I.is_valid(attributeId) > 0) { H5A.close(attributeId); } } return(result); }
public static (long AttributeId, bool IsNew) OpenOrCreateAttribute(long locationId, string name, long attributeTypeId, ulong length, ulong[] dimensionLimitSet) { return(IOHelper.OpenOrCreateAttribute(locationId, name, attributeTypeId, () => { long dataspaceId = -1; long attributeId = -1; try { dataspaceId = H5S.create_simple(1, new ulong[] { length }, dimensionLimitSet); attributeId = H5A.create(locationId, name, attributeTypeId, dataspaceId); if (H5I.is_valid(attributeId) <= 0) { throw new Exception(ErrorMessage.IOHelper_CouldNotOpenOrCreateAttribute); } } finally { if (H5I.is_valid(dataspaceId) > 0) { H5S.close(dataspaceId); } } return attributeId; })); }
public void H5AexistsTest2() { Assert.IsFalse( H5A.exists(Utilities.RandomInvalidHandle(), ".") >= 0); Assert.IsFalse( H5A.exists(m_v2_class_file, "") >= 0); }
public void H5AdeleteTest1() { hid_t att = H5A.create(m_v0_class_file, "DNA", H5T.IEEE_F32BE, m_space_null); Assert.IsTrue(att >= 0); Assert.IsTrue(H5A.close(att) >= 0); att = H5A.create(m_v2_class_file, "DNA", H5T.IEEE_F32BE, m_space_null); Assert.IsTrue(att >= 0); Assert.IsTrue(H5A.close(att) >= 0); att = H5A.create(m_v0_class_file, "DSA", H5T.IEEE_F32BE, m_space_scalar); Assert.IsTrue(att >= 0); Assert.IsTrue(H5A.close(att) >= 0); att = H5A.create(m_v2_class_file, "DSA", H5T.IEEE_F32BE, m_space_scalar); Assert.IsTrue(att >= 0); Assert.IsTrue(H5A.close(att) >= 0); Assert.IsTrue(H5A.delete(m_v0_class_file, "DNA") >= 0); Assert.IsTrue(H5A.delete(m_v0_class_file, "DSA") >= 0); Assert.IsTrue(H5A.delete(m_v2_class_file, "DNA") >= 0); Assert.IsTrue(H5A.delete(m_v2_class_file, "DSA") >= 0); }
public void H5Aget_info_by_nameTest1() { H5A.info_t info = new H5A.info_t(); hid_t att = H5A.create(m_v2_test_file, "A", H5T.IEEE_F64LE, m_space_scalar); Assert.IsTrue(att >= 0); Assert.IsTrue(H5A.close(att) >= 0); att = H5A.create(m_v2_test_file, "B", H5T.IEEE_F64LE, m_space_scalar); Assert.IsTrue(att >= 0); Assert.IsTrue(H5A.close(att) >= 0); Assert.IsTrue(H5A.get_info_by_name(m_v2_test_file, ".", "A", ref info) >= 0); Assert.IsTrue(H5A.get_info_by_name(m_v2_test_file, ".", "B", ref info) >= 0); att = H5A.create(m_v0_test_file, "A", H5T.IEEE_F64LE, m_space_scalar); Assert.IsTrue(att >= 0); Assert.IsTrue(H5A.close(att) >= 0); Assert.IsTrue(H5A.get_info_by_name(m_v0_test_file, ".", "A", ref info) >= 0); Assert.IsFalse(H5A.get_info_by_name(m_v0_test_file, ".", "B", ref info) >= 0); }
public static int WritePrimitiveAttribute <T>(hid_t groupId, string name, Array attributes, string datasetName = null) //where T : struct { var tmpId = groupId; if (!string.IsNullOrWhiteSpace(datasetName)) { var datasetId = H5D.open(groupId, datasetName); if (datasetId > 0) { groupId = datasetId; } } int rank = attributes.Rank; ulong[] dims = Enumerable.Range(0, rank).Select(i => { return((ulong)attributes.GetLength(i)); }).ToArray(); ulong[] maxDims = null; var spaceId = H5S.create_simple(rank, dims, maxDims); var datatype = GetDatatype(typeof(T)); var typeId = H5T.copy(datatype); var attributeId = H5A.create(groupId, name, datatype, spaceId); GCHandle hnd = GCHandle.Alloc(attributes, GCHandleType.Pinned); var result = H5A.write(attributeId, datatype, hnd.AddrOfPinnedObject()); hnd.Free(); H5A.close(attributeId); H5S.close(spaceId); H5T.close(typeId); if (tmpId != groupId) { H5D.close(groupId); } return(result); }
private bool getOMXFileAttributes() { string version = "unknown"; // OMX Version H5AttributeId verId = H5A.open(fileId, omxVersionName); H5T.H5TClass verCl = H5T.getClass(H5A.getType(verId)); if (verCl.Equals(H5T.H5TClass.STRING)) { Byte[] buff = getAttribute <byte>(verId); ASCIIEncoding enc = new ASCIIEncoding(); version = enc.GetString(buff); } else if (verCl.Equals(H5T.H5TClass.FLOAT)) { float[] buff = getAttribute <float>(verId); version = buff.ToString(); // produces garbage - bail out from here... throw new NotImplementedException(); } else { throw new NotImplementedException(); } //Console.WriteLine("omx version: {0}", version); this.OmxVersion = version; H5A.close(verId); // matrix shape H5AttributeId shId = H5A.open(fileId, omxShapeAttr); H5T.H5TClass shCl = H5T.getClass(H5A.getType(shId)); if (shCl.Equals(H5T.H5TClass.INTEGER)) { int[] shape = getAttribute <int>(shId); this.Shape[0] = (long)shape[0]; this.Shape[1] = (long)shape[1]; } else if (shCl.Equals(H5T.H5TClass.FLOAT)) { float[] shape = getAttribute <float>(shId); this.Shape[0] = (long)shape[0]; this.Shape[1] = (long)shape[1]; // returns garbage, bail out from here throw new NotImplementedException(); } else { throw new NotImplementedException(); } H5A.close(shId); return(true); }
public void H5AreadTest1() { double[] x = { Math.PI }; IntPtr buf = Marshal.AllocHGlobal(8); hid_t att = H5A.create(m_v2_test_file, "A", H5T.IEEE_F64LE, m_space_scalar); Assert.IsTrue(att >= 0); Assert.IsTrue(H5A.read(att, H5T.IEEE_F64BE, buf) >= 0); Assert.IsTrue(H5A.read(att, H5T.NATIVE_DOUBLE, buf) >= 0); Marshal.Copy(buf, x, 0, 1); Assert.IsTrue(x[0] == 0.0); Assert.IsTrue(H5A.close(att) >= 0); att = H5A.create(m_v0_test_file, "A", H5T.IEEE_F64LE, m_space_scalar); Assert.IsTrue(att >= 0); Assert.IsTrue(H5A.read(att, H5T.IEEE_F64BE, buf) >= 0); Assert.IsTrue(H5A.read(att, H5T.NATIVE_DOUBLE, buf) >= 0); Marshal.Copy(buf, x, 0, 1); Assert.IsTrue(x[0] == 0.0); Assert.IsTrue(H5A.close(att) >= 0); Marshal.FreeHGlobal(buf); }
public void H5Aopen_by_nameTest2() { Assert.IsFalse( H5A.open_by_name(Utilities.RandomInvalidHandle(), ".", "") >= 0); Assert.IsFalse( H5A.open_by_name(m_v2_class_file, ".", "") >= 0); }
private static void WriteAttribute(H5ObjectWithAttributes target, string name, string value) { if (string.IsNullOrEmpty(name)) { throw new ArgumentException("Name must not be empty (or null)", "name"); } if (string.IsNullOrEmpty(value)) { throw new ArgumentException("Value must not be empty or null", "value"); } H5DataTypeId dtype; byte[] strdata = EncodeStringData(value, out dtype); H5DataSpaceId spaceId = H5S.create(H5S.H5SClass.SCALAR); H5AttributeId attributeId = H5A.create(target, name, dtype, spaceId); H5A.write(attributeId, dtype, new H5Array <byte>(strdata)); H5A.close(attributeId); H5T.close(dtype); H5S.close(spaceId); }
public static T ReadEnumAttribute <T>(hid_t hid, string key) where T : struct, IConvertible { var attribute = H5A.open(hid, key); if (attribute < 0) { throw new ArgumentException(string.Format("Attribute {0} not found.", key)); } var type = H5A.get_type(attribute); if (type < 0) { H5A.close(attribute); throw new Exception("H5A.get_type failed."); } var size = H5T.get_size(type).ToInt32(); if (size == 0) { H5T.close(type); H5A.close(attribute); throw new Exception("H5T.get_size failed."); } var unmanagedBuffer = new UnmanagedBuffer(size); H5A.read(attribute, type, unmanagedBuffer); H5T.close(type); H5A.close(attribute); return(unmanagedBuffer.ReadEnum <T>()); }
private void GetAllFileAttributes() { //所有Attributes的键 ArrayList arrayList = new ArrayList(); GCHandle handle = GCHandle.Alloc(arrayList); ulong n = 0; // the callback is defined in H5ATest.cs H5A.operator_t cb = (int location_id, IntPtr attr_name, ref H5A.info_t ainfo, IntPtr op_data) => { GCHandle hnd = (GCHandle)op_data; ArrayList al = (hnd.Target as ArrayList); int len = 0; while (Marshal.ReadByte(attr_name, len) != 0) { ++len; } byte[] buf = new byte[len]; Marshal.Copy(attr_name, buf, 0, len); al.Add(Encoding.UTF8.GetString(buf)); return(0); }; H5A.iterate(_h5FileId, H5.index_t.NAME, H5.iter_order_t.NATIVE, ref n, cb, (IntPtr)handle); handle.Free(); foreach (string attributeName in arrayList) { _fileAttrs.Add(attributeName, ReadAttributeValue(_h5FileId, attributeName)); } }
private bool setOMXFileAttributes() { // write OMX attributes H5DataSpaceId dspace; H5DataTypeId dtype; H5AttributeId attr; // OMX version dspace = H5S.create(H5S.H5SClass.SCALAR); dtype = H5T.copy(H5T.H5Type.C_S1); // string datatype H5T.setSize(dtype, dllVersion[0].Length); attr = H5A.create(fileId, omxVersionName, dtype, dspace); ASCIIEncoding ascii = new ASCIIEncoding(); H5A.write(attr, dtype, new H5Array <System.Byte>(ascii.GetBytes(dllVersion[0]))); H5A.close(attr); // OMX shape - only 2D tables dspace = H5S.create_simple(1, new long[] { 2 }); dtype = H5T.copy(H5T.H5Type.NATIVE_INT); attr = H5A.create(fileId, omxShapeAttr, dtype, dspace); int[] shape = new int[2]; shape[0] = (int)Shape[0]; shape[1] = (int)Shape[1]; H5A.write <int>(attr, dtype, new H5Array <int>(shape)); H5S.close(dspace); H5A.close(attr); return(true); }
public static string GetAttributeValue(H5ObjectWithAttributes objectWithAttributes, string name) { if (objectWithAttributes is null) { throw new ArgumentNullException(nameof(objectWithAttributes)); } if (name is null) { throw new ArgumentNullException(nameof(name)); } H5AttributeId h5AttributeId = H5A.open(objectWithAttributes, name); H5DataTypeId h5DataTypeId = H5A.getType(h5AttributeId); if (H5T.isVariableString(h5DataTypeId)) { VariableLengthString[] variableLengthStrings = new VariableLengthString[1]; H5A.read(h5AttributeId, h5DataTypeId, new H5Array <VariableLengthString> (variableLengthStrings)); H5T.close(h5DataTypeId); H5A.close(h5AttributeId); return(variableLengthStrings[0].ToString()); } byte[] bytes = new byte[H5T.getSize(h5DataTypeId)]; H5A.read(h5AttributeId, h5DataTypeId, new H5Array <byte> (bytes)); H5T.close(h5DataTypeId); H5A.close(h5AttributeId); return(Encoding.ASCII.GetString(bytes)); }
/// <summary> /// Store a string in this *attribute*. /// </summary> public void Writes(string value) { using (H5Type dtype = GetDType()) { if (typeof(System.String) != dtype.PrimitiveType) { throw new InvalidCastException(dtype.PrimitiveType.ToString()); } long slen = dtype.Size; if (value.Length > slen - 1) { throw new IndexOutOfRangeException($"string longer than ({slen})"); } byte[] buf = new byte[slen]; Array.Copy(string1d.Enc.GetBytes(value), buf, value.Length); GCHandle pinnedArray = GCHandle.Alloc(buf, GCHandleType.Pinned); int status = H5A.write(ID, dtype.ID, pinnedArray.AddrOfPinnedObject()); pinnedArray.Free(); if (status < 0) { throw new H5LibraryException($"H5A.write() returned ({status})"); } } }
/// <summary> /// 写数据集属性 /// </summary> public void WriteDatasetAttribute(string datasetName, string attrName, string value) { H5DataSetId datasetId = H5D.open(_fileId, datasetName); H5DataTypeId typeId = H5T.copy(H5T.H5Type.C_S1); H5DataSpaceId spaceId = H5S.create(H5S.H5SClass.SCALAR); H5T.setSize(typeId, value.Length); H5AttributeId attrId = H5A.create(datasetId, attrName, typeId, spaceId); if (value != "") { H5Array <byte> buffer = new H5Array <byte>(Encoding.Default.GetBytes(value)); H5A.write(attrId, typeId, buffer); } if (typeId != null) { H5T.close(typeId); } if (spaceId != null) { H5S.close(spaceId); } if (attrId != null) { H5A.close(attrId); } if (datasetId != null) { H5D.close(datasetId); } }
internal static H5Attribute Create(hid_t loc_id, string name, Type primitive, object default_ = null) { if (primitive == null) { primitive = default_.GetType(); // may throw NullReferenceException, which is informational enough } int rank = 1; long[] dims = new long[1] { 1 }; hid_t id; using (H5Space space = H5Space.Create(rank, dims)) using (H5Type dtype = H5Type.Create(primitive)) { if ((id = H5A.create(loc_id, name, dtype.ID, space.ID, H5P.DEFAULT, H5P.DEFAULT)) < 0) { throw new H5LibraryException($"H5A.create() returned ({id})"); } } H5Attribute rv = FromID(id); if (default_ != null) { rv.Write(default_); } return(rv); }
public static Dictionary <uint, string> GetLabelWorkingSet(long group_id) { Dictionary <uint, string> labelWorkingSet = new Dictionary <uint, string>(); H5A.operator_t callBackMethod = DelegateMethod; ArrayList attrNameArray = new ArrayList(); GCHandle nameArrayAlloc = GCHandle.Alloc(attrNameArray); IntPtr ptrOnAllocArray = (IntPtr)nameArrayAlloc; int status; ulong beginAt = 0; status = H5A.iterate(group_id, H5.index_t.CRT_ORDER, H5.iter_order_t.INC, ref beginAt, callBackMethod, ptrOnAllocArray); for (int i = 0; i < attrNameArray.Count; i++) { string attr_name = Convert.ToString(attrNameArray[i]); long attr_id = H5A.open(group_id, attr_name); uint[] attr_value = { 0 }; GCHandle valueAlloc = GCHandle.Alloc(attr_value, GCHandleType.Pinned); status = H5A.read(attr_id, H5T.NATIVE_UINT32, valueAlloc.AddrOfPinnedObject()); status = H5A.close(attr_id); labelWorkingSet.Add(attr_value[0], attr_name); } status = H5G.close(group_id); return(labelWorkingSet); }
public void H5Aopen_by_idxTest1() { hid_t att = H5A.create(m_v2_test_file, "A", H5T.IEEE_F64LE, m_space_scalar); Assert.IsTrue(att >= 0); Assert.IsTrue(H5A.close(att) >= 0); att = H5A.create(m_v2_test_file, "AA", H5T.IEEE_F64LE, m_space_scalar); Assert.IsTrue(att >= 0); Assert.IsTrue(H5A.close(att) >= 0); att = H5A.open_by_idx(m_v2_test_file, ".", H5.index_t.NAME, H5.iter_order_t.NATIVE, 0); Assert.IsTrue(att >= 0); Assert.IsTrue(H5A.close(att) >= 0); att = H5A.open_by_idx(m_v2_test_file, ".", H5.index_t.NAME, H5.iter_order_t.NATIVE, 1); Assert.IsTrue(att >= 0); Assert.IsTrue(H5A.close(att) >= 0); att = H5A.create(m_v0_test_file, "A", H5T.IEEE_F64LE, m_space_scalar); Assert.IsTrue(att >= 0); Assert.IsTrue(H5A.close(att) >= 0); att = H5A.open_by_idx(m_v0_test_file, ".", H5.index_t.NAME, H5.iter_order_t.NATIVE, 0); Assert.IsTrue(att >= 0); Assert.IsTrue(H5A.close(att) >= 0); }
public void H5Adelete_by_nameTest2() { Assert.IsFalse( H5A.delete_by_name(Utilities.RandomInvalidHandle(), "A", ".") >= 0); Assert.IsFalse(H5A.delete_by_name(m_v0_test_file, ".", ".") >= 0); }
public static (int success, hid_t CreatedgroupId) WriteStringAttributes(hid_t groupId, string name, IEnumerable <string> strs, string datasetName = null) { hid_t tmpId = groupId; if (!string.IsNullOrWhiteSpace(datasetName)) { hid_t datasetId = H5D.open(groupId, datasetName); if (datasetId > 0) { groupId = datasetId; } } // create UTF-8 encoded attributes hid_t datatype = H5T.create(H5T.class_t.STRING, H5T.VARIABLE); H5T.set_cset(datatype, H5T.cset_t.UTF8); H5T.set_strpad(datatype, H5T.str_t.SPACEPAD); int strSz = strs.Count(); hid_t spaceId = H5S.create_simple(1, new ulong[] { (ulong)strSz }, null); var attributeId = H5A.create(groupId, name, datatype, spaceId); GCHandle[] hnds = new GCHandle[strSz]; IntPtr[] wdata = new IntPtr[strSz]; int cntr = 0; foreach (string str in strs) { hnds[cntr] = GCHandle.Alloc( Encoding.UTF8.GetBytes(str), GCHandleType.Pinned); wdata[cntr] = hnds[cntr].AddrOfPinnedObject(); cntr++; } var hnd = GCHandle.Alloc(wdata, GCHandleType.Pinned); var result = H5A.write(attributeId, datatype, hnd.AddrOfPinnedObject()); hnd.Free(); for (int i = 0; i < strSz; ++i) { hnds[i].Free(); } H5A.close(attributeId); H5S.close(spaceId); H5T.close(datatype); if (tmpId != groupId) { H5D.close(groupId); } return(result, attributeId); }