通过管道的gnuplot c ++接口-无法打开wgnuplot [英] gnuplot c++ interface through pipes -cannot open wgnuplot

查看:97
本文介绍了通过管道的gnuplot c ++接口-无法打开wgnuplot的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试通过C ++程序在gnuplot中实时绘制图形.我已经安装了gnuplot 4.6,并且能够打开gnuplot.exe并绘制图形,但是我无法通过管道打开应用程序.这是我使用的代码.

I am trying to plot my graph real time in gnuplot from my c++ program.I have installed gnuplot 4.6 and am able to open the gnuplot.exe and plot graphs.But I cannot open the application through pipes. This is the code I have used.

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

int main()
{
  FILE* gp;
  char *path = "C:\Program Files\gnuplot\bin\wgnuplot";
#ifdef WIN32
  gp = _popen("gnuplot -persist", "w");
#else
  gp = _popen(path, "w");
#endif

  if (gp == NULL)
    return -1;

  fprintf(gp, "set isosample 100\n");
  fprintf(gp, "min=-1\n");
  fprintf(gp, "max=1\n");
  fprintf(gp, "pi=3.141592\n");
  fprintf(gp, "set hidden3d\n");
  fprintf(gp, "set pm3d\n");
  fprintf(gp, "set contour\n");
  fprintf(gp, "splot [min:max] [min:max] x*x+2*y*y-0.3*cos(3*pi*x)-0.4*cos(4*pi*y)+0.7\n");
  fprintf(gp, "pause -1\n");

  return 0;
}

我已经设置了环境变量,并且出现以下错误. c:program \无法识别为内部或外部命令以及可操作的程序或批处理文件.

I have set the environment variables and I get the following error. c:program\ is not recognised as a internal or external command and operable program or batch file..

我尝试使用相同的路径运行exe,但是没有打开.是因为可以在cmd提示符下给出字符串的最大长度.

I tried running the exe with the same path.But it is not opening. Is it because of the maximum length of the string that can be given in the cmd prompt..

请提出您的宝贵建议.

谢谢

推荐答案

而不是使用char *路径,您应该将_popen函数编写为

instead of using char* path you should write the _popen function as

gp = _popen("E:\\ myprograms \\ ProgramFiles \\ libraries \\ Gnuplot \\ bin \\ gnuplot -persist","w");

gp = _popen("E:\\myprograms\\ProgramFiles\\libraries\\Gnuplot\\bin\\gnuplot -persist", "w");

并可能通过这种方式调用相应的数据数据文件

and possibly call the corresponding data data file via this manner

fprintf(gp,"splot \" C:\\\\ Users \\\\ username \\\\ Documents \\\\ Visual Studio 2012 \\\\\ Projects \\\\ laplace equation \\\\\ laplace.dat \"\ n");

fprintf(gp,"splot \"C:\\\\Users\\\\username\\\\Documents\\\\Visual Studio 2012\\\\Projects\\\\laplace equation\\\\laplace.dat\"\n");

这篇关于通过管道的gnuplot c ++接口-无法打开wgnuplot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