On Fri, 11 Dec 2015, Artur Tarassow wrote:
I just tried to setup a general function which mixes
line-/impulse-plots. List L1 includes variables to plot using
lines, while variables in L2 shall occur with impulses, instead.
However, the following piece shows that gnuplot prints correctly
the plot when I do not call a function.
(But not when the same code is called from within a function.)
I cannot figure out where the issue lies. I am using the current
git-version on (l)ubuntu 15.10.
<hansl>
clear
set echo off
set messages off
open denmark.gdt -q
function void indplot(list L1, list L2)
list lplot = L1|| L2
string S1 = varname(L1)
string S2 = varname(L2)
plot lplot
option with-lines=@S1
option with-impulses=@S2
option time-series
#literal set term pdfcairo font 'Helvetica,14' lw 1
literal set key outside below
literal set linetype 2 lc rgb 'black' lw 2
literal set linetype 1 lc rgb 'blue'
literal set linetype 3 lc rgb 'red' lw 2
end plot --output=display
end function
list L1 = LRM
list L2 = IBO
indplot(L1,L2)
[...]
</hansl>
This is to do with the handling of list arguments to gretl
functions, which is inherently tricky (see the sub-section titled
"List arguments" in the chapter on User-defined functions in the
Gretl User's Guide). When you do
option with-lines=@S1
in your function, "@S1" gets cashed out to "LRM", but there's no
series named LRM in scope inside the function, so this option has no
effect. (Arguably, an error should be generated here.)
Within a loop, you get "get hold of" a series supplied via a list
argument to a function using listname.$i, but right now I don't
think there's any other way.
If we want to allow this sort of thing, maybe the best way would be
accept the names of lists with the relevant "plot" options, so you
could just say
option with-lines=L1
option with-impulses=L2
in your function. Some thought required here!
Allin