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