在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=”后面第一个字符不能为数字。