如何在 Gnuplot 5 中制作动画 gif
How to make animated gif in Gnuplot 5
基本上,我已经求解了 (x,y,t) 的热方程,我想用 time.The 程序显示温度函数的变化,程序是用 Fortran 90 编写的,求解数据已存储在文件中 diffeqn3D_file.txt.
这是程序:
Program diffeqn3D
Implicit none
Integer:: b,c,d,l,i,j,k,x,y,t
Real:: a,r,s,h,t1,k1,u,v,tt,p
Real,Dimension(0:500,0:500,0:500):: f1 !f=f(x,t)
!t1=time step and h=position step along x and
!k=position step along y and a=conductivity
open(7, file='diffeqn3D_file.txt', status='unknown')
a=0.024
t1=0.1
h=0.1
k1=0.1
r=(h**2)/(k1**2)
s=(h**2)/(a*t1)
l=10
tt=80.5
b=100
c=100
d=100
!The temperature is TT at x=0 and 0 at x=l.
!The rod is heated along the line x=0.
!Initial conditions to be changed as per problem..
Do x=0,b
Do y=0,c
Do t=0,d
If(x==0) Then
f1(x,y,t)=tt
Else If((x.ne.0).and.t==0) Then
f1(x,y,t)=0
End If
End Do
End Do
End Do
print *,f1(9,7,5)
print *,r
print *,a,h,t1,h**2,a*t1,(h**2)/(a*t1)
print *,f1(0,1,1)
print *,f1(3,1,1)
!num_soln_of_eqnwrite(7,*)
Do t=1,d
Do y=1,c-1
Do x=1,b-1
p=f1(x-1,y,t-1)+f1(x+1,y,t-1)+r*f1(x,y-1,t-1)+r*f1(x,y+1,t-1)-(2+2*r-s)*f1(x,y,t-1)
f1(x,y,t)=p/s
!f1(x,t)=0.5*(f1(x-1,t-1)+f1(x+1,t-1))
!print *,f1(x,t),b
End Do
End Do
End Do
Do i=0,d
Do k=0,b
Do j=0,c
u=k*h
v=j*k1
write(7,*) u,v,f1(k,j,i)
End Do
End Do
write(7,*) " "
write(7,*) " "
End Do
close(7)
End Program diffeqn3D
并且在编译和运行之后,我在gnuplot中输入了下面的代码但是它没有运行,而是挂起或者创建了一个gif图片,而不是动画。
set terminal gif animate delay 1
set output 'diffeqn3D.gif'
stats 'diffeqn3D_file.txt' nooutput
do for [i=1:int(STATS_blocks)] {
splot 'diffeqn3D_file.txt'
}
有时它还会发出警告消息,指出自动缩放范围没有 z 值。
我的代码有什么问题,我应该如何处理?
首先,尝试为 "debug" 信息添加一些 print
命令:
set terminal gif animate delay 1
set output 'diffeqn3D.gif'
stats 'diffeqn3D_file.txt' nooutput
print int(STATS_blocks)
do for [i=1:int(STATS_blocks)] {
print i
splot 'diffeqn3D_file.txt'
}
其次,会发生什么?
splot
命令没有索引说明符,尝试使用:
splot 'diffeqn3D_file.txt' index i
没有 index i
gnuplots 总是绘制整个文件,这有两个结果:
- 数据文件很大。绘图需要相当长的时间,而且 gnuplot 似乎挂起。
- Gnuplot 始终绘制相同的数据,动画中不会出现任何变化。
现在 gnuplot 运行得更快,我们将修复自动缩放错误。同样,有两点:
index
指定数据文件中的一个数据集。 stats
命令计算那些 "are separated by pairs of blank records" 的集合(来自 gnuplot 文档)。您的数据文件以一对空白记录结尾——这将在 gnuplot 中启动一个新数据集。但是这个数据集是空的,最终导致错误。只有STATS_blocks-1
个数据集。
index
是从零开始的。循环应该从 0 开始到 STATS_blocks-2.
结束
所以我们得到了这个绘图命令:
do for [i=0:int(STATS_blocks)-2] {
print i
splot 'diffeqn3D_file.txt' index i
}
基本上,我已经求解了 (x,y,t) 的热方程,我想用 time.The 程序显示温度函数的变化,程序是用 Fortran 90 编写的,求解数据已存储在文件中 diffeqn3D_file.txt.
这是程序:
Program diffeqn3D
Implicit none
Integer:: b,c,d,l,i,j,k,x,y,t
Real:: a,r,s,h,t1,k1,u,v,tt,p
Real,Dimension(0:500,0:500,0:500):: f1 !f=f(x,t)
!t1=time step and h=position step along x and
!k=position step along y and a=conductivity
open(7, file='diffeqn3D_file.txt', status='unknown')
a=0.024
t1=0.1
h=0.1
k1=0.1
r=(h**2)/(k1**2)
s=(h**2)/(a*t1)
l=10
tt=80.5
b=100
c=100
d=100
!The temperature is TT at x=0 and 0 at x=l.
!The rod is heated along the line x=0.
!Initial conditions to be changed as per problem..
Do x=0,b
Do y=0,c
Do t=0,d
If(x==0) Then
f1(x,y,t)=tt
Else If((x.ne.0).and.t==0) Then
f1(x,y,t)=0
End If
End Do
End Do
End Do
print *,f1(9,7,5)
print *,r
print *,a,h,t1,h**2,a*t1,(h**2)/(a*t1)
print *,f1(0,1,1)
print *,f1(3,1,1)
!num_soln_of_eqnwrite(7,*)
Do t=1,d
Do y=1,c-1
Do x=1,b-1
p=f1(x-1,y,t-1)+f1(x+1,y,t-1)+r*f1(x,y-1,t-1)+r*f1(x,y+1,t-1)-(2+2*r-s)*f1(x,y,t-1)
f1(x,y,t)=p/s
!f1(x,t)=0.5*(f1(x-1,t-1)+f1(x+1,t-1))
!print *,f1(x,t),b
End Do
End Do
End Do
Do i=0,d
Do k=0,b
Do j=0,c
u=k*h
v=j*k1
write(7,*) u,v,f1(k,j,i)
End Do
End Do
write(7,*) " "
write(7,*) " "
End Do
close(7)
End Program diffeqn3D
并且在编译和运行之后,我在gnuplot中输入了下面的代码但是它没有运行,而是挂起或者创建了一个gif图片,而不是动画。
set terminal gif animate delay 1
set output 'diffeqn3D.gif'
stats 'diffeqn3D_file.txt' nooutput
do for [i=1:int(STATS_blocks)] {
splot 'diffeqn3D_file.txt'
}
有时它还会发出警告消息,指出自动缩放范围没有 z 值。
我的代码有什么问题,我应该如何处理?
首先,尝试为 "debug" 信息添加一些 print
命令:
set terminal gif animate delay 1
set output 'diffeqn3D.gif'
stats 'diffeqn3D_file.txt' nooutput
print int(STATS_blocks)
do for [i=1:int(STATS_blocks)] {
print i
splot 'diffeqn3D_file.txt'
}
其次,会发生什么?
splot
命令没有索引说明符,尝试使用:
splot 'diffeqn3D_file.txt' index i
没有 index i
gnuplots 总是绘制整个文件,这有两个结果:
- 数据文件很大。绘图需要相当长的时间,而且 gnuplot 似乎挂起。
- Gnuplot 始终绘制相同的数据,动画中不会出现任何变化。
现在 gnuplot 运行得更快,我们将修复自动缩放错误。同样,有两点:
index
指定数据文件中的一个数据集。stats
命令计算那些 "are separated by pairs of blank records" 的集合(来自 gnuplot 文档)。您的数据文件以一对空白记录结尾——这将在 gnuplot 中启动一个新数据集。但是这个数据集是空的,最终导致错误。只有STATS_blocks-1
个数据集。index
是从零开始的。循环应该从 0 开始到 STATS_blocks-2. 结束
所以我们得到了这个绘图命令:
do for [i=0:int(STATS_blocks)-2] {
print i
splot 'diffeqn3D_file.txt' index i
}