I have been attempting to convert some code to use parameterised derived types. My old code used include files to define the core of the functions and I was able to define multiple implementations of each function, each with a different length array or different REAL kind within the derived type.
I still need include files for the different kind types but the lengths are now generalised. I wrote functions like this:
module Bar implicit none integer, parameter :: SP = SELECTED_REAL_KIND(6) integer, parameter :: DP = SELECTED_REAL_KIND(13) integer, parameter :: QP = SELECTED_REAL_KIND(24) type VarA(k, n) integer, kind :: k integer, len :: n real(k) :: v real(k) :: d(n) end type interface foo module procedure foo_SP, foo_DP, foo_QP end interface contains pure elemental function foo_SP(a, b) result(c) type(VarA(SP,*)), intent(in) :: a type(VarA(SP,a%n)), intent(in) :: b type(VarA(SP,a%n)) c include 'foo_comomon.f90' end function pure elemental function foo_DP(a, b) result(c) type(VarA(DP,*)), intent(in) :: a type(VarA(DP,a%n)), intent(in) :: b type(VarA(DP,a%n)) c include 'foo_comomon.f90' end function pure elemental function foo_QP(a, b) result(c) type(VarA(QP,*)), intent(in) :: a type(VarA(QP,a%n)), intent(in) :: b type(VarA(QP,a%n)) c include 'foo_comomon.f90' end function end module
Compiling with XE 15.0.1.148 gives
error #7618: In an elemental subprogram, a dummy argument, or a subobject thereof, shall not appear in a specification-expr except as the argument to certain inquiry functions. [A]
Is there a way to avoid this limitation within the standard otherwise I will need to write array variants of every method and I have hundreds to do ?
At the moment I don't see any advantage of using parameterised derived types