gpt4 book ai didi

compiler-errors - Fortran 编译错误 : Unclassifiable statement

转载 作者:行者123 更新时间:2023-12-02 10:44:35 25 4
gpt4 key购买 nike

有人可以帮我解决以下问题吗?我是 Fortran 新手,正在尝试使用 GCC for Windows 运行以下命令。

program jacobi
implicit none
double precision, dimension(:,:), allocatable :: u, u_n
double precision :: Res_2, Res_inf
integer :: i,j,mesh,unit
mesh=64

Res_2=0
allocate(u(0:mesh,0:mesh))
allocate(u_n(0:mesh,0:mesh))
u=0
u_n=0
u(:,0)=1
u_n(:,0)=1
unit=12

open(unit, file="array.txt", access='append', status='old')

do while (Res_2>1D-10)
Res_2=0
do (i=1,mesh-1)
do (j=1,mesh-1)
u(i,j)=0.25D0*(u_n(i+1,j)+u_n(i-1,j)+u_n(i,j-1))
end do
end do
Res_inf=-4D0*maxval((u-u_n))
do (i=1,mesh-1)
do (j=1,mesh-1)
Res_2=Res_2+(-4D0*(u(i,j)-u_n(i,j)))**2
end do
end do
Res_2=sqrt(Res_2)
write(1,*) Res_2
end do
close(unit)

end program jacobi

我在编译时不断收到这些错误:
jacobi.f95:21.2:

do (i=1,mesh-1)
1
Error: Unclassifiable statement at (1)
jacobi.f95:22.3:

do (j=1,mesh-1)
1
Error: Unclassifiable statement at (1)
jacobi.f95:25.5:

end do
1
Error: Expecting END PROGRAM statement at (1)
jacobi.f95:27.2:

我使用 do 循环错了吗?我是否错误地声明了变量“i,j”?

最佳答案

语句中的括号,例如

do (i=1,mesh-1)

Not Acceptable ,Fortran 中的正确形式是
do i=1,mesh-1

未能看到(有效的) do声明编译器后来提示发现不匹配的 end do陈述。修复 do语句,关于期望 end program 的错误声明应该消失。

关于compiler-errors - Fortran 编译错误 : Unclassifiable statement,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22268773/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com