libsim Versione 7.2.6
kinds.F90
1! Copyright (C) 2010 ARPA-SIM <urpsim@smr.arpa.emr.it>
2! authors:
3! Davide Cesari <dcesari@arpa.emr.it>
4! Paolo Patruno <ppatruno@arpa.emr.it>
5
6! This program is free software; you can redistribute it and/or
7! modify it under the terms of the GNU General Public License as
8! published by the Free Software Foundation; either version 2 of
9! the License, or (at your option) any later version.
10
11! This program is distributed in the hope that it will be useful,
12! but WITHOUT ANY WARRANTY; without even the implied warranty of
13! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14! GNU General Public License for more details.
15
16! You should have received a copy of the GNU General Public License
17! along with this program. If not, see <http://www.gnu.org/licenses/>.
18#include "config.h"
19!> \defgroup base Libsim package, base library.
20!! The libsim base library defines modules and classes of general
21!! use for scientifical applications in Fortran 90. In order to
22!! compile and link programs using this library, you have to insert
23!! the required \c USE statements in the program units involved,
24!! specify the location of module files when compiling (tipically \c
25!! -I/usr/lib/gfortran/modules or \c -I/usr/lib64/gfortran/modules or
26!! \c -I/usr/include) and indicate the library name \c -lsim_base when
27!! linking, assuming that the library has been installed in a default
28!! location.
29
30!> Definition of constants to be used for declaring variables of a
31!! desired type. This module defines constants that can be portably
32!! used when declaring variables (through the \c KIND attribute) and
33!! when defining constants (through the underscore character \c _ ) in
34!! order to be sure that the desired type is used.
35!!
36!! There is a subtle difference between platform-default single and
37!! double precision real, obtained by declaring a variable of type \c
38!! REAL or \c DOUBLE \c PRECISION respectively, and single and double
39!! precision IEEE (4 and 8 bytes respectively) which are the standard
40!! IEEE data types and which are declared through \c REAL(kind=fp_s)
41!! and \c REAL(kind=fp_d) respectively: these two pairs of types
42!! usually coincide, but it may be not the case on some platforms, so
43!! you should choose one or the other approach depending on situation.
44!!
45!! Example of typical use:
46!! \code
47!! USE kinds
48!! ...
49!! INTEGER(kind=int_b) :: ab, bb
50!! REAL(kind=fp_d) :: dd
51!!
52!! ab = 13_int_b
53!! dd = REAL(ab, kind=fp_d)
54!! ...
55!! \endcode
56!! \ingroup base
57MODULE kinds
58IMPLICIT NONE
59
60INTEGER, PARAMETER :: int_b = selected_int_kind(1) !< 1-byte integer (byte)
61INTEGER, PARAMETER :: int_s = selected_int_kind(4) !< 2-byte integer (short)
62INTEGER, PARAMETER :: int_l = selected_int_kind(8) !< 4-byte integer (long)
63INTEGER, PARAMETER, PRIVATE :: &
64 int_ll_t = selected_int_kind(16)
65!> 8-byte integer (long long) if supported, otherwise 4-byte integer
66INTEGER, PARAMETER :: int_ll = &
67 ( ( ( 1 + sign( 1, int_ll_t ) ) / 2 ) * int_ll_t ) + &
68 ( ( ( 1 - sign( 1, int_ll_t ) ) / 2 ) * int_l )
69
70INTEGER, PARAMETER :: fp_s = selected_real_kind(6) !< single precision floating point (4 byte IEEE)
71INTEGER, PARAMETER :: fp_d = selected_real_kind(15) !< double precision floating point (8 byte IEEE)
72INTEGER, PARAMETER, PRIVATE :: fp_q_t = selected_real_kind(20)
73!> quad precision floating point (16 byte IEEE) if supported, otherwise double precision floating point
74INTEGER, PARAMETER :: fp_q = &
75 ( ( ( 1 + sign( 1, fp_q_t ) ) / 2 ) * fp_q_t ) + &
76 ( ( ( 1 - sign( 1, fp_q_t ) ) / 2 ) * fp_d )
77
78INTEGER, PARAMETER :: ptr_c = sizeof_ptr_c !< kind for an integer having the same size of a C pointer
79
80END MODULE kinds
Definition of constants to be used for declaring variables of a desired type.
Definition kinds.F90:245

Generated with Doxygen.