Is there a way to define generic procedures to dynamically handle each kind
of int
, character
and real
without having to specify a procedure for each one? I guess this is also asking whether kind
polymorphism exists in Fortran.
I'm thinking of something that would be interfaced something like this:
module generics_test
interface read_generic
module procedure read_int, &
read_real, &
read_char
end interface read_generic
contains
subroutine read_int(value)
implicit none
! Arguments
<what sort of type spec could go here?> :: value
! Implementation
<would there need to be some kind handling here?>
end subroutine read_int
<other read subroutines here>
end module generics_test
It seems that polymorphism in Fortran 2003 focuses on derived types, such as the examples from the Portland Group. I'm only interested in generic handling of intrinsic types.
This is mainly for curiosity, since we work almost exclusively with defaults for integer
and character
, and real(8)
. (N.B. I know we should use iso_fortran_env
, but not all of the compilers we use have support for it.)