#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. linux学习记录.5.git & github

    参考 https://www.linuxidc.com/Linux/2016-11/136769.htm 安装 安装 Git: apt-get install git 查看当前版本: git --ve ...

  2. 《区块链100问》第82集:应用类项目Golem

    Golem是第一个基于以太坊区块链打造的计算资源交易平台.通过区块链,Golem能链接全球的算力资源,从而实现计算能力的全球共享.应用所有者和个体用户(算力“请求方”)可以点对点地从其他用户处租用算力 ...

  3. Go语言的接口interface、struct和组合、继承

    Go语言的interface概念相对于C++中的基类,通过interface来实现多态功能. 在C++中,当需要实现多态功能时,步骤是首先定义一个基类,该基类使用虚函数或者纯虚函数抽象了所有子类会用到 ...

  4. 关于runOnUiThread()与Handler两种更新UI的方法

    在Android开发过程中,常需要更新界面的UI.而更新UI是要主线程来更新的,即UI线程更新.如果在主线线程之外的线程中直接更新页面显示常会报错.抛出异常:android.view.ViewRoot ...

  5. 深拷贝数组 np.copy

    数组对象自带了浅拷贝和深拷贝的方法,但是一般用深拷贝多一些: 代码如下: >>> a = np.ones((2,2)) >>> b = a >>> ...

  6. Oracle基础结构认知—初识oracle【转】

    Oracle服务器(oracle server)由实例和数据库组成.其中,实例就是所谓的关系型数据库管理系统(Relational Database Management System,RDBMS), ...

  7. Serv-U 的升级及数据备份和迁移【转】

    Serv-U 配置备份   在serv-u7.x及以上版本安装目录下,有一个文件Serv-U.Archive是serv-u的配置文件,有一个users文件夹是Serv-U的域和用户的信息,那么我们只需 ...

  8. 读书笔记 effective c++ Item 19 像设计类型(type)一样设计类

    1. 你需要重视类的设计 c++同其他面向对象编程语言一样,定义了一个新的类就相当于定义了一个新的类型(type),因此作为一个c++开发人员,大量时间会被花费在扩张你的类型系统上面.这意味着你不仅仅 ...

  9. 002_curl及postman专题

    一. 步骤 1: 下载cURL工具 使用您的Windows机器从cURL web站点下载最新版本的cURL: (1) 通常情况下,多数的Windows用户可以从官网下载页面http://curl.ha ...

  10. vue总结 01基础特性

    最近有时间来总结一下vue的知识: 一.vue.js 被定义成一个开发web界面的前端库,是一个非常轻量的工具.vue.js本身具有响应式和组件化的特点. 我们不需要在维护视图和数据的统一上花费大量的 ...