【问题标题】:How to make animated gif in Gnuplot 5如何在 Gnuplot 5 中制作动画 gif
【发布时间】:2017-12-26 12:37:34
【问题描述】:

基本上,我已经求解了 (x,y,t) 的热方程,我想显示温度函数随时间的变化。程序是用 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 值。

我的代码有什么问题,我应该如何处理?

【问题讨论】:

  • 对于所有 Fortran 问题,请使用标签 fortran。您的问题甚至不是针对旧的 90 标准。实际上,我不确定 Fortran 部分是否与此处相关......
  • 您确实可以用它创建的输出样本替换整个 Fortran 代码(它甚至只是列表导向的输出)。
  • @francescalus 你能告诉我 GNU 术语中的代码有什么问题吗?我不是一个狂热的程序员。
  • 恐怕我对这些 gnuplot 方面完全没有经验。但是,如果您对 Fortran 有疑问...

标签: animation fortran gnuplot animated-gif


【解决方案1】:

首先,尝试为“调试”信息添加一些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 总是绘制整个文件,这有两个后果:

  1. 数据文件很大。绘图需要很长时间,而且 gnuplot 似乎挂起。
  2. Gnuplot 总是绘制相同的数据,动画中不会显示任何变化。

现在 gnuplot 运行得更快了,我们将修复自动缩放错误。同样,有两点:

  1. index 指定数据文件中的数据集。 stats 命令计算那些“由成对的空白记录分隔”的集合(来自 gnuplot 文档)。您的数据文件以一对空白记录结尾 - 这会在 gnuplot 中启动一个新数据集。但是这个数据集是空的,最终导致错误。只有STATS_blocks-1 数据集。

  2. index 从零开始。循环应该从 0 开始并在 STATS_blocks-2 结束。

所以我们得到了这个绘图命令:

do for [i=0:int(STATS_blocks)-2] {
  print i
  splot 'diffeqn3D_file.txt' index i
}

【讨论】:

    猜你喜欢
    • 2014-05-18
    • 1970-01-01
    • 2015-08-13
    • 2021-07-19
    • 2020-06-02
    • 2018-03-01
    • 2019-05-24
    • 2014-04-10
    相关资源
    最近更新 更多