首页 > 解决方案 > Fortran - 跳转其他子程序

问题描述

我正在尝试在 Fortran 代码中跳转其他子程序。我使用了返回函数,但在某些情况下它不起作用。有什么办法可以跳转到其他子程序。我做了一个简单的例子来定义问题。如果条件在同一个子程序中,我可以使用goto 标签,但我需要跳转不同的子程序。如果条件正确(case = .True.),我不想计算那个子程序,所以我会跳过那个子程序,我会开始使用新数据。例如,如果i=3 and case=true,程序不应在第三个循环中打印 a=8 并在子程序 abc 中跳转 do 循环。

---------------------------------------------- 
subroutine abc()

do i=1, 5

 !if case is true, start to program from here.
 call vector ()
end do
end subroutine
-------------------------------------
subroutine vector()
if (case = .True.)then
 *****JUMP call vector in main program *****
 print *,"skip and jump "
 return
 a= 8
 print *, a 
 else
 b= 9
 print *, b
 print *, "continue the process "
 end if
end subroutine
------------------------------------------------

 -----output should be-------
 9
 9
 skip and jump
 9
 9

标签: fortransubroutine

解决方案


推荐阅读