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

Running Gnuplot from another program

210 views
Skip to first unread message

Konrad Hinsen

unread,
May 22, 1997, 3:00:00 AM5/22/97
to

I'd like one of my programs to call Gnuplot to display some graphs.
Sounds easy, but it seems Gnuplot is doing its best to make this difficult.

My first attempt was to produce a data file and a command file (doing
a plot) and then run "gnuplot command_file". That flashes up a window
and closes it immediately. Not very useful.

Next try: Open a pipe to Gnuplot and feed it the load command. Works
fine. Then send a quit command - and the window closes immediately.
But I want the window to stay open until it is closed by the user!

Next try: Open a pipe to Gnuplot once, and then send one load command
after the other. Works fine as long as the user never closes the
window - then Gnuplot just says "Broken pipe" when I want it to
display a plot.

The only remaining way I can think of is forking a new process each
time, run Gnuplot in it with a load commmand, and forget about it.
But doing this many times will result in many useless processes.

Is there any other solution? Someone must have tried this before me!
--
-------------------------------------------------------------------------------
Konrad Hinsen | E-Mail: hin...@ibs.ibs.fr
Laboratoire de Dynamique Moleculaire | Tel.: +33-4.76.88.99.28
Institut de Biologie Structurale | Fax: +33-4.76.88.54.94
41, av. des Martyrs | Deutsch/Esperanto/English/
38027 Grenoble Cedex 1, France | Nederlands/Francais
-------------------------------------------------------------------------------

Konrad Hinsen

unread,
May 22, 1997, 3:00:00 AM5/22/97
to

Lars Hecking

unread,
May 22, 1997, 3:00:00 AM5/22/97
to

Konrad Hinsen <hin...@ibs.ibs.fr> writes:

> Next try: Open a pipe to Gnuplot and feed it the load command. Works
> fine. Then send a quit command - and the window closes immediately.
> But I want the window to stay open until it is closed by the user!

I assume you are using X11. Newer betas of gnuplot (since 318?) provide
the '-persist' cmd line switch. From the help:

In addition to the X Toolkit options, the following options may be specified
on the command line when starting `gnuplot` or as resources in your
".Xdefaults" file:
`-mono` forces monochrome rendering on color displays.
`-gray` requests grayscale rendering on grayscale or color displays.
(Grayscale displays receive monochrome rendering by default.)
`-clear` requests that the window be cleared momentarily before a
new plot is displayed.
`-tvtwm` requests that geometry specifications for position of the
window be made relative to the currently displayed portion
of the virtual root.
`+raise` raise plot window after each plot
`-raise` do not raise plot window after each plot
`-persist` plot windows survive after main gnuplot program exits
The options are shown above in their command-line syntax. When entered as
resources in ".Xdefaults", they require a different syntax.

Gnuplot beta releases can be grabbed from
<URL:ftp://cmpc1.phys.soton.ac.uk/pub/>

Shen-C. Wu

unread,
May 23, 1997, 3:00:00 AM5/23/97
to

Relating your first approach, insert the following line after the "plot"
instruction:

pause -1 "Press enter to Continue"


This has worked for me with version 3.5 and earlier.

Konrad Hinsen (hin...@ibs.ibs.fr) wrote:
: I'd like one of my programs to call Gnuplot to display some graphs.


: Sounds easy, but it seems Gnuplot is doing its best to make this difficult.

: My first attempt was to produce a data file and a command file (doing
: a plot) and then run "gnuplot command_file". That flashes up a window
: and closes it immediately. Not very useful.

: Next try: Open a pipe to Gnuplot and feed it the load command. Works


: fine. Then send a quit command - and the window closes immediately.
: But I want the window to stay open until it is closed by the user!

: Next try: Open a pipe to Gnuplot once, and then send one load command

Konrad Hinsen

unread,
May 23, 1997, 3:00:00 AM5/23/97
to

Konrad Hinsen <hin...@ibs.ibs.fr> writes:

> Is there any other solution? Someone must have tried this before me!

Thanks to all who replied. The most frequent (and most useful)
suggestion was to upgrade to 3.6beta and use the -persist option.
That does exactly what I need.

Markus Harms

unread,
May 26, 1997, 3:00:00 AM5/26/97
to

Hi all

> Is there any other solution? Someone must have tried this before me!

What about this solution (V3.5):

1) Generate a gnuplot data file with the commands:

---8<-------------------(dummy.plt)
set term latex
set output "dummy.pic"
...
---8<-----------------------------
Execute "gnuplot dummy.plt" (no window is opened).

2) Edit a template-file like

---8<-------------------(dummy.tex)
\documentclass[10pt]{report}
\usepackage{latexsym}
\usepackage{rotating}
\begin{document}
\special{papersize=100, 120}
\pagestyle{empty}
\input{dummy.pic}
\end{document}
---8<-----------------------------

and run "latex dummy.tex"

3) Display the result with "xdvi dummy.dvi"


The advatages of this solution:
- high quality output (compared with other possible terminals)
- the XDvi-program updates automaticaly when the dvi-file changes
- you are able to zoom into the image (using antialiasing)
- all you can get from using latex
(with a prprocessing of the pictex-file you can also get color)

Markus Harms

Juan Carlos Gil Montoro

unread,
May 27, 1997, 3:00:00 AM5/27/97
to

Konrad Hinsen wrote:
>
> I'd like one of my programs to call Gnuplot to display some graphs.
> Sounds easy, but it seems Gnuplot is doing its best to make this difficult.
>
> My first attempt was to produce a data file and a command file (doing
> a plot) and then run "gnuplot command_file". That flashes up a window
> and closes it immediately. Not very useful.
>

Try 'pause -1' at the end of the command_file.


====================================================================
Juan Carlos Gil Montoro G.M.V. SA mailto:jg...@gmv.es

0 new messages