Since I don’t want to lose gfortran support and gfortran still has the known problem with parameterized type-bound procedures (see: 82943 – [F03] Error with type-bound procedure of parametrized derived type), I defined the needed derived types for different kinds.
So far it works, but after many years I noticed that the modules and submodules are very large because the different types are defined multiple times just because they have different kinds.
Here is an example that I have used so far:
TYPE :: TYP_REL4
REAL(KIND=4), ALLOCATABLE, DIMENSION(:, :) :: value
CONTAINS
PROCEDURE :: PRC1 => PRC1_REL4
PROCEDURE :: PRC2 => PRC2_REL4
PROCEDURE :: PRC3 => PRC3_REL4
END TYPE TYP_REL4
TYPE :: TYP_REL8
REAL(KIND=8), ALLOCATABLE, DIMENSION(:, :) :: value
CONTAINS
PROCEDURE :: PRC1 => PRC1_REL8
PROCEDURE :: PRC2 => PRC2_REL8
PROCEDURE :: PRC3 => PRC3_REL8
END TYPE TYP_REL8
TYPE :: TYP_REL10
REAL(KIND=10), ALLOCATABLE, DIMENSION(:, :) :: value
CONTAINS
PROCEDURE :: PRC1 => PRC1_REL10
PROCEDURE :: PRC2 => PRC2_REL10
PROCEDURE :: PRC3 => PRC3_REL10
END TYPE TYP_REL10
TYPE :: TYP_REL16
REAL(KIND=16), ALLOCATABLE, DIMENSION(:, :) :: value
CONTAINS
PROCEDURE :: PRC1 => PRC1_REL16
PROCEDURE :: PRC2 => PRC2_REL16
PROCEDURE :: PRC3 => PRC3_REL16
END TYPE TYP_REL16
Using PDT this example can be reduced like this:
TYPE :: TYP_REL(K)
INTEGER, KIND :: K = 8
REAL(KIND=K), ALLOCATABLE, DIMENSION(:, :) :: value
CONTAINS
PROCEDURE :: PRC1 => PRC1_REL
PROCEDURE :: PRC2 => PRC2_REL
PROCEDURE :: PRC3 => PRC3_REL
END TYPE TYP_REL
What would you suggest to avoid multiple type definitions in this situation?
Thanks
Ali