April 2nd, 2012 | No Comments
Since last month the new Gnuplot version 4.6 is officially available. There are a lot of interesting changes in this new version and we will cover the bigger ones within the next posts. Here we start with, in my opinion, the nicest new feature: block-structured conditions and loops.
Until 4.6 an iteration over different lines of code was only possible with the help of an extra file. This technique was used, for example, for the gif animation entry. There the loop was executed by
t = 0 end_time = 1 load 'bessel.plt'
with the file bessel.plt containing the code to execute within the loop
# bessel.plt t = t + 0.02 outfile = sprintf('animation/bessel%03.0f.png',50*t) set output outfile splot u*sin(v),u*cos(v),bessel(u,t) w pm3d ls 1 if(t<end_time) reread;
This can now be reformulated in a much shorter way by applying the new do command and the block-structure given by the { }
do for [t=0:50] { outfile = sprintf('animation/bessel%03.0f.png',t) set output outfile splot u*sin(v),u*cos(v),bessel(u,t/50.0) w pm3d ls 1 }
Now there is no need for an additional file. The only thing to consider is the change of the index t, because for the for-loop t has to be an integer.
The block-structure can in the same way be applied to the if-statement.