gtool5 Fortran 90/95 ライブラリ 1.0.0-rc5
English
Loading...
Searching...
No Matches
dc_message.f90
Go to the documentation of this file.
1! -*- mode: f90; coding: utf-8 -*-
2!-----------------------------------------------------------------------
3! Copyright (c) 2000-2026 Gtool Development Group. All rights reserved.
4!-----------------------------------------------------------------------
5!>
6!> @author Yasuhiro MORIKAWA, Masatsugu ODAKA
7!> @copyright Copyright (C) GFD Dennou Club, 2000-2026. All rights reserved. <br/>
8!> License is BSD-2-Clause. see [COPYRIGHT](@ref COPYRIGHT) in detail
9!>
10!> @en
11!> @brief Message output module
12!> @details
13!> This module provides subroutines for outputting messages.
14!> It is intended to be used as a higher-level interface to
15!> dcl's MSGDMP.f (http://www.gfd-dennou.org/arch/dcl/dcl-f77doc/rc1/math1/node26.html).
16!> Currently, the output device is fixed to standard output.
17!>
18!> @section dc_message_output Output Form
19!>
20!> Messages are output in the following formats by subroutines of this module:
21!>
22!> @code
23!> *** MESSAGE [where] *** message
24!>
25!> *** WARNING [where] *** message
26!>
27!> *** ERROR (Code number) [where] *** message
28!> @endcode
29!>
30!> @enden
31!>
32!> @ja
33!> @brief メッセージの出力
34!> @details
35!> メッセージの出力を行うためのサブルーチン群を持つモジュールです。
36!> dcl の MSGDMP.f (http://www.gfd-dennou.org/arch/dcl/dcl-f77doc/rc1/math1/node26.html)
37!> の上位互換としても利用することを想定しています。
38!> 現在、出力装置は標準出力に固定されています。
39!>
40!> @section dc_message_output_ja 出力形式
41!>
42!> 本モジュールのサブルーチンによって以下のような形式のメッセージ
43!> が出力されます。
44!>
45!> @code
46!> *** MESSAGE [where] *** message
47!>
48!> *** WARNING [where] *** message
49!>
50!> *** ERROR (Code number) [where] *** message
51!> @endcode
52!>
53!> @endja
54!>
56 implicit none
57 private
58 public:: messagenotify
59 public:: messagesuppressmpi
60 interface messagenotify
61 module procedure messagenotifyc
62 module procedure messagenotifyi
63 end interface
65 module procedure messagesuppressmpi0
66 end interface
67 integer, save:: output_rank = -1
68contains
69 !> @en
70 !> @brief Output message or terminate with error
71 !> @details
72 !> Use this subroutine when you want to output a message to standard output.
73 !>
74 !> Give the character variable `where` as the program name (subroutine name) etc.,
75 !> indicating where in the program the message is output.
76 !>
77 !> Give the character variable `message` the string you want to output.
78 !> You can also add optional variables i, r, d, L, s, n, c1, c2, c3.
79 !> See dc_string::CPrintf for details.
80 !>
81 !> The character variable `level` determines the type of message to output:
82 !> - "W" (or "Warning", etc. starting with "W") indicates a **warning**
83 !> - "E" (or "Error", etc. starting with "E") indicates an **error** (program terminates after message output)
84 !> - Other characters (usually "M" is expected) indicate a **normal message**
85 !>
86 !> If "E" is given, the program is forcibly terminated after the message is output.
87 !> The error code will be dc_error::USR_ERRNO.
88 !>
89 !> @param[in] level Message level ("E", "W", or "M")
90 !> @param[in] where Program name, procedure name
91 !> @param[in] message Message text
92 !> @param[in] i Integer values for formatting
93 !> @param[in] r Real values for formatting
94 !> @param[in] d Double precision values for formatting
95 !> @param[in] L Logical values for formatting
96 !> @param[in] n Integer values for formatting
97 !> @param[in] c1 Character string 1 for formatting
98 !> @param[in] c2 Character string 2 for formatting
99 !> @param[in] c3 Character string 3 for formatting
100 !> @param[in] ca Character array for formatting
101 !> @param[in] rank_mpi When MPI is used, messages are output only on the node with
102 !> this rank number. If a negative value is given, output is done on all nodes.
103 !> This option is ignored if MPI is not used.
104 !> @enden
105 !>
106 !> @ja
107 !> @brief メッセージの出力およびエラーによる終了
108 !> @details
109 !> メッセージを標準出力へ出力したい場合に用います。
110 !>
111 !> 文字型変数 `where` にはプログラム名 (サブルーチン名) など、
112 !> プログラム内のどこでメッセージを出力するのかを示すものを与えます。
113 !>
114 !> 文字型変数 `message` には、出力したい文字列を与えます。
115 !> オプション変数 i, r, d, L, s, n, c1, c2, c3 を付加する事も出来ます。
116 !> 詳細に関しては dc_string::CPrintf を参照して下さい。
117 !>
118 !> 文字型変数 `level` は出力するメッセージの種類を決める引数で、
119 !> - "W" (または "Warning" など "W" で始まる文字) を与える事で **警告** であることを指定
120 !> - "E" (または "Error" など "E" で始まる文字) を与える事で **エラー** (メッセージ出力後プログラムを終了) であることを指定
121 !> - それ以外の文字 (大抵は "M" を与えることを想定) を与える事で **通常のメッセージ** であることを指定
122 !>
123 !> "E" を与えた場合はメッセージ出力後、プログラムを強制終了させます。
124 !> エラーコードは dc_error::USR_ERRNO となります。
125 !>
126 !> @param[in] level メッセージレベル ("E", "W", "M" のいずれか)
127 !> @param[in] where プログラム名、手続き名
128 !> @param[in] message メッセージ
129 !> @param[in] i フォーマット用整数配列
130 !> @param[in] r フォーマット用実数配列
131 !> @param[in] d フォーマット用倍精度実数配列
132 !> @param[in] L フォーマット用論理配列
133 !> @param[in] n フォーマット用整数配列
134 !> @param[in] c1 フォーマット用文字列1
135 !> @param[in] c2 フォーマット用文字列2
136 !> @param[in] c3 フォーマット用文字列3
137 !> @param[in] ca フォーマット用文字列配列
138 !> @param[in] rank_mpi MPI 使用時に、ここで指定されたランク数のノードでのみ
139 !> メッセージ出力を行います。負の値を与えた場合には、
140 !> 全てのノードで出力を行います。MPI を使用していない場合には無視されます。
141 !> @endja
142 subroutine messagenotifyc(level, where, message, &
143 & i, r, d, L, n, c1, c2, c3, ca, rank_mpi )
144 use dc_types ,only: string, dp
145 use dc_string ,only: uchar, strhead, printf, cprintf
146 use dc_error ,only: storeerror, usr_errno
147 implicit none
148 character(*), intent(in) :: level
149 character(*), intent(in) :: where
150 character(*), intent(in) :: message
151 integer , intent(in), optional:: i(:), n(:)
152 real , intent(in), optional:: r(:)
153 real(DP) , intent(in), optional:: d(:)
154 logical , intent(in), optional:: L(:)
155 character(*), intent(in), optional:: c1, c2, c3
156 character(*), intent(in), optional:: ca(:)
157 integer , intent(in), optional:: rank_mpi
158 character(string) :: msg
159 continue
160 if ( invalid_rank_number( rank_mpi ) ) return
161 if ( strhead( 'ERROR', trim( uchar(level) ) ) ) then
162 msg = cprintf(message, &
163 & i=i, r=r, d=d, l=l, n=n, c1=c1, c2=c2, c3=c3, ca=ca)
164 call storeerror(usr_errno, where, cause_c=msg)
165 elseif ( strhead( 'WARNING', trim( uchar(level) ) ) ) then
166 msg = cprintf(message, &
167 & i=i, r=r, d=d, l=l, n=n, c1=c1, c2=c2, c3=c3, ca=ca)
168 msg=' *** WARNING [' // trim(where) // '] *** '// trim(msg)
169 call printf(fmt='%c', c1=msg)
170 else
171 msg = cprintf(message, &
172 & i=i, r=r, d=d, l=l, n=n, c1=c1, c2=c2, c3=c3, ca=ca)
173 msg=' *** MESSAGE [' // trim(where) // '] *** ' // trim(msg)
174 call printf(fmt='%c', c1=msg)
175 endif
176 return
177 end subroutine messagenotifyc
178 !> @en
179 !> @brief Output message or terminate with error (with error code)
180 !> @details
181 !> Basically the same as the other MessageNotify (or dc_message::MessageNotifyC),
182 !> but this one takes a numeric variable `number` as the first argument.
183 !> This `number` is passed directly to dc_error::StoreError as an error code.
184 !> See dc_error for error codes.
185 !>
186 !> @param[in] number Error code (see dc_error)
187 !> @param[in] where Program name, procedure name
188 !> @param[in] message Message text (optional)
189 !> @param[in] i Integer values for formatting
190 !> @param[in] r Real values for formatting
191 !> @param[in] d Double precision values for formatting
192 !> @param[in] L Logical values for formatting
193 !> @param[in] n Integer values for formatting
194 !> @param[in] c1 Character string 1 for formatting
195 !> @param[in] c2 Character string 2 for formatting
196 !> @param[in] c3 Character string 3 for formatting
197 !> @param[in] ca Character array for formatting
198 !> @param[in] rank_mpi When MPI is used, messages are output only on the node with
199 !> this rank number. If a negative value is given, output is done on all nodes.
200 !> This option is ignored if MPI is not used.
201 !> @enden
202 !>
203 !> @ja
204 !> @brief メッセージの出力およびエラーによる終了 (エラーコード版)
205 !> @details
206 !> 基本的にもう一方の MessageNotify (または dc_message::MessageNotifyC)
207 !> と同様ですが、こちらは第1引数に数値型変数 `number` をとります。
208 !> この `number` はエラーコードとして、そのまま dc_error::StoreError に
209 !> 引き渡されます。エラーコードに関しては dc_error を参照ください。
210 !>
211 !> @param[in] number エラーコード (dc_error 参照)
212 !> @param[in] where プログラム名、手続き名
213 !> @param[in] message メッセージ (省略可)
214 !> @param[in] i フォーマット用整数配列
215 !> @param[in] r フォーマット用実数配列
216 !> @param[in] d フォーマット用倍精度実数配列
217 !> @param[in] L フォーマット用論理配列
218 !> @param[in] n フォーマット用整数配列
219 !> @param[in] c1 フォーマット用文字列1
220 !> @param[in] c2 フォーマット用文字列2
221 !> @param[in] c3 フォーマット用文字列3
222 !> @param[in] ca フォーマット用文字列配列
223 !> @param[in] rank_mpi MPI 使用時に、ここで指定されたランク数のノードでのみ
224 !> メッセージ出力を行います。負の値を与えた場合には、
225 !> 全てのノードで出力を行います。MPI を使用していない場合には無視されます。
226 !> @endja
227 subroutine messagenotifyi(number, where, message, &
228 & i, r, d, L, n, c1, c2, c3, ca, rank_mpi )
229 use dc_types ,only: dp
230 use dc_string ,only: cprintf
231 use dc_error ,only: storeerror
232 implicit none
233 integer, intent(in) :: number
234 character(*), intent(in) :: where
235 character(*), intent(in), optional:: message
236 integer , intent(in), optional:: i(:), n(:)
237 real , intent(in), optional:: r(:)
238 real(DP) , intent(in), optional:: d(:)
239 logical , intent(in), optional:: L(:)
240 character(*), intent(in), optional:: c1, c2, c3
241 character(*), intent(in), optional:: ca(:)
242 integer , intent(in), optional:: rank_mpi
243 continue
244 if ( invalid_rank_number( rank_mpi ) ) return
245 if (.not. present(message)) then
246 call storeerror(number, where)
247 else
248 call storeerror(number, where, &
249 & cause_c=cprintf( message, &
250 & i=i, r=r, d=d, l=l, n=n, c1=c1, c2=c2, c3=c3, ca=ca ) )
251 endif
252 return
253 end subroutine messagenotifyi
254 !> @en
255 !> @brief Suppress message output on other MPI nodes
256 !> @details
257 !> Sets the rank of the node that outputs messages.
258 !> Output on nodes that do not have this rank number is suppressed.
259 !> This subroutine is ignored if MPI is not used.
260 !>
261 !> @param[in] rank Number of rank of the node that outputs messages.
262 !> Output on nodes that do not have this rank number is suppressed.
263 !> @enden
264 !>
265 !> @ja
266 !> @brief MPI 使用時のメッセージ出力抑止設定
267 !> @details
268 !> 出力するノードのランク数を設定します。
269 !> ここに指定されたランク数以外のノードでの出力は抑止されます。
270 !> MPI を使用していない場合にはサブルーチンは無効です。
271 !>
272 !> @param[in] rank 出力するノードのランク数。
273 !> ここに指定されたランク数以外のノードでの出力は抑止されます。
274 !> @endja
275 subroutine messagesuppressmpi0( rank )
276 implicit none
277 integer, intent(in):: rank
278 continue
279 output_rank = rank
280 end subroutine messagesuppressmpi0
281 !> @en
282 !> @brief Check if the current MPI rank should suppress output
283 !> @details
284 !> Returns .true. if the current MPI rank should not output messages,
285 !> .false. if output is allowed. When MPI is not used, always returns .false.
286 !>
287 !> @param[in] rank_mpi When MPI is used, messages are output only on the node with
288 !> this rank number. If a negative value is given, output is done on all nodes.
289 !> This option is ignored if MPI is not used.
290 !> @return .true. if output should be suppressed, .false. otherwise
291 !> @enden
292 !>
293 !> @ja
294 !> @brief 現在の MPI ランクが出力を抑止すべきかチェック
295 !> @details
296 !> 現在の MPI ランクがメッセージを出力すべきでない場合に .true. を返し、
297 !> 出力が許可されている場合は .false. を返します。
298 !> MPI を使用していない場合は常に .false. を返します。
299 !>
300 !> @param[in] rank_mpi MPI 使用時に、ここで指定されたランク数のノードでのみ
301 !> メッセージ出力を行います。負の値を与えた場合には、
302 !> 全てのノードで出力を行います。MPI を使用していない場合には無視されます。
303 !> @return 出力を抑止すべき場合は .true.、それ以外は .false.
304 !> @endja
305 logical function invalid_rank_number( rank_mpi ) result(result)
306 implicit none
307 integer , intent(in), optional:: rank_mpi
308 continue
309 result = .false.
310 return
311 end function invalid_rank_number
312 !> @namespace dc_message
313end module dc_message
エラー処理用モジュール
Definition dc_error.f90:454
subroutine, public storeerror(number, where, err, cause_c, cause_i)
Definition dc_error.f90:891
integer, parameter, public usr_errno
-1000 以下: ユーザー定義
Definition dc_error.f90:579
メッセージの出力
文字型変数の操作
Definition dc_string.f90:83
種別型パラメタを提供します。
Definition dc_types.f90:55
integer, parameter, public string
文字列を保持する 文字型変数の種別型パラメタ
Definition dc_types.f90:137
integer, parameter, public dp
倍精度実数型変数
Definition dc_types.f90:92