在Ubuntu上进行Fortran模块化编程,你可以遵循以下步骤:
sudo apt update
sudo apt install gfortran
module_example.f90的文件,并在其中定义一个简单的模块:! module_example.f90
module my_module
implicit none
integer, parameter :: my_param = 42
contains
subroutine my_subroutine(x)
integer, intent(in) :: x
print *, 'The value of x is:', x
end subroutine my_subroutine
end module my_module
main.f90的文件:! main.f90
program main
use my_module
implicit none
call my_subroutine(my_param)
end program main
gfortran -o main module_example.f90 main.f90
这将生成一个名为main的可执行文件。
5. 运行程序:
在终端中运行生成的可执行文件:
./main
你应该会看到输出:
The value of x is: 42
这就是在Ubuntu上进行Fortran模块化编程的基本过程。你可以根据需要创建更多的模块和子程序,并在主程序中使用它们。记得在编译时包含所有相关的源文件。