(git:936074a)
Loading...
Searching...
No Matches
print_messages.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2025 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Perform an abnormal program termination.
10!> \note These routines are low-level and thus provide also an error recovery
11!> when dependencies do not allow the use of the error logger. Only
12!> the master (root) process will dump, if para_env is available and
13!> properly specified. Otherwise (without any information about the
14!> parallel environment) most likely more than one process or even all
15!> processes will send their error dump to the default output unit.
16!> \par History
17!> - Routine external_control moved to a separate module
18!> - Delete stop_memory routine, rename module
19!> \author Matthias Krack (12.02.2001)
20! **************************************************************************************************
22#include "../base/base_uses.f90"
23 IMPLICIT NONE
24
25 PRIVATE
26
27 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'print_messages'
28
29 PUBLIC :: print_message
30
31CONTAINS
32
33! **************************************************************************************************
34!> \brief Perform a basic blocking of the text in message and print it
35!> optionally decorated with a frame of stars as defined by declev.
36!> \param message ...
37!> \param output_unit ...
38!> \param declev ...
39!> \param before ...
40!> \param after ...
41!> \date 28.08.1996
42!> \par History
43!> - Translated to Fortran 90/95 (07.10.1999, Matthias Krack)
44!> - CP2K by JH 21.08.2000
45!> - Bugs in the dynamic format generation removed (09.02.2001, MK)
46!> - Revised (26.01.2011,MK)
47!> \author Matthias Krack (MK)
48!> \note
49!> after : Number of empty lines after the message.
50!> before : Number of empty lines before the message.
51!> declev : Decoration level (0,1,2, ... star lines).
52!> message : String with the message text.
53!> output_unit: Logical unit number of output unit.
54! **************************************************************************************************
55 SUBROUTINE print_message(message, output_unit, declev, before, after)
56
57 CHARACTER(LEN=*), INTENT(IN) :: message
58 INTEGER, INTENT(IN) :: output_unit
59 INTEGER, INTENT(IN), OPTIONAL :: declev, before, after
60
61 CHARACTER(LEN=1), PARAMETER :: decoration_char = "*"
62
63 INTEGER :: blank_lines_after, blank_lines_before, &
64 decoration_level, i, ibreak, ipos1, &
65 ipos2, maxrowlen, msglen, nrow, rowlen
66
67 IF (PRESENT(after)) THEN
68 blank_lines_after = max(after, 0)
69 ELSE
70 blank_lines_after = 1
71 END IF
72
73 IF (PRESENT(before)) THEN
74 blank_lines_before = max(before, 0)
75 ELSE
76 blank_lines_before = 1
77 END IF
78
79 IF (PRESENT(declev)) THEN
80 decoration_level = max(declev, 0)
81 ELSE
82 decoration_level = 0
83 END IF
84
85 IF (decoration_level == 0) THEN
86 rowlen = 78
87 ELSE
88 rowlen = 70
89 END IF
90
91 msglen = len_trim(message)
92
93 ! Calculate number of rows
94
95 nrow = msglen/(rowlen + 1) + 1
96
97 ! Calculate appropriate row length
98
99 rowlen = min(msglen, rowlen)
100
101 ! Generate the blank lines before the message
102
103 DO i = 1, blank_lines_before
104 WRITE (unit=output_unit, fmt="(A)") ""
105 END DO
106
107 ! Scan for the longest row
108
109 ipos1 = 1
110 ipos2 = rowlen
111 maxrowlen = 0
112
113 DO
114 IF (ipos2 < msglen) THEN
115 i = index(message(ipos1:ipos2), " ", back=.true.)
116 IF (i == 0) THEN
117 ibreak = ipos2
118 ELSE
119 ibreak = ipos1 + i - 2
120 END IF
121 ELSE
122 ibreak = ipos2
123 END IF
124
125 maxrowlen = max(maxrowlen, ibreak - ipos1 + 1)
126
127 ipos1 = ibreak + 2
128 ipos2 = min(msglen, ipos1 + rowlen - 1)
129
130 ! When the last row is processed, exit loop
131
132 IF (ipos1 > msglen) EXIT
133
134 END DO
135
136 ! Generate the first set of star rows
137
138 IF (decoration_level > 1) THEN
139 DO i = 1, decoration_level - 1
140 WRITE (unit=output_unit, fmt="(T2,A)") &
141 repeat(decoration_char, maxrowlen + 8)
142 END DO
143 END IF
144
145 ! Break long messages
146
147 ipos1 = 1
148 ipos2 = rowlen
149
150 DO
151 IF (ipos2 < msglen) THEN
152 i = index(message(ipos1:ipos2), " ", back=.true.)
153 IF (i == 0) THEN
154 ibreak = ipos2
155 ELSE
156 ibreak = ipos1 + i - 2
157 END IF
158 ELSE
159 ibreak = ipos2
160 END IF
161
162 IF (decoration_level == 0) THEN
163 WRITE (unit=output_unit, fmt="(T2,A)") message(ipos1:ibreak)
164 ELSE IF (decoration_level > 0) THEN
165 WRITE (unit=output_unit, fmt="(T2,A)") &
166 repeat(decoration_char, 3)//" "//message(ipos1:ibreak)// &
167 repeat(" ", ipos1 + maxrowlen - ibreak)// &
168 repeat(decoration_char, 3)
169 END IF
170
171 ipos1 = ibreak + 2
172 ipos2 = min(msglen, ipos1 + rowlen - 1)
173
174 ! When the last row is processed, exit loop
175
176 IF (ipos1 > msglen) EXIT
177 END DO
178
179 ! Generate the second set star rows
180
181 IF (decoration_level > 1) THEN
182 DO i = 1, decoration_level - 1
183 WRITE (unit=output_unit, fmt="(T2,A)") &
184 repeat(decoration_char, maxrowlen + 8)
185 END DO
186 END IF
187
188 ! Generate the blank lines after the message
189
190 DO i = 1, blank_lines_after
191 WRITE (unit=output_unit, fmt="(A)") ""
192 END DO
193
194 END SUBROUTINE print_message
195
196END MODULE print_messages
Perform an abnormal program termination.
subroutine, public print_message(message, output_unit, declev, before, after)
Perform a basic blocking of the text in message and print it optionally decorated with a frame of sta...