fortran 没有全局变量。
共享数据的方式有:
虚参传递。可使用动态数组
common 公共区。不可使用动态数组,老语法,不推荐。
module 模块。可使用动态数组,强力推荐
例:
program main
use subs
implicit none
real(8) :: a(5)
call test1
call test2(a)
print *, a
end program
module subs
contains
subroutine test1()
use sharemod
implicit none
allocate(share(5))
share = (/1., 2., 3., 5., 6./)
end subroutine
subroutine test2(output)
use sharemod
implicit none
real(8), intent(out) :: output(5)
output = share
end subroutine test2
end module subs
module sharemod
implicit none
save
real(8), allocatable, dimension(:) :: share
end module sharemod