我遇到这样的问题:
所有四点都是单独写的。
main.f90时
include sub_A.f90
include sub_B.f90
include other_stuffs.f90
program MAIN
use A
use B
use other
...
call proc_A
call_proc_B
end program MAIN
sub_A.f90
module A
contains
subroutine proc_A
use other
...
call compute_something_1
end subroutine proc_A
end module A
sub_B.f90
module B
contains
subroutine proc_B
use other
...
call compute_something_2
end subroutine proc_B
end module B
other_stuffs.f90
module other
contains
subroutine compute_something_1
...
end subroutine compute_something_1
subroutine compute_something_2
...
end subroutine compute_something_2
end module other
不幸的是,它没有用。我做错什么了吗?
答案 0 :(得分:2)
您错过了contains
模块中的other
部分。
只能从模块外部访问contains
部分中的子程序,函数和变量。
module other
contains
subroutine compute_something_1
...
end subroutine compute_something_1
subroutine compute_something_2
...
end subroutine compute_something_2
end module other
答案 1 :(得分:0)
答案应如下
<强> main.f90时强>
IIS_IUSRS ([server name]\IIS_IUSRS)
<强> sub_A.f90 强>
include other_stuffs.f90 !It becomes the first now
include sub_A.f90
include sub_B.f90
program MAIN
use other
use A
use B
...
call proc_A
call_proc_B
end program MAIN
<强> sub_B.f90 强>
module A
use other ! CORRECT PLACE
contains
subroutine proc_A
! use other !WRONG PLACE !!!
...
call compute_something_1
end subroutine proc_A
end module A
<强> other_stuffs.f90 强>
module B
use other ! CORRECT PLACE
contains
subroutine proc_B
! use other !WRONG PLACE !!!
...
call compute_something_2
end subroutine proc_B
end module B
谢谢大家。