[1682] | 1 | !> @file message.f90 |
---|
[1036] | 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 | ! |
---|
[1818] | 16 | ! Copyright 1997-2016 Leibniz Universitaet Hannover |
---|
[1036] | 17 | !--------------------------------------------------------------------------------! |
---|
| 18 | ! |
---|
[484] | 19 | ! Current revisions: |
---|
[213] | 20 | ! ----------------- |
---|
[1765] | 21 | ! |
---|
[1809] | 22 | ! |
---|
[1321] | 23 | ! Former revisions: |
---|
| 24 | ! ----------------- |
---|
| 25 | ! $Id: message.f90 1818 2016-04-06 15:53:27Z hoffmann $ |
---|
| 26 | ! |
---|
[1809] | 27 | ! 1808 2016-04-05 19:44:00Z raasch |
---|
| 28 | ! routine local_flush replaced by FORTRAN statement |
---|
| 29 | ! |
---|
[1765] | 30 | ! 1764 2016-02-28 12:45:19Z raasch |
---|
| 31 | ! nest id added to header string, add linefeed to stdout to get messages better |
---|
| 32 | ! seperated from the location messages, |
---|
| 33 | ! in case of nested runs, location messages are given only by the root domain |
---|
| 34 | ! |
---|
[1683] | 35 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
| 36 | ! Code annotations made doxygen readable |
---|
| 37 | ! |
---|
[1665] | 38 | ! 1664 2015-09-23 06:18:12Z knoop |
---|
| 39 | ! updated information_string_2 to meet the new server structure |
---|
| 40 | ! |
---|
[1403] | 41 | ! 1402 2014-05-09 14:25:13Z raasch |
---|
| 42 | ! formatting of messages modified |
---|
| 43 | ! |
---|
[1385] | 44 | ! 1384 2014-05-02 14:31:06Z raasch |
---|
| 45 | ! routine location_message added |
---|
| 46 | ! |
---|
[1321] | 47 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
[1320] | 48 | ! ONLY-attribute added to USE-statements, |
---|
| 49 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
| 50 | ! revision history before 2012 removed, |
---|
| 51 | ! comment fields (!:) to be used for variable explanations added to |
---|
| 52 | ! all variable declaration statements |
---|
[213] | 53 | ! |
---|
[1037] | 54 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
| 55 | ! code put under GPL (PALM 3.9) |
---|
| 56 | ! |
---|
[226] | 57 | ! 213 2008-11-13 10:26:18Z raasch |
---|
| 58 | ! Initial revision |
---|
| 59 | ! |
---|
[213] | 60 | ! Description: |
---|
| 61 | ! ------------ |
---|
[1682] | 62 | !> Handling of the different kinds of messages. |
---|
| 63 | !> Meaning of formal parameters: |
---|
| 64 | !> requested_action: 0 - continue, 1 - abort by stop, 2 - abort by mpi_abort |
---|
[1764] | 65 | !> 3 - abort by mpi_abort using MPI_COMM_WORLD |
---|
[1682] | 66 | !> message_level: 0 - informative, 1 - warning, 2 - error |
---|
| 67 | !> output_on_pe: -1 - all, else - output on specified PE |
---|
| 68 | !> file_id: 6 - stdout (*) |
---|
[1808] | 69 | !> flush_file: 0 - no action, 1 - flush the respective output buffer |
---|
[213] | 70 | !------------------------------------------------------------------------------! |
---|
[1682] | 71 | SUBROUTINE message( routine_name, message_identifier, requested_action, & |
---|
[1808] | 72 | message_level, output_on_pe, file_id, flush_file ) |
---|
[1682] | 73 | |
---|
[1384] | 74 | USE control_parameters, & |
---|
[1320] | 75 | ONLY: abort_mode, message_string |
---|
| 76 | |
---|
| 77 | USE kinds |
---|
| 78 | |
---|
[213] | 79 | USE pegrid |
---|
| 80 | |
---|
[1764] | 81 | USE pmc_interface, & |
---|
| 82 | ONLY: cpl_id, nested_run |
---|
| 83 | |
---|
[213] | 84 | IMPLICIT NONE |
---|
| 85 | |
---|
[1682] | 86 | CHARACTER(LEN=6) :: message_identifier !< |
---|
[1764] | 87 | CHARACTER(LEN=20) :: nest_string !< nest id information |
---|
[1682] | 88 | CHARACTER(LEN=*) :: routine_name !< |
---|
| 89 | CHARACTER(LEN=200) :: header_string !< |
---|
| 90 | CHARACTER(LEN=200) :: information_string_1 !< |
---|
| 91 | CHARACTER(LEN=200) :: information_string_2 !< |
---|
[213] | 92 | |
---|
[1682] | 93 | INTEGER(iwp) :: file_id !< |
---|
[1808] | 94 | INTEGER(iwp) :: flush_file !< |
---|
[1682] | 95 | INTEGER(iwp) :: i !< |
---|
| 96 | INTEGER(iwp) :: message_level !< |
---|
| 97 | INTEGER(iwp) :: output_on_pe !< |
---|
| 98 | INTEGER(iwp) :: requested_action !< |
---|
[213] | 99 | |
---|
[1682] | 100 | LOGICAL :: do_output !< |
---|
| 101 | LOGICAL :: pe_out_of_range !< |
---|
[213] | 102 | |
---|
| 103 | |
---|
| 104 | do_output = .FALSE. |
---|
| 105 | pe_out_of_range = .FALSE. |
---|
| 106 | |
---|
| 107 | ! |
---|
[1764] | 108 | !-- In case of nested runs create the nest id informations |
---|
| 109 | IF ( nested_run ) THEN |
---|
| 110 | WRITE( nest_string, '(1X,A,I2.2)' ) 'from nest-id ', cpl_id |
---|
| 111 | ELSE |
---|
| 112 | nest_string = '' |
---|
| 113 | ENDIF |
---|
| 114 | ! |
---|
[213] | 115 | !-- Create the complete output string, starting with the message level |
---|
| 116 | IF ( message_level == 0 ) THEN |
---|
[1764] | 117 | header_string = '--- informative message' // TRIM(nest_string) // & |
---|
| 118 | ' --- ID:' |
---|
[213] | 119 | ELSEIF ( message_level == 1 ) THEN |
---|
[1764] | 120 | header_string = '+++ warning message' // TRIM(nest_string) // ' --- ID:' |
---|
[213] | 121 | ELSEIF ( message_level == 2 ) THEN |
---|
[1764] | 122 | header_string = '+++ error message' // TRIM(nest_string) // ' --- ID:' |
---|
[213] | 123 | ELSE |
---|
[1764] | 124 | WRITE( header_string,'(A,I2)' ) '+++ unknown message level' // & |
---|
| 125 | TRIM(nest_string) // ': ', & |
---|
[213] | 126 | message_level |
---|
| 127 | ENDIF |
---|
| 128 | |
---|
| 129 | ! |
---|
| 130 | !-- Add the message identifier and the generating routine |
---|
| 131 | header_string = TRIM( header_string ) // ' ' // message_identifier // & |
---|
| 132 | ' generated by routine: ' // TRIM( routine_name ) |
---|
[311] | 133 | |
---|
| 134 | information_string_1 = 'Further information can be found at' |
---|
| 135 | IF(message_identifier(1:2) == 'NC') THEN |
---|
[1664] | 136 | information_string_2 = 'http://palm.muk.uni-hannover.de/trac/wiki/doc' // & |
---|
[563] | 137 | '/app/errmsg#NC' |
---|
[311] | 138 | ELSE |
---|
[1664] | 139 | information_string_2 = 'http://palm.muk.uni-hannover.de/trac/wiki/doc' // & |
---|
[563] | 140 | '/app/errmsg#' // message_identifier |
---|
[1764] | 141 | ENDIF |
---|
[311] | 142 | |
---|
[213] | 143 | |
---|
| 144 | ! |
---|
| 145 | !-- Output the output string and the corresponding message string which had |
---|
| 146 | !-- been already assigned in the calling subroutine. |
---|
| 147 | ! |
---|
| 148 | !-- First find out if output shall be done on this PE. |
---|
| 149 | IF ( output_on_pe == -1 ) THEN |
---|
| 150 | do_output = .TRUE. |
---|
| 151 | ELSEIF ( myid == output_on_pe ) THEN |
---|
| 152 | do_output = .TRUE. |
---|
| 153 | ENDIF |
---|
| 154 | #if defined( __parallel ) |
---|
| 155 | ! |
---|
| 156 | !-- In case of illegal pe number output on pe0 |
---|
| 157 | IF ( output_on_pe > numprocs-1 ) THEN |
---|
| 158 | pe_out_of_range = .TRUE. |
---|
| 159 | IF ( myid == 0 ) do_output = .TRUE. |
---|
| 160 | ENDIF |
---|
| 161 | #endif |
---|
| 162 | |
---|
| 163 | ! |
---|
| 164 | !-- Now do the output |
---|
| 165 | IF ( do_output ) THEN |
---|
[1402] | 166 | |
---|
[213] | 167 | IF ( file_id == 6 ) THEN |
---|
| 168 | ! |
---|
| 169 | !-- Output on stdout |
---|
[1764] | 170 | WRITE( *, '(//A/)' ) TRIM( header_string ) |
---|
[213] | 171 | ! |
---|
| 172 | !-- Cut message string into pieces and output one piece per line. |
---|
| 173 | !-- Remove leading blanks. |
---|
| 174 | message_string = ADJUSTL( message_string ) |
---|
| 175 | i = INDEX( message_string, '&' ) |
---|
| 176 | DO WHILE ( i /= 0 ) |
---|
| 177 | WRITE( *, '(4X,A)' ) ADJUSTL( message_string(1:i-1) ) |
---|
| 178 | message_string = ADJUSTL( message_string(i+1:) ) |
---|
| 179 | i = INDEX( message_string, '&' ) |
---|
| 180 | ENDDO |
---|
| 181 | WRITE( *, '(4X,A)' ) TRIM( message_string ) |
---|
[311] | 182 | WRITE( *, '(4X,A)' ) '' |
---|
| 183 | WRITE( *, '(4X,A)' ) TRIM( information_string_1 ) |
---|
| 184 | WRITE( *, '(4X,A)' ) TRIM( information_string_2 ) |
---|
[335] | 185 | WRITE( *, '(4X,A)' ) '' |
---|
[213] | 186 | |
---|
| 187 | ELSE |
---|
| 188 | ! |
---|
| 189 | !-- Output on requested file id (file must have been opened elsewhere!) |
---|
| 190 | WRITE( file_id, '(A/)' ) TRIM( header_string ) |
---|
| 191 | ! |
---|
| 192 | !-- Cut message string into pieces and output one piece per line. |
---|
| 193 | !-- Remove leading blanks. |
---|
| 194 | message_string = ADJUSTL( message_string ) |
---|
| 195 | i = INDEX( message_string, '&' ) |
---|
| 196 | DO WHILE ( i /= 0 ) |
---|
| 197 | WRITE( file_id, '(4X,A)' ) ADJUSTL( message_string(1:i-1) ) |
---|
| 198 | message_string = ADJUSTL( message_string(i+1:) ) |
---|
| 199 | i = INDEX( message_string, '&' ) |
---|
| 200 | ENDDO |
---|
| 201 | WRITE( file_id, '(4X,A)' ) TRIM( message_string ) |
---|
[335] | 202 | WRITE( file_id, '(4X,A)' ) '' |
---|
[311] | 203 | WRITE( file_id, '(4X,A)' ) TRIM( information_string_1 ) |
---|
| 204 | WRITE( file_id, '(4X,A)' ) TRIM( information_string_2 ) |
---|
[335] | 205 | WRITE( file_id, '(4X,A)' ) '' |
---|
[213] | 206 | ! |
---|
| 207 | !-- Flush buffer, if requested |
---|
[1808] | 208 | IF ( flush_file == 1 ) FLUSH( file_id ) |
---|
[213] | 209 | ENDIF |
---|
| 210 | |
---|
| 211 | IF ( pe_out_of_range ) THEN |
---|
[226] | 212 | WRITE ( *, '(A)' ) '+++ WARNING from routine message:' |
---|
[213] | 213 | WRITE ( *, '(A,I6,A)' ) ' PE ', output_on_pe, & |
---|
| 214 | ' choosed for output is larger ' |
---|
| 215 | WRITE ( *, '(A,I6)' ) ' than the maximum number of used PEs', & |
---|
| 216 | numprocs-1 |
---|
| 217 | WRITE ( *, '(A)' ) ' Output is done on PE0 instead' |
---|
| 218 | ENDIF |
---|
| 219 | |
---|
| 220 | ENDIF |
---|
| 221 | |
---|
| 222 | ! |
---|
| 223 | !-- Abort execution, if requested |
---|
| 224 | IF ( requested_action > 0 ) THEN |
---|
| 225 | abort_mode = requested_action |
---|
| 226 | CALL local_stop |
---|
| 227 | ENDIF |
---|
| 228 | |
---|
[226] | 229 | END SUBROUTINE message |
---|
[1384] | 230 | |
---|
| 231 | |
---|
| 232 | !------------------------------------------------------------------------------! |
---|
| 233 | ! Description: |
---|
| 234 | ! ------------ |
---|
[1682] | 235 | !> Prints out the given location on stdout |
---|
[1384] | 236 | !------------------------------------------------------------------------------! |
---|
[1682] | 237 | |
---|
| 238 | SUBROUTINE location_message( location, advance ) |
---|
[1384] | 239 | |
---|
[1682] | 240 | |
---|
[1402] | 241 | USE, INTRINSIC :: ISO_FORTRAN_ENV, & |
---|
[1764] | 242 | ONLY: OUTPUT_UNIT |
---|
[1402] | 243 | |
---|
[1384] | 244 | USE pegrid, & |
---|
[1764] | 245 | ONLY: myid |
---|
[1384] | 246 | |
---|
[1764] | 247 | USE pmc_interface, & |
---|
| 248 | ONLY: cpl_id |
---|
| 249 | |
---|
[1384] | 250 | IMPLICIT NONE |
---|
| 251 | |
---|
[1682] | 252 | CHARACTER(LEN=*) :: location !< text to be output on stdout |
---|
| 253 | LOGICAL :: advance !< switch for advancing/noadvancing I/O |
---|
[1384] | 254 | |
---|
[1764] | 255 | ! |
---|
| 256 | !-- Output for nested runs only on the root domain |
---|
| 257 | IF ( cpl_id /= 1 ) RETURN |
---|
[1384] | 258 | |
---|
| 259 | IF ( myid == 0 ) THEN |
---|
[1402] | 260 | IF ( advance ) THEN |
---|
| 261 | WRITE ( OUTPUT_UNIT, '(6X,''--- '',A)' ) TRIM( location ) |
---|
| 262 | ELSE |
---|
| 263 | WRITE ( OUTPUT_UNIT, '(6X,''... '',A)', ADVANCE='NO' ) & |
---|
| 264 | TRIM( location ) |
---|
| 265 | ENDIF |
---|
[1808] | 266 | FLUSH( OUTPUT_UNIT ) |
---|
[1384] | 267 | ENDIF |
---|
| 268 | |
---|
| 269 | END SUBROUTINE location_message |
---|