Reputation: 1537
Is it possible to make a precision of a variable itself a variable that will be defined at a run time? Say, if I try to compile:
SUBROUTINE FOO( VARIABLE, PRECISION_VALUE )
IMPLICIT NONE
INTEGER(4) :: PRECISION_VALUE
INTEGER(PRECISION_VALUE) :: VARIABLE
RETURN
END
the compiler output is:
error #6683: A kind type parameter must be a compile-time constant. [PRECISION_VALUE]
INTEGER(PRECISION_VALUE) :: VARIABLE
--------------^
compilation aborted for trial.f (code 1)
Anyway around it? I understand that not any arbitrary value can be used for KIND
, but that's not my concern in this question.
Upvotes: 8
Views: 2466
Reputation: 3819
No, it's not possible, type, kind and rank have to be known. However, you can define generic subroutine interfaces with implementations for all the kinds that you expect to be passed into a routine at runtime.
Upvotes: 11