Cnot gnuplot interface via -cannot open wgnuplot channels

I am trying to plot a real-time graph in gnuplot from my C ++ program. I installed gnuplot 4.6 and can open gnuplot.exe and the graph chart. But I can not open the application through the channels. This is the code I 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;
}

I set the environment variables and I got the following error. c: program \ is not recognized as an internal or external command and operating program or batch file.

I tried to run exe with the same path. But he does not open. This is because of the maximum line length that can be specified on the cmd command line.

Please give your valuable advice.

thank

+1
source share
3 answers

( ):

char *path = "C:\\Program Files\\gnuplot\\bin\\wgnuplot";
+1

char * _popen

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

, ,

fprintf (gp, "splot \" C: \\\\ \\\\ _ \\\\ \\\\ Visual Studio 2012 \\\\ \\\\ \\\\ laplace.dat\ "\ " );

+1

You can use gnuplot-cpp to draw your graphs.

This small snippet solves your problem (test1.cpp):

#include "gnuplot_i.hpp" 

int main()
{
   Gnuplot gp;
   gp.cmd("set isosample 100\n");
   gp.cmd("min=-1\n");
   gp.cmd("max=1\n");
   gp.cmd("pi=3.141592\n");
   gp.cmd("set hidden3d\n");
   gp.cmd("set pm3d\n");
   gp.cmd("set contour\n");
   gp.cmd("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");
   gp.cmd("pause -1\n");


   std::cout << std::endl << "Press ENTER to continue..." << std::endl;
   std::cin.clear();
   std::cin.ignore(std::cin.rdbuf()->in_avail());
   std::cin.get();

   return 0;
}

Compile and run this application on Linux using

g++ test1.cpp && ./a.out

This gives Result

0
source

All Articles