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