예제 #1
0
        public static unsafe void AddDataWithSharedDataType(long fileId, ContainerType container)
        {
            long typeId = H5T.copy(H5T.C_S1);

            H5T.set_size(typeId, H5T.VARIABLE);
            H5T.set_cset(typeId, H5T.cset_t.UTF8);
            H5T.commit(fileId, "string_t", typeId);

            var data     = new string[] { "001", "11", "22", "33", "44", "55", "66", "77", "  ", "AA", "ZZ", "!!" };
            var dataChar = data
                           .SelectMany(value => Encoding.ASCII.GetBytes(value + '\0'))
                           .ToArray();

            fixed(byte *dataVarPtr = dataChar)
            {
                var basePtr = new IntPtr(dataVarPtr);

                var addresses = new IntPtr[]
                {
                    IntPtr.Add(basePtr, 0), IntPtr.Add(basePtr, 4), IntPtr.Add(basePtr, 7), IntPtr.Add(basePtr, 10),
                    IntPtr.Add(basePtr, 13), IntPtr.Add(basePtr, 16), IntPtr.Add(basePtr, 19), IntPtr.Add(basePtr, 22),
                    IntPtr.Add(basePtr, 25), IntPtr.Add(basePtr, 28), IntPtr.Add(basePtr, 31), IntPtr.Add(basePtr, 34)
                };

                fixed(void *dataVarAddressesPtr = addresses)
                {
                    TestUtils.Add(container, fileId, "shared_data_type", "shared_data_type", typeId, dataVarAddressesPtr, length: 12);
                }
            }

            if (H5I.is_valid(typeId) > 0)
            {
                H5T.close(typeId);
            }
        }
예제 #2
0
        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;
            }));
        }
예제 #3
0
 protected override void CloseId(long id)
 {
     if (H5I.is_valid(id) > 0)
     {
         H5D.close(id);
     }
 }
예제 #4
0
        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);
                    }
                }
            }
        }
예제 #5
0
        /// <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);
        }
예제 #6
0
        public void H5Iget_nameTest2()
        {
            IntPtr size = H5I.get_name(Utilities.RandomInvalidHandle(), null,
                                       IntPtr.Zero);

            Assert.IsFalse(size.ToInt32() >= 0);
        }
예제 #7
0
        public void H5Iget_nameTest1()
        {
            hid_t gid = H5G.create(m_v0_test_file, "AAAAAAAAAAAAAAAAAAAAA");

            Assert.IsTrue(gid > 0);

            ssize_t buf_size = H5I.get_name(gid, (StringBuilder)null,
                                            IntPtr.Zero) + 1;

            Assert.IsTrue(buf_size.ToInt32() > 1);
            StringBuilder nameBuilder = new StringBuilder(buf_size.ToInt32());
            IntPtr        size        = H5I.get_name(gid, nameBuilder, buf_size);

            Assert.IsTrue(size.ToInt32() > 0);
            Assert.IsTrue(nameBuilder.ToString() == "/AAAAAAAAAAAAAAAAAAAAA");

            Assert.IsTrue(H5G.close(gid) >= 0);

            gid = H5G.create(m_v2_test_file, "AAAAAAAAAAAAAAAAAAAAA");
            Assert.IsTrue(gid > 0);

            buf_size = H5I.get_name(gid, (StringBuilder)null, IntPtr.Zero) + 1;
            Assert.IsTrue(buf_size.ToInt32() > 1);
            nameBuilder = new StringBuilder(buf_size.ToInt32());
            size        = H5I.get_name(gid, nameBuilder, buf_size);
            Assert.IsTrue(size.ToInt32() > 0);
            Assert.IsTrue(nameBuilder.ToString() == "/AAAAAAAAAAAAAAAAAAAAA");

            Assert.IsTrue(H5G.close(gid) >= 0);
        }
예제 #8
0
        protected override void FreeUnmanagedResources()
        {
            base.FreeUnmanagedResources();

            if (H5I.is_valid(_fileId) > 0)
            {
                this.CloseHdfFile(_fileId);
            }
        }
