/// <summary> /// 里程与修正后的里程做对比,然后根据修正后的里程找到点(文件中的指针) /// </summary> /// <param name="addFileName">idf文件</param> /// <param name="mi">输入的里程(单位为公里)</param> /// <returns>当前点在修正后的里程中相对应的文件指针</returns> private long MeterToPointNew(DataInfoClass dic, float mi, out IndexStaClass indexStaClsout, out int resultType) { List <IndexStaClass> listIndexStaCls = CommonClass.wdp.GetDataIndexInfo(dic.sAddFile); float len = 0; long currentPos = 0; indexStaClsout = new IndexStaClass(); resultType = 0;//代表在校正里程里没有找到里程点,并且在文件原始里程中也找不到。 foreach (IndexStaClass indexStaCls in listIndexStaCls) { if (dic.sKmInc == "增") { if (mi > float.Parse(indexStaCls.lStartMeter) && mi <= float.Parse(indexStaCls.LEndMeter)) { len = mi - float.Parse(indexStaCls.lStartMeter); } } else { if (mi < float.Parse(indexStaCls.lStartMeter) && mi >= float.Parse(indexStaCls.LEndMeter)) { len = float.Parse(indexStaCls.lStartMeter) - mi; } } if (len != 0) { currentPos = indexStaCls.lStartPoint + (long)((float)(len * indexStaCls.lContainsPoint) / float.Parse(indexStaCls.lContainsMeter)) * dic.fScale.Length * 2; indexStaClsout = indexStaCls; resultType = 1;//代表在校正后的里程范围中找到测量点 break; } } if (len == 0) { /* * 遍历结束,里程点不在indexStaClass的范围内。有两种情况: * 一:输入的里程点不在cit文件的里程范围内。返回0. * 二:cit文件还没有经过里程校正,直接寻找文件中的里程,找到则返回,否则返回0. */ currentPos = CommonClass.wdp.MeterToPoint(dic.sFilePath, (long)(mi * 10000), 4, dic.fOffset.Length, dic.bEncrypt); if (currentPos != 0) { resultType = 2;//代表在文件中的原始数据找到测量点 } } //FileStream fs = new FileStream(dic.sFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); //BinaryReader br = new BinaryReader(fs); //br.BaseStream.Position = indexStaClsout.lStartPoint; //Byte[] b = br.ReadBytes(dic.fScale.Length * 2); //if (dic.bEncrypt) //{ // b = WaveformDataProcess.ByteXORByte(b); //} //short km = BitConverter.ToInt16(b, 0); //short count = BitConverter.ToInt16(b, 2); return(currentPos); }
private string GetValuesOfChannelPerCit(string citHead, DataInfoClass dic, String[] positions, int m_meterageRadius, string[] channelChinNames) { StringBuilder retSB = new StringBuilder(); string tmpStr = null; foreach (string position in positions) { IndexStaClass indexStaCls; int resultType; int dotNum = 0; string tips = null; long currentPos = MeterToPointNew(dic, float.Parse(position), out indexStaCls, out resultType); if (resultType == 0) {//测量点在校正里程范围内找不到,并且在文件原始里程里也找不到 tmpStr = ""; StringBuilder sb = new StringBuilder(); foreach (string channelName in channelChinNames) { sb.AppendFormat(",{0}", "0"); } sb.Remove(0, 1); tmpStr = sb.ToString(); tips = "测量点在校正里程和文件原始里程范围内找不到"; } else { if (resultType == 1) {//测量点在校正里程范围内。 dotNum = GetDotFromMeterageRadius(m_meterageRadius, indexStaCls); tips = "测量点在校正里程范围内"; } else if (resultType == 2) {//测量点在文件原始里程范围内 dotNum = m_meterageRadius * 4; tips = "测量点在文件原始里程内"; } //int dotNum = GetDotFromMeterageRadius(m_meterageRadius, indexStaCls); long startPos = currentPos - dotNum * dic.fScale.Length * 2; long endPos = currentPos + dotNum * dic.fScale.Length * 2; tmpStr = GetMaxValuesOfChannels(dic, startPos, endPos, channelChinNames); } retSB.AppendFormat("{0},{1},{2},{3}", citHead, position, tmpStr, tips); retSB.AppendLine(); } return(retSB.ToString()); }
/// <summary> /// 根据通道Id把文件中起始点和结束点之间的绝对值最大的点的原始值 /// </summary> /// <param name="dic">cit文件</param> /// <param name="startPos">起始指针</param> /// <param name="endPos">结束指针</param> /// <param name="channelId">通道号</param> /// <returns>起始指针和结束指针之间绝对值最大的点的值</returns> private float GetMaxValuesOfChannelById(DataInfoClass dic, long startPos, long endPos, ChannelsClass channelCls) { try { FileStream fs = new FileStream(dic.sFilePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); BinaryReader br = new BinaryReader(fs); int gjtds = dic.fScale.Length; bool bEncrypt = dic.bEncrypt; byte[] b = new byte[gjtds * 2]; long findpos = startPos; br.BaseStream.Position = startPos; List <float> dataArray = new List <float>(); while (findpos < endPos) { b = br.ReadBytes(gjtds * 2); if (bEncrypt) { b = WaveformDataProcess.ByteXORByte(b); } short km = BitConverter.ToInt16(b, 0); short count = BitConverter.ToInt16(b, 2); short channelValueS = BitConverter.ToInt16(b, channelCls.Id * 2); float channelValueF = channelValueS / dic.fScale[channelCls.Id] + dic.fOffset[channelCls.Id]; dataArray.Add(channelValueF); findpos += gjtds * 2; } br.Close(); fs.Close(); float fRet = MaxValueOfDataArray(dataArray.ToArray()); return(fRet); } catch { return(0); } }
private string GetMaxValuesOfChannels(DataInfoClass dic, long startPos, long endPos, string[] channelNames) { StringBuilder retSB = new StringBuilder(); string tmpStr = null; foreach (string channelName in channelNames) { ChannelsClass m_channelCls = null; foreach (ChannelsClass channelCls in dic.listCC) { if (channelCls.ChineseName == channelName) { m_channelCls = channelCls; break; } } tmpStr = GetMaxValuesOfChannelById(dic, startPos, endPos, m_channelCls).ToString(); retSB.AppendFormat("{0},", tmpStr); } retSB.Remove(retSB.Length - 1, 1); return(retSB.ToString()); }