在Fortran中重构和模块化代码可以通过以下步骤实现:
module
关键字来定义一个模块。例如:module mymodule
implicit none
private
contains
subroutine sub1()
! sub1 code
end subroutine
end module
use
语句来引用已经定义的模块,以便使用其中定义的子程序和变量。例如:program main
use mymodule
implicit none
call sub1()
end program
module mymodule
implicit none
contains
subroutine sub1()
! sub1 code
end subroutine
end module
program main
use mymodule
implicit none
interface
subroutine sub1()
end subroutine
end interface
call sub1()
end program
type
来实现。例如:module mymodule
implicit none
type :: mytype
integer :: data
end type
contains
subroutine sub1(obj)
type(mytype), intent(inout) :: obj
! sub1 code
end subroutine
end module