예제 #9
0
        private void Menu_2()
        {
            long vdsFileId     = -1;
            long vdsMetaFileId = -1;
            long fcPropertyId  = -1;

            string vdsFilePath;
            string vdsMetaFilePath;

            List <CampaignInfo>    campaignInfoSet;
            IList <HdfElementBase> currentList;

            //
            vdsFilePath     = Path.Combine(Program.BaseDirectoryPath, "VDS.h5");
            vdsMetaFilePath = Path.Combine(Program.BaseDirectoryPath, "VDS_META.h5");

            try
            {
                if (File.Exists(vdsFilePath))
                {
                    vdsFileId = H5F.open(vdsFilePath, H5F.ACC_RDONLY);
                }
                else
                {
                    return;
                }

                if (File.Exists(vdsMetaFilePath))
                {
                    vdsMetaFileId = H5F.open(vdsMetaFilePath, H5F.ACC_RDWR);
                }

                if (vdsMetaFileId == -1)
                {
                    fcPropertyId = H5P.create(H5P.FILE_CREATE);
                    H5P.set_file_space(fcPropertyId, H5F.file_space_type_t.ALL_PERSIST);
                    vdsMetaFileId = H5F.create(vdsMetaFilePath, H5F.ACC_TRUNC, fcPropertyId);
                }

                campaignInfoSet = GeneralHelper.GetCampaignInfoSet(vdsFileId, true);
                currentList     = campaignInfoSet.Cast <HdfElementBase>().ToList();

                new VdsMetaNavigator(vdsFileId, vdsMetaFileId, "/", currentList);
            }
            finally
            {
                if (H5I.is_valid(vdsFileId) > 0)
                {
                    H5F.close(vdsFileId);
                }
                if (H5I.is_valid(vdsMetaFileId) > 0)
                {
                    H5F.close(vdsMetaFileId);
                }
            }
        }
예제 #10
0
        private void UpdateVariableInfo(FileContext fileContext, long variableGroupId)
        {
            ulong idx;

            idx = 0;

            _variableGroupSet = IOHelper.UpdateAttributeList(variableGroupId, "group_set", _variableGroupSet.ToArray()).ToList();

            if (fileContext.FormatVersion != 1)
            {
                _unitSet             = IOHelper.UpdateAttributeList(variableGroupId, "unit_set", _unitSet.ToArray()).ToList();
                _transferFunctionSet = IOHelper.UpdateAttributeList(variableGroupId, "transfer_function_set", _transferFunctionSet.ToArray()).ToList();
            }

            H5L.iterate(variableGroupId, H5.index_t.NAME, H5.iter_order_t.INC, ref idx, Callback, IntPtr.Zero);

            int Callback(long variableGroupId2, IntPtr intPtrName, ref H5L.info_t info, IntPtr userDataPtr)
            {
                long   datasetId           = -1;
                long   typeId_do_not_close = -1;
                string name;

                DatasetInfo currentDatasetInfo;

                try
                {
                    name = Marshal.PtrToStringAnsi(intPtrName);

                    if (H5L.exists(variableGroupId2, name) > 0)
                    {
                        datasetId = H5D.open(variableGroupId2, name);

                        currentDatasetInfo = _datasetInfoSet.FirstOrDefault(datasetInfo => datasetInfo.Name == name);

                        if (currentDatasetInfo == null)
                        {
                            typeId_do_not_close = H5D.get_type(datasetId);
                            currentDatasetInfo  = new DatasetInfo(name, typeId_do_not_close, this, this.IsLazyLoading);

                            _datasetInfoSet.Add(currentDatasetInfo);
                        }

                        currentDatasetInfo.Update(fileContext);
                    }
                }
                finally
                {
                    if (H5I.is_valid(datasetId) > 0)
                    {
                        H5D.close(datasetId);
                    }
                }

                return(0);
            }
        }
예제 #11
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);
        }
