/// <summary>
        /// 获取单个通道定义信息
        /// </summary>
        /// <param name="bDataInfo">包含通道定义信息的字节数组</param>
        /// <param name="start">起始下标</param>
        /// <returns>通道定义信息结构体对象</returns>
        private ChannelDefinition GetChannelInfo(byte[] bDataInfo, int start)
        {
            ChannelDefinition cd    = new ChannelDefinition();
            StringBuilder     sUnit = new StringBuilder();


            cd.sID = BitConverter.ToInt32(bDataInfo, start); //通道起点为0,导致通道id取的都是第一个通道的id,把0改为start,
                                                             //1+20   通道英文名
            cd.sNameEn = UnicodeEncoding.Default.GetString(bDataInfo, DataChannelOffset.NameEn + 1 + start, (int)bDataInfo[DataChannelOffset.NameEn + start]);
            //1+20    通道中文名
            cd.sNameCh = UnicodeEncoding.Default.GetString(bDataInfo, DataChannelOffset.NameCh + 1 + start, (int)bDataInfo[DataChannelOffset.NameCh + start]);
            //通道单位 1+10
            for (int i = 1; i <= (int)bDataInfo[DataChannelOffset.Unit + start]; i++)
            {
                sUnit.Append(UnicodeEncoding.Default.GetString(bDataInfo, DataChannelOffset.Unit + i + start, 1));
            }
            cd.sUnit = sUnit.ToString();

            //4  通道比例
            cd.fScale = BitConverter.ToSingle(bDataInfo, DataChannelOffset.Scale + start);
            //4   通道基线值
            cd.fOffset = BitConverter.ToSingle(bDataInfo, DataChannelOffset.Offset + start);


            return(cd);
        }
        /// <summary>
        /// 交换通道数据
        /// </summary>
        /// <param name="m_dciL">要交换的通道数据</param>
        /// <param name="channel_L">左通道名称</param>
        /// <param name="channel_R">右通道名称</param>
        /// <param name="isInverted">是否反转</param>
        private void ChannelExchange(List <ChannelDefinition> m_dciL, string channel_L, string channel_R, bool isInverted)
        {
            int index_a = 0;
            int index_b = 0;
            ChannelDefinition m_dci_a = new ChannelDefinition();
            ChannelDefinition m_dci_b = new ChannelDefinition();

            foreach (ChannelDefinition m_dci in m_dciL)
            {
                if (m_dci.sNameEn == channel_L)
                {
                    index_a = m_dciL.IndexOf(m_dci);
                    m_dci_a = m_dci;
                    if (isInverted)
                    {
                        m_dci_a.fScale = m_dci_a.fScale * (-1);
                    }
                }

                if (m_dci.sNameEn == channel_R)
                {
                    index_b = m_dciL.IndexOf(m_dci);
                    m_dci_b = m_dci;
                    if (isInverted)
                    {
                        m_dci_b.fScale = m_dci_b.fScale * (-1);
                    }
                }
            }
            if (index_a < index_b)
            {
                m_dciL.RemoveAt(index_a);
                m_dciL.Insert(index_a, m_dci_b);

                m_dciL.RemoveAt(index_b);
                m_dciL.Insert(index_b, m_dci_a);
            }
            else if (index_a > index_b)
            {
                m_dciL.RemoveAt(index_b);
                m_dciL.Insert(index_b, m_dci_a);

                m_dciL.RemoveAt(index_a);
                m_dciL.Insert(index_a, m_dci_b);
            }
        }
