在CentOS系統中,使用Fortran模塊需要遵循以下步驟:
sudo yum install gcc-gfortran
mymodule.f90),并在其中定義模塊。例如:module mymodule
implicit none
integer, parameter :: myconst = 42
contains
subroutine mysubroutine(a, b)
integer, intent(in) :: a
integer, intent(out) :: b
b = a * myconst
end subroutine mysubroutine
end module mymodule
.mod文件:gfortran -c mymodule.f90
這將在當前目錄下生成一個名為mymodule.mod的文件。
main.f90),并在其中導入和使用剛剛創建的模塊。例如:program main
use mymodule
implicit none
integer :: result
call mysubroutine(2, result)
print *, 'The result is:', result
end program main
gfortran -o main main.f90 mymodule.o
這將在當前目錄下生成一個名為main的可執行文件。
./main
這將輸出:
The result is: 84
這就是在CentOS中使用Fortran模塊的基本過程。根據實際需求,可以創建和使用多個模塊,并在主程序中導入它們。