예제 #12
0
        public static (long DatasetId, bool IsNew) OpenOrCreateDataset(long locationId, string datasetPath, long datasetTypeId, ulong chunkLength, ulong chunkCount, IntPtr fillValue = default)
        {
            return(IOHelper.OpenOrCreateDataset(locationId, datasetPath, datasetTypeId, () =>
            {
                long dcPropertyId = -1;
                long lcPropertyId = -1;
                long dataspaceId = -1;
                long datasetId = -1;

                try
                {
                    dcPropertyId = H5P.create(H5P.DATASET_CREATE);

                    if (fillValue != IntPtr.Zero)
                    {
                        H5P.set_fill_value(dcPropertyId, datasetTypeId, fillValue);
                    }

                    H5P.set_shuffle(dcPropertyId);
                    H5P.set_deflate(dcPropertyId, 7);
                    H5P.set_chunk(dcPropertyId, 1, new ulong[] { chunkLength });

                    lcPropertyId = H5P.create(H5P.LINK_CREATE);
                    H5P.set_create_intermediate_group(lcPropertyId, 1);

                    dataspaceId = H5S.create_simple(1, new ulong[] { chunkLength *chunkCount }, null);
                    datasetId = H5D.create(locationId, datasetPath, datasetTypeId, dataspaceId, lcPropertyId, dcPropertyId);

                    if (H5I.is_valid(datasetId) <= 0)
                    {
                        throw new Exception($"{ ErrorMessage.IOHelper_CouldNotOpenOrCreateDataset } Dataset: '{ datasetPath }'.");
                    }
                }
                finally
                {
                    if (H5I.is_valid(dcPropertyId) > 0)
                    {
                        H5P.close(dcPropertyId);
                    }
                    if (H5I.is_valid(lcPropertyId) > 0)
                    {
                        H5P.close(lcPropertyId);
                    }
                    if (H5I.is_valid(dataspaceId) > 0)
                    {
                        H5S.close(dataspaceId);
                    }
                }

                return datasetId;
            }));
        }
예제 #13
0
        private ISimpleDataStorage LoadDataset(long sourceFileId, string datasetPath, ulong start, ulong stride, ulong block, ulong count)
        {
            long datasetId = -1;
            long typeId    = -1;

            Array dataset;
            Array dataset_status;

            Type genericType;

            ExtendedDataStorageBase extendedDataStorage;
            ISimpleDataStorage      simpleDataStorage;

            dataset = IOHelper.ReadDataset(sourceFileId, datasetPath, start, stride, block, count);

            // apply status (only if native dataset)
            if (H5L.exists(sourceFileId, datasetPath + "_status") > 0)
            {
                try
                {
                    datasetId = H5D.open(sourceFileId, datasetPath);
                    typeId    = H5D.get_type(datasetId);

                    dataset_status = IOHelper.ReadDataset(sourceFileId, datasetPath + "_status", start, stride, block, count).Cast <byte>().ToArray();

                    genericType         = typeof(ExtendedDataStorage <>).MakeGenericType(TypeConversionHelper.GetTypeFromHdfTypeId(typeId));
                    extendedDataStorage = (ExtendedDataStorageBase)Activator.CreateInstance(genericType, dataset, dataset_status);

                    dataset_status = null;
                }
                finally
                {
                    if (H5I.is_valid(datasetId) > 0)
                    {
                        H5D.close(datasetId);
                    }
                    if (H5I.is_valid(typeId) > 0)
                    {
                        H5T.close(typeId);
                    }
                }

                simpleDataStorage = extendedDataStorage.ToSimpleDataStorage();
                extendedDataStorage.Dispose();

                return(simpleDataStorage);
            }
            else
            {
                return(new SimpleDataStorage(dataset.Cast <double>().ToArray()));
            }
        }
예제 #14
0
        public void H5Idec_refTest1()
        {
            hid_t gid = H5G.create(m_v0_test_file, "A");

            Assert.IsTrue(gid > 0);
            Assert.IsTrue(H5I.dec_ref(gid) >= 0);
            Assert.IsFalse(H5G.close(gid) >= 0);

            gid = H5G.create(m_v2_test_file, "A");
            Assert.IsTrue(gid > 0);
            Assert.IsTrue(H5I.dec_ref(gid) >= 0);
            Assert.IsFalse(H5G.close(gid) >= 0);
        }
