-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.f90
144 lines (134 loc) · 7.26 KB
/
error.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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
!=========================================================================================
! Peacemaker -- A Quantum Cluster Equilibrium Code.
!
! Copyright 2004-2006 Barbara Kirchner, University of Bonn
! Copyright 2007-2012 Barbara Kirchner, University of Leipzig
! Copyright 2013-2018 Barbara Kirchner, University of Bonn
!
! This file is part of Peacemaker.
!
! Peacemaker is free software: you can redistribute it and/or modify
! it under the terms of the GNU General Public License as published by
! the Free Software Foundation, either version 3 of the License, or
! (at your option) any later version.
!
! Peacemaker is distributed in the hope that it will be useful,
! but WITHOUT ANY WARRANTY; without even the implied warranty of
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
! GNU General Public License for more details.
!
! You should have received a copy of the GNU General Public License
! along with Peacemaker. If not, see <http://www.gnu.org/licenses/>
!=========================================================================================
! This module provides two very simple routines for error handling.
!=========================================================================================
module error
use, intrinsic :: iso_fortran_env
use iso_varying_string
implicit none
private
!=====================================================================================
! Public entities.
public :: pmk_error
public :: pmk_missing_key_error
public :: pmk_argument_error
public :: pmk_argument_count_error
public :: pmk_unphysical_argument_error
public :: pmk_illegal_range_error
public :: pmk_warning
!=====================================================================================
! Interfaces.
interface pmk_unphysical_argument_error
module procedure pmk_unphysical_argument_error_char
module procedure pmk_unphysical_argument_error_string
end interface pmk_unphysical_argument_error
!=====================================================================================
interface pmk_argument_error
module procedure pmk_argument_error_char
module procedure pmk_argument_error_string
end interface pmk_argument_error
!=====================================================================================
interface pmk_argument_count_error
module procedure pmk_argument_count_error_char
module procedure pmk_argument_count_error_string
end interface pmk_argument_count_error
!=====================================================================================
! Error unit. Change this, if iso_fortran_env is not available on your system.
integer, parameter :: my_unit = error_unit
!=====================================================================================
contains
!=================================================================================
! Writes an error message and stops execution.
subroutine pmk_error(what)
character(*), intent(in) :: what
write(my_unit, '(A,1X,A)') "error;", what
stop
end subroutine pmk_error
!=================================================================================
! Writes an error message indicating that an argument is invalid for the given
! keyword/section. Terminates execution.
subroutine pmk_argument_error_string(key, section)
character(*), intent(in) :: key
type(varying_string), intent(in) :: section
call pmk_argument_error_char(key, char(section))
end subroutine pmk_argument_error_string
!=================================================================================
subroutine pmk_argument_error_char(key, section)
character(*), intent(in) :: key, section
call pmk_error("illegal argument in for keyword '" // key // &
"' in section [" // section // "]")
end subroutine pmk_argument_error_char
!=================================================================================
! Writes an error message indicating that the argument count for the given
! keyword/section is invalid. Terminates execution.
subroutine pmk_argument_count_error_string(key, section)
character(*), intent(in) :: key
type(varying_string), intent(in) :: section
call pmk_argument_count_error(key, char(section))
end subroutine pmk_argument_count_error_string
!=================================================================================
subroutine pmk_argument_count_error_char(key, section)
character(*), intent(in) :: key, section
call pmk_error("illegal number of arguments for keyword '" // key // &
"' in section [" // section // "]")
end subroutine pmk_argument_count_error_char
!=================================================================================
! Writes an error message indicating that an argument has an unphsyical value.
! Terminates execution.
subroutine pmk_unphysical_argument_error_char(key, section)
character(*), intent(in) :: key, section
call pmk_error("unphsyical value for keyword '" // key // &
"' in section [" // section // "]")
end subroutine pmk_unphysical_argument_error_char
!=================================================================================
subroutine pmk_unphysical_argument_error_string(key, section)
character(*), intent(in) :: key
type(varying_string), intent(in) :: section
call pmk_unphysical_argument_error_char(key, char(section))
end subroutine pmk_unphysical_argument_error_string
!=================================================================================
! Writes an error message indicating that the given keyword is missing. Terminates
! execution.
subroutine pmk_missing_key_error(key, section)
character(*), intent(in) :: key
type(varying_string), intent(in) :: section
call pmk_error("missing keyword '" // key // "' in section [" // &
char(section) // "]")
end subroutine pmk_missing_key_error
!=================================================================================
! Writes an error message indicating that there was something wrong with the
! range specification.
subroutine pmk_illegal_range_error(key, section)
character(*), intent(in) :: key, section
call pmk_error("illegal range specification for keyword '" // key // &
"' in section [" // section // "]")
end subroutine pmk_illegal_range_error
!=================================================================================
! Writes a warning.
subroutine pmk_warning(what)
character(*), intent(in) :: what
write(my_unit, '(A,1X,A)') "warning;", what
end subroutine pmk_warning
!=================================================================================
end module error
!=========================================================================================