source: palm/trunk/SOURCE/message.f90 @ 1682

Last change on this file since 1682 was 1682, checked in by knoop, 6 years ago

Code annotations made doxygen readable

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