예제 #15
0
        private void UpdateCampaignInfo(FileContext fileContext, long campaignGroupId)
        {
            ulong idx;

            idx = 0;

            _chunkDatasetInfo.Update(fileContext);

            GeneralHelper.SuppressErrors(() => H5L.iterate(campaignGroupId, H5.index_t.NAME, H5.iter_order_t.INC, ref idx, Callback, IntPtr.Zero));

            int Callback(long campaignGroupId2, IntPtr intPtrName, ref H5L.info_t info, IntPtr userDataPtr)
            {
                long   groupId = -1;
                string name;

                VariableInfo currentVariableInfo;

                try
                {
                    name = Marshal.PtrToStringAnsi(intPtrName);

                    // this is necessary, since H5Oget_info_by_name is slow because it wants verbose object header data
                    // and H5G_loc_info is not directly accessible
                    // only chance is to modify source code (H5Oget_info_by_name)
                    groupId = H5G.open(campaignGroupId2, name);

                    if (groupId > -1)
                    {
                        currentVariableInfo = _variableInfoSet.FirstOrDefault(variableInfo => variableInfo.Name == name);

                        if (currentVariableInfo == null)
                        {
                            currentVariableInfo = new VariableInfo(name, this, this.IsLazyLoading);
                            _variableInfoSet.Add(currentVariableInfo);
                        }

                        currentVariableInfo.Update(fileContext);
                    }
                }
                finally
                {
                    if (H5I.is_valid(groupId) > 0)
                    {
                        H5G.close(groupId);
                    }
                }

                return(0);
            }
        }
예제 #16
0
        public void H5Iis_validTest1()
        {
            hid_t gid = H5G.create(m_v0_test_file, "A");

            Assert.IsTrue(gid > 0);
            Assert.IsTrue(H5I.is_valid(gid) > 0);
            Assert.IsTrue(H5G.close(gid) >= 0);
            Assert.IsTrue(H5I.is_valid(gid) == 0);

            gid = H5G.create(m_v2_test_file, "A");
            Assert.IsTrue(gid > 0);
            Assert.IsTrue(H5I.is_valid(gid) > 0);
            Assert.IsTrue(H5G.close(gid) >= 0);
            Assert.IsTrue(H5I.is_valid(gid) == 0);
        }
예제 #17
0
        public void H5Iget_typeTest1()
        {
            Assert.IsTrue(H5I.get_type(m_v0_class_file) == H5I.type_t.FILE);
            hid_t gid = H5G.create(m_v0_test_file, "A");

            Assert.IsTrue(gid > 0);
            Assert.IsTrue(H5I.get_type(gid) == H5I.type_t.GROUP);
            Assert.IsTrue(H5G.close(gid) >= 0);

            Assert.IsTrue(H5I.get_type(m_v2_class_file) == H5I.type_t.FILE);
            gid = H5G.create(m_v2_test_file, "A");
            Assert.IsTrue(gid > 0);
            Assert.IsTrue(H5I.get_type(gid) == H5I.type_t.GROUP);
            Assert.IsTrue(H5G.close(gid) >= 0);
        }
예제 #18
0
        public static ulong[] PrepareAttributeValueSet <T>(long attributeId, ref T[] valueSet, bool isReference)
        {
            long dataspaceId = -1;

            ulong[] dimensionSet;
            ulong[] dimensionLimitSet;

            dimensionSet      = new ulong[] { 0 };
            dimensionLimitSet = new ulong[] { 0 };

            try
            {
                dataspaceId = H5A.get_space(attributeId);

                H5S.get_simple_extent_dims(dataspaceId, null, dimensionLimitSet);

                // merge data
                if (dimensionLimitSet[0] == H5S.UNLIMITED)
                {
                    T[] valueSet_File = IOHelper.Read <T>(attributeId, DataContainerType.Attribute);

                    if (isReference)
                    {
                        if (valueSet_File.Count() == 0 || !Enumerable.SequenceEqual(valueSet_File, valueSet.Skip(Math.Max(0, valueSet.Count() - valueSet_File.Count()))))
                        {
                            valueSet = valueSet.Concat(valueSet_File).ToArray();
                        }
                    }
                    else
                    {
                        if (valueSet.Count() == 0 || !Enumerable.SequenceEqual(valueSet, valueSet_File.Skip(Math.Max(0, valueSet_File.Count() - valueSet.Count()))))
                        {
                            valueSet = valueSet_File.Concat(valueSet).ToArray();
                        }
                    }
                }
            }
            finally
            {
                if (H5I.is_valid(dataspaceId) > 0)
                {
                    H5S.close(dataspaceId);
                }
            }

            return(dimensionLimitSet);
        }
