是否有可能(甚至明智地)从模块中“封装”常量以在 USE : ONLY 语句中使用?

问题描述 投票:0回答:1

下面是我的模块源码的框架。 我知道如何执行“use : only”来根据需要从中提取函数和子例程。我不知道如何做的是对模块进行编码,以便我可以仅使用 USE 绘制顶部的两个常量,并忽略函数和子例程(如果我愿意的话)。有这样做的源构造吗? (使用 gfortran,如果这有影响的话。)

或者我是否需要将所有常量放在自己的模块文件中,以便可以独立于其他任何内容引入它们?

a module QBtools
    implicit none

!module constants
integer, parameter  :: MAXSIZE = 500 !max allowed length of input record
integer, parameter  :: FIELDSIZE = 150 !max allowed length of individual fields from input record

contains




function QBgetfield(record,desired_field) result(fieldbuffer)

!function code here

endfunction QBgetfield



function getWINenv(request) result(varout)

!function code here

end function getWINenv


subroutine QBTrmlfs(filein)

!function code here

end subroutine QBTrmlfs

function QBfieldcount(record) result(counter)

!function code here

endfunction QBfieldcount

function QBstrip(str) result(strout)

!function code here

end function QBstrip



end module QBtools

fortran gfortran
1个回答
0
投票

你做过实验吗?

module foo

   implicit none  ! <-- Always included to force declaration of entities.
   private        ! <-- Always included to hide everything in the module
   public pi, ln2 ! <-- Entities in module that are visible through USE

   real, parameter :: pi  = 0.6931
   real, parameter :: ln2 = 3.1415
end module foo

program bah
   use foo, only : pi, ln2
   print *, pi, ln2
end program bah
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.