1 | SUBROUTINE message( routine_name, message_identifier, requested_action, & |
---|
2 | message_level, output_on_pe, file_id, flush ) |
---|
3 | |
---|
4 | !--------------------------------------------------------------------------------! |
---|
5 | ! This file is part of PALM. |
---|
6 | ! |
---|
7 | ! PALM is free software: you can redistribute it and/or modify it under the terms |
---|
8 | ! of the GNU General Public License as published by the Free Software Foundation, |
---|
9 | ! either version 3 of the License, or (at your option) any later version. |
---|
10 | ! |
---|
11 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
12 | ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
13 | ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
14 | ! |
---|
15 | ! You should have received a copy of the GNU General Public License along with |
---|
16 | ! PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
17 | ! |
---|
18 | ! Copyright 1997-2014 Leibniz Universitaet Hannover |
---|
19 | !--------------------------------------------------------------------------------! |
---|
20 | ! |
---|
21 | ! Current revisions: |
---|
22 | ! ----------------- |
---|
23 | ! |
---|
24 | ! |
---|
25 | ! Former revisions: |
---|
26 | ! ----------------- |
---|
27 | ! $Id: message.f90 1403 2014-05-09 14:52:24Z hoffmann $ |
---|
28 | ! |
---|
29 | ! 1402 2014-05-09 14:25:13Z raasch |
---|
30 | ! formatting of messages modified |
---|
31 | ! |
---|
32 | ! 1384 2014-05-02 14:31:06Z raasch |
---|
33 | ! routine location_message added |
---|
34 | ! |
---|
35 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
36 | ! ONLY-attribute added to USE-statements, |
---|
37 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
38 | ! revision history before 2012 removed, |
---|
39 | ! comment fields (!:) to be used for variable explanations added to |
---|
40 | ! all variable declaration statements |
---|
41 | ! |
---|
42 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
43 | ! code put under GPL (PALM 3.9) |
---|
44 | ! |
---|
45 | ! 213 2008-11-13 10:26:18Z raasch |
---|
46 | ! Initial revision |
---|
47 | ! |
---|
48 | ! Description: |
---|
49 | ! ------------ |
---|
50 | ! Handling of the different kinds of messages. |
---|
51 | ! Meaning of formal parameters: |
---|
52 | ! requested_action: 0 - continue, 1 - abort by stop, 2 - abort by mpi_abort |
---|
53 | ! message_level: 0 - informative, 1 - warning, 2 - error |
---|
54 | ! output_on_pe: -1 - all, else - output on specified PE |
---|
55 | ! file_id: 6 - stdout (*) |
---|
56 | ! flush: 0 - no action, 1 - flush the respective output buffer |
---|
57 | !------------------------------------------------------------------------------! |
---|
58 | |
---|
59 | USE control_parameters, & |
---|
60 | ONLY: abort_mode, message_string |
---|
61 | |
---|
62 | USE kinds |
---|
63 | |
---|
64 | USE pegrid |
---|
65 | |
---|
66 | IMPLICIT NONE |
---|
67 | |
---|
68 | CHARACTER(LEN=6) :: message_identifier !: |
---|
69 | CHARACTER(LEN=*) :: routine_name !: |
---|
70 | CHARACTER(LEN=200) :: header_string !: |
---|
71 | CHARACTER(LEN=200) :: information_string_1 !: |
---|
72 | CHARACTER(LEN=200) :: information_string_2 !: |
---|
73 | |
---|
74 | INTEGER(iwp) :: file_id !: |
---|
75 | INTEGER(iwp) :: flush !: |
---|
76 | INTEGER(iwp) :: i !: |
---|
77 | INTEGER(iwp) :: message_level !: |
---|
78 | INTEGER(iwp) :: output_on_pe !: |
---|
79 | INTEGER(iwp) :: requested_action !: |
---|
80 | |
---|
81 | LOGICAL :: do_output !: |
---|
82 | LOGICAL :: pe_out_of_range !: |
---|
83 | |
---|
84 | |
---|
85 | do_output = .FALSE. |
---|
86 | pe_out_of_range = .FALSE. |
---|
87 | |
---|
88 | ! |
---|
89 | !-- Create the complete output string, starting with the message level |
---|
90 | IF ( message_level == 0 ) THEN |
---|
91 | header_string = '--- informative message --- ID:' |
---|
92 | ELSEIF ( message_level == 1 ) THEN |
---|
93 | header_string = '+++ warning message --- ID:' |
---|
94 | ELSEIF ( message_level == 2 ) THEN |
---|
95 | header_string = '+++ error message --- ID:' |
---|
96 | ELSE |
---|
97 | WRITE( header_string,'(A,I2)' ) '+++ unknown message level: ', & |
---|
98 | message_level |
---|
99 | ENDIF |
---|
100 | |
---|
101 | ! |
---|
102 | !-- Add the message identifier and the generating routine |
---|
103 | header_string = TRIM( header_string ) // ' ' // message_identifier // & |
---|
104 | ' generated by routine: ' // TRIM( routine_name ) |
---|
105 | |
---|
106 | information_string_1 = 'Further information can be found at' |
---|
107 | IF(message_identifier(1:2) == 'NC') THEN |
---|
108 | information_string_2 = 'http://palm.muk.uni-hannover.de/wiki/doc' // & |
---|
109 | '/app/errmsg#NC' |
---|
110 | ELSE |
---|
111 | information_string_2 = 'http://palm.muk.uni-hannover.de/wiki/doc' // & |
---|
112 | '/app/errmsg#' // message_identifier |
---|
113 | END IF |
---|
114 | |
---|
115 | |
---|
116 | ! |
---|
117 | !-- Output the output string and the corresponding message string which had |
---|
118 | !-- been already assigned in the calling subroutine. |
---|
119 | ! |
---|
120 | !-- First find out if output shall be done on this PE. |
---|
121 | IF ( output_on_pe == -1 ) THEN |
---|
122 | do_output = .TRUE. |
---|
123 | ELSEIF ( myid == output_on_pe ) THEN |
---|
124 | do_output = .TRUE. |
---|
125 | ENDIF |
---|
126 | #if defined( __parallel ) |
---|
127 | ! |
---|
128 | !-- In case of illegal pe number output on pe0 |
---|
129 | IF ( output_on_pe > numprocs-1 ) THEN |
---|
130 | pe_out_of_range = .TRUE. |
---|
131 | IF ( myid == 0 ) do_output = .TRUE. |
---|
132 | ENDIF |
---|
133 | #endif |
---|
134 | |
---|
135 | ! |
---|
136 | !-- Now do the output |
---|
137 | IF ( do_output ) THEN |
---|
138 | |
---|
139 | IF ( file_id == 6 ) THEN |
---|
140 | ! |
---|
141 | !-- Output on stdout |
---|
142 | WRITE( *, '(A/)' ) TRIM( header_string ) |
---|
143 | ! |
---|
144 | !-- Cut message string into pieces and output one piece per line. |
---|
145 | !-- Remove leading blanks. |
---|
146 | message_string = ADJUSTL( message_string ) |
---|
147 | i = INDEX( message_string, '&' ) |
---|
148 | DO WHILE ( i /= 0 ) |
---|
149 | WRITE( *, '(4X,A)' ) ADJUSTL( message_string(1:i-1) ) |
---|
150 | message_string = ADJUSTL( message_string(i+1:) ) |
---|
151 | i = INDEX( message_string, '&' ) |
---|
152 | ENDDO |
---|
153 | WRITE( *, '(4X,A)' ) TRIM( message_string ) |
---|
154 | WRITE( *, '(4X,A)' ) '' |
---|
155 | WRITE( *, '(4X,A)' ) TRIM( information_string_1 ) |
---|
156 | WRITE( *, '(4X,A)' ) TRIM( information_string_2 ) |
---|
157 | WRITE( *, '(4X,A)' ) '' |
---|
158 | |
---|
159 | ELSE |
---|
160 | ! |
---|
161 | !-- Output on requested file id (file must have been opened elsewhere!) |
---|
162 | WRITE( file_id, '(A/)' ) TRIM( header_string ) |
---|
163 | ! |
---|
164 | !-- Cut message string into pieces and output one piece per line. |
---|
165 | !-- Remove leading blanks. |
---|
166 | message_string = ADJUSTL( message_string ) |
---|
167 | i = INDEX( message_string, '&' ) |
---|
168 | DO WHILE ( i /= 0 ) |
---|
169 | WRITE( file_id, '(4X,A)' ) ADJUSTL( message_string(1:i-1) ) |
---|
170 | message_string = ADJUSTL( message_string(i+1:) ) |
---|
171 | i = INDEX( message_string, '&' ) |
---|
172 | ENDDO |
---|
173 | WRITE( file_id, '(4X,A)' ) TRIM( message_string ) |
---|
174 | WRITE( file_id, '(4X,A)' ) '' |
---|
175 | WRITE( file_id, '(4X,A)' ) TRIM( information_string_1 ) |
---|
176 | WRITE( file_id, '(4X,A)' ) TRIM( information_string_2 ) |
---|
177 | WRITE( file_id, '(4X,A)' ) '' |
---|
178 | ! |
---|
179 | !-- Flush buffer, if requested |
---|
180 | IF ( flush == 1 ) CALL local_flush( file_id ) |
---|
181 | ENDIF |
---|
182 | |
---|
183 | IF ( pe_out_of_range ) THEN |
---|
184 | WRITE ( *, '(A)' ) '+++ WARNING from routine message:' |
---|
185 | WRITE ( *, '(A,I6,A)' ) ' PE ', output_on_pe, & |
---|
186 | ' choosed for output is larger ' |
---|
187 | WRITE ( *, '(A,I6)' ) ' than the maximum number of used PEs', & |
---|
188 | numprocs-1 |
---|
189 | WRITE ( *, '(A)' ) ' Output is done on PE0 instead' |
---|
190 | ENDIF |
---|
191 | |
---|
192 | ENDIF |
---|
193 | |
---|
194 | ! |
---|
195 | !-- Abort execution, if requested |
---|
196 | IF ( requested_action > 0 ) THEN |
---|
197 | abort_mode = requested_action |
---|
198 | CALL local_stop |
---|
199 | ENDIF |
---|
200 | |
---|
201 | END SUBROUTINE message |
---|
202 | |
---|
203 | |
---|
204 | SUBROUTINE location_message( location, advance ) |
---|
205 | |
---|
206 | !------------------------------------------------------------------------------! |
---|
207 | ! Description: |
---|
208 | ! ------------ |
---|
209 | ! Prints out the given location on stdout |
---|
210 | !------------------------------------------------------------------------------! |
---|
211 | |
---|
212 | USE, INTRINSIC :: ISO_FORTRAN_ENV, & |
---|
213 | ONLY : OUTPUT_UNIT |
---|
214 | |
---|
215 | USE pegrid, & |
---|
216 | ONLY : myid |
---|
217 | |
---|
218 | IMPLICIT NONE |
---|
219 | |
---|
220 | CHARACTER(LEN=*) :: location !: text to be output on stdout |
---|
221 | LOGICAL :: advance !: switch for advancing/noadvancing I/O |
---|
222 | |
---|
223 | |
---|
224 | IF ( myid == 0 ) THEN |
---|
225 | IF ( advance ) THEN |
---|
226 | WRITE ( OUTPUT_UNIT, '(6X,''--- '',A)' ) TRIM( location ) |
---|
227 | ELSE |
---|
228 | WRITE ( OUTPUT_UNIT, '(6X,''... '',A)', ADVANCE='NO' ) & |
---|
229 | TRIM( location ) |
---|
230 | ENDIF |
---|
231 | CALL local_flush( OUTPUT_UNIT ) |
---|
232 | ENDIF |
---|
233 | |
---|
234 | END SUBROUTINE location_message |
---|