我正在尝试使用与我的主程序在同一文件中的模块.但是,我无法让它发挥作用.Fortran是否允许模块包含在与主程序相同的文件中,或者它是否必须位于单独的文件中?这是我的代码的简单版本:
main program
use my_module
call my_subroutine()
end program main
module my_module
contains
subroutine my_subroutine()
print *, "Hello World!"
end subroutine my_subroutine
end module my_module
Run Code Online (Sandbox Code Playgroud)
当我尝试编译此文件时,我得到:
Fatal Error: Can't open module file 'my_module.mod' for reading at (1): No such file or directory
Run Code Online (Sandbox Code Playgroud)
Dav*_*sen 10
是的,Fortran确实允许模块包含在与主程序相同的文件中.但是,必须在主程序之前编写模块:
module my_module
contains
subroutine my_subroutine()
print *, "Hello World!"
end subroutine my_subroutine
end module my_module
program main
use my_module
call my_subroutine()
end program main
Run Code Online (Sandbox Code Playgroud)