next up previous

3.1 Numeric Kind Parameterization     continued...

Fortunately there is a way to both isolate implementation kind value dependencies from application code and make the code more readable at the same time. That technique is to use the KIND intrinsic function to establish the correct values for (appropriately named) integer constants. (The KIND intrinsic returns the integer kind value for the type of its argument for that implementation.) For example, suppose that SINGLE and DOUBLE are the names of integer constants that have (somehow acquired) the proper kind value for single and double precision real, respectively. Then

REAL(SINGLE)    ...single precision variables...
REAL(DOUBLE)    ...double precision variables...
may be used to declare single and double precision real variables, as indicated. Alternatively, the ``full blown" syntax for such declarations is:
REAL(KIND=SINGLE)    ...single precision variables...
REAL(KIND=DOUBLE)    ...double precision variables...
Prior to their use in this way, SINGLE and DOUBLE have to be given the proper values, which may be accomplished with the following declaration:
INTEGER, PARAMETER ::  SINGLE = KIND(1.0),                   &
                       DOUBLE = KIND(1D0)