Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

pipe data to gnuplot under Windows

1,073 views
Skip to first unread message

jl Hamel

unread,
May 13, 1998, 3:00:00 AM5/13/98
to

Hi,

A frequently asked question about gnuplot is :

How to pipe data to gnuplot as under UNIX ?

I have found a method which works OK under Windows 95. I am using
the b330 version of gnuplot and the executable is named wgnuplot.exe.
The text child window as a title "gnuplot" and a class "wgnuplot_text".

Under those conditions, I have made a little wrapper program which
runs in a DOS box ; compile it and name it "gnuplot.exe". Type a
command file which contains a list of gnuplot commands ended by
"exit" and try:

TYPE COMMAND_FILE | GNUPLOT

Remark: you have to customize the path to wgnuplot.exe.

jl Hamel
jlh...@cea.fr

Here is the program:

/* Test gnuplot */
#include <stdio.h>
#include <windows.h>

main () {
/* Customize this path if needed */
char s[] = "C:\\gnuplot\\wgnuplot.exe";
char *d, buf[80];
HWND hwnd_parent;
HWND hwnd_text;

/* load gnuplot (minimized in order to show only the graphic
window) */
if (WinExec(s, SW_MINIMIZE) <= 32) {
printf("Can't load gnuplot\n");
exit(1);
} else {
printf("Gnuplot loaded\n");
}

/* wait for the gnuplot window */
Sleep(1000);
hwnd_parent = FindWindow((LPSTR) NULL, (LPCTSTR) "gnuplot");
if ( ! hwnd_parent) {
printf("Can't find the gnuplot window");
exit(1);
}

/* find the child text window */
hwnd_text = FindWindowEx(hwnd_parent, (HWND)
NULL, (LPCTSTR)"wgnuplot_text",
(LPCTSTR)NULL);

/* wait for commands on stdin, and send them to the gnuplot
text window */
do {
gets(buf);
d = buf;
while(*d) {
PostMessage(hwnd_text, WM_CHAR, *d, 1L);
d++;
}
PostMessage(hwnd_text, WM_CHAR, '\n', 1L);
} while(strcmp(buf, "exit"));
}

jl Hamel

unread,
May 13, 1998, 3:00:00 AM5/13/98
to

jl Hamel wrote:
>
> Hi,
>
> A frequently asked question about gnuplot is :
>
> How to pipe data to gnuplot as under UNIX ?
...................

I apologize for a mistake in this article:

Don't name the executable wrapper program "gnuplot.exe" nor
"wgnuplot.exe", because of a name conflict with the true gnuplot
application.

You can name it "pgnuplot".

jl Hamel
jlh...@cea.fr

David Denholm

unread,
May 14, 1998, 3:00:00 AM5/14/98
to

jl Hamel <jlh...@cea.fr> writes:

> Hi,
>
> A frequently asked question about gnuplot is :
>
> How to pipe data to gnuplot as under UNIX ?
>

> I have found a method which works OK under Windows 95. I am using
> the b330 version of gnuplot and the executable is named wgnuplot.exe.
> The text child window as a title "gnuplot" and a class "wgnuplot_text".
>
> Under those conditions, I have made a little wrapper program which
> runs in a DOS box ; compile it and name it "gnuplot.exe". Type a
> command file which contains a list of gnuplot commands ended by
> "exit" and try:
>
> TYPE COMMAND_FILE | GNUPLOT
>
> Remark: you have to customize the path to wgnuplot.exe.
>
> jl Hamel
> jlh...@cea.fr


I tried a technique very similar to this : in the main gnuplot
program, it would spin off a thread which read characters from
stdin and sent them as messages to the main program.
If I remember correctly, it went wrong if there was a pause
in the command stream, and if one uses fit, the commands
would back up because the fit takes so long.

dd
--
David Denholm da...@ctxuk.citrix.com
Citrix Systems UK Ltd. http://www.citrix.com/

jl Hamel

unread,
May 15, 1998, 3:00:00 AM5/15/98
to

David Denholm wrote:
>
> I tried a technique very similar to this : in the main gnuplot
> program, it would spin off a thread which read characters from
> stdin and sent them as messages to the main program.
> If I remember correctly, it went wrong if there was a pause
> in the command stream, and if one uses fit, the commands
> would back up because the fit takes so long.
>
> dd
> --
> David Denholm da...@ctxuk.citrix.com
> Citrix Systems UK Ltd. http://www.citrix.com/

With my method, I can use gnuplot binary "as is" without modifs.
It is possible to send the commands manually, from the DOS box or
pipe them from a file. If there is a pause in the stream, gnuplot
(under Windows, not Unix) spawns a dialog box and wait for a
mouse clic, and of course the stream waits also.

Remark: don't name the wrapper program "gnuplot.exe" or "wgnuplot.exe"
my article, because of a conflict with the true gnuplot application.

jl Hamel
jlh...@cea.fr

Douglas Natelson

unread,
May 16, 1998, 3:00:00 AM5/16/98
to

jl Hamel <jlh...@club-internet.fr> wrote:
>
>With my method, I can use gnuplot binary "as is" without modifs.
>It is possible to send the commands manually, from the DOS box or
>pipe them from a file. If there is a pause in the stream, gnuplot
>(under Windows, not Unix) spawns a dialog box and wait for a
>mouse clic, and of course the stream waits also.

Thanks for posting this piece of code! I've been idly trying
to do something like this for a while, but don't know enough about
the win32 API....

So, I have a program that worked fine under OS/2, where it spawned
gnuplot via popen() and then sent commands to that pipe using fprintf.
When I run under NT, if I spawn your stdin wrapper using popen and use
fprint to send plot commands to it, something weird happens. The
gnuplot process is started, minimized, as expected, but the graphics
window does not pop up at all unless I stick in 'exit', which doesn't
work well for my application, which is trying to update a particular
plot every 30 sec. It seems like I need to be flushing the buffer
differently than I am. What I don't understand is why this behavior
doesn't happen when I run your wrapper from the command line. I named
your code stdin_wrapper.exe, and if I run that at a command prompt,
and then type directly into stdin (say 'plot sin(x)'), the plot window
pops up immediately. However, if I make a file named junk that is the line
'plot sin(x)', and type 'type junk | stdin_wrapper', again
the gnuplot program is started, but the plot window doesn't appear
until I terminate the pipe w/ control-C, or place 'exit' at the
end of the 'junk' file. (Actually, to keep the plot up there,
I need to put 'pause -1; exit' at the end of 'junk').

This is getting really close to the functionality I need; I'm
sure there's some clever way to do this. So, how can I make the
graphics window spawn without terminating the pipe to it, and
why isn't this an issue when I'm typing into stdin directly?

Thanks again,
Doug Natelson
natelson at leland.stanford.edu


jl Hamel

unread,
May 18, 1998, 3:00:00 AM5/18/98
to Douglas Natelson

> However, if I make a file named junk that is the line
> 'plot sin(x)', and type 'type junk | stdin_wrapper', again
> the gnuplot program is started, but the plot window doesn't appear
> until I terminate the pipe

I have tried the wrapper program with a command file junk.txt like that:

splot x*y
pause 3
plot sin(x)
pause 3
exit

with:
type junk.txt | stdin_wrapper

and it runs OK under Windows95 and NT4.

If you send the commands from a program instead of "type commands.txt"
you have to flush the output at each time you want to send the data
to the gnuplot program (including the \r terminating each line).
To do that, try to invoke the FlushFileBuffers function.

jl Hamel
jlh...@cea.fr

0 new messages