有人可以帮我解决以下问题吗?我是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'?
答案 0 :(得分:3)
您的陈述中的括号,例如
do (i=1,mesh-1)
是不可接受的,Fortran中的正确形式是
do i=1,mesh-1
未能看到(有效)do
语句后,编译器会在找到无法匹配的end do
语句时抱怨。修复do
语句,关于期望end program
语句的错误应该消失。