From 5f42163a8c4fe5f51a506ce8593e03412abdd23b Mon Sep 17 00:00:00 2001 From: gekoukate <1670391937@qq.com> Date: Tue, 4 Apr 2023 18:04:18 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=BB=E5=8F=96=E5=A4=9A=E4=B8=AA=E6=96=87?= =?UTF-8?q?=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mseedChart.MainModule/Models/MmEvent.cs | 310 +++--------------- mseedChart.MainModule/Models/StationModel.cs | 5 - mseedChart.MainModule/Models/WavesModel.cs | 144 +------- mseedChart.MainModule/RegionNames.cs | 4 +- .../ViewModels/ChartPlotViewModel.cs | 121 +++++-- 5 files changed, 137 insertions(+), 447 deletions(-) diff --git a/mseedChart.MainModule/Models/MmEvent.cs b/mseedChart.MainModule/Models/MmEvent.cs index b189292..1e4ff0d 100644 --- a/mseedChart.MainModule/Models/MmEvent.cs +++ b/mseedChart.MainModule/Models/MmEvent.cs @@ -12,97 +12,13 @@ namespace mseedChart.MainModule.Models { public class MmEvent : CoordBase { - private bool isShow; - - public int MoniID = 0; - - public int LayerID = 0; - - public int EventID = 0; - - private int _second; - - private int _milliSecond; private DateTime _eventTime; - private double _horiError; - - private double _vertError; - - private double _cnt; - private double _ml; private double _rms; - private Dictionary _phases; - - public float[] standData; - - public float[][] nearData; - - public float minTimeDiff = 0f; - - public bool Falcone = false; - - public float errorCircularRadius = 0f; - - public float errorH = 0f; - - public int isShowed = 1; - - public float Hlen = 0f; - - public float Llen = 0f; - - public float VF = 0f; - - public List SN = new List(); - - public List PM = new List(); - - public List GCS = new List(); - - public int WorkAreaID { get; set; } = 0; - - - public bool IsShow - { - get - { - return isShow; - } - set - { - isShow = value; - } - } - - public int Second - { - get - { - return _second; - } - set - { - _second = value; - } - } - - public int Millisecond - { - get - { - return _milliSecond; - } - set - { - _milliSecond = value; - } - } - public string EventTimeStr { get; set; } public DateTime EventTime @@ -117,42 +33,6 @@ namespace mseedChart.MainModule.Models } } - public double HoriError - { - get - { - return _horiError; - } - set - { - _horiError = value; - } - } - - public double VertError - { - get - { - return _vertError; - } - set - { - _vertError = value; - } - } - - public double Cnt - { - get - { - return _cnt; - } - set - { - _cnt = value; - } - } - public double ML { get @@ -177,6 +57,7 @@ namespace mseedChart.MainModule.Models } } + private Dictionary _phases; public Dictionary Phases { get @@ -189,167 +70,56 @@ namespace mseedChart.MainModule.Models } } - public double Stress { get; set; } - - public double Energy { get; set; } - - public int LocSta { get; set; } - - public int MLSta { get; set; } - - public string EventTpye { get; set; } - - public int SourceChara { get; set; } - - public double Direction { get; set; } - - public double StressDrop { get; set; } - public double DominantFreq { get; set; } - public double MW { get; set; } - - public double Amplitude { get; set; } - - public double Semiperiod { get; set; } - - public double Coda { get; set; } - public string JsonFile { get; set; } - public string MseedFile { get; set; } - public string AsciiFile { get; set; } - public float Amp { get; set; } - - public FocalMechanismType FocalType { get; set; } - - public static void SavePos(string fn, List mMEvents) - { - StreamWriter streamWriter = new StreamWriter(fn); - try - { - if (mMEvents != null && mMEvents.Count > 0) - { - streamWriter.WriteLine(mMEvents.Count.ToString()); - List list = (from o in mMEvents - orderby o.Second, o.Millisecond - select o).ToList(); - for (int i = 0; i < list.Count; i++) - { - MmEvent mmEvent = list[i]; - streamWriter.WriteLine(Math.Round(mmEvent.X, 1) + "\t" + Math.Round(mmEvent.Y, 1) + "\t" + Math.Round(mmEvent.Z, 1) + "\t" + mmEvent.Second + "." + mmEvent.Millisecond); - } - } - } - catch (Exception) - { - throw; - } - finally - { - streamWriter.Close(); - } - } - - public static void SaveNewPin(string fn, int layerIndex, List mMEvents) - { - StreamWriter streamWriter = new StreamWriter(fn); - int num = layerIndex; - int num2 = layerIndex; - try - { - List list = (from o in mMEvents - orderby o.Second, o.Millisecond - select o).ToList(); - for (int i = 0; i < list.Count; i++) - { - MmEvent mmEvent = list[i]; - string pMStr = GetPMStr(mmEvent); - streamWriter.WriteLine(Math.Round(mmEvent.X, 1) + "\t" + Math.Round(mmEvent.Y, 1) + "\t" + Math.Round(mmEvent.Z, 1) + "\t" + mmEvent.Second + "." + mmEvent.Millisecond + "\t" + num + "\t" + num2 + "\t" + mmEvent.errorCircularRadius + "\t" + mmEvent.errorH + "\t" + 0 + "\t" + mmEvent.ML + pMStr); - } - - streamWriter.Close(); - } - catch (Exception) - { - throw; - } - finally - { - streamWriter.Close(); - } - } - - public static void SaveOldPin(string fn, int layer, List mMEvents) + public static float SetAmp(List amps) { - StreamWriter streamWriter = new StreamWriter(fn); - try - { - List list = (from o in mMEvents - orderby o.Second, o.Millisecond - select o).ToList(); - for (int i = 0; i < list.Count; i++) - { - MmEvent mmEvent = list[i]; - string pMStr = GetPMStr(mmEvent); - streamWriter.WriteLine(layer + "\t" + Math.Round(mmEvent.X, 0) + "\t" + Math.Round(mmEvent.Y, 0) + "\t" + Math.Round(mmEvent.Z, 0) + "\t" + mmEvent.Second + "." + mmEvent.Millisecond + "\t" + mmEvent.ML + "\t" + mmEvent.errorCircularRadius + "\t" + mmEvent.errorH + "\t" + mmEvent.minTimeDiff + pMStr); - } - - streamWriter.Close(); - } - catch (Exception) - { - throw; - } - finally - { - streamWriter.Close(); - } + amps.Sort(); + return amps[amps.Count / 2]; } + } - public static string GetPMStr(MmEvent p) - { - string text = "\t"; - int[] mpIndex = new int[p.SN.Count]; - for (int j = 0; j < mpIndex.Length; j++) - { - mpIndex[j] = p.SN[j]; - } - - for (int k = 0; k < mpIndex.Length - 1; k++) - { - for (int l = 0; l < mpIndex.Length - 1 - k; l++) - { - if (mpIndex[l] > mpIndex[l + 1]) - { - int num = mpIndex[l]; - mpIndex[l] = mpIndex[l + 1]; - mpIndex[l + 1] = num; - } - } - } - - int i; - for (i = 0; i < p.PM.Count; i++) - { - int index = p.SN.FindIndex((int s) => s == mpIndex[i]); - text = ((p.PM.Count - 1 != i) ? (text + p.SN[index] + ":" + p.PM[index] + "\t") : (text + p.SN[index] + ":" + p.PM[index])); - } - - return text; - } - public void SetEnergy() - { - Energy = Math.Round(63000.0 * Math.Pow(10.0, 1.47 * ML), 2); - } + public class JsonST + { + public DateTime otime { get;set;} + public double lon { get; set; } + public double lat { get; set; } + public double depth { get; set; } + public double ml { get; set; } + public double rms { get; set; } + public List phases { get; set; } + public List amps { get; set; } + } - public static float SetAmp(List amps) - { - amps.Sort(); - return amps[amps.Count / 2]; + public class phases + { + public string id { get; set; } + public string name { get; set; } + public DateTime atime { get; set; } + public double resi { get; set; } + public double first_motion_direct { get; set; } + public double fmd_semi_period { get; set; } + public double deltaKm { get; set; } + + public double disKm { get; set; } + public double model_time { get; set; } + public double weight { get; set; } + public double prob { get; set; } + } + public class amps + { + public string id { get; set; } + public string name { get; set; } + public DateTime atime { get; set; } + public string mag_type { get; set; } + public double mag_value { get; set; } + public double amp { get; set; } } + } \ No newline at end of file diff --git a/mseedChart.MainModule/Models/StationModel.cs b/mseedChart.MainModule/Models/StationModel.cs index 61c3e55..0133eaa 100644 --- a/mseedChart.MainModule/Models/StationModel.cs +++ b/mseedChart.MainModule/Models/StationModel.cs @@ -37,11 +37,6 @@ namespace mseedChart.MainModule.Models public List de = new List(); - public ConcurrentQueue cz = new ConcurrentQueue(); - - public ConcurrentQueue ce = new ConcurrentQueue(); - - public ConcurrentQueue cn = new ConcurrentQueue(); public string Name { get; set; } diff --git a/mseedChart.MainModule/Models/WavesModel.cs b/mseedChart.MainModule/Models/WavesModel.cs index 42f7ea4..ac8ec92 100644 --- a/mseedChart.MainModule/Models/WavesModel.cs +++ b/mseedChart.MainModule/Models/WavesModel.cs @@ -72,7 +72,7 @@ namespace mseedChart.MainModule.Models seriesZ.SamplingFrequency = samplingFrequency; seriesZ.FirstSampleTimeStamp = 1.0 / samplingFrequency; - seriesZ.LineStyle.Width = 1; + seriesZ.LineStyle.Width = 0.5; seriesZ.LineStyle.AntiAliasing = LineAntialias.None; seriesZ.ScrollModePointsKeepLevel = 1; seriesZ.ScrollingStabilizing = true; @@ -100,7 +100,7 @@ namespace mseedChart.MainModule.Models seriesE.SamplingFrequency = samplingFrequency; seriesE.FirstSampleTimeStamp = 1.0 / samplingFrequency; - seriesE.LineStyle.Width = 1; + seriesE.LineStyle.Width = 0.5; seriesE.LineStyle.AntiAliasing = LineAntialias.None; seriesE.ScrollModePointsKeepLevel = 1; seriesE.ScrollingStabilizing = true; @@ -128,7 +128,7 @@ namespace mseedChart.MainModule.Models seriesN.SamplingFrequency = samplingFrequency; seriesN.FirstSampleTimeStamp = 1.0 / samplingFrequency; - seriesN.LineStyle.Width = 1; + seriesN.LineStyle.Width = 0.5; seriesN.LineStyle.AntiAliasing = LineAntialias.None; seriesN.ScrollModePointsKeepLevel = 1; seriesN.ScrollingStabilizing = true; @@ -176,138 +176,14 @@ namespace mseedChart.MainModule.Models } return new List(); } - public MmEvent Json2MmEvent(string jsonFile) - { - using (StreamReader sr = System.IO.File.OpenText(jsonFile)) - { - MmEvent mmEvent = new MmEvent(); - mmEvent.JsonFile = jsonFile; - string filePath = System.IO.Path.GetDirectoryName(jsonFile); - string fileName = System.IO.Path.GetFileNameWithoutExtension(jsonFile).TrimEnd('B').TrimEnd('A'); - string ascName = filePath + "\\" + fileName + ".txt"; - mmEvent.AsciiFile = ascName; - JsonTextReader reader = new JsonTextReader(sr); - JArray jArray = (JArray)JToken.ReadFrom(reader); - //解析普通属性和数组混合的Json文件 - //数组0是普通属性集合 - JObject jobj = (JObject)jArray[0]; - string dateStr = jobj["otime"].ToString(); - mmEvent.EventTime = DateTime.Parse(dateStr); - mmEvent.EventTimeStr = dateStr; - mmEvent.X = double.Parse(jobj["lon"].ToString()); - mmEvent.Y = double.Parse(jobj["lat"].ToString()); - mmEvent.Z = double.Parse(jobj["depth"].ToString()); - mmEvent.ML = double.Parse(jobj["ml"].ToString()); - mmEvent.RMS = double.Parse(jobj["rms"].ToString()); - mmEvent.SetEnergy(); - mmEvent.DominantFreq = 15; - mmEvent.Phases = new Dictionary(); - List DominantFreqlist = new List(); - JArray phaseArr = JArray.FromObject(jobj["phases"]); - List DominantFreqList = new List(); - for (int i = 0; i < phaseArr.Count; i++) - { - if (phaseArr[i]["first_motion_direct"] != null) - { - mmEvent.Phases.Add(phaseArr[i]["id"].ToString().Substring(3, 3), - int.Parse(phaseArr[i]["first_motion_direct"].ToString())); - } - if (phaseArr[i]["fmd_semi_period"] != null) - { - DominantFreqlist.Add(double.Parse(phaseArr[i]["fmd_semi_period"].ToString())); - } - } - if (DominantFreqlist.Count > 0) - { - if (DominantFreqlist.Count > 3) - { - double min = DominantFreqlist.Min(); - double max = DominantFreqlist.Max(); - DominantFreqlist.Remove(min); - DominantFreqlist.Remove(max); - mmEvent.DominantFreq = DominantFreqlist.Sum() / (double)DominantFreqlist.Count; - } - else - { - mmEvent.DominantFreq = 0; - } - } - return mmEvent; - } - //return null; - } - public MmEvent Json2MmEventWithPara(string jsonFile) + + public JsonST mseedJsonResolve(string jsonFile) { - using (StreamReader sr = System.IO.File.OpenText(jsonFile)) - { - MmEvent mmEvent = new MmEvent(); - mmEvent.JsonFile = jsonFile; - string filePath = System.IO.Path.GetDirectoryName(jsonFile); - string fileName = System.IO.Path.GetFileNameWithoutExtension(jsonFile).TrimEnd('B').TrimEnd('A'); - //fileName=fileName.TrimEnd('B'); - //fileName.TrimEnd('A'); - string ascName = filePath + "\\" + fileName + ".txt"; - mmEvent.AsciiFile = ascName; - JsonTextReader reader = new JsonTextReader(sr); - JArray jArray = (JArray)JToken.ReadFrom(reader); - //解析普通属性和数组混合的Json文件 - //数组0是普通属性集合 - JObject jobj = (JObject)jArray[0]; - string dateStr = jobj["otime"].ToString(); - //LocalSqLiteServerAccess localSqLiteServerAccess = new LocalSqLiteServerAccess(); - //int selectResult = localSqLiteServerAccess.SelectWithTime(dateStr); - int selectResult = 1; - if (selectResult < 1) - { - return null; - } - else - { - mmEvent.Phases = new Dictionary(); - List Semiperiodlist = new List(); - JArray phaseArr = JArray.FromObject(jobj["phases"]); - List DominantFreqList = new List(); - for (int i = 0; i < phaseArr.Count; i++) - { - if (phaseArr[i]["first_motion_direct"] != null) - { - mmEvent.Phases.Add(phaseArr[i]["id"].ToString().Substring(3, 3), - int.Parse(phaseArr[i]["first_motion_direct"].ToString())); - } - if (phaseArr[i]["fmd_semi_period"] != null) - { - Semiperiodlist.Add(double.Parse(phaseArr[i]["fmd_semi_period"].ToString())); - } - } - if (Semiperiodlist.Count > 0) - { - if (Semiperiodlist.Count > 3) - { - double min = Semiperiodlist.Min(); - double max = Semiperiodlist.Max(); - Semiperiodlist.Remove(min); - Semiperiodlist.Remove(max); - mmEvent.DominantFreq = Semiperiodlist.Sum() / (double)Semiperiodlist.Count; - } - else - { - mmEvent.DominantFreq = 0; - } - } - JArray ampsArr = JArray.FromObject(jobj["amps"]); - List ampsArrList = new List(); - for (int i = 0; i < ampsArr.Count; i++) - { - if (ampsArr[i]["amp"] != null) - { - ampsArrList.Add(float.Parse(ampsArr[i]["amp"].ToString())); - } - } - MmEvent.SetAmp(ampsArrList); - return mmEvent; - } - } - } + var str = File.ReadAllText(jsonFile); + var st = JsonConvert.DeserializeObject(str); + JsonST jsonST = st[0]; + return jsonST; + } } } diff --git a/mseedChart.MainModule/RegionNames.cs b/mseedChart.MainModule/RegionNames.cs index cc78187..a68935b 100644 --- a/mseedChart.MainModule/RegionNames.cs +++ b/mseedChart.MainModule/RegionNames.cs @@ -11,10 +11,10 @@ namespace mseedChart.Core { public const string ContentRegion = "ContentRegion"; - public static string MseedFilePath = @"H:\EwsCache\Mseed"; //AppDomain.CurrentDomain.BaseDirectory + "EwsCache\\Mseed"; + public static string MseedFilePath = @"D:\EwsCache\Mseed"; //AppDomain.CurrentDomain.BaseDirectory + "EwsCache\\Mseed"; - public static string TxtFilePath = @"H:\EwsCache\Txt";//;AppDomain.CurrentDomain.BaseDirectory + "EwsCache\\Txt"; + public static string TxtFilePath = @"D:\EwsCache\Txt";//;AppDomain.CurrentDomain.BaseDirectory + "EwsCache\\Txt"; public static string DataTypeString = "A"; diff --git a/mseedChart.MainModule/ViewModels/ChartPlotViewModel.cs b/mseedChart.MainModule/ViewModels/ChartPlotViewModel.cs index 61942b0..971ca82 100644 --- a/mseedChart.MainModule/ViewModels/ChartPlotViewModel.cs +++ b/mseedChart.MainModule/ViewModels/ChartPlotViewModel.cs @@ -9,9 +9,11 @@ using Prism.Events; using Prism.Mvvm; using SharpDX.DirectWrite; using System; +using System.Collections.Concurrent; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; +using System.ComponentModel.Design.Serialization; using System.Diagnostics; using System.IO; using System.Linq; @@ -19,6 +21,7 @@ using System.Threading; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; +using System.Windows.Markup; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Threading; @@ -35,8 +38,9 @@ namespace mseedChart.MainModule.ViewModels CreateChart(); (Application.Current.MainWindow as System.Windows.Window).Closing += ApplicationClosingDispose; - string fileName = "2023-03-31T07:43:15.464036"; - ShowWave(null,obj:fileName); + string fileName = "2023-03-28T04:53:46.199584"; + // fileName = "2023-03-24T04:53:46.199584"; + bool multFlies = true; string eventTimeStr = fileName; string datePath = eventTimeStr.Substring(0, 4) + eventTimeStr.Substring(5, 2) + eventTimeStr.Substring(8, 2); string dataFilePath = RegionNames.MseedFilePath + "\\" + datePath + "\\"; @@ -44,7 +48,13 @@ namespace mseedChart.MainModule.ViewModels + eventTimeStr.Substring(8, 2) + eventTimeStr.Substring(10, 3) + eventTimeStr.Substring(14, 2) + eventTimeStr.Substring(17, 2) + ".01" + RegionNames.DataTypeString; string jsonStr = ".json"; - _wavesModel.Json2MmEvent(dataFilePath+dataFileName+jsonStr); + string mseedStr = ".mseed"; + string asciiSavePath = RegionNames.TxtFilePath + "\\" + datePath + "\\"; + if (!multFlies) + { + _wavesModel.mseedJsonResolve(dataFilePath + dataFileName + jsonStr); + } + ShowWave(dataFilePath + dataFileName + mseedStr, asciiSavePath + dataFileName + ".txt" , multFlies); } #region 字段 @@ -57,7 +67,7 @@ namespace mseedChart.MainModule.ViewModels WavesModel _wavesModel; private int _lChartCount = 1; - public List smList; + public ConcurrentQueue smList; #endregion #region 属性 @@ -159,14 +169,14 @@ namespace mseedChart.MainModule.ViewModels }; if (openFileDialog.ShowDialog() == true) { - ShowWave(openFileDialog.FileName); + //ShowWave(openFileDialog.FileName); } } #endregion - public void UpdateWavesFromTxt(string fn) + public List UpdateWavesFromTxt(string fn) { string allStr; - smList = new List(); + List temSM = new List(); using (StreamReader streamReader = new StreamReader(fn)) { allStr = streamReader.ReadToEnd(); @@ -187,18 +197,23 @@ namespace mseedChart.MainModule.ViewModels int channelFlag = 0; - for (int i = 1; i < strLines.Length; i++) + for (int i = 0; i < strLines.Length; i++) { string row = strLines[i].Trim(); if (strLines[i].Contains("HA")) { string[] rowStr = strLines[i].Split(','); string chnStr1 = rowStr[0].Substring(21, 3); - if (chnStr1 == "SHZ") + string stationName = rowStr[0].Substring(14, 3); + if (!temSM.Any(name => name.Name == stationName)) { - smList.Add(station); station = new StationModel(); - station.Name = rowStr[0].Substring(14, 3); + station.Name = stationName; + temSM.Add(station); + } + if (chnStr1 == "SHZ") + { + channelFlag = 0;//Z } else if (chnStr1 == "SHN") @@ -226,9 +241,10 @@ namespace mseedChart.MainModule.ViewModels } } } - smList.Add(station); - smList.Reverse(); + // temSM.Add(station); + temSM.Reverse(); } + return temSM; } public void MSeed2Asc(string filePath, string savePath) { @@ -237,6 +253,7 @@ namespace mseedChart.MainModule.ViewModels compiler.StartInfo.FileName = "mseed2ascii.exe"; compiler.StartInfo.Arguments = filePath + " -o " + savePath; compiler.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; + compiler.StartInfo.CreateNoWindow = true; compiler.Start(); compiler.WaitForExit(); } @@ -274,11 +291,20 @@ namespace mseedChart.MainModule.ViewModels LChartALL.ViewXY.XAxes[0].AllowScrolling = false; LChartALL.ViewXY.XAxes[0].PanningEnabled = false; LChartALL.ViewXY.XAxes[0].SweepingGap = 0; - // LChartALL.ViewXY.XAxes[0].ValueType = AxisValueType.Number; + LChartALL.ViewXY.XAxes[0].ValueType = AxisValueType.DateTime; LChartALL.ViewXY.XAxes[0].AutoFormatLabels = false; // LChartALL.ViewXY.XAxes[0].LabelsNumberFormat = "N0"; // LChartALL.ViewXY.XAxes[0].MajorGrid.Pattern = LinePattern.Solid; + LChartALL.ViewXY.XAxes[0].MinorGrid.Visible = false; + LChartALL.ViewXY.XAxes[0].MajorGrid.Pattern = LinePattern.Solid; + + //LChartALL.ViewXY.XAxes[0].MinimumDateTime=DateTime.Now; + LChartALL.ViewXY.XAxes[0].AutoDivSpacing = false; + LChartALL.ViewXY.XAxes[0].MinorDivTickStyle.Visible = true; + LChartALL.ViewXY.XAxes[0].KeepDivCountOnRangeChange = true; + LChartALL.ViewXY.XAxes[0].MajorDivCount = 5; + LChartALL.ViewXY.XAxes[0].LabelsTimeFormat = "HH:mm.ss.ffff"; //图表背景颜色 LChartALL.ViewXY.GraphBackground.Color = Colors.White; //LChartALL.ViewXY.GraphBackground.GradientFill = GradientFill.Solid; @@ -292,31 +318,54 @@ namespace mseedChart.MainModule.ViewModels this.ChildContent = GridChart; } - private void ShowWave(string filePath, string obj = "2023-03-29T06:41:21.348") + private void ShowWave(string dataFilePath, string asciiSavePath, bool isMultFile = false) { - string EventTimeStr = obj; - string datePath = EventTimeStr.Substring(0, 4) + EventTimeStr.Substring(5, 2) + EventTimeStr.Substring(8, 2); - string dataFilePath = RegionNames.MseedFilePath + "\\" + datePath + "\\"; - string dataFileName = "HA." + EventTimeStr.Substring(0, 4) + EventTimeStr.Substring(5, 2) - + EventTimeStr.Substring(8, 2) + EventTimeStr.Substring(10, 3) - + EventTimeStr.Substring(14, 2) + EventTimeStr.Substring(17, 2) + ".01" + RegionNames.DataTypeString; - string mseedStr = ".mseed"; - string asciiSavePath = RegionNames.TxtFilePath + "\\" + datePath + "\\" + dataFileName + ".txt"; - if (filePath != null) asciiSavePath = filePath; - if (!Directory.Exists(dataFilePath)) + if (!Directory.Exists(Path.GetDirectoryName(dataFilePath))) { - Directory.CreateDirectory(dataFilePath); + Directory.CreateDirectory(Path.GetDirectoryName(dataFilePath)); } if (!Directory.Exists(Path.GetDirectoryName(asciiSavePath))) { Directory.CreateDirectory(Path.GetDirectoryName(asciiSavePath)); } - - if (!File.Exists(asciiSavePath)) + smList = new ConcurrentQueue(); + if (isMultFile) { - MSeed2Asc(dataFilePath + dataFileName + mseedStr, asciiSavePath); - } - UpdateWavesFromTxt(asciiSavePath); + var filePath = new DirectoryInfo(Path.GetDirectoryName(dataFilePath)); + FileInfo[] files = filePath.GetFiles(); + //var dic = file.GetDirectories(); + var mseedFiles = files.Where(i => i.Extension == ".mseed"); + + var asciiFiles = new DirectoryInfo(Path.GetDirectoryName(asciiSavePath)); + var asciifile = asciiFiles.GetFiles(); + if (asciifile.Count()==0) + { + // 并行运算 + Stopwatch sw = Stopwatch.StartNew(); + Parallel.ForEach(mseedFiles, (item) => + { + MSeed2Asc(item.FullName, asciiSavePath + Path.GetFileNameWithoutExtension(item.Name)); + }); + sw.Stop(); + Debug.WriteLine("MSeed2Asc解压时间:" +sw.Elapsed.TotalSeconds); + } + // 并行运算 + Parallel.ForEach(asciiFiles.GetFiles(), (item) => + { + var list = UpdateWavesFromTxt(item.FullName); + list.ForEach(i => smList.Enqueue(i)); + }); + } + else + { + if (!File.Exists(asciiSavePath)) + { + MSeed2Asc(dataFilePath, asciiSavePath); + } + var list = UpdateWavesFromTxt(asciiSavePath); + list.ForEach(i => smList.Enqueue(i)); + } + _channelCount = smList.Count * 3; UpdateChart(); UpdateChartData(); @@ -329,7 +378,7 @@ namespace mseedChart.MainModule.ViewModels DisposeAllAndClear(LChartALL.ViewXY.YAxes); DisposeAllAndClear(LChartALL.ViewXY.SampleDataSeries); - LChartALL.ViewXY.YAxes.AddRange(_wavesModel.CreateYAxisChart(smList, LChartALL)); + LChartALL.ViewXY.YAxes.AddRange(_wavesModel.CreateYAxisChart(smList.ToList(), LChartALL)); int seriesIndex = 0; foreach (var axisY in LChartALL.ViewXY.YAxes) { @@ -378,7 +427,7 @@ namespace mseedChart.MainModule.ViewModels LChartALL.ViewXY.XAxes[0].LabelsColor = Colors.Black; LChartALL.ViewXY.SampleDataSeries.AddRange( - _wavesModel.GetSampleDataSeriesPingPu(smList, LChartALL, LChartALL.ViewXY.XAxes[0], + _wavesModel.GetSampleDataSeriesPingPu(smList.ToList(), LChartALL, LChartALL.ViewXY.XAxes[0], LChartALL.ViewXY.YAxes, _samplingFrequency)); } private void UpdateChartData() @@ -388,9 +437,9 @@ namespace mseedChart.MainModule.ViewModels { for (int channelIndex = 0; channelIndex < smList.Count; channelIndex++) { - multiChannelData[channelIndex * 3] = smList[channelIndex].dz.ToArray(); - multiChannelData[channelIndex * 3 + 1] = smList[channelIndex].dn.ToArray(); - multiChannelData[channelIndex * 3 + 2] = smList[channelIndex].de.ToArray(); + multiChannelData[channelIndex * 3] = smList.ElementAt(channelIndex).dz.ToArray(); + multiChannelData[channelIndex * 3 + 1] = smList.ElementAt(channelIndex).dn.ToArray(); + multiChannelData[channelIndex * 3 + 2] = smList.ElementAt(channelIndex).de.ToArray(); } // Invoke FeedNewDataToChart. _dispatcher.Invoke(() =>