public void H5Iget_file_idTest1() { hid_t gid = H5G.create(m_v0_test_file, "A"); Assert.IsTrue(gid > 0); hid_t file = H5I.get_file_id(gid); Assert.IsTrue(file >= 0); Assert.IsTrue(file == m_v0_test_file); Assert.IsTrue(H5G.close(gid) >= 0); gid = H5G.create(m_v2_test_file, "A"); Assert.IsTrue(gid > 0); file = H5I.get_file_id(gid); Assert.IsTrue(file >= 0); Assert.IsTrue(file == m_v2_test_file); Assert.IsTrue(H5G.close(gid) >= 0); }
/// <summary> /// Prepares an attribute. The following use cases exist: /// InitializeAttribute = False: no data is written /// InitializeAttribute = True and DimensionLimitSet < H5S.Unlimited: overwrite attribute data /// InitializeAttribute = True and DimensionLimitSet = H5S.Unlimited: merge attribute data /// </summary> /// <typeparam name="T">The data type of the attribute to be created.</typeparam> /// <param name="locationId">The location ID.</param> /// <param name="name">The name of the attribute.</param> /// <param name="valueSet">The values to be written to the attribute.</param> /// <param name="dimensionLimitSet">The maximum dimensions of the attribute.</param> /// <param name="initializeAttribute">A boolean which indicates if the attribute data shall be untouched, overwritten or merged.</param> /// <param name="callerMemberName">The name of the calling function.</param> public static void PrepareAttribute <T>(long locationId, string name, T[] valueSet, ulong[] dimensionLimitSet, bool initializeAttribute, [CallerMemberName()] string callerMemberName = "") { Contract.Requires(valueSet != null, nameof(valueSet)); long fileId = -1; long typeId = -1; long attributeId = -1; ulong[] dimensionSet; bool isNew; Type elementType; dimensionSet = new ulong[] { 0 }; elementType = typeof(T); try { fileId = H5I.get_file_id(locationId); // create attribute typeId = TypeConversionHelper.GetHdfTypeIdFromType(fileId, elementType); (attributeId, isNew) = IOHelper.OpenOrCreateAttribute(locationId, name, typeId, (ulong)valueSet.LongLength, dimensionLimitSet); // write attribute data (regenerate attribute if necessary) if (initializeAttribute) { ulong[] oldValueSetCount; if (!isNew && callerMemberName != nameof(IOHelper.PrepareAttribute)) { oldValueSetCount = IOHelper.PrepareAttributeValueSet(attributeId, ref valueSet, false); } else { oldValueSetCount = new ulong[1] { (ulong)valueSet.Count() }; } if (valueSet.Count() == (int)oldValueSetCount[0]) { IOHelper.Write(attributeId, valueSet, DataContainerType.Attribute); } else { H5A.close(attributeId); H5A.delete(locationId, name); IOHelper.PrepareAttribute(locationId, name, valueSet, dimensionLimitSet, true); } } } finally { if (H5I.is_valid(attributeId) > 0) { H5A.close(attributeId); } if (H5I.is_valid(typeId) > 0) { H5T.close(typeId); } if (H5I.is_valid(fileId) > 0) { H5F.close(fileId); } } }
public void H5Iget_file_idTest2() { Assert.IsFalse( H5I.get_file_id(Utilities.RandomInvalidHandle()) >= 0); }