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

Last change on this file since 3247 was 3247, checked in by sward, 6 years ago

parin_fail_message now also outputs the line number at which namelist reading failed

  • Property svn:keywords set to Id
File size: 11.4 KB
RevLine 
[1682]1!> @file message.f90
[2000]2!------------------------------------------------------------------------------!
[2696]3! This file is part of the PALM model system.
[1036]4!
[2000]5! PALM is free software: you can redistribute it and/or modify it under the
6! terms of the GNU General Public License as published by the Free Software
7! Foundation, either version 3 of the License, or (at your option) any later
8! version.
[1036]9!
10! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
11! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13!
14! You should have received a copy of the GNU General Public License along with
15! PALM. If not, see <http://www.gnu.org/licenses/>.
16!
[2718]17! Copyright 1997-2018 Leibniz Universitaet Hannover
[2000]18!------------------------------------------------------------------------------!
[1036]19!
[484]20! Current revisions:
[213]21! -----------------
[2001]22!
[2961]23!
[1321]24! Former revisions:
25! -----------------
26! $Id: message.f90 3247 2018-09-14 07:06:30Z sward $
[3247]27! Subroutine description updated and parin_fail_message now also outputs
28! the line number in which namelist reading failed
29!
30! 3246 2018-09-13 15:14:50Z sward
[3246]31! Added SUBROUTINE parin_fail_message for error handling of input namelists
32!
33! 3241 2018-09-12 15:02:00Z raasch
[3241]34! unused variables removed
35!
36! 3019 2018-05-13 07:05:43Z maronga
[3019]37! Temporaraly deactivate MPI_BARRIER as long as nested systems freeze due to
38! asynchronous calls of location_message.
39!
40! 2961 2018-04-12 10:13:48Z suehring
[2961]41! Synchronize location message between parent and child. Message will be not
42! flushed before all models finished their respective task. 
43!
44! 2932 2018-03-26 09:39:22Z maronga
[2716]45! Corrected "Former revisions" section
46!
47! 2696 2017-12-14 17:12:51Z kanani
48! Change in file header (GPL part)
[1321]49!
[2716]50! 2101 2017-01-05 16:42:31Z suehring
51!
[2001]52! 2000 2016-08-20 18:09:15Z knoop
53! Forced header and separation lines into 80 columns
54!
[1809]55! 1808 2016-04-05 19:44:00Z raasch
56! routine local_flush replaced by FORTRAN statement
57!
[1765]58! 1764 2016-02-28 12:45:19Z raasch
59! nest id added to header string, add linefeed to stdout to get messages better
60! seperated from the location messages,
61! in case of nested runs, location messages are given only by the root domain
62!
[1683]63! 1682 2015-10-07 23:56:08Z knoop
64! Code annotations made doxygen readable
65!
[1665]66! 1664 2015-09-23 06:18:12Z knoop
67! updated information_string_2 to meet the new server structure
68!
[1403]69! 1402 2014-05-09 14:25:13Z raasch
70! formatting of messages modified
71!
[1385]72! 1384 2014-05-02 14:31:06Z raasch
73! routine location_message added
74!
[1321]75! 1320 2014-03-20 08:40:49Z raasch
[1320]76! ONLY-attribute added to USE-statements,
77! kind-parameters added to all INTEGER and REAL declaration statements,
78! revision history before 2012 removed,
79! comment fields (!:) to be used for variable explanations added to
80! all variable declaration statements
[213]81!
[1037]82! 1036 2012-10-22 13:43:42Z raasch
83! code put under GPL (PALM 3.9)
84!
[226]85! 213 2008-11-13 10:26:18Z raasch
86! Initial revision
87!
[213]88! Description:
89! ------------
[1682]90!> Handling of the different kinds of messages.
91!> Meaning of formal parameters:
92!> requested_action: 0 - continue, 1 - abort by stop, 2 - abort by mpi_abort
[1764]93!>                   3 - abort by mpi_abort using MPI_COMM_WORLD
[1682]94!> message_level: 0 - informative, 1 - warning, 2 - error
95!> output_on_pe: -1 - all, else - output on specified PE
96!> file_id: 6 - stdout (*)
[1808]97!> flush_file: 0 - no action, 1 - flush the respective output buffer
[213]98!------------------------------------------------------------------------------!
[1682]99 SUBROUTINE message( routine_name, message_identifier, requested_action, &
[1808]100                     message_level, output_on_pe, file_id, flush_file )
[1682]101 
[1384]102    USE control_parameters,                                                    &
[1320]103        ONLY:  abort_mode, message_string
104
105    USE kinds
106
[213]107    USE pegrid
108
[1764]109    USE pmc_interface,                                                         &
110        ONLY:  cpl_id, nested_run
111
[213]112    IMPLICIT NONE
113
[1682]114    CHARACTER(LEN=6)   ::  message_identifier            !<
[1764]115    CHARACTER(LEN=20)  ::  nest_string                   !< nest id information
[1682]116    CHARACTER(LEN=*)   ::  routine_name                  !<
117    CHARACTER(LEN=200) ::  header_string                 !<
118    CHARACTER(LEN=200) ::  information_string_1          !<
119    CHARACTER(LEN=200) ::  information_string_2          !<
[213]120
[1682]121    INTEGER(iwp) ::  file_id                             !<
[1808]122    INTEGER(iwp) ::  flush_file                          !<
[1682]123    INTEGER(iwp) ::  i                                   !<
124    INTEGER(iwp) ::  message_level                       !<
125    INTEGER(iwp) ::  output_on_pe                        !<
126    INTEGER(iwp) ::  requested_action                    !<
[213]127
[1682]128    LOGICAL ::  do_output                                !<
129    LOGICAL ::  pe_out_of_range                          !<
[213]130
131
132    do_output       = .FALSE.
133    pe_out_of_range = .FALSE.
134
135!
[1764]136!-- In case of nested runs create the nest id informations
137    IF ( nested_run )  THEN
138       WRITE( nest_string, '(1X,A,I2.2)' )  'from nest-id ', cpl_id
139    ELSE
140       nest_string = ''
141    ENDIF
142!
[213]143!-- Create the complete output string, starting with the message level
144    IF ( message_level == 0 )  THEN
[1764]145       header_string = '--- informative message' // TRIM(nest_string) //       &
146                       ' ---  ID:'
[213]147    ELSEIF ( message_level == 1 )  THEN
[1764]148       header_string = '+++ warning message' // TRIM(nest_string) // ' ---  ID:'
[213]149    ELSEIF ( message_level == 2 )  THEN
[1764]150       header_string = '+++ error message' // TRIM(nest_string) // ' ---  ID:'
[213]151    ELSE
[1764]152       WRITE( header_string,'(A,I2)' )  '+++ unknown message level' //         &
153                                        TRIM(nest_string) // ': ',             &
[213]154                                        message_level
155    ENDIF
156
157!
158!-- Add the message identifier and the generating routine
159    header_string = TRIM( header_string ) // ' ' // message_identifier // &
160                    '   generated by routine: ' // TRIM( routine_name )
[311]161 
162    information_string_1 = 'Further information can be found at'
163    IF(message_identifier(1:2) == 'NC') THEN
[1664]164       information_string_2 = 'http://palm.muk.uni-hannover.de/trac/wiki/doc' // &
[563]165                              '/app/errmsg#NC'
[311]166    ELSE
[1664]167       information_string_2 = 'http://palm.muk.uni-hannover.de/trac/wiki/doc' // &
[563]168                              '/app/errmsg#' // message_identifier
[1764]169    ENDIF
[311]170   
[213]171
172!
173!-- Output the output string and the corresponding message string which had
174!-- been already assigned in the calling subroutine.
175!
176!-- First find out if output shall be done on this PE.
177    IF ( output_on_pe == -1 )  THEN
178       do_output = .TRUE.
179    ELSEIF ( myid == output_on_pe )  THEN
180       do_output = .TRUE.
181    ENDIF
182#if defined( __parallel )
183!
184!-- In case of illegal pe number output on pe0
185    IF ( output_on_pe > numprocs-1 )  THEN
186       pe_out_of_range = .TRUE.
187       IF ( myid == 0 )  do_output = .TRUE.
188    ENDIF
189#endif
190
191!
192!-- Now do the output
193    IF ( do_output )  THEN
[1402]194
[213]195       IF ( file_id == 6 )  THEN
196!
197!--       Output on stdout
[1764]198          WRITE( *, '(//A/)' )  TRIM( header_string )
[213]199!
200!--       Cut message string into pieces and output one piece per line.
201!--       Remove leading blanks.
202          message_string = ADJUSTL( message_string )
203          i = INDEX( message_string, '&' )
204          DO WHILE ( i /= 0 )
205             WRITE( *, '(4X,A)' )  ADJUSTL( message_string(1:i-1) )
206             message_string = ADJUSTL( message_string(i+1:) )
207             i = INDEX( message_string, '&' )
208          ENDDO
209          WRITE( *, '(4X,A)' )  TRIM( message_string )
[311]210          WRITE( *, '(4X,A)' )  ''
211          WRITE( *, '(4X,A)' )  TRIM( information_string_1 ) 
212          WRITE( *, '(4X,A)' )  TRIM( information_string_2 ) 
[335]213          WRITE( *, '(4X,A)' )  ''
[213]214
215       ELSE
216!
217!--       Output on requested file id (file must have been opened elsewhere!)
218          WRITE( file_id, '(A/)' )  TRIM( header_string )
219!
220!--       Cut message string into pieces and output one piece per line.
221!--       Remove leading blanks.
222          message_string = ADJUSTL( message_string )
223          i = INDEX( message_string, '&' )
224          DO WHILE ( i /= 0 )
225             WRITE( file_id, '(4X,A)' )  ADJUSTL( message_string(1:i-1) )
226             message_string = ADJUSTL( message_string(i+1:) )
227             i = INDEX( message_string, '&' )
228          ENDDO
229          WRITE( file_id, '(4X,A)' )  TRIM( message_string )
[335]230          WRITE( file_id, '(4X,A)' )  ''
[311]231          WRITE( file_id, '(4X,A)' )  TRIM( information_string_1 ) 
232          WRITE( file_id, '(4X,A)' )  TRIM( information_string_2 ) 
[335]233          WRITE( file_id, '(4X,A)' )  ''
[213]234!
235!--       Flush buffer, if requested
[1808]236          IF ( flush_file == 1 )  FLUSH( file_id )
[213]237       ENDIF
238
239       IF ( pe_out_of_range )  THEN
[226]240          WRITE ( *, '(A)' )  '+++ WARNING from routine message:'
[213]241          WRITE ( *, '(A,I6,A)' )  '    PE ', output_on_pe, &
242                                   ' choosed for output is larger '
243          WRITE ( *, '(A,I6)' )  '    than the maximum number of used PEs', &
244                                 numprocs-1
245          WRITE ( *, '(A)' )  '    Output is done on PE0 instead'
246       ENDIF
247
248    ENDIF
249
250!
251!-- Abort execution, if requested
252    IF ( requested_action > 0 )  THEN
253       abort_mode = requested_action
254       CALL local_stop
255    ENDIF
256
[226]257 END SUBROUTINE message
[1384]258
259
260!------------------------------------------------------------------------------!
261! Description:
262! ------------
[1682]263!> Prints out the given location on stdout
[1384]264!------------------------------------------------------------------------------!
[1682]265 
266 SUBROUTINE location_message( location, advance )
[1384]267
[1682]268
[1402]269    USE, INTRINSIC ::  ISO_FORTRAN_ENV,                                        &
[1764]270        ONLY:  OUTPUT_UNIT
[1402]271
[2961]272    USE pegrid
[1384]273
[1764]274    USE pmc_interface,                                                         &
[3241]275        ONLY:  cpl_id
[1764]276
[1384]277    IMPLICIT NONE
278
[1682]279    CHARACTER(LEN=*) ::  location !< text to be output on stdout
280    LOGICAL          ::  advance  !< switch for advancing/noadvancing I/O
[1384]281
[1764]282!
283!-- Output for nested runs only on the root domain
284    IF ( cpl_id /= 1 )  RETURN
[1384]285
286    IF ( myid == 0 )  THEN
[1402]287       IF ( advance )  THEN
288          WRITE ( OUTPUT_UNIT, '(6X,''--- '',A)' )  TRIM( location )
289       ELSE
290          WRITE ( OUTPUT_UNIT, '(6X,''... '',A)', ADVANCE='NO' )               &
291                TRIM( location )
292       ENDIF
[1808]293       FLUSH( OUTPUT_UNIT )
[1384]294    ENDIF
295
296 END SUBROUTINE location_message
[3246]297
298
299!------------------------------------------------------------------------------!
300! Description:
301! ------------
[3247]302!> Abort routine for failures durin reading of namelists
[3246]303!------------------------------------------------------------------------------!
304 
305 SUBROUTINE parin_fail_message( location, line )
306
307    USE control_parameters,                                                    &
308        ONLY:  message_string
309
[3247]310    USE kinds
311
[3246]312    IMPLICIT NONE
313
314    CHARACTER(LEN=*) ::  location !< text to be output on stdout
315    CHARACTER(LEN=*) ::  line
316
[3247]317    CHARACTER(LEN=80) ::  line_dum
318
319    INTEGER(iwp) ::  line_counter
320
321    line_dum = ' '
322    line_counter = 0
323
324    REWIND( 11 )
325    DO   WHILE ( INDEX( line_dum, TRIM(line) ) == 0 )
326         READ ( 11, '(A)', END=20 )  line_dum
327         line_counter = line_counter + 1
328    ENDDO
329
330 20 WRITE( message_string, '(A,I3,A)' )                                        &
331                   'Error(s) in NAMELIST '// TRIM(location) //                 &
332                   '&Reading fails on line ', line_counter,                    &
333                   ' at&' // line
[3246]334          CALL message( 'parin', 'PA0271', 1, 2, 0, 6, 0 )
335
336 END SUBROUTINE parin_fail_message
Note: See TracBrowser for help on using the repository browser.