

Fortran 90 has defined several intrinsic functions for retrieving the defining characteristics for each intrinsic type. The following example defines three KIND parameters to handle the three intrinsic types which will be used.
Note how literal constants and variables are declared using these parameter types.
Code examples
module numeric_ implicit none ! define several KIND parameters for use everywhere ! 32bit integer integer, parameter :: INT_ = selected_int_kind(R=9) ! 64bit real integer, parameter :: REAL_ = selected_real_kind(P=13,R=300) ! 64+64bit complex integer, parameter :: COMPLEX_ = selected_real_kind(P=13,R=300) ! ! create an overloaded 'generic' interface which depends ! on the subroutine 'signature' based on data type, ! kind number,and rank (TKR) interface show_kind module procedure show_int_, show_real_, show_complex_ end interface ! ! force the use of the generic interface by excluding ! any public access to specific routines private show_int_, show_real_, show_complex_ contains subroutine show_int_(x) implicit none integer(kind=INT_), intent(in) :: x ! kind must not be variable write(6,'(/1x,"***INT_ KIND = ", i6, 10x,"requested = ", i6)') & kind(x), selected_int_kind(R=9) write(6,'(1x,"RADIX = ", i6)') radix(x) write(6,'(1x,"DIGITS = ", i6)') digits(x) write(6,'(1x,"RANGE = ", i6)') range(x) write(6,'(1x,"HUGE = ")',advance='NO') write(6, *) huge(x) write(6,'(1x,"value = ")',advance='NO') write(6, *) x end subroutine show_int_ subroutine show_real_(x) implicit none real(kind=REAL_), intent(in) :: x ! kind must not be variable write(6,'(/1x,"***REAL_ KIND = ", i6, 10x,"requested = ", i6)') & kind(x), selected_real_kind(P=13,R=300) write(6,'(1x,"PRECISION = ", i6)') precision(x) write(6,'(1x,"MAXEXPONENT = ", i6)') maxexponent(x) write(6,'(1x,"MINEXPONENT = ", i6)') minexponent(x) write(6,'(1x,"RADIX = ", i6)') radix(x) write(6,'(1x,"DIGITS = ", i6)') digits(x) write(6,'(1x,"EPSILON = ")',advance='NO') write(6, *) epsilon(x) write(6,'(1x,"value = ")',advance='NO') write(6, *) x end subroutine show_real_ subroutine show_complex_(x) implicit none complex(kind=COMPLEX_), intent(in) :: x ! kind must not be variable write(6,'(/1x,"***COMPLEX_ KIND = ", i6, 10x,"requested = ", i6)') & kind(x), selected_real_kind(P=13,R=300) write(6,'(1x,"PRECISION = ", i6)') precision(real(x)) write(6,'(1x,"MAXEXPONENT = ", i6)') maxexponent(real(x)) write(6,'(1x,"MINEXPONENT = ", i6)') minexponent(real(x)) write(6,'(1x,"RADIX = ", i6)') radix(real(x)) write(6,'(1x,"DIGITS = ", i6)') digits(real(x)) write(6,'(1x,"EPSILON = ")',advance='NO') write(6, *) epsilon(real(x)) write(6,'(1x,"value = ")',advance='NO') write(6, *) x end subroutine show_complex_ end module numeric_ program tnumeric use numeric_ ! Note how variables and literal constants are declared integer(kind=INT_) :: i = 1_INT_ real(kind=REAL_) :: xx = 1.0_REAL_/3.0_REAL_ ! note that the COMPLEX_ kind specification must be appended to each ! literal constant ... not to the complex pair complex(kind=COMPLEX_) :: cc = & (1.0_COMPLEX_,1.0_COMPLEX_)/(3.0_COMPLEX_,0.0_COMPLEX_) ! call show_int_(i) ! illegal - no public access write(6,'(/1x,"Use generic interface")') call show_kind(i) call show_kind(xx) call show_kind(cc) end program tnumeric
x86 Linux - g77/vastf90 Use generic interface ***INT_ KIND = 4 requested = 4 RADIX = 2 DIGITS = 31 RANGE = 9 HUGE = 2147483647 value = 1 ***REAL_ KIND = 8 requested = 8 PRECISION = 15 MAXEXPONENT = 1024 MINEXPONENT = -1021 RADIX = 2 DIGITS = 53 EPSILON = 2.22044605E-16 value = 0.333333333 ***COMPLEX_ KIND = 8 requested = 8 PRECISION = 15 MAXEXPONENT = 1024 MINEXPONENT = -1021 RADIX = 2 DIGITS = 53 EPSILON = 2.22044605E-16 value = (0.333333333,0.333333333)

