[226] | 1 | SUBROUTINE message( routine_name, message_identifier, requested_action, & |
---|
| 2 | message_level, output_on_pe, file_id, flush ) |
---|
[213] | 3 | |
---|
| 4 | !------------------------------------------------------------------------------! |
---|
| 5 | ! Actual revisions: |
---|
| 6 | ! ----------------- |
---|
[226] | 7 | ! |
---|
[213] | 8 | ! |
---|
| 9 | ! Former revisions: |
---|
| 10 | ! ----------------- |
---|
| 11 | ! $Id: message.f90 311 2009-05-11 15:02:15Z raasch $ |
---|
| 12 | ! |
---|
[226] | 13 | ! 213 2008-11-13 10:26:18Z raasch |
---|
| 14 | ! Initial revision |
---|
| 15 | ! |
---|
[213] | 16 | ! Description: |
---|
| 17 | ! ------------ |
---|
| 18 | ! Handling of the different kinds of messages. |
---|
| 19 | ! Meaning of formal parameters: |
---|
| 20 | ! requested_action: 0 - continue, 1 - abort by stop, 2 - abort by mpi_abort |
---|
| 21 | ! message_level: 0 - informative, 1 - warning, 2 - error |
---|
| 22 | ! output_on_pe: -1 - all, else - output on specified PE |
---|
| 23 | ! file_id: 6 - stdout (*) |
---|
| 24 | ! flush: 0 - no action, 1 - flush the respective output buffer |
---|
| 25 | !------------------------------------------------------------------------------! |
---|
| 26 | |
---|
| 27 | USE pegrid |
---|
| 28 | USE control_parameters |
---|
| 29 | |
---|
| 30 | IMPLICIT NONE |
---|
| 31 | |
---|
| 32 | CHARACTER(LEN=6) :: message_identifier |
---|
| 33 | CHARACTER(LEN=*) :: routine_name |
---|
[311] | 34 | CHARACTER(LEN=200) :: header_string, information_string_1,information_string_2 |
---|
[213] | 35 | |
---|
| 36 | INTEGER :: file_id, flush, i, message_level, output_on_pe, requested_action |
---|
| 37 | |
---|
| 38 | LOGICAL :: do_output, pe_out_of_range |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | do_output = .FALSE. |
---|
| 42 | pe_out_of_range = .FALSE. |
---|
| 43 | |
---|
| 44 | ! print*, '#1' |
---|
| 45 | ! |
---|
| 46 | !-- Create the complete output string, starting with the message level |
---|
| 47 | IF ( message_level == 0 ) THEN |
---|
| 48 | header_string = '--- informative message --- ID:' |
---|
| 49 | ELSEIF ( message_level == 1 ) THEN |
---|
| 50 | header_string = '+++ warning message --- ID:' |
---|
| 51 | ELSEIF ( message_level == 2 ) THEN |
---|
| 52 | header_string = '+++ error message --- ID:' |
---|
| 53 | ELSE |
---|
| 54 | WRITE( header_string,'(A,I2)' ) '+++ unknown message level: ', & |
---|
| 55 | message_level |
---|
| 56 | ENDIF |
---|
| 57 | |
---|
| 58 | ! print*, '#2' |
---|
| 59 | ! |
---|
| 60 | !-- Add the message identifier and the generating routine |
---|
| 61 | header_string = TRIM( header_string ) // ' ' // message_identifier // & |
---|
| 62 | ' generated by routine: ' // TRIM( routine_name ) |
---|
[311] | 63 | |
---|
| 64 | information_string_1 = 'Further information can be found at' |
---|
| 65 | IF(message_identifier(1:2) == 'NC') THEN |
---|
| 66 | information_string_2 = 'http://www.muk.uni-hannover.de/~raasch/PALM_group/doc' // & |
---|
| 67 | '/app/appendix_a.html#NC****' |
---|
| 68 | ELSE |
---|
| 69 | information_string_2 = 'http://www.muk.uni-hannover.de/~raasch/PALM_group/doc' // & |
---|
| 70 | '/app/appendix_a.html#' // message_identifier |
---|
| 71 | END IF |
---|
| 72 | |
---|
[213] | 73 | |
---|
| 74 | ! print*, '#3' |
---|
| 75 | ! |
---|
| 76 | !-- Output the output string and the corresponding message string which had |
---|
| 77 | !-- been already assigned in the calling subroutine. |
---|
| 78 | ! |
---|
| 79 | !-- First find out if output shall be done on this PE. |
---|
| 80 | IF ( output_on_pe == -1 ) THEN |
---|
| 81 | do_output = .TRUE. |
---|
| 82 | ELSEIF ( myid == output_on_pe ) THEN |
---|
| 83 | do_output = .TRUE. |
---|
| 84 | ENDIF |
---|
| 85 | ! print*, '#4' |
---|
| 86 | #if defined( __parallel ) |
---|
| 87 | ! |
---|
| 88 | !-- In case of illegal pe number output on pe0 |
---|
| 89 | IF ( output_on_pe > numprocs-1 ) THEN |
---|
| 90 | pe_out_of_range = .TRUE. |
---|
| 91 | IF ( myid == 0 ) do_output = .TRUE. |
---|
| 92 | ENDIF |
---|
| 93 | ! print*, '#5' |
---|
| 94 | #endif |
---|
| 95 | |
---|
| 96 | ! |
---|
| 97 | !-- Now do the output |
---|
| 98 | IF ( do_output ) THEN |
---|
| 99 | ! print*, '#6' |
---|
| 100 | IF ( file_id == 6 ) THEN |
---|
| 101 | ! |
---|
| 102 | !-- Output on stdout |
---|
| 103 | WRITE( *, '(A/)' ) TRIM( header_string ) |
---|
| 104 | ! print*, '#7' |
---|
| 105 | ! |
---|
| 106 | !-- Cut message string into pieces and output one piece per line. |
---|
| 107 | !-- Remove leading blanks. |
---|
| 108 | message_string = ADJUSTL( message_string ) |
---|
| 109 | i = INDEX( message_string, '&' ) |
---|
| 110 | DO WHILE ( i /= 0 ) |
---|
| 111 | WRITE( *, '(4X,A)' ) ADJUSTL( message_string(1:i-1) ) |
---|
| 112 | message_string = ADJUSTL( message_string(i+1:) ) |
---|
| 113 | i = INDEX( message_string, '&' ) |
---|
| 114 | ENDDO |
---|
| 115 | WRITE( *, '(4X,A)' ) TRIM( message_string ) |
---|
| 116 | ! print*, '#8' |
---|
[311] | 117 | WRITE( *, '(4X,A)' ) '' |
---|
| 118 | WRITE( *, '(4X,A)' ) TRIM( information_string_1 ) |
---|
| 119 | WRITE( *, '(4X,A)' ) TRIM( information_string_2 ) |
---|
[213] | 120 | |
---|
| 121 | ELSE |
---|
| 122 | ! print*, '#9' |
---|
| 123 | ! |
---|
| 124 | !-- Output on requested file id (file must have been opened elsewhere!) |
---|
| 125 | WRITE( file_id, '(A/)' ) TRIM( header_string ) |
---|
| 126 | ! |
---|
| 127 | !-- Cut message string into pieces and output one piece per line. |
---|
| 128 | !-- Remove leading blanks. |
---|
| 129 | message_string = ADJUSTL( message_string ) |
---|
| 130 | i = INDEX( message_string, '&' ) |
---|
| 131 | DO WHILE ( i /= 0 ) |
---|
| 132 | WRITE( file_id, '(4X,A)' ) ADJUSTL( message_string(1:i-1) ) |
---|
| 133 | message_string = ADJUSTL( message_string(i+1:) ) |
---|
| 134 | i = INDEX( message_string, '&' ) |
---|
| 135 | ENDDO |
---|
| 136 | WRITE( file_id, '(4X,A)' ) TRIM( message_string ) |
---|
[311] | 137 | WRITE( *, '(4X,A)' ) '' |
---|
| 138 | WRITE( file_id, '(4X,A)' ) TRIM( information_string_1 ) |
---|
| 139 | WRITE( file_id, '(4X,A)' ) TRIM( information_string_2 ) |
---|
[213] | 140 | ! |
---|
| 141 | !-- Flush buffer, if requested |
---|
| 142 | IF ( flush == 1 ) CALL local_flush( file_id ) |
---|
| 143 | ENDIF |
---|
| 144 | ! print*, '#10' |
---|
| 145 | |
---|
| 146 | IF ( pe_out_of_range ) THEN |
---|
[226] | 147 | WRITE ( *, '(A)' ) '+++ WARNING from routine message:' |
---|
[213] | 148 | WRITE ( *, '(A,I6,A)' ) ' PE ', output_on_pe, & |
---|
| 149 | ' choosed for output is larger ' |
---|
| 150 | WRITE ( *, '(A,I6)' ) ' than the maximum number of used PEs', & |
---|
| 151 | numprocs-1 |
---|
| 152 | WRITE ( *, '(A)' ) ' Output is done on PE0 instead' |
---|
| 153 | ENDIF |
---|
| 154 | ! print*, '#11' |
---|
| 155 | |
---|
| 156 | ENDIF |
---|
| 157 | |
---|
| 158 | ! |
---|
| 159 | !-- Abort execution, if requested |
---|
| 160 | ! print*, '#12' |
---|
| 161 | IF ( requested_action > 0 ) THEN |
---|
| 162 | abort_mode = requested_action |
---|
| 163 | CALL local_stop |
---|
| 164 | ENDIF |
---|
| 165 | ! print*, '#13' |
---|
| 166 | |
---|
[226] | 167 | END SUBROUTINE message |
---|