gpt4 book ai didi

if-statement - 将 Go-to 语句从 FORTRAN 77 转换为 Fortran 90

转载 作者:行者123 更新时间:2023-12-05 01:32:44 24 4
gpt4 key购买 nike

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 导致“跳出循环”。在这个特定的例子中,这相当于一个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

关于if-statement - 将 Go-to 语句从 FORTRAN 77 转换为 Fortran 90,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31616958/

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