-
Notifications
You must be signed in to change notification settings - Fork 0
/
kinds.f90
107 lines (94 loc) · 4.48 KB
/
kinds.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
module kinds
!$$$ module documentation block
! . . . .
! module: kinds
! prgmmr: treadon org: np23 date: 2004-08-15
!
! abstract: Module to hold specification kinds for variable declaration.
! This module is based on (copied from) Paul vanDelst's
! type_kinds module found in the community radiative transfer
! model
!
! module history log:
! 2004-08-15 treadon
! 2011-07-04 todling - define main precision during compilation
!
! Subroutines Included:
!
! Functions Included:
!
! remarks:
! The numerical data types defined in this module are:
! i_byte - specification kind for byte (1-byte) integer variable
! i_short - specification kind for short (2-byte) integer variable
! i_long - specification kind for long (4-byte) integer variable
! i_llong - specification kind for double long (8-byte) integer variable
! r_single - specification kind for single precision (4-byte) real variable
! r_double - specification kind for double precision (8-byte) real variable
! r_quad - specification kind for quad precision (16-byte) real variable
!
! i_kind - generic specification kind for default integer
! r_kind - generic specification kind for default floating point
!
!
! attributes:
! language: f90
! machine: ibm RS/6000 SP
!
!$$$ end documentation block
implicit none
private
! Integer type definitions below
! Integer types
integer, parameter, public :: i_byte = selected_int_kind(1) ! byte integer
integer, parameter, public :: i_short = selected_int_kind(4) ! short integer
integer, parameter, public :: i_long = selected_int_kind(8) ! long integer
integer, parameter, private :: llong_t = selected_int_kind(16) ! llong integer
integer, parameter, public :: i_llong = max( llong_t, i_long )
! Expected 8-bit byte sizes of the integer kinds
integer, parameter, public :: num_bytes_for_i_byte = 1
integer, parameter, public :: num_bytes_for_i_short = 2
integer, parameter, public :: num_bytes_for_i_long = 4
integer, parameter, public :: num_bytes_for_i_llong = 8
! Define arrays for default definition
integer, parameter, private :: num_i_kinds = 4
integer, parameter, dimension( num_i_kinds ), private :: integer_types = (/ &
i_byte, i_short, i_long, i_llong /)
integer, parameter, dimension( num_i_kinds ), private :: integer_byte_sizes = (/ &
num_bytes_for_i_byte, num_bytes_for_i_short, &
num_bytes_for_i_long, num_bytes_for_i_llong /)
! Default values
! **** CHANGE THE FOLLOWING TO CHANGE THE DEFAULT INTEGER TYPE KIND ***
integer, parameter, private :: default_integer = 3 ! 1=byte,
! 2=short,
! 3=long,
! 4=llong
integer, parameter, public :: i_kind = integer_types( default_integer )
integer, parameter, public :: num_bytes_for_i_kind = &
integer_byte_sizes( default_integer )
! Real definitions below
! Real types
integer, parameter, public :: r_single = selected_real_kind(6) ! single precision
integer, parameter, public :: r_double = selected_real_kind(15) ! double precision
integer, parameter, private :: quad_t = selected_real_kind(20) ! quad precision
integer, parameter, public :: r_quad = max( quad_t, r_double )
! Expected 8-bit byte sizes of the real kinds
integer, parameter, public :: num_bytes_for_r_single = 4
integer, parameter, public :: num_bytes_for_r_double = 8
integer, parameter, public :: num_bytes_for_r_quad = 16
! Define arrays for default definition
integer, parameter, private :: num_r_kinds = 3
integer, parameter, dimension( num_r_kinds ), private :: real_kinds = (/ &
r_single, r_double, r_quad /)
integer, parameter, dimension( num_r_kinds ), private :: real_byte_sizes = (/ &
num_bytes_for_r_single, num_bytes_for_r_double, &
num_bytes_for_r_quad /)
! Default values
! **** CHANGE THE FOLLOWING TO CHANGE THE DEFAULT REAL TYPE KIND ***
integer, parameter, private :: default_real = 1 ! 1=single,
! integer, parameter, private :: default_real = 2 ! 2=double,
! integer, parameter, private :: default_real = 3 ! 3=quad
integer, parameter, public :: r_kind = real_kinds( default_real )
integer, parameter, public :: num_bytes_for_r_kind = &
real_byte_sizes( default_real )
end module kinds