Fortran中输出Tecplot格式

在Fortran代码中,若要输出Tecplot格式结果,主要是要注意Tecplot文件的头部格式。

代码示例:

    program main
    implicit none
    integer(kind=4),parameter :: N=100
    integer(kind=4) :: i,j
    real(kind=8) :: H
    real(kind=8) :: x(1:N+1,1:N+1),y(1:N+1,1:N+1),phi(1:N+1,1:N+1)
   
   H=2.D0/100
    do j=1,N+1,1
       do i=1,N+1,1
           x(i,j)=real(i-1,8)*H
           y(i,j)=real(j-1,8)*H
       end do
    end do
   phi=1.D0
   
    call output1(phi,x,y,N+1)
    call output2(phi,x,y,N+1)
    call output3(phi,x,y,N+1)
    call output4(phi,x,y,N+1)
    call output5(phi,x,y,N+1)
   
    stop
    end program main
    


    形式1:
    subroutine output1(phi,x,y,M)
    implicit none  
   integer(kind=4) :: i,j,M
    real(kind=8) :: x(M,M),y(M,M),phi(M,M)
   
   open(unit=99,file="Tecplot.dat")
    write(99,*) 'title="Tecplot"'
    write(99,*) 'variables="x" "y" "phi"'
    write(99,*) 'zone t="Fortran"  i=',M,' j=',M,' f=point'
    do j=1,M,1
       do i=1,M,1
           write(99,*) x(i,j),y(i,j),phi(i,j)
       end do
    end do
   close(99)

 

   return
    end subroutine output1
   
   

   形式2:
    subroutine output2(phi,x,y,M)
    implicit none  
   integer(kind=4) :: i,j,M
    real(kind=8) :: x(M,M),y(M,M),phi(M,M)
   
   open(unit=99,file="Tecplot.dat")
    write(99,*) 'title="Tecplot"'
    write(99,*) 'variables="x" "y" "phi"'
    write(99,*) 'zone t="Fortran"  i=',M,' j=',M,' f=point'
    write(99,*) ((x(i,j),y(i,j),phi(i,j),i=1,M,1),j=1,M,1)
   close(99)

 

   return
    end subroutine output2
    


    形式3:
    subroutine output3(phi,x,y,M)
    implicit none  
   integer(kind=4),intent(in) :: M
   real(kind=8),intent(in) :: x(M,M),y(M,M),phi(M,M)
   integer(kind=4) :: i,j
   
   open(unit=99,file="Tecplot.dat")
    write(99,*) 'title="Tecplot"'
    write(99,*) 'variables="x" "y" "phi"'
    write(99,*) 'zone t="Fortran"  i=',M,' j=',M,' f=point'
   write(99,100) ((x(i,j),y(i,j),phi(i,j),i=1,M,1),j=1,M,1)
   close(99)
   
100 format(F10.7,3X,F10.7,3X,F10.7)

 

   return
    end subroutine output3
   


    形式4:
    subroutine output4(phi,x,y,M)
    implicit none  
   integer(kind=4),intent(in) :: M
   real(kind=8),intent(in) :: x(M,M),y(M,M),phi(M,M)
   integer(kind=4) :: i,j
   
   open(unit=99,file="Tecplot.dat")
   write(99,"('title=""Tecplot""',A20)")
   write(99,"('variables=""x"",""y"",""phi""',A20)")
   write(99,"('zone t=""Fortran"",i=',I3,',j=',I3,',f=point',A20)") M,M
   write(99,"(F10.7,3X,F10.7,3X,F10.7)") ((x(i,j),y(i,j),phi(i,j),i=1,M,1),j=1,M,1)
   close(99)

 

   return
    end subroutine output4
   


    形式5:
    subroutine output5(phi,x,y,M)
    implicit none  
   integer(kind=4),intent(in) :: M
   real(kind=8),intent(in) :: x(M,M),y(M,M),phi(M,M)
   integer(kind=4) :: i,j
   character(len=100) :: Fortran,outpath="D:\路径..\"
   
   write(Fortran,*) M
   open(unit=99,file="Tecplot.dat")
   !open(unit=99,file=trim(adjustl(outpath))//"Tecplot.dat")
   write(99,"('title=""Tecplot""',A20)")
   write(99,"('variables=""x"",""y"",""phi""',A20)")
   write(99,"('zone t=',A8,',i=',I3,',j=',I3,',f=point',A20)") 'Num'//trim(adjustl(Fortran)),M,M
   write(99,"(F10.7,3X,F10.7,3X,F10.7)") ((x(i,j),y(i,j),phi(i,j),i=1,M,1),j=1,M,1)
   close(99)

 

   return
    end subroutine output5
   !注:在输出Tecplot格式时,注意在第三行中“t=”后面第一个字符不能为数字。

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值