8

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.

Puchatek
  • 1,477
  • 3
  • 15
  • 33
  • 4
    Perhaps http://stackoverflow.com/questions/2560182/fortran-determine-variable-type or http://stackoverflow.com/questions/2257248/how-to-write-wrapper-for-allocate will help with what you want to do. – M. S. B. May 10 '12 at 05:40

1 Answers1

11

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.

talonmies
  • 70,661
  • 34
  • 192
  • 269
haraldkl
  • 3,809
  • 26
  • 44