NetCDF-Fortran  4.4.3
typeSizes.f90
1 ! Description:
2 ! Provide named kind parameters for use in declarations of real and integer
3 ! variables with specific byte sizes (i.e. one, two, four, and eight byte
4 ! integers; four and eight byte reals). The parameters can then be used
5 ! in (KIND = XX) modifiers in declarations.
6 ! A single function (byteSizesOK()) is provided to ensure that the selected
7 ! kind parameters are correct.
8 !
9 ! Input Parameters:
10 ! None.
11 !
12 ! Output Parameters:
13 ! Public parameters, fixed at compile time:
14 ! OneByteInt, TwoByteInt, FourByteInt, EightByteInt
15 ! FourByteReal, EightByteRadl
16 !
17 ! References and Credits:
18 ! Written by
19 ! Robert Pincus
20 ! Cooperative Institue for Meteorological Satellite Studies
21 ! University of Wisconsin - Madison
22 ! 1225 W. Dayton St.
23 ! Madison, Wisconsin 53706
24 ! Robert.Pincus@ssec.wisc.edu
25 !
26 ! Design Notes:
27 ! Fortran 90 doesn't allow one to check the number of bytes in a real variable;
28 ! we check only that four byte and eight byte reals have different kind parameters.
29 !
30 module typesizes
31  implicit none
32  public
33  integer, parameter :: onebyteint = selected_int_kind(2), &
34  twobyteint = selected_int_kind(4), &
35  fourbyteint = selected_int_kind(9), &
36  eightbyteint = selected_int_kind(18)
37 
38  integer, parameter :: &
39  fourbytereal = selected_real_kind(p = 6, r = 37), &
40  eightbytereal = selected_real_kind(p = 13, r = 307)
41 contains
42  logical function bytesizesok()
43  ! Users may call this function once to ensure that the kind parameters
44  ! the module defines are available with the current compiler.
45  ! We can't ensure that the two REAL kinds are actually four and
46  ! eight bytes long, but we can ensure that they are distinct.
47  ! Early Fortran 90 compilers would sometimes report incorrect results for
48  ! the bit_size intrinsic, but I haven't seen this in a long time.
49 
50  ! Local variables
51  integer (kind = OneByteInt) :: one
52  integer (kind = TwoByteInt) :: two
53  integer (kind = FourByteInt) :: four
54  integer (kind = EightByteInt) :: eight
55 
56  if (bit_size( one) == 8 .and. bit_size( two) == 16 .and. &
57  bit_size(four) == 32 .and. bit_size( eight) == 64 .and. &
58  fourbytereal > 0 .and. eightbytereal > 0 .and. &
59  fourbytereal /= eightbytereal) then
60  bytesizesok = .true.
61  else
62  bytesizesok = .false.
63  end if
64  end function bytesizesok
65 end module typesizes

Return to the Main Unidata NetCDF page.
Generated on Sun Mar 27 2016 13:46:12 for NetCDF-Fortran. NetCDF is a Unidata library.