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.
Obtaining the Kind ValueThe range is thus from 10-r to 10+r. For example, selected_real_kind (p = 10, r = 99) returns the kind value needed for a precision of 10 decimal places, and a range of at least 10-99 to 10+99.
A double-precision exponent consists of the letter D , followed by an optional plus or minus sign, followed by an integer. A double-precision exponent denotes a power of 10. The value of a double-precision constant is the product of that power of 10 and the constant that precedes the D .
Note that a processor may assign an in itial value of zero (0.) to all double precision variables. In FORTRAN, the double-precision zero is written as 0.0D0, in which D stands for "times ten to the power...", i.e., 0.0 X 100. Likewise, 5.3D6 stands for 5.3 times ten to sixth power (that is, 5300000.00000000).
The KIND of a variable is an integer label which tells the compiler which of its supported kinds it should use. Beware that although it is common for the KIND parameter to be the same as the number of bytes stored in a variable of that KIND, it is not required by the Fortran standard.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With