将 Go-to 语句从 FORTRAN 77 转换为 Fortran 90
Converting a Go-to statement from FORTRAN 77 to Fortran 90
I am working on a piece of legacy F77 code and trying to convert it
to equivalent F90 code. I ran into these lines below and could some
one advise if my conversion is correct?
Fortran 77 代码:
Subroutine area(x,y,z,d)
do 15 j=1,10
if (a.gt.b) go to 20
15 CONTINUE
20 Statement 1
Statement 2
Statement 3
end subroutine
我尝试将其转换为 F90,结果如下:
Subroutine area(x,y,z,d)
dloop: do j=1,10
if (a>b) then
statement 1
statement 2
statement 3
else
write(*,*) 'Exiting dloop'
exit dloop
end if
end do dloop
end subroutine
谁能告诉我这个方法是否正确?在我的结果中,我没有得到我期望的结果。所以我的逻辑可能有问题。
你的翻译有点错误...第一步是重建 do
循环,它在 15
处循环:
Subroutine area(x,y,z,d)
do j=1,10
if (a.gt.b) go to 20
enddo
20 Statement 1
Statement 2
Statement 3
end subroutine
现在您可以看到 goto
结果为 "jumping out of the loop"。在这个特定的例子中,这相当于一个exit
,代码可以写成
Subroutine area(x,y,z,d)
do j=1,10
if (a.gt.b) exit
enddo
Statement 1
Statement 2
Statement 3
end subroutine
I am working on a piece of legacy F77 code and trying to convert it to equivalent F90 code. I ran into these lines below and could some one advise if my conversion is correct?
Fortran 77 代码:
Subroutine area(x,y,z,d)
do 15 j=1,10
if (a.gt.b) go to 20
15 CONTINUE
20 Statement 1
Statement 2
Statement 3
end subroutine
我尝试将其转换为 F90,结果如下:
Subroutine area(x,y,z,d)
dloop: do j=1,10
if (a>b) then
statement 1
statement 2
statement 3
else
write(*,*) 'Exiting dloop'
exit dloop
end if
end do dloop
end subroutine
谁能告诉我这个方法是否正确?在我的结果中,我没有得到我期望的结果。所以我的逻辑可能有问题。
你的翻译有点错误...第一步是重建 do
循环,它在 15
处循环:
Subroutine area(x,y,z,d)
do j=1,10
if (a.gt.b) go to 20
enddo
20 Statement 1
Statement 2
Statement 3
end subroutine
现在您可以看到 goto
结果为 "jumping out of the loop"。在这个特定的例子中,这相当于一个exit
,代码可以写成
Subroutine area(x,y,z,d)
do j=1,10
if (a.gt.b) exit
enddo
Statement 1
Statement 2
Statement 3
end subroutine