0

I wrote a computer simulation program (the details are irrelevant) that writes on two files some results in a 2 colums format, then i used gnuplot from another terminal to plot these results on a graph, successfully. Now i want to integrate the graph with the program, so that i don't have to run gnuplot from another terminal. so

/*while loop that writes data on the 2 files, the data is consistent as the graphs are good running gnuplot from a separate terminal
*/

fclose(file_wait);
fclose(file_discarted);

system("gnuplot -p -e \"plot 'wait.dat'\"");
system("gnuplot -p -e \"plot 'discarted.dat'\"");

The funny thing is that this program work when the file has less than 1000 lines (the full data set is 2600 lines) more that that and the program terminates but the grapsh aren't visualized.

pjs
  • 18,696
  • 4
  • 27
  • 56
Crysis85
  • 345
  • 3
  • 17
  • 2
    Use `popen()` there is an example [here](http://stackoverflow.com/a/6934363/1983495). Your program will not work because you need to exit the first window to plot the second file, so write a `gnuplot` script instead. – Iharob Al Asimi Feb 09 '15 at 14:11
  • Actually when the data sets are less then 1000 lines it plot both graphs opening 2 windows. I tryed with only one file too, same situation. – Crysis85 Feb 09 '15 at 14:17
  • 1
    did you try the suggested `popen()` method? – Iharob Al Asimi Feb 09 '15 at 14:27
  • Nope, it doesn't work `FILE * gnuplotPipe = popen ("gnuplot", "w");` returns NULL – Crysis85 Feb 09 '15 at 18:07
  • sure it does, try `FILE * gnuplotPipe = popen ("gnuplot", "r");` – Iharob Al Asimi Feb 09 '15 at 18:13
  • it works with write (and the flag --persist) It's my fault for forgetting the new line "\n" at the end of the commands. Anyhow...now I have to figure out how to plot wait.dat in a window and open another window to plot the other dataset. Found it! "set terminal qt 1" before the second plot command. Thanks for the help iharob – Crysis85 Feb 09 '15 at 18:24
  • You have to generate a `gnuplot` script and then pass it to `gnuplot`. – Iharob Al Asimi Feb 09 '15 at 18:39

0 Answers0