form1.cs

来自「读取雷达站上传的新一代天气雷达报警信息及参数文件。」· CS 代码 · 共 345 行

CS
345
字号
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.IO;

namespace SrsiRead
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public enum eSCANMODE
        {
            NONE,		//无扫描
            PPI,		//PPI扫描
            RHI,		//RHI扫描
            VOL		//VOL扫描
        }


        [StructLayout(LayoutKind.Sequential, Pack = 1)]
        public struct tagREPORT
        {
            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
            public char[] sRadarType1;		//雷达型号
            public float fVersion;		//文件版本  	
            public byte ucYear1;		//上报时间的年千百位(19-20)
            public byte ucYear2;		//上报时间的年十个位(00-99)
            public byte ucMonth;		//上报时间的月(1-12)
            public byte ucDay;			//上报时间的日(1-31)
            public byte ucHour;			//上报时间的时(0-23)
            public byte ucMinute;		//上报时间的分(0-59)
            public byte ucSecond;		//上报时间的秒(0-59)

            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 30)]
            public char[] sCountry;		//国家名

            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
            public char[] sProvince;		//省名

            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 40)]
            public char[] sStation;		//站名

            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
            public char[] sStationNumber;	//区站号

            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 20)]
            public char[] sRadarType2;		//雷达型号
            public ushort usLongitudeDegree;	//经度(度)
            public byte ucLongitudeMinute;	//经度(分)
            public byte ucLongitudeSecond;	//经度(秒)
            public ushort usLatitudeDegree;	//纬度(度)
            public byte ucLatitudeMinute;	//纬度(分)
            public byte ucLatitudeSecond;	//纬度(秒)
            public float fHeight;		//海拔高度(m)
            public eSCANMODE ScanMode;		//扫描模式

            [MarshalAs(UnmanagedType.ByValArray, SizeConst = 10)]
            public char[] sVOLMode;		//体扫模式(当VOL时) PM1-降水模式1 PM2-降水模式2 GM-警戒模式 UM-用户模式
            public bool bRemoteControl;		//遥控状态 TRUE-遥控  FALSE-本控
            public bool bFilter;		//滤波状态 TRUE-有  FALSE-无
            public float fPower;			//发射功率(kW)
            public float fNoise;			//噪声电平(dB)
            public float fAntennaGain;		//天线增益(dB)
            public float fHorizontalBeamWidth;	//水平波束宽度(°)
            public float fVerticalBeamWidth;	//垂直波束宽度(°)
            public float fAmountLoss;		//损耗(dB)
            public float fBandWidth;		//中频带宽(MHz)
            public float fPulseWidth;		//脉冲宽度(us)
            public float fWavelength;		//波长(m)
            public float fC;			//雷达常数
        }

        

        

        private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {

                if (openFileDialog1.OpenFile().Length != 226)
                {
                    MessageBox.Show("参数文件已破坏或文件不是参数文件!\n\n请正确选择!", "!!!错误", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                else
                {
                    textBox1.Text = "请选择参数文件!";   //刷新文本框中的显示
                    
                    textBox1.Text =  "文件名:" + openFileDialog1.FileName + "\r\n";

                    FileStream fs = new FileStream(openFileDialog1.FileName, FileMode.Open, FileAccess.Read);
                    BinaryReader br = new BinaryReader(fs);

                    byte[] b = br.ReadBytes((int)fs.Length);

                    IntPtr intprt = GCHandle.Alloc(b, GCHandleType.Pinned).AddrOfPinnedObject();

                    int isize = Marshal.SizeOf(typeof(tagREPORT));

                    tagREPORT t = (tagREPORT)Marshal.PtrToStructure(intprt, typeof(tagREPORT));

                    br.Close();

                    fs.Close();

                   

/////////////////////////////////以下为具体参数信息读取部分//////////////////////////////////////////////////////
/////////////////////////////////
                    /////////////////雷达基本信息//////////////////
                    textBox1.AppendText( "\r\n" + "雷达基本信息" + "\r\n" ); 
                    //文件生成时间
                    //观测日期
                    string year2;
                    if (t.ucYear2 < 10)
                    {
                        year2 = "0" + t.ucYear2.ToString();
                    }
                    else year2 = t.ucYear2.ToString();

                    textBox1.AppendText("\r\n" + "观测日期:" + t.ucYear1 + year2.ToString() + "年" + t.ucMonth + "月" + t.ucDay + "日");

                    //观测时间
                    string hour1, minute, second;
                    if (t.ucHour < 10)
                    {
                        hour1 = "0" + t.ucHour.ToString();
                    }
                    else hour1 = t.ucHour.ToString();

                    if (t.ucMinute < 10)
                    {
                        minute = "0" + t.ucMinute.ToString();
                    }
                    else minute = t.ucMinute.ToString();

                    if (t.ucSecond < 10)
                    {
                        second = "0" + t.ucSecond.ToString();
                    }
                    else second = t.ucSecond.ToString();

                    textBox1.AppendText("\r\n" + "观测时间:" + hour1 + ":" + minute + ":" + second + "(北京时)");

                    int IntHour = t.ucHour - 8;
                    string hour2 = IntHour.ToString();
                    if (IntHour < 10)
                    {
                        hour2 = "0" + IntHour.ToString();
                    }
                    else hour2 = IntHour.ToString();

                    textBox1.AppendText("    " + hour2 + ":" + minute + ":" + second + "(世界时)");
///////////////////////////////////
                    //观测站点
                    
                    //读国家名
                    int i = 0;
                    string country = null;
                    while (t.sCountry[i] != 0 && i < 30)
                    {
                        country = country + t.sCountry[i].ToString();
                        i++;
                    }

                    //读省名
                    i = 0;
                    string province = null;
                    while (t.sProvince[i] != 0 && i < 20)
                    {
                        province = province + t.sProvince[i].ToString();
                        i++;
                    }

                    //读站名
                    i = 0;
                    string station = null;
                    while (t.sStation[i] != 0 && i < 40)
                    {
                        station = station + t.sStation[i].ToString();
                        i++;
                    }
                    textBox1.AppendText("\r\n" + "观测站点:" + country + "  " +  province + "  " +  station);
                    
                    //区站号
                    i = 0;
                    string stationnum = null;
                    while (t.sStation[i] != 0 && i < 10)
                    {
                        stationnum = stationnum + t.sStationNumber[i].ToString();
                        i++;
                    }
                    textBox1.AppendText("\r\n" + "区站号:" + stationnum);


                    //雷达型号
                    i = 0;
                    string radartype = null;
                    while (t.sStation[i] != 0 && i < 20)
                    {
                        radartype = radartype + t.sRadarType1[i].ToString();
                        i++;
                    }
                    textBox1.AppendText("\r\n" + "雷达型号:" + radartype);

                    //天线经度
                    textBox1.AppendText("\r\n" + "天线经度:" + t.usLongitudeDegree + "°" + t.ucLongitudeMinute + "′" + t.ucLongitudeSecond + "″E");
                   
                    //天线纬度
                    textBox1.AppendText("\r\n" + "天线纬度:" + t.usLatitudeDegree + "°" + t.ucLatitudeMinute + "′" + t.ucLatitudeSecond + "″N");
                    
                    //海拔高度
                    textBox1.AppendText("\r\n" + "海拔高度:" + t.fHeight + "m" + "\r\n\r\n");


                    /////////////////雷达状态参数//////////////////
                    textBox1.AppendText("\r\n" + "雷达状态参数" + "\r\n"); 
                    
                    //扫描模式
                    textBox1.AppendText("\r\n" + "扫描模式:" + t.ScanMode);
                   
                    //体扫模式
                    i = 0;
                    string volmode = null;
                    while (t.sStation[i] != 0 && i < 10)
                    {
                        volmode = volmode + t.sVOLMode[i].ToString();
                        i++;
                    }
                    textBox1.AppendText("\r\n" + "体扫模式:" + volmode);
                   
              //////////////////////////
                    /*
                    if (volmode == "PM1\08")
                    {
                        textBox1.AppendText("(降水模式1)");
                    }
                    else if (volmode.ToString() == "PM2")
                    {
                        textBox1.AppendText("(降水模式2)");
                    }
                    else
                    {
                        textBox1.AppendText("(警戒模式)");
                    }
                     *///////////////////////////////////
                    
                    //遥控状态
                    if (t.bRemoteControl == true)
                    {
                        textBox1.AppendText("\r\n" + "遥控状态:遥控");
                    }
                    else textBox1.AppendText("\r\n" + "遥控状态:本控");
                    
                    //滤波状态
                    if (t.bFilter == true)
                    {
                        textBox1.AppendText("\r\n" + "滤波状态:有滤波");
                    }
                    else textBox1.AppendText("\r\n" + "滤波状态:无滤波");
                    
                    //发射功率
                    textBox1.AppendText("\r\n" + "发射功率:" + t.fPower + "kw");
                    
                    //噪声电平
                    textBox1.AppendText("\r\n" + "噪声电平:" + t.fNoise + "dB");
                    
                    //天线增益
                    textBox1.AppendText("\r\n" + "天线增益:" + t.fAntennaGain + "dB");
                    
                    //水平波束宽度
                    textBox1.AppendText("\r\n" + "水平波束宽度:" + (float)t.fHorizontalBeamWidth + "°");
                    
                    //垂直波束宽度
                    textBox1.AppendText("\r\n" + "垂直波束宽度:" + t.fVerticalBeamWidth + "°");
                    
                    //系统损耗
                    textBox1.AppendText("\r\n" + "系统损耗:" + t.fAmountLoss + "dB");
                    
                    //中频带宽
                    textBox1.AppendText("\r\n" + "中频带宽:" + t.fBandWidth + "MHz");
                    
                    //脉冲宽度
                    textBox1.AppendText("\r\n" + "脉冲宽度:" + t.fPulseWidth + "us");
                    
                    //波长
                    textBox1.AppendText("\r\n" + "波长:" + t.fWavelength*100 + "cm");
                    
                    //雷达常数
                    textBox1.AppendText("\r\n" + "雷达常数:" + t.fC);
 
                }
            }
        }

        private void 刷新ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            textBox1.Text = "请选择参数文件!";
        }

        private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string filename = "C:\\雷达参数信息.txt";
            StreamWriter sw = new StreamWriter(filename);
            if (sw != null)
            {
                if (textBox1.Text != "请选择参数文件!")
                {
                    sw.Write(textBox1.Text);
                    sw.Close();
                    MessageBox.Show("雷达参数信息已保存到C:\\雷达参数信息.txt.\n\r\n请查看!", "雷达参数信息保存", MessageBoxButtons.OK);


                }
                else
                {
                    sw.Close();
                    MessageBox.Show("没有打开文件!", "!错误", MessageBoxButtons.OK);

                }
            }

        }

        private void 退出XToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void 关于AToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("       雷达参数信息生成系统1.0           \n\n\n       兰州中心气象台研制开发\n         All Rights Reserved.", "关于...", MessageBoxButtons.OK);
        }
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?