Exemple #1
0
        public void TestExceptionOnCreateExisting()
        {
            var fn = $"{TestContext.CurrentContext.TestDirectory}\\TestCreateTwice.h5";

            if (File.Exists(fn))
            {
                File.Delete(fn);
            }

            HDF5File f1 = null, f2 = null;
            var      threw = false;

            f1 = new HDF5File(fn, HDF5FileMode.WriteNew);
            try
            {
                f2 = new HDF5File(fn, HDF5FileMode.WriteNew);
            }
            catch (IOException)
            {
                threw = true;
            }

            f1.Close();
            Assert.IsTrue(threw, "Expected an IOException when we tried to create the file the second time round.");
            Assert.IsNull(f2);
        }
Exemple #2
0
        /// <summary>
        /// 在采集结束时才能设置
        /// </summary>
        /// <param name="sampleCount">每通道采样总数</param>
        public void SetAndClose(int sampleCount)
        {
            myHDF5Group.SetAttribute("SampleCount", HDF5AttributeTypes.DOUBLE, sampleCount);

            //关闭所有打开的 HDF5 项目
            foreach (var d in myHDF5Datasets)
            {
                d.Close();
            }
            myHDF5Group.Close();
            myHDF5File.Close();
        }
Exemple #3
0
        /// <summary>
        /// 从文件中读出指定通道的数据片段,支持复杂读取
        /// </summary>
        /// <param name="channelNo">指定的通道,从 0 开始</param>
        /// <param name="start">开始点</param>
        /// <param name="stride">每次向后多少点</param>
        /// <param name="count">读多少次</param>
        /// <param name="block">每次读多少个连续点</param>
        /// <returns></returns>
        public double[] LoadDataFromFileComplex(int channelNo, ulong start, ulong stride, ulong count, ulong block = 1)
        {
            if (!IsParamsRight(channelNo, start, stride, count, block))
            {
                return(null);
            }

            try
            {
                myH5File.Open(dataFilePath);
                myH5Dataset = myH5File.GetDataset("channel" + channelNo.ToString());
                double[] data = (double[])myH5Dataset.ComplexRead1DimChunkDataset(start, stride, count, block);
                myH5Dataset.Close();
                myH5File.Close();

                return(data);
            }
            catch
            {
                throw new Exception("Something wrong with Data Read, may be you can adjust your params and try again.");
            }
        }
Exemple #4
0
        /// <summary>
        /// 依照 BinData 签名的构造函数
        /// </summary>
        /// <param name="dataFileDirectory">HDF5 文件所在文件夹</param>
        /// <param name="name">HDF5 文件名不带后缀</param>
        public DataReader(string dataFileDirectory, string name)
        {
            this.name         = name;
            this.dataFilePath = dataFileDirectory + name + ".hdf5";

            myH5File = new HDF5File();
            myH5File.Open(this.dataFilePath);
            myH5Group = myH5File.GetGroup("Attribute");

            // double 转 object 后,object 不能直接转 int,需要先转 double 再转 int
            double d = (double)myH5Group.GetAttribute("ChannelCount");

            channelCount = (int)d;
            d            = (double)myH5Group.GetAttribute("SampleCount");
            sampleCount  = (int)d;
            sampleRate   = (double)myH5Group.GetAttribute("SampleRate");
            startTime    = (double)myH5Group.GetAttribute("StartTime");
            createTime   = (double)myH5Group.GetAttribute("CreateTime");

            myH5Group.Close();
            myH5File.Close();
        }
Exemple #5
0
 public void TearDown()
 {
     file.Close();
 }
Exemple #6
0
 public void TearDown()
 {
     file.Close();
     File.Delete(FullFilename);
 }