예제 #19
0
        public static T[] ReadDataset <T>(long locationId, string datasetPath, ulong start = 0, ulong stride = 0, ulong block = 0, ulong count = 0)
        {
            long datasetId   = -1;
            long dataspaceId = -1;

            T[] result;

            try
            {
                datasetId = H5D.open(locationId, datasetPath);

                if (H5I.is_valid(datasetId) <= 0)
                {
                    throw new Exception(ErrorMessage.IOHelper_CouldNotOpenDataset);
                }

                if (start == 0 && stride == 0 && block == 0 && count == 0)
                {
                    result = IOHelper.Read <T>(datasetId, DataContainerType.Dataset);
                }
                else
                {
                    dataspaceId = H5D.get_space(datasetId);

                    if (H5S.select_hyperslab(dataspaceId, H5S.seloper_t.SET, new ulong[] { start }, new ulong[] { stride }, new ulong[] { block }, new ulong[] { count }) < 0)
                    {
                        throw new Exception(ErrorMessage.IOHelper_CouldNotSelectHyperslab);
                    }

                    result = IOHelper.Read <T>(datasetId, DataContainerType.Dataset, dataspaceId);
                }
            }
            finally
            {
                if (H5I.is_valid(dataspaceId) > 0)
                {
                    H5S.close(dataspaceId);
                }
                if (H5I.is_valid(datasetId) > 0)
                {
                    H5D.close(datasetId);
                }
            }

            return(result);
        }
예제 #20
0
        public static (long DatasetId, bool IsNew) OpenOrCreateDataset(long locationId, string datasetPath, long datasetTypeId, Func <long> createDatasetCallback)
        {
            Contract.Requires(createDatasetCallback != null);

            long datasetId            = -1;
            long datasetTypeId_actual = -1;

            bool isNew;

            try
            {
                if (IOHelper.CheckLinkExists(locationId, datasetPath))
                {
                    datasetId            = H5D.open(locationId, datasetPath);
                    datasetTypeId_actual = H5D.get_type(datasetId);

                    if (H5T.equal(datasetTypeId_actual, datasetTypeId) <= 0)
                    {
                        throw new Exception($"{ ErrorMessage.IOHelper_DataTypeMismatch } Dataset: '{ datasetPath }'.");
                    }

                    isNew = false;
                }
                else
                {
                    datasetId = createDatasetCallback.Invoke();

                    isNew = true;
                }

                if (H5I.is_valid(datasetId) <= 0)
                {
                    throw new Exception($"{ ErrorMessage.IOHelper_CouldNotOpenOrCreateDataset } Dataset: '{ datasetPath }'.");
                }
            }
            finally
            {
                if (H5I.is_valid(datasetTypeId_actual) > 0)
                {
                    H5T.close(datasetTypeId_actual);
                }
            }

            return(datasetId, isNew);
        }
예제 #21
0
        public static T[] UpdateAttributeList <T>(long locationId, string attributeName, T[] referenceValueSet)
        {
            long attributeId = -1;

            try
            {
                attributeId = H5A.open(locationId, attributeName);
                IOHelper.PrepareAttributeValueSet(attributeId, ref referenceValueSet, true);
            }
            finally
            {
                if (H5I.is_valid(attributeId) > 0)
                {
                    H5A.close(attributeId);
                }
            }

            return(referenceValueSet);
        }
