Exemplo n.º 1
0
        /// <summary>
        /// 读取分析文件
        /// </summary>
        /// <param name="fileAddr"></param>
        public void readAnalysisFileForAll(string fileAddr, List <FreqNavBar> freqnavbarList)
        {
            Dictionary <double, FreqStatModel> dicFreqStatModel = new Dictionary <double, FreqStatModel>();
            StreamReader read = new StreamReader(fileAddr);
            string       str;

            while (read.Peek() != -1)
            {
                str = read.ReadLine();
                FreqStatModel freqStatModel = new FreqStatModel();
                freqStatModel.DicAmplitudeCount = new Dictionary <int, int>();
                string[] arrFreqStat = str.TrimEnd(' ').Split(' ');
                freqStatModel.AmplitudeValue = Convert.ToDouble(arrFreqStat[0]);
                for (int i = 1; i < arrFreqStat.Length; i += 2)
                {
                    freqStatModel.DicAmplitudeCount.Add(Convert.ToInt32(arrFreqStat[i]), Convert.ToInt32(arrFreqStat[i + 1]));
                }
                dicFreqStatModel.Add(Convert.ToDouble(arrFreqStat[0]), freqStatModel);
                //temp
            }
            read.Close();
            foreach (var fnr in freqnavbarList)
            {
                Dictionary <double, FreqStatModel> dictionaryAsc = dicFreqStatModel.Where(x => x.Key >= Convert.ToDouble(fnr.FreqStart) * 1000 && x.Key <= Convert.ToDouble(fnr.FreqStop) * 1000).ToDictionary(o => o.Key, p => p.Value);
                ctrlStatDataForAll(dictionaryAsc, fnr);
            }
        }
Exemplo n.º 2
0
        //private void getFileNames()
        //{
        //    fileNameList = new ArrayList();
        //    CollectionDataSave cds = new CollectionDataSave();
        //    cds.openSQLiteConnection();
        //    fileNameList = cds.getFileNames();
        //}

        /// <summary>
        /// 读取原始文件进行分析
        /// </summary>
        private void readFileData()
        {
            Dictionary <double, FreqStatModel> temp = new Dictionary <double, FreqStatModel>();
            FreqStatModel freqStatModel             = null;

            for (int i = 0; i < fileNameList.Count; i++)
            {
                FreqCollectionIndex fci = (FreqCollectionIndex)fileNameList[i];
                double frequency        = fci.StartFreq;
                double step             = fci.FreqStep / 1000;
                using (FileStream fsRead = new FileStream(@fci.FileAddr, FileMode.Open))
                {
                    //long fsLen = (long)fsRead.Length;
                    //byte[] heByte = new byte[fsLen];
                    //int r = fsRead.Read(heByte, 0, heByte.Length);
                    //float[] targetData = new float[r / 4];
                    int countTemp = 0;
                    for (int k = 0; k < fsRead.Length; k += 4)
                    {
                        byte[] heBytetemp = new byte[4];
                        fsRead.Read(heBytetemp, 0, 4);
                        float targetData = BitConverter.ToSingle(heBytetemp, 0);
                        if (countTemp == freqCount)
                        {
                            countTemp = 0;
                            frequency = fci.StartFreq;
                        }
                        if (targetData + 107 < -20 || targetData + 107 > 100)
                        {
                            frequency += step;
                            countTemp++;
                            continue;
                        }
                        int AmplitudeValue = Convert.ToInt32(targetData) + 107;
                        if (!temp.ContainsKey(frequency))
                        {
                            //if (freqStatModel.DicAmplitudeCount != null)
                            //{
                            //    freqStatModel.DicAmplitudeCount.Clear();
                            //}
                            freqStatModel = new FreqStatModel();
                            freqStatModel.AmplitudeValue    = frequency;
                            freqStatModel.DicAmplitudeCount = new Dictionary <int, int>();
                            freqStatModel.DicAmplitudeCount.Add(AmplitudeValue, 1);
                            temp.Add(frequency, freqStatModel);
                        }
                        else
                        {
                            //freqStatModel = null;
                            freqStatModel = temp[frequency];
                            if (freqStatModel.DicAmplitudeCount.ContainsKey(AmplitudeValue))
                            {
                                freqStatModel.DicAmplitudeCount[AmplitudeValue] = freqStatModel.DicAmplitudeCount[AmplitudeValue] + 1;
                            }
                            else
                            {
                                freqStatModel.DicAmplitudeCount.Add(AmplitudeValue, 1);
                            }
                        }
                        frequency += step;
                        countTemp++;
                    }
                    //if (DataConvert(heByte, ref targetData))
                    //{
                    //    heByte = null;
                    //    for (int j = 0; j < targetData.Length; j++)
                    //    {
                    //        if (frequency > fci.EndFreq)
                    //        {
                    //            frequency = fci.StartFreq;
                    //        }
                    //        if (targetData[j] + 107 < -20 || targetData[j] + 107 > 100)
                    //        {
                    //            frequency += 25;
                    //            continue;
                    //        }
                    //        string AmplitudeValue = (Convert.ToInt32(targetData[j]) + 107).ToString();
                    //        if (!temp.ContainsKey(frequency))
                    //        {
                    //            //if (freqStatModel.DicAmplitudeCount != null)
                    //            //{
                    //            //    freqStatModel.DicAmplitudeCount.Clear();
                    //            //}
                    //            freqStatModel = new FreqStatModel();
                    //            freqStatModel.AmplitudeValue = frequency;
                    //            freqStatModel.DicAmplitudeCount = new Dictionary<string, int>();
                    //            freqStatModel.DicAmplitudeCount.Add(AmplitudeValue, 1);
                    //            temp.Add(frequency, freqStatModel);
                    //        }
                    //        else
                    //        {
                    //            freqStatModel = null;
                    //            freqStatModel = temp[frequency];
                    //            if (freqStatModel.DicAmplitudeCount.ContainsKey(AmplitudeValue))
                    //            {
                    //                freqStatModel.DicAmplitudeCount[AmplitudeValue] = freqStatModel.DicAmplitudeCount[AmplitudeValue] + 1;
                    //            }
                    //            else
                    //            {
                    //                freqStatModel.DicAmplitudeCount.Add(AmplitudeValue, 1);
                    //            }
                    //        }
                    //        frequency += 25;
                    //    }
                    //    targetData = null;
                    //}
                    fsRead.Close();
                    fsRead.Dispose();
                }
            }
            Dictionary <double, FreqStatModel> dictionaryAsc = temp.Where(x => x.Key >= Convert.ToDouble(freqNavBar.FreqStart) * 1000 && x.Key <= Convert.ToDouble(freqNavBar.FreqStop) * 1000).OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value);

            if (dictionaryAsc.Count == 0)
            {
                reminderBoxDelegate("选中频段超出数据范围!");
            }
            else
            {
                streamStatFile(dictionaryAsc);
                ctrlStatData(dictionaryAsc, freqNavBar);
            }
        }