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

前端之家收集整理的这篇文章主要介绍了Gnuplot,来自windows.命令窗口打开和关闭前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有以下,无论我尝试什么命令窗口再次打开和关闭.没有显示图表,也没有写入文件.任何有c使用gnuplot的解决方案的人.我有4.4和4.6rc1可用.
  1. #ifdef WIN32
  2. gp = _popen("C:\Program Files (x86)\gnuplot\bin\pgnuplot.exe","w");
  3. #else
  4. gp = popen("gnuplot -persist","w");
  5. #endif
  6.  
  7.  
  8. if (gp == NULL)
  9. return -1;
  10.  
  11. /* fprintf(gp,"unset border\n");
  12. fprintf(gp,"set clip\n");
  13. fprintf(gp,"set polar\n");
  14. fprintf(gp,"set xtics axis nomirror\n");
  15. fprintf(gp,"set ytics axis nomirror\n");
  16. fprintf(gp,"unset rtics\n");
  17. fprintf(gp,"set samples 160\n");
  18. fprintf(gp,"set zeroaxis");
  19. fprintf(gp," set trange [0:2*pi]");*/
  20.  
  21.  
  22. fprintf(gp,"set term png\n");
  23. fprintf(gp,"set output \"c:\\printme.png\"");
  24. fprintf(gp,"plot .5,1,1.5\n");
  25. fprintf(gp,"pause -1\n");
  26.  
  27. fflush(gp);
以下程序已在Windows上使用Visual Studio和MinGW编译器以及使用gcc的GNU / Linux进行了测试. gnuplot二进制文件必须位于路径上,而在Windows上,必须使用二进制文件的管道pgnuplot版本.

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

  1. #include <iostream>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4.  
  5. // Tested on:
  6. // 1. Visual Studio 2012 on Windows
  7. // 2. Mingw gcc 4.7.1 on Windows
  8. // 3. gcc 4.6.3 on GNU/Linux
  9.  
  10. // Note that gnuplot binary must be on the path
  11. // and on Windows we need to use the piped version of gnuplot
  12. #ifdef WIN32
  13. #define GNUPLOT_NAME "pgnuplot -persist"
  14. #else
  15. #define GNUPLOT_NAME "gnuplot"
  16. #endif
  17.  
  18. int main()
  19. {
  20. #ifdef WIN32
  21. FILE *pipe = _popen(GNUPLOT_NAME,"w");
  22. #else
  23. FILE *pipe = popen(GNUPLOT_NAME,"w");
  24. #endif
  25.  
  26. if (pipe != NULL)
  27. {
  28. fprintf(pipe,"set term wx\n"); // set the terminal
  29. fprintf(pipe,"plot '-' with lines\n"); // plot type
  30. for(int i = 0; i < 10; i++) // loop over the data [0,...,9]
  31. fprintf(pipe,"%d\n",i); // data terminated with \n
  32. fprintf(pipe,"%s\n","e"); // termination character
  33. fflush(pipe); // flush the pipe
  34.  
  35. // wait for key press
  36. std::cin.clear();
  37. std::cin.ignore(std::cin.rdbuf()->in_avail());
  38. std::cin.get();
  39.  
  40. #ifdef WIN32
  41. _pclose(pipe);
  42. #else
  43. pclose(pipe);
  44. #endif
  45. }
  46. else
  47. std::cout << "Could not open pipe" << std::endl;
  48. return 0;
  49. }

猜你在找的Windows相关文章