I can think of at least three ways to do this, although I doubt it is worth the effort.
(1) Create and save a gnuplot script in each iteration as well as the data from x(1) to x(i), then run the script (say, foo.plt) with call system('gnuplot -p foo.plt'
). The gnuplot script can be easily created with standard Fortran open
, write
, and close
commands. It should clear the screen and plot on the same window each iteration. For this to look nice you should also know the x and y range of the plot (maxval(x)
and maxval(y)
), and use them each time for each plot.
(2) Alternatively, you can just save all your data once, then in each iteration use a gnuplot script to plot part of it. This involves GNU/Linux commands such as awk
, again called in your program with the system
command. The rest of the procedure is as in (1). More sophisticated but also more complicated.
(3) Use gnuplot streams. This can be done in several ways, but the outline of the method is described here (although this is in Pearl). I played with streams in the past, and I got the result I wanted, but in the end I wasnât sure I prefer this solution over the others, even though in theory it is more ârobustâ.
However, I wouldnât call any of the above an elegant solution. Donât get me wrong, gnuplot is excellent software, I use it all the time. But it is not ideal for what you want to do, because gnuplot is external software that has nothing to do with Fortran. Using gnuplot within a Fortran program is perfectly ok if you just want to plot some results, but becomes unnecessarily complicated when it comes to animations.
If I wanted to do something like this, I would definitely look for other, more promising solutions: PLplot comes to mind first (alone or with gtk-fortran), or Dislin. Both can be used in your program as a Fortran module, so you can be more interactive without the hassle of relying on system
commands.
Last but not least, I am not sure all this is worth the effort. Unless you have serious, time consuming computations needed to be done in each loop iteration, you wouldnât see any animation since the frames would be plotted very quickly, so you would have to sleep your program in each iteration to actually see any frame. There is a reason people just save all the results, plot them with gnuplot, then create an animation using external software such as gimp or imagemagick.