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 婆婆66岁祝福语简短
13 今天孩子高考祝福语简短
14 送彩票生日祝福语简短
15 分别祝福语简短情话英文
16 画室揭牌仪式祝福语简短
17 女友妈妈生日祝福语简短
18 离别赠言离职祝福语简短