예제 #22
0
        /// <summary>
        /// Writes data to 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>
        /// <param name="valueSet">The data to be written.</param>
        public static void WriteAttribute <T>(long locationId, string attributeName, T[] valueSet)
        {
            Contract.Requires(valueSet != null, nameof(valueSet));

            long attributeId = -1;

            try
            {
                attributeId = H5A.open(locationId, attributeName);
                IOHelper.Write <T>(attributeId, valueSet, DataContainerType.Attribute);
            }
            finally
            {
                if (H5I.is_valid(attributeId) > 0)
                {
                    H5A.close(attributeId);
                }
            }
        }
예제 #23
0
        public static void WriteDataset <T>(long locationId, string datasetName, T[] valueSet)
        {
            Contract.Requires(valueSet != null, nameof(valueSet));

            long datasetId = -1;

            try
            {
                datasetId = H5D.open(locationId, datasetName);
                IOHelper.Write <T>(datasetId, valueSet, DataContainerType.Dataset);
            }
            finally
            {
                if (H5I.is_valid(datasetId) > 0)
                {
                    H5D.close(datasetId);
                }
            }
        }
예제 #24
0
        public static (long AttributeId, bool IsNew) OpenOrCreateAttribute(long locationId, string name, long attributeTypeId, Func <long> createAttributeCallback)
        {
            long attributeId            = -1;
            long attributeTypeId_actual = -1;

            bool isNew;

            try
            {
                if (H5A.exists(locationId, name) > 0)
                {
                    attributeId            = H5A.open(locationId, name);
                    attributeTypeId_actual = H5A.get_type(attributeId);

                    if (H5T.equal(attributeTypeId_actual, attributeTypeId) <= 0)
                    {
                        throw new Exception($"{ ErrorMessage.IOHelper_DataTypeMismatch } Attribute: '{ name }'.");
                    }

                    isNew = false;
                }
                else
                {
                    attributeId = createAttributeCallback.Invoke();

                    isNew = true;
                }

                if (H5I.is_valid(attributeId) <= 0)
                {
                    throw new Exception($"{ ErrorMessage.IOHelper_CouldNotOpenOrCreateAttribute } Attribute: '{ name }'.");
                }
            }
            finally
            {
                if (H5I.is_valid(attributeTypeId_actual) > 0)
                {
                    H5T.close(attributeTypeId_actual);
                }
            }

            return(attributeId, isNew);
        }
예제 #25
0
        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);
        }
예제 #26
0
        public static object ReadAttribute(long locationId, string attributeName)
        {
            long attributeId = -1;
            long typeId      = -1;

            object result;

            try
            {
                attributeId = H5A.open(locationId, attributeName);

                if (H5I.is_valid(attributeId) <= 0)
                {
                    throw new Exception(ErrorMessage.IOHelper_CouldNotOpenAttribute);
                }

                typeId = H5A.get_type(attributeId);

                // invoke HdfHelper.Read
                result = GeneralHelper.InvokeGenericMethod(typeof(IOHelper), null, nameof(IOHelper.Read),
                                                           BindingFlags.Public | BindingFlags.Static,
                                                           TypeConversionHelper.GetTypeFromHdfTypeId(typeId),
                                                           new object[] { attributeId, DataContainerType.Attribute, Type.Missing });
            }
            finally
            {
                if (H5I.is_valid(typeId) > 0)
                {
                    H5T.close(typeId);
                }
                if (H5I.is_valid(attributeId) > 0)
                {
                    H5A.close(attributeId);
                }
            }

            return(result);
        }
