#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. c++虚函数&重写

    虚函数是C++中实现多态的一种方法,父类A的一个函数声明为虚函数,在子类B中覆盖定义之后,当在调用的时候使用A*a=new B(),此时调用对应的那个虚函数的名字,则会执行B中的函数.当父类中没有定义 ...

  2. windows git gui右键sublime打开当前文件编辑

    git安装目录\Git\libexec\git-core\git-gui.tcl的 proc create_common_diff_popup 下追加: $ctxm add command \ -la ...

  3. soj1767.传纸条

    这道题目想了一会儿觉得不知道如何下手,上网看了下资料,原来这道是一道非常经典的题目. 设 f [ k ][ i ][ j ] 表示第 k 步,第 1 条路径走到第 i 行,第 2 条路径走到第 j 行 ...

  4. ArcGis10.1 Feature Class Properties无法编辑

    被这个问题困扰了很久,最后从官网帮助中查询到资料解决了 先看一下截图: 这种问题一般是FratureClass被锁,被mxd引用,并且发布服务有实例在运行,但我新创建一个FeatureClass也无法 ...

  5. CodeVS4416 FFF 团卧底的后宫

    题目描述 Description 你在某日收到了 FFF 团卧底的求助,在他某日旅游回来,他的后宫们出现了一些不可调和的矛盾,如果 FFF 团卧底把自己的宝贝分给 a 号妹子,那么 b 号妹子至少要在 ...

  6. sql server 查询本周、本月所有天数的数据

    查询本月所有的天数: --本月所有的天数 ),) day from (),,)+'-01' day) t1, ( ) t2 ),) ),,)+'%' 查询本周所有的天数: ),,),) ),,),) ...

  7. 关于数据区间变换及numpy数组转图片数据的python实现

    python实现区间转换.numpy图片数据转换 需求: 客户的需求是永无止境的,这不?前几天,用户提出了一个需求,需要将一组数据从一个区间缩放到另一区间? 思路: 先将数据归一化,再乘以对应区间的差 ...

  8. Django进阶(路由系统、中间件、缓存、Cookie和Session、Ajax发送数据

    路由系统 1.每个路由规则对应一个view中的函数 url(r'^index/(\d*)', views.index), url(r'^manage/(?P<name>\w*)/(?P&l ...

  9. 关于 jQuery 中的 $.data() 方法和 jQuery 对象上的data 方法

    参见文章:http://www.it165.net/pro/html/201404/11922.html

  10. HTML 解析 textarea 中的换行符

    用户在textarea中输入的换行符,传到后台,再返回前端,展示在div中. 如果需要div显示为与textarea 一致的效果,需添加: .detail { white-space: pre-lin ...