gnuplot supports input via pipes (on windows, there's a separate executable for this, pgnuplot
). Then your program can send new commands to gnuplot, such as replot
, just as if you were typing them into the gnuplot interface directly.
How you set up the pipe connection and write to the sending end of the pipe from your C++ program varies by operating system, so you'll have to tell us what you're using if you want more help.
On Windows, there's CreatePipe
and then you set the hStdInput
element of the STARTUPINFO
struct you pass to CreateProcess
. Ditto with hStdOutput
if you need the status messages from pgnuplot
.
On POSIX (Unix, Linux, Mac OSX, etc), you can just use popen
as the quick way to get a unidirectional connection. For bidirectional, it works more like on Windows: pipe
to get handles to the ends, then fork
and in the child process call dup2
to associate stdin and stdout with the pipe, then exec
to have gnuplot
replace the child process, keeping the pipes you set up.
EDIT: From the gnuplot documentation:
The special filename ’-’ specifies
that the data are inline; i.e., they
follow the command. Only the data
follow the command; plot options like
filters, titles, and line styles
remain on the plot command line. This
is similar to << in unix shell script,
and $DECK in VMS DCL. The data are
entered as though they are being read
from a file, one data point per
record. The letter "e" at the start of
the first column terminates data
entry. The using option can be applied
to these data — using it to filter
them through a function might make
sense, but selecting columns probably
doesn’t!