예제 #27
0
        protected override void OnWrite(ChannelContextGroup contextGroup, ulong fileOffset, ulong bufferOffset, ulong length)
        {
            long groupId = -1;

            try
            {
                var firstChunk = (long)this.ToChunkIndex(fileOffset, contextGroup.SampleRate);
                var lastChunk  = (long)this.ToChunkIndex(fileOffset + length, contextGroup.SampleRate) - 1;

                groupId = H5G.open(_fileId, $"/info");

                _lastCompletedChunk = IOHelper.ReadDataset <double>(groupId, "last_completed_chunk").FirstOrDefault();

                // this does not work in conjunction with multiple context groups
                if (firstChunk <= _lastCompletedChunk)
                {
                    // throw new Exception(ErrorMessage.Mat73Writer_ChunkAlreadyWritten);
                }

                // write data
                for (int i = 0; i < contextGroup.ChannelContextSet.Count(); i++)
                {
                    this.WriteData(fileOffset, bufferOffset, length, contextGroup.ChannelContextSet[i]);
                }

                // write last_completed_chunk
                IOHelper.WriteDataset(groupId, "last_completed_chunk", new double[] { lastChunk });
            }
            finally
            {
                if (H5I.is_valid(groupId) > 0)
                {
                    H5G.close(groupId);
                }

                H5F.flush(_fileId, H5F.scope_t.GLOBAL);
            }
        }
예제 #28
0
        private void UpdateDatasetInfo(FileContext fileContext, long datasetId)
        {
            long dataspaceId = -1;

            ulong[] actualDimenionSet   = new ulong[1];
            ulong[] maximumDimensionSet = new ulong[1];

            try
            {
                dataspaceId = H5D.get_space(datasetId);

                H5S.get_simple_extent_dims(dataspaceId, actualDimenionSet, maximumDimensionSet);

                _sourceFileInfoSet.Add(new SourceFileInfo(fileContext.FilePath, actualDimenionSet.First(), fileContext.DateTime));
            }
            finally
            {
                if (H5I.is_valid(dataspaceId) > 0)
                {
                    H5S.close(dataspaceId);
                }
            }
        }
예제 #29
0
        public static (long GroupId, bool IsNew) OpenOrCreateGroup(long locationId, string groupPath)
        {
            long groupId    = -1;
            long propertyId = -1;

            bool isNew;

            try
            {
                if (IOHelper.CheckLinkExists(locationId, groupPath))
                {
                    groupId = H5G.open(locationId, groupPath);
                    isNew   = false;
                }
                else
                {
                    propertyId = H5P.create(H5P.LINK_CREATE);
                    H5P.set_create_intermediate_group(propertyId, 1);
                    groupId = H5G.create(locationId, groupPath, propertyId);
                    isNew   = true;
                }

                if (H5I.is_valid(groupId) <= 0)
                {
                    throw new Exception($"{ ErrorMessage.IOHelper_CouldNotOpenOrCreateGroup } Group name: '{ groupPath }'.");
                }
            }
            finally
            {
                if (H5I.is_valid(propertyId) > 0)
                {
                    H5P.close(propertyId);
                }
            }

            return(groupId, isNew);
        }