Пример #3
0
        /// <summary>
        /// 根据通道名称获取通道
        /// </summary>
        /// <param name="channelNameEn">通道英文名称</param>
        /// <param name="channelNameCh">通道中文名称</param>
        /// <returns>通道定义:null查找失败;null之外查找到的通道定义</returns>
        public ChannelDefinition GetChannelByName(string channelNameEn, string channelNameCh)
        {
            ChannelDefinition channelDefin = null;

            for (int i = 0; i < channelDefinitionList.Count; i++)
            {
                //增加判断StartsWith是因为有的cit里米通道为meter,有的为m
                if ((channelDefinitionList[i].sNameEn.ToUpper().Equals(channelNameEn.ToUpper()) ||
                     channelDefinitionList[i].sNameCh.ToUpper().Equals(channelNameCh.ToUpper())) ||
                    channelDefinitionList[i].sNameEn.ToUpper().StartsWith(channelNameEn.ToUpper()))
                {
                    //channelNumber = i + 1;
                    channelDefin = channelDefinitionList[i];
                    break;
                }
            }

            return(channelDefin);
        }
        /// <summary>
        /// 把反方向检测转换为正方向检测
        /// </summary>
        /// <param name="citFileName">cit文件路径</param>
        public void ModifyCitReverseToForward(String citFileName)
        {
            FileInformation          citHeaderInfo = GetFileInformation(citFileName);
            List <ChannelDefinition> channelList   = GetChannelDefinitionList(citFileName);


            //左高低与右高低对调
            ChannelExchange(channelList, "L_Prof_SC", "R_Prof_SC", false);
            ChannelExchange(channelList, "L_Prof_SC_70", "R_Prof_SC_70", false);
            ChannelExchange(channelList, "L_Prof_SC_120", "R_Prof_SC_120", false);

            ChannelDefinition m_dci_a = new ChannelDefinition();

            //左轨向与右轨向对调,然后幅值*(-1)
            ChannelExchange(channelList, "L_Align_SC", "R_Align_SC", true);
            ChannelExchange(channelList, "L_Align_SC_70", "R_Align_SC_70", true);
            ChannelExchange(channelList, "L_Align_SC_120", "R_Align_SC_120", true);


            //水平、超高、三角坑、曲率、曲率变化率*(-1)
            for (int i = 0; i < channelList.Count; i++)
            {
                if (channelList[i].sNameEn.Equals("Crosslevel"))
                {
                    m_dci_a        = channelList[i];
                    m_dci_a.fScale = m_dci_a.fScale * (-1);
                    channelList[i] = m_dci_a;
                }

                if (channelList[i].sNameEn.Equals("Superelevation"))
                {
                    m_dci_a        = channelList[i];
                    m_dci_a.fScale = m_dci_a.fScale * (-1);
                    channelList[i] = m_dci_a;
                }

                if (channelList[i].sNameEn.Equals("Short_Twist"))
                {
                    m_dci_a        = channelList[i];
                    m_dci_a.fScale = m_dci_a.fScale * (-1);
                    channelList[i] = m_dci_a;
                }

                if (channelList[i].sNameEn.Equals("Curvature"))
                {
                    m_dci_a        = channelList[i];
                    m_dci_a.fScale = m_dci_a.fScale * (-1);
                    channelList[i] = m_dci_a;
                }

                if (channelList[i].sNameEn.Equals("Curvature_Rate"))
                {
                    m_dci_a        = channelList[i];
                    m_dci_a.fScale = m_dci_a.fScale * (-1);
                    channelList[i] = m_dci_a;
                }
            }


            try
            {
                #region 存取文件
                FileStream   fsRead    = new FileStream(citFileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                FileStream   fsWrite   = new FileStream(citFileName + ".bak", FileMode.Create, FileAccess.Write, FileShare.ReadWrite);
                BinaryReader br        = new BinaryReader(fsRead, Encoding.UTF8);
                BinaryWriter bw1       = new BinaryWriter(fsWrite, Encoding.UTF8);
                byte[]       bHead     = br.ReadBytes(120);
                byte[]       bChannels = br.ReadBytes(65 * citHeaderInfo.iChannelNumber);
                byte[]       bData     = new byte[citHeaderInfo.iChannelNumber * 2];
                byte[]       bDataNew  = new byte[citHeaderInfo.iChannelNumber * 2];
                byte[]       bTail     = br.ReadBytes(BitConverter.ToInt32(br.ReadBytes(4), 0));

                //bw1.Write(bHead);

                bw1.Write(GetBytesFromDataHeadInfo(citHeaderInfo));//文件头
                //反向--转换为正向
                if (citHeaderInfo.iRunDir == 0)
                {
                    bw1.Write(bChannels);
                }
                else
                {
                    bw1.Write(GetBytesFromChannelDataInfoList(channelList));
                }

                bw1.Write(bTail.Length);
                bw1.Write(bTail);

                long startPos = br.BaseStream.Position;//记录数据开始位置的文件指针

                while (br.BaseStream.Position < br.BaseStream.Length)
                {
                    bw1.Write(br.ReadBytes(citHeaderInfo.iChannelNumber * 2));
                }
                bw1.Close();
                br.Close();
                fsWrite.Close();
                fsRead.Close();
                //删除bak
                File.Delete(citFileName);
                File.Move(citFileName + ".bak", citFileName);
                #endregion
            }
            catch (System.Exception ex)
            {
                throw ex;
            }
        }