[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 | ! |
---|
[4360] | 17 | ! Copyright 1997-2020 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 4536 2020-05-17 17:24:13Z moh.hefny $ |
---|
[4536] | 27 | ! location message format changed |
---|
| 28 | ! |
---|
| 29 | ! 4360 2020-01-07 11:25:50Z suehring |
---|
[4182] | 30 | ! Corrected "Former revisions" section |
---|
| 31 | ! |
---|
| 32 | ! 4097 2019-07-15 11:59:11Z suehring |
---|
[4097] | 33 | ! Avoid overlong lines - limit is 132 characters per line |
---|
| 34 | ! |
---|
| 35 | ! 3987 2019-05-22 09:52:13Z kanani |
---|
[3987] | 36 | ! Improved formatting of job logfile output, |
---|
| 37 | ! changed output of DEBUG file |
---|
| 38 | ! |
---|
| 39 | ! 3885 2019-04-11 11:29:34Z kanani |
---|
[3885] | 40 | ! Changes related to global restructuring of location messages and introduction |
---|
| 41 | ! of additional debug messages |
---|
| 42 | ! |
---|
| 43 | ! 3655 2019-01-07 16:51:22Z knoop |
---|
[3248] | 44 | ! Minor formating changes |
---|
[1321] | 45 | ! |
---|
[4182] | 46 | ! 213 2008-11-13 10:26:18Z raasch |
---|
| 47 | ! Initial revision |
---|
| 48 | ! |
---|
[213] | 49 | ! Description: |
---|
| 50 | ! ------------ |
---|
[1682] | 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 |
---|
[1764] | 54 | !> 3 - abort by mpi_abort using MPI_COMM_WORLD |
---|
[1682] | 55 | !> message_level: 0 - informative, 1 - warning, 2 - error |
---|
| 56 | !> output_on_pe: -1 - all, else - output on specified PE |
---|
| 57 | !> file_id: 6 - stdout (*) |
---|
[1808] | 58 | !> flush_file: 0 - no action, 1 - flush the respective output buffer |
---|
[213] | 59 | !------------------------------------------------------------------------------! |
---|
[1682] | 60 | SUBROUTINE message( routine_name, message_identifier, requested_action, & |
---|
[1808] | 61 | message_level, output_on_pe, file_id, flush_file ) |
---|
[1682] | 62 | |
---|
[1384] | 63 | USE control_parameters, & |
---|
[1320] | 64 | ONLY: abort_mode, message_string |
---|
| 65 | |
---|
| 66 | USE kinds |
---|
| 67 | |
---|
[213] | 68 | USE pegrid |
---|
| 69 | |
---|
[1764] | 70 | USE pmc_interface, & |
---|
| 71 | ONLY: cpl_id, nested_run |
---|
| 72 | |
---|
[213] | 73 | IMPLICIT NONE |
---|
| 74 | |
---|
[1682] | 75 | CHARACTER(LEN=6) :: message_identifier !< |
---|
[1764] | 76 | CHARACTER(LEN=20) :: nest_string !< nest id information |
---|
[1682] | 77 | CHARACTER(LEN=*) :: routine_name !< |
---|
| 78 | CHARACTER(LEN=200) :: header_string !< |
---|
[3987] | 79 | CHARACTER(LEN=200) :: header_string_2 !< for message ID and routine name |
---|
[1682] | 80 | CHARACTER(LEN=200) :: information_string_1 !< |
---|
| 81 | CHARACTER(LEN=200) :: information_string_2 !< |
---|
[213] | 82 | |
---|
[1682] | 83 | INTEGER(iwp) :: file_id !< |
---|
[1808] | 84 | INTEGER(iwp) :: flush_file !< |
---|
[1682] | 85 | INTEGER(iwp) :: i !< |
---|
| 86 | INTEGER(iwp) :: message_level !< |
---|
| 87 | INTEGER(iwp) :: output_on_pe !< |
---|
| 88 | INTEGER(iwp) :: requested_action !< |
---|
[213] | 89 | |
---|
[1682] | 90 | LOGICAL :: do_output !< |
---|
| 91 | LOGICAL :: pe_out_of_range !< |
---|
[213] | 92 | |
---|
| 93 | |
---|
| 94 | do_output = .FALSE. |
---|
| 95 | pe_out_of_range = .FALSE. |
---|
| 96 | |
---|
| 97 | ! |
---|
[1764] | 98 | !-- In case of nested runs create the nest id informations |
---|
| 99 | IF ( nested_run ) THEN |
---|
| 100 | WRITE( nest_string, '(1X,A,I2.2)' ) 'from nest-id ', cpl_id |
---|
| 101 | ELSE |
---|
| 102 | nest_string = '' |
---|
| 103 | ENDIF |
---|
| 104 | ! |
---|
[213] | 105 | !-- Create the complete output string, starting with the message level |
---|
| 106 | IF ( message_level == 0 ) THEN |
---|
[1764] | 107 | header_string = '--- informative message' // TRIM(nest_string) // & |
---|
[3987] | 108 | ' ---' |
---|
[213] | 109 | ELSEIF ( message_level == 1 ) THEN |
---|
[3987] | 110 | header_string = '+++ warning message' // TRIM(nest_string) // ' ---' |
---|
[213] | 111 | ELSEIF ( message_level == 2 ) THEN |
---|
[3987] | 112 | header_string = '+++ error message' // TRIM(nest_string) // ' ---' |
---|
[213] | 113 | ELSE |
---|
[1764] | 114 | WRITE( header_string,'(A,I2)' ) '+++ unknown message level' // & |
---|
| 115 | TRIM(nest_string) // ': ', & |
---|
[213] | 116 | message_level |
---|
| 117 | ENDIF |
---|
| 118 | |
---|
| 119 | ! |
---|
| 120 | !-- Add the message identifier and the generating routine |
---|
[3987] | 121 | header_string_2 = 'ID: ' // message_identifier // & |
---|
| 122 | ' generated by routine: ' // TRIM( routine_name ) |
---|
[311] | 123 | |
---|
| 124 | information_string_1 = 'Further information can be found at' |
---|
| 125 | IF(message_identifier(1:2) == 'NC') THEN |
---|
[1664] | 126 | information_string_2 = 'http://palm.muk.uni-hannover.de/trac/wiki/doc' // & |
---|
[563] | 127 | '/app/errmsg#NC' |
---|
[311] | 128 | ELSE |
---|
[1664] | 129 | information_string_2 = 'http://palm.muk.uni-hannover.de/trac/wiki/doc' // & |
---|
[563] | 130 | '/app/errmsg#' // message_identifier |
---|
[1764] | 131 | ENDIF |
---|
[311] | 132 | |
---|
[213] | 133 | |
---|
| 134 | ! |
---|
| 135 | !-- Output the output string and the corresponding message string which had |
---|
| 136 | !-- been already assigned in the calling subroutine. |
---|
| 137 | ! |
---|
| 138 | !-- First find out if output shall be done on this PE. |
---|
| 139 | IF ( output_on_pe == -1 ) THEN |
---|
| 140 | do_output = .TRUE. |
---|
| 141 | ELSEIF ( myid == output_on_pe ) THEN |
---|
| 142 | do_output = .TRUE. |
---|
| 143 | ENDIF |
---|
| 144 | #if defined( __parallel ) |
---|
| 145 | ! |
---|
| 146 | !-- In case of illegal pe number output on pe0 |
---|
| 147 | IF ( output_on_pe > numprocs-1 ) THEN |
---|
| 148 | pe_out_of_range = .TRUE. |
---|
| 149 | IF ( myid == 0 ) do_output = .TRUE. |
---|
| 150 | ENDIF |
---|
| 151 | #endif |
---|
| 152 | |
---|
| 153 | ! |
---|
| 154 | !-- Now do the output |
---|
| 155 | IF ( do_output ) THEN |
---|
[1402] | 156 | |
---|
[213] | 157 | IF ( file_id == 6 ) THEN |
---|
| 158 | ! |
---|
| 159 | !-- Output on stdout |
---|
[3987] | 160 | WRITE( *, '(16X,A)' ) TRIM( header_string ) |
---|
| 161 | WRITE( *, '(20X,A)' ) TRIM( header_string_2 ) |
---|
[213] | 162 | ! |
---|
| 163 | !-- Cut message string into pieces and output one piece per line. |
---|
| 164 | !-- Remove leading blanks. |
---|
| 165 | message_string = ADJUSTL( message_string ) |
---|
| 166 | i = INDEX( message_string, '&' ) |
---|
| 167 | DO WHILE ( i /= 0 ) |
---|
[3987] | 168 | WRITE( *, '(20X,A)' ) ADJUSTL( message_string(1:i-1) ) |
---|
[213] | 169 | message_string = ADJUSTL( message_string(i+1:) ) |
---|
| 170 | i = INDEX( message_string, '&' ) |
---|
| 171 | ENDDO |
---|
[3987] | 172 | WRITE( *, '(20X,A)' ) '' |
---|
| 173 | WRITE( *, '(20X,A)' ) TRIM( message_string ) |
---|
| 174 | WRITE( *, '(20X,A)' ) '' |
---|
| 175 | WRITE( *, '(20X,A)' ) TRIM( information_string_1 ) |
---|
| 176 | WRITE( *, '(20X,A)' ) TRIM( information_string_2 ) |
---|
| 177 | WRITE( *, '(20X,A)' ) '' |
---|
[213] | 178 | |
---|
| 179 | ELSE |
---|
| 180 | ! |
---|
| 181 | !-- Output on requested file id (file must have been opened elsewhere!) |
---|
| 182 | WRITE( file_id, '(A/)' ) TRIM( header_string ) |
---|
| 183 | ! |
---|
| 184 | !-- Cut message string into pieces and output one piece per line. |
---|
| 185 | !-- Remove leading blanks. |
---|
| 186 | message_string = ADJUSTL( message_string ) |
---|
| 187 | i = INDEX( message_string, '&' ) |
---|
| 188 | DO WHILE ( i /= 0 ) |
---|
| 189 | WRITE( file_id, '(4X,A)' ) ADJUSTL( message_string(1:i-1) ) |
---|
| 190 | message_string = ADJUSTL( message_string(i+1:) ) |
---|
| 191 | i = INDEX( message_string, '&' ) |
---|
| 192 | ENDDO |
---|
| 193 | WRITE( file_id, '(4X,A)' ) TRIM( message_string ) |
---|
[335] | 194 | WRITE( file_id, '(4X,A)' ) '' |
---|
[311] | 195 | WRITE( file_id, '(4X,A)' ) TRIM( information_string_1 ) |
---|
| 196 | WRITE( file_id, '(4X,A)' ) TRIM( information_string_2 ) |
---|
[335] | 197 | WRITE( file_id, '(4X,A)' ) '' |
---|
[213] | 198 | ! |
---|
| 199 | !-- Flush buffer, if requested |
---|
[1808] | 200 | IF ( flush_file == 1 ) FLUSH( file_id ) |
---|
[213] | 201 | ENDIF |
---|
| 202 | |
---|
| 203 | IF ( pe_out_of_range ) THEN |
---|
[226] | 204 | WRITE ( *, '(A)' ) '+++ WARNING from routine message:' |
---|
[213] | 205 | WRITE ( *, '(A,I6,A)' ) ' PE ', output_on_pe, & |
---|
| 206 | ' choosed for output is larger ' |
---|
| 207 | WRITE ( *, '(A,I6)' ) ' than the maximum number of used PEs', & |
---|
| 208 | numprocs-1 |
---|
| 209 | WRITE ( *, '(A)' ) ' Output is done on PE0 instead' |
---|
| 210 | ENDIF |
---|
| 211 | |
---|
| 212 | ENDIF |
---|
| 213 | |
---|
| 214 | ! |
---|
| 215 | !-- Abort execution, if requested |
---|
| 216 | IF ( requested_action > 0 ) THEN |
---|
| 217 | abort_mode = requested_action |
---|
| 218 | CALL local_stop |
---|
| 219 | ENDIF |
---|
| 220 | |
---|
[226] | 221 | END SUBROUTINE message |
---|
[1384] | 222 | |
---|
| 223 | |
---|
[3885] | 224 | !--------------------------------------------------------------------------------------------------! |
---|
[1384] | 225 | ! Description: |
---|
| 226 | ! ------------ |
---|
[1682] | 227 | !> Prints out the given location on stdout |
---|
[3885] | 228 | !--------------------------------------------------------------------------------------------------! |
---|
[1682] | 229 | |
---|
[3885] | 230 | SUBROUTINE location_message( location, message_type ) |
---|
[1384] | 231 | |
---|
[1682] | 232 | |
---|
[3885] | 233 | USE, INTRINSIC :: ISO_FORTRAN_ENV, & |
---|
[1764] | 234 | ONLY: OUTPUT_UNIT |
---|
[1402] | 235 | |
---|
[2961] | 236 | USE pegrid |
---|
[1384] | 237 | |
---|
[3885] | 238 | USE pmc_interface, & |
---|
[3241] | 239 | ONLY: cpl_id |
---|
[1764] | 240 | |
---|
[1384] | 241 | IMPLICIT NONE |
---|
| 242 | |
---|
[3885] | 243 | CHARACTER(LEN=*) :: location !< text to be output on stdout |
---|
[3987] | 244 | CHARACTER(LEN=60) :: location_string = ' ' !< |
---|
[3885] | 245 | CHARACTER(LEN=*) :: message_type !< attribute marking 'start' or 'end' of routine |
---|
| 246 | CHARACTER(LEN=11) :: message_type_string = ' ' !< |
---|
| 247 | CHARACTER(LEN=10) :: system_time !< system clock time |
---|
| 248 | CHARACTER(LEN=10) :: time |
---|
[1764] | 249 | ! |
---|
| 250 | !-- Output for nested runs only on the root domain |
---|
| 251 | IF ( cpl_id /= 1 ) RETURN |
---|
[1384] | 252 | |
---|
| 253 | IF ( myid == 0 ) THEN |
---|
[3885] | 254 | ! |
---|
| 255 | !-- Get system time for debug info output (helpful to estimate the required computing time for |
---|
| 256 | !-- specific parts of code |
---|
| 257 | CALL date_and_time( TIME=time ) |
---|
| 258 | system_time = time(1:2)//':'//time(3:4)//':'//time(5:6) |
---|
| 259 | ! |
---|
| 260 | !-- Write pre-string depending on message_type |
---|
| 261 | IF ( TRIM( message_type ) == 'start' ) WRITE( message_type_string, * ) '-', TRIM( message_type ), '----' |
---|
| 262 | IF ( TRIM( message_type ) == 'finished' ) WRITE( message_type_string, * ) '-', TRIM( message_type ), '-' |
---|
| 263 | ! |
---|
[3987] | 264 | !-- Write dummy location_string in order to allow left-alignment of text despite the fixed (=A60) |
---|
| 265 | !-- format. |
---|
| 266 | WRITE( location_string, * ) TRIM( location ) |
---|
| 267 | ! |
---|
[3885] | 268 | !-- Write and flush debug location or info message to file |
---|
[4536] | 269 | WRITE( OUTPUT_UNIT, 200 ) TRIM( system_time ), TRIM( message_type_string ), & |
---|
| 270 | TRIM( location_string ) |
---|
[1808] | 271 | FLUSH( OUTPUT_UNIT ) |
---|
[3885] | 272 | ! |
---|
| 273 | !-- Message formats |
---|
[4536] | 274 | 200 FORMAT ( 3X, A, 3x, A, 2X, A ) |
---|
[3885] | 275 | |
---|
[1384] | 276 | ENDIF |
---|
| 277 | |
---|
| 278 | END SUBROUTINE location_message |
---|
[3246] | 279 | |
---|
| 280 | |
---|
[3885] | 281 | !--------------------------------------------------------------------------------------------------! |
---|
| 282 | ! Description: |
---|
| 283 | ! ------------ |
---|
| 284 | !> Prints out the given debug information to unit 9 (DEBUG files in temporary directory) |
---|
| 285 | !> for each PE on each domain. |
---|
| 286 | !--------------------------------------------------------------------------------------------------! |
---|
| 287 | |
---|
| 288 | SUBROUTINE debug_message( debug_string, message_type ) |
---|
| 289 | |
---|
| 290 | |
---|
| 291 | USE control_parameters, & |
---|
[3987] | 292 | ONLY: time_since_reference_point |
---|
[3885] | 293 | |
---|
| 294 | IMPLICIT NONE |
---|
| 295 | |
---|
| 296 | |
---|
| 297 | CHARACTER(LEN=*) :: debug_string !< debug message to be output on unit 9 |
---|
| 298 | CHARACTER(LEN=*) :: message_type !< 'start', 'end', 'info' |
---|
| 299 | CHARACTER(LEN=10) :: message_type_string = ' ' !< |
---|
| 300 | CHARACTER(LEN=10) :: system_time !< system clock time |
---|
| 301 | CHARACTER(LEN=10) :: time |
---|
| 302 | |
---|
| 303 | INTEGER, PARAMETER :: debug_output_unit = 9 |
---|
| 304 | |
---|
| 305 | ! |
---|
| 306 | !-- Get system time for debug info output (helpful to estimate the required computing time for |
---|
| 307 | !-- specific parts of code |
---|
| 308 | CALL date_and_time( TIME=time ) |
---|
| 309 | system_time = time(1:2)//':'//time(3:4)//':'//time(5:6) |
---|
| 310 | ! |
---|
| 311 | !-- Write pre-string depending on message_type |
---|
| 312 | IF ( TRIM( message_type ) == 'start' ) WRITE( message_type_string, * ) '-', TRIM( message_type ), '-' |
---|
| 313 | IF ( TRIM( message_type ) == 'end' ) WRITE( message_type_string, * ) '-', TRIM( message_type ), '---' |
---|
| 314 | IF ( TRIM( message_type ) == 'info' ) WRITE( message_type_string, * ) '-', TRIM( message_type ), '--' |
---|
| 315 | ! |
---|
| 316 | !-- Write and flush debug location or info message to file |
---|
[4097] | 317 | WRITE( debug_output_unit, 201 ) TRIM( system_time ), time_since_reference_point, & |
---|
| 318 | TRIM( message_type_string ), TRIM( debug_string ) |
---|
[3885] | 319 | FLUSH( debug_output_unit ) |
---|
| 320 | |
---|
| 321 | ! |
---|
| 322 | !-- Message formats |
---|
[3987] | 323 | 201 FORMAT ( 'System time: ', A, ' | simulated time (s): ', F12.3, ' | ', A, ' ', A ) |
---|
[3885] | 324 | |
---|
| 325 | |
---|
| 326 | END SUBROUTINE debug_message |
---|
| 327 | |
---|
| 328 | |
---|
[3246] | 329 | !------------------------------------------------------------------------------! |
---|
| 330 | ! Description: |
---|
| 331 | ! ------------ |
---|
[3247] | 332 | !> Abort routine for failures durin reading of namelists |
---|
[3246] | 333 | !------------------------------------------------------------------------------! |
---|
| 334 | |
---|
| 335 | SUBROUTINE parin_fail_message( location, line ) |
---|
| 336 | |
---|
| 337 | USE control_parameters, & |
---|
| 338 | ONLY: message_string |
---|
| 339 | |
---|
[3247] | 340 | USE kinds |
---|
| 341 | |
---|
[3246] | 342 | IMPLICIT NONE |
---|
| 343 | |
---|
| 344 | CHARACTER(LEN=*) :: location !< text to be output on stdout |
---|
| 345 | CHARACTER(LEN=*) :: line |
---|
| 346 | |
---|
[3247] | 347 | CHARACTER(LEN=80) :: line_dum |
---|
| 348 | |
---|
| 349 | INTEGER(iwp) :: line_counter |
---|
| 350 | |
---|
| 351 | line_dum = ' ' |
---|
| 352 | line_counter = 0 |
---|
| 353 | |
---|
| 354 | REWIND( 11 ) |
---|
[3248] | 355 | DO WHILE ( INDEX( line_dum, TRIM(line) ) == 0 ) |
---|
| 356 | READ ( 11, '(A)', END=20 ) line_dum |
---|
| 357 | line_counter = line_counter + 1 |
---|
[3247] | 358 | ENDDO |
---|
| 359 | |
---|
| 360 | 20 WRITE( message_string, '(A,I3,A)' ) & |
---|
| 361 | 'Error(s) in NAMELIST '// TRIM(location) // & |
---|
| 362 | '&Reading fails on line ', line_counter, & |
---|
| 363 | ' at&' // line |
---|
[3248] | 364 | CALL message( 'parin', 'PA0271', 1, 2, 0, 6, 0 ) |
---|
[3246] | 365 | |
---|
| 366 | END SUBROUTINE parin_fail_message |
---|