dc_message.f90
Go to the documentation of this file.
1 != メッセージの出力
2 !
3 ! Authors:: Yasuhiro MORIKAWA, Masatsugu ODAKA
4 ! Version:: $Id: dc_message.F90,v 1.1 2009-03-20 09:09:53 morikawa Exp $
5 ! Tag Name:: $Name: $
6 ! Copyright:: Copyright (C) GFD Dennou Club, 2000-2005. All rights reserved.
7 ! License:: See COPYRIGHT[link:../../COPYRIGHT]
8 !
9 module dc_message
10  !
11  != メッセージの出力
12  !
13  !メッセージの出力を行うためのサブルーチン群を持つモジュールです。
14  !{dcl の MSGDMP.f}[http://www.gfd-dennou.org/arch/dcl/dcl-f77doc/rc1/math1/node26.html]
15  !の上位互換としても利用することを想定しています。
16  !現在、出力装置は標準出力に固定されています。
17  !
18  !
19  !== Tutorial
20  !
21  ! * gtool5 オフィシャルチュートリアル:
22  ! {メッセージの出力}[link:../tutorial/dc_message.htm]
23  !
24  !== Output Form
25  !
26  ! 本モジュールのサブルーチンによって以下のような形式のメッセージ
27  ! が出力されます。
28  !
29  !  
30  ! *** MESSAGE [where] *** message
31  !  
32  ! *** WARNING [where] *** message
33  !  
34  ! *** ERROR (Code number) [where] *** message
35  !
36  implicit none
37  private
38  public:: messagenotify
39  public:: messagesuppressmpi
40  interface messagenotify
41  module procedure messagenotifyc
42  module procedure messagenotifyi
43  end interface
45  module procedure messagesuppressmpi0
46  end interface
47  integer, save:: output_rank = -1
48 contains
49  subroutine messagenotifyc(level, where, message, &
50  & i, r, d, L, n, c1, c2, c3, ca, rank_mpi )
51  !
52  !=== メッセージの出力およびエラーによる終了
53  !
54  ! メッセージを標準出力へ出力したい場合に用います。
55  !
56  ! 文字型変数 where にはプログラム名 (サブルーチン名) など、
57  ! プログラム内のどこでメッセージを出力するのかを示すものを与えます。
58  !
59  ! 文字型変数 message には、出力したい文字列を与えます。
60  ! オプション変数 i, r, d, L, s, n, c1, c2, c3 を付加する事も出来ます。
61  ! 詳細に関しては dc_string#CPrintf を参照して下さい。
62  !
63  ! 文字型変数 level は出力するメッセージの種類を決める引数で、
64  ! <b><tt>"W"</tt></b> (または<b><tt>"Warning"</tt></b>
65  ! など <b><tt>"W"</tt></b> で始まる文字)
66  ! を与える事で<b>警告</b>であることを、
67  ! <b><tt>"E"</tt></b> (または<b><tt>"Error"</tt></b>
68  ! など <b><tt>"E"</tt></b> で始まる文字) を与える事で
69  ! <b>エラー (メッセージ出力後プログラムを終了) </b>であることを、
70  ! それ以外の文字 (大抵は <b><tt>"M"</tt></b>
71  ! を与えることを想定しています)
72  ! を与える事で<b>通常のメッセージ</b>であることを指定します。
73  ! <b><tt>"E"</tt></b>を与えた場合はメッセージ出力後、プログラムを
74  ! 強制終了させます。エラーコードは dc_error#USR_ERRNO となります。
75  !
76  use dc_types ,only: string, dp
77  use dc_string ,only: uchar, strhead, printf, cprintf
78  use dc_error ,only: storeerror, usr_errno
79  implicit none
80  character(*), intent(in) :: level ! "E", "W", "M" のどれかを与える。
81  character(*), intent(in) :: where ! プログラム名、手続き名
82  character(*), intent(in) :: message ! メッセージ
83  integer , intent(in), optional:: i(:), n(:)
84  real , intent(in), optional:: r(:)
85  real(DP) , intent(in), optional:: d(:)
86  logical , intent(in), optional:: L(:)
87  character(*), intent(in), optional:: c1, c2, c3
88  character(*), intent(in), optional:: ca(:)
89  integer , intent(in), optional:: rank_mpi
90  ! MPI 使用時に, ここで指定された
91  ! ランク数のノードでのみ
92  ! メッセージ出力を行います.
93  ! 負の値を与えた場合には,
94  ! 全てのノードで出力を行います.
95  !
96  ! MPI を使用していない場合には
97  ! このオプションは無視されます.
98  !
99  ! When MPI is used, messages are
100  ! output in only node that has
101  ! this runk number.
102  ! If negative value is given,
103  ! output is done on all nodes
104  !
105  ! This option is ignored
106  ! if MPI is not used.
107  !
108  character(string) :: msg
109  continue
110  if ( invalid_rank_number( rank_mpi ) ) return
111  if ( strhead( 'ERROR', trim( uchar(level) ) ) ) then
112  msg = cprintf(message, &
113  & i=i, r=r, d=d, l=l, n=n, c1=c1, c2=c2, c3=c3, ca=ca)
114  call storeerror(usr_errno, where, cause_c=msg)
115  elseif ( strhead( 'WARNING', trim( uchar(level) ) ) ) then
116  msg = cprintf(message, &
117  & i=i, r=r, d=d, l=l, n=n, c1=c1, c2=c2, c3=c3, ca=ca)
118  msg=' *** WARNING [' // trim(where) // '] *** '// trim(msg)
119  call printf(fmt='%c', c1=msg)
120  else
121  msg = cprintf(message, &
122  & i=i, r=r, d=d, l=l, n=n, c1=c1, c2=c2, c3=c3, ca=ca)
123  msg=' *** MESSAGE [' // trim(where) // '] *** ' // trim(msg)
124  call printf(fmt='%c', c1=msg)
125  endif
126  return
127  end subroutine messagenotifyc
128  subroutine messagenotifyi(number, where, message, &
129  & i, r, d, L, n, c1, c2, c3, ca, rank_mpi )
130  !
131  !=== メッセージの出力およびエラーによる終了
132  !
133  ! 基本的にもう一方の MessageNotify (または dc_message#MessageNotifyC)
134  ! と同様ですが、こちらは第1引数に数値型変数
135  ! number をとります。この number はエラーコードとして、
136  ! そのまま dc_error#StoreError に引き渡されます。
137  ! エラーコードに関しては (dc_error を参照ください)
138  !
139  use dc_types ,only: dp
140  use dc_string ,only: cprintf
141  use dc_error ,only: storeerror, usr_errno
142  implicit none
143  integer, intent(in) :: number ! エラーコード (dc_error 参照)
144  character(*), intent(in) :: where
145  character(*), intent(in), optional:: message
146  integer , intent(in), optional:: i(:), n(:)
147  real , intent(in), optional:: r(:)
148  real(DP) , intent(in), optional:: d(:)
149  logical , intent(in), optional:: L(:)
150  character(*), intent(in), optional:: c1, c2, c3
151  character(*), intent(in), optional:: ca(:)
152  integer , intent(in), optional:: rank_mpi
153  ! MPI 使用時に, ここで指定された
154  ! ランク数のノードでのみ
155  ! メッセージ出力を行います.
156  ! 負の値を与えた場合には,
157  ! 全てのノードで出力を行います.
158  !
159  ! MPI を使用していない場合には
160  ! このオプションは無視されます.
161  !
162  ! When MPI is used, messages are
163  ! output in only node that has
164  ! this runk number.
165  ! If negative value is given,
166  ! output is done on all nodes
167  !
168  ! This option is ignored
169  ! if MPI is not used.
170  !
171  continue
172  if ( invalid_rank_number( rank_mpi ) ) return
173  if (.not. present(message)) then
174  call storeerror(number, where)
175  else
176  call storeerror(number, where, &
177  & cause_c=cprintf( message, &
178  & i=i, r=r, d=d, l=l, n=n, c1=c1, c2=c2, c3=c3, ca=ca ) )
179  endif
180  return
181  end subroutine messagenotifyi
182  subroutine messagesuppressmpi0( rank )
183  implicit none
184  integer, intent(in):: rank
185  ! 出力するノードのランク数.
186  !
187  ! ここに指定されたランク数以外の
188  ! ノードでの出力は抑止されます.
189  !
190  ! MPI を使用していない場合には
191  ! サブルーチンは無効です.
192  !
193  ! Number of rank of an node that output.
194  !
195  ! Output on nodes that do not have
196  ! this rank number is suppressed.
197  !
198  ! This subroutine is ignored,
199  ! if MPI is not used.
200  !
201  continue
202  output_rank = rank
203  end subroutine messagesuppressmpi0
204  logical function invalid_rank_number( rank_mpi ) result(result)
205  implicit none
206  integer , intent(in), optional:: rank_mpi
207  ! MPI 使用時に, ここで指定された
208  ! ランク数のノードでのみ
209  ! メッセージ出力を行います.
210  ! 負の値を与えた場合には,
211  ! 全てのノードで出力を行います.
212  !
213  ! MPI を使用していない場合には
214  ! このオプションは無視されます.
215  !
216  ! When MPI is used, messages are
217  ! output in only node that has
218  ! this runk number.
219  ! If negative value is given,
220  ! output is done on all nodes
221  !
222  ! This option is ignored
223  ! if MPI is not used.
224  !
225  continue
226  result = .false.
227  return
228  end function invalid_rank_number
229 end module dc_message
integer, parameter, public usr_errno
Definition: dc_error.f90:604
subroutine, public storeerror(number, where, err, cause_c, cause_i)
Definition: dc_error.f90:830
subroutine messagenotifyi(number, where, message, i, r, d, L, n, c1, c2, c3, ca, rank_mpi)
Definition: dc_message.f90:130
subroutine messagenotifyc(level, where, message, i, r, d, L, n, c1, c2, c3, ca, rank_mpi)
Definition: dc_message.f90:51
logical function invalid_rank_number(rank_mpi)
Definition: dc_message.f90:205
integer, save output_rank
Definition: dc_message.f90:47
integer, parameter, public dp
倍精度実数型変数
Definition: dc_types.f90:83
文字型変数の操作.
Definition: dc_string.f90:24
種別型パラメタを提供します。
Definition: dc_types.f90:49
subroutine messagesuppressmpi0(rank)
Definition: dc_message.f90:183
integer, parameter, public string
文字列を保持する 文字型変数の種別型パラメタ
Definition: dc_types.f90:118