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