1
votes

i am trying to make a fluid vector animation in gnuplot. To create the vector values i use FORTRAN. My FORTRAN subroutine program prints vector data in a txt file called vekdata.txt and creates another file called plotvek.txt with gnuplot commands. This subroutine is inside a do loop so for every iteration vekdata.txt gets updated.

So i was wandering how i can make an animation of this as it develops in time? Is there some simple commands? As it is now it prints a huge amount of picture to my screen. Every picture is a bit different so i know the code works.

do t=1,1000

call vektorplot(storu,storv,n,Re,t)

end do





open(21,access='sequential',file='plotvek.txt',status='unknown')

write(21,*)'set term png enhanced'
write(21,*)'# plotvek.txt'
write(21,*)'set output sprintf(''frame_%09d.png'',',t,')'




!animation commands
write(21,*)'set output sprintf("frame_%9d",'t,')'


close(21,status='keep')


call execute_command_line("gnuplot -persist plotvek.txt")
2

2 Answers

2
votes

I'm posting here an alternative.

Although I usually prefer the animated gif as Karl answers, sometimes too big gifs are difficult to rented and especially for very long movies, they tend to create unresponsive applications (browser or slide presentations).


Basically you write to a file every frame and then create a movie.

In this link you have both gif and movie examples. I'm going to recall here the principles.

For every frame you set a png terminal and output file. As fortran command, this would be something like:

write(21,*)'set term png enhanced'
write(21,*)'# plotvek.txt'
write(21,*)'set output sprintf("frame_%09d.png",',n+1,')'
[...]

Then, once the program is run, you can create a movie:

mencoder mf://frame_%09d.png -mf fps=30 -ovc lavc -o my_video.avi

Of course mencoder has a tons of options to tune your movie.

Another alternative to mencoder is ffmpeg:

ffmpeg -framerate 1/5 -i frame_%09d.png -c:v libx264 -r 30 -pix_fmt yuv420p my_video.mp4
2
votes

The gif terminal has an option to make a gif animation, but you have to plot it all in one call to the gnuplot script.

You could try something like this:

$ makevectors | gnuplot 

where makevectors is the executable of your fortran code, only it prints everything to STDOUT, first

set term gif animation
set out 'vectors.gif'
# plus the rest of your settings
do for [i=1:100] {plot '-' using 1:2:($3*30):($4*25) with vectors}

, then 100 data sets, with an EOF after each. Lastly print

set out

(Ok, the output would close anyway, but just to be very orderly) and you've got a file with that gif animation.

Update: I'd recommend you move your gnuplot commands to a script file and have gnuplot call that on the command line makevectors | gnuplot script.gp. That way you don't have to recompile the program every time you want to change a line colour or something.