示例#1
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.");
            }
        }
示例#2
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();
        }