#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QFileDialog>
#include <string>
#include <math.h>       /* cos */

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(findCliecked()));
    connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(parseLogCliecked()));
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::findCliecked()
{
    QStringList    fileNameList;
    QFileDialog* fd = new QFileDialog(this);
    fd->resize(240,320);
    //fd->setFixedHeight(tr("Allfile(*.*);;vplog(*.vpl)")); //?置文件??器
    fd->setViewMode(QFileDialog::List);
    if ( fd->exec() == QDialog::Accepted )
    {
        fileNameList = fd->selectedFiles();
        ui->textEdit->setText(fileNameList[0]);
    }
    else
    {
        fd->close();
    }
}

void MainWindow::parseLogCliecked()
{
    QString qfilename = ui->textEdit->toPlainText();
    if (qfilename.isEmpty())
    {
        return;
    }

std::string filename = qfilename.toStdString();
    FILE * fp = fopen(filename.c_str(),"rb");
    FILE * wfp = NULL;
    if (fp)
    {

int n = filename.rfind('/');
        std::string cvsfilename;
        if (n != std::string::npos)
        {
            cvsfilename = filename.substr(0,n+1);
            cvsfilename += "vp.csv";
            wfp = fopen(cvsfilename.c_str(),"wb");
            if (!wfp)
            {
                fclose(fp);
                return;
            }
            char buff[] = "Time,X,Y,Z\n";
            fwrite(buff, 1, strlen(buff),wfp);
        }

char line[1024] = {0};
        char outline[1024] = {0};

while(fgets(line,1024,fp))
        {
            std::string strline = line;
            std::string strtime = parseLine(strline,"time:","]");
            int m = strtime.find(',');
            if (m != std::string::npos)
            {
                strtime.replace(m,1," ");
            }
            std::string strX = parseLine(strline,"X:",",");
            std::string strY = parseLine(strline,"Y:",",");
            std::string strZ = parseLine(strline,"Z:",",");
            if (!strX.empty())
            {
                sprintf(outline,"%s,%s,%s,%s\n",strtime.c_str(),strX.c_str(),strY.c_str(),strZ.c_str());
                fwrite(outline,1,strlen(outline),wfp);
            }
        }
    }
    fclose(fp);
    fclose(wfp);
    QMessageBox message(QMessageBox::NoIcon, "Title", "finished.");
    message.exec();
}

std::string MainWindow::parseLine(const std::string & strline, const char* start,
                      const char* end)
{
    std::string strResutl;
    int pos = strline.find(start);
    if (pos != std::string::npos)
    {
        int pos2= strline.find(end,pos);
        if (std::string::npos != pos2)
        {
            strResutl = strline.substr(pos+2,(pos2 -(pos+2)));
        }
    }

return strResutl;
}

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QFileDialog>
#include <string>
#include <math.h>       /* cos */

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(findCliecked()));
    connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(parseLogCliecked()));
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::findCliecked()
{
    QStringList    fileNameList;
    QFileDialog* fd = new QFileDialog(this);
    fd->resize(240,320);
    //fd->setFixedHeight(tr("Allfile(*.*);;vplog(*.vpl)")); //?置文件??器
    fd->setViewMode(QFileDialog::List);
    if ( fd->exec() == QDialog::Accepted )
    {
        fileNameList = fd->selectedFiles();
        ui->textEdit->setText(fileNameList[0]);
    }
    else
    {
        fd->close();
    }
}

void MainWindow::parseLogCliecked()
{
    QString qfilename = ui->textEdit->toPlainText();
    if (qfilename.isEmpty())
    {
        return;
    }

std::string filename = qfilename.toStdString();
    FILE * fp = fopen(filename.c_str(),"rb");
    FILE * wfp = NULL;
    if (fp)
    {

int n = filename.rfind('/');
        std::string cvsfilename;
        if (n != std::string::npos)
        {
            cvsfilename = filename.substr(0,n+1);
            cvsfilename += "vp.csv";
            wfp = fopen(cvsfilename.c_str(),"wb");
            if (!wfp)
            {
                fclose(fp);
                return;
            }
            char buff[] = "Time,X,Y,Z\n";
            fwrite(buff, 1, strlen(buff),wfp);
        }

char line[1024] = {0};
        char outline[1024] = {0};

while(fgets(line,1024,fp))
        {
            std::string strline = line;
            std::string strtime = parseLine(strline,"time:","]");
            int m = strtime.find(',');
            if (m != std::string::npos)
            {
                strtime.replace(m,1," ");
            }
            std::string strX = parseLine(strline,"X:",",");
            std::string strY = parseLine(strline,"Y:",",");
            std::string strZ = parseLine(strline,"Z:",",");
            if (!strX.empty())
            {
                sprintf(outline,"%s,%s,%s,%s\n",strtime.c_str(),strX.c_str(),strY.c_str(),strZ.c_str());
                fwrite(outline,1,strlen(outline),wfp);
            }
        }
    }
    fclose(fp);
    fclose(wfp);
    QMessageBox message(QMessageBox::NoIcon, "Title", "finished.");
    message.exec();
}

std::string MainWindow::parseLine(const std::string & strline, const char* start,
                      const char* end)
{
    std::string strResutl;
    int pos = strline.find(start);
    if (pos != std::string::npos)
    {
        int pos2= strline.find(end,pos);
        if (std::string::npos != pos2)
        {
            strResutl = strline.substr(pos+2,(pos2 -(pos+2)));
        }
    }

return strResutl;
}

