Portability of numerical code has long been difficult, primarily due to differences in the word sizes of the computers on which the code is run. Fortran 90 introduces parameterized types, increasing portability of software from machine to machine. This is done using kind values, constants associated with an intrinsic type such as integer or real. Parameterization of kind values allows precision changes by changing a single constant in the program. Several intrinsic functions are provided to select kind values based on the range and precision desired and inquire about a variable's precision characteristics in a portable way.
module Precision
! Define Q to be the kind number corresponding to at least 10
! decimal digits with a decimal exponent of at least 30.
integer, parameter :: Q = selected_real_kind( 10, 30 )
end module Precision
module Swapping
use Precision
contains
subroutine swap( x, y )
real( Q ), intent( inout ) :: x, y
real( Q ) tmp
tmp = x; x = y; y = tmp
end subroutine swap
end module Swapping
program Portable
use Precision
use Swapping
! Declare and initialize a and b using constants with kind value
! given by Q in the Precision module.
real( Q ) :: a = 1.0_Q, b = 2.0_Q
print *, a, b
call swap( a, b )
print *, a, b
end program Portable