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