如何在fortran的另一个子例程中调用和使用子例程? [英] How to call and use a subroutine inside another subroutine in fortran?
问题描述
我正在做一个程序,其中main包含许多子程序和函数。为了构建主程序的这些子程序之一(假设子程序A),我需要使用另一个子程序(比方说B)。我的问题是,如何使子程序A调用并使用子程序B?我是一个初学者,我搜查了很多,但没有发现我清楚的理解......
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!
推荐答案
布局示例在一个文件中:
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.
这篇关于如何在fortran的另一个子例程中调用和使用子例程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!