Fortran 使用其他程序单元中的模块
示例
要从另一个程序单元(模块,过程或程序)访问模块中声明的实体,该模块必须与语句一起使用use。
module shared_data implicit none integer :: iarray(4) = [1, 2, 3, 4] real :: rarray(4) = [1., 2., 3., 4.] end module program test !use statements most come before implicit none use shared_data implicit none print *, iarray print *, rarray end program
该use语句仅支持导入所选名称
program test !only iarray is accessible use shared_data, only: iarray implicit none print *, iarray end program
也可以使用重命名列表以其他名称访问实体:
program test !only iarray is locally renamed to local_name, rarray is still acessible use shared_data, local_name => iarray implicit none print *, local_name print *, rarray end program
此外,可以将重命名与only选项结合使用
program test use shared_data, only : local_name => iarray end program
这样就只能iarray访问模块实体,但是它具有本地名称local_name。
如果选择导入名称标记为私有,则不能将其导入程序。
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下