Fortran - adjusting the appearance / accuracy of a variable at run time

Is it possible to make the accuracy of a variable the variable itself, which will be determined at 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 

compiler output:

  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? I understand that no arbitrary value can be used for KIND , but this is not my problem in this matter.

+8
fortran precision
source share
1 answer

No, this is not possible, type, type and rank must be known. However, you can define common subprogram interfaces with implementations for all kinds that you expect to be passed to the subprogram at runtime.

+11
source share

All Articles