FILE operattion的更多相关文章

  1. 记一个mvn奇怪错误: Archive for required library: 'D:/mvn/repos/junit/junit/3.8.1/junit-3.8.1.jar' in project 'xxx' cannot be read or is not a valid ZIP file

    我的maven 项目有一个红色感叹号, 而且Problems 存在 errors : Description Resource Path Location Type Archive for requi ...

  2. HTML中上传与读取图片或文件(input file)----在路上(25)

    input file相关知识简例 在此介绍的input file相关知识为: 上传照片及文件,其中包括单次上传.批量上传.删除照片.增加照片.读取图片.对上传的图片或文件的判断,比如限制图片的张数.限 ...

  3. logstash file输入,无输出原因与解决办法

    1.现象 很多同学在用logstash input 为file的时候,经常会出现如下问题:配置文件无误,logstash有时一直停留在等待输入的界面 2.解释 logstash作为日志分析的管道,在实 ...

  4. input[tyle="file"]样式修改及上传文件名显示

    默认的上传样式我们总觉得不太好看,根据需求总想改成和上下结构统一的风格…… 实现方法和思路: 1.在input元素外加a超链接标签 2.给a标签设置按钮样式 3.设置input[type='file' ...

  5. .NET平台开源项目速览(16)C#写PDF文件类库PDF File Writer介绍

    1年前,我在文章:这些.NET开源项目你知道吗?.NET平台开源文档与报表处理组件集合(三)中(第9个项目),给大家推荐了一个开源免费的PDF读写组件 PDFSharp,PDFSharp我2年前就看过 ...

  6. [笔记]HAproxy reload config file with uninterrupt session

    HAProxy is a high performance load balancer. It is very light-weight, and free, making it a great op ...

  7. VSCode调试go语言出现:exec: "gcc": executable file not found in %PATH%

    1.问题描述 由于安装VS15 Preview 5,搞的系统由重新安装一次:在用vscdoe编译go语言时,出现以下问题: # odbcexec: "gcc": executabl ...

  8. input type='file'上传控件假样式

    采用bootstrap框架样式 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> &l ...

  9. FILE文件流的中fopen、fread、fseek、fclose的使用

    FILE文件流用于对文件的快速操作,主要的操作函数有fopen.fseek.fread.fclose,在对文件结构比较清楚时使用这几个函数会比较快捷的得到文件中具体位置的数据,提取对我们有用的信息,满 ...

随机推荐

  1. 关于ES6 Class语法相关总结

    关于ES6,其实网上已经有很多的资料可供查询,教程可参考阮一峰大神的ES6入门,本文只是对Class这一语法做一个总结: 一.Class基本语法 constructor方法 constructor是类 ...

  2. 正则表达式 grep文本查询 sed流处理 应用

    一.正则表达: ^:以什么什么开头,^a:以a字符开头 $:以什么什么结尾,b$:以b字符结尾 *:左边字符0-无穷个 +:左边字符1-无穷个 .:代表单字符 ?:前导字符为零个或1个 {n}:左面字 ...

  3. 【转】C# Graphics类详解

    Brush 类 .NET Framework 4 定义用于填充图形形状(如矩形.椭圆.饼形.多边形和封闭路径)的内部的对象. 属于命名空间:  System.Drawing 这是一个抽象基类,不能进行 ...

  4. 基本控件文档-UISwitch属性

    CHENYILONG Blog 基本控件文档-UISwitch属性 Fullscreen     UISwitch属性 技术博客http://www.cnblogs.com/ChenYilong/ 新 ...

  5. 天梯赛 L2-024. (并查集) 部落

    题目链接 题目描述 在一个社区里,每个人都有自己的小圈子,还可能同时属于很多不同的朋友圈.我们认为朋友的朋友都算在一个部落里,于是要请你统计一下,在一个给定社区中,到底有多少个互不相交的部落?并且检查 ...

  6. python概念-常用模块之究竟你是什么鬼

    模块: 一个模块就是一个包含了python定义和声明的文件,文件名就是模块名字加上.py的后缀. 说白了,就是一个python文件中定义好了类和方法,实现了一些功能,可以被别的python文件所调用 ...

  7. NodeJS让前端与后端更友好的分手

    学问   最近“上层建筑”在兴起国学热,所以公司几个月前决定开发一款名叫“学问”的有关于国学的app.     APP的详情页面还是由web来显现具体内容,有些类似于新闻页,图文混排什么的web是最适 ...

  8. 字符串hash&&对字符串hash的理解

     对字符串hash的一些总结: 1,首先,我们在转化的时候,取底的时候一般是取131这些数,因为要避免不同的字符串对应相同的hash值这种情况的出现.如果卡精度的时候,我们可以采取双模数的方式尽量减少 ...

  9. 字典树&&01字典树专题&&对字典树的理解

    对于字典树和01字典树的一点理解: 首先,字典树建树的过程就是按照每个数的前缀来的,如果你要存储一个全小写字母字符串,那么这个树每一个节点最多26个节点,这样的话,如果要找特定的单词的话,按照建树的方 ...

  10. 2016.6.19——Length of Last Word

    Length of Last Word 本题收获: 1.str.size()为负 2.size_t引发的死循环 3.题目思路,有时在写代码时很不清楚边界条件的输出值是什么,若为面试,一定要问清楚. 题 ...