public bool preProcess(double[] tt, double[] wx, double[] wvelo, string FileName, string sAddFileName, string swx) { try { List <PointIDX> Lidx = new List <PointIDX>(); //调用刘博士的算法,得到索引数组idx int oneTimeLength = 1000000; //一次处理的点数 for (int i = 0; i < tt.Length; i += oneTimeLength) { int remain = 0; int index = (i / oneTimeLength) * oneTimeLength; remain = tt.Length - oneTimeLength * (i / oneTimeLength + 1); int ThisTimeLength = remain > 0 ? oneTimeLength : (remain += oneTimeLength); double[] tmpCh1 = new double[ThisTimeLength]; double[] tmpCh2 = new double[ThisTimeLength]; double[] tmpCh3 = new double[ThisTimeLength]; for (int j = 0; j < ThisTimeLength; j++) { tmpCh1[j] = tt[index + j]; tmpCh2[j] = wx[index + j]; tmpCh3[j] = wvelo[index + j]; } MWNumericArray dtt = new MWNumericArray(tmpCh1); MWNumericArray dwx = new MWNumericArray(tmpCh2); MWNumericArray dwvelo = new MWNumericArray(tmpCh3); //调用算法 MWNumericArray resultArrayAB = (MWNumericArray)CommonClassIDP.ppc.sub_identify_abnormal_point(dtt, dwx, dwvelo); double[,] result = (double[, ])resultArrayAB.ToArray(); if (result.GetLength(1) == 0) { continue; } Lidx.Clear(); for (int m = 0; m < result.GetLength(1); m++) { PointIDX pi = new PointIDX(); pi.s = result[0, m] + index; pi.e = result[1, m] + index; Lidx.Add(pi); } InfoLabel2.Visible = true; int k = 0; //按对处理索引数组 List <PointIDX> .Enumerator listCredentials = Lidx.GetEnumerator(); while (listCredentials.MoveNext()) { InfoLabel2.Text = swx + ": i=" + i + " ,length=" + tt.Length + "\n正在写入第" + k + "条,共" + Lidx.Count + "条"; InfoLabel2.Refresh(); k++; //根据索引值获取对应的文件指针。 double sPox = CommonClassIDP.cdp.GetPosByIdx(FileName, listCredentials.Current.s); double ePox = CommonClassIDP.cdp.GetPosByIdx(FileName, listCredentials.Current.e); //根据文件指针,获取里程信息。 double smile = CommonClassIDP.cdp.GetMileByPos(sAddFileName, FileName, sPox); double emile = CommonClassIDP.cdp.GetMileByPos(sAddFileName, FileName, ePox); //调用InvalidDataInsertInto,写idf文件。 CommonClassIDP.wdp.InvalidDataInsertInto(sAddFileName, sPox.ToString(), ePox.ToString(), toKM(smile), toKM(emile), 6, "无效滤除算法", swx); } } InfoLabel2.Visible = false; } catch (Exception ex) { MessageBox.Show(ex.Message); return(false); } return(true); }
/// <summary> /// 无效数据滤除--处理多个通道 /// </summary> /// <param name="tt">里程数组:公里</param> /// <param name="wx_prof_L">轨道左高低不平顺</param> /// <param name="wx_prof_R">轨道右高低不平顺</param> /// <param name="wx_align_L">轨道左轨向不平顺</param> /// <param name="wx_align_R">轨道右轨向不平顺</param> /// <param name="wx_gauge">轨距</param> /// <param name="wx_level">水平</param> /// <param name="wvelo">速度:km/h</param> /// <param name="wgauge_L">单边轨距左</param> /// <param name="wgauge_R">单边轨距右</param> /// <param name="FileName">cit文件名</param> /// <param name="sAddFileName">idf文件名</param> /// <param name="swx">英文通道名:这里统一写成"自动标识"</param> /// <returns>结果</returns> private bool preProcess(double[] tt, double[] wx_prof_L, double[] wx_prof_R, double[] wx_align_L, double[] wx_align_R, double[] wx_gauge, double[] wx_level, double[] wvelo, double[] wgauge_L, double[] wgauge_R, string FileName, string sAddFileName, string swx) { try { List <PointIDX> Lidx = new List <PointIDX>(); //调用刘博士的算法,得到索引数组idx int oneTimeLength = 1000000; //一次处理的点数 for (int i = 0; i < tt.Length; i += oneTimeLength) { int remain = 0; int index = (i / oneTimeLength) * oneTimeLength; remain = tt.Length - oneTimeLength * (i / oneTimeLength + 1); int ThisTimeLength = remain > 0 ? oneTimeLength : (remain += oneTimeLength); double[] tmp_tt = new double[ThisTimeLength]; double[] tmp_wx_prof_L = new double[ThisTimeLength]; double[] tmp_wx_prof_R = new double[ThisTimeLength]; double[] tmp_wx_align_L = new double[ThisTimeLength]; double[] tmp_wx_align_R = new double[ThisTimeLength]; double[] tmp_wx_gauge = new double[ThisTimeLength]; double[] tmp_wx_level = new double[ThisTimeLength]; double[] tmp_wvelo = new double[ThisTimeLength]; double[] tmp_wgauge_L = new double[ThisTimeLength]; double[] tmp_wgauge_R = new double[ThisTimeLength]; for (int j = 0; j < ThisTimeLength; j++) { tmp_tt[j] = tt[index + j]; tmp_wx_prof_L[j] = wx_prof_L[index + j]; tmp_wx_prof_R[j] = wx_prof_R[index + j]; tmp_wx_align_L[j] = wx_align_L[index + j]; tmp_wx_align_R[j] = wx_align_R[index + j]; tmp_wx_gauge[j] = wx_gauge[index + j]; tmp_wx_level[j] = wx_level[index + j]; tmp_wvelo[j] = wvelo[index + j]; tmp_wgauge_L[j] = wgauge_L[index + j]; tmp_wgauge_R[j] = wgauge_R[index + j]; } MWNumericArray d_tt = new MWNumericArray(tmp_tt); MWNumericArray d_wx_prof_L = new MWNumericArray(tmp_wx_prof_L); MWNumericArray d_wx_prof_R = new MWNumericArray(tmp_wx_prof_R); MWNumericArray d_wx_align_L = new MWNumericArray(tmp_wx_align_L); MWNumericArray d_wx_align_R = new MWNumericArray(tmp_wx_align_R); MWNumericArray d_wx_gauge = new MWNumericArray(tmp_wx_gauge); MWNumericArray d_wx_level = new MWNumericArray(tmp_wx_level); MWNumericArray d_wvelo = new MWNumericArray(tmp_wvelo); MWNumericArray d_wgauge_L = new MWNumericArray(tmp_wgauge_L); MWNumericArray d_wgauge_R = new MWNumericArray(tmp_wgauge_R); //调用算法 MWNumericArray resultArrayAB = (MWNumericArray)ppmc.sub_identify_abnormal_point(d_tt, d_wx_prof_L, d_wx_prof_R, d_wx_align_L, d_wx_align_R, d_wx_gauge, d_wx_level, d_wvelo, d_wgauge_L, d_wgauge_R); double[,] result = (double[, ])resultArrayAB.ToArray(); if (result.GetLength(1) == 0) { continue; } Lidx.Clear(); for (int m = 0; m < result.GetLength(0); m++) { PointIDX pi = new PointIDX(); pi.s = result[m, 0] + index; pi.e = result[m, 1] + index; pi.type = (int)(result[m, 2]); Lidx.Add(pi); } //按对处理索引数组 List <PointIDX> .Enumerator listCredentials = Lidx.GetEnumerator(); try { using (OleDbConnection sqlconn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + sAddFileName + ";Persist Security Info=True")) { sqlconn.Open(); OleDbCommand sqlcom; string sSql = null; int id = 0;//无效区段id sSql = "select max(Id) from InvalidData"; sqlcom = new OleDbCommand(sSql, sqlconn); OleDbDataReader oledbReader = sqlcom.ExecuteReader(); Boolean isNull = oledbReader.HasRows;//是否是第一条记录,第一条记录id为1; if (isNull == false) { id = 1; } else { while (oledbReader.Read()) { if (String.IsNullOrEmpty(oledbReader.GetValue(0).ToString())) { id = 1; } else { id = int.Parse(oledbReader.GetValue(0).ToString()) + 1; } } } while (listCredentials.MoveNext()) { //根据索引值获取对应的文件指针。 double sPox = cdp.GetPosByIdx(FileName, listCredentials.Current.s); double ePox = cdp.GetPosByIdx(FileName, listCredentials.Current.e); //根据文件指针,获取里程信息。 double smile = cdp.GetMileByPos(sAddFileName, FileName, sPox); double emile = cdp.GetMileByPos(sAddFileName, FileName, ePox); int type = listCredentials.Current.GetType(); sSql = "insert into InvalidData values(" + (id++).ToString() + ",'" + sPox.ToString() + "','" + ePox.ToString() + "','" + smile.ToString() + "','" + emile.ToString() + "'," + type + ",'无效数据',0,'" + swx + "')"; //插入数据库 sqlcom = new OleDbCommand(sSql, sqlconn); sqlcom.ExecuteNonQuery(); } sqlconn.Close(); } } catch (Exception ex) { MessageBox.Show("无效区段设置异常:" + ex.Message); } } //InfoLabel2.Visible = false; } catch (Exception ex) { MessageBox.Show(swx + "通道处理出错"); MessageBox.Show(ex.Source); MessageBox.Show(ex.StackTrace); MessageBox.Show(ex.Message); return(false); } return(true); }