5

I am writing an app which uses GnuPlot for ploting data. Instead of using text format to comunicate both programs though a pipe (it is slow because of the vprintf() and the big amount of data being passed) I decided to use "binary" format.

The problem is that in binary format GnuPlot expects a EOF (Ctrl+D) to end the transmission and plot the data. This is easy in UNIX console mode. Just pressing Ctrl+D will end the data input, plot the data AND mantain the console open waiting for more commands.

But in my C++ app the only way to send a EOF is to close the pipe. This causes the gnuplot process to die and does not show the plot to the screen.

¿Is there some trick to send a EOF to a pipe? ¿How does the UNIX terminal manage to send a EOF without closing its pipe with the running process?

PD: I can't close and reopen GnuPlot with "-persist", because that generates a NEW plot instead of updating the old plot (it is a real time system so it generates near ~inf plot windows).

DarkZeros
  • 8,235
  • 1
  • 26
  • 36
  • Did you try using a library which provides a pipe directly go gnuplot? More info here: http://ndevilla.free.fr/gnuplot/ – Azrael3000 Mar 09 '12 at 12:09
  • That interface seems cool. But I already wrote a draft myself. Anyway I think it does not handle "binary" format..... or at least I didn't find it. BTW I already use a direct pipe to gnuplot. – DarkZeros Mar 09 '12 at 12:31
  • This could be interesting for you as well: http://users.softlab.ntua.gr/~ttsiod/gnuplotStreaming.html It uses bash to do the piping. But you can use the stdout of your program to do the plotting. – Azrael3000 Mar 09 '12 at 13:42

1 Answers1

1

I don't think what you want to do will work. See for example:

http://www.velocityreviews.com/forums/t365339-write-eof-without-closing.html

Can we write an EOF character ourselves?

Basically EOF is no character per se. It's the end of the file.

So as I noted in the comment above I suggest you try using a library which connects you directly to gnuplot. Then you should be able to control it such that your desired behaviour is achieved (most likely using something like replot).

Community
  • 1
  • 1
Azrael3000
  • 1,847
  • 12
  • 23
  • It can't be done with EOF. But I figured out a trick to fix it just by sending the size to the gnuplot( binary array=xxx ). This way it stops acepting data without closing the pipe. Thank anyway!!! – DarkZeros Mar 09 '12 at 16:24
  • Ah when I first thought about the problem, I had the same thought. Didn't know it was possible though. But it's not surprising as it's kind of common practice to have a size at the beginning of a binary file. Out of interest, are you going to publish your library? – Azrael3000 Mar 09 '12 at 20:52
  • 1
    Sry, the library is part of another proyect witch is private. But it is just a popen() command followed by a fprintf() sending the gnuplot commands fprintf(pipe,"plot '-' binary format="%float64%float64" record=%d using lines",data) and after that a fwrite with all the RAW data. The hardest part was just to figure out the "record=X" or "array=X" trick to avoid the EOF in the pipe. – DarkZeros Mar 12 '12 at 11:42