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

Ner*_*ess 2 fortran if-statement fortran77 fortran90 do-loops

我正在处理一段旧的F77代码,并尝试将其转换为等效的F90代码。我在下面遇到了这些问题,有人可以建议我的转换正确吗?

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
Run Code Online (Sandbox Code Playgroud)

我试图将其转换为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
Run Code Online (Sandbox Code Playgroud)

有人可以建议这种方法是否正确吗?在我的结果中,我没有得到我期望的结果。因此,我的逻辑可能存在问题。

Ale*_*ogt 5

您的翻译略有错误...第一步是重建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
Run Code Online (Sandbox Code Playgroud)

现在您可以看到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
Run Code Online (Sandbox Code Playgroud)