Vittorio G. Caffa wrote:
> I don't use include...
I also prefer not to use include, but I have found one useful application
for it that can't be done with modules: Simulating what are called
"generic packages" in Ada or "templates" in C++.
Here's how I do it:
module Single_Precision
private
interface FUNC; module procedure FUNC_; end interface; public FUNC
integer, parameter :: RK = KIND(0.0e0)
contains
include `x_body.inc'
end module Single_Precision
module Double_Precision
private
interface FUNC; module procedure FUNC_; end interface; public FUNC
integer, parameter :: RK = KIND(0.0d0)
contains
include `x_body.inc'
end module Single_Precision
%cat x_body.inc
real(RK) function FUNC_ ( X )
real(RK) :: X
real(RK) :: my_var_1, my_var_2
...
end function FUNC
Notice that you need to use separate modules so that the header for the
FUNC_ function can be in the include file. Otherwise, you'd have two
FUNC_ functions in one module, and that wouldn't work.
You can do it with types that are different by other than kind by moving the
procedure header, declaration of arguments, maybe declaration of a few
local variables, and the "end function" statement into the module. Fortran
2000 proposes to include a "type alias" feature that would simplify this,
but at present it's crippled by prohibiting to use intrinsic types.
Of course, the real solution is a generic/template facility, but that's
not even on the table for Fortran 2000.
Best regards,
Van Snyder
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|