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

how to access external variables ?

1,157 views
Skip to first unread message

gvdmoort

unread,
Jan 30, 2011, 6:45:48 AM1/30/11
to
Hello,

I'd like to plot at regular intervalls a file with gnuplot
instructions (say "foo.dem"), eventually with cron.

But the title of the plot should be dependant of external variables,
so it can't be specified in the .dem file. It could be for instance
the time at this moment.

And it could be interessant to save the plots in files with differents
names, dependant of such variables.

Is it possible to specify a string or any variable according to an
environment variable, or to pass it through an option ?

Thanks in advance,

Gauthier

Ingo Thies

unread,
Jan 30, 2011, 7:08:24 AM1/30/11
to
Am 2011-01-30 12:45, schrieb gvdmoort:

> But the title of the plot should be dependant of external variables,
> so it can't be specified in the .dem file. It could be for instance
> the time at this moment.

Depending on what you particularly want, you could create an auxiliary
file "aux.gp" containing statements like

titlestring="yourtitle"

(and also define, of course, numerical variables uses in the plot,
accordingly) and load it into gnuplot by

load "aux.gp"

You can also convert numbers into strings via the sprintf function (it
actually uses a C printf statement to create a string; please see the
gnuplot help or gnuplot.pdf for more information) and concatenate
strings with

string3=string1.string2

or

string3="something"."somethingelse".sprintf(...)

etc.

> And it could be interessant to save the plots in files with differents
> names, dependant of such variables.

You can define the output file name (which is set by set output <name>)
using the strings created like shown above. Maybe there is another
method I am not aware of, but passing variables via a helper file gives
you a high degree of freedom.

HTH,

Ingo

sfeam

unread,
Jan 30, 2011, 1:35:02 PM1/30/11
to
gvdmoort wrote:

accessing an environmental variable from inside gnuplot:

gnuplot> nextfile = system("echo $NEXTFILE")
gnuplot> set term png
gnuplot> set out nextfile . ".png"
gnuplot> plot nextfile ...

or if you prefer to do the substitution from the command line
before entering gnuplot:

gnuplot -e "file = $NEXTFILE" gnuplot_command_script.gp

0 new messages