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。
如果选择导入名称标记为私有,则不能将其导入程序。
热门推荐
10 五一公司放假祝福语简短
11 追星女孩的祝福语简短
12 给长辈端午祝福语 简短
13 生日祝福语有诗意简短
14 团圆日祝福语简短
15 中秋商务祝福语简短最新
16 温暖文艺简短祝福语短句
17 男孩上学祝福语简短的
18 入住酒店文案祝福语简短