libsim Versione 7.2.6
missing_values.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
19!> Definitions of constants and functions for working with missing values.
20!! This modules provides tools for handling missing values in various
21!! data types. Users should use the various \a *miss constants for
22!! setting a variable to a missing value, and use the interfaced
23!! function \a c_e or an equality test with the corresponding \a *miss
24!! constant for checking the validity of a value.
25!!
26!! When using the \a *miss constants, it is important to choose the
27!! constant of the right type in order to avoid implicit conversions
28!! that would impair the results.
29!!
30!! Example of typical use:
31!! \code
32!! USE missing_values
33!! ...
34!! INTEGER :: i
35!! INTEGER(kind=int_b) :: ib
36!! REAL :: r
37!!
38!! i = imiss
39!! ib = ibmiss
40!! r = rmiss
41!! IF (c_e(i) .OR. c_e(ib)) THEN
42!! PRINT*,"this is not executed"
43!! ENDIF
44!! IF (.NOT.c_e(r)) THEN
45!! PRINT*,"this is executed"
46!! ENDIF
47!! ...
48!! \endcode
49!! \ingroup base
51USE kinds
52IMPLICIT NONE
53
54REAL, PARAMETER :: rmiss = huge(1.0) !< default single precision real
55DOUBLE PRECISION, PARAMETER :: dmiss = huge(1.0d0) !< default double precision real
56REAL(kind=fp_s), PARAMETER :: rsmiss = huge(1.0_fp_s) !< single precision IEEE real \a (kind=fp_s)
57REAL(kind=fp_d), PARAMETER :: rdmiss = huge(1.0_fp_d) !< double precision IEEE real \a (kind=fp_d)
58INTEGER, PARAMETER :: imiss = huge(0) !< default integer
59INTEGER(kind=int_b), PARAMETER :: ibmiss = huge(0_int_b) !< 1-byte integer \a (kind=int_b)
60INTEGER(kind=int_b), PARAMETER :: bmiss = ibmiss
61INTEGER(kind=int_s), PARAMETER :: ismiss = huge(0_int_s) !< 2-byte integer \a (kind=int_s)
62INTEGER(kind=int_l), PARAMETER :: ilmiss = huge(0_int_l) !< 4-byte integer \a (kind=int_l)
63INTEGER(kind=int_ll), PARAMETER :: illmiss = huge(0_int_ll) !< 8-byte integer if supported \a (kind=int_ll)
64CHARACTER(len=1), PARAMETER :: cmiss = char(0) !< character (any length)
65
66
67!> Function to check whether a value is missing or not.
68!! It works with all the basic types supported and returns a logical
69!! value \a .TRUE. if the argument is a valid value and \a .FALSE. if
70!! not. It is elemental, so it works also for arrays of any size and
71!! shape.
72INTERFACE c_e
73 MODULE PROCEDURE c_e_b, c_e_s, c_e_l,c_e_ll, c_e_r, c_e_d, c_e_c
74END INTERFACE
75
76PRIVATE c_e_b, c_e_s, c_e_l,c_e_ll, c_e_r, c_e_d, c_e_c
77
78CONTAINS
79
80!> Check whether the byte argument is valid.
81ELEMENTAL LOGICAL FUNCTION c_e_b(var)
82INTEGER(kind=int_b),INTENT(in) :: var !< value to be checked
83
84c_e_b = var /= ibmiss
85
86END FUNCTION c_e_b
87
88
89!> Check whether the short integer argument is valid.
90ELEMENTAL LOGICAL FUNCTION c_e_s(var)
91INTEGER(kind=int_s),INTENT(in) :: var !< value to be checked
92
93c_e_s = var /= ismiss
94
95END FUNCTION c_e_s
96
97
98!> Check whether the long integer argument is valid.
99ELEMENTAL LOGICAL FUNCTION c_e_l(var)
100INTEGER(kind=int_l),INTENT(in) :: var !< value to be checked
101
102c_e_l = var /= ilmiss
103
104END FUNCTION c_e_l
105
106
107! This may not compile if long long is as long as long
108!> Check whether the long long integer argument is valid.
109ELEMENTAL LOGICAL FUNCTION c_e_ll(var)
110INTEGER(kind=int_ll),INTENT(in) :: var !< value to be checked
111
112c_e_ll = var /= illmiss
113
114END FUNCTION c_e_ll
115
116
117!> Check whether the real argument is valid.
118ELEMENTAL LOGICAL FUNCTION c_e_r(var)
119REAL,INTENT(in) :: var !< value to be checked
120
121c_e_r = var /= rmiss
122
123END FUNCTION c_e_r
124
125
126!> Check whether the double precision argument is valid.
127ELEMENTAL LOGICAL FUNCTION c_e_d(var)
128DOUBLE PRECISION,INTENT(in) :: var !< value to be checked
129
130c_e_d = var /= dmiss
131
132END FUNCTION c_e_d
133! cannot implement quad precision otherwise it may not compile if missing
134
135!> Check whether the character argument is valid.
136ELEMENTAL LOGICAL FUNCTION c_e_c(var)
137CHARACTER(len=*),INTENT(in) :: var !< value to be checked
138
139c_e_c = var /= cmiss
140
141END FUNCTION c_e_c
142
143
144END MODULE missing_values
Function to check whether a value is missing or not.
Definition of constants to be used for declaring variables of a desired type.
Definition kinds.F90:245
Definitions of constants and functions for working with missing values.

Generated with Doxygen.