|
From: sfeam <sf...@us...> - 2017-10-09 00:31:10
|
On Sunday, 08 October 2017 21:17:40 Achim Gratz wrote:
> sfeam via gnuplot-beta writes:
> > With one exception, gnuplot variables are global.
>
> That is not what I was seeing (much to my surprise), although things may
> have been complicated by my additional use of a call statement and
> mixing with functions. So, I have a file that implements a callable
> include:
Too complicated for me to work through in detail but one line
is waving a red flag. This line
set ytics @ticdef
is almost certainly not what you want to do.
The macro expansion operator @ is like a #define statement in C.
It causes a substitution at the time the file/block/clause/program unit
is read in. It is _not_ reevaluated at run time.
An example of evaluation at run time would be:
... loop that constructs ticdef ...
eval "set ytics " . ticdef
Ethan
>
> --8<---------------cut here---------------start------------->8---
> # call "scale.gp" linear|asinh knee
> type = ((ARGC>0) ? ARG1 : "asinh")
> knee = ((ARGC>1) ? ARG2 : 1e-5)
> ticdef = ''
> if (type eq "asinh") {
> s(y) = asinh( 0.5*y/knee )
> tic( s,u,n,v ) = sprintf( '"%s%i %s" %ss(%f),', s, n, u, ((s eq "±")?'':s), v );
> omag = 1.
> ticdef = tic( "±", "s", 0, 0 )
> do for [unit in "s ms µs ns"] {
> do for [mag = 0:2] {
> m = 10**mag
> v = omag*m
> ticdef = ticdef . tic( "+", unit, m, v)
> ticdef = ticdef . tic( "-", unit, m, v)
> }
> omag = omag / 1000.
> }
> ticdef = '(' . ticdef . ')'
> }
> if (type eq "linear") {
> s(y) = y
> }
> set ytics @ticdef
> --8<---------------cut here---------------end--------------->8---
>
> The original version created ticdef inside the block and also set the
> ytics there, but the result was never visible in the caller. This is
> with gnuplot 5.0.7 from openSUSE.
>
>
> Regards,
> Achim.
>
|