F90 Model : Kinds of Type

LeftRight
Fortran 90 introduces the concept of KIND, which, if used properly, can free the programmer of targeting code for a certain platform. For example, workstations generally have 32-bit REALs and 64-bit DOUBLE PRECISION. Contrast this to SGI/Crays which have default 64-bit REALs and implements a 128-bit DOUBLE PRECISION in software.

For this example I also use the `C' preprocessor for conditional compilation. The source file is tkind.F90, which #includes tkind.h. This method is common on UNIX systems, and on other platforms as well. The `C' preprocessor is more flexible and provides much more capability than the Fortran 90 standard `INCLUDE' (which is deprecated).

In this case, the conditional compilation is necessary for the GENERIC INTERFACE code. Generic interfaces allow the overloading of user functions, similar to overloading ABS to equate to ABS, IABS, DABS, CABS, or etc. It selects the correct function depending on the type of argument given. Generic interfaces require the functions to be distinguishable by Type, Kind, or Rank (TKR). One implementation couldn't handle the KIND=16 and demoted it to KIND=8 instead of failing. This created an ambiguity between show_real8 and show_real16, which yielded a compiler error.

The selected kinds, precision and ranges, are typical for IEEE implementation of floating point representations. Also, notice that parameter values are kept in a MODULE for easy inclusion in all the subroutines.

Code examples

LeftRight
Slide 6