! This file: http://ftp.cac.psu.edu/pub/ger/fortran/hdk/FindKinds.f90 ! ! This program searches for the available integer and real kinds. ! by Bart Vandewoestyne as postd at comp.lang.fortran on 5 Feb. 2007. ! ! http://www.cs.kuleuven.be/~bartv/stuff/find_kinds2.f90 ! ! Author: Bart Vandewoestyne ! program find_kinds2 implicit none integer :: current_kind ! the current kind value integer :: last_kind_seen ! the last kind value we have seen integer :: p ! equivalent decimal precision integer :: r ! equivalent decimal exponent range write(unit=*, fmt="(/A)") "Integer kinds" write(unit=*, fmt="(A)") "-------------" r = 0 ! we can also start checking at r=1 to avoid some problems with buggy ! compilers... current_kind = selected_int_kind(r) last_kind_seen = current_kind do if (current_kind == -1) then exit end if r = r + 1 current_kind = selected_int_kind(r) if (current_kind /= last_kind_seen) then write(unit=*, fmt="(A, I3, A, I2.2, A, I2.2, A)") & "kind", last_kind_seen, ": -10^", r-1, " --> +10^", r-1, & " is assured to be representable." last_kind_seen = current_kind endif end do write(unit=*, fmt="(/A)") "Real kinds" write(unit=*, fmt="(A)") "----------" p = 1 r = 1 current_kind = selected_real_kind(p, r) last_kind_seen = current_kind do if (current_kind <= 0) then exit end if do if (current_kind /= last_kind_seen) then exit end if p = p + 1 current_kind = selected_real_kind(p, r) end do p = p - 1 current_kind = selected_real_kind(p, r) do if (current_kind /= last_kind_seen) then exit end if r = r + 1 current_kind = selected_real_kind(p, r) end do r = r - 1 write(unit=*, fmt="(A4, I3, A1)") & "kind", last_kind_seen, ":" write(unit=*, fmt="(A37, I0)") & " equivalent decimal precision of ", p write(unit=*, fmt="(A47, I0, A5, I0)") & " equivalent decimal exponent range between ", -r, & " and ", r p = p + 1 r = r + 1 current_kind = selected_real_kind(p, r) last_kind_seen = current_kind end do end program find_kinds2