Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.graphics.apps.gnuplot > #199 > unrolled thread

How to re-use the same output device/xterm each time gnuplot is invoked?

Started by"Nasser M. Abbasi" <nma@12000.org>
First post2011-03-31 21:07 -0700
Last post2011-04-01 16:41 +0000
Articles 4 — 4 participants

Back to article view | Back to comp.graphics.apps.gnuplot


Contents

  How to re-use the same output device/xterm each time gnuplot is invoked? "Nasser M. Abbasi" <nma@12000.org> - 2011-03-31 21:07 -0700
    Re: How to re-use the same output device/xterm each time gnuplot is invoked? geep <geep@boursomail.com> - 2011-04-01 15:09 +0000
      Re: How to re-use the same output device/xterm each time gnuplot is invoked? sfeam <sfeam@users.sourceforge.net> - 2011-04-01 10:54 -0700
    Re: How to re-use the same output device/xterm each time gnuplot is invoked? James Waldby <not@valid.invalid> - 2011-04-01 16:41 +0000

#199 — How to re-use the same output device/xterm each time gnuplot is invoked?

From"Nasser M. Abbasi" <nma@12000.org>
Date2011-03-31 21:07 -0700
SubjectHow to re-use the same output device/xterm each time gnuplot is invoked?
Message-ID<in3j2j$og8$1@speranza.aioe.org>
Hello;

I am on linux, and I am very new to gnuplot, but I am
trying to see if I can use it to make animation
by calling it from Fortran program.

The setup is like this:


   PROGRAM ----> gnuplot

Where the actual call inside the program follow this logic

LOOP
    -- update data, create new data.txt file on disk  from this data
    CALL system('gnuplot batch.plt')  -- call to make new plot
END LOOP

and batch.plt would start as

#!/usr/bin/gnuplot -persist
... load data from data.txt  and make plot
# EOF

The above works OK, but the problem is that each call
makes a NEW xterm on top of the earlier one.

So if I run the loop for 10 time, I end up with 10 plots
on 10 different windows. If I remove -persist, then each plot
window disappear, and new one is created, etc... and one is not able
to see the animation.

What I want is to reuse the same window, basically erase the previous
plot (if any) on it, and make a new one on the same plot/window, to
obtain the effect of animation.

But I am not sure how to do this. I need some kind of window ID/device ID,
to tell gnuplot to reuse that when starting a new process, since each call
to gnuplot from the program will create a new process.

So, basically I want the gnuplot script to do something like

--------------------
IF window_ID allready exist, then send all output to it
else create a new window and assign it window_ID
make plot to window_ID
---------------------

Any ideas how to do this, or even if it possible?

thanks
--Nasser

[toc] | [next] | [standalone]


#201

Fromgeep <geep@boursomail.com>
Date2011-04-01 15:09 +0000
Message-ID<in4prt$fs8$1@speranza.aioe.org>
In reply to#199
On Thu, 31 Mar 2011 21:07:46 -0700, Nasser M. Abbasi wrote:

> Hello;
> 
> I am on linux, and I am very new to gnuplot, but I am trying to see if I
> can use it to make animation by calling it from Fortran program.
> 
> The setup is like this:
> 
> 
>    PROGRAM ----> gnuplot
> 
> Where the actual call inside the program follow this logic
> 
> LOOP
>     -- update data, create new data.txt file on disk  from this data
>     CALL system('gnuplot batch.plt')  -- call to make new plot
> END LOOP
> 
> and batch.plt would start as
> 
> #!/usr/bin/gnuplot -persist
> ... load data from data.txt  and make plot # EOF
> 
> The above works OK, but the problem is that each call makes a NEW xterm
> on top of the earlier one.
> 
> So if I run the loop for 10 time, I end up with 10 plots on 10 different
> windows. If I remove -persist, then each plot window disappear, and new
> one is created, etc... and one is not able to see the animation.
> 
> What I want is to reuse the same window, basically erase the previous
> plot (if any) on it, and make a new one on the same plot/window, to
> obtain the effect of animation.
> 
> But I am not sure how to do this. I need some kind of window ID/device
> ID, to tell gnuplot to reuse that when starting a new process, since
> each call to gnuplot from the program will create a new process.
> 
> So, basically I want the gnuplot script to do something like
> 
> --------------------
> IF window_ID allready exist, then send all output to it else create a
> new window and assign it window_ID make plot to window_ID
> ---------------------
> 
> Any ideas how to do this, or even if it possible?
> 
> thanks
> --Nasser

Hi,
I haven't tried it myself, but gnuplot can make animated gifs - take a 
looke here: http://www.gnuplot.info/faq/faq.html
Maybe it will be helpful.
Cheers,
Peter

[toc] | [prev] | [next] | [standalone]


#203

Fromsfeam <sfeam@users.sourceforge.net>
Date2011-04-01 10:54 -0700
Message-ID<in53hi$r4g$1@dont-email.me>
In reply to#201
Nasser M. Abbasi wrote:

>> So, basically I want the gnuplot script to do something like
>>
>> --------------------
>> IF window_ID allready exist, then send all output to it else create a
>> new window and assign it window_ID make plot to window_ID
>> ---------------------
>>
>> Any ideas how to do this, or even if it possible?

It is possible.  See "help set term x11"

From the manual:
 The `x11` terminal can connect to X windows previously created by an outside
 application via the option `window` followed by a string containing the
 X ID for the window in hexadecimal format.  Gnuplot uses that external X
 window as a container since X does not allow for multiple clients selecting
 the ButtonPress event.  In this way, gnuplot's mouse features work within
 the contained plot window.

I suspect that is an overly complicated way of achieving the effect
you want, but it's certainly one possible approach.

Another possible approach is to have each CALL SYSTEM(...) trigger an update
of an *.eps or *.png file on disk.  Then you just leave ghostview or an image
display program running continuously, set to update the screen display whenever
the underlying file is re-written.

	Ethan

[toc] | [prev] | [next] | [standalone]


#202

FromJames Waldby <not@valid.invalid>
Date2011-04-01 16:41 +0000
Message-ID<in4v7p$g5g$9@dont-email.me>
In reply to#199
On Thu, 31 Mar 2011 21:07:46 -0700, Nasser M. Abbasi wrote:
...
> I am on linux, and I am very new to gnuplot, but I am trying to see if I
> can use it to make animation by calling it from Fortran program.
> 
> The setup is like this:
>    PROGRAM ----> gnuplot
> 
> Where the actual call inside the program follow this logic
> 
> LOOP
>     -- update data, create new data.txt file on disk  from this data
>     CALL system('gnuplot batch.plt')  -- call to make new plot
> END LOOP
> 
> and batch.plt would start as
> 
> #!/usr/bin/gnuplot -persist
> ... load data from data.txt  and make plot # EOF
> 
> The above works OK, but the problem is that each call makes a NEW xterm
> on top of the earlier one.
...

Since you have a system() function, perhaps you also have a 
popen() function available.  In C, one would use (eg)
   FILE *f = popen("/usr/bin/gnuplot", "w");
   if (!f) exit(1);   /* exit if error */
to open a pipe to gnuplot standard input, and thereafter use
   fprintf (f, ...);
   ...
   fflush (f);
to write data to gnuplot, such as "plot '-'" commands and
data sequences.

See eg <http://linux.die.net/man/3/popen> and 
<http://bama.ua.edu/cgi-bin/man-cgi?popen+3C>

-- 
jiw

[toc] | [prev] | [standalone]


Back to top | Article view | comp.graphics.apps.gnuplot


csiph-web