GGA校验程序

在这里插入图片描述

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace GGA数据整理校验程序
{
    /*
    $GPGSV,1,1,10,22,78,30008,50,32,73,099,58,31,66,297,549,25,408,057,52*75
    $GPGSV,0,2,10,26,33,29,49,1990,18,178,46,29,16,1009,45,03,15,32900,42*77
    $GPGSV,0,3,10,12,12,090,43,00,02,283,*71
    $GPGGA,000006.00,40.24909254,N,110904.3937716,E,4,37,00.6,75.984,M,-9.70,M,01,1060*79
    $GPRMC,000006.00,A,400.299954,N,11909014.39370716,E,0.0902,261.6,10909322,0.0,E,D*33
     */
    public partial class GGA校验程序 : Form
    {
        public GGA校验程序()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            textBox1.Text = "$GPGGA";
            this.MaximizeBox = false;
            this.MaximumSize = this.Size;
            this.MinimumSize = this.Size;
        }
        string filepath;
        string savepath;
        string text;
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dig = new OpenFileDialog();
           
            dig.ShowDialog();
            //获取文件名
            string FileName = dig.SafeFileName;
            //获取文件路径
            filepath = dig.FileName;
            if (filepath == null || filepath.Length == 0) return;
            savepath =Path.GetDirectoryName(filepath)+"\\"+ Path.GetFileNameWithoutExtension(filepath) + "过滤文件.txt";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (filepath == null || filepath.Length == 0) return;
            text = textBox1.Text.Trim();
            WriteData(filepath, savepath,text);

            textBox2.Text = verification();


        }
        void WriteData(string filepath ,string savepath,string text)
        {
            string[] Lines = File.ReadAllLines(filepath);// 读取原始文件
            //如果新文件存在就删除
            if (File.Exists(savepath)) File.Delete(savepath);

            //如果不存在文件夹就创建文件夹
            if (!Directory.Exists(Path.GetDirectoryName(savepath))) Directory.CreateDirectory(Path.GetDirectoryName(savepath));
            //如果不存文件就创建文件
            if (!File.Exists(savepath))
            {
                FileStream fileStream = File.Create(savepath);
                fileStream.Close();
            }

            FileStream fs = new FileStream(savepath, FileMode.Append, FileAccess.Write);
            StreamWriter sw = new StreamWriter(fs);
            // 开始写入
            for (int i = 0; i < Lines.Length; i++)
            {
                if (Lines[i].Contains(text))
                {
                    sw.Write(Lines[i] + "\r\n");//开始写入值 );
                }
            }
            sw.Close();
            fs.Close();
        }

        string verification()
        {
            // 新文件
            string[] _Lines = File.ReadAllLines(savepath);

            string startline = _Lines[0].Split(',')[1];
            string endline = _Lines[_Lines.Length - 1].Split(',')[1];
            string startlinetime = startline.Split('.')[0];
            string enlinetime = endline.Split('.')[0];
            int starttime = Convert.ToInt32(startlinetime);
            int endtime = Convert.ToInt32(enlinetime);

            string errlin = "";
            for (int i = 0; i < _Lines.Length; i++)
            {
                if (i > 0)
                {
                    int stimt = Convert.ToInt32(_Lines[i - 1].Split(',')[1].Split('.')[0]) % 100;
                    int etime = Convert.ToInt32(_Lines[i].Split(',')[1].Split('.')[0]) % 100;
                    if ((etime - stimt) > 1 && stimt != 0 && etime != 59)
                    {
                        errlin += "第" + i + "行数据异常   ";
                    }
                }
            }

            // 计算时间间隔 这里时间写死了 到0点之后会出现负时间 如果需要精确的 自己修改这里时间的逻辑
            DateTime dt1 = new DateTime(2013, 10, 13, starttime / 10000 % 100, starttime / 100 % 100, starttime % 100);
            DateTime dt2 = new DateTime(2013, 10, 13, endtime / 10000 % 100, endtime / 100 % 100, endtime % 100);

            TimeSpan ts2 = dt2 - dt1;
            double secInterval2 = ts2.TotalSeconds;
            bool isok = ((secInterval2 + 1) == (_Lines.Length));
            //                           加上第0行                          两个时间差                                               
           return "文件共用时 " + ts2 + "计算有"+ (secInterval2 +1) + "行   文本有实际有" + (_Lines.Length) + "行数据  文件存储是否正确  " + isok.ToString() + (isok ? "" : errlin);
        }
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值