/// <summary> /// 接口函数:滤波后,计算连续多波指标 /// </summary> /// <param name="citFileName">cit文件全路径名</param> /// <param name="channelNameEn">英文通道名</param> /// <param name="channelNameCh">中文通道名</param> /// <param name="thresh_p2p">连续多波的阈值</param> /// <param name="thresh_multi_wave">连续多波的个数</param> /// <param name="Fs">采样频率:2000/6</param> /// <param name="Frep_L">下限频率</param> /// <param name="Frep_H">上限频率</param> /// <returns></returns> public List <String> SubProcess(String citFileName, String channelNameEn, String channelNameCh, float thresh_p2p, float thresh_multi_wave, float Fs, float Frep_L, float Frep_H) { List <String> dataStrList = new List <String>(); CITDataProcess.DataHeadInfo dhi = cdp.GetDataInfoHeadNew(citFileName); int tds = dhi.iChannelNumber; //加速度系统也是按照一米四个点,只是频率高,导致在相同的位置打上很多点 dhi.iSmaleRate = 4; long startPos = 0; long endPos = 0; using (FileStream fs = new FileStream(citFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (BinaryReader br = new BinaryReader(fs)) { byte[] b = new byte[tds * 2]; br.ReadBytes(120); //120 br.ReadBytes(65 * tds); //65 br.ReadBytes(BitConverter.ToInt32(br.ReadBytes(4), 0)); startPos = br.BaseStream.Position; endPos = br.BaseStream.Length; br.Close(); } fs.Close(); } //double[] d_tt = cdp.GetMilesDataDouble(citFileName);//里程 double[] d_tt = wdp.GetDataMileageInfoDouble(citFileName, tds, dhi.iSmaleRate, CommonClass.listDIC[0].bEncrypt, CommonClass.listDIC[0].listIC, CommonClass.listDIC[0].bIndex, startPos, endPos, CommonClass.listDIC[0].sKmInc);//里程 double[] d_wx = cdp.GetSingleChannelData(citFileName, dataProcessing.GetChannelNumberByChannelName(citFileName, channelNameEn, channelNameCh)); double[] d_wx_filter = subFilter.Sub_filter_by_fft_and_ifft(d_wx, d_tt, Fs, Frep_L, Frep_H); List <String> tmpDataStrList = pcmw.Sub_preprocessing_continous_multi_wave_on_acc(channelNameCh, d_tt, d_wx_filter, thresh_multi_wave, thresh_p2p); dataStrList.AddRange(tmpDataStrList); return(dataStrList); }
private void Process() { CalcProcess cp = new CalcProcess(); //处理 for (int i = 0; i < listBox1.Items.Count; i++) { //被修正的原始文件--cit String citFilePath = listBox1.Items[i].ToString(); CITDataProcess.DataHeadInfo dhi = CommonClass.cdp.GetDataInfoHead(citFilePath); //根据相关性,修正cit文件的索引 List <IndexOriClass> listIOC = cp.CorrelationCalc(CommonClass.listDIC[0].sFilePath, citFilePath, CommonClass.wdp.GetLayerIndexInfo(CommonClass.listDIC[0].sAddFile, "0", CommonClass.listDIC[0].sKmInc), CommonClass.listDIC[0].iSmaleRate, CommonClass.listDIC[0].iChannelNumber, CommonClass.listDIC[0].bEncrypt, CommonClass.listDIC[0].sKmInc , float.Parse(textBox超高门阀值.Text), float.Parse(textBox轨距门阀值.Text), float.Parse(textBox左高低门阀值.Text) , float.Parse(textBox右高低门阀值.Text), int.Parse(textBox原始数据点.Text), int.Parse(textBox目标数据点.Text), dhi.iChannelNumber); if (listIOC.Count > 0) { String idfFilePath = citFilePath.Replace(".cit", ".idf"); CommonClass.wdp.CreateDB(idfFilePath); CommonClass.wdp.CreateTable(idfFilePath); //删除 CommonClass.wdp.deleteLayerIndexInfo(idfFilePath); //重新保存索引库 for (int j = 0; j < listIOC.Count; j++) { CommonClass.wdp.InsertLayerAllIndexInfo(idfFilePath, listIOC[j].iId.ToString() , listIOC[j].iIndexId.ToString(), listIOC[j].IndexPoint.ToString(), listIOC[j].IndexMeter.ToString()); } //创建计算后的索引库 List <CDLClass> listCDL = CommonClass.GetCDL(); //根据标定的里程特征点信息创建索引文件idf CommonClass.wdp.CreateIndexInfo(citFilePath, idfFilePath, "1", listCDL, CommonClass.listDIC[0].sKmInc, dhi.iChannelNumber, CommonClass.listDIC[0].iSmaleRate); } else { MessageBox.Show("CommonClass.listDIC[0]的文件索引为空,没有执行修正!"); this.Enabled = true; Application.DoEvents(); return; } } }
/// <summary> /// 接口函数:计算连续多波指标 /// </summary> /// <param name="citFileName">cit文件全路径名</param> /// <returns></returns> public List <String> PreproceingContinousMultiWave(String citFileName) { List <String> dataStrList = new List <String>(); CITDataProcess.DataHeadInfo dhi = cdp.GetDataInfoHeadNew(citFileName); int tds = dhi.iChannelNumber; long startPos = 0; long endPos = 0; using (FileStream fs = new FileStream(citFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (BinaryReader br = new BinaryReader(fs)) { byte[] b = new byte[tds * 2]; br.ReadBytes(120); //120 br.ReadBytes(65 * tds); //65 br.ReadBytes(BitConverter.ToInt32(br.ReadBytes(4), 0)); startPos = br.BaseStream.Position; endPos = br.BaseStream.Length; br.Close(); } fs.Close(); } //double[] d_tt = cdp.GetMilesDataDouble(citFileName);//里程 double[] d_tt = wdp.GetDataMileageInfoDouble(citFileName, tds, dhi.iSmaleRate, CommonClass.listDIC[0].bEncrypt, CommonClass.listDIC[0].listIC, CommonClass.listDIC[0].bIndex, startPos, endPos, CommonClass.listDIC[0].sKmInc);//里程 double[] d_wvelo = cdp.GetSingleChannelData(citFileName, dataProcessing.GetChannelNumberByChannelName(citFileName, "Speed", "速度")); double[] d_gauge = cdp.GetSingleChannelData(citFileName, dataProcessing.GetChannelNumberByChannelName(citFileName, "Gage", "轨距")); double[] d_wx = cdp.GetSingleChannelData(citFileName, dataProcessing.GetChannelNumberByChannelName(citFileName, "L_Prof_SC", "左高低_中波")); List <String> tmpDataStrList = pcmw.ContinousMultiWavePreprocess("左高低_中波", d_tt, d_wx, d_wvelo, d_gauge, 3.0, 3.0); dataStrList.AddRange(tmpDataStrList); d_wx = cdp.GetSingleChannelData(citFileName, dataProcessing.GetChannelNumberByChannelName(citFileName, "R_Prof_SC", "右高低_中波")); tmpDataStrList = pcmw.ContinousMultiWavePreprocess("右高低_中波", d_tt, d_wx, d_wvelo, d_gauge, 3.0, 3.0); dataStrList.AddRange(tmpDataStrList); d_wx = cdp.GetSingleChannelData(citFileName, dataProcessing.GetChannelNumberByChannelName(citFileName, "L_Align_SC", "左轨向_中波")); tmpDataStrList = pcmw.ContinousMultiWavePreprocess("左轨向_中波", d_tt, d_wx, d_wvelo, d_gauge, 3.0, 3.0); dataStrList.AddRange(tmpDataStrList); d_wx = cdp.GetSingleChannelData(citFileName, dataProcessing.GetChannelNumberByChannelName(citFileName, "R_Align_SC", "右轨向_中波")); tmpDataStrList = pcmw.ContinousMultiWavePreprocess("右轨向_中波", d_tt, d_wx, d_wvelo, d_gauge, 3.0, 3.0); dataStrList.AddRange(tmpDataStrList); return(dataStrList); }
private void ReadCIT(String citFilePath) { if (numericUpDown1.Value <= 0) { MessageBox.Show("容许跳变值为 0"); return; } try { autoIndexClsList.Clear(); dataGridView1.Rows.Clear(); CITDataProcess.DataHeadInfo m_dhi = cdp.GetDataInfoHead(citFilePath); List <CITDataProcess.DataChannelInfo> m_dcil = cdp.GetDataChannelInfoHeadNew(citFilePath); FileStream fs = new FileStream(citFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); BinaryReader br = new BinaryReader(fs, Encoding.Default); br.BaseStream.Position = 0; br.ReadBytes(120); br.ReadBytes(65 * m_dhi.iChannelNumber); br.ReadBytes(BitConverter.ToInt32(br.ReadBytes(4), 0)); int iChannelNumberSize = m_dhi.iChannelNumber * 2; byte[] b = new byte[iChannelNumberSize]; long milePos = 0; int km_pre = 0; int meter_pre = 0; int km_currrent = 0; int meter_current = 0; int meter_between = 0; int km_index = 0; int meter_index = 2; long iArray = (br.BaseStream.Length - br.BaseStream.Position) / iChannelNumberSize; for (int i = 0; i < iArray; i++) { milePos = br.BaseStream.Position; b = br.ReadBytes(iChannelNumberSize); if (m_dhi.sDataVersion.StartsWith("3.")) { b = CITDataProcess.ByteXORByte(b); } if (i == 0) { //km_pre = (int)(BitConverter.ToInt16(b, km_index) / m_dcil[km_index].fScale + m_dcil[km_index].fOffset); //meter_pre = (int)(BitConverter.ToInt16(b, meter_index) / m_dcil[meter_index].fScale + m_dcil[meter_index].fOffset); km_pre = (int)(BitConverter.ToInt16(b, km_index)); meter_pre = (int)(BitConverter.ToInt16(b, meter_index)); } else { //km_currrent = (int)(BitConverter.ToInt16(b, km_index) / m_dcil[km_index].fScale + m_dcil[km_index].fOffset); //meter_current = (int)(BitConverter.ToInt16(b, meter_index) / m_dcil[meter_index].fScale + m_dcil[meter_index].fOffset); km_currrent = (int)(BitConverter.ToInt16(b, km_index)); meter_current = (int)(BitConverter.ToInt16(b, meter_index)); meter_between = (km_currrent - km_pre) * 4000 + (meter_current - meter_pre); if (Math.Abs(meter_between) > numericUpDown1.Value) { AutoIndexClass autoIndexCls = new AutoIndexClass(); autoIndexCls.milePos = milePos; autoIndexCls.km_current = km_currrent; autoIndexCls.meter_current = meter_current; autoIndexCls.km_pre = km_pre; autoIndexCls.meter_pre = meter_pre; autoIndexCls.meter_between = meter_between; autoIndexClsList.Add(autoIndexCls); } km_pre = km_currrent; meter_pre = meter_current; } } br.Close(); fs.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// 接口函数:计算功率谱 /// </summary> /// <param name="citFileName">cit全路径文件名</param> /// <param name="channelNameEn">英文通道名</param> /// <param name="channelNameCh">中文通道名</param> /// <param name="kmStart">起始里程</param> /// <param name="kmEnd">结束里程</param> /// <param name="fourierLen">傅里叶变换窗长</param> /// <param name="timeLen">时间步长</param> /// <returns>频率和幅值谱</returns> private List <String> SubProcess(String citFileName, String channelNameEn, String channelNameCh, float kmStart, float kmEnd, float fourierLen, float timeLen) { double[] retVal = new double[2]; CITDataProcess.DataHeadInfo dhi = cdp.GetDataInfoHeadNew(citFileName); int tds = dhi.iChannelNumber; long startPos = 0; long endPos = 0; using (FileStream fs = new FileStream(citFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { using (BinaryReader br = new BinaryReader(fs)) { byte[] b = new byte[tds * 2]; br.ReadBytes(120); //120 br.ReadBytes(65 * tds); //65 br.ReadBytes(BitConverter.ToInt32(br.ReadBytes(4), 0)); startPos = br.BaseStream.Position; endPos = br.BaseStream.Length; br.Close(); } fs.Close(); } //先把整条线的数据取出,然后再从中取出一段数 double[] d_tt = wdp.GetDataMileageInfoDouble(citFileName, tds, 4, CommonClass.listDIC[0].bEncrypt, CommonClass.listDIC[0].listIC, CommonClass.listDIC[0].bIndex, startPos, endPos, CommonClass.listDIC[0].sKmInc);//里程 double[] d_wx = cdp.GetSingleChannelData(citFileName, dataProcessing.GetChannelNumberByChannelName(citFileName, channelNameEn, channelNameCh)); int indexStart = 0; int indexEnd = d_tt.Length - 1; if (d_tt[0] < d_tt[d_tt.Length - 1]) { //增里程 for (int i = 0; i < d_tt.Length; i++) { if (d_tt[i] >= kmStart) { indexStart = i; break; } } for (int i = 0; i < d_tt.Length; i++) { if (d_tt[i] >= kmEnd) { indexEnd = i; break; } } } else { //减里程 for (int i = 0; i < d_tt.Length; i++) { if (d_tt[i] <= kmStart) { indexStart = i; break; } } for (int i = 0; i < d_tt.Length; i++) { if (d_tt[i] <= kmEnd) { indexEnd = i; break; } } } int len = indexEnd - indexStart + 1; double[] tt_new = new double[len]; double[] wx_new = new double[len]; Array.Copy(d_tt, indexStart, tt_new, 0, len); Array.Copy(d_wx, indexStart, wx_new, 0, len); List <String> str_retVal = glpc.Sub_Fourier_analysis(channelNameCh, tt_new, wx_new, fourierLen, timeLen); return(str_retVal); }
private void buttonConvertData_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(textBoxGeoPath.Text)) { MessageBox.Show("请先选择一个波形文件!"); return; } if (comboBoxLineName.SelectedIndex < 0 || comboBoxLineDir.SelectedIndex < 0 || comboBoxTrainCode.SelectedIndex < 0 || comboBoxRunDir.SelectedIndex < 0 || comboBoxKmInc.SelectedIndex < 0 || string.IsNullOrEmpty(textBoxStartPos.Text) || string.IsNullOrEmpty(textBoxEndPos.Text)) { MessageBox.Show("请完善基础信息!"); return; } for (int i = 0; i < listLineCodeAndName.Count; i++) { if (i == comboBoxLineName.SelectedIndex) { lineCode = listLineCodeAndName[i].lineCode; break; } } try { listGEO2CIT = new List <GEO2CITBind>(); String trainCode = (String)comboBoxTrainCode.SelectedItem; if (trainCode.Contains("999307")) { iType = 307;//iType=307时,geo转换有特殊情况 } else { iType = 1; } StreamReader sr = new StreamReader(dicTrainCodeAndConfigPath[trainCode], Encoding.Default); while (sr.Peek() != -1) { string[] sSplit = sr.ReadLine().Trim().Split(new char[] { '=' }); GEO2CITBind fa = new GEO2CITBind(); fa.sCIT = sSplit[0].Trim(); fa.sGEO = sSplit[1].Trim(); fa.sChinese = sSplit[2].Trim(); listGEO2CIT.Add(fa); } sr.Close(); dhi = new CITDataProcess.DataHeadInfo(); dhi.iDataType = 1; dhi.sDataVersion = "3.0.0"; dhi.sTrackCode = lineCode; dhi.sTrackName = comboBoxLineName.SelectedItem.ToString(); dhi.sTrain = comboBoxTrainCode.SelectedItem.ToString(); dhi.sDate = dateTimePickerData.Value.ToString("yyyy-MM-dd"); dhi.sTime = dateTimePickerTime.Value.ToString("HH:mm:ss"); dhi.iSmaleRate = 4; dhi.iRunDir = comboBoxRunDir.SelectedIndex; dhi.iKmInc = comboBoxKmInc.SelectedIndex; dhi.iDir = comboBoxLineDir.SelectedIndex + 1; //geoProcess.ConvertData(textBoxGeoPath.Text, textBoxGeoPath.Text + "_new" + ".cit", listGEO2CIT, 1, dhi); //MessageBox.Show("波形转换完成!\n新文件位置及名字:" + textBoxGeoPath.Text + "_new" + ".cit"); SetContralEnable(false); backgroundWorker1.RunWorkerAsync(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }