typeSizes.f90
! Description:
! Provide named kind parameters for use in declarations of real and integer
! variables with specific byte sizes (i.e. one, two, four, and eight byte
! integers; four and eight byte reals). The parameters can then be used
! in (KIND = XX) modifiers in declarations.
! A single function (byteSizesOK()) is provided to ensure that the selected
! kind parameters are correct.
!
! Input Parameters:
! None.
!
! Output Parameters:
! Public parameters, fixed at compile time:
! OneByteInt, TwoByteInt, FourByteInt, EightByteInt
! FourByteReal, EightByteRadl
!
! References and Credits:
! Written by
! Robert Pincus
! Cooperative Institue for Meteorological Satellite Studies
! University of Wisconsin - Madison
! 1225 W. Dayton St.
! Madison, Wisconsin 53706
! Robert.Pincus@ssec.wisc.edu
!
! Design Notes:
! Fortran 90 doesn't allow one to check the number of bytes in a real variable;
! we check only that four byte and eight byte reals have different kind parameters.
!
module typesizes
implicit none
public
integer, parameter :: onebyteint = selected_int_kind(2), &
twobyteint = selected_int_kind(4), &
fourbyteint = selected_int_kind(9), &
eightbyteint = selected_int_kind(18)
integer, parameter :: &
fourbytereal = selected_real_kind(p = 6, r = 37), &
eightbytereal = selected_real_kind(p = 13, r = 307)
contains
logical function bytesizesok()
! Users may call this function once to ensure that the kind parameters
! the module defines are available with the current compiler.
! We can't ensure that the two REAL kinds are actually four and
! eight bytes long, but we can ensure that they are distinct.
! Early Fortran 90 compilers would sometimes report incorrect results for
! the bit_size intrinsic, but I haven't seen this in a long time.
! Local variables
integer (kind = OneByteInt) :: one
integer (kind = TwoByteInt) :: two
integer (kind = FourByteInt) :: four
integer (kind = EightByteInt) :: eight
if (bit_size( one) == 8 .and. bit_size( two) == 16 .and. &
bit_size(four) == 32 .and. bit_size( eight) == 64 .and. &
fourbytereal > 0 .and. eightbytereal > 0 .and. &
fourbytereal /= eightbytereal) then
bytesizesok = .true.
else
bytesizesok = .false.
end if
end function bytesizesok
end module typesizes

Return to the Main Unidata NetCDF page.