加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

Gnuplot,来自windows.命令窗口打开和关闭

发布时间:2020-12-13 20:45:30 所属栏目:Windows 来源:网络整理
导读:我有以下,无论我尝试什么命令窗口再次打开和关闭.没有显示图表,也没有写入文件.任何有c使用gnuplot的解决方案的人.我有4.4和4.6rc1可用. #ifdef WIN32 gp = _popen("C:Program Files (x86)gnuplotbinpgnuplot.exe","w");#else gp = popen("gnuplot -pers
我有以下,无论我尝试什么命令窗口再次打开和关闭.没有显示图表,也没有写入文件.任何有c使用gnuplot的解决方案的人.我有4.4和4.6rc1可用.
#ifdef WIN32
  gp = _popen("C:Program Files (x86)gnuplotbinpgnuplot.exe","w");
#else
  gp = popen("gnuplot -persist","w");
#endif


 if (gp == NULL)
       return -1;

  /* fprintf(gp,"unset bordern");
  fprintf(gp,"set clipn");
  fprintf(gp,"set polarn");
  fprintf(gp,"set xtics axis nomirrorn");
  fprintf(gp,"set ytics axis nomirrorn");
  fprintf(gp,"unset rticsn");
  fprintf(gp,"set samples 160n");
  fprintf(gp,"set zeroaxis");
    fprintf(gp,"  set trange [0:2*pi]");*/


  fprintf(gp,"set term pngn");
  fprintf(gp,"set output "c:printme.png"");
  fprintf(gp,"plot .5,1,1.5n");
   fprintf(gp,"pause -1n");

     fflush(gp);
以下程序已在Windows上使用Visual Studio和MinGW编译器以及使用gcc的GNU / Linux进行了测试. gnuplot二进制文件必须位于路径上,而在Windows上,必须使用二进制文件的管道pgnuplot版本.

我发现Windows管道比GNU / Linux上的相应管道慢得多.对于大型数据集,在Windows上通过管道将数据传输到gnuplot很慢并且通常不可靠.此外,按键等待代码在GNU / Linux上更有用,其中一旦调用pclose(),绘图窗口将关闭.

#include <iostream>
#include <stdio.h>
#include <stdlib.h>

// Tested on:
// 1. Visual Studio 2012 on Windows
// 2. Mingw gcc 4.7.1 on Windows
// 3. gcc 4.6.3 on GNU/Linux

// Note that gnuplot binary must be on the path
// and on Windows we need to use the piped version of gnuplot
#ifdef WIN32
    #define GNUPLOT_NAME "pgnuplot -persist"
#else 
    #define GNUPLOT_NAME "gnuplot"
#endif

int main() 
{
    #ifdef WIN32
        FILE *pipe = _popen(GNUPLOT_NAME,"w");
    #else
        FILE *pipe = popen(GNUPLOT_NAME,"w");
    #endif

    if (pipe != NULL)
    {
        fprintf(pipe,"set term wxn");         // set the terminal
        fprintf(pipe,"plot '-' with linesn"); // plot type
        for(int i = 0; i < 10; i++)             // loop over the data [0,...,9]
            fprintf(pipe,"%dn",i);           // data terminated with n
        fprintf(pipe,"%sn","e");             // termination character
        fflush(pipe);                           // flush the pipe

        // wait for key press
        std::cin.clear();
        std::cin.ignore(std::cin.rdbuf()->in_avail());
        std::cin.get();

        #ifdef WIN32
                _pclose(pipe);
        #else
                pclose(pipe);
        #endif
    }
    else
        std::cout << "Could not open pipe" << std::endl; 
return 0;
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读