How to call and use a subroutine inside another subroutine in fortran?

狂风中的少年 提交于 2019-12-23 18:30:32

问题


I am doing a program in which the main contains many subroutines and functions. For constructing one of these subroutines of the main (let's say subroutine A) I need to make use of another subroutine (let's say B). My question is, how can I make subroutine A call and use subroutine B? I am a beginner and I have searched a lot but found nothing that I understand clearly...

Any help would be appreciated, thanks in advance!


回答1:


Example of layout, in one file:

module MySubs

contains

subroutine A (..)

end subroutine A

subroutine B (..)

   call subroutine A (..)

end subroutine B

function C (..)

end function C

end module MySubs

program MyProg

  use MySubs

  call A (..)

  X = C (..)

end program MyProg

You can also place the module and and main program in different files. In that case compile the file with the module first.




回答2:


Normally you put all procedures in a module and then use the module.

If, as your question suggest make all procedures as internal to your main program, there is no problem in calling them. Just invoke them normally using the call statement, or by using the function name with the argument list.



来源:https://stackoverflow.com/questions/20772817/how-to-call-and-use-a-subroutine-inside-another-subroutine-in-fortran

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!