예제 #30
0
        protected override bool OnWaitForUserInput()
        {
            if (this.SelectedIndex < 0)
            {
                this.SelectedIndex = _vdsMetaAggregateFunctionSet.Count() > 0 ? 0 : -1;
            }
            else if (this.SelectedIndex >= _vdsMetaAggregateFunctionSet.Count())
            {
                this.SelectedIndex = _vdsMetaAggregateFunctionSet.Count() - 1;
            }

            if (this.LastIndex >= 0)
            {
                Console.SetCursorPosition(1, this.LastIndex);
                Console.Write(" ");
            }

            if (this.SelectedIndex >= 0)
            {
                Console.SetCursorPosition(1, this.SelectedIndex + 2);
                Console.Write("x");
            }

            _consoleKeyInfo = Console.ReadKey(true);

            switch (_consoleKeyInfo.Key)
            {
            case ConsoleKey.UpArrow:

                if (this.SelectedIndex > 0)
                {
                    this.LastIndex      = Console.CursorTop;
                    this.SelectedIndex -= 1;
                }

                break;

            case ConsoleKey.DownArrow:

                if (this.SelectedIndex < _vdsMetaAggregateFunctionSet.Count() - 1)
                {
                    this.LastIndex      = Console.CursorTop;
                    this.SelectedIndex += 1;
                }

                break;

            case ConsoleKey.Enter:
            case ConsoleKey.RightArrow:

                if (this.SelectedIndex >= 0)
                {
                    _vdsMetaAggregateFunctionSet[this.SelectedIndex] = Program.PromptAggregateFunctionData(_vdsMetaAggregateFunctionSet[this.SelectedIndex]);
                    _updateAttribute = true;
                }

                break;

            case ConsoleKey.N:

                _vdsMetaAggregateFunctionSet.Add(Program.PromptAggregateFunctionData(new hdf_aggregate_function_t()));

                this.SelectedIndex = _vdsMetaAggregateFunctionSet.Count();
                _updateAttribute   = true;

                break;

            case ConsoleKey.C:

                if (this.SelectedIndex >= 0)
                {
                    _vdsMetaAggregateFunctionSet.Add(_vdsMetaAggregateFunctionSet[this.SelectedIndex]);
                    this.SelectedIndex = _vdsMetaAggregateFunctionSet.Count();
                    this.OnRedraw();
                }

                break;

            case ConsoleKey.D:

                _vdsMetaAggregateFunctionSet.Add(new hdf_aggregate_function_t("mean", "none"));
                _vdsMetaAggregateFunctionSet.Add(new hdf_aggregate_function_t("min", "none"));
                _vdsMetaAggregateFunctionSet.Add(new hdf_aggregate_function_t("max", "none"));
                _vdsMetaAggregateFunctionSet.Add(new hdf_aggregate_function_t("std", "none"));
                _updateAttribute = true;
                this.OnRedraw();

                break;

            case ConsoleKey.Delete:

                if (this.SelectedIndex >= 0)
                {
                    Console.Clear();
                    Console.Write("The selected item will be deleted. Proceed (Y/N)? ");

                    if (Console.ReadKey().Key == ConsoleKey.Y)
                    {
                        _vdsMetaAggregateFunctionSet.RemoveAt(this.SelectedIndex);
                        _updateAttribute = true;
                    }

                    this.OnRedraw();
                }

                break;

            case ConsoleKey.PageUp:

                if (this.SelectedIndex >= 1 && this.SelectedIndex < _vdsMetaAggregateFunctionSet.Count())
                {
                    hdf_aggregate_function_t hdf_aggregate_function = _vdsMetaAggregateFunctionSet[this.SelectedIndex];
                    _vdsMetaAggregateFunctionSet.RemoveAt(this.SelectedIndex);
                    _vdsMetaAggregateFunctionSet.Insert(this.SelectedIndex - 1, hdf_aggregate_function);
                    this.SelectedIndex -= 1;
                    _updateAttribute    = true;
                }

                break;

            case ConsoleKey.PageDown:

                if (this.SelectedIndex >= 0 && this.SelectedIndex < _vdsMetaAggregateFunctionSet.Count() - 1)
                {
                    hdf_aggregate_function_t hdf_aggregate_function = _vdsMetaAggregateFunctionSet[this.SelectedIndex];
                    _vdsMetaAggregateFunctionSet.RemoveAt(this.SelectedIndex);
                    _vdsMetaAggregateFunctionSet.Insert(this.SelectedIndex + 1, hdf_aggregate_function);
                    this.SelectedIndex += 1;
                    _updateAttribute    = true;
                }

                break;

            case ConsoleKey.Escape:
            case ConsoleKey.LeftArrow:
                return(true);
            }

            // update attribute
            if (_updateAttribute)
            {
                _groupId = IOHelper.OpenOrCreateGroup(_vdsMetaFileId, _currentPath).GroupId;
                IOHelper.PrepareAttribute(_groupId, "aggregate_function_set", _vdsMetaAggregateFunctionSet.ToArray(), new ulong[] { (ulong)_vdsMetaAggregateFunctionSet.Count() }, true);
                _updateAttribute = false;
                this.OnRedraw();
            }

            // clean up
            if (H5I.is_valid(_groupId) > 0)
            {
                H5F.flush(_groupId, H5F.scope_t.GLOBAL);
                H5G.close(_groupId);
            }

            